Subversion Repositories HelenOS

Compare Revisions

Ignore whitespace Rev 4727 → Rev 4728

/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;
}