Subversion Repositories HelenOS

Compare Revisions

Ignore whitespace Rev 4727 → Rev 4728

/branches/network/uspace/srv/net/tl/icmp/icmp_header.h
32,7 → 32,7
 
/** @file
* ICMP header definition.
* Names according to the linux src/include/linux/icmp.h header file.
* Based on the RFC~792.
*/
 
#ifndef __NET_ICMP_HEADER_H__
58,10 → 58,10
struct icmp_echo{
/** Message idintifier.
*/
icmp_param_t id;
icmp_param_t identifier;
/** Message sequence number.
*/
icmp_param_t sequence;
icmp_param_t sequence_number;
} __attribute__ ((packed));
 
/** Type definition of the internet control message header.
77,14 → 77,15
/** Internet control message header.
*/
struct icmp_header{
/** Specifies the type of the message.
/** The type of the message.
*/
uint8_t type;
/** Contains the error code for the datagram reported by this ICMP message.
/** The error code for the datagram reported by the ICMP message.
* The interpretation is dependent on the message type.
*/
uint8_t code;
/** Contains the checksum for the ICMP message starting with the ICMP Type field.
/** The checksum is the 16-bit ones's complement of the one's complement sum of the ICMP message starting with the ICMP Type.
* For computing the checksum, the checksum field should be zero.
* If the checksum does not match the contents, the datagram is discarded.
*/
uint16_t checksum;
100,9 → 101,10
/** Fragmentation needed specific data.
*/
struct{
/** Unused field.
/** Reserved field.
* Must be zero.
*/
icmp_param_t _unused;
icmp_param_t reserved;
/** Proposed MTU.
*/
icmp_param_t mtu;
113,9 → 115,10
/** Problem pointer.
*/
icmp_param_t pointer;
/** Unused field.
/** Reserved field.
* Must be zero.
*/
icmp_param_t _unused;
icmp_param_t reserved;
} param;
} un;
} __attribute__ ((packed));
/branches/network/uspace/srv/net/tl/icmp/icmp.c
283,11 → 283,11
if( ! echo_data ){
res = ENOENT;
}else{
res = icmp_echo( echo_data->id, echo_data->sequence, size, timeout, ttl, tos, dont_fragment, addr, addrlen );
if( echo_data->sequence < MAX_UINT16 ){
++ echo_data->sequence;
res = icmp_echo( echo_data->identifier, echo_data->sequence_number, size, timeout, ttl, tos, dont_fragment, addr, addrlen );
if( echo_data->sequence_number < MAX_UINT16 ){
++ echo_data->sequence_number;
}else{
echo_data->sequence = 0;
echo_data->sequence_number = 0;
}
}
fibril_rwlock_write_unlock( & icmp_globals.lock );
366,8 → 366,8
return icmp_release_and_return( packet, ENOMEM );
}
bzero( header, sizeof( * header ));
header->un.echo.id = id;
header->un.echo.sequence = sequence;
header->un.echo.identifier = id;
header->un.echo.sequence_number = sequence;
 
