Subversion Repositories HelenOS

Compare Revisions

Ignore whitespace Rev 4742 → Rev 4743

/branches/network/uspace/srv/net/tl/tcp/tcp_header.h
32,7 → 32,7
 
/** @file
* TCP header definition.
* Names according to the linux src/include/linux/tcp.h header file.
* Based on the RFC~793.
*/
 
#ifndef __NET_TCP_HEADER_H__
40,6 → 40,16
 
#include <sys/types.h>
 
/** Returns the actual TCP header length.
* @param header The TCP packet header. Input parameter.
*/
#define TCP_HEADER_LENGTH( header ) (( header )->header_length * 4u )
 
/** Returns the actual TCP header length.
* @param header The TCP packet header. Input parameter.
*/
#define TCP_COMPUTE_HEADER_LENGTH( length ) (( uint8_t ) (( length ) / 4u ))
 
/** Type definition of the transmission datagram header.
* @see tcp_header
*/
50,105 → 60,162
*/
typedef tcp_header_t * tcp_header_ref;
 
/** Type definition of the transmission datagram header option.
* @see tcp_option
*/
typedef struct tcp_option tcp_option_t;
 
/** Type definition of the transmission datagram header option pointer.
* @see tcp_option
*/
typedef tcp_option_t * tcp_option_ref;
 
/** Type definition of the Maximum segment size TCP option.
* @see ...
*/
typedef struct tcp_max_segment_size_option tcp_max_segment_size_option_t;
 
/** Type definition of the Maximum segment size TCP option pointer.
* @see tcp_max_segment_size_option
*/
typedef tcp_max_segment_size_option_t * tcp_max_segment_size_option_ref;
 
/** Transmission datagram header.
*/
struct tcp_header{
/** The 16-bit source port number, used by the receiver to reply.
/** The source port number.
*/
uint16_t source;
/** The 16-bit destination port number.
uint16_t source_port;
/** The destination port number.
*/
uint16_t dest;
/** The sequence number of the first data byte in this segment.
* If the SYN control bit is set, the sequence number is the initial sequence number (n) and the first data byte is n+1.
uint16_t destination_port;
/** The sequence number of the first data octet in this segment (except when SYN is present).
* If SYN is present the sequence number is the initial sequence number (ISN) and the first data octet is ISN+1.
*/
uint32_t seq;
/** If the ACK control bit is set, this field contains the value of the next sequence number that the receiver is expecting to receive.
uint32_t sequence_number;
/** If the ACK control bit is set this field contains the value of the next sequence number the sender of the segment is expecting to receive.
* Once a~connection is established this is always sent.
* @see acknowledge
*/
uint32_t ack_seq;
uint32_t acknowledgement_number;
#ifdef ARCH_IS_BIG_ENDIAN
/** The number of 32-bit words in the TCP header.
* It indicates where the data begins.
/** The number of 32~bit words in the TCP Header.
* This indicates where the data begins.
* The TCP header (even one including options) is an integral number of 32~bits long.
*/
uint8_t doff:4;
uint8_t header_length:4;
/** Four bits reserved for future use.
* Must be zero.
*/
uint8_t res1:4;
uint8_t reserved1:4;
#else
/** Four bits reserved for future use.
* Must be zero.
*/
uint8_t res1:4;
/** The number of 32-bit words in the TCP header.
* It indicates where the data begins.
uint8_t reserved1:4;
/** The number of 32~bit words in the TCP Header.
* This indicates where the data begins.
* The TCP header (even one including options) is an integral number of 32~bits long.
*/
uint8_t doff:4;
uint8_t header_length:4;
#endif
#ifdef ARCH_IS_BIG_ENDIAN
/** Two bits reserved for future use.
* Must be zero.
*/
uint8_t res2:2;
/** Indicates that the urgent pointer field is significant in this segment.
uint8_t reserved2:2;
/** Urgent Pointer field significant.
* @see tcp_header:urgent_pointer
*/
uint8_t urg:1;
/** Indicates that the acknowledgment field is significant in this segment.
uint8_t urgent:1;
/** Acknowledgment field significant
* @see tcp_header:acknowledgement_number
*/
uint8_t ack:1;
uint8_t acknowledge:1;
/** Push function.
*/
uint8_t psh:1;
/** Resets the connection.
uint8_t push:1;
/** Reset the connection.
*/
uint8_t rst:1;
/** Synchronizes the sequence numbers.
uint8_t reset:1;
/** Synchronize the sequence numbers.
*/
uint8_t syn:1;
/** No more data from sender.
uint8_t synchronize:1;
/** No more data from the sender.
*/
uint8_t fin:1;
uint8_t finalize:1;
#else
/** No more data from sender.
/** No more data from the sender.
*/
uint8_t fin:1;
/** Synchronizes the sequence numbers.
uint8_t finalize:1;
/** Synchronize the sequence numbers.
*/
uint8_t syn:1;
/** Resets the connection.
uint8_t synchronize:1;
/** Reset the connection.
*/
uint8_t rst:1;
uint8_t reset:1;
/** Push function.
*/
uint8_t psh:1;
/** Indicates that the acknowledgment field is significant in this segment.
uint8_t push:1;
/** Acknowledgment field significant.
* @see tcp_header:acknowledgement_number
*/
uint8_t ack:1;
/** Indicates that the urgent pointer field is significant in this segment.
uint8_t acknowledge:1;
/** Urgent Pointer field significant.
* @see tcp_header:urgent_pointer
*/
uint8_t urg:1;
uint8_t urgent:1;
/** Two bits reserved for future use.
* Must be zero.
*/
uint8_t res2:2;
uint8_t reserved2:2;
#endif
/** Used in ACK segments.
* It specifies the number of data bytes, beginning with the one indicated in the acknowledgment number field that the receiver (the sender of this segment) is willing to accept.
/** The number of data octets beginning with the one indicated in the acknowledgment field which the sender of this segment is willing to accept.
* @see tcp_header:acknowledge
*/
uint16_t window;
/** The 16-bit one's complement of the one's complement sum of all 16-bit words in a pseudo-header, the TCP header, and the TCP data.
* While computing the checksum, the checksum field itself is considered zero.
/** The checksum field is the 16~bit one's complement of the one's complement sum of all 16~bit words in the header and text.
* If a~segment contains an odd number of header and text octets to be checksummed, the last octet is padded on the right with zeros to form a~16~bit word for checksum purposes.
* The pad is not transmitted as part of the segment.
* While computing the checksum, the checksum field itself is replaced with zeros.
* The checksum also coves a~pseudo header conceptually.
* The pseudo header conceptually prefixed to the TCP header contains the source address, the destination address, the protocol, and the TCP length.
* This information gives protection against misrouted datagrams.
* If the computed checksum is zero, it is transmitted as all ones (the equivalent in one's complement arithmetic).
*/
uint16_t check;
/** Points to the first data octet following the urgent data.
* Only significant when the URG control bit is set.
uint16_t checksum;
/** This field communicates the current value of the urgent pointer as a~positive offset from the sequence number in this segment.
* The urgent pointer points to the sequence number of the octet following the urgent data.
* This field is only be interpreted in segments with the URG control bit set.
* @see tcp_header:urgent
*/
uint16_t urg_ptr;
uint16_t urgent_pointer;
} __attribute__ ((packed));
 
