blob: e70499de624f327b3b5e5a56c0a85ef370045517 [file] [log] [blame]
// Copyright 2016 The Fuchsia Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef __NET_IPV6_INET6_H__
#define __NET_IPV6_INET6_H__
#include "net/ethernet.h"
#define ETH_HDR_LEN 14
#define ETH_MTU 1514
#define IPV6_ADDR_LEN 16
#define IPV6_HDR_LEN 40
#define IPV6_MIN_MTU 1280
#define UDP_HDR_LEN 8
typedef struct __attribute__((packed)) {
uint8_t x[IPV6_ADDR_LEN];
} Ipv6Address;
extern const Ipv6Address ipv6_ll_all_nodes;
extern const Ipv6Address ipv6_ll_all_routers;
#define HDR_HNH_OPT 0
#define HDR_TCP 6
#define HDR_UDP 17
#define HDR_ROUTING 43
#define HDR_FRAGMENT 44
#define HDR_ICMP6 58
#define HDR_NONE 59
#define HDR_DST_OPT 60
typedef struct __attribute__((packed)) {
uint32_t ver_tc_flow;
uint16_t length;
uint8_t next_header;
uint8_t hop_limit;
uint8_t src[IPV6_ADDR_LEN];
uint8_t dst[IPV6_ADDR_LEN];
} Ipv6Hdr;
typedef struct __attribute__((packed)) {
uint16_t src_port;
uint16_t dst_port;
uint16_t length;
uint16_t checksum;
} UdpHdr;
#define ICMP6_DEST_UNREACHABLE 1
#define ICMP6_PACKET_TOO_BIG 2
#define ICMP6_TIME_EXCEEDED 3
#define ICMP6_PARAMETER_PROBLEM 4
#define ICMP6_ECHO_REQUEST 128
#define ICMP6_ECHO_REPLY 129
#define ICMP6_NDP_N_SOLICIT 135
#define ICMP6_NDP_N_ADVERTISE 136
typedef struct __attribute__((packed)) {
uint8_t type;
uint8_t code;
uint16_t checksum;
} Icmp6Hdr;
typedef struct __attribute__((packed)) {
uint8_t type;
uint8_t code;
uint16_t checksum;
uint32_t flags;
uint8_t target[IPV6_ADDR_LEN];
uint8_t options[0];
} NdpNHdr;
#define NDP_N_SRC_LL_ADDR 1
#define NDP_N_TGT_LL_ADDR 2
#define NDP_N_PREFIX_INFO 3
#define NDP_N_REDIRECTED_HDR 4
#define NDP_N_MTU 5
// at least IP6TOAMAX bytes in size), and returns the buffer address.
char *ipv6toa(char *_out, void *ipv6addr);
#define IPV6TOAMAX 40
// provided by inet6.c
void ipv6_init(const void *macaddr);
void eth_recv(void *data, size_t len);
// provided by interface driver
void *eth_get_buffer(size_t len);
void eth_put_buffer(void *ptr);
int eth_send(void *data, size_t len);
int eth_add_mcast_filter(const MacAddress *addr);
// call to transmit a UDP packet
int udpv6_send(const void *data, size_t len,
const Ipv6Address *daddr, uint16_t dport,
uint16_t sport);
// implement to recive UDP packets
void udpv6_recv(void *data, size_t len,
const Ipv6Address *daddr, uint16_t dport,
const Ipv6Address *saddr, uint16_t sport);
// NOTES
//
// This is an extremely minimal IPv6 stack, supporting just enough
// functionality to talk to link local hosts over UDP.
//
// It responds to ICMPv6 Neighbor Solicitations for its link local
// address, which is computed from the mac address provided by the
// ethernet interface driver.
//
// It responds to PINGs.
//
// It can only transmit to multicast addresses or to the address it
// last received a packet from (general usecase is to reply to a UDP
// packet from the UDP callback, which this supports)
//
// It does not currently do duplicate address detection, which is
// probably the most severe bug.
//
// It does not support any IPv6 options and will drop packets with
// options.
//
// It expects the network stack to provide transmit buffer allocation
// and free functionality. It will allocate a single transmit buffer
// from udp6_send() or icmp6_send() to fill out and either pass to the
// network stack via eth_send() or, in the event of an error, release
// via eth_put_buffer().
//
#endif /* __NET_IPV6_INET6_H__ */