Internet Protocol (IP) Service
[Inter-networking layer]


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_tip_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_tip_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_tip_netif_address (ip_netif_t *netif)
 Returns the network interface's IP address.
static ip_route_tip_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_tip_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 Documentation

typedef struct ip_globals ip_globals_t

Type definition of the IP global data.

See also:
ip_globals

Definition at line 52 of file ip.h.

typedef struct ip_netif ip_netif_t

Type definition of the IP network interface specific data.

See also:
ip_netif

Definition at line 57 of file ip.h.

typedef struct ip_proto ip_proto_t

Type definition of the IP protocol specific data.

See also:
ip_proto

Definition at line 62 of file ip.h.

typedef struct ip_route ip_route_t

Type definition of the IP route specific data.

See also:
ip_route

Definition at line 67 of file ip.h.


Function Documentation

DEVICE_MAP_DECLARE ( ip_netifs  ,
ip_netif_t   
)

IP network interfaces.

Maps devices to the IP network interface specific data.

See also:
device.h

GENERIC_FIELD_DECLARE ( ip_routes  ,
ip_route_t   
)

IP routing table.

See also:
generic_field.h

int il_initialize ( int  net_phone  ) 

Module initialization.

This has to be implemented in user code.

Parameters:
[in] net_phone Networking module phone.
Returns:
EOK on success.

Other error codes as defined for each specific module initialize function.

Definition at line 245 of file ip.c.

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.

Parameters:
[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.
Returns:
EOK on success.

ENOTSUP if the message is not known.

See also:
ip_interface.h

il_remote.h

IS_NET_IP_MESSAGE()

Definition at line 1900 of file ip.c.

INT_MAP_DECLARE ( ip_protos  ,
ip_proto_t   
)

IP registered protocols.

Maps protocols to the IP protocol specific data.

See also:
int_map.h

static void ip_create_last_header ( ip_header_t last,
ip_header_t first 
) [static]

Copies the fragment header.

Copies only the header itself and relevant IP options.

Parameters:
[out] last The created header.
[in] first The original header to be copied.

Definition at line 625 of file ip.c.

static ip_header_t* ip_create_middle_header ( packet_t packet,
ip_header_t last 
) [static]

Prefixes a middle fragment header based on the last fragment header to the packet.

Parameters:
[in] packet The packet to be prefixed.
[in] last The last header to be copied.
Returns:
The prefixed middle header.

NULL on error.

Definition at line 860 of file ip.c.

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.

Parameters:
[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.
Returns:
EOK on success.

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.

Definition at line 1311 of file ip.c.

static int ip_device_state_message ( device_id_t  device_id,
device_state_t  state 
) [static]

Updates the device state.

Parameters:
[in] device_id The device identifier.
[in] state The new state value.
Returns:
EOK on success.

ENOENT if device is not found.

Definition at line 1257 of file ip.c.

static ip_route_t* ip_find_route ( in_addr_t  destination  )  [static]

Searches all network interfaces if there is a suitable route.

Parameters:
[in] destination The destination address.
Returns:
The found route.

NULL if no route was found.

Definition at line 584 of file ip.c.

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.

Parameters:
[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.
Returns:
EOK on success.

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.

Definition at line 900 of file ip.c.

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.

Parameters:
[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.
Returns:
EOK on success.

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.

Definition at line 816 of file ip.c.

static in_addr_t ip_get_destination ( ip_header_t header  )  [static]

Returns the packet destination address from the IP header.

Parameters:
[in] header The packet IP header to be read.
Returns:
The packet destination address.

Definition at line 1281 of file ip.c.

static int ip_get_icmp_phone ( void   )  [static]

Returns the ICMP phone.

Searches the registered protocols.

Returns:
The found ICMP phone.

ENOENT if the ICMP is not registered.

Definition at line 143 of file ip.c.

static int ip_mtu_changed_message ( device_id_t  device_id,
size_t  mtu 
) [static]

Updates the device content length according to the new MTU value.

Parameters:
[in] device_id The device identifier.
[in] mtu The new mtu value.
Returns:
EOK on success.

ENOENT if device is not found.

Definition at line 1571 of file ip.c.

static in_addr_t* ip_netif_address ( ip_netif_t netif  )  [static]

Returns the network interface's IP address.

Parameters:
[in] netif The network interface.
Returns:
The IP address.

NULL if no IP address was found.

Definition at line 610 of file ip.c.

static ip_route_t* ip_netif_find_route ( ip_netif_t netif,
in_addr_t  destination 
) [static]

Searches the network interfaces if there is a suitable route.

Parameters:
[in] netif The network interface to be searched for routes. May be NULL.
[in] destination The destination address.
Returns:
The found route.

NULL if no route was found.

Definition at line 557 of file ip.c.

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.

Parameters:
[in,out] ip_netif Network interface specific data.
Returns:
EOK on success.

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.

Definition at line 301 of file ip.c.

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.

Parameters:
[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.
Returns:
EOK on success.

Definition at line 1513 of file ip.c.

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.

Parameters:
[in] packet The packet or the packet queue to be reported as faulty.
[in] header The first packet IP header. May be NULL.
Returns:
EOK on success.

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().

Definition at line 171 of file ip.c.

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.

Parameters:
[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.
Returns:
The found ICMP phone.

EINVAL if the error parameter is set.

EINVAL if the ICMP phone is not found.

EINVAL if the ip_prepare_icmp() fails.

Definition at line 234 of file ip.c.

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.

Parameters:
[in] source The source address.
[in] dest The destination address.
[in,out] packet The packet to be sent.
[in] destination The destination hardware address.
Returns:
EOK on success.

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.

Definition at line 684 of file ip.c.

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.

Parameters:
[in] device_id The source device identifier.
[in] packet The received packet to be processed.
Returns:
EOK on success.

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.

Definition at line 1412 of file ip.c.

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.

Parameters:
[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.
Returns:
EOK on success.

Definition at line 1758 of file ip.c.

static void ip_receiver ( ipc_callid_t  iid,
ipc_call_t icall 
) [static]

Process IPC messages from the registered device driver modules.

Parameters:
[in] iid Message identifier.
[in,out] icall Message parameters.

Definition at line 1595 of file ip.c.

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.

Parameters:
[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.
Returns:
EOK on success.

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.

Definition at line 1653 of file ip.c.

static int ip_release_and_return ( packet_t packet,
int  result 
) [static]

Releases the packet and returns the result.

Parameters:
[in] packet The packet queue to be released.
[in] result The result to be returned.
Returns:
The result parameter.

Definition at line 130 of file ip.c.

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.

Parameters:
[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.
Returns:
EOK on success.

Other error codes as defined for the arp_translate_req() function.

Other error codes as defined for the ip_prepare_packet() function.

Definition at line 1077 of file ip.c.

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.

Parameters:
[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.
Returns:
The packet or the packet queue of the allowed length.

NULL if there are no packets left.

Definition at line 1008 of file ip.c.

int main ( int  argc,
char *  argv[] 
)

Main entry point.

Parameters:
[in] argc Nmber of arguments in argv vector (ignored).
[in] argv Cmdline argument vector (ignored).
Returns:
Error code.
Driver debug level is set here.

Definition at line 1993 of file ip.c.


Generated on Thu Jun 2 07:45:55 2011 for HelenOS/USB by  doxygen 1.4.7