Rev 4351 | Rev 4396 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 4351 | Rev 4394 | ||
---|---|---|---|
Line 123... | Line 123... | ||
123 | /** Processes the received ARP packet. |
123 | /** Processes the received ARP packet. |
124 | * Updates the source hardware address if the source entry exists or the packet is targeted to my protocol address. |
124 | * Updates the source hardware address if the source entry exists or the packet is targeted to my protocol address. |
125 | * Responses to the ARP request if the packet is the ARP request and is targeted to my address. |
125 | * Responses to the ARP request if the packet is the ARP request and is targeted to my address. |
126 | * @param device_id The source device identifier. Input parameter. |
126 | * @param device_id The source device identifier. Input parameter. |
127 | * @param packet The received packet. Input/output parameter. |
127 | * @param packet The received packet. Input/output parameter. |
128 | * @returns EOK on success. |
128 | * @returns EOK on success and the packet is no longer needed. |
- | 129 | * @returns 1 on success and the packet has been reused. |
|
129 | * @returns EINVAL if the packet is too small to carry the ARP packet. |
130 | * @returns EINVAL if the packet is too small to carry the ARP packet. |
130 | * @returns EINVAL if the received address lengths differs from the registered values. |
131 | * @returns EINVAL if the received address lengths differs from the registered values. |
131 | * @returns ENOENT if the device is not found in the cache. |
132 | * @returns ENOENT if the device is not found in the cache. |
132 | * @returns ENOENT if the protocol for the device is not found in the cache. |
133 | * @returns ENOENT if the protocol for the device is not found in the cache. |
133 | * @returns ENOMEM if there is not enough memory left. |
134 | * @returns ENOMEM if there is not enough memory left. |
Line 368... | Line 369... | ||
368 | length = 8 + ( CONVERT_SIZE( char, uint8_t, proto->addr->length ) + CONVERT_SIZE( char, uint8_t, device->addr->length )) * 2; |
369 | length = 8 + ( CONVERT_SIZE( char, uint8_t, proto->addr->length ) + CONVERT_SIZE( char, uint8_t, device->addr->length )) * 2; |
369 | if( length > device->content ) return NULL; |
370 | if( length > device->content ) return NULL; |
370 | packet = packet_get_4( arp_globals.net_phone, device->addr_len, device->prefix, length, device->suffix ); |
371 | packet = packet_get_4( arp_globals.net_phone, device->addr_len, device->prefix, length, device->suffix ); |
371 | if( ! packet ) return NULL; |
372 | if( ! packet ) return NULL; |
372 | header = ( arp_header_ref ) packet_suffix( packet, length ); |
373 | header = ( arp_header_ref ) packet_suffix( packet, length ); |
- | 374 | if( ! header ){ |
|
- | 375 | pq_release( packet ); |
|
- | 376 | return NULL; |
|
- | 377 | } |
|
373 | header->hardware = htons( device->hardware ); |
378 | header->hardware = htons( device->hardware ); |
374 | header->hardware_length = device->addr->length; |
379 | header->hardware_length = device->addr->length; |
375 | header->protocol = htons( protocol_map( device->service, protocol )); |
380 | header->protocol = htons( protocol_map( device->service, protocol )); |
376 | header->protocol_length = proto->addr->length; |
381 | header->protocol_length = proto->addr->length; |
377 | header->operation = htons( ARPOP_REQUEST ); |
382 | header->operation = htons( ARPOP_REQUEST ); |
Line 381... | Line 386... | ||
381 | memcpy((( uint8_t * ) header ) + length, proto->addr->value, proto->addr->length ); |
386 | memcpy((( uint8_t * ) header ) + length, proto->addr->value, proto->addr->length ); |
382 | length += proto->addr->length; |
387 | length += proto->addr->length; |
383 | bzero((( uint8_t * ) header ) + length, device->addr->length ); |
388 | bzero((( uint8_t * ) header ) + length, device->addr->length ); |
384 | length += device->addr->length; |
389 | length += device->addr->length; |
385 | memcpy((( uint8_t * ) header ) + length, target->value, target->length ); |
390 | memcpy((( uint8_t * ) header ) + length, target->value, target->length ); |
386 | packet_set_addr( packet, ( uint8_t * ) device->addr->value, ( uint8_t * ) device->broadcast_addr->value, CONVERT_SIZE( char, uint8_t, device->addr->length )); |
391 | if( packet_set_addr( packet, ( uint8_t * ) device->addr->value, ( uint8_t * ) device->broadcast_addr->value, CONVERT_SIZE( char, uint8_t, device->addr->length )) != EOK ){ |
- | 392 | pq_release( packet ); |
|
- | 393 | return NULL; |
|
- | 394 | } |
|
387 | nil_send_msg( device->phone, device_id, packet, SERVICE_ARP ); |
395 | nil_send_msg( device->phone, device_id, packet, SERVICE_ARP ); |
388 | return NULL; |
396 | return NULL; |
389 | } |
397 | } |
390 | 398 | ||
391 | int arp_receive_message( device_id_t device_id, packet_t packet ){ |
399 | int arp_receive_message( device_id_t device_id, packet_t packet ){ |
Line 439... | Line 447... | ||
439 | header->operation = htons( ARPOP_REPLY ); |
447 | header->operation = htons( ARPOP_REPLY ); |
440 | memcpy( des_proto, src_proto, header->protocol_length ); |
448 | memcpy( des_proto, src_proto, header->protocol_length ); |
441 | memcpy( src_proto, proto->addr->value, header->protocol_length ); |
449 | memcpy( src_proto, proto->addr->value, header->protocol_length ); |
442 | memcpy( src_hw, device->addr->value, device->addr_len ); |
450 | memcpy( src_hw, device->addr->value, device->addr_len ); |
443 | memcpy( des_hw, hw_source->value, header->hardware_length ); |
451 | memcpy( des_hw, hw_source->value, header->hardware_length ); |
444 | packet_set_addr( packet, src_hw, des_hw, header->hardware_length ); |
452 | ERROR_PROPAGATE( packet_set_addr( packet, src_hw, des_hw, header->hardware_length )); |
445 | nil_send_msg( device->phone, device_id, packet, SERVICE_ARP ); |
453 | nil_send_msg( device->phone, device_id, packet, SERVICE_ARP ); |
446 | }else{ |
454 | return 1; |
447 | pq_release( arp_globals.net_phone, packet_get_id( packet )); |
- | |
448 | } |
455 | } |
449 | } |
456 | } |
450 | return EOK; |
457 | return EOK; |
451 | } |
458 | } |
452 | 459 | ||
Line 474... | Line 481... | ||
474 | 481 | ||
475 | measured_string_ref address; |
482 | measured_string_ref address; |
476 | measured_string_ref translation; |
483 | measured_string_ref translation; |
477 | char * data; |
484 | char * data; |
478 | packet_t packet; |
485 | packet_t packet; |
- | 486 | packet_t next; |
|
479 | 487 | ||
480 | // printf( "message %d - %d\n", IPC_GET_METHOD( * call ), NET_ARP_FIRST ); |
488 | // printf( "message %d - %d\n", IPC_GET_METHOD( * call ), NET_ARP_FIRST ); |
481 | * answer_count = 0; |
489 | * answer_count = 0; |
482 | switch( IPC_GET_METHOD( * call )){ |
490 | switch( IPC_GET_METHOD( * call )){ |
483 | case IPC_M_PHONE_HUNGUP: |
491 | case IPC_M_PHONE_HUNGUP: |
Line 510... | Line 518... | ||
510 | // do nothing - keep the cache |
518 | // do nothing - keep the cache |
511 | return EOK; |
519 | return EOK; |
512 | case NET_IL_RECEIVED: |
520 | case NET_IL_RECEIVED: |
513 | if( ! ERROR_OCCURRED( packet_translate( arp_globals.net_phone, & packet, IPC_GET_PACKET( call )))){ |
521 | if( ! ERROR_OCCURRED( packet_translate( arp_globals.net_phone, & packet, IPC_GET_PACKET( call )))){ |
514 | rwlock_read_lock( & arp_globals.lock ); |
522 | rwlock_read_lock( & arp_globals.lock ); |
- | 523 | do{ |
|
- | 524 | next = pq_next( packet ); |
|
- | 525 | packet_detach( packet ); |
|
515 | ERROR_CODE = arp_receive_message( IPC_GET_DEVICE( call ), packet ); |
526 | ERROR_CODE = arp_receive_message( IPC_GET_DEVICE( call ), packet ); |
- | 527 | if( ERROR_CODE != 1 ) pq_release( arp_globals.net_phone, packet_get_id( packet )); |
|
- | 528 | packet = next; |
|
- | 529 | }while( packet ); |
|
516 | rwlock_read_unlock( & arp_globals.lock ); |
530 | rwlock_read_unlock( & arp_globals.lock ); |
517 | } |
531 | } |
518 | return ERROR_CODE; |
532 | return ERROR_CODE; |
519 | } |
533 | } |
520 | return ENOTSUP; |
534 | return ENOTSUP; |