33,7 → 33,6 |
/** @file |
* IP module implementation. |
* @see arp.h |
* \todo |
*/ |
|
#include <async.h> |
137,8 → 136,8 |
GENERIC_FIELD_IMPLEMENT( ip_routes, ip_route_t ) |
|
/** Updates the device content length according to the new MTU value. |
* @param device_id The device identifier. Input parameter. |
* @param mtu The new mtu value. Input parameter. |
* @param[in] device_id The device identifier. |
* @param[in] mtu The new mtu value. |
* @returns EOK on success. |
* @returns ENOENT if device is not found. |
*/ |
145,19 → 144,30 |
int ip_mtu_changed_message( device_id_t device_id, size_t mtu ); |
|
/** Updates the device state. |
* @param device_id The device identifier. Input parameter. |
* @param state The new state value. Input parameter. |
* @param[in] device_id The device identifier. |
* @param[in] state The new state value. |
* @returns EOK on success. |
* @returns ENOENT if device is not found. |
*/ |
int ip_device_state_message( device_id_t device_id, device_state_t state ); |
|
/** Registers the transport layer protocol. |
* The traffic of this protocol will be supplied using either the receive function or IPC message. |
* @param[in] protocol The transport layer module protocol. |
* @param[in] service The transport layer module service. |
* @param[in] phone The transport layer module phone. |
* @param[in] tl_received_msg The receiving function. |
* @returns EOK on success. |
* @returns EINVAL if the protocol parameter and/or the service parameter is zero (0). |
* @returns EINVAL if the phone parameter is not a positive number and the tl_receive_msg is NULL. |
* @returns ENOMEM if there is not enough memory left. |
*/ |
int ip_register( int protocol, services_t service, int phone, tl_received_msg_t tl_received_msg ); |
|
/** 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. |
* @param ip_netif Network interface specific data. Input/output parameter. |
* @param[in,out] ip_netif Network interface specific data. |
* @returns EOK on success. |
* @returns ENOTSUP if DHCP is configured. |
* @returns ENOTSUP if IPv6 is configured. |
171,22 → 181,126 |
*/ |
int ip_netif_initialize( ip_netif_ref ip_netif ); |
|
/** 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. |
* @param[in,out] packet The packet to be sent. |
* @param[in] netif The target network interface. |
* @param[in] route The target route. |
* @param[in] src The source address. |
* @param[in] dest The destination address. |
* @param[in] error The error module service. |
* @returns EOK on success. |
* @returns Other error codes as defined for the arp_translate_req() function. |
* @returns Other error codes as defined for the ip_prepare_packet() function. |
*/ |
int ip_send_route( packet_t packet, ip_netif_ref netif, ip_route_ref route, in_addr_t * src, in_addr_t dest, services_t error ); |
|
/** 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. |
* @param[in] source The source address. |
* @param[in] dest The destination address. |
* @param[in,out] packet The packet to be sent. |
* @param[in] destination The destination hardware address. |
* @returns EOK on success. |
* @returns EINVAL if the packet is too small to contain the IP header. |
* @returns EINVAL if the packet is too long than the IP allows. |
* @returns ENOMEM if there is not enough memory left. |
* @returns Other error codes as defined for the packet_set_addr() function. |
*/ |
int ip_prepare_packet( in_addr_t * source, in_addr_t dest, packet_t packet, measured_string_ref destination ); |
|
/** 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. |
* @param[in,out] packet The packet or the packet queue to be checked. |
* @param[in] prefix The minimum prefix size. |
* @param[in] content The maximum content size. |
* @param[in] suffix The minimum suffix size. |
* @param[in] addr_len The minimum address length. |
* @param[in] error The error module service. |
* @returns The packet or the packet queue of the allowed length. |
* @returns NULL if there are no packets left. |
*/ |
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 length and fragments it if needed. |
* The new fragments are queued before the original packet. |
* @param[in,out] packet The packet to be checked. |
* @param[in] length The maximum packet length. |
* @param[in] prefix The minimum prefix size. |
* @param[in] suffix The minimum suffix size. |
* @param[in] addr_len The minimum address length. |
* @returns EOK on success. |
* @returns EINVAL if the packet_get_addr() function fails. |
* @returns EINVAL if the packet does not contain the IP header. |
* @returns EPERM if the packet needs to be fragmented and the fragmentation is not allowed. |
* @returns ENOMEM if there is not enough memory left. |
* @returns ENOMEM if there is no packet available. |
* @returns ENOMEM if the packet is too small to contain the IP header. |
* @returns Other error codes as defined for the packet_trim() function. |
* @returns Other error codes as defined for the ip_create_middle_header() function. |
* @returns Other error codes as defined for the ip_fragment_packet_data() function. |
*/ |
int ip_fragment_packet( packet_t packet, size_t length, size_t prefix, size_t suffix, socklen_t addr_len ); |
|
/** Fragments the packet from the end. |
* @param[in] packet The packet to be fragmented. |
* @param[in,out] new_packet The new packet fragment. |
* @param[in,out] header The original packet header. |
* @param[in,out] new_header The new packet fragment header. |
* @param[in] length The new fragment length. |
* @param[in] src The source address. |
* @param[in] dest The destiantion address. |
* @param[in] addrlen The address length. |
* @returns EOK on success. |
* @returns ENOMEM if the target packet is too small. |
* @returns Other error codes as defined for the packet_set_addr() function. |
* @returns Other error codes as defined for the pq_insert_after() function. |
*/ |
int ip_fragment_packet_data( packet_t packet, packet_t new_packet, ip_header_ref header, ip_header_ref new_header, size_t length, const struct sockaddr * src, const struct sockaddr * dest, socklen_t addrlen ); |
|
/** Prefixes a middle fragment header based on the last fragment header to the packet. |
* @param[in] packet The packet to be prefixed. |
* @param[in] last The last header to be copied. |
* @returns The prefixed middle header. |
* @returns NULL on error. |
*/ |
ip_header_ref ip_create_middle_header( packet_t packet, ip_header_ref last ); |
|
/** Copies the fragment header. |
* Copies only the header itself and relevant IP options. |
* @param[out] last The created header. |
* @param[in] first The original header to be copied. |
*/ |
void ip_create_last_header( ip_header_ref last, ip_header_ref first ); |
|
/** Returns the network interface's IP address. |
* @param[in] netif The network interface. |
* @returns The IP address. |
* @returns NULL if no IP address was found. |
*/ |
in_addr_t * ip_netif_address( ip_netif_ref netif ); |
|
/** Searches all network interfaces if there is a suitable route. |
* @param[in] destination The destination address. |
* @returns The found route. |
* @returns NULL if no route was found. |
*/ |
ip_route_ref ip_find_route( in_addr_t destination ); |
|
/** Searches the network interfaces if there is a suitable route. |
* @param[in] netif The network interface to be searched for routes. May be NULL. |
* @param[in] destination The destination address. |
* @returns The found route. |
* @returns NULL if no route was found. |
*/ |
ip_route_ref ip_netif_find_route( ip_netif_ref netif, in_addr_t destination ); |
|
/** Processes the received IP packet. |
* @param device_id The source device identifier. Input parameter. |
* @param packet The received packet. Input/output parameter. |
/** Processes the received IP packet or the packet queue one by one. |
* The packet is either passed to another module or released on error. |
* @param[in] device_id The source device identifier. |
* @param[in,out] packet The received packet. |
* @returns EOK on success and the packet is no longer needed. |
* @returns EINVAL if the packet is too small to carry the IP packet. |
* @returns EINVAL if the received address lengths differs from the registered values. |
196,14 → 310,84 |
*/ |
int ip_receive_message( device_id_t device_id, packet_t packet ); |
|
/** 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 (2). |
* 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. |
* @param[in] device_id The source device identifier. |
* @param[in] packet The received packet to be processed. |
* @returns EOK on success. |
* @returns EINVAL if the TTL is less than two (2). |
* @returns EINVAL if the checksum is invalid. |
* @returns EAFNOSUPPORT if the address family is not supported. |
* @returns ENOENT if no route was found. |
* @returns ENOENT if the packet is for another host and the routing is disabled. |
*/ |
int ip_process_packet( device_id_t device_id, packet_t packet ); |
|
/** Returns the packet destination address from the IP header. |
* @param[in] header The packet IP header to be read. |
* @returns The packet destination address. |
*/ |
in_addr_t ip_get_destination( ip_header_ref header ); |
|
/** 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. |
* @param[in] device_id The source device identifier. |
* @param[in] packet The packet to be delivered. |
* @param[in] header The first packet IP header. May be NULL. |
* @param[in] error The packet error service. |
* @returns EOK on success. |
* @returns ENOTSUP if the packet is a fragment. |
* @returns EAFNOSUPPORT if the address family is not supported. |
* @returns ENOENT if the target protocol is not found. |
* @returns Other error codes as defined for the packet_set_addr() function. |
* @returns Other error codes as defined for the packet_trim() function. |
* @returns Other error codes as defined for the protocol specific tl_received_msg function. |
*/ |
int ip_deliver_local( device_id_t device_id, packet_t packet, ip_header_ref header, services_t error ); |
|
/** Prepares the ICMP notification packet. |
* Releases additional packets and keeps only the first one. |
* All packets is released on error. |
* @param[in] error The packet error service. |
* @param[in] packet The packet or the packet queue to be reported as faulty. |
* @param[in] header The first packet IP header. May be NULL. |
* @returns The found ICMP phone. |
* @returns EINVAL if the error parameter is set. |
* @returns EINVAL if the ICMP phone is not found. |
* @returns EINVAL if the ip_prepare_icmp() fails. |
*/ |
int ip_prepare_icmp_and_get_phone( services_t error, packet_t packet, ip_header_ref header ); |
|
/** Returns the ICMP phone. |
* Searches the registered protocols. |
* @returns The found ICMP phone. |
* @returns ENOENT if the ICMP is not registered. |
*/ |
int ip_get_icmp_phone( void ); |
|
/** Prepares the ICMP notification packet. |
* Releases additional packets and keeps only the first one. |
* @param[in] packet The packet or the packet queue to be reported as faulty. |
* @param[in] header The first packet IP header. May be NULL. |
* @returns EOK on success. |
* @returns EINVAL if there are no data in the packet. |
* @returns EINVAL if the packet is a fragment. |
* @returns ENOMEM if the packet is too short to contain the IP header. |
* @returns EAFNOSUPPORT if the address family is not supported. |
* @returns Other error codes as defined for the packet_set_addr(). |
*/ |
int ip_prepare_icmp( packet_t packet, ip_header_ref header ); |
|
/** Releases the packet and returns the result. |
* @param[in] packet The packet queue to be released. |
* @param[in] result The result to be returned. |
* @return The result parameter. |
*/ |
int ip_release_and_return( packet_t packet, int result ); |
|
int ip_initialize( async_client_conn_t client_connection ){ |
1050,7 → 1234,7 |
dest = ( struct sockaddr * ) & dest_in; |
break; |
*/ default: |
return EAFNOSUPPORT; |
return ip_release_and_return( packet, EAFNOSUPPORT ); |
} |
ERROR_PROPAGATE( packet_set_addr( packet, NULL, ( uint8_t * ) & addr, addrlen )); |
route = ip_find_route( dest ); |