Files | |
file | ip.c |
IP module implementation. | |
file | ip.h |
IP module. | |
Data Structures | |
struct | ip_globals |
IP global data. More... | |
struct | ip_netif |
IP network interface specific data. More... | |
struct | ip_proto |
IP protocol specific data. More... | |
struct | ip_route |
IP route specific data. More... | |
Defines | |
#define | ARP_FILENAME "/srv/arp" |
ARP module filename. | |
#define | ARP_NAME "arp" |
ARP module name. | |
#define | IP_ADDR sizeof(struct sockaddr_in6) |
IP packet address length. | |
#define | IP_MAX_CONTENT 65535 |
IP packet maximum content length. | |
#define | IP_MIN_CONTENT 576 |
Minimum IP packet content. | |
#define | IP_PREFIX sizeof(ip_header_t) |
IP packet prefix length. | |
#define | IP_SUFFIX 0 |
IP packet suffix length. | |
#define | IPV4 4 |
IP version 4. | |
#define | IPV4_LOCALHOST_ADDRESS htonl((127 << 24) + 1) |
The IP localhost address. | |
#define | NAME "ip" |
IP module name. | |
#define | NET_DEFAULT_IP_ROUTING false |
Default network interface IP routing. | |
#define | NET_DEFAULT_IPV IPV4 |
Default network interface IP version. | |
Typedefs | |
typedef ip_globals | ip_globals_t |
Type definition of the IP global data. | |
typedef ip_netif | ip_netif_t |
Type definition of the IP network interface specific data. | |
typedef ip_proto | ip_proto_t |
Type definition of the IP protocol specific data. | |
typedef ip_route | ip_route_t |
Type definition of the IP route specific data. | |
Functions | |
DEVICE_MAP_DECLARE (ip_netifs, ip_netif_t) | |
IP network interfaces. | |
GENERIC_FIELD_DECLARE (ip_routes, ip_route_t) | |
IP routing table. | |
int | il_initialize (int net_phone) |
Module initialization. | |
int | il_module_message (ipc_callid_t callid, ipc_call_t *call, ipc_call_t *answer, size_t *answer_count) |
Process the internetwork layer module message. | |
INT_MAP_DECLARE (ip_protos, ip_proto_t) | |
IP registered protocols. | |
static int | ip_add_route_req_local (int ip_phone, device_id_t device_id, in_addr_t address, in_addr_t netmask, in_addr_t gateway) |
static void | ip_create_last_header (ip_header_t *last, ip_header_t *first) |
Copies the fragment header. | |
static ip_header_t * | ip_create_middle_header (packet_t *packet, ip_header_t *last) |
Prefixes a middle fragment header based on the last fragment header to the packet. | |
static int | ip_deliver_local (device_id_t device_id, packet_t *packet, ip_header_t *header, services_t error) |
Delivers the packet to the local host. | |
static int | ip_device_req_local (int il_phone, device_id_t device_id, services_t netif) |
static int | ip_device_state_message (device_id_t device_id, device_state_t state) |
Updates the device state. | |
static ip_route_t * | ip_find_route (in_addr_t destination) |
Searches all network interfaces if there is a suitable route. | |
static int | ip_fragment_packet (packet_t *packet, size_t length, size_t prefix, size_t suffix, socklen_t addr_len) |
Checks the packet length and fragments it if needed. | |
static int | ip_fragment_packet_data (packet_t *packet, packet_t *new_packet, ip_header_t *header, ip_header_t *new_header, size_t length, const struct sockaddr *src, const struct sockaddr *dest, socklen_t addrlen) |
Fragments the packet from the end. | |
static in_addr_t | ip_get_destination (ip_header_t *header) |
Returns the packet destination address from the IP header. | |
static int | ip_get_icmp_phone (void) |
Returns the ICMP phone. | |
static int | ip_get_route_req_local (int ip_phone, ip_protocol_t protocol, const struct sockaddr *destination, socklen_t addrlen, device_id_t *device_id, void **header, size_t *headerlen) |
static int | ip_mtu_changed_message (device_id_t device_id, size_t mtu) |
Updates the device content length according to the new MTU value. | |
static in_addr_t * | ip_netif_address (ip_netif_t *netif) |
Returns the network interface's IP address. | |
static ip_route_t * | ip_netif_find_route (ip_netif_t *netif, in_addr_t destination) |
Searches the network interfaces if there is a suitable route. | |
static int | ip_netif_initialize (ip_netif_t *ip_netif) |
Initializes a new network interface specific data. | |
static int | ip_packet_size_message (device_id_t device_id, size_t *addr_len, size_t *prefix, size_t *content, size_t *suffix) |
Returns the device packet dimensions for sending. | |
static int | ip_prepare_icmp (packet_t *packet, ip_header_t *header) |
Prepares the ICMP notification packet. | |
static int | ip_prepare_icmp_and_get_phone (services_t error, packet_t *packet, ip_header_t *header) |
Prepares the ICMP notification packet. | |
static int | ip_prepare_packet (in_addr_t *source, in_addr_t dest, packet_t *packet, measured_string_t *destination) |
Prepares the outgoing packet or the packet queue. | |
static int | ip_process_packet (device_id_t device_id, packet_t *packet) |
Processes the received packet. | |
static int | ip_received_error_msg_local (int ip_phone, device_id_t device_id, packet_t *packet, services_t target, services_t error) |
Notify the IP module about the received error notification packet. | |
static void | ip_receiver (ipc_callid_t iid, ipc_call_t *icall) |
Process IPC messages from the registered device driver modules. | |
static int | ip_register (int protocol, services_t service, int phone, tl_received_msg_t received_msg) |
Registers the transport layer protocol. | |
static int | ip_release_and_return (packet_t *packet, int result) |
Releases the packet and returns the result. | |
static int | ip_send_msg_local (int il_phone, device_id_t device_id, packet_t *packet, services_t sender, services_t error) |
static int | ip_send_route (packet_t *packet, ip_netif_t *netif, ip_route_t *route, in_addr_t *src, in_addr_t dest, services_t error) |
Sends the packet or the packet queue via the specified route. | |
static int | ip_set_gateway_req_local (int ip_phone, device_id_t device_id, in_addr_t gateway) |
static packet_t * | ip_split_packet (packet_t *packet, size_t prefix, size_t content, size_t suffix, socklen_t addr_len, services_t error) |
Checks the packet queue lengths and fragments the packets if needed. | |
int | main (int argc, char *argv[]) |
Main entry point. | |
Variables | |
ip_globals_t | ip_globals |
IP global data. |
typedef struct ip_globals ip_globals_t |
typedef struct ip_netif ip_netif_t |
typedef struct ip_proto ip_proto_t |
typedef struct ip_route ip_route_t |
DEVICE_MAP_DECLARE | ( | ip_netifs | , | |
ip_netif_t | ||||
) |
GENERIC_FIELD_DECLARE | ( | ip_routes | , | |
ip_route_t | ||||
) |
int il_initialize | ( | int | net_phone | ) |
int il_module_message | ( | ipc_callid_t | callid, | |
ipc_call_t * | call, | |||
ipc_call_t * | answer, | |||
size_t * | answer_count | |||
) |
Process the internetwork layer module message.
[in] | callid | The message identifier. |
[in] | call | The message parameters. |
[out] | answer | The message answer parameters. |
[out] | answer_count | The last parameter for the actual answer in the answer parameter. |
ENOTSUP if the message is not known.
INT_MAP_DECLARE | ( | ip_protos | , | |
ip_proto_t | ||||
) |
static void ip_create_last_header | ( | ip_header_t * | last, | |
ip_header_t * | first | |||
) | [static] |
static ip_header_t* ip_create_middle_header | ( | packet_t * | packet, | |
ip_header_t * | last | |||
) | [static] |
static int ip_deliver_local | ( | device_id_t | device_id, | |
packet_t * | packet, | |||
ip_header_t * | header, | |||
services_t | error | |||
) | [static] |
Delivers the packet to the local host.
The packet is either passed to another module or released on error. The ICMP_PROT_UNREACH error notification may be sent if the protocol is not found.
[in] | device_id | The source device identifier. |
[in] | packet | The packet to be delivered. |
[in] | header | The first packet IP header. May be NULL. |
[in] | error | The packet error service. |
ENOTSUP if the packet is a fragment.
EAFNOSUPPORT if the address family is not supported.
ENOENT if the target protocol is not found.
Other error codes as defined for the packet_set_addr() function.
Other error codes as defined for the packet_trim() function.
Other error codes as defined for the protocol specific tl_received_msg() function.
static int ip_device_state_message | ( | device_id_t | device_id, | |
device_state_t | state | |||
) | [static] |
static ip_route_t* ip_find_route | ( | in_addr_t | destination | ) | [static] |
static int ip_fragment_packet | ( | packet_t * | packet, | |
size_t | length, | |||
size_t | prefix, | |||
size_t | suffix, | |||
socklen_t | addr_len | |||
) | [static] |
Checks the packet length and fragments it if needed.
The new fragments are queued before the original packet.
[in,out] | packet | The packet to be checked. |
[in] | length | The maximum packet length. |
[in] | prefix | The minimum prefix size. |
[in] | suffix | The minimum suffix size. |
[in] | addr_len | The minimum address length. |
EINVAL if the packet_get_addr() function fails.
EINVAL if the packet does not contain the IP header.
EPERM if the packet needs to be fragmented and the fragmentation is not allowed.
ENOMEM if there is not enough memory left.
ENOMEM if there is no packet available.
ENOMEM if the packet is too small to contain the IP header.
Other error codes as defined for the packet_trim() function.
Other error codes as defined for the ip_create_middle_header() function.
Other error codes as defined for the ip_fragment_packet_data() function.
static int ip_fragment_packet_data | ( | packet_t * | packet, | |
packet_t * | new_packet, | |||
ip_header_t * | header, | |||
ip_header_t * | new_header, | |||
size_t | length, | |||
const struct sockaddr * | src, | |||
const struct sockaddr * | dest, | |||
socklen_t | addrlen | |||
) | [static] |
Fragments the packet from the end.
[in] | packet | The packet to be fragmented. |
[in,out] | new_packet | The new packet fragment. |
[in,out] | header | The original packet header. |
[in,out] | new_header | The new packet fragment header. |
[in] | length | The new fragment length. |
[in] | src | The source address. |
[in] | dest | The destiantion address. |
[in] | addrlen | The address length. |
ENOMEM if the target packet is too small.
Other error codes as defined for the packet_set_addr() function.
Other error codes as defined for the pq_insert_after() function.
static in_addr_t ip_get_destination | ( | ip_header_t * | header | ) | [static] |
static int ip_get_icmp_phone | ( | void | ) | [static] |
static int ip_mtu_changed_message | ( | device_id_t | device_id, | |
size_t | mtu | |||
) | [static] |
static in_addr_t* ip_netif_address | ( | ip_netif_t * | netif | ) | [static] |
static ip_route_t* ip_netif_find_route | ( | ip_netif_t * | netif, | |
in_addr_t | destination | |||
) | [static] |
static int ip_netif_initialize | ( | ip_netif_t * | ip_netif | ) | [static] |
Initializes a new network interface specific data.
Connects to the network interface layer module, reads the netif configuration, starts an ARP module if needed and sets the netif routing table.
The device identifier and the nil service has to be set.
[in,out] | ip_netif | Network interface specific data. |
ENOTSUP if DHCP is configured.
ENOTSUP if IPv6 is configured.
EINVAL if any of the addresses is invalid.
EINVAL if the used ARP module is not known.
ENOMEM if there is not enough memory left.
Other error codes as defined for the net_get_device_conf_req() function.
Other error codes as defined for the bind_service() function.
Other error codes as defined for the specific arp_device_req() function.
Other error codes as defined for the nil_packet_size_req() function.
static int ip_packet_size_message | ( | device_id_t | device_id, | |
size_t * | addr_len, | |||
size_t * | prefix, | |||
size_t * | content, | |||
size_t * | suffix | |||
) | [static] |
Returns the device packet dimensions for sending.
[in] | phone | The service module phone. |
[in] | message | The service specific message. |
[in] | device_id | The device identifier. |
[out] | addr_len | The minimum reserved address length. |
[out] | prefix | The minimum reserved prefix size. |
[out] | content | The maximum content size. |
[out] | suffix | The minimum reserved suffix size. |
static int ip_prepare_icmp | ( | packet_t * | packet, | |
ip_header_t * | header | |||
) | [static] |
Prepares the ICMP notification packet.
Releases additional packets and keeps only the first one.
[in] | packet | The packet or the packet queue to be reported as faulty. |
[in] | header | The first packet IP header. May be NULL. |
EINVAL if there are no data in the packet.
EINVAL if the packet is a fragment.
ENOMEM if the packet is too short to contain the IP header.
EAFNOSUPPORT if the address family is not supported.
EPERM if the protocol is not allowed to send ICMP notifications. The ICMP protocol itself.
Other error codes as defined for the packet_set_addr().
static int ip_prepare_icmp_and_get_phone | ( | services_t | error, | |
packet_t * | packet, | |||
ip_header_t * | header | |||
) | [static] |
Prepares the ICMP notification packet.
Releases additional packets and keeps only the first one. All packets are released on error.
[in] | error | The packet error service. |
[in] | packet | The packet or the packet queue to be reported as faulty. |
[in] | header | The first packet IP header. May be NULL. |
EINVAL if the error parameter is set.
EINVAL if the ICMP phone is not found.
EINVAL if the ip_prepare_icmp() fails.
static int ip_prepare_packet | ( | in_addr_t * | source, | |
in_addr_t | dest, | |||
packet_t * | packet, | |||
measured_string_t * | destination | |||
) | [static] |
Prepares the outgoing packet or the packet queue.
The packet queue is a fragmented packet Updates the first packet's IP header. Prefixes the additional packets with fragment headers.
[in] | source | The source address. |
[in] | dest | The destination address. |
[in,out] | packet | The packet to be sent. |
[in] | destination | The destination hardware address. |
EINVAL if the packet is too small to contain the IP header.
EINVAL if the packet is too long than the IP allows.
ENOMEM if there is not enough memory left.
Other error codes as defined for the packet_set_addr() function.
static int ip_process_packet | ( | device_id_t | device_id, | |
packet_t * | packet | |||
) | [static] |
Processes the received packet.
The packet is either passed to another module or released on error.
The ICMP_PARAM_POINTER error notification may be sent if the checksum is invalid. The ICMP_EXC_TTL error notification may be sent if the TTL is less than two. The ICMP_HOST_UNREACH error notification may be sent if no route was found. The ICMP_HOST_UNREACH error notification may be sent if the packet is for another host and the routing is disabled.
[in] | device_id | The source device identifier. |
[in] | packet | The received packet to be processed. |
EINVAL if the TTL is less than two.
EINVAL if the checksum is invalid.
EAFNOSUPPORT if the address family is not supported.
ENOENT if no route was found.
ENOENT if the packet is for another host and the routing is disabled.
static int ip_received_error_msg_local | ( | int | ip_phone, | |
device_id_t | device_id, | |||
packet_t * | packet, | |||
services_t | target, | |||
services_t | error | |||
) | [static] |
Notify the IP module about the received error notification packet.
[in] | ip_phone | The IP module phone used for (semi)remote calls. |
[in] | device_id | The device identifier. |
[in] | packet | The received packet or the received packet queue. |
[in] | target | The target internetwork module service to be delivered to. |
[in] | error | The packet error reporting service. Prefixes the received packet. |
static void ip_receiver | ( | ipc_callid_t | iid, | |
ipc_call_t * | icall | |||
) | [static] |
static int ip_register | ( | int | protocol, | |
services_t | service, | |||
int | phone, | |||
tl_received_msg_t | received_msg | |||
) | [static] |
Registers the transport layer protocol.
The traffic of this protocol will be supplied using either the receive function or IPC message.
[in] | protocol | The transport layer module protocol. |
[in] | service | The transport layer module service. |
[in] | phone | The transport layer module phone. |
[in] | received_msg | The receiving function. |
EINVAL if the protocol parameter and/or the service parameter is zero.
EINVAL if the phone parameter is not a positive number and the tl_receive_msg is NULL.
ENOMEM if there is not enough memory left.
static int ip_release_and_return | ( | packet_t * | packet, | |
int | result | |||
) | [static] |
static int ip_send_route | ( | packet_t * | packet, | |
ip_netif_t * | netif, | |||
ip_route_t * | route, | |||
in_addr_t * | src, | |||
in_addr_t | dest, | |||
services_t | error | |||
) | [static] |
Sends the packet or the packet queue via the specified route.
The ICMP_HOST_UNREACH error notification may be sent if route hardware destination address is found.
[in,out] | packet | The packet to be sent. |
[in] | netif | The target network interface. |
[in] | route | The target route. |
[in] | src | The source address. |
[in] | dest | The destination address. |
[in] | error | The error module service. |
Other error codes as defined for the arp_translate_req() function.
Other error codes as defined for the ip_prepare_packet() function.
static packet_t* ip_split_packet | ( | packet_t * | packet, | |
size_t | prefix, | |||
size_t | content, | |||
size_t | suffix, | |||
socklen_t | addr_len, | |||
services_t | error | |||
) | [static] |
Checks the packet queue lengths and fragments the packets if needed.
The ICMP_FRAG_NEEDED error notification may be sent if the packet needs to be fragmented and the fragmentation is not allowed.
[in,out] | packet | The packet or the packet queue to be checked. |
[in] | prefix | The minimum prefix size. |
[in] | content | The maximum content size. |
[in] | suffix | The minimum suffix size. |
[in] | addr_len | The minimum address length. |
[in] | error | The error module service. |
NULL if there are no packets left.
int main | ( | int | argc, | |
char * | argv[] | |||
) |