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 * data,
int len,
162 int (*if_tx_commit)(
struct knetif * self);
168 int (*if_rx_poll)(
struct knetif * self);
176 int (*if_set_flags)(
struct knetif * self,
uint32 flags_and,
uint32 flags_or);
183 int (*if_set_mc)(
struct knetif *self,
const uint8 *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
228#define PACKED __attribute__((packed))
245typedef struct ip_hdr_s {
267typedef struct ipv6_hdr_s {
471#define ICMP_PROTOCOL_UNREACHABLE 2
472#define ICMP_PORT_UNREACHABLE 3
491#define ICMP_REASSEMBLY_TIME_EXCEEDED 1
514typedef struct net_ipv4_stats {
602 const struct in6_addr *target,
int dupdet);
615 const struct in6_addr *target,
int sol);
634#define ICMP6_DEST_UNREACH_NO_ROUTE 0
635#define ICMP6_DEST_UNREACH_PROHIBITED 1
636#define ICMP6_DEST_UNREACH_BEYOND_SCOPE 2
637#define ICMP6_DEST_UNREACH_ADDR_UNREACH 3
638#define ICMP6_DEST_UNREACH_PORT_UNREACH 4
639#define ICMP6_DEST_UNREACH_FAIL_EGRESS 5
640#define ICMP6_DEST_UNREACH_BAD_ROUTE 6
664#define ICMP6_TIME_EXCEEDED_HOPS_EXC 0
665#define ICMP6_TIME_EXCEEDED_FRAGMENT 1
686#define ICMP6_PARAM_PROB_BAD_HEADER 0
687#define ICMP6_PARAM_PROB_UNK_HEADER 1
688#define ICMP6_PARAM_PROB_UNK_OPTION 2
703 const uint8 *ppkt,
size_t psz);
715typedef struct net_ipv6_stats {
797typedef struct net_udp_stats {
int net_arp_input(netif_t *nif, const uint8 *pkt, int len)
Receive an ARP packet and process it (called by net_input).
int net_arp_init(void)
Init ARP.
void net_arp_shutdown(void)
Shutdown ARP.
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.
int net_arp_revlookup(netif_t *nif, uint8 ip_out[4], const uint8 mac_in[6])
Do a reverse ARP lookup.
int net_arp_query(netif_t *nif, const uint8 ip[4])
Generate an ARP who-has query on the given device.
int net_arp_insert(netif_t *nif, const uint8 mac[6], const uint8 ip[4], uint64 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.
uint16 net_crc16ccitt(const uint8 *data, int size, uint16 start)
Calculate a CRC16-CCITT over a block of data.
uint32 net_crc32be(const uint8 *data, int size)
Calculate a "big-endian" CRC-32 over a block of data.
int net_input(netif_t *device, const uint8 *data, int len)
Device drivers should call this function to submit packets received in the background.
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.
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_input_func)(netif_t *nif, const uint8 *pkt, int len)
Network input callback type.
Definition net.h:389
void net_shutdown(void)
Shutdown network support.
int net_init(uint32 ip)
Init network support.
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!
net_echo_cb net_icmp_echo_cb
Where will we handle possibly notifying the user of ping replies?
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_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:443
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_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_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.
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.
net6_echo_cb net_icmp6_echo_cb
Where will we handle possibly notifying the user of ping replies?
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:567
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_icmp6_send_rsol(netif_t *net)
Send a Router Solicitation request 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.
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.
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.
uint32 net_ipv4_address(const uint8 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.
void net_multicast_shutdown(void)
Shutdown multicast support.
int net_multicast_check(const uint8 mac[6])
Check if an address is on the multicast list.
int net_multicast_init(void)
Init multicast support.
int net_multicast_del(const uint8 mac[6])
Delete a entry from our multicast list.
int net_multicast_add(const uint8 mac[6])
Add a entry to our multicast list.
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.
void net_ndp_shutdown(void)
Shutdown NDP.
void net_ndp_gc(void)
Garbage collect timed out NDP entries.
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.
int net_ndp_init(void)
Init NDP.
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.
typedef LIST_HEAD(nmmgr_list, nmmgr_handler) nmmgr_list_t
Name handler list type.
unsigned short uint16
16-bit unsigned integer
Definition types.h:34
unsigned long long uint64
64-bit unsigned integer
Definition types.h:32
unsigned long uint32
32-bit unsigned integer
Definition types.h:33
unsigned char uint8
8-bit unsigned integer
Definition types.h:35
Definitions for the Internet address family.
Structure used to store an IPv6 address.
Definition in.h:57
IPv4 Packet header.
Definition net.h:245
uint16 length
Length.
Definition net.h:248
uint8 tos
Type of Service.
Definition net.h:247
uint16 checksum
IP checksum.
Definition net.h:253
uint32 dest
Destination IP address.
Definition net.h:255
uint32 src
Source IP address.
Definition net.h:254
uint16 flags_frag_offs
Flags and fragment offset.
Definition net.h:250
uint8 ttl
Time to live.
Definition net.h:251
uint16 packet_id
Packet ID.
Definition net.h:249
uint8 protocol
IP protocol.
Definition net.h:252
uint8 version_ihl
IP version and header length.
Definition net.h:246
IPv6 Packet header.
Definition net.h:267
uint16 length
Length.
Definition net.h:273
uint8 next_header
Next header type.
Definition net.h:274
uint16 lclass
Low-order class byte.
Definition net.h:272
uint8 hop_limit
Hop limit.
Definition net.h:275
uint8 hclass_lflow
High-order class byte, low-order flow byte.
Definition net.h:270
uint8 version_lclass
Version and low-order class byte.
Definition net.h:268
IPv4 statistics structure.
Definition net.h:514
uint32 pkt_sent
Definition net.h:515
uint32 pkt_recv
Packets that failed to send.
Definition net.h:517
uint32 pkt_send_failed
Packets sent out successfully.
Definition net.h:516
uint32 pkt_recv_bad_proto
Packets with a bad checksum.
Definition net.h:520
uint32 pkt_recv_bad_size
Packets received successfully.
Definition net.h:518
uint32 pkt_recv_bad_chksum
Packets of a bad size.
Definition net.h:519
IPv6 statistics structure.
Definition net.h:715
uint32 pkt_recv
Packets received successfully.
Definition net.h:718
uint32 pkt_recv_bad_ext
Packets with an unknown hdr.
Definition net.h:721
uint32 pkt_sent
Packets sent out successfully.
Definition net.h:716
uint32 pkt_send_failed
Packets that failed to send.
Definition net.h:717
uint32 pkt_recv_bad_size
Packets of a bad size.
Definition net.h:719
uint32 pkt_recv_bad_proto
Packets with an unknown proto.
Definition net.h:720
UDP statistics structure.
Definition net.h:797
uint32 pkt_recv_bad_size
Packets of a bad size.
Definition net.h:801
uint32 pkt_send_failed
Packets that failed to send.
Definition net.h:799
uint32 pkt_sent
Packets sent out successfully.
Definition net.h:798
uint32 pkt_recv_no_sock
Packets with to a closed port.
Definition net.h:803
uint32 pkt_recv_bad_chksum
Packets with a bad checksum.
Definition net.h:802
uint32 pkt_recv
Packets received successfully.
Definition net.h:800
Structure describing one usable network device.
Definition net.h:53
uint32 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
int mtu
The device's MTU.
Definition net.h:92
uint32 dev_id
Internal device ID (for whatever the driver wants)
Definition net.h:68
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 flags
Interface flags.
Definition net.h:71