/** Transmission datagram header option.
*/
struct tcp_option{
/** Option type.
*/
uint8_t type;
/** Option length.
*/
uint8_t length;
};
 
/** Maximum segment size TCP option.
*/
struct tcp_max_segment_size_option{
/** TCP option.
* @see TCPOPT_MAX_SEGMENT_SIZE
* @see TCPOPT_MAX_SEGMENT_SIZE_LENGTH
*/
tcp_option_t option;
/** Maximum segment size in bytes.
*/
uint16_t max_segment_size;
} __attribute__ ((packed));
 
#endif
 
/** @}
/branches/network/uspace/srv/net/tl/tcp/Makefile
38,7 → 38,7
SOURCES = \
$(NAME).c \
$(NAME)_module.c \
$(NET_BASE)crc.c \
$(NET_BASE)checksum.c \
$(NET_BASE)module.c \
$(NET_BASE)modules.c \
$(NET_BASE)il/ip/ip_client.c \
/branches/network/uspace/srv/net/tl/icmp/icmp_messages.h
61,10 → 61,6
* @see icmp_source_quench_msg()
*/
NET_ICMP_SOURCE_QUENCH,
/** Sends redirect error message.
* @see icmp_redirect_msg()
*/
NET_ICMP_REDIRECT,
/** Sends time exceeded error message.
* @see icmp_time_exceeded_msg()
*/
/branches/network/uspace/srv/net/tl/icmp/icmp_client.c
36,6 → 36,7
*/
 
#include <errno.h>
//#include <stdio.h>
 
#include <sys/types.h>
 
59,6 → 60,8
if( code ) * code = header->code;
if( pointer ) * pointer = header->un.param.pointer;
if( mtu ) * mtu = header->un.frag.mtu;
// remove debug dump
// printf( "ICMP error %d (%d) in packet %d\n", header->type, header->code, packet_get_id( packet ));
return sizeof( icmp_header_t );
}
 
/branches/network/uspace/srv/net/tl/icmp/icmp.c
53,7 → 53,7
#include "../../structures/packet/packet_client.h"
 
#include "../../include/byteorder.h"
#include "../../include/crc.h"
#include "../../include/checksum.h"
#include "../../include/icmp_api.h"
#include "../../include/icmp_client.h"
#include "../../include/icmp_codes.h"
/branches/network/uspace/srv/net/tl/icmp/Makefile
39,7 → 39,7
$(NAME).c \
$(NAME)_module.c \
$(NAME)_client.c \
$(NET_BASE)crc.c \
$(NET_BASE)checksum.c \
$(NET_BASE)module.c \
$(NET_BASE)modules.c \
$(NET_BASE)il/ip/ip_client.c \
/branches/network/uspace/srv/net/tl/tl_common.c
56,7 → 56,7
const struct sockaddr_in * address_in;
const struct sockaddr_in6 * address_in6;
 
