31,9 → 31,6 |
*/ |
|
/** @file |
* IP module implementation. |
* @see arp.h |
* \todo |
*/ |
|
#include <async.h> |
76,65 → 73,24 |
#include "ip_messages.h" |
#include "ip_module.h" |
|
/** Default IP version. |
*/ |
#define DEFAULT_IPV 4 |
|
/** Minimum IP packet content. |
*/ |
#define IP_MIN_CONTENT 576 |
|
/** ARP module name. |
*/ |
#define ARP_NAME "arp" |
|
/** ARP module filename. |
*/ |
#define ARP_FILENAME "/srv/arp" |
|
/** IP packet address length. |
*/ |
#define IP_ADDR sizeof( in_addr_t ) |
|
/** IP packet prefix length. |
*/ |
#define IP_PREFIX sizeof( ip_header_t ) |
|
/** IP packet suffix length. |
*/ |
#define IP_SUFFIX 0 |
|
/** IP packet maximum content length. |
*/ |
#define IP_MAX_CONTENT 65535 |
|
/** Returns the actual IP header length. |
* @param header The IP packet header. Input parameter. |
*/ |
#define IP_HEADER_LENGTH( header ) (( header )->ihl * 4u ) |
|
/** Returns the actual IP packet total length. |
* @param header The IP packet header. Input parameter. |
*/ |
#define IP_TOTAL_LENGTH( header ) ntohs(( header )->total_length ) |
|
/** Returns the actual IP packet data length. |
* @param header The IP packet header. Input parameter. |
*/ |
#define IP_HEADER_DATA_LENGTH( header ) ( IP_TOTAL_LENGTH( header ) - IP_HEADER_LENGTH( header )) |
|
/** Returns the IP packet header checksum. |
* @param header The IP packet header. Input parameter. |
*/ |
#define IP_HEADER_CHECKSUM( header ) ( htons( ip_checksum(( uint8_t * )( header ), IP_HEADER_LENGTH( header )))) |
|
/** IP header checksum value for computed zero checksum. |
* Zero is returned as 0xFFFF (not flipped) |
*/ |
//zero is returned as 0xFFFF (not flipped) |
#define IP_HEADER_CHECKSUM_ZERO 0xFFFFu |
|
/** IP global data. |
*/ |
ip_globals_t ip_globals; |
|
DEVICE_MAP_IMPLEMENT( ip_netifs, ip_netif_t ) |
143,39 → 99,9 |
|
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. |
* @returns EOK on success. |
* @returns ENOENT if device is not found. |
*/ |
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. |
* @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 ); |
|
int ip_mtu_changed_msg( device_id_t device_id, size_t mtu ); |
int ip_device_state_msg( int il_phone, device_id_t device_id, device_state_t state ); |
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. |
* @returns EOK on success. |
* @returns ENOTSUP if DHCP is configured. |
* @returns ENOTSUP if IPv6 is configured. |
* @returns EINVAL if any of the addresses is invalid. |
* @returns EINVAL if the used ARP module is not known. |
* @returns ENOMEM if there is not enough memory left. |
* @returns Other error codes as defined for the net_get_device_conf_req() function. |
* @returns Other error codes as defined for the bind_service() function. |
* @returns Other error codes as defined for the specific arp_device_req() function. |
* @returns Other error codes as defined for the nil_packet_size_req() function. |
*/ |
int ip_netif_initialize( ip_netif_ref ip_netif ); |
|
int ip_send_route( packet_t packet, ip_netif_ref netif, ip_route_ref route, in_addr_t * src, in_addr_t dest ); |
191,18 → 117,7 |
ip_route_ref ip_find_route( in_addr_t destination ); |
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. |
* @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. |
* @returns ENOENT if the device is not found in the cache. |
* @returns ENOENT if the protocol for the device is not found in the cache. |
* @returns ENOMEM if there is not enough memory left. |
*/ |
int ip_receive_message( device_id_t device_id, packet_t packet ); |
|
int ip_received_msg( device_id_t device_id, packet_t packet ); |
int ip_process_packet( device_id_t device_id, packet_t packet ); |
in_addr_t ip_get_destination( ip_header_ref header ); |
int ip_deliver_local( device_id_t device_id, packet_t packet, ip_header_ref header ); |
227,6 → 142,8 |
return ( ~ checksum ) ? ~ checksum : IP_HEADER_CHECKSUM_ZERO; |
} |
|
/** Initializes the module. |
*/ |
int ip_initialize( async_client_conn_t client_connection ){ |
ERROR_DECLARE; |
|
314,7 → 231,7 |
ip_route_ref route; |
in_addr_t gateway; |
|
ip_netif->arp = NULL; |
ip_netif->arp = 0; |
route = NULL; |
configuration = & names[ 0 ]; |
// get configuration |
406,7 → 323,7 |
return EOK; |
} |
|
int ip_mtu_changed_message( device_id_t device_id, size_t mtu ){ |
int ip_mtu_changed_msg( device_id_t device_id, size_t mtu ){ |
ip_netif_ref netif; |
|
fibril_rwlock_write_lock( & ip_globals.netifs_lock ); |
421,7 → 338,7 |
return EOK; |
} |
|
int ip_device_state_message( device_id_t device_id, device_state_t state ){ |
int ip_device_state_msg( int il_phone, device_id_t device_id, device_state_t state ){ |
// ERROR_DECLARE; |
|
/* measured_string_t address; |
701,10 → 618,10 |
ERROR_PROPAGATE( packet_translate( ip_globals.net_phone, & packet, IPC_GET_PACKET( call ))); |
return ip_send_msg( 0, IPC_GET_DEVICE( call ), packet, 0 ); |
case NET_IL_DEVICE_STATE: |
return ip_device_state_message( IPC_GET_DEVICE( call ), IPC_GET_STATE( call )); |
return ip_device_state_msg( 0, IPC_GET_DEVICE( call ), IPC_GET_STATE( call )); |
case NET_IL_RECEIVED: |
ERROR_PROPAGATE( packet_translate( ip_globals.net_phone, & packet, IPC_GET_PACKET( call ))); |
return ip_receive_message( IPC_GET_DEVICE( call ), packet ); |
return ip_received_msg( IPC_GET_DEVICE( call ), packet ); |
case NET_IP_ADD_ROUTE: |
return ip_add_route_req( 0, IPC_GET_DEVICE( call ), IP_GET_ADDRESS( call ), IP_GET_NETMASK( call ), IP_GET_GATEWAY( call )); |
case NET_IP_SET_GATEWAY: |
714,7 → 631,7 |
* answer_count = 3; |
return EOK; |
case NET_IL_MTU_CHANGED: |
return ip_mtu_changed_message( IPC_GET_DEVICE( call ), IPC_GET_MTU( call )); |
return ip_mtu_changed_msg( IPC_GET_DEVICE( call ), IPC_GET_MTU( call )); |
} |
return ENOTSUP; |
} |
985,7 → 902,7 |
last->header_checksum = 0; |
} |
|
int ip_receive_message( device_id_t device_id, packet_t packet ){ |
int ip_received_msg( device_id_t device_id, packet_t packet ){ |
packet_t next; |
|
do{ |