53typedef struct knetif {
120 int (*if_detect)(
struct knetif *self);
126 int (*if_init)(
struct knetif *self);
132 int (*if_shutdown)(
struct knetif *self);
138 int (*if_start)(
struct knetif *self);
144 int (*if_stop)(
struct knetif *self);
155 int (*if_tx)(
struct knetif *self,
const uint8_t *data,
int len,
162 int (*if_tx_commit)(
struct knetif *self);
168 int (*if_rx_poll)(
struct knetif *self);
183 int (*if_set_mc)(
struct knetif *self,
const uint8_t *list,
int count);
191#define NETIF_NO_FLAGS 0x00000000
192#define NETIF_REGISTERED 0x00000001
193#define NETIF_DETECTED 0x00000002
194#define NETIF_INITIALIZED 0x00000004
195#define NETIF_RUNNING 0x00000008
196#define NETIF_PROMISC 0x00010000
197#define NETIF_NEEDSPOLL 0x01000000
198#define NETIF_NOETH 0x10000000
207#define NETIF_TX_ERROR -1
208#define NETIF_TX_AGAIN -2
216#define NETIF_NOBLOCK 0
239typedef struct ip_hdr_s {
261typedef struct ipv6_hdr_s {
330 const ip_hdr_t *pkt,
const uint8_t *data,
int data_size);
434typedef void (*
net_echo_cb)(
const uint8_t *ip, uint16_t seq, uint64_t delta_us,
435 uint8_t ttl,
const uint8_t *data,
size_t len);
455 uint16_t seq,
const uint8_t *data,
size_t size);
462#define ICMP_PROTOCOL_UNREACHABLE 2
463#define ICMP_PORT_UNREACHABLE 3
482#define ICMP_REASSEMBLY_TIME_EXCEEDED 1
505typedef struct net_ipv4_stats {
559 uint64_t delta_us, uint8_t hlim,
const uint8_t *data,
580 uint16_t seq,
const uint8_t *data,
size_t size);
593 const struct in6_addr *target,
int dupdet);
606 const struct in6_addr *target,
int sol);
625#define ICMP6_DEST_UNREACH_NO_ROUTE 0
626#define ICMP6_DEST_UNREACH_PROHIBITED 1
627#define ICMP6_DEST_UNREACH_BEYOND_SCOPE 2
628#define ICMP6_DEST_UNREACH_ADDR_UNREACH 3
629#define ICMP6_DEST_UNREACH_PORT_UNREACH 4
630#define ICMP6_DEST_UNREACH_FAIL_EGRESS 5
631#define ICMP6_DEST_UNREACH_BAD_ROUTE 6
655#define ICMP6_TIME_EXCEEDED_HOPS_EXC 0
656#define ICMP6_TIME_EXCEEDED_FRAGMENT 1
677#define ICMP6_PARAM_PROB_BAD_HEADER 0
678#define ICMP6_PARAM_PROB_UNK_HEADER 1
679#define ICMP6_PARAM_PROB_UNK_OPTION 2
694 const uint8_t *ppkt,
size_t psz);
706typedef struct net_ipv6_stats {
769 const ipv6_hdr_t *pkt,
const uint8_t *data,
int data_size);
788typedef struct net_udp_stats {
Various common macros used throughout the codebase.
int net_arp_query(netif_t *nif, const uint8_t ip[4])
Generate an ARP who-has query on the given device.
int net_arp_init(void)
Init ARP.
void net_arp_shutdown(void)
Shutdown ARP.
int net_arp_insert(netif_t *nif, const uint8_t mac[6], const uint8_t ip[4], uint64_t timestamp)
Add an entry to the ARP cache manually.
int net_arp_lookup(netif_t *nif, const uint8_t ip_in[4], uint8_t mac_out[6], const ip_hdr_t *pkt, const uint8_t *data, int data_size)
Look up an entry from the ARP cache.
int net_arp_revlookup(netif_t *nif, uint8_t ip_out[4], const uint8_t mac_in[6])
Do a reverse ARP lookup.
int net_arp_input(netif_t *nif, const uint8_t *pkt, int len)
Receive an ARP packet and process it (called by net_input).
uint32_t __pure net_crc32le(const uint8_t *data, int size)
Calculate a "little-endian" CRC-32 over a block of data.
uint32_t __pure net_crc32be(const uint8_t *data, int size)
Calculate a "big-endian" CRC-32 over a block of data.
uint16_t __pure net_crc16ccitt(const uint8_t *data, int size, uint16_t start)
Calculate a CRC16-CCITT over a block of data.
netif_t * net_set_default(netif_t *n)
Set our default device to an arbitrary device.
struct netif_list * net_get_if_list(void)
Function to retrieve the interface list.
int(* net_input_func)(netif_t *nif, const uint8_t *pkt, int len)
Network input callback type.
Definition net.h:380
net_input_func net_input_target
Where will input packets be routed?
netif_t * net_default_dev
The default network device, used with sockets (read-only).
int net_reg_device(netif_t *device)
Register a network device.
int net_init(uint32_t ip)
Init network support.
void net_shutdown(void)
Shutdown network support.
int net_input(netif_t *device, const uint8_t *data, int len)
Device drivers should call this function to submit packets received in the background.
net_input_func net_input_set_target(net_input_func t)
Setup a network input target.
int net_unreg_device(netif_t *device)
Unregister a network device.
struct netif_list net_if_list
Interface list; note: do not manipulate directly!
int net_icmp_send_time_exceeded(netif_t *net, uint8_t code, const uint8_t *msg)
Send an ICMP Time Exceeded packet in reply to the given message.
net_echo_cb net_icmp_echo_cb
Where will we handle possibly notifying the user of ping replies?
int net_icmp_send_dest_unreach(netif_t *net, uint8_t code, const uint8_t *msg)
Send an ICMP Destination Unreachable packet in reply to the given message.
int net_icmp_send_echo(netif_t *net, const uint8_t ipaddr[4], uint16_t ident, uint16_t seq, const uint8_t *data, size_t size)
Send an ICMP Echo packet to the specified IP.
void(* net_echo_cb)(const uint8_t *ip, uint16_t seq, uint64_t delta_us, uint8_t ttl, const uint8_t *data, size_t len)
ICMPv4 echo reply callback type.
Definition net.h:434
int net_icmp6_send_param_prob(netif_t *net, uint8_t code, uint32_t ptr, const uint8_t *ppkt, size_t psz)
Send an ICMPv6 Parameter Problem about the given packet.
void(* net6_echo_cb)(const struct in6_addr *ip, uint16_t seq, uint64_t delta_us, uint8_t hlim, const uint8_t *data, size_t len)
ICMPv6 echo reply callback type.
Definition net.h:558
int net_icmp6_send_echo(netif_t *net, const struct in6_addr *dst, uint16_t ident, uint16_t seq, const uint8_t *data, size_t size)
Send an ICMPv6 Echo (PING6) packet to the specified device.
net6_echo_cb net_icmp6_echo_cb
Where will we handle possibly notifying the user of ping replies?
int net_icmp6_send_dest_unreach(netif_t *net, uint8_t code, const uint8_t *ppkt, size_t psz)
Send a destination unreachable packet on the specified interface.
int net_icmp6_send_rsol(netif_t *net)
Send a Router Solicitation request on the specified interface.
int net_icmp6_send_time_exceeded(netif_t *net, uint8_t code, const uint8_t *ppkt, size_t psz)
Send a time exceeded message on the specified interface.
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.
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.
void net_ipv4_parse_address(uint32_t addr, uint8_t out[4])
Parse an IP address that is packet into a uint32_t into an array of the individual bytes.
uint32_t __pure net_ipv4_address(const uint8_t addr[4])
Create a 32-bit IP address, based on the individual numbers contained within the IP.
net_ipv4_stats_t net_ipv4_get_stats(void)
Retrieve statistics from the IPv4 layer.
net_ipv6_stats_t net_ipv6_get_stats(void)
Retrieve statistics from the IPv6 layer.
int net_multicast_add(const uint8_t mac[6])
Add a entry to our multicast list.
void net_multicast_shutdown(void)
Shutdown multicast support.
int net_multicast_init(void)
Init multicast support.
int net_multicast_del(const uint8_t mac[6])
Delete a entry from our multicast list.
int net_multicast_check(const uint8_t mac[6])
Check if an address is on the multicast list.
int net_ndp_lookup(netif_t *net, const struct in6_addr *ip, uint8_t mac_out[6], const ipv6_hdr_t *pkt, const uint8_t *data, int data_size)
Look up an entry from the NDP cache.
void net_ndp_shutdown(void)
Shutdown NDP.
void net_ndp_gc(void)
Garbage collect timed out NDP entries.
int net_ndp_init(void)
Init NDP.
int net_ndp_insert(netif_t *nif, const uint8_t mac[6], const struct in6_addr *ip, int unsol)
Add an entry to the NDP cache.
void net_tcp_shutdown(void)
Shutdown TCP.
int net_tcp_init(void)
Init TCP.
net_udp_stats_t net_udp_get_stats(void)
Retrieve statistics from the UDP layer.
void net_udp_shutdown(void)
Shutdown UDP.
int net_udp_init(void)
Init UDP.
static uint32_t("Please see purupuru_effect_t for modern equivalent.") PURUPURU_EFFECT2_UINTENSITY(uint8_t x)
Definition purupuru.h:96
typedef LIST_HEAD(nmmgr_list, nmmgr_handler) nmmgr_list_t
Name handler list type.
Definitions for the Internet address family.
Structure used to store an IPv6 address.
Definition in.h:57
IPv4 Packet header.
Definition net.h:239
uint32_t src
Source IP address.
Definition net.h:248
uint16_t packet_id
Packet ID.
Definition net.h:243
uint32_t dest
Destination IP address.
Definition net.h:249
uint8_t version_ihl
IP version and header length.
Definition net.h:240
uint16_t length
Length.
Definition net.h:242
uint16_t checksum
IP checksum.
Definition net.h:247
uint8_t protocol
IP protocol.
Definition net.h:246
uint8_t ttl
Time to live.
Definition net.h:245
uint8_t tos
Type of Service.
Definition net.h:241
uint16_t flags_frag_offs
Flags and fragment offset.
Definition net.h:244
IPv6 Packet header.
Definition net.h:261
uint16_t length
Length.
Definition net.h:267
uint8_t hclass_lflow
High-order class byte, low-order flow byte.
Definition net.h:264
uint16_t lclass
Low-order class byte.
Definition net.h:266
uint8_t next_header
Next header type.
Definition net.h:268
uint8_t version_lclass
Version and low-order class byte.
Definition net.h:262
uint8_t hop_limit
Hop limit.
Definition net.h:269
IPv4 statistics structure.
Definition net.h:505
uint32_t pkt_sent
Definition net.h:506
uint32_t pkt_recv_bad_chksum
Packets of a bad size.
Definition net.h:510
uint32_t pkt_send_failed
Packets sent out successfully.
Definition net.h:507
uint32_t pkt_recv_bad_size
Packets received successfully.
Definition net.h:509
uint32_t pkt_recv_bad_proto
Packets with a bad checksum.
Definition net.h:511
uint32_t pkt_recv
Packets that failed to send.
Definition net.h:508
IPv6 statistics structure.
Definition net.h:706
uint32_t pkt_recv
Packets received successfully.
Definition net.h:709
uint32_t pkt_send_failed
Packets that failed to send.
Definition net.h:708
uint32_t pkt_recv_bad_ext
Packets with an unknown hdr.
Definition net.h:712
uint32_t pkt_recv_bad_size
Packets of a bad size.
Definition net.h:710
uint32_t pkt_sent
Packets sent out successfully.
Definition net.h:707
uint32_t pkt_recv_bad_proto
Packets with an unknown proto.
Definition net.h:711
UDP statistics structure.
Definition net.h:788
uint32_t pkt_recv_bad_size
Packets of a bad size.
Definition net.h:792
uint32_t pkt_sent
Packets sent out successfully.
Definition net.h:789
uint32_t pkt_recv_no_sock
Packets with to a closed port.
Definition net.h:794
uint32_t pkt_recv
Packets received successfully.
Definition net.h:791
uint32_t pkt_recv_bad_chksum
Packets with a bad checksum.
Definition net.h:793
uint32_t pkt_send_failed
Packets that failed to send.
Definition net.h:790
Structure describing one usable network device.
Definition net.h:53
uint32_t mtu6
Default MTU over IPv6.
Definition net.h:107
int ip6_addr_count
Definition net.h:101
int index
Unit index (starts at zero and counts upwards for multiple network devices of the same type)
Definition net.h:65
struct in6_addr * ip6_addrs
Any further IPv6 addresses the device has.
Definition net.h:100
uint32_t flags
Interface flags.
Definition net.h:71
int mtu
The device's MTU.
Definition net.h:92
LIST_ENTRY(knetif) if_list
Device list handle (not a function!)
const char * descr
Long description of the device.
Definition net.h:61
int hop_limit
Default hop limit over IPv6.
Definition net.h:110
const char * name
Device name ("bba", "la", etc)
Definition net.h:58
uint32_t dev_id
Internal device ID (for whatever the driver wants)
Definition net.h:68