Subversion Repositories HelenOS

Compare Revisions

Ignore whitespace Rev 4749 → Rev 4750

/branches/network/uspace/srv/net/tl/tcp/tcp.c
172,7 → 172,6
*/
int tcp_release_and_return( packet_t packet, int result );
 
int tcp_get_packet_dimension( device_id_t device_id, packet_dimension_ref * packet_dimension );
void tcp_prepare_operation_header( socket_core_ref socket, tcp_socket_data_ref socket_data, tcp_header_ref header, int synchronize, int finalize );
int tcp_prepare_timeout( int ( * timeout_function )( void * tcp_timeout_t ), socket_core_ref socket, tcp_socket_data_ref socket_data, size_t sequence_number, tcp_socket_state_t state, suseconds_t timeout, int globals_read_only );
void tcp_free_socket_data( socket_core_ref socket );
206,8 → 205,6
int tcp_accept_message( socket_cores_ref local_sockets, int socket_id, size_t * addrlen );
int tcp_close_message( socket_cores_ref local_sockets, int socket_id );
 
DEVICE_MAP_IMPLEMENT( packet_dimensions, packet_dimension_t );
 
/** TCP global data.
*/
tcp_globals_t tcp_globals;
1632,29 → 1629,6
}
}
 
int tcp_get_packet_dimension( device_id_t device_id, packet_dimension_ref * packet_dimension ){
ERROR_DECLARE;
 
assert( packet_dimension );
 
* packet_dimension = packet_dimensions_find( & tcp_globals.dimensions, device_id );
if( ! * packet_dimension ){
// ask for and remember them if not found
* packet_dimension = malloc( sizeof( ** packet_dimension ));
if( ! * packet_dimension ) return ENOMEM;
if( ERROR_OCCURRED( ip_packet_size_req( tcp_globals.ip_phone, device_id, & ( ** packet_dimension ).addr_len, & ( ** packet_dimension ).prefix, & ( ** packet_dimension ).content, & ( ** packet_dimension ).suffix ))){
free( * packet_dimension );
return ERROR_CODE;
}
ERROR_CODE = packet_dimensions_add( & tcp_globals.dimensions, device_id, * packet_dimension );
if( ERROR_CODE < 0 ){
free( * packet_dimension );
return ERROR_CODE;
}
}
return EOK;
}
 
void tcp_prepare_operation_header( socket_core_ref socket, tcp_socket_data_ref socket_data, tcp_header_ref header, int synchronize, int finalize ){
assert( socket );
assert( socket_data );
1778,7 → 1752,7
return ENOTCONN;
}
 
ERROR_PROPAGATE( tcp_get_packet_dimension( socket_data->device_id, & packet_dimension ));
ERROR_PROPAGATE( tl_get_ip_packet_dimension( tcp_globals.ip_phone, & tcp_globals.dimensions, socket_data->device_id, & packet_dimension ));
 
// TODO return the device_id + data_fragment_size if different - the client should send it again
// ( two messages are better than ip fragmentation )
1869,7 → 1843,7
assert( packet );
 
// get the device packet dimension
ERROR_PROPAGATE( tcp_get_packet_dimension( socket_data->device_id, & packet_dimension ));
ERROR_PROPAGATE( tl_get_ip_packet_dimension( tcp_globals.ip_phone, & tcp_globals.dimensions, socket_data->device_id, & packet_dimension ));
// get a new packet
* packet = packet_get_4( tcp_globals.net_phone, sizeof( tcp_header_t ), packet_dimension->addr_len, packet_dimension->prefix, packet_dimension->suffix );
if( ! * packet ) return ENOMEM;
/branches/network/uspace/srv/net/tl/tcp/tcp.h
77,12 → 77,6
*/
typedef enum tcp_socket_state tcp_socket_state_t;
 
/** Device packet dimensions.
* Maps devices to the packet dimensions.
* @see device.h
*/
DEVICE_MAP_DECLARE( packet_dimensions, packet_dimension_t );
 
