Changes in uspace/srv/net/tl/tl_common.c [aadf01e:91478aa] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/srv/net/tl/tl_common.c
raadf01e r91478aa 55 55 #include "tl_common.h" 56 56 57 DEVICE_MAP_IMPLEMENT(packet_dimensions, packet_dimension_t); 58 59 int tl_get_address_port(const struct sockaddr * addr, int addrlen, uint16_t * port){ 60 const struct sockaddr_in * address_in; 61 const struct sockaddr_in6 * address_in6; 62 63 if((addrlen <= 0) || ((size_t) addrlen < sizeof(struct sockaddr))){ 64 return EINVAL; 65 } 66 switch(addr->sa_family){ 57 DEVICE_MAP_IMPLEMENT( packet_dimensions, packet_dimension_t ); 58 59 int tl_get_address_port( const struct sockaddr * addr, int addrlen, uint16_t * port ){ 60 const struct sockaddr_in * address_in; 61 const struct sockaddr_in6 * address_in6; 62 63 if(( addrlen <= 0 ) || (( size_t ) addrlen < sizeof( struct sockaddr ))) return EINVAL; 64 switch( addr->sa_family ){ 67 65 case AF_INET: 68 if(addrlen != sizeof(struct sockaddr_in)){ 69 return EINVAL; 70 } 71 address_in = (struct sockaddr_in *) addr; 72 *port = ntohs(address_in->sin_port); 66 if( addrlen != sizeof( struct sockaddr_in )) return EINVAL; 67 address_in = ( struct sockaddr_in * ) addr; 68 * port = ntohs( address_in->sin_port ); 73 69 break; 74 70 case AF_INET6: 75 if(addrlen != sizeof(struct sockaddr_in6)){ 76 return EINVAL; 77 } 78 address_in6 = (struct sockaddr_in6 *) addr; 79 *port = ntohs(address_in6->sin6_port); 71 if( addrlen != sizeof( struct sockaddr_in6 )) return EINVAL; 72 address_in6 = ( struct sockaddr_in6 * ) addr; 73 * port = ntohs( address_in6->sin6_port ); 80 74 break; 81 75 default: … … 85 79 } 86 80 87 int tl_get_ip_packet_dimension( int ip_phone, packet_dimensions_ref packet_dimensions, device_id_t device_id, packet_dimension_ref * packet_dimension){81 int tl_get_ip_packet_dimension( int ip_phone, packet_dimensions_ref packet_dimensions, device_id_t device_id, packet_dimension_ref * packet_dimension ){ 88 82 ERROR_DECLARE; 89 83 90 if(! packet_dimension){ 91 return EBADMEM; 92 } 93 94 *packet_dimension = packet_dimensions_find(packet_dimensions, device_id); 95 if(! * packet_dimension){ 84 if( ! packet_dimension ) return EBADMEM; 85 86 * packet_dimension = packet_dimensions_find( packet_dimensions, device_id ); 87 if( ! * packet_dimension ){ 96 88 // ask for and remember them if not found 97 *packet_dimension = malloc(sizeof(** packet_dimension)); 98 if(! * packet_dimension){ 99 return ENOMEM; 100 } 101 if(ERROR_OCCURRED(ip_packet_size_req(ip_phone, device_id, * packet_dimension))){ 102 free(*packet_dimension); 89 * packet_dimension = malloc( sizeof( ** packet_dimension )); 90 if( ! * packet_dimension ) return ENOMEM; 91 if( ERROR_OCCURRED( ip_packet_size_req( ip_phone, device_id, * packet_dimension ))){ 92 free( * packet_dimension ); 103 93 return ERROR_CODE; 104 94 } 105 ERROR_CODE = packet_dimensions_add( packet_dimensions, device_id, * packet_dimension);106 if( ERROR_CODE < 0){107 free( *packet_dimension);95 ERROR_CODE = packet_dimensions_add( packet_dimensions, device_id, * packet_dimension ); 96 if( ERROR_CODE < 0 ){ 97 free( * packet_dimension ); 108 98 return ERROR_CODE; 109 99 } … … 112 102 } 113 103 114 int tl_update_ip_packet_dimension(packet_dimensions_ref packet_dimensions, device_id_t device_id, size_t content){ 115 packet_dimension_ref packet_dimension; 116 117 packet_dimension = packet_dimensions_find(packet_dimensions, device_id); 118 if(! packet_dimension){ 119 return ENOENT; 120 } 104 int tl_update_ip_packet_dimension( packet_dimensions_ref packet_dimensions, device_id_t device_id, size_t content ){ 105 packet_dimension_ref packet_dimension; 106 107 packet_dimension = packet_dimensions_find( packet_dimensions, device_id ); 108 if( ! packet_dimension ) return ENOENT; 121 109 packet_dimension->content = content; 122 if( device_id != DEVICE_INVALID_ID){123 packet_dimension = packet_dimensions_find( packet_dimensions, DEVICE_INVALID_ID);124 if( packet_dimension){125 if( packet_dimension->content >= content){110 if( device_id != DEVICE_INVALID_ID ){ 111 packet_dimension = packet_dimensions_find( packet_dimensions, DEVICE_INVALID_ID ); 112 if( packet_dimension ){ 113 if( packet_dimension->content >= content ){ 126 114 packet_dimension->content = content; 127 115 }else{ 128 packet_dimensions_exclude( packet_dimensions, DEVICE_INVALID_ID);116 packet_dimensions_exclude( packet_dimensions, DEVICE_INVALID_ID ); 129 117 } 130 118 } … … 133 121 } 134 122 135 int tl_set_address_port(struct sockaddr * addr, int addrlen, uint16_t port){ 136 struct sockaddr_in * address_in; 137 struct sockaddr_in6 * address_in6; 138 size_t length; 139 140 if(addrlen < 0){ 141 return EINVAL; 142 } 143 length = (size_t) addrlen; 144 if(length < sizeof(struct sockaddr)){ 145 return EINVAL; 146 } 147 switch(addr->sa_family){ 123 int tl_set_address_port( struct sockaddr * addr, int addrlen, uint16_t port ){ 124 struct sockaddr_in * address_in; 125 struct sockaddr_in6 * address_in6; 126 size_t length; 127 128 if( addrlen < 0 ) return EINVAL; 129 length = ( size_t ) addrlen; 130 if( length < sizeof( struct sockaddr )) return EINVAL; 131 switch( addr->sa_family ){ 148 132 case AF_INET: 149 if(length != sizeof(struct sockaddr_in)){ 150 return EINVAL; 151 } 152 address_in = (struct sockaddr_in *) addr; 153 address_in->sin_port = htons(port); 133 if( length != sizeof( struct sockaddr_in )) return EINVAL; 134 address_in = ( struct sockaddr_in * ) addr; 135 address_in->sin_port = htons( port ); 154 136 return EOK; 155 137 case AF_INET6: 156 if(length != sizeof(struct sockaddr_in6)){ 157 return EINVAL; 158 } 159 address_in6 = (struct sockaddr_in6 *) addr; 160 address_in6->sin6_port = htons(port); 138 if( length != sizeof( struct sockaddr_in6 )) return EINVAL; 139 address_in6 = ( struct sockaddr_in6 * ) addr; 140 address_in6->sin6_port = htons( port ); 161 141 return EOK; 162 142 default: … … 165 145 } 166 146 167 int tl_prepare_icmp_packet( int packet_phone, int icmp_phone, packet_t packet, services_t error){168 packet_t 169 uint8_t * 170 int 147 int tl_prepare_icmp_packet( int packet_phone, int icmp_phone, packet_t packet, services_t error ){ 148 packet_t next; 149 uint8_t * src; 150 int length; 171 151 172 152 // detach the first packet and release the others 173 next = pq_detach( packet);174 if( next){175 pq_release( packet_phone, packet_get_id(next));176 } 177 length = packet_get_addr( packet, &src, NULL);178 if(( length > 0)179 && (! error)180 && (icmp_phone >= 0)153 next = pq_detach( packet ); 154 if( next ){ 155 pq_release( packet_phone, packet_get_id( next )); 156 } 157 length = packet_get_addr( packet, & src, NULL ); 158 if(( length > 0 ) 159 && ( ! error ) 160 && ( icmp_phone >= 0 ) 181 161 // set both addresses to the source one (avoids the source address deletion before setting the destination one) 182 && (packet_set_addr(packet, src, src, (size_t) length) == EOK)){162 && ( packet_set_addr( packet, src, src, ( size_t ) length ) == EOK )){ 183 163 return EOK; 184 164 }else{ 185 pq_release( packet_phone, packet_get_id(packet));165 pq_release( packet_phone, packet_get_id( packet )); 186 166 } 187 167 return ENOENT; 188 168 } 189 169 190 int tl_socket_read_packet_data( int packet_phone, packet_ref packet, size_t prefix, const packet_dimension_ref dimension, const struct sockaddr * addr, socklen_t addrlen){170 int tl_socket_read_packet_data( int packet_phone, packet_ref packet, size_t prefix, const packet_dimension_ref dimension, const struct sockaddr * addr, socklen_t addrlen ){ 191 171 ERROR_DECLARE; 192 172 193 ipc_callid_t callid; 194 size_t length; 195 void * data; 196 197 if(! dimension){ 198 return EINVAL; 199 } 173 ipc_callid_t callid; 174 size_t length; 175 void * data; 176 177 if( ! dimension ) return EINVAL; 200 178 // get the data length 201 if(! async_data_write_receive(&callid, &length)){ 202 return EINVAL; 203 } 179 if( ! async_data_write_receive( & callid, & length )) return EINVAL; 204 180 // get a new packet 205 *packet = packet_get_4(packet_phone, length, dimension->addr_len, prefix + dimension->prefix, dimension->suffix); 206 if(! packet){ 181 * packet = packet_get_4( packet_phone, length, dimension->addr_len, prefix + dimension->prefix, dimension->suffix ); 182 if( ! packet ) return ENOMEM; 183 // allocate space in the packet 184 data = packet_suffix( * packet, length ); 185 if( ! data ){ 186 pq_release( packet_phone, packet_get_id( * packet )); 207 187 return ENOMEM; 208 188 } 209 // allocate space in the packet210 data = packet_suffix(*packet, length);211 if(! data){212 pq_release(packet_phone, packet_get_id(*packet));213 return ENOMEM;214 }215 189 // read the data into the packet 216 if( ERROR_OCCURRED(async_data_write_finalize(callid, data, length))190 if( ERROR_OCCURRED( async_data_write_finalize( callid, data, length )) 217 191 // set the packet destination address 218 || ERROR_OCCURRED(packet_set_addr(*packet, NULL, (uint8_t *) addr, addrlen))){219 pq_release( packet_phone, packet_get_id(*packet));192 || ERROR_OCCURRED( packet_set_addr( * packet, NULL, ( uint8_t * ) addr, addrlen ))){ 193 pq_release( packet_phone, packet_get_id( * packet )); 220 194 return ERROR_CODE; 221 195 } 222 return ( int) length;196 return ( int ) length; 223 197 } 224 198
Note:
See TracChangeset
for help on using the changeset viewer.