// prepare the reply and the reply timeout structures
reply_timeout = malloc( sizeof( * reply_timeout ));
379,7 → 379,7
free( reply_timeout );
return icmp_release_and_return( packet, ENOMEM );
}
reply_timeout->reply_key = ICMP_GET_REPLY_KEY( header->un.echo.id, header->un.echo.sequence );
reply_timeout->reply_key = ICMP_GET_REPLY_KEY( header->un.echo.identifier, header->un.echo.sequence_number );
// timeout in microseconds
reply_timeout->timeout = timeout * 1000;
fibril_mutex_initialize( & reply->mutex );
511,7 → 511,7
fibril_rwlock_write_unlock( & icmp_globals.lock );
return index;
}else{
id = echo_data->id;
id = echo_data->identifier;
fibril_rwlock_write_unlock( & icmp_globals.lock );
// return the echo data identifier as the ICMP phone
return id;
668,7 → 668,7
icmp_reply_ref reply;
 
// compute the reply key
reply_key = ICMP_GET_REPLY_KEY( header->un.echo.id, header->un.echo.sequence );
reply_key = ICMP_GET_REPLY_KEY( header->un.echo.identifier, header->un.echo.sequence_number );
pq_release( icmp_globals.net_phone, packet_get_id( packet ));
// lock the globals
fibril_rwlock_write_lock( & icmp_globals.lock );
710,7 → 710,7
ERROR_DECLARE;
 
bool keep_on_going = true;
fibril_rwlock_t lock;
// fibril_rwlock_t lock;
ipc_call_t answer;
int answer_count;
size_t length;
724,7 → 724,7
*/
ipc_answer_0( callid, EOK );
 
fibril_rwlock_initialize( & lock );
// fibril_rwlock_initialize( & lock );
 
echo_data = ( icmp_echo_ref ) malloc( sizeof( * echo_data ));
if( ! echo_data ) return ENOMEM;
748,7 → 748,7
ERROR_CODE = EOK;
break;
case NET_ICMP_ECHO:
fibril_rwlock_write_lock( & lock );
// fibril_rwlock_write_lock( & lock );
if( ! ipc_data_write_receive( & data_callid, & length )){
ERROR_CODE = EINVAL;
}else{
758,18 → 758,18
}else{
if( ! ERROR_OCCURRED( ipc_data_write_finalize( data_callid, addr, length ))){
fibril_rwlock_write_lock( & icmp_globals.lock );
ERROR_CODE = icmp_echo( echo_data->id, echo_data->sequence, ICMP_GET_SIZE( call ), ICMP_GET_TIMEOUT( call ), ICMP_GET_TTL( call ), ICMP_GET_TOS( call ), ICMP_GET_DONT_FRAGMENT( call ), addr, ( socklen_t ) length );
ERROR_CODE = icmp_echo( echo_data->identifier, echo_data->sequence_number, ICMP_GET_SIZE( call ), ICMP_GET_TIMEOUT( call ), ICMP_GET_TTL( call ), ICMP_GET_TOS( call ), ICMP_GET_DONT_FRAGMENT( call ), addr, ( socklen_t ) length );
fibril_rwlock_write_unlock( & icmp_globals.lock );
free( addr );
if( echo_data->sequence < MAX_UINT16 ){
++ echo_data->sequence;
if( echo_data->sequence_number < MAX_UINT16 ){
++ echo_data->sequence_number;
}else{
echo_data->sequence = 0;
echo_data->sequence_number = 0;
}
}
}
}
fibril_rwlock_write_unlock( & lock );
// fibril_rwlock_write_unlock( & lock );
break;
default:
ERROR_CODE = icmp_process_message( & call );
780,7 → 780,7
 
// release the identifier
fibril_rwlock_write_lock( & icmp_globals.lock );
icmp_echo_data_exclude( & icmp_globals.echo_data, echo_data->id );
icmp_echo_data_exclude( & icmp_globals.echo_data, echo_data->identifier );
fibril_rwlock_write_unlock( & icmp_globals.lock );
return EOK;
}
845,8 → 845,8
break;
}
}while( icmp_echo_data_find( & icmp_globals.echo_data, index ) != NULL );
echo_data->id = index;
echo_data->sequence = 0;
echo_data->identifier = index;
echo_data->sequence_number = 0;
return icmp_echo_data_add( & icmp_globals.echo_data, index, echo_data );
}
 
/branches/network/uspace/srv/net/tl/udp/udp_header.h
32,7 → 32,7
 
/** @file
* UDP header definition.
* Names according to the linux src/include/linux/udp.h header file.
* Based on the RFC~768.
*/
 
