KallistiOS
##version##
|
Network support. More...
Go to the source code of this file.
Data Structures | |
struct | knetif |
Structure describing one usable network device. More... | |
struct | ip_hdr_s |
IPv4 Packet header. More... | |
struct | ipv6_hdr_s |
IPv6 Packet header. More... | |
struct | net_ipv4_stats |
IPv4 statistics structure. More... | |
struct | net_ipv6_stats |
IPv6 statistics structure. More... | |
struct | net_udp_stats |
UDP statistics structure. More... | |
Macros | |
#define | NETIF_NO_FLAGS 0x00000000 |
No flags set. More... | |
#define | NETIF_REGISTERED 0x00000001 |
Is it registered? More... | |
#define | NETIF_DETECTED 0x00000002 |
Is it detected? More... | |
#define | NETIF_INITIALIZED 0x00000004 |
Has it been initialized? More... | |
#define | NETIF_RUNNING 0x00000008 |
Has start() been called? More... | |
#define | NETIF_PROMISC 0x00010000 |
Promiscuous mode. More... | |
#define | NETIF_NEEDSPOLL 0x01000000 |
Needs to be polled for input. More... | |
#define | NETIF_NOETH 0x10000000 |
Does not use ethernet. More... | |
#define | NETIF_TX_OK 0 |
Tx success. More... | |
#define | NETIF_TX_ERROR -1 |
Tx general error. More... | |
#define | NETIF_TX_AGAIN -2 |
Retry Tx later. More... | |
#define | NETIF_NOBLOCK 0 |
Don't block for Tx. More... | |
#define | NETIF_BLOCK 1 |
Blocking is OK for Tx. More... | |
#define | ICMP_PROTOCOL_UNREACHABLE 2 |
Protocol unreachable. More... | |
#define | ICMP_PORT_UNREACHABLE 3 |
Port unreachable. More... | |
#define | ICMP_REASSEMBLY_TIME_EXCEEDED 1 |
Reassembly time gone. More... | |
#define | ICMP6_DEST_UNREACH_NO_ROUTE 0 |
No route available. More... | |
#define | ICMP6_DEST_UNREACH_PROHIBITED 1 |
Access prohibited. More... | |
#define | ICMP6_DEST_UNREACH_BEYOND_SCOPE 2 |
Gone beyond scope. More... | |
#define | ICMP6_DEST_UNREACH_ADDR_UNREACH 3 |
Address unreachable. More... | |
#define | ICMP6_DEST_UNREACH_PORT_UNREACH 4 |
Port unreachable. More... | |
#define | ICMP6_DEST_UNREACH_FAIL_EGRESS 5 |
Egress failure. More... | |
#define | ICMP6_DEST_UNREACH_BAD_ROUTE 6 |
Bad route specified. More... | |
#define | ICMP6_TIME_EXCEEDED_HOPS_EXC 0 |
Hops exceeded. More... | |
#define | ICMP6_TIME_EXCEEDED_FRAGMENT 1 |
Reassembly time gone. More... | |
#define | ICMP6_PARAM_PROB_BAD_HEADER 0 |
Malformed header. More... | |
#define | ICMP6_PARAM_PROB_UNK_HEADER 1 |
Unknown header. More... | |
#define | ICMP6_PARAM_PROB_UNK_OPTION 2 |
Unknown header option. More... | |
Typedefs | |
typedef struct knetif | netif_t |
Structure describing one usable network device. More... | |
typedef struct ip_hdr_s | ip_hdr_t |
IPv4 Packet header. More... | |
typedef struct ipv6_hdr_s | ipv6_hdr_t |
IPv6 Packet header. More... | |
typedef int(* | net_input_func )(netif_t *nif, const uint8 *pkt, int len) |
Network input callback type. More... | |
typedef 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. More... | |
typedef struct net_ipv4_stats | net_ipv4_stats_t |
IPv4 statistics structure. More... | |
typedef 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. More... | |
typedef struct net_ipv6_stats | net_ipv6_stats_t |
IPv6 statistics structure. More... | |
typedef struct net_udp_stats | net_udp_stats_t |
UDP statistics structure. More... | |
Functions | |
int | net_arp_init (void) |
Init ARP. More... | |
void | net_arp_shutdown (void) |
Shutdown ARP. More... | |
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. More... | |
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. More... | |
int | net_arp_revlookup (netif_t *nif, uint8 ip_out[4], const uint8 mac_in[6]) |
Do a reverse ARP lookup. More... | |
int | net_arp_input (netif_t *nif, const uint8 *pkt, int len) |
Receive an ARP packet and process it (called by net_input). More... | |
int | net_arp_query (netif_t *nif, const uint8 ip[4]) |
Generate an ARP who-has query on the given device. More... | |
int | net_input (netif_t *device, const uint8 *data, int len) |
Device drivers should call this function to submit packets received in the background. More... | |
net_input_func | net_input_set_target (net_input_func t) |
Setup a network input target. More... | |
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. More... | |
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. More... | |
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. More... | |
net_ipv4_stats_t | net_ipv4_get_stats (void) |
Retrieve statistics from the IPv4 layer. More... | |
uint32 | net_ipv4_address (const uint8 addr[4]) |
Create a 32-bit IP address, based on the individual numbers contained within the IP. More... | |
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. More... | |
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. More... | |
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. More... | |
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. More... | |
int | net_icmp6_send_rsol (netif_t *net) |
Send a Router Solicitation request on the specified interface. More... | |
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. More... | |
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. More... | |
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. More... | |
net_ipv6_stats_t | net_ipv6_get_stats (void) |
Retrieve statistics from the IPv6 layer. More... | |
int | net_ndp_init (void) |
Init NDP. More... | |
void | net_ndp_shutdown (void) |
Shutdown NDP. More... | |
void | net_ndp_gc (void) |
Garbage collect timed out NDP entries. This will be called periodically as NDP queries come in. More... | |
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. More... | |
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. More... | |
net_udp_stats_t | net_udp_get_stats (void) |
Retrieve statistics from the UDP layer. More... | |
int | net_udp_init (void) |
Init UDP. More... | |
void | net_udp_shutdown (void) |
Shutdown UDP. More... | |
int | net_tcp_init (void) |
Init TCP. More... | |
void | net_tcp_shutdown (void) |
Shutdown TCP. More... | |
uint32 | net_crc32le (const uint8 *data, int size) |
Calculate a "little-endian" CRC-32 over a block of data. More... | |
uint32 | net_crc32be (const uint8 *data, int size) |
Calculate a "big-endian" CRC-32 over a block of data. More... | |
uint16 | net_crc16ccitt (const uint8 *data, int size, uint16 start) |
Calculate a CRC16-CCITT over a block of data. More... | |
int | net_multicast_add (const uint8 mac[6]) |
Add a entry to our multicast list. More... | |
int | net_multicast_del (const uint8 mac[6]) |
Delete a entry from our multicast list. More... | |
int | net_multicast_check (const uint8 mac[6]) |
Check if an address is on the multicast list. More... | |
int | net_multicast_init (void) |
Init multicast support. More... | |
void | net_multicast_shutdown (void) |
Shutdown multicast support. More... | |
struct netif_list * | net_get_if_list (void) |
Function to retrieve the interface list. More... | |
netif_t * | net_set_default (netif_t *n) |
Set our default device to an arbitrary device. More... | |
int | net_reg_device (netif_t *device) |
Register a network device. More... | |
int | net_unreg_device (netif_t *device) |
Unregister a network device. More... | |
int | net_init (void) |
Init network support. More... | |
void | net_shutdown (void) |
Shutdown network support. More... | |
Variables | |
net_input_func | net_input_target |
Where will input packets be routed? More... | |
net_echo_cb | net_icmp_echo_cb |
Where will we handle possibly notifying the user of ping replies? More... | |
net6_echo_cb | net_icmp6_echo_cb |
Where will we handle possibly notifying the user of ping replies? More... | |
struct netif_list | net_if_list |
Interface list; note: do not manipulate directly! More... | |
netif_t * | net_default_dev |
The default network device, used with sockets (read-only). More... | |
Network support.
This file contains declarations related to networking support. KOS' built-in network stack supports UDP over IPv4, and to some degree has some basic IPv6 support as well. This will change over time, hopefully leaving us with full TCP and UDP support both over IPv4 and IPv6.
#define ICMP6_DEST_UNREACH_ADDR_UNREACH 3 |
Address unreachable.
#define ICMP6_DEST_UNREACH_BAD_ROUTE 6 |
Bad route specified.
#define ICMP6_DEST_UNREACH_BEYOND_SCOPE 2 |
Gone beyond scope.
#define ICMP6_DEST_UNREACH_FAIL_EGRESS 5 |
Egress failure.
#define ICMP6_DEST_UNREACH_NO_ROUTE 0 |
No route available.
#define ICMP6_DEST_UNREACH_PORT_UNREACH 4 |
Port unreachable.
#define ICMP6_DEST_UNREACH_PROHIBITED 1 |
Access prohibited.
#define ICMP6_PARAM_PROB_BAD_HEADER 0 |
Malformed header.
#define ICMP6_PARAM_PROB_UNK_HEADER 1 |
Unknown header.
#define ICMP6_PARAM_PROB_UNK_OPTION 2 |
Unknown header option.
#define ICMP6_TIME_EXCEEDED_FRAGMENT 1 |
Reassembly time gone.
#define ICMP6_TIME_EXCEEDED_HOPS_EXC 0 |
Hops exceeded.
#define ICMP_PORT_UNREACHABLE 3 |
Port unreachable.
#define ICMP_PROTOCOL_UNREACHABLE 2 |
Protocol unreachable.
#define ICMP_REASSEMBLY_TIME_EXCEEDED 1 |
Reassembly time gone.
#define NETIF_BLOCK 1 |
Blocking is OK for Tx.
#define NETIF_NOBLOCK 0 |
Don't block for Tx.
#define NETIF_TX_AGAIN -2 |
Retry Tx later.
#define NETIF_TX_ERROR -1 |
Tx general error.
#define NETIF_TX_OK 0 |
Tx success.
typedef struct ipv6_hdr_s ipv6_hdr_t |
IPv6 Packet header.
typedef 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.
ip | The IPv6 address the reply is from. |
seq | The sequence number of the packet. |
delta_us | The time difference, in microseconds. |
hlim | The hop limit value in the packet. |
data | Any data in the packet. |
len | The length of the data, in bytes. |
typedef 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.
ip | The IPv4 address the reply is from. |
seq | The sequence number of the packet. |
delta_us | The time difference, in microseconds. |
ttl | The TTL value in the packet. |
data | Any data in the packet. |
len | The length of the data, in bytes. |
Network input callback type.
nif | The network device in use. |
pkt | The packet received. |
len | The length of the packet, in bytes. |
typedef struct net_ipv4_stats net_ipv4_stats_t |
IPv4 statistics structure.
This structure holds some basic statistics about the IPv4 layer of the stack, and can be retrieved with the appropriate function.
typedef struct net_ipv6_stats net_ipv6_stats_t |
IPv6 statistics structure.
This structure holds some basic statistics about the IPv6 layer of the stack, and can be retrieved with the appropriate function.
typedef struct net_udp_stats net_udp_stats_t |
UDP statistics structure.
This structure holds some basic statistics about the UDP layer of the stack, and can be retrieved with the appropriate function.
Structure describing one usable network device.
Each usable network device should have one of these describing it. These must be registered to the network layer before the device is useable.
int net_arp_init | ( | void | ) |
Init ARP.
0 | On success (no error conditions defined). |
Receive an ARP packet and process it (called by net_input).
nif | The network device in use. |
pkt | The packet received. |
len | The length of the packet. |
0 | On success (no error conditions defined). |
Add an entry to the ARP cache manually.
nif | The network device in use. |
mac | The MAC address of the entry. |
ip | The IPv4 address of the entry. |
timestamp | The entry's timestamp. Set to 0 for a permanent entry, otherwise set to jiffies. |
0 | On success (no error conditions defined). |
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.
If no entry is found, then an ARP query will be sent and an error will be returned. If you specify a packet with the call, it will be sent when the reply comes in.
nif | The network device in use. |
ip_in | The IP address to lookup. |
mac_out | Storage for the MAC address, if found. |
pkt | A simple IPv4 header, if you want to send one when a response comes in (if not found immediately). |
data | Packet data to go with the header. |
data_size | The size of data. |
0 | On success. |
-1 | A query is outstanding for that address. |
-2 | Address not found, query generated. |
Generate an ARP who-has query on the given device.
nif | The network device to use. |
ip | The IP to query. |
0 | On success (no error conditions defined). |
Do a reverse ARP lookup.
This function looks for an IP for a given mac address; note that if this fails, you have no recourse.
nif | The network device in use. |
ip_out | Storage for the IPv4 address. |
mac_in | The MAC address to look up. |
0 | On success. |
-1 | On failure. |
void net_arp_shutdown | ( | void | ) |
Shutdown ARP.
Calculate a CRC16-CCITT over a block of data.
data | The data to calculate over. |
size | The size of the data, in bytes. |
start | The value to start with. This could be a previous return value from this function (if continuing a previous calculation) or some initial seed value (typically 0xFFFF or 0x0000). |
Calculate a "big-endian" CRC-32 over a block of data.
data | The data to calculate over. |
size | The size of the data, in bytes. |
Calculate a "little-endian" CRC-32 over a block of data.
data | The data to calculate over. |
size | The size of the data, in bytes. |
struct netif_list* net_get_if_list | ( | void | ) |
Function to retrieve the interface list.
Do not manipulate what this returns to you!
Send a destination unreachable packet on the specified interface.
net | The network device to use. |
code | The type of message this is. |
ppkt | The message that caused this error. |
psz | Size of the original 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.
net | The network device to use. |
dst | The address to send to. |
ident | A packet identifier. |
seq | A packet sequence number. |
data | Data to send with the packet. |
size | Length of the data, in bytes. |
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.
net | The network device to use. |
dst | The destination address. |
target | The target address. |
sol | 1 if solicited, 0 otherwise. |
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.
net | The network device to use. |
dst | The destination address. |
target | The target address. |
dupdet | 1 if this is for duplicate detection. |
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.
net | The network device to use. |
code | The error code. |
ptr | Where in the packet is the error? |
ppkt | The message that caused the error. |
psz | Size of the original packet. |
int net_icmp6_send_rsol | ( | netif_t * | net | ) |
Send a Router Solicitation request on the specified interface.
net | The network device to use. |
Send a time exceeded message on the specified interface.
net | The network device to use. |
code | The error code. |
ppkt | The message that caused this error. |
psz | Size of the original packet. |
Send an ICMP Destination Unreachable packet in reply to the given message.
net | The network device to use. |
code | The type of message this is. |
msg | The message that caused this error. |
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.
net | The network device to use. |
ipaddr | The IPv4 address to send to. |
ident | A packet identifier. |
seq | A packet sequence number. |
data | Data to send with the packet. |
size | The size of the data to send. |
Send an ICMP Time Exceeded packet in reply to the given message.
net | The network device to use. |
code | The type of message this is. |
msg | The message that caused this error. |
int net_init | ( | void | ) |
Init network support.
Device drivers should call this function to submit packets received in the background.
This function may or may not return immidiately but it won't take an infinitely long time (so it's safe to call inside interrupt handlers).
device | The network device submitting packets. |
data | The packet to submit. |
len | The length of the packet, in bytes. |
net_input_func net_input_set_target | ( | net_input_func | t | ) |
Setup a network input target.
t | The new target callback. |
Create a 32-bit IP address, based on the individual numbers contained within the IP.
addr | Array of IP address octets. |
net_ipv4_stats_t net_ipv4_get_stats | ( | void | ) |
Retrieve statistics from the IPv4 layer.
Parse an IP address that is packet into a uint32 into an array of the individual bytes.
addr | The full address, in host byte order. |
out | The output buffer. |
net_ipv6_stats_t net_ipv6_get_stats | ( | void | ) |
Retrieve statistics from the IPv6 layer.
int net_multicast_add | ( | const uint8 | mac[6] | ) |
Add a entry to our multicast list.
This function will auto-commit the multicast list to the network interface in the process.
mac | The MAC address to add. |
int net_multicast_check | ( | const uint8 | mac[6] | ) |
Check if an address is on the multicast list.
mac | The MAC address to check for. |
0 | The address is not in the list. |
1 | The address is in the list. |
-1 | On error. |
int net_multicast_del | ( | const uint8 | mac[6] | ) |
Delete a entry from our multicast list.
This function will auto-commit the multicast list to the network interface in the process.
mac | The MAC address to add. |
int net_multicast_init | ( | void | ) |
Init multicast support.
void net_multicast_shutdown | ( | void | ) |
Shutdown multicast support.
void net_ndp_gc | ( | void | ) |
Garbage collect timed out NDP entries. This will be called periodically as NDP queries come in.
int net_ndp_init | ( | void | ) |
Init NDP.
0 | On success (no error conditions defined). |
Add an entry to the NDP cache.
nif | The network device in question. |
mac | The MAC address for the entry. |
ip | The IPv6 address for the entry. |
unsol | Was this unsolicited? |
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.
If no entry is found, then an NDP query will be sent and an error will be returned. If you specify a packet with the call, it will be sent when the reply comes in.
net | The network device to use. |
ip | The IPv6 address to query. |
mac_out | Storage for the MAC address on success. |
pkt | A simple IPv6 header, if you want to send a packet when a reply comes in. |
data | Anything that comes after the header. |
data_size | The size of data. |
void net_ndp_shutdown | ( | void | ) |
Shutdown NDP.
int net_reg_device | ( | netif_t * | device | ) |
Register a network device.
device | The device to register. |
Set our default device to an arbitrary device.
n | The device to set as default. |
void net_shutdown | ( | void | ) |
Shutdown network support.
int net_tcp_init | ( | void | ) |
Init TCP.
0 | On success (no error conditions defined). |
void net_tcp_shutdown | ( | void | ) |
Shutdown TCP.
net_udp_stats_t net_udp_get_stats | ( | void | ) |
Retrieve statistics from the UDP layer.
int net_udp_init | ( | void | ) |
Init UDP.
0 | On success (no error conditions defined). |
void net_udp_shutdown | ( | void | ) |
Shutdown UDP.
int net_unreg_device | ( | netif_t * | device | ) |
Unregister a network device.
device | The device to unregister. |
netif_t* net_default_dev |
The default network device, used with sockets (read-only).
net6_echo_cb net_icmp6_echo_cb |
Where will we handle possibly notifying the user of ping replies?
net_echo_cb net_icmp_echo_cb |
Where will we handle possibly notifying the user of ping replies?
struct netif_list net_if_list |
Interface list; note: do not manipulate directly!
net_input_func net_input_target |
Where will input packets be routed?