/** TCP socket state.
*/
enum tcp_socket_state{
/branches/network/uspace/srv/net/tl/tl_common.c
47,11 → 47,14
#include "../include/in.h"
#include "../include/in6.h"
#include "../include/inet.h"
#include "../include/ip_interface.h"
#include "../include/socket_codes.h"
#include "../include/socket_errno.h"
 
#include "tl_common.h"
 
DEVICE_MAP_IMPLEMENT( packet_dimensions, packet_dimension_t );
 
int tl_get_address_port( const struct sockaddr * addr, int addrlen, uint16_t * port ){
const struct sockaddr_in * address_in;
const struct sockaddr_in6 * address_in6;
74,6 → 77,29
return EOK;
}
 
int tl_get_ip_packet_dimension( int ip_phone, packet_dimensions_ref packet_dimensions, device_id_t device_id, packet_dimension_ref * packet_dimension ){
ERROR_DECLARE;
 
if( ! packet_dimension ) return EBADMEM;
 
* packet_dimension = packet_dimensions_find( packet_dimensions, device_id );
if( ! * packet_dimension ){
// ask for and remember them if not found
* packet_dimension = malloc( sizeof( ** packet_dimension ));
if( ! * packet_dimension ) return ENOMEM;
if( ERROR_OCCURRED( ip_packet_size_req( ip_phone, device_id, & ( ** packet_dimension ).addr_len, & ( ** packet_dimension ).prefix, & ( ** packet_dimension ).content, & ( ** packet_dimension ).suffix ))){
free( * packet_dimension );
return ERROR_CODE;
}
ERROR_CODE = packet_dimensions_add( packet_dimensions, device_id, * packet_dimension );
if( ERROR_CODE < 0 ){
free( * packet_dimension );
return ERROR_CODE;
}
}
return EOK;
}
 
int tl_set_address_port( struct sockaddr * addr, int addrlen, uint16_t port ){
struct sockaddr_in * address_in;
struct sockaddr_in6 * address_in6;
/branches/network/uspace/srv/net/tl/udp/udp.c
205,8 → 205,13
if( udp_globals.ip_phone < 0 ){
return udp_globals.ip_phone;
}
// read default packet dimensions
ERROR_PROPAGATE( ip_packet_size_req( udp_globals.ip_phone, -1, & udp_globals.packet_dimension.addr_len, & udp_globals.packet_dimension.prefix, & udp_globals.packet_dimension.content, & udp_globals.packet_dimension.suffix ));
ERROR_PROPAGATE( socket_ports_initialize( & udp_globals.sockets ));
if( ERROR_OCCURRED( packet_dimensions_initialize( & udp_globals.dimensions ))){
socket_ports_destroy( & udp_globals.sockets );
return ERROR_CODE;
}
udp_globals.packet_dimension.prefix += sizeof( udp_header_t );
udp_globals.packet_dimension.content -= sizeof( udp_header_t );
udp_globals.last_used_port = UDP_FREE_PORTS_START - 1;
525,6 → 530,7
ip_pseudo_header_ref ip_header;
size_t headerlen;
device_id_t device_id;
packet_dimension_ref packet_dimension;
 
ERROR_PROPAGATE( tl_get_address_port( addr, addrlen, & dest_port ));
 
553,11 → 559,21
// }while( socket->port <= 0 );
}
 
// TODO do not ask all the time
ERROR_PROPAGATE( ip_packet_size_req( udp_globals.ip_phone, -1, & udp_globals.packet_dimension.addr_len, & udp_globals.packet_dimension.prefix, & udp_globals.packet_dimension.content, & udp_globals.packet_dimension.suffix ));
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 );
}
// get the device packet dimension
// ERROR_PROPAGATE( tl_get_ip_packet_dimension( udp_globals.ip_phone, & udp_globals.dimensions, device_id, & packet_dimension ));
}
// }else{
// do not ask all the time
ERROR_PROPAGATE( ip_packet_size_req( udp_globals.ip_phone, -1, & udp_globals.packet_dimension.addr_len, & udp_globals.packet_dimension.prefix, & udp_globals.packet_dimension.content, & udp_globals.packet_dimension.suffix ));
packet_dimension = & udp_globals.packet_dimension;
// }
 
// read the first packet fragment
result = tl_socket_read_packet_data( udp_globals.net_phone, & packet, sizeof( udp_header_t ), & udp_globals.packet_dimension, addr, addrlen );
result = tl_socket_read_packet_data( udp_globals.net_phone, & packet, sizeof( udp_header_t ), packet_dimension, addr, addrlen );
if( result < 0 ) return result;
total_length = ( size_t ) result;
if( udp_globals.checksum_computing ){
573,7 → 589,7
bzero( header, sizeof( * header ));
// read the rest of the packet fragments
for( index = 1; index < fragments; ++ index ){
result = tl_socket_read_packet_data( udp_globals.net_phone, & next_packet, 0, & udp_globals.packet_dimension, addr, addrlen );
result = tl_socket_read_packet_data( udp_globals.net_phone, & next_packet, 0, packet_dimension, addr, addrlen );
if( result < 0 ){
return udp_release_and_return( packet, result );
}
589,9 → 605,9
header->total_length = htons( total_length + sizeof( * header ));
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 );
}
// 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 );
// }
if( ERROR_OCCURRED( ip_client_set_pseudo_header_data_length( ip_header, headerlen, total_length + sizeof( udp_header_t )))){
free( ip_header );
return udp_release_and_return( packet, ERROR_CODE );
/branches/network/uspace/srv/net/tl/udp/udp.h
75,6 → 75,9
/** Active sockets.
*/
socket_ports_t sockets;
/** Device packet dimensions.
*/
packet_dimensions_t dimensions;
/** Safety lock.
*/
fibril_rwlock_t lock;
/branches/network/uspace/srv/net/tl/tl_common.h
39,6 → 39,7
 
#include "../structures/packet/packet.h"
 
#include "../include/device.h"
#include "../include/inet.h"
#include "../include/socket_codes.h"
 
69,6 → 70,12
size_t addr_len;
};
 
/** Device packet dimensions.
* Maps devices to the packet dimensions.
* @see device.h
*/
DEVICE_MAP_DECLARE( packet_dimensions, packet_dimension_t );
 
/** Gets the address port.
* Supports AF_INET and AF_INET6 address families.
* @param addr The address to be updated. Input/output parameter.
80,6 → 87,21
*/
int tl_get_address_port( const struct sockaddr * addr, int addrlen, uint16_t * port );
 
/** Gets IP packet dimensions.
* Tries to search a cache and queries the IP module if not found.
* The reply is cached then.
* @param[in] ip_phone The IP moduel phone for (semi)remote calls.
* @param[in] packet_dimensions The packet dimensions cache.
* @param[in] device_id The device identifier.
* @param[out] packet_dimention The IP packet dimensions.
* @returns EOK on success.
* @returns EBADMEM if the packet_dimension parameter is NULL.
* @return ENOMEM if there is not enough memory left.
* @returns EINVAL if the packet_dimensions cache is not valid.
* @returns Other codes as defined for the ip_packet_size_req() function.
*/
int tl_get_ip_packet_dimension( int ip_phone, packet_dimensions_ref packet_dimensions, device_id_t device_id, packet_dimension_ref * packet_dimension );
 
/** Sets the address port.
* Supports AF_INET and AF_INET6 address families.
* @param addr The address to be updated. Input/output parameter.