Changeset ca2d142 in mainline
- Timestamp:
- 2010-02-18T10:00:30Z (15 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- e326edc
- Parents:
- b8da2a3 (diff), 91478aa (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the(diff)
links above to see all the changes relative to each parent. - Location:
- uspace/srv/net
- Files:
-
- 18 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/srv/net/il/arp/arp.c
rb8da2a3 rca2d142 337 337 } 338 338 // get packet dimensions 339 if( ERROR_OCCURRED( nil_packet_size_req( device->phone, device_id, & device-> addr_len, & device->prefix, & device->content, & device->suffix))){339 if( ERROR_OCCURRED( nil_packet_size_req( device->phone, device_id, & device->packet_dimension ))){ 340 340 fibril_rwlock_write_unlock( & arp_globals.lock ); 341 341 arp_protos_destroy( & device->protos ); … … 392 392 // ARP packet content size = header + ( address + translation ) * 2 393 393 length = 8 + ( CONVERT_SIZE( char, uint8_t, proto->addr->length ) + CONVERT_SIZE( char, uint8_t, device->addr->length )) * 2; 394 if( length > device-> content ) return NULL;395 packet = packet_get_4( arp_globals.net_phone, device-> addr_len, device->prefix, length, device->suffix );394 if( length > device->packet_dimension.content ) return NULL; 395 packet = packet_get_4( arp_globals.net_phone, device->packet_dimension.addr_len, device->packet_dimension.prefix, length, device->packet_dimension.suffix ); 396 396 if( ! packet ) return NULL; 397 397 header = ( arp_header_ref ) packet_suffix( packet, length ); … … 472 472 memcpy( des_proto, src_proto, header->protocol_length ); 473 473 memcpy( src_proto, proto->addr->value, header->protocol_length ); 474 memcpy( src_hw, device->addr->value, device-> addr_len );474 memcpy( src_hw, device->addr->value, device->packet_dimension.addr_len ); 475 475 memcpy( des_hw, hw_source->value, header->hardware_length ); 476 476 ERROR_PROPAGATE( packet_set_addr( packet, src_hw, des_hw, header->hardware_length )); … … 511 511 return ENOENT; 512 512 } 513 device-> content = mtu;513 device->packet_dimension.content = mtu; 514 514 printf( "arp - device %d changed mtu to %d\n\n", device_id, mtu ); 515 515 fibril_rwlock_write_unlock( & arp_globals.lock ); -
uspace/srv/net/il/arp/arp.h
rb8da2a3 rca2d142 103 103 */ 104 104 hw_type_t hardware; 105 /** Reserved packet prefix length.105 /** Packet dimension. 106 106 */ 107 size_t prefix; 108 /** Maximal packet content length. 109 */ 110 size_t content; 111 /** Reserved packet suffix length. 112 */ 113 size_t suffix; 114 /** Packet address length. 115 * The hardware address length is used. 116 */ 117 size_t addr_len; 107 packet_dimension_t packet_dimension; 118 108 /** Actual device hardware address. 119 109 */ -
uspace/srv/net/il/ip/ip.c
rb8da2a3 rca2d142 152 152 int ip_device_state_message( device_id_t device_id, device_state_t state ); 153 153 154 /** Returns the device packet dimensions for sending. 155 * @param[in] phone The service module phone. 156 * @param[in] message The service specific message. 157 * @param[in] device_id The device identifier. 158 * @param[out] addr_len The minimum reserved address length. 159 * @param[out] prefix The minimum reserved prefix size. 160 * @param[out] content The maximum content size. 161 * @param[out] suffix The minimum reserved suffix size. 162 * @returns EOK on success. 163 */ 164 int ip_packet_size_message( device_id_t device_id, size_t * addr_len, size_t * prefix, size_t * content, size_t * suffix ); 165 154 166 /** Registers the transport layer protocol. 155 167 * The traffic of this protocol will be supplied using either the receive function or IPC message. … … 380 392 * @returns ENOMEM if the packet is too short to contain the IP header. 381 393 * @returns EAFNOSUPPORT if the address family is not supported. 394 * @returns EPERM if the protocol is not allowed to send ICMP notifications. The ICMP protocol itself. 382 395 * @returns Other error codes as defined for the packet_set_addr(). 383 396 */ … … 550 563 } 551 564 // get packet dimensions 552 ERROR_PROPAGATE( nil_packet_size_req( ip_netif->phone, ip_netif->device_id, & ip_netif-> addr_len, & ip_netif->prefix, & ip_netif->content, & ip_netif->suffix));553 if( ip_netif-> content < IP_MIN_CONTENT ){554 printf( "Maximum transmission unit %d bytes is too small, at least %d bytes are needed\n", ip_netif-> content, IP_MIN_CONTENT );555 ip_netif-> content = IP_MIN_CONTENT;565 ERROR_PROPAGATE( nil_packet_size_req( ip_netif->phone, ip_netif->device_id, & ip_netif->packet_dimension )); 566 if( ip_netif->packet_dimension.content < IP_MIN_CONTENT ){ 567 printf( "Maximum transmission unit %d bytes is too small, at least %d bytes are needed\n", ip_netif->packet_dimension.content, IP_MIN_CONTENT ); 568 ip_netif->packet_dimension.content = IP_MIN_CONTENT; 556 569 } 557 570 index = ip_netifs_add( & ip_globals.netifs, ip_netif->device_id, ip_netif ); … … 576 589 return ENOENT; 577 590 } 578 netif-> content = mtu;591 netif->packet_dimension.content = mtu; 579 592 printf( "ip - device %d changed mtu to %d\n\n", device_id, mtu ); 580 593 fibril_rwlock_write_unlock( & ip_globals.netifs_lock ); … … 767 780 pq_release( ip_globals.net_phone, packet_get_id( packet )); 768 781 }else{ 769 packet = ip_split_packet( packet, netif->p refix, netif->content, netif->suffix, netif->addr_len, error );782 packet = ip_split_packet( packet, netif->packet_dimension.prefix, netif->packet_dimension.content, netif->packet_dimension.suffix, netif->packet_dimension.addr_len, error ); 770 783 if( packet ){ 771 784 nil_send_msg( netif->phone, netif->device_id, packet, SERVICE_IP ); … … 890 903 return ERROR_CODE; 891 904 case NET_IL_PACKET_SPACE: 892 ERROR_PROPAGATE( ip_packet_size_ req( 0,IPC_GET_DEVICE( call ), IPC_SET_ADDR( answer ), IPC_SET_PREFIX( answer ), IPC_SET_CONTENT( answer ), IPC_SET_SUFFIX( answer )));905 ERROR_PROPAGATE( ip_packet_size_message( IPC_GET_DEVICE( call ), IPC_SET_ADDR( answer ), IPC_SET_PREFIX( answer ), IPC_SET_CONTENT( answer ), IPC_SET_SUFFIX( answer ))); 893 906 * answer_count = 3; 894 907 return EOK; … … 899 912 } 900 913 901 int ip_packet_size_req( int ip_phone, device_id_t device_id, size_t * addr_len, size_t * prefix, size_t * content, size_t * suffix ){ 914 int ip_packet_size_req( int ip_phone, device_id_t device_id, packet_dimension_ref packet_dimension ){ 915 if( ! packet_dimension ) return EBADMEM; 916 return ip_packet_size_message( device_id, & packet_dimension->addr_len, & packet_dimension->prefix, & packet_dimension->content, & packet_dimension->suffix ); 917 } 918 919 int ip_packet_size_message( device_id_t device_id, size_t * addr_len, size_t * prefix, size_t * content, size_t * suffix ){ 902 920 ip_netif_ref netif; 903 921 int index; … … 913 931 netif = ip_netifs_get_index( & ip_globals.netifs, index ); 914 932 if( netif ){ 915 if( netif-> addr_len > * addr_len ) * addr_len = netif->addr_len;916 if( netif->p refix > * prefix ) * prefix = netif->prefix;917 if( netif-> suffix > * suffix ) * suffix = netif->suffix;933 if( netif->packet_dimension.addr_len > * addr_len ) * addr_len = netif->packet_dimension.addr_len; 934 if( netif->packet_dimension.prefix > * prefix ) * prefix = netif->packet_dimension.prefix; 935 if( netif->packet_dimension.suffix > * suffix ) * suffix = netif->packet_dimension.suffix; 918 936 } 919 937 } … … 926 944 return ENOENT; 927 945 } 928 * addr_len = ( netif-> addr_len > IP_ADDR ) ? netif->addr_len : IP_ADDR;929 * prefix = netif->p refix + IP_PREFIX;930 * suffix = netif-> suffix + IP_SUFFIX;946 * addr_len = ( netif->packet_dimension.addr_len > IP_ADDR ) ? netif->packet_dimension.addr_len : IP_ADDR; 947 * prefix = netif->packet_dimension.prefix + IP_PREFIX; 948 * suffix = netif->packet_dimension.suffix + IP_SUFFIX; 931 949 } 932 950 fibril_rwlock_read_unlock( & ip_globals.netifs_lock ); … … 1415 1433 // only for the first fragment 1416 1434 if( IP_FRAGMENT_OFFSET( header )) return EINVAL; 1435 // not for the ICMP protocol 1436 if( header->protocol == IPPROTO_ICMP ){ 1437 return EPERM; 1438 } 1417 1439 // set the destination address 1418 1440 switch( header->version ){ -
uspace/srv/net/il/ip/ip.h
rb8da2a3 rca2d142 137 137 */ 138 138 ip_routes_t routes; 139 /** Reserved packet prefix length. 140 */ 141 size_t prefix; 142 /** Maximal packet content length. 143 */ 144 size_t content; 145 /** Reserved packet suffix length. 146 */ 147 size_t suffix; 148 /** Packet address length. 149 * The hardware address length is used. 150 */ 151 size_t addr_len; 139 /** Packet dimension. 140 */ 141 packet_dimension_t packet_dimension; 152 142 }; 153 143 -
uspace/srv/net/il/ip/ip_remote.c
rb8da2a3 rca2d142 72 72 } 73 73 74 int ip_packet_size_req( int ip_phone, device_id_t device_id, size_t * addr_len, size_t * prefix, size_t * content, size_t * suffix){75 return generic_packet_size_req( ip_phone, NET_IL_PACKET_SPACE, device_id, addr_len, prefix, content, suffix);74 int ip_packet_size_req( int ip_phone, device_id_t device_id, packet_dimension_ref packet_dimension ){ 75 return generic_packet_size_req( ip_phone, NET_IL_PACKET_SPACE, device_id, packet_dimension ); 76 76 } 77 77 -
uspace/srv/net/include/ip_interface.h
rb8da2a3 rca2d142 137 137 int ip_set_gateway_req( int ip_phone, device_id_t device_id, in_addr_t gateway ); 138 138 139 /** Returns the device packet dimension sfor sending.139 /** Returns the device packet dimension for sending. 140 140 * @param[in] ip_phone The IP module phone used for (semi)remote calls. 141 141 * @param[in] device_id The device identifier. 142 * @param[out] addr_len The minimum reserved address length. 143 * @param[out] prefix The minimum reserved prefix size. 144 * @param[out] content The maximum content size. 145 * @param[out] suffix The minimum reserved suffix size. 142 * @param[out] packet_dimension The packet dimension. 146 143 * @returns EOK on success. 147 * @returns EBADMEM if either one of the parameters is NULL.148 144 * @returns ENOENT if there is no such device. 149 145 * @returns Other error codes as defined for the generic_packet_size_req() function. 150 146 */ 151 int ip_packet_size_req( int ip_phone, device_id_t device_id, size_t * addr_len, size_t * prefix, size_t * content, size_t * suffix);147 int ip_packet_size_req( int ip_phone, device_id_t device_id, packet_dimension_ref packet_dimension ); 152 148 153 149 /** Notifies the IP module about the received error notification packet. -
uspace/srv/net/include/nil_interface.h
rb8da2a3 rca2d142 98 98 generic_send_msg( nil_phone, NET_NIL_SEND, device_id, packet_get_id( packet ), sender, 0 ) 99 99 100 /** Returns the device packet dimension sfor sending.100 /** Returns the device packet dimension for sending. 101 101 * @param[in] nil_phone The network interface layer phone. 102 102 * @param[in] device_id The device identifier. 103 * @param[out] addr_len The minimum reserved address length. 104 * @param[out] prefix The minimum reserved prefix size. 105 * @param[out] content The maximum content size. 106 * @param[out] suffix The minimum reserved suffix size. 103 * @param[out] packet_dimension The packet dimensions. 107 104 * @returns EOK on success. 108 * @returns EBADMEM if either one of the parameters is NULL.109 105 * @returns ENOENT if there is no such device. 110 106 * @returns Other error codes as defined for the generic_packet_size_req() function. 111 107 */ 112 #define nil_packet_size_req( nil_phone, device_id, addr_len, prefix, content, suffix) \113 generic_packet_size_req( nil_phone, NET_NIL_PACKET_SPACE, device_id, addr_len, prefix, content, suffix)108 #define nil_packet_size_req( nil_phone, device_id, packet_dimension ) \ 109 generic_packet_size_req( nil_phone, NET_NIL_PACKET_SPACE, device_id, packet_dimension ) 114 110 115 111 /** Registers new device or updates the MTU of an existing one. -
uspace/srv/net/messages.h
rb8da2a3 rca2d142 459 459 } 460 460 461 /** Returns the device packet dimensions for sending. 462 * @param[in] phone The service module phone. 463 * @param[in] message The service specific message. 464 * @param[in] device_id The device identifier. 465 * @param[out] addr_len The minimum reserved address length. 466 * @param[out] prefix The minimum reserved prefix size. 467 * @param[out] content The maximum content size. 468 * @param[out] suffix The minimum reserved suffix size. 469 * @returns EOK on success. 461 /** Returns the device packet dimension for sending. 462 * @param[in] phone The service module phone. 463 * @param[in] message The service specific message. 464 * @param[in] device_id The device identifier. 465 * @param[out] packet_dimension The packet dimension. 466 * @returns EOK on success. 467 * @returns EBADMEM if the packet_dimension parameter is NULL. 470 468 * @returns Other error codes as defined for the specific service message. 471 469 */ 472 static inline int generic_packet_size_req( int phone, int message, device_id_t device_id, size_t * addr_len, size_t * prefix, size_t * content, size_t * suffix ){ 473 return ( int ) async_req_1_4( phone, ( ipcarg_t ) message, ( ipcarg_t ) device_id, ( ipcarg_t * ) addr_len, ( ipcarg_t * ) prefix, ( ipcarg_t * ) content, ( ipcarg_t * ) suffix ); 470 static inline int generic_packet_size_req( int phone, int message, device_id_t device_id, packet_dimension_ref packet_dimension ){ 471 ipcarg_t result; 472 ipcarg_t prefix; 473 ipcarg_t content; 474 ipcarg_t suffix; 475 ipcarg_t addr_len; 476 477 if( ! packet_dimension ) return EBADMEM; 478 result = async_req_1_4( phone, ( ipcarg_t ) message, ( ipcarg_t ) device_id, & addr_len, & prefix, & content, & suffix ); 479 packet_dimension->prefix = ( size_t ) prefix; 480 packet_dimension->content = ( size_t ) content; 481 packet_dimension->suffix = ( size_t ) suffix; 482 packet_dimension->addr_len = ( size_t ) addr_len; 483 return ( int ) result; 474 484 } 475 485 -
uspace/srv/net/netif/dp8390/dp8390.c
rb8da2a3 rca2d142 350 350 tmp = pq_next( tmp ); 351 351 } 352 if( ! pq_add( tmp, packet, 0, 0 )){352 if( pq_add( & tmp, packet, 0, 0 ) != EOK ){ 353 353 return EINVAL; 354 354 } … … 1006 1006 int last, count; 1007 1007 packet_t packet; 1008 packet_t queue;1009 1008 1010 1009 // if (!(dep->de_flags & DEF_READING)) … … 1045 1044 return ELIMIT; 1046 1045 }else{ 1047 queue = pq_add( dep->received_queue, packet, 0, 0 ); 1048 if( queue ){ 1049 dep->received_queue = queue; 1046 if( pq_add( & dep->received_queue, packet, 0, 0 ) == EOK ){ 1050 1047 ++ dep->received_count; 1051 1048 }else{ -
uspace/srv/net/structures/packet/packet.c
rb8da2a3 rca2d142 184 184 } 185 185 186 packet_t pq_add( packet_tfirst, packet_t packet, size_t order, size_t metric ){186 int pq_add( packet_t * first, packet_t packet, size_t order, size_t metric ){ 187 187 packet_t item; 188 188 189 if( ! packet_is_valid( packet )) return NULL;189 if(( ! first ) || ( ! packet_is_valid( packet ))) return EINVAL; 190 190 pq_set_order( packet, order, metric ); 191 if( packet_is_valid( first )){192 item = first;191 if( packet_is_valid( * first )){ 192 item = * first; 193 193 do{ 194 194 if( item->order < order ){ … … 198 198 item->next = packet->packet_id; 199 199 packet->previous = item->packet_id; 200 return first;200 return EOK; 201 201 } 202 202 }else{ … … 205 205 item->previous = packet->packet_id; 206 206 item = pm_find( packet->previous ); 207 if( item ) item->next = packet->packet_id; 208 return item ? first : packet; 207 if( item ){ 208 item->next = packet->packet_id; 209 }else{ 210 * first = packet; 211 } 212 return EOK; 209 213 } 210 214 }while( packet_is_valid( item )); 211 215 } 212 return packet; 216 * first = packet; 217 return EOK; 213 218 } 214 219 -
uspace/srv/net/structures/packet/packet.h
rb8da2a3 rca2d142 53 53 typedef packet_t * packet_ref; 54 54 55 /** Type definition of the packet dimension. 56 * @see packet_dimension 57 */ 58 typedef struct packet_dimension packet_dimension_t; 59 60 /** Type definition of the packet dimension pointer. 61 * @see packet_dimension 62 */ 63 typedef packet_dimension_t * packet_dimension_ref; 64 65 /** Packet dimension. 66 */ 67 struct packet_dimension{ 68 /** Reserved packet prefix length. 69 */ 70 size_t prefix; 71 /** Maximal packet content length. 72 */ 73 size_t content; 74 /** Reserved packet suffix length. 75 */ 76 size_t suffix; 77 /** Maximal packet address length. 78 */ 79 size_t addr_len; 80 }; 81 55 82 /** @name Packet management system interface 56 83 */ … … 86 113 * The queue is sorted in the ascending order. 87 114 * The packet is inserted right before the packets of the same order value. 88 * @param[in ] first The first packet of the queue. May be NULL.115 * @param[in,out] first The first packet of the queue. Sets the first packet of the queue. The original first packet may be shifted by the new packet. 89 116 * @param[in] packet The packet to be added. 90 117 * @param[in] order The packet order value. 91 118 * @param[in] metric The metric value of the packet. 92 * @returns The first packet of the queue. The original first packet may be shifted by the new packet. 93 * @returns NULL if the packet is not valid. 119 * @returns EOK on success. 120 * @returns EINVAL if the first parameter is NULL. 121 * @returns EINVAL if the packet is not valid. 94 122 */ 95 packet_t pq_add( packet_tfirst, packet_t packet, size_t order, size_t metric );123 int pq_add( packet_t * first, packet_t packet, size_t order, size_t metric ); 96 124 97 125 /** Finds the packet with the given order. -
uspace/srv/net/structures/packet/packet_server.c
rb8da2a3 rca2d142 229 229 void packet_release( packet_t packet ){ 230 230 int index; 231 int result; 231 232 232 233 // remove debug dump 233 234 // printf( "packet %d released\n", packet->packet_id ); 234 235 for( index = 0; ( index < FREE_QUEUES_COUNT - 1 ) && ( packet->length > ps_globals.sizes[ index ] ); ++ index ); 235 ps_globals.free[ index ] = pq_add(ps_globals.free[ index ], packet, packet->length, packet->length );236 assert( ps_globals.free[ index ]);236 result = pq_add( & ps_globals.free[ index ], packet, packet->length, packet->length ); 237 assert( result == EOK ); 237 238 } 238 239 -
uspace/srv/net/tl/icmp/icmp.c
rb8da2a3 rca2d142 115 115 #define ICMP_GET_REPLY_KEY( id, sequence ) ((( id ) << 16 ) | ( sequence & 0xFFFF )) 116 116 117 /** Type definition of the ICMP reply timeout.118 * @see icmp_reply_timeout119 */120 typedef struct icmp_reply_timeout icmp_reply_timeout_t;121 122 /** Type definition of the ICMP reply timeout pointer.123 * @see icmp_reply_timeout124 */125 typedef icmp_reply_timeout_t * icmp_reply_timeout_ref;126 127 /** ICMP reply timeout data.128 * Used as a timeouting fibril argument.129 * @see icmp_timeout_for_reply()130 */131 struct icmp_reply_timeout{132 /** Reply data key.133 */134 int reply_key;135 /** Timeout in microseconds.136 */137 suseconds_t timeout;138 };139 140 117 /** Processes the received ICMP packet. 141 118 * Is used as an entry point from the underlying IP module. … … 255 232 int icmp_process_echo_reply( packet_t packet, icmp_header_ref header, icmp_type_t type, icmp_code_t code ); 256 233 257 /** Tries to set the pending reply result as timeouted.258 * Sleeps the timeout period of time and then tries to obtain and set the pending reply result as timeouted and signals the reply result.259 * If the reply data are still present, the reply timeouted and the parent fibril is awaken.260 * The global lock is not released in this case to be reused by the parent fibril.261 * Should run in a searate fibril.262 * @param[in] data The icmp_reply_timeout structure.263 * @returns EOK on success.264 * @returns EINVAL if the data parameter is NULL.265 */266 int icmp_timeout_for_reply( void * data );267 268 234 /** Assigns a new identifier for the connection. 269 235 * Fills the echo data parameter with the assigned values. … … 304 270 } 305 271 306 int icmp_timeout_for_reply( void * data ){307 icmp_reply_ref reply;308 icmp_reply_timeout_ref timeout = data;309 310 if( ! timeout ){311 return EINVAL;312 }313 // sleep the given timeout314 async_usleep( timeout->timeout );315 // lock the globals316 fibril_rwlock_write_lock( & icmp_globals.lock );317 // find the pending reply318 reply = icmp_replies_find( & icmp_globals.replies, timeout->reply_key );319 if( reply ){320 // set the timeout result321 reply->result = ETIMEOUT;322 // notify the main fibril323 fibril_condvar_signal( & reply->condvar );324 }else{325 // unlock only if no reply326 fibril_rwlock_write_unlock( & icmp_globals.lock );327 }328 // release the timeout structure329 free( timeout );330 return EOK;331 }332 333 272 int icmp_echo( icmp_param_t id, icmp_param_t sequence, size_t size, mseconds_t timeout, ip_ttl_t ttl, ip_tos_t tos, int dont_fragment, const struct sockaddr * addr, socklen_t addrlen ){ 334 273 ERROR_DECLARE; … … 339 278 uint8_t * data; 340 279 icmp_reply_ref reply; 341 i cmp_reply_timeout_ref reply_timeout;280 int reply_key; 342 281 int result; 343 282 int index; 344 fid_t fibril;345 283 346 284 if( addrlen <= 0 ){ … … 349 287 length = ( size_t ) addrlen; 350 288 // TODO do not ask all the time 351 ERROR_PROPAGATE( ip_packet_size_req( icmp_globals.ip_phone, -1, & icmp_globals. addr_len, & icmp_globals.prefix, & icmp_globals.content, & icmp_globals.suffix));352 packet = packet_get_4( icmp_globals.net_phone, size, icmp_globals. addr_len, ICMP_HEADER_SIZE + icmp_globals.prefix, icmp_globals.suffix );289 ERROR_PROPAGATE( ip_packet_size_req( icmp_globals.ip_phone, -1, & icmp_globals.packet_dimension )); 290 packet = packet_get_4( icmp_globals.net_phone, size, icmp_globals.packet_dimension.addr_len, ICMP_HEADER_SIZE + icmp_globals.packet_dimension.prefix, icmp_globals.packet_dimension.suffix ); 353 291 if( ! packet ) return ENOMEM; 354 292 … … 379 317 header->un.echo.sequence_number = sequence; 380 318 381 // prepare the reply and the reply timeout structures 382 reply_timeout = malloc( sizeof( * reply_timeout )); 383 if( ! reply_timeout ){ 384 return icmp_release_and_return( packet, ENOMEM ); 385 } 319 // prepare the reply structure 386 320 reply = malloc( sizeof( * reply )); 387 321 if( ! reply ){ 388 free( reply_timeout );389 322 return icmp_release_and_return( packet, ENOMEM ); 390 323 } 391 // prepare the timeouting thread392 fibril = fibril_create( icmp_timeout_for_reply, reply_timeout );393 if( ! fibril ){394 free( reply );395 free( reply_timeout );396 return icmp_release_and_return( packet, EPARTY );397 }398 reply_timeout->reply_key = ICMP_GET_REPLY_KEY( header->un.echo.identifier, header->un.echo.sequence_number );399 // timeout in microseconds400 reply_timeout->timeout = timeout * 1000;401 324 fibril_mutex_initialize( & reply->mutex ); 402 325 fibril_mutex_lock( & reply->mutex ); 403 326 fibril_condvar_initialize( & reply->condvar ); 404 // start the timeouting fibril 405 fibril_add_ready( fibril ); 406 index = icmp_replies_add( & icmp_globals.replies, reply_timeout->reply_key, reply ); 327 reply_key = ICMP_GET_REPLY_KEY( header->un.echo.identifier, header->un.echo.sequence_number ); 328 index = icmp_replies_add( & icmp_globals.replies, reply_key, reply ); 407 329 if( index < 0 ){ 408 330 free( reply ); … … 417 339 418 340 // wait for a reply 419 fibril_condvar_wait( & reply->condvar, & reply->mutex ); 420 421 // read the result 422 result = reply->result; 341 // timeout in microseconds 342 if( ERROR_OCCURRED( fibril_condvar_wait_timeout( & reply->condvar, & reply->mutex, timeout * 1000 ))){ 343 result = ERROR_CODE; 344 345 // lock the globals again and clean up 346 fibril_rwlock_write_lock( & icmp_globals.lock ); 347 }else{ 348 // read the result 349 result = reply->result; 350 351 // release the reply structure 352 fibril_mutex_unlock( & reply->mutex ); 353 } 423 354 424 355 // destroy the reply structure 425 fibril_mutex_unlock( & reply->mutex );426 356 icmp_replies_exclude_index( & icmp_globals.replies, index ); 427 357 return result; … … 547 477 return icmp_globals.ip_phone; 548 478 } 549 ERROR_PROPAGATE( ip_packet_size_req( icmp_globals.ip_phone, -1, & icmp_globals. addr_len, & icmp_globals.prefix, & icmp_globals.content, & icmp_globals.suffix));550 icmp_globals.p refix += ICMP_HEADER_SIZE;551 icmp_globals. content -= ICMP_HEADER_SIZE;479 ERROR_PROPAGATE( ip_packet_size_req( icmp_globals.ip_phone, -1, & icmp_globals.packet_dimension )); 480 icmp_globals.packet_dimension.prefix += ICMP_HEADER_SIZE; 481 icmp_globals.packet_dimension.content -= ICMP_HEADER_SIZE; 552 482 // get configuration 553 483 icmp_globals.error_reporting = NET_DEFAULT_ICMP_ERROR_REPORTING; -
uspace/srv/net/tl/icmp/icmp.h
rb8da2a3 rca2d142 94 94 */ 95 95 int ip_phone; 96 /** Reserved packet prefix length.96 /** Packet dimension. 97 97 */ 98 size_t prefix; 99 /** Maximal packet content length. 100 */ 101 size_t content; 102 /** Reserved packet suffix length. 103 */ 104 size_t suffix; 105 /** Packet address length. 106 */ 107 size_t addr_len; 98 packet_dimension_t packet_dimension; 108 99 /** Networking module phone. 109 100 */ -
uspace/srv/net/tl/tcp/tcp.c
rb8da2a3 rca2d142 613 613 next_packet = pq_detach( packet ); 614 614 length = packet_get_data_length( packet ); 615 tmp_packet = pq_add( socket_data->incoming, packet, new_sequence_number, length ); 616 if( ! tmp_packet ){ 615 if( ERROR_OCCURRED( pq_add( & socket_data->incoming, packet, new_sequence_number, length ))){ 617 616 // remove the corrupted packets 618 617 pq_release( tcp_globals.net_phone, packet_get_id( packet )); 619 618 pq_release( tcp_globals.net_phone, packet_get_id( next_packet )); 620 619 }else{ 621 socket_data->incoming = tmp_packet;622 620 while( next_packet ){ 623 621 new_sequence_number += length; … … 939 937 packet_t next; 940 938 packet_t acknowledged = NULL; 941 packet_t first;942 939 uint32_t old; 943 940 … … 981 978 } 982 979 // add to acknowledged or release 983 first = pq_add( acknowledged, packet, 0, 0 ); 984 if( first ){ 985 acknowledged = first; 986 }else{ 980 if( pq_add( & acknowledged, packet, 0, 0 ) != EOK ){ 987 981 pq_release( tcp_globals.net_phone, packet_get_id( packet )); 988 982 } … … 1508 1502 int tcp_queue_packet( socket_core_ref socket, tcp_socket_data_ref socket_data, packet_t packet, size_t data_length ){ 1509 1503 ERROR_DECLARE; 1510 packet_t first;1511 1504 1512 1505 assert( socket ); … … 1516 1509 ERROR_PROPAGATE( tcp_queue_prepare_packet( socket, socket_data, packet, data_length )); 1517 1510 1518 first = pq_add( socket_data->outgoing, packet, socket_data->next_outgoing, data_length ); 1519 if( ! first ){ 1520 return tcp_release_and_return( packet, EINVAL ); 1521 } 1522 socket_data->outgoing = first; 1511 if( ERROR_OCCURRED( pq_add( & socket_data->outgoing, packet, socket_data->next_outgoing, data_length ))){ 1512 return tcp_release_and_return( packet, ERROR_CODE ); 1513 } 1523 1514 socket_data->next_outgoing += data_length; 1524 1515 return EOK; -
uspace/srv/net/tl/tl_common.c
rb8da2a3 rca2d142 89 89 * packet_dimension = malloc( sizeof( ** packet_dimension )); 90 90 if( ! * packet_dimension ) return ENOMEM; 91 if( ERROR_OCCURRED( ip_packet_size_req( ip_phone, device_id, & ( ** packet_dimension ).addr_len, & ( ** packet_dimension ).prefix, & ( ** packet_dimension ).content, & ( ** packet_dimension ).suffix))){91 if( ERROR_OCCURRED( ip_packet_size_req( ip_phone, device_id, * packet_dimension ))){ 92 92 free( * packet_dimension ); 93 93 return ERROR_CODE; -
uspace/srv/net/tl/tl_common.h
rb8da2a3 rca2d142 43 43 #include "../include/inet.h" 44 44 #include "../include/socket_codes.h" 45 46 /** Type definition of the packet dimension.47 * @see packet_dimension48 */49 typedef struct packet_dimension packet_dimension_t;50 51 /** Type definition of the packet dimension pointer.52 * @see packet_dimension53 */54 typedef packet_dimension_t * packet_dimension_ref;55 56 /** Packet dimension.57 */58 struct packet_dimension{59 /** Reserved packet prefix length.60 */61 size_t prefix;62 /** Maximal packet content length.63 */64 size_t content;65 /** Reserved packet suffix length.66 */67 size_t suffix;68 /** Maximal packet address length.69 */70 size_t addr_len;71 };72 45 73 46 /** Device packet dimensions. -
uspace/srv/net/tl/udp/udp.c
rb8da2a3 rca2d142 205 205 } 206 206 // read default packet dimensions 207 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));207 ERROR_PROPAGATE( ip_packet_size_req( udp_globals.ip_phone, -1, & udp_globals.packet_dimension )); 208 208 ERROR_PROPAGATE( socket_ports_initialize( & udp_globals.sockets )); 209 209 if( ERROR_OCCURRED( packet_dimensions_initialize( & udp_globals.dimensions ))){ … … 579 579 // }else{ 580 580 // do not ask all the time 581 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));581 ERROR_PROPAGATE( ip_packet_size_req( udp_globals.ip_phone, -1, & udp_globals.packet_dimension )); 582 582 packet_dimension = & udp_globals.packet_dimension; 583 583 // } … … 604 604 return udp_release_and_return( packet, result ); 605 605 } 606 packet = pq_add( packet, next_packet, index, 0 ); 606 if( ERROR_OCCURRED( pq_add( & packet, next_packet, index, 0 ))){ 607 return udp_release_and_return( packet, ERROR_CODE ); 608 } 607 609 total_length += ( size_t ) result; 608 610 if( udp_globals.checksum_computing ){
Note:
See TracChangeset
for help on using the changeset viewer.