if( addrlen < sizeof( struct sockaddr )) return EINVAL;
if(( addrlen <= 0 ) || (( size_t ) addrlen < sizeof( struct sockaddr ))) return EINVAL;
switch( addr->sa_family ){
case AF_INET:
if( addrlen != sizeof( struct sockaddr_in )) return EINVAL;
/branches/network/uspace/srv/net/tl/udp/udp.c
38,6 → 38,7
#include <async.h>
#include <fibril_sync.h>
#include <malloc.h>
#include <stdio.h>
 
#include <ipc/ipc.h>
#include <ipc/services.h>
49,7 → 50,7
#include "../../structures/dynamic_fifo.h"
#include "../../structures/packet/packet_client.h"
 
#include "../../include/crc.h"
#include "../../include/checksum.h"
#include "../../include/in.h"
#include "../../include/in6.h"
#include "../../include/inet.h"
232,7 → 233,9
 
fibril_rwlock_write_lock( & udp_globals.lock );
result = udp_process_packet( packet, error );
fibril_rwlock_write_unlock( & udp_globals.lock );
if( result != EOK ){
fibril_rwlock_write_unlock( & udp_globals.lock );
}
 
return result;
}
379,6 → 382,7
}
 
// notify the destination socket
fibril_rwlock_write_unlock( & udp_globals.lock );
async_msg_5( socket->phone, NET_SOCKET_RECEIVED, ( ipcarg_t ) socket->socket_id, 0, 0, 0, ( ipcarg_t ) fragments );
return EOK;
}
414,7 → 418,7
 
/*
* Accept the connection
* - Answer the first IPC_M_CONNECT_ME_TO call.
* - Answer the first IPC_M_CONNECT_TO_ME call.
*/
ipc_answer_0( callid, EOK );
 
461,7 → 465,9
fibril_rwlock_read_lock( & lock );
fibril_rwlock_write_lock( & udp_globals.lock );
res = udp_sendto_message( & local_sockets, SOCKET_GET_SOCKET_ID( call ), addr, addrlen, SOCKET_GET_DATA_FRAGMENTS( call ), SOCKET_GET_DATA_FRAGMENT_SIZE( call ), SOCKET_GET_FLAGS( call ));
fibril_rwlock_write_unlock( & udp_globals.lock );
if( res != EOK ){
fibril_rwlock_write_unlock( & udp_globals.lock );
}
fibril_rwlock_read_unlock( & lock );
free( addr );
}
527,24 → 533,24
 
if(( socket->port <= 0 ) && udp_globals.autobinding ){
// bind the socket to a random free port if not bound
do{
// do{
// try to find a free port
// fibril_rwlock_read_unlock( & udp_globals.lock );
// fibril_rwlock_write_lock( & udp_globals.lock );
// might be changed in the meantime
if( socket->port <= 0 ){
// if( socket->port <= 0 ){
if( ERROR_OCCURRED( socket_bind_free_port( & udp_globals.sockets, socket, UDP_FREE_PORTS_START, UDP_FREE_PORTS_END, udp_globals.last_used_port ))){
fibril_rwlock_write_unlock( & udp_globals.lock );
fibril_rwlock_read_lock( & udp_globals.lock );
// fibril_rwlock_write_unlock( & udp_globals.lock );
// fibril_rwlock_read_lock( & udp_globals.lock );
return ERROR_CODE;
}
// set the next port as the search starting port number
udp_globals.last_used_port = socket->port;
}
// }
// fibril_rwlock_write_unlock( & udp_globals.lock );
// fibril_rwlock_read_lock( & udp_globals.lock );
// might be changed in the meantime
}while( socket->port <= 0 );
// }while( socket->port <= 0 );
}
 
// TODO do not ask all the time
602,7 → 608,9
return udp_release_and_return( packet, ERROR_CODE );
}
// send the packet
return ip_send_msg( udp_globals.ip_phone, device_id, packet, SERVICE_UDP, 0 );
fibril_rwlock_write_unlock( & udp_globals.lock );
ip_send_msg( udp_globals.ip_phone, device_id, packet, SERVICE_UDP, 0 );
return EOK;
}
 
int udp_recvfrom_message( socket_cores_ref local_sockets, int socket_id, int flags, size_t * addrlen ){
/branches/network/uspace/srv/net/tl/udp/Makefile
38,7 → 38,7
SOURCES = \
$(NAME).c \
$(NAME)_module.c \
$(NET_BASE)crc.c \
$(NET_BASE)checksum.c \
$(NET_BASE)module.c \
$(NET_BASE)modules.c \
$(NET_BASE)il/ip/ip_client.c \
/branches/network/uspace/srv/net/tl/tl_messages.h
40,6 → 40,8
 
#include <ipc/ipc.h>
 
#include "../messages.h"
 
/** Transport layer modules messages.
*/
typedef enum{