243,7 → 243,6 |
size_t length; |
size_t offset; |
int result; |
uint8_t * data; |
udp_header_ref header; |
socket_core_ref * socket; |
packet_t next_packet; |
260,14 → 259,13 |
if( error ){ |
switch( error ){ |
case SERVICE_ICMP: |
// ignore error |
// length = icmp_client_header_length( packet ); |
// process error |
// TODO remove debug dump |
// length = icmp_client_header_length( packet ); |
result = icmp_client_process_packet( packet, & type, & code, NULL, NULL ); |
if( result < 0 ){ |
return udp_release_and_return( packet, result ); |
} |
printf( "ICMP error %d (%d) in packet %d\n", type, code, packet_get_id( packet ) ); |
length = ( size_t ) result; |
if( ERROR_OCCURRED( packet_trim( packet, length, 0 ))){ |
return udp_release_and_return( packet, ERROR_CODE ); |
291,22 → 289,26 |
if( length < sizeof( udp_header_t ) + offset ){ |
return udp_release_and_return( packet, NO_DATA ); |
} |
data = packet_get_data( packet ); |
if( ! data ){ |
|
// trim all but UDP header |
if( ERROR_OCCURRED( packet_trim( packet, offset, 0 ))){ |
return udp_release_and_return( packet, ERROR_CODE ); |
} |
|
// get udp header |
header = ( udp_header_ref ) packet_get_data( packet ); |
if( ! header ){ |
return udp_release_and_return( packet, NO_DATA ); |
} |
// get udp header |
header = ( udp_header_ref )( data + offset ); |
// find the destination socket |
socket = socket_ports_find( & udp_globals.sockets, ntohs( header->destination_port )); |
if( ! socket ){ |
tl_send_icmp_port_unreachable( udp_globals.net_phone, udp_globals.icmp_phone, packet, error ); |
if( tl_prepare_icmp_packet( udp_globals.net_phone, udp_globals.icmp_phone, packet, error ) == EOK ){ |
icmp_destination_unreachable_msg( udp_globals.icmp_phone, ICMP_PORT_UNREACH, 0, packet ); |
} |
return EADDRNOTAVAIL; |
} |
|
// trim after successful processing to be able to send an ICMP error message! |
ERROR_PROPAGATE( packet_trim( packet, offset, 0 )); |
|
// count the received packet fragments |
next_packet = packet; |
fragments = 0; |
363,12 → 365,13 |
// check checksum |
if( header->checksum ){ |
if( flip_checksum( compact_checksum( checksum ))){ |
// TODO checksum error ICMP? |
// TODO remove debug dump |
printf("udp check failed %x => %x\n", header->checksum, flip_checksum( compact_checksum( checksum ))); |
return udp_release_and_return( packet, EINVAL ); |
if( tl_prepare_icmp_packet( udp_globals.net_phone, udp_globals.icmp_phone, packet, error ) == EOK ){ |
// checksum error ICMP |
icmp_parameter_problem_msg( udp_globals.icmp_phone, ICMP_PARAM_POINTER, (( size_t ) (( void * ) & header->checksum )) - (( size_t ) (( void * ) header )), packet ); |
} |
return EINVAL; |
} |
} |
|
// queue the received packet |
if( ERROR_OCCURRED( dyn_fifo_push( &( ** socket ).received, packet_get_id( packet ), SOCKET_MAX_RECEIVED_SIZE ))){ |
436,6 → 439,7 |
// fibril_rwlock_write_lock( & lock ); |
res = socket_create( & local_sockets, app_phone, NULL, SOCKET_SET_SOCKET_ID( answer )); |
// fibril_rwlock_write_unlock( & lock ); |
// TODO max fragment size |
* SOCKET_SET_DATA_FRAGMENT_SIZE( answer ) = MAX_UDP_FRAGMENT_SIZE; |
* SOCKET_SET_HEADER_SIZE( answer ) = sizeof( udp_header_t ); |
answer_count = 3; |
582,11 → 586,7 |
free( ip_header ); |
return udp_release_and_return( packet, ERROR_CODE ); |
} |
/*// TODO remove debug dump: |
uint8_t * data; |
data = ip_header; |
printf( "ip_header:\tlength\t= %d\n\tdata\t= %.2hhX %.2hhX %.2hhX %.2hhX:%.2hhX %.2hhX %.2hhX %.2hhX:%.2hhX %.2hhX %.2hhX %.2hhX\n", headerlen, data[ 0 ], data[ 1 ], data[ 2 ], data[ 3 ], data[ 4 ], data[ 5 ], data[ 6 ], data[ 7 ], data[ 8 ], data[ 9 ], data[ 10 ], data[ 11 ] ); |
*/ checksum = compute_checksum( checksum, ip_header, headerlen ); |
checksum = compute_checksum( checksum, ip_header, headerlen ); |
checksum = compute_checksum( checksum, ( uint8_t * ) header, sizeof( * header )); |
header->checksum = htons( flip_checksum( compact_checksum( checksum ))); |
free( ip_header ); |