#ifndef __NET_UDP_HEADER_H__
56,14 → 56,14
/** Source Port is an optional field, when meaningful, it indicates the port of the sending process, and may be assumed to be the port to which a reply should be addressed in the absence of any other information.
* If not used, a value of zero is inserted.
*/
uint16_t source;
uint16_t source_port;
/** Destination port has a meaning within the context of a particular internet destination address.
*/
uint16_t dest;
uint16_t destination_port;
/** Length is the length in octets of this user datagram including this header and the data.
* This means the minimum value of the length is eight.
*/
uint16_t len;
uint16_t total_length;
/** Checksum is the 16-bit one's complement of the one's complement sum of a pseudo header of information from the IP header, the UDP header, and the data, padded with zero octets at the end (if necessary) to make a multiple of two octets.
* The pseudo header conceptually prefixed to the UDP header contains the source address, the destination address, the protocol, and the UDP length.
* This information gives protection against misrouted datagrams.
70,7 → 70,7
* If the computed checksum is zero, it is transmitted as all ones (the equivalent in one's complement arithmetic).
* An all zero transmitted checksum value means that the transmitter generated no checksum (for debugging or for higher level protocols that don't care).
*/
uint16_t check;
uint16_t checksum;
} __attribute__ ((packed));
 
#endif
/branches/network/uspace/srv/net/tl/udp/udp.c
271,7 → 271,7
// get udp header
header = ( udp_header_ref )( data + offset );
// find the destination socket
socket = socket_ports_find( & udp_globals.sockets, ntohs( header->dest ));
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 );
return EADDRNOTAVAIL;
281,9 → 281,9
// count the received packet fragments
next_packet = packet;
fragments = 0;
total_length = ntohs( header->len );
total_length = ntohs( header->total_length );
// compute header checksum if set
if( header->check && ( ! error )){
if( header->checksum && ( ! error )){
result = packet_get_addr( packet, ( uint8_t ** ) & src, ( uint8_t ** ) & dest );
if( result <= 0 ){
return udp_release_and_return( packet, result );
296,7 → 296,7
free( ip_header );
}
}else{
header->check = 0;
header->checksum = 0;
checksum = 0;
}
do{
310,7 → 310,7
return udp_release_and_return( packet, ERROR_CODE );
}
// add partial checksum if set
if( header->check ){
if( header->checksum ){
checksum = compute_checksum( checksum, packet_get_data( packet ), packet_get_data_length( packet ));
}
// relese the rest of the packet fragments
325,16 → 325,16
}
total_length -= length;
// add partial checksum if set
if( header->check ){
if( header->checksum ){
checksum = compute_checksum( checksum, packet_get_data( packet ), packet_get_data_length( packet ));
}
}while(( next_packet = pq_next( next_packet )) && ( total_length > 0 ));
// check checksum
if( header->check ){
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->check, flip_checksum( compact_checksum( checksum )));
printf("udp check failed %x => %x\n", header->checksum, flip_checksum( compact_checksum( checksum )));
return udp_release_and_return( packet, EINVAL );
}
}
536,10 → 536,10
}
}
// set the udp header
header->source = htons( socket->port );
header->dest = htons( dest_port );
header->len = htons( total_length + sizeof( udp_header_t ));
header->check = 0;
header->source_port = htons( socket->port );
header->destination_port = htons( dest_port );
header->total_length = htons( total_length + sizeof( udp_header_t ));
header->checksum = 0;
if( udp_globals.checksum_computing ){
if( ERROR_OCCURRED( ip_get_route_req( udp_globals.ip_phone, IPPROTO_UDP, addr, addrlen, & device_id, & ip_header, & headerlen ))){
return udp_release_and_return( packet, ERROR_CODE );
554,7 → 554,7
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, ( uint8_t * ) header, sizeof( * header ));
header->check = htons( flip_checksum( compact_checksum( checksum )));
header->checksum = htons( flip_checksum( compact_checksum( checksum )));
free( ip_header );
}else{
device_id = -1;
600,7 → 600,7
 
// set the source address port
result = packet_get_addr( packet, ( uint8_t ** ) & addr, NULL );
if( ERROR_OCCURRED( tl_set_address_port( addr, result, ntohs( header->source )))){
if( ERROR_OCCURRED( tl_set_address_port( addr, result, ntohs( header->source_port )))){
pq_release( udp_globals.net_phone, packet_id );
return ERROR_CODE;
}