24 #include <sys/cdefs.h>
28 #include <sys/queue.h>
178 #define NETIF_NO_FLAGS 0x00000000
179 #define NETIF_REGISTERED 0x00000001
180 #define NETIF_DETECTED 0x00000002
181 #define NETIF_INITIALIZED 0x00000004
182 #define NETIF_RUNNING 0x00000008
183 #define NETIF_PROMISC 0x00010000
184 #define NETIF_NEEDSPOLL 0x01000000
185 #define NETIF_NOETH 0x10000000
189 #define NETIF_TX_OK 0
190 #define NETIF_TX_ERROR -1
191 #define NETIF_TX_AGAIN -2
194 #define NETIF_NOBLOCK 0
195 #define NETIF_BLOCK 1
205 #define PACKED __attribute__((packed))
375 #define ICMP_PROTOCOL_UNREACHABLE 2
376 #define ICMP_PORT_UNREACHABLE 3
388 #define ICMP_REASSEMBLY_TIME_EXCEEDED 1
472 const struct in6_addr *target,
int dupdet);
482 const struct in6_addr *target,
int sol);
491 #define ICMP6_DEST_UNREACH_NO_ROUTE 0
492 #define ICMP6_DEST_UNREACH_PROHIBITED 1
493 #define ICMP6_DEST_UNREACH_BEYOND_SCOPE 2
494 #define ICMP6_DEST_UNREACH_ADDR_UNREACH 3
495 #define ICMP6_DEST_UNREACH_PORT_UNREACH 4
496 #define ICMP6_DEST_UNREACH_FAIL_EGRESS 5
497 #define ICMP6_DEST_UNREACH_BAD_ROUTE 6
510 #define ICMP6_TIME_EXCEEDED_HOPS_EXC 0
511 #define ICMP6_TIME_EXCEEDED_FRAGMENT 1
524 #define ICMP6_PARAM_PROB_BAD_HEADER 0
525 #define ICMP6_PARAM_PROB_UNK_HEADER 1
526 #define ICMP6_PARAM_PROB_UNK_OPTION 2
537 const uint8 *ppkt,
size_t psz);
uint32 pkt_recv
Packets received successfully.
Definition: net.h:617
uint32 pkt_recv_bad_proto
Packets with a bad checksum.
Definition: net.h:413
IPv4 statistics structure.
Definition: net.h:407
uint32 pkt_recv_bad_chksum
Packets of a bad size.
Definition: net.h:412
uint8 version_ihl
IP version and header length.
Definition: net.h:212
uint32 pkt_sent
Packets sent out successfully.
Definition: net.h:615
uint8 netmask[4]
The device's netmask.
Definition: net.h:69
uint32 net_crc32be(const uint8 *data, int size)
Calculate a "big-endian" CRC-32 over a block of data.
int net_icmp6_send_nsol(netif_t *net, const struct in6_addr *dst, const struct in6_addr *target, int dupdet)
Send a Neighbor Solicitation packet on the specified device.
uint8 version_lclass
Version and low-order class byte.
Definition: net.h:228
uint8 ip_addr[4]
The device's IP address (if any)
Definition: net.h:66
int(* if_rx_poll)(struct knetif *self)
Poll for queued receive packets, if neccessary.
Definition: net.h:157
net_input_func net_input_target
Where will input packets be routed?
void net_shutdown(void)
Shutdown network support.
net_echo_cb net_icmp_echo_cb
Where will we handle possibly notifying the user of ping replies?
net_ipv6_stats_t net_ipv6_get_stats(void)
Retrieve statistics from the IPv6 layer.
typedef LIST_HEAD(nmmgr_list, nmmgr_handler) nmmgr_list_t
Name handler list type.
uint16 checksum
IP checksum.
Definition: net.h:219
struct net_udp_stats net_udp_stats_t
UDP statistics structure.
struct ipv6_hdr_s ipv6_hdr_t
IPv6 Packet header.
int(* if_stop)(struct knetif *self)
Stop (hibernate) the device.
Definition: net.h:133
struct in6_addr src_addr
Source IP address.
Definition: net.h:236
uint32 pkt_recv_bad_ext
Packets with an unknown hdr.
Definition: net.h:554
void net_udp_shutdown(void)
Shutdown UDP.
int(* if_init)(struct knetif *self)
Initialize the device.
Definition: net.h:115
uint16 net_crc16ccitt(const uint8 *data, int size, uint16 start)
Calculate a CRC16-CCITT over a block of data.
int net_icmp6_send_dest_unreach(netif_t *net, uint8 code, const uint8 *ppkt, size_t psz)
Send a destination unreachable packet on the specified interface.
int net_icmp_send_time_exceeded(netif_t *net, uint8 code, const uint8 *msg)
Send an ICMP Time Exceeded packet in reply to the given message.
void net_arp_shutdown(void)
Shutdown ARP.
const char * descr
Long description of the device.
Definition: net.h:50
void net_ipv4_parse_address(uint32 addr, uint8 out[4])
Parse an IP address that is packet into a uint32 into an array of the individual bytes.
int ip6_addr_count
Definition: net.h:90
uint32 pkt_recv_bad_size
Packets of a bad size.
Definition: net.h:618
int(* if_tx)(struct knetif *self, const uint8 *data, int len, int blocking)
Queue a packet for transmission.
Definition: net.h:144
int net_icmp6_send_time_exceeded(netif_t *net, uint8 code, const uint8 *ppkt, size_t psz)
Send a time exceeded message on the specified interface.
int net_input(netif_t *device, const uint8 *data, int len)
Device drivers should call this function to submit packets received in the background.
uint16 packet_id
Packet ID.
Definition: net.h:215
netif_t * net_set_default(netif_t *n)
Set our default device to an arbitrary device.
int(* if_detect)(struct knetif *self)
Attempt to detect the device.
Definition: net.h:109
int net_ndp_init(void)
Init NDP.
struct in6_addr ip6_gateway
The device's gateway's IPv6 address.
Definition: net.h:93
struct knetif netif_t
Structure describing one usable network device.
void(* net6_echo_cb)(const struct in6_addr *ip, uint16 seq, uint64 delta_us, uint8 hlim, const uint8 *data, size_t len)
ICMPv6 echo reply callback type.
Definition: net.h:445
Definitions for the Internet address family.
uint8 mac_addr[6]
The device's MAC address.
Definition: net.h:63
uint32 pkt_send_failed
Packets that failed to send.
Definition: net.h:616
void(* net_echo_cb)(const uint8 *ip, uint16 seq, uint64 delta_us, uint8 ttl, const uint8 *data, size_t len)
ICMPv4 echo reply callback type.
Definition: net.h:356
uint16 length
Length.
Definition: net.h:214
net_ipv4_stats_t net_ipv4_get_stats(void)
Retrieve statistics from the IPv4 layer.
uint32 pkt_recv
Packets that failed to send.
Definition: net.h:410
int net_icmp_send_echo(netif_t *net, const uint8 ipaddr[4], uint16 ident, uint16 seq, const uint8 *data, size_t size)
Send an ICMP Echo packet to the specified IP.
int net_arp_lookup(netif_t *nif, const uint8 ip_in[4], uint8 mac_out[6], const ip_hdr_t *pkt, const uint8 *data, int data_size)
Look up an entry from the ARP cache.
struct in6_addr dst_addr
Destination IP address.
Definition: net.h:237
uint32 pkt_recv_bad_size
Packets received successfully.
Definition: net.h:411
uint16 length
Length.
Definition: net.h:233
int net_tcp_init(void)
Init TCP.
uint32 pkt_recv_bad_size
Packets of a bad size.
Definition: net.h:552
void net_tcp_shutdown(void)
Shutdown TCP.
int net_icmp6_send_rsol(netif_t *net)
Send a Router Solicitation request on the specified interface.
const char * name
Device name ("bba", "la", etc)
Definition: net.h:47
int(* if_start)(struct knetif *self)
Start the device (after init or stop).
Definition: net.h:127
uint32 pkt_recv_no_sock
Packets with to a closed port.
Definition: net.h:620
int(* net_input_func)(netif_t *nif, const uint8 *pkt, int len)
Network input callback type.
Definition: net.h:322
unsigned long long uint64
64-bit unsigned integer
Definition: types.h:27
int(* if_shutdown)(struct knetif *self)
Shutdown the device.
Definition: net.h:121
struct in6_addr ip6_lladdr
The device's Link-local IPv6 address.
Definition: net.h:84
int net_icmp6_send_echo(netif_t *net, const struct in6_addr *dst, uint16 ident, uint16 seq, const uint8 *data, size_t size)
Send an ICMPv6 Echo (PING6) packet to the specified device.
uint32 pkt_recv
Packets received successfully.
Definition: net.h:551
uint32 pkt_sent
Packets sent out successfully.
Definition: net.h:549
uint32 pkt_recv_bad_proto
Packets with an unknown proto.
Definition: net.h:553
UDP statistics structure.
Definition: net.h:614
uint32 net_ipv4_address(const uint8 addr[4])
Create a 32-bit IP address, based on the individual numbers contained within the IP.
int net_arp_revlookup(netif_t *nif, uint8 ip_out[4], const uint8 mac_in[6])
Do a reverse ARP lookup.
int net_arp_input(netif_t *nif, const uint8 *pkt, int len)
Receive an ARP packet and process it (called by net_input).
int(* if_set_mc)(struct knetif *self, const uint8 *list, int count)
Set the device's multicast list.
Definition: net.h:172
uint8 ttl
Time to live.
Definition: net.h:217
unsigned short uint16
16-bit unsigned integer
Definition: types.h:29
struct ip_hdr_s ip_hdr_t
IPv4 Packet header.
struct net_ipv6_stats net_ipv6_stats_t
IPv6 statistics structure.
int net_multicast_init(void)
Init multicast support.
Structure used to store an IPv6 address.
Definition: in.h:50
int mtu
The device's MTU.
Definition: net.h:81
uint16 flags_frag_offs
Flags and fragment offset.
Definition: net.h:216
int net_arp_init(void)
Init ARP.
int net_reg_device(netif_t *device)
Register a network device.
uint8 tos
Type of Service.
Definition: net.h:213
struct netif_list net_if_list
Interface list; note: do not manipulate directly!
int net_icmp6_send_nadv(netif_t *net, const struct in6_addr *dst, const struct in6_addr *target, int sol)
Send a Neighbor Advertisement packet on the specified device.
uint32 pkt_send_failed
Packets that failed to send.
Definition: net.h:550
int(* if_set_flags)(struct knetif *self, uint32 flags_and, uint32 flags_or)
Set flags; you should generally manipulate flags through here so that the driver gets a chance to act...
Definition: net.h:165
uint8 gateway[4]
The device's gateway's IP address.
Definition: net.h:72
unsigned long uint32
32-bit unsigned integer
Definition: types.h:28
int net_unreg_device(netif_t *device)
Unregister a network device.
struct net_ipv4_stats net_ipv4_stats_t
IPv4 statistics structure.
LIST_ENTRY(knetif) if_list
Device list handle (not a function!)
uint8 next_header
Next header type.
Definition: net.h:234
uint32 pkt_sent
Definition: net.h:408
int net_ndp_lookup(netif_t *net, const struct in6_addr *ip, uint8 mac_out[6], const ipv6_hdr_t *pkt, const uint8 *data, int data_size)
Look up an entry from the NDP cache.
uint32 pkt_recv_bad_chksum
Packets with a bad checksum.
Definition: net.h:619
net_input_func net_input_set_target(net_input_func t)
Setup a network input target.
uint32 mtu6
Default MTU over IPv6.
Definition: net.h:96
uint8 hop_limit
Hop limit.
Definition: net.h:235
IPv4 Packet header.
Definition: net.h:211
int net_init(void)
Init network support.
uint16 lclass
Low-order class byte.
Definition: net.h:232
uint32 dev_id
Internal device ID (for whatever the driver wants)
Definition: net.h:57
void net_ndp_shutdown(void)
Shutdown NDP.
net_udp_stats_t net_udp_get_stats(void)
Retrieve statistics from the UDP layer.
IPv6 statistics structure.
Definition: net.h:548
uint8 broadcast[4]
The device's broadcast address.
Definition: net.h:75
uint32 src
Source IP address.
Definition: net.h:220
unsigned char uint8
8-bit unsigned integer
Definition: types.h:30
int hop_limit
Default hop limit over IPv6.
Definition: net.h:99
int net_udp_init(void)
Init UDP.
int net_ndp_insert(netif_t *nif, const uint8 mac[6], const struct in6_addr *ip, int unsol)
Add an entry to the NDP cache.
uint8 hclass_lflow
High-order class byte, low-order flow byte.
Definition: net.h:230
struct in6_addr * ip6_addrs
Any further IPv6 addresses the device has. The first address in this list will always be used...
Definition: net.h:89
uint8 dns[4]
The device's DNS server address.
Definition: net.h:78
Structure describing one usable network device.
Definition: net.h:42
net6_echo_cb net_icmp6_echo_cb
Where will we handle possibly notifying the user of ping replies?
int net_multicast_check(const uint8 mac[6])
Check if an address is on the multicast list.
int index
Unit index (starts at zero and counts upwards for multiple network devices of the same type) ...
Definition: net.h:54
uint32 pkt_send_failed
Packets sent out successfully.
Definition: net.h:409
uint8 protocol
IP protocol.
Definition: net.h:218
uint32 flags
Interface flags.
Definition: net.h:60
int net_multicast_del(const uint8 mac[6])
Delete a entry from our multicast list.
int net_icmp6_send_param_prob(netif_t *net, uint8 code, uint32 ptr, const uint8 *ppkt, size_t psz)
Send an ICMPv6 Parameter Problem about the given packet.
int net_arp_insert(netif_t *nif, const uint8 mac[6], const uint8 ip[4], uint32 timestamp)
Add an entry to the ARP cache manually.
uint32 net_crc32le(const uint8 *data, int size)
Calculate a "little-endian" CRC-32 over a block of data.
netif_t * net_default_dev
The default network device, used with sockets (read-only).
int(* if_tx_commit)(struct knetif *self)
Commit any queued output packets.
Definition: net.h:151
void net_ndp_gc(void)
Garbage collect timed out NDP entries. This will be called periodically as NDP queries come in...
struct netif_list * net_get_if_list(void)
Function to retrieve the interface list.
int net_icmp_send_dest_unreach(netif_t *net, uint8 code, const uint8 *msg)
Send an ICMP Destination Unreachable packet in reply to the given message.
int net_multicast_add(const uint8 mac[6])
Add a entry to our multicast list.
uint32 dest
Destination IP address.
Definition: net.h:221
void net_multicast_shutdown(void)
Shutdown multicast support.
IPv6 Packet header.
Definition: net.h:227
int net_arp_query(netif_t *nif, const uint8 ip[4])
Generate an ARP who-has query on the given device.