Rev 4743 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
| Rev 4743 | Rev 4750 | ||
|---|---|---|---|
| Line 203... | Line 203... | ||
| 203 | } |
203 | } |
| 204 | udp_globals.ip_phone = ip_bind_service( SERVICE_IP, IPPROTO_UDP, SERVICE_UDP, client_connection, udp_received_msg ); |
204 | udp_globals.ip_phone = ip_bind_service( SERVICE_IP, IPPROTO_UDP, SERVICE_UDP, client_connection, udp_received_msg ); |
| 205 | if( udp_globals.ip_phone < 0 ){ |
205 | if( udp_globals.ip_phone < 0 ){ |
| 206 | return udp_globals.ip_phone; |
206 | return udp_globals.ip_phone; |
| 207 | } |
207 | } |
| - | 208 | // read default packet dimensions |
|
| 208 | 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 )); |
209 | 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 )); |
| 209 | ERROR_PROPAGATE( socket_ports_initialize( & udp_globals.sockets )); |
210 | ERROR_PROPAGATE( socket_ports_initialize( & udp_globals.sockets )); |
| - | 211 | if( ERROR_OCCURRED( packet_dimensions_initialize( & udp_globals.dimensions ))){ |
|
| - | 212 | socket_ports_destroy( & udp_globals.sockets ); |
|
| - | 213 | return ERROR_CODE; |
|
| - | 214 | } |
|
| 210 | udp_globals.packet_dimension.prefix += sizeof( udp_header_t ); |
215 | udp_globals.packet_dimension.prefix += sizeof( udp_header_t ); |
| 211 | udp_globals.packet_dimension.content -= sizeof( udp_header_t ); |
216 | udp_globals.packet_dimension.content -= sizeof( udp_header_t ); |
| 212 | udp_globals.last_used_port = UDP_FREE_PORTS_START - 1; |
217 | udp_globals.last_used_port = UDP_FREE_PORTS_START - 1; |
| 213 | // get configuration |
218 | // get configuration |
| 214 | udp_globals.checksum_computing = NET_DEFAULT_UDP_CHECKSUM_COMPUTING; |
219 | udp_globals.checksum_computing = NET_DEFAULT_UDP_CHECKSUM_COMPUTING; |
| Line 523... | Line 528... | ||
| 523 | uint16_t dest_port; |
528 | uint16_t dest_port; |
| 524 | uint32_t checksum; |
529 | uint32_t checksum; |
| 525 | ip_pseudo_header_ref ip_header; |
530 | ip_pseudo_header_ref ip_header; |
| 526 | size_t headerlen; |
531 | size_t headerlen; |
| 527 | device_id_t device_id; |
532 | device_id_t device_id; |
| - | 533 | packet_dimension_ref packet_dimension; |
|
| 528 | 534 | ||
| 529 | ERROR_PROPAGATE( tl_get_address_port( addr, addrlen, & dest_port )); |
535 | ERROR_PROPAGATE( tl_get_address_port( addr, addrlen, & dest_port )); |
| 530 | 536 | ||
| 531 | socket = socket_cores_find( local_sockets, socket_id ); |
537 | socket = socket_cores_find( local_sockets, socket_id ); |
| 532 | if( ! socket ) return ENOTSOCK; |
538 | if( ! socket ) return ENOTSOCK; |
| Line 551... | Line 557... | ||
| 551 | // fibril_rwlock_read_lock( & udp_globals.lock ); |
557 | // fibril_rwlock_read_lock( & udp_globals.lock ); |
| 552 | // might be changed in the meantime |
558 | // might be changed in the meantime |
| 553 | // }while( socket->port <= 0 ); |
559 | // }while( socket->port <= 0 ); |
| 554 | } |
560 | } |
| 555 | 561 | ||
| - | 562 | if( udp_globals.checksum_computing ){ |
|
| - | 563 | if( ERROR_OCCURRED( ip_get_route_req( udp_globals.ip_phone, IPPROTO_UDP, addr, addrlen, & device_id, & ip_header, & headerlen ))){ |
|
| - | 564 | return udp_release_and_return( packet, ERROR_CODE ); |
|
| - | 565 | } |
|
| - | 566 | // get the device packet dimension |
|
| - | 567 | // ERROR_PROPAGATE( tl_get_ip_packet_dimension( udp_globals.ip_phone, & udp_globals.dimensions, device_id, & packet_dimension )); |
|
| - | 568 | } |
|
| - | 569 | // }else{ |
|
| 556 | // TODO do not ask all the time |
570 | // do not ask all the time |
| 557 | 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 )); |
571 | 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 )); |
| - | 572 | packet_dimension = & udp_globals.packet_dimension; |
|
| - | 573 | // } |
|
| 558 | 574 | ||
| 559 | // read the first packet fragment |
575 | // read the first packet fragment |
| 560 | result = tl_socket_read_packet_data( udp_globals.net_phone, & packet, sizeof( udp_header_t ), & udp_globals.packet_dimension, addr, addrlen ); |
576 | result = tl_socket_read_packet_data( udp_globals.net_phone, & packet, sizeof( udp_header_t ), packet_dimension, addr, addrlen ); |
| 561 | if( result < 0 ) return result; |
577 | if( result < 0 ) return result; |
| 562 | total_length = ( size_t ) result; |
578 | total_length = ( size_t ) result; |
| 563 | if( udp_globals.checksum_computing ){ |
579 | if( udp_globals.checksum_computing ){ |
| 564 | checksum = compute_checksum( 0, packet_get_data( packet ), packet_get_data_length( packet )); |
580 | checksum = compute_checksum( 0, packet_get_data( packet ), packet_get_data_length( packet )); |
| 565 | }else{ |
581 | }else{ |
| Line 571... | Line 587... | ||
| 571 | return udp_release_and_return( packet, ENOMEM ); |
587 | return udp_release_and_return( packet, ENOMEM ); |
| 572 | } |
588 | } |
| 573 | bzero( header, sizeof( * header )); |
589 | bzero( header, sizeof( * header )); |
| 574 | // read the rest of the packet fragments |
590 | // read the rest of the packet fragments |
| 575 | for( index = 1; index < fragments; ++ index ){ |
591 | for( index = 1; index < fragments; ++ index ){ |
| 576 | result = tl_socket_read_packet_data( udp_globals.net_phone, & next_packet, 0, & udp_globals.packet_dimension, addr, addrlen ); |
592 | result = tl_socket_read_packet_data( udp_globals.net_phone, & next_packet, 0, packet_dimension, addr, addrlen ); |
| 577 | if( result < 0 ){ |
593 | if( result < 0 ){ |
| 578 | return udp_release_and_return( packet, result ); |
594 | return udp_release_and_return( packet, result ); |
| 579 | } |
595 | } |
| 580 | packet = pq_add( packet, next_packet, index, 0 ); |
596 | packet = pq_add( packet, next_packet, index, 0 ); |
| 581 | total_length += ( size_t ) result; |
597 | total_length += ( size_t ) result; |
| Line 587... | Line 603... | ||
| 587 | header->source_port = htons(( socket->port > 0 ) ? socket->port : 0 ); |
603 | header->source_port = htons(( socket->port > 0 ) ? socket->port : 0 ); |
| 588 | header->destination_port = htons( dest_port ); |
604 | header->destination_port = htons( dest_port ); |
| 589 | header->total_length = htons( total_length + sizeof( * header )); |
605 | header->total_length = htons( total_length + sizeof( * header )); |
| 590 | header->checksum = 0; |
606 | header->checksum = 0; |
| 591 | if( udp_globals.checksum_computing ){ |
607 | if( udp_globals.checksum_computing ){ |
| 592 | if( ERROR_OCCURRED( ip_get_route_req( udp_globals.ip_phone, IPPROTO_UDP, addr, addrlen, & device_id, & ip_header, & headerlen ))){ |
608 | // if( ERROR_OCCURRED( ip_get_route_req( udp_globals.ip_phone, IPPROTO_UDP, addr, addrlen, & device_id, & ip_header, & headerlen ))){ |
| 593 | return udp_release_and_return( packet, ERROR_CODE ); |
609 | // return udp_release_and_return( packet, ERROR_CODE ); |
| 594 | } |
610 | // } |
| 595 | if( ERROR_OCCURRED( ip_client_set_pseudo_header_data_length( ip_header, headerlen, total_length + sizeof( udp_header_t )))){ |
611 | if( ERROR_OCCURRED( ip_client_set_pseudo_header_data_length( ip_header, headerlen, total_length + sizeof( udp_header_t )))){ |
| 596 | free( ip_header ); |
612 | free( ip_header ); |
| 597 | return udp_release_and_return( packet, ERROR_CODE ); |
613 | return udp_release_and_return( packet, ERROR_CODE ); |
| 598 | } |
614 | } |
| 599 | checksum = compute_checksum( checksum, ip_header, headerlen ); |
615 | checksum = compute_checksum( checksum, ip_header, headerlen ); |