Rev 4589 | Rev 4702 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
| Rev 4589 | Rev 4695 | ||
|---|---|---|---|
| Line 97... | Line 97... | ||
| 97 | 97 | ||
| 98 | INT_MAP_IMPLEMENT( ip_protos, ip_proto_t ) |
98 | INT_MAP_IMPLEMENT( ip_protos, ip_proto_t ) |
| 99 | 99 | ||
| 100 | GENERIC_FIELD_IMPLEMENT( ip_routes, ip_route_t ) |
100 | GENERIC_FIELD_IMPLEMENT( ip_routes, ip_route_t ) |
| 101 | 101 | ||
| - | 102 | int ip_mtu_changed_msg( device_id_t device_id, size_t mtu ); |
|
| 102 | int ip_device_state_msg( int il_phone, device_id_t device_id, device_state_t state ); |
103 | int ip_device_state_msg( int il_phone, device_id_t device_id, device_state_t state ); |
| 103 | int ip_register( int protocol, services_t service, int phone, tl_received_msg_t tl_received_msg ); |
104 | int ip_register( int protocol, services_t service, int phone, tl_received_msg_t tl_received_msg ); |
| 104 | int ip_netif_initialize( ip_netif_ref ip_netif ); |
105 | int ip_netif_initialize( ip_netif_ref ip_netif ); |
| 105 | 106 | ||
| 106 | int ip_send_route( packet_t packet, ip_netif_ref netif, ip_route_ref route, in_addr_t * src, in_addr_t dest ); |
107 | int ip_send_route( packet_t packet, ip_netif_ref netif, ip_route_ref route, in_addr_t * src, in_addr_t dest ); |
| Line 220... | Line 221... | ||
| 220 | } |
221 | } |
| 221 | 222 | ||
| 222 | int ip_netif_initialize( ip_netif_ref ip_netif ){ |
223 | int ip_netif_initialize( ip_netif_ref ip_netif ){ |
| 223 | ERROR_DECLARE; |
224 | ERROR_DECLARE; |
| 224 | 225 | ||
| 225 | measured_string_t names[ 9 ] = {{ "IPV", 3 }, { "IP_CONFIG", 9 }, { "IP_ADDR", 7 }, { "NETMASK", 7 }, { "GATEWAY", 7 }, { "BROADCAST", 9 }, { "DNS1", 4 }, { "DNS2", 4 }, { "ARP", 3 }}; |
226 | measured_string_t names[] = {{ "IPV", 3 }, { "IP_CONFIG", 9 }, { "IP_ADDR", 7 }, { "NETMASK", 7 }, { "GATEWAY", 7 }, { "BROADCAST", 9 }, { "DNS1", 4 }, { "DNS2", 4 }, { "ARP", 3 }, { "IP_ROUTING", 10 }}; |
| 226 | measured_string_ref configuration; |
227 | measured_string_ref configuration; |
| 227 | size_t count = sizeof( names ) / sizeof( measured_string_t ); |
228 | size_t count = sizeof( names ) / sizeof( measured_string_t ); |
| 228 | char * data; |
229 | char * data; |
| 229 | int index; |
230 | int index; |
| 230 | ip_route_ref route; |
231 | ip_route_ref route; |
| Line 284... | Line 285... | ||
| 284 | return EINVAL; |
285 | return EINVAL; |
| 285 | } |
286 | } |
| 286 | }else{ |
287 | }else{ |
| 287 | ip_netif->arp = NULL; |
288 | ip_netif->arp = NULL; |
| 288 | } |
289 | } |
| - | 290 | ip_netif->routing = configuration[ 9 ].value && ( configuration[ 9 ].value[ 0 ] == 'y' ); |
|
| 289 | net_free_settings( configuration, data ); |
291 | net_free_settings( configuration, data ); |
| 290 | } |
292 | } |
| 291 | ip_netif->phone = bind_service( ip_netif->service, ( ipcarg_t ) ip_netif->device_id, SERVICE_IP, 0, ip_globals.client_connection ); |
293 | ip_netif->phone = bind_service( ip_netif->service, ( ipcarg_t ) ip_netif->device_id, SERVICE_IP, 0, ip_globals.client_connection ); |
| 292 | if( ip_netif->phone < 0 ){ |
294 | if( ip_netif->phone < 0 ){ |
| 293 | printf( "Failed to contact the nil service %d\n", ip_netif->service ); |
295 | printf( "Failed to contact the nil service %d\n", ip_netif->service ); |
| Line 319... | Line 321... | ||
| 319 | ip_globals.gateway.netif = ip_netif; |
321 | ip_globals.gateway.netif = ip_netif; |
| 320 | } |
322 | } |
| 321 | return EOK; |
323 | return EOK; |
| 322 | } |
324 | } |
| 323 | 325 | ||
| - | 326 | int ip_mtu_changed_msg( device_id_t device_id, size_t mtu ){ |
|
| - | 327 | ip_netif_ref netif; |
|
| - | 328 | ||
| - | 329 | fibril_rwlock_write_lock( & ip_globals.netifs_lock ); |
|
| - | 330 | netif = ip_netifs_find( & ip_globals.netifs, device_id ); |
|
| - | 331 | if( ! netif ){ |
|
| - | 332 | fibril_rwlock_write_unlock( & ip_globals.netifs_lock ); |
|
| - | 333 | return ENOENT; |
|
| - | 334 | } |
|
| - | 335 | netif->content = mtu; |
|
| - | 336 | printf( "ip - device %d changed mtu to %d\n\n", device_id, mtu ); |
|
| - | 337 | fibril_rwlock_write_unlock( & ip_globals.netifs_lock ); |
|
| - | 338 | return EOK; |
|
| - | 339 | } |
|
| - | 340 | ||
| 324 | int ip_device_state_msg( int il_phone, device_id_t device_id, device_state_t state ){ |
341 | int ip_device_state_msg( int il_phone, device_id_t device_id, device_state_t state ){ |
| 325 | // ERROR_DECLARE; |
342 | // ERROR_DECLARE; |
| 326 | 343 | ||
| 327 | /* measured_string_t address; |
344 | /* measured_string_t address; |
| 328 | measured_string_ref translation; |
345 | measured_string_ref translation; |
| Line 582... | Line 599... | ||
| 582 | // unnecessary for all protocols |
599 | // unnecessary for all protocols |
| 583 | header->header_checksum = IP_HEADER_CHECKSUM( header ); |
600 | header->header_checksum = IP_HEADER_CHECKSUM( header ); |
| 584 | return EOK; |
601 | return EOK; |
| 585 | } |
602 | } |
| 586 | 603 | ||
| 587 | - | ||
| 588 | - | ||
| 589 | int ip_message( ipc_callid_t callid, ipc_call_t * call, ipc_call_t * answer, int * answer_count ){ |
604 | int ip_message( ipc_callid_t callid, ipc_call_t * call, ipc_call_t * answer, int * answer_count ){ |
| 590 | ERROR_DECLARE; |
605 | ERROR_DECLARE; |
| 591 | 606 | ||
| 592 | packet_t packet; |
607 | packet_t packet; |
| 593 | 608 | ||
| Line 601... | Line 616... | ||
| 601 | return ip_register( IL_GET_PROTO( call ), IL_GET_SERVICE( call ), IPC_GET_PHONE( call ), NULL ); |
616 | return ip_register( IL_GET_PROTO( call ), IL_GET_SERVICE( call ), IPC_GET_PHONE( call ), NULL ); |
| 602 | case NET_IL_SEND: |
617 | case NET_IL_SEND: |
| 603 | ERROR_PROPAGATE( packet_translate( ip_globals.net_phone, & packet, IPC_GET_PACKET( call ))); |
618 | ERROR_PROPAGATE( packet_translate( ip_globals.net_phone, & packet, IPC_GET_PACKET( call ))); |
| 604 | return ip_send_msg( 0, IPC_GET_DEVICE( call ), packet, 0 ); |
619 | return ip_send_msg( 0, IPC_GET_DEVICE( call ), packet, 0 ); |
| 605 | case NET_IL_DEVICE_STATE: |
620 | case NET_IL_DEVICE_STATE: |
| 606 | case NET_NIL_DEVICE_STATE: |
- | |
| 607 | return ip_device_state_msg( 0, IPC_GET_DEVICE( call ), IPC_GET_STATE( call )); |
621 | return ip_device_state_msg( 0, IPC_GET_DEVICE( call ), IPC_GET_STATE( call )); |
| 608 | case NET_IL_RECEIVED: |
622 | case NET_IL_RECEIVED: |
| 609 | case NET_NIL_RECEIVED: |
- | |
| 610 | ERROR_PROPAGATE( packet_translate( ip_globals.net_phone, & packet, IPC_GET_PACKET( call ))); |
623 | ERROR_PROPAGATE( packet_translate( ip_globals.net_phone, & packet, IPC_GET_PACKET( call ))); |
| 611 | return ip_received_msg( IPC_GET_DEVICE( call ), packet ); |
624 | return ip_received_msg( IPC_GET_DEVICE( call ), packet ); |
| 612 | case NET_IP_ADD_ROUTE: |
625 | case NET_IP_ADD_ROUTE: |
| 613 | return ip_add_route_req( 0, IPC_GET_DEVICE( call ), IP_GET_ADDRESS( call ), IP_GET_NETMASK( call ), IP_GET_GATEWAY( call )); |
626 | return ip_add_route_req( 0, IPC_GET_DEVICE( call ), IP_GET_ADDRESS( call ), IP_GET_NETMASK( call ), IP_GET_GATEWAY( call )); |
| 614 | case NET_IP_SET_GATEWAY: |
627 | case NET_IP_SET_GATEWAY: |
| 615 | return ip_set_gateway_req( 0, IPC_GET_DEVICE( call ), IP_GET_GATEWAY( call )); |
628 | return ip_set_gateway_req( 0, IPC_GET_DEVICE( call ), IP_GET_GATEWAY( call )); |
| 616 | case NET_IL_PACKET_SPACE: |
629 | case NET_IL_PACKET_SPACE: |
| 617 | ERROR_PROPAGATE( ip_packet_size_req( 0, IPC_GET_DEVICE( call ), IPC_SET_ADDR( answer ), IPC_SET_PREFIX( answer ), IPC_SET_CONTENT( answer ), IPC_SET_SUFFIX( answer ))); |
630 | ERROR_PROPAGATE( ip_packet_size_req( 0, IPC_GET_DEVICE( call ), IPC_SET_ADDR( answer ), IPC_SET_PREFIX( answer ), IPC_SET_CONTENT( answer ), IPC_SET_SUFFIX( answer ))); |
| 618 | * answer_count = 3; |
631 | * answer_count = 3; |
| 619 | return EOK; |
632 | return EOK; |
| - | 633 | case NET_IL_MTU_CHANGED: |
|
| - | 634 | return ip_mtu_changed_msg( IPC_GET_DEVICE( call ), IPC_GET_MTU( call )); |
|
| 620 | } |
635 | } |
| 621 | return ENOTSUP; |
636 | return ENOTSUP; |
| 622 | } |
637 | } |
| 623 | 638 | ||
| 624 | int ip_packet_size_req( int ip_phone, device_id_t device_id, size_t * addr_len, size_t * prefix, size_t * content, size_t * suffix ){ |
639 | int ip_packet_size_req( int ip_phone, device_id_t device_id, size_t * addr_len, size_t * prefix, size_t * content, size_t * suffix ){ |
| Line 924... | Line 939... | ||
| 924 | if( ! route ) return ENOENT; |
939 | if( ! route ) return ENOENT; |
| 925 | if( route->address.s_addr == dest.s_addr ){ |
940 | if( route->address.s_addr == dest.s_addr ){ |
| 926 | // local delivery |
941 | // local delivery |
| 927 | return ip_deliver_local( device_id, packet, header ); |
942 | return ip_deliver_local( device_id, packet, header ); |
| 928 | }else{ |
943 | }else{ |
| - | 944 | // only if routing enabled |
|
| - | 945 | if( route->netif->routing ){ |
|
| 929 | return ip_send_route( packet, route->netif, route, NULL, dest ); |
946 | return ip_send_route( packet, route->netif, route, NULL, dest ); |
| - | 947 | } |
|
| - | 948 | else |
|
| - | 949 | { |
|
| - | 950 | // TODO icmp unreachable? |
|
| - | 951 | return ENOENT; |
|
| - | 952 | } |
|
| 930 | } |
953 | } |
| 931 | } |
954 | } |
| 932 | 955 | ||
| 933 | int ip_deliver_local( device_id_t device_id, packet_t packet, ip_header_ref header ){ |
956 | int ip_deliver_local( device_id_t device_id, packet_t packet, ip_header_ref header ){ |
| 934 | ERROR_DECLARE; |
957 | ERROR_DECLARE; |