/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; |
} |
/branches/network/uspace/srv/net/nil/eth/eth.c |
---|
458,7 → 458,7 |
} |
suffix += sizeof( eth_fcs_t ); |
} |
if( ERROR_OCCURRED( packet_set_addr( packet, header->header.src, header->header.dest, ETH_ADDR )) |
if( ERROR_OCCURRED( packet_set_addr( packet, header->header.source_address, header->header.destination_address, ETH_ADDR )) |
|| ERROR_OCCURRED( packet_trim( packet, prefix, suffix ))){ |
return NULL; |
} |
598,9 → 598,9 |
header_dix = PACKET_PREFIX( packet, eth_header_t ); |
if( ! header_dix ) return ENOMEM; |
header_dix->ethertype = ( uint16_t ) ethertype; |
memcpy( header_dix->src, src_addr, ETH_ADDR ); |
memcpy( header_dix->dest, dest, ETH_ADDR ); |
src = & header_dix->dest[ 0 ]; |
memcpy( header_dix->source_address, src_addr, ETH_ADDR ); |
memcpy( header_dix->destination_address, dest, ETH_ADDR ); |
src = & header_dix->destination_address[ 0 ]; |
}else if( IS_8023_2_SNAP( flags )){ |
header = PACKET_PREFIX( packet, eth_header_ex_t ); |
if( ! header ) return ENOMEM; |
608,11 → 608,11 |
header->lsap.dsap = ( uint16_t ) ETH_LSAP_SNAP; |
header->lsap.ssap = header->lsap.dsap; |
header->lsap.ctrl = 0; |
for( i = 0; i < 3; ++ i ) header->snap.proto[ i ] = 0; |
for( i = 0; i < 3; ++ i ) header->snap.protocol[ i ] = 0; |
header->snap.ethertype = ( uint16_t ) ethertype; |
memcpy( header->header.src, src_addr, ETH_ADDR ); |
memcpy( header->header.dest, dest, ETH_ADDR ); |
src = & header->header.dest[ 0 ]; |
memcpy( header->header.source_address, src_addr, ETH_ADDR ); |
memcpy( header->header.destination_address, dest, ETH_ADDR ); |
src = & header->header.destination_address[ 0 ]; |
} |
if( IS_DUMMY( flags )){ |
fcs = PACKET_SUFFIX( packet, eth_fcs_t ); |
/branches/network/uspace/srv/net/nil/eth/eth_header.h |
---|
32,7 → 32,7 |
/** @file |
* Ethernet protocol header definitions. |
* Names according to the linux src/include/linux/ip.h header file. |
* Based on the IEEE~802.3-2005 |
*/ |
#ifndef __NET_ETH_HEADER_H__ |
124,7 → 124,7 |
struct eth_header_snap{ |
/** Protocol identifier or organization code. |
*/ |
uint8_t proto[ 3 ]; |
uint8_t protocol[ 3 ]; |
/** Ethernet protocol identifier in the network byte order (big endian). |
* @see ethernet_protocols.h |
*/ |
150,10 → 150,10 |
struct eth_header{ |
/** Destination host Ethernet address (MAC address). |
*/ |
uint8_t dest[ ETH_ADDR ]; |
uint8_t destination_address[ ETH_ADDR ]; |
/** Source host Ethernet address (MAC address). |
*/ |
uint8_t src[ ETH_ADDR ]; |
uint8_t source_address[ ETH_ADDR ]; |
/** Ethernet protocol identifier in the network byte order (big endian). |
* @see ethernet_protocols.h |
*/ |
/branches/network/uspace/srv/net/include/hardware.h |
---|
32,7 → 32,6 |
/** @file |
* Hardware types according to the on-line IANA - Address Resolution Protocol (ARP) Parameters - <http://www.iana.org/assignments/arp-parameters/arp-parameters.xml>, cited January 14 2009. |
* Names similar to the linux src/include/linux/if_arp.h header file. |
*/ |
#ifndef __NET_HW_TYPES_H__ |
/branches/network/uspace/srv/net/include/device.h |
---|
83,33 → 83,32 |
}; |
/** Device usage statistics. |
* Based on linux_kernel/include/linux/netdevice.h. |
*/ |
struct device_stats{ |
/** Total packets received. |
*/ |
unsigned long rx_packets; |
unsigned long receive_packets; |
/** Total packets transmitted. |
*/ |
unsigned long tx_packets; |
unsigned long send_packets; |
/** Total bytes received. |
*/ |
unsigned long rx_bytes; |
unsigned long receive_bytes; |
/** Total bytes transmitted. |
*/ |
unsigned long tx_bytes; |
unsigned long send_bytes; |
/** Bad packets received counter. |
*/ |
unsigned long rx_errors; |
unsigned long receive_errors; |
/** Packet transmition problems counter. |
*/ |
unsigned long tx_errors; |
unsigned long send_errors; |
/** No space in buffers counter. |
*/ |
unsigned long rx_dropped; |
unsigned long receive_dropped; |
/** No space available counter. |
*/ |
unsigned long tx_dropped; |
unsigned long send_dropped; |
/** Total multicast packets received. |
*/ |
unsigned long multicast; |
117,50 → 116,50 |
*/ |
unsigned long collisions; |
/* detailed rx_errors: */ |
/* detailed receive_errors: */ |
/** Received packet length error counter. |
*/ |
unsigned long rx_length_errors; |
unsigned long receive_length_errors; |
/** Receiver buffer overflow counter. |
*/ |
unsigned long rx_over_errors; |
unsigned long receive_over_errors; |
/** Received packet with crc error counter. |
*/ |
unsigned long rx_crc_errors; |
unsigned long receive_crc_errors; |
/** Received frame alignment error counter. |
*/ |
unsigned long rx_frame_errors; |
unsigned long receive_frame_errors; |
/** Receiver fifo overrun counter. |
*/ |
unsigned long rx_fifo_errors; |
unsigned long receive_fifo_errors; |
/** Receiver missed packet counter. |
*/ |
unsigned long rx_missed_errors; |
unsigned long receive_missed_errors; |
/* detailed tx_errors */ |
/* detailed send_errors */ |
/** Transmitter aborted counter. |
*/ |
unsigned long tx_aborted_errors; |
unsigned long send_aborted_errors; |
/** Transmitter carrier errors counter. |
*/ |
unsigned long tx_carrier_errors; |
unsigned long send_carrier_errors; |
/** Transmitter fifo overrun counter. |
*/ |
unsigned long tx_fifo_errors; |
unsigned long send_fifo_errors; |
/** Transmitter carrier errors counter. |
*/ |
unsigned long tx_heartbeat_errors; |
unsigned long send_heartbeat_errors; |
/** Transmitter window errors counter. |
*/ |
unsigned long tx_window_errors; |
unsigned long send_window_errors; |
/* for cslip etc */ |
/** Total compressed packets received. |
*/ |
unsigned long rx_compressed; |
unsigned long receive_compressed; |
/** Total compressed packet transmitted. |
*/ |
unsigned long tx_compressed; |
unsigned long send_compressed; |
}; |
#endif |
/branches/network/uspace/srv/net/include/socket_codes.h |
---|
43,6 → 43,7 |
/** @name Address families definitions |
*/ |
/*@{*/ |
/** Unspecified address family. |
*/ |
#define AF_UNSPEC 0 |
174,6 → 175,7 |
/** Maximum address family. |
*/ |
#define AF_MAX 34 |
/*@}*/ |
/** @name Protocol families definitions |
180,6 → 182,7 |
* Same as address families. |
*/ |
/*@{*/ |
/** Unspecified protocol family. |
*/ |
#define PF_UNSPEC AF_UNSPEC |
311,6 → 314,7 |
/** Maximum protocol family. |
*/ |
#define PF_MAX AF_MAX |
/*@}*/ |
/** @name Socket option levels definitions |
432,11 → 436,6 |
/*@}*/ |
// |
/* * IPX options. |
*/ |
//#define IPX_TYPE 1 |
/** Socket types. |
*/ |
typedef enum sock_type{ |
/branches/network/uspace/srv/net/include/icmp_codes.h |
---|
32,7 → 32,6 |
/** @file |
* ICMP types and codes according to the on-line IANA - ICMP Type Numbers - <http://http://www.iana.org/assignments/icmp-parameters>, cited September 14 2009. |
* Names according to the linux src/include/linux/icmp.h header file. |
*/ |
#ifndef __NET_ICMP_CODES_H__ |
/branches/network/uspace/srv/net/include/ip_protocols.h |
---|
32,7 → 32,6 |
/** @file |
* Internet protocol numbers according to the on-line IANA - Assigned Protocol numbers - <http://www.iana.org/assignments/protocol-numbers/protocol-numbers.xml>, cited January 14 2009. |
* Names according to the linux src/include/linux/in.h header file. |
*/ |
#ifndef __NET_IPPROTOCOLS_H__ |
/branches/network/uspace/srv/net/include/ethernet_protocols.h |
---|
32,7 → 32,6 |
/** @file |
* Ethernet protocol numbers according to the on-line IANA - Ethernet numbers - <http://www.iana.org/assignments/ethernet-numbers>, cited January 17 2009. |
* Names according to the linux src/include/linux/if_ether.h header file. |
*/ |
#ifndef __NET_ETHERNET_PROTOCOLS_H__ |
/branches/network/uspace/srv/net/include/socket.h |
---|
33,7 → 33,7 |
/** @file |
* Socket application program interface (API). |
* This is a part of the network application library. |
* Based on the linux src/include/linux/socket.h header file and BSD socket interface. |
* Based on the BSD socket interface. |
*/ |
#ifndef __NET_SOCKET_H__ |
/branches/network/uspace/srv/net/il/arp/arp_header.h |
---|
32,6 → 32,7 |
/** @file |
* ARP protocol header. |
* Based on the RFC~826. |
*/ |
#ifndef __NET_ARP_HEADER_H__ |
/branches/network/uspace/srv/net/il/arp/arp_oc.h |
---|
32,7 → 32,6 |
/** @file |
* ARP operation codes according to the on-line IANA - Address Resolution Protocol (ARP) Parameters - <http://www.iana.org/assignments/arp-parameters/arp-parameters.xml>, cited January 14 2009. |
* Names according to the linux src/include/linux/if_arp.h header file. |
*/ |
#ifndef __NET_ARP_ARPOP_H__ |
/branches/network/uspace/srv/net/il/ip/ip_header.h |
---|
32,7 → 32,7 |
/** @file |
* IP header and options definitions. |
* Names according to the linux src/include/linux/ip.h header file. |
* Based on the RFC~791. |
*/ |
#ifndef __NET_IP_HEADER_H__ |
41,6 → 41,36 |
#include <byteorder.h> |
#include <sys/types.h> |
/** Returns the actual IP header length. |
* @param header The IP packet header. Input parameter. |
*/ |
#define IP_HEADER_LENGTH( header ) (( header )->header_length * 4u ) |
/** Returns the actual IP header length. |
* @param header The IP packet header. Input parameter. |
*/ |
#define IP_COMPUTE_HEADER_LENGTH( length ) (( uint8_t ) (( length ) / 4u )) |
/** Returns the actual IP packet total length. |
* @param header The IP packet header. Input parameter. |
*/ |
#define IP_TOTAL_LENGTH( header ) ntohs(( header )->total_length ) |
/** Returns the actual IP packet data length. |
* @param header The IP packet header. Input parameter. |
*/ |
#define IP_HEADER_DATA_LENGTH( header ) ( IP_TOTAL_LENGTH( header ) - IP_HEADER_LENGTH( header )) |
/** Returns the IP packet header checksum. |
* @param header The IP packet header. Input parameter. |
*/ |
#define IP_HEADER_CHECKSUM( header ) ( htons( ip_checksum(( uint8_t * )( header ), IP_HEADER_LENGTH( header )))) |
/** Returns the fragment offest. |
* @param length The prefixed data total length. Input parameter. |
*/ |
#define IP_COMPUTE_FRAGMENT_OFFSET( length ) (( length ) / 8 ) |
/** Type definition of the internet header. |
* @see ip_header |
*/ |
62,12 → 92,12 |
/** Internet Header Length is the length of the internet header in 32~bit words, and thus points to the beginning of the data. |
* Note that the minimum value for a~correct header is~5. |
*/ |
uint8_t ihl:4; |
uint8_t header_length:4; |
#else |
/** Internet Header Length is the length of the internet header in 32~bit words, and thus points to the beginning of the data. |
* Note that the minimum value for a~correct header is~5. |
*/ |
uint8_t ihl:4; |
uint8_t header_length:4; |
/** The Version field indicates the format of the internet header. |
*/ |
uint8_t version:4; |
200,14 → 230,6 |
/*@}*/ |
/* |
#define IPOPT_OPTVAL 0 |
#define IPOPT_OLEN 1 |
#define IPOPT_OFFSET 2 |
#define IPOPT_MINOFF 4 |
#define MAX_IPOPTLEN 40 |
*/ |
/** Type definition of the internet version 4 pseudo header. |
* @see ipv4_pseudo_header |
*/ |
227,9 → 249,10 |
/** The destination address. |
*/ |
uint32_t destination_address; |
/** Zero byte. |
/** Reserved byte. |
* Must be zero. |
*/ |
uint8_t zero; |
uint8_t reserved; |
/** This field indicates the next level protocol used in the data portion of the internet datagram. |
*/ |
uint8_t protocol; |
/branches/network/uspace/srv/net/il/ip/ip_client.c |
---|
61,7 → 61,7 |
if( ! data ) return ENOMEM; |
while( padding -- ) data[ sizeof( ip_header_t ) + padding ] = IPOPT_NOOP; |
header = ( ip_header_ref ) data; |
header->ihl = ( uint8_t ) ( sizeof( ip_header_t ) + ipopt_length ) / 4; |
header->header_length = IP_COMPUTE_HEADER_LENGTH( sizeof( ip_header_t ) + ipopt_length ); |
header->ttl = ttl ? (( ttl <= MAXTTL ) ? ttl : MAXTTL ) : IPDEFTTL; |
header->tos = tos; |
header->protocol = protocol; |
82,10 → 82,10 |
if( tos ) * tos = header->tos; |
if( dont_fragment ) * dont_fragment = header->flags & IPFLAG_DONT_FRAGMENT; |
if( ipopt_length ){ |
* ipopt_length = header->ihl * 4 - sizeof( ip_header_t ); |
* ipopt_length = IP_HEADER_LENGTH( header ) - sizeof( ip_header_t ); |
return sizeof( ip_header_t ); |
}else{ |
return header->ihl * 4; |
return IP_HEADER_LENGTH( header ); |
} |
} |
97,7 → 97,7 |
|| ( packet_get_data_length( packet ) < sizeof( ip_header_t ))){ |
return 0; |
} |
return header->ihl * 4u; |
return IP_HEADER_LENGTH( header ); |
} |
int ip_client_set_pseudo_header_data_length( ip_pseudo_header_ref header, size_t headerlen, size_t data_length ){ |
/branches/network/uspace/srv/net/il/ip/ip.c |
---|
122,31 → 122,6 |
*/ |
#define IP_MAX_CONTENT 65535 |
/** Returns the actual IP header length. |
* @param header The IP packet header. Input parameter. |
*/ |
#define IP_HEADER_LENGTH( header ) (( header )->ihl * 4u ) |
/** Returns the actual IP packet total length. |
* @param header The IP packet header. Input parameter. |
*/ |
#define IP_TOTAL_LENGTH( header ) ntohs(( header )->total_length ) |
/** Returns the actual IP packet data length. |
* @param header The IP packet header. Input parameter. |
*/ |
#define IP_HEADER_DATA_LENGTH( header ) ( IP_TOTAL_LENGTH( header ) - IP_HEADER_LENGTH( header )) |
/** Returns the IP packet header checksum. |
* @param header The IP packet header. Input parameter. |
*/ |
#define IP_HEADER_CHECKSUM( header ) ( htons( ip_checksum(( uint8_t * )( header ), IP_HEADER_LENGTH( header )))) |
/** Returns the fragment offest. |
* @param length The prefixed data total length. Input parameter. |
*/ |
#define IP_FRAGMENT_OFFSET( length ) (( length ) / 8 ) |
/** The IP localhost address. |
*/ |
#define IPV4_LOCALHOST_ADDRESS htonl(( 127 << 24 ) + 1 ) |
706,7 → 681,7 |
memcpy( middle_header, last_header, IP_HEADER_LENGTH( last_header )); |
header->flags |= IPFLAG_MORE_FRAGMENTS; |
middle_header->total_length = htons( packet_get_data_length( next )); |
middle_header->fragment_offset = IP_FRAGMENT_OFFSET( length ); |
middle_header->fragment_offset = IP_COMPUTE_FRAGMENT_OFFSET( length ); |
middle_header->header_checksum = IP_HEADER_CHECKSUM( middle_header ); |
if( destination ){ |
ERROR_PROPAGATE( packet_set_addr( next, NULL, ( uint8_t * ) destination->value, CONVERT_SIZE( char, uint8_t, destination->length ))); |
718,7 → 693,7 |
if( ! middle_header ) return ENOMEM; |
memcpy( middle_header, last_header, IP_HEADER_LENGTH( last_header )); |
middle_header->total_length = htons( packet_get_data_length( next )); |
middle_header->fragment_offset = IP_FRAGMENT_OFFSET( length ); |
middle_header->fragment_offset = IP_COMPUTE_FRAGMENT_OFFSET( length ); |
middle_header->header_checksum = IP_HEADER_CHECKSUM( middle_header ); |
if( destination ){ |
ERROR_PROPAGATE( packet_set_addr( next, NULL, ( uint8_t * ) destination->value, CONVERT_SIZE( char, uint8_t, destination->length ))); |
1033,7 → 1008,7 |
length = sizeof( ip_header_t ); |
next = sizeof( ip_header_t ); |
// process all ip options |
while( next < first->ihl ){ |
while( next < first->header_length ){ |
option = ( ip_option_ref ) ((( uint8_t * ) first ) + next ); |
// skip end or noop |
if(( option->type == IPOPT_END ) || ( option->type == IPOPT_NOOP )){ |
1051,9 → 1026,9 |
// align 4 byte boundary |
if( length % 4 ){ |
bzero((( uint8_t * ) last ) + length, 4 - ( length % 4 )); |
last->ihl = length / 4 + 1; |
last->header_length = length / 4 + 1; |
}else{ |
last->ihl = length / 4; |
last->header_length = length / 4; |
} |
last->header_checksum = 0; |
} |
/branches/network/uspace/srv/net/netif/dp8390/dp8390_module.c |
---|
106,18 → 106,18 |
ERROR_PROPAGATE( find_device( device_id, & device )); |
de_stat = & (( dpeth_t * ) device->specific )->de_stat; |
null_device_stats( stats ); |
stats->rx_errors = de_stat->ets_recvErr; |
stats->tx_errors = de_stat->ets_sendErr; |
stats->rx_crc_errors = de_stat->ets_CRCerr; |
stats->rx_frame_errors = de_stat->ets_frameAll; |
stats->rx_missed_errors = de_stat->ets_missedP; |
stats->rx_packets = de_stat->ets_packetR; |
stats->tx_packets = de_stat->ets_packetT; |
stats->receive_errors = de_stat->ets_recvErr; |
stats->send_errors = de_stat->ets_sendErr; |
stats->receive_crc_errors = de_stat->ets_CRCerr; |
stats->receive_frame_errors = de_stat->ets_frameAll; |
stats->receive_missed_errors = de_stat->ets_missedP; |
stats->receive_packets = de_stat->ets_packetR; |
stats->send_packets = de_stat->ets_packetT; |
stats->collisions = de_stat->ets_collision; |
stats->tx_aborted_errors = de_stat->ets_transAb; |
stats->tx_carrier_errors = de_stat->ets_carrSense; |
stats->tx_heartbeat_errors = de_stat->ets_CDheartbeat; |
stats->tx_window_errors = de_stat->ets_OWC; |
stats->send_aborted_errors = de_stat->ets_transAb; |
stats->send_carrier_errors = de_stat->ets_carrSense; |
stats->send_heartbeat_errors = de_stat->ets_CDheartbeat; |
stats->send_window_errors = de_stat->ets_OWC; |
return EOK; |
} |
/branches/network/uspace/srv/net/netif/lo/lo.c |
---|
188,11 → 188,11 |
if( device->state != NETIF_ACTIVE ) return EPERM; |
next = packet; |
do{ |
++ (( device_stats_ref ) device->specific )->tx_packets; |
++ (( device_stats_ref ) device->specific )->rx_packets; |
++ (( device_stats_ref ) device->specific )->send_packets; |
++ (( device_stats_ref ) device->specific )->receive_packets; |
length = packet_get_data_length( next ); |
(( device_stats_ref ) device->specific )->tx_bytes += length; |
(( device_stats_ref ) device->specific )->rx_bytes += length; |
(( device_stats_ref ) device->specific )->send_bytes += length; |
(( device_stats_ref ) device->specific )->receive_bytes += length; |
next = pq_next( next ); |
}while( next ); |
phone = device->nil_phone; |