Changeset f14291b in mainline for uspace/lib/net/tl/tl_common.c
- Timestamp:
- 2010-10-19T20:55:53Z (14 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- a93d79a
- Parents:
- 1882525 (diff), a7a85d16 (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. - File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/net/tl/tl_common.c
r1882525 rf14291b 36 36 */ 37 37 38 #include <net/socket_codes.h> 39 #include <net/in.h> 40 #include <net/in6.h> 41 #include <net/inet.h> 38 42 #include <async.h> 39 43 #include <ipc/services.h> 40 41 #include <net_err.h> 42 #include <packet/packet.h> 43 #include <packet/packet_client.h> 44 #include <errno.h> 45 #include <err.h> 46 47 #include <net/packet.h> 48 #include <packet_client.h> 44 49 #include <packet_remote.h> 45 #include <net _device.h>50 #include <net/device.h> 46 51 #include <icmp_interface.h> 47 #include <in.h>48 #include <in6.h>49 #include <inet.h>50 #include <ip_local.h>51 52 #include <ip_remote.h> 52 #include <socket_codes.h>53 #include <socket_errno.h>54 53 #include <ip_interface.h> 55 54 #include <tl_interface.h> … … 58 57 DEVICE_MAP_IMPLEMENT(packet_dimensions, packet_dimension_t); 59 58 60 int tl_get_address_port(const struct sockaddr * addr, int addrlen, uint16_t * port){ 61 const struct sockaddr_in * address_in; 62 const struct sockaddr_in6 * address_in6; 63 64 if((addrlen <= 0) || ((size_t) addrlen < sizeof(struct sockaddr))){ 65 return EINVAL; 66 } 67 switch(addr->sa_family){ 68 case AF_INET: 69 if(addrlen != sizeof(struct sockaddr_in)){ 59 int 60 tl_get_address_port(const struct sockaddr *addr, int addrlen, uint16_t *port) 61 { 62 const struct sockaddr_in *address_in; 63 const struct sockaddr_in6 *address_in6; 64 65 if ((addrlen <= 0) || ((size_t) addrlen < sizeof(struct sockaddr))) 66 return EINVAL; 67 68 switch (addr->sa_family) { 69 case AF_INET: 70 if (addrlen != sizeof(struct sockaddr_in)) 71 return EINVAL; 72 73 address_in = (struct sockaddr_in *) addr; 74 *port = ntohs(address_in->sin_port); 75 break; 76 case AF_INET6: 77 if (addrlen != sizeof(struct sockaddr_in6)) 70 78 return EINVAL; 71 } 72 address_in = (struct sockaddr_in *) addr; 73 *port = ntohs(address_in->sin_port); 74 break; 75 case AF_INET6: 76 if(addrlen != sizeof(struct sockaddr_in6)){ 77 return EINVAL; 78 } 79 address_in6 = (struct sockaddr_in6 *) addr; 80 *port = ntohs(address_in6->sin6_port); 81 break; 82 default: 83 return EAFNOSUPPORT; 84 } 79 80 address_in6 = (struct sockaddr_in6 *) addr; 81 *port = ntohs(address_in6->sin6_port); 82 break; 83 default: 84 return EAFNOSUPPORT; 85 } 86 85 87 return EOK; 86 88 } … … 112 114 return EBADMEM; 113 115 114 *packet_dimension = packet_dimensions_find(packet_dimensions, device_id); 116 *packet_dimension = packet_dimensions_find(packet_dimensions, 117 device_id); 115 118 if (!*packet_dimension) { 116 119 /* Ask for and remember them if not found */ … … 136 139 } 137 140 138 int tl_update_ip_packet_dimension(packet_dimensions_ref packet_dimensions, device_id_t device_id, size_t content){ 141 int 142 tl_update_ip_packet_dimension(packet_dimensions_ref packet_dimensions, 143 device_id_t device_id, size_t content) 144 { 139 145 packet_dimension_ref packet_dimension; 140 146 141 147 packet_dimension = packet_dimensions_find(packet_dimensions, device_id); 142 if (! packet_dimension){148 if (!packet_dimension) 143 149 return ENOENT; 144 }145 150 packet_dimension->content = content; 146 if(device_id != DEVICE_INVALID_ID){ 147 packet_dimension = packet_dimensions_find(packet_dimensions, DEVICE_INVALID_ID); 148 if(packet_dimension){ 149 if(packet_dimension->content >= content){ 151 152 if (device_id != DEVICE_INVALID_ID) { 153 packet_dimension = packet_dimensions_find(packet_dimensions, 154 DEVICE_INVALID_ID); 155 156 if (packet_dimension) { 157 if (packet_dimension->content >= content) 150 158 packet_dimension->content = content; 151 }else{ 152 packet_dimensions_exclude(packet_dimensions, DEVICE_INVALID_ID); 153 } 159 else 160 packet_dimensions_exclude(packet_dimensions, 161 DEVICE_INVALID_ID); 162 154 163 } 155 164 } 165 156 166 return EOK; 157 167 } 158 168 159 int tl_set_address_port(struct sockaddr * addr, int addrlen, uint16_t port){ 160 struct sockaddr_in * address_in; 161 struct sockaddr_in6 * address_in6; 169 int tl_set_address_port(struct sockaddr * addr, int addrlen, uint16_t port) 170 { 171 struct sockaddr_in *address_in; 172 struct sockaddr_in6 *address_in6; 162 173 size_t length; 163 174 164 if (addrlen < 0){165 return EINVAL; 166 }175 if (addrlen < 0) 176 return EINVAL; 177 167 178 length = (size_t) addrlen; 168 if(length < sizeof(struct sockaddr)){ 169 return EINVAL; 170 } 171 switch(addr->sa_family){ 172 case AF_INET: 173 if(length != sizeof(struct sockaddr_in)){ 179 if (length < sizeof(struct sockaddr)) 180 return EINVAL; 181 182 switch (addr->sa_family) { 183 case AF_INET: 184 if (length != sizeof(struct sockaddr_in)) 185 return EINVAL; 186 address_in = (struct sockaddr_in *) addr; 187 address_in->sin_port = htons(port); 188 return EOK; 189 case AF_INET6: 190 if (length != sizeof(struct sockaddr_in6)) 174 191 return EINVAL; 175 } 176 address_in = (struct sockaddr_in *) addr; 177 address_in->sin_port = htons(port); 178 return EOK; 179 case AF_INET6: 180 if(length != sizeof(struct sockaddr_in6)){ 181 return EINVAL; 182 } 183 address_in6 = (struct sockaddr_in6 *) addr; 184 address_in6->sin6_port = htons(port); 185 return EOK; 186 default: 187 return EAFNOSUPPORT; 188 } 189 } 190 191 int tl_prepare_icmp_packet(int packet_phone, int icmp_phone, packet_t packet, services_t error){ 192 address_in6 = (struct sockaddr_in6 *) addr; 193 address_in6->sin6_port = htons(port); 194 return EOK; 195 default: 196 return EAFNOSUPPORT; 197 } 198 } 199 200 int 201 tl_prepare_icmp_packet(int packet_phone, int icmp_phone, packet_t packet, 202 services_t error) 203 { 192 204 packet_t next; 193 uint8_t * 205 uint8_t *src; 194 206 int length; 195 207 … … 200 212 201 213 length = packet_get_addr(packet, &src, NULL); 202 if((length > 0) 203 && (! error) 204 && (icmp_phone >= 0) 205 // set both addresses to the source one (avoids the source address deletion before setting the destination one) 206 && (packet_set_addr(packet, src, src, (size_t) length) == EOK)){ 214 if ((length > 0) && (!error) && (icmp_phone >= 0) && 215 // set both addresses to the source one (avoids the source address 216 // deletion before setting the destination one) 217 (packet_set_addr(packet, src, src, (size_t) length) == EOK)) { 207 218 return EOK; 208 } else{219 } else 209 220 pq_release_remote(packet_phone, packet_get_id(packet)); 210 } 221 211 222 return ENOENT; 212 223 } 213 224 214 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){ 225 int 226 tl_socket_read_packet_data(int packet_phone, packet_ref packet, size_t prefix, 227 const packet_dimension_ref dimension, const struct sockaddr *addr, 228 socklen_t addrlen) 229 { 215 230 ERROR_DECLARE; 216 231 … … 219 234 void * data; 220 235 221 if (! dimension){222 return EINVAL; 223 } 236 if (!dimension) 237 return EINVAL; 238 224 239 // get the data length 225 if (! async_data_write_receive(&callid, &length)){226 return EINVAL; 227 } 240 if (!async_data_write_receive(&callid, &length)) 241 return EINVAL; 242 228 243 // get a new packet 229 *packet = packet_get_4_remote(packet_phone, length, dimension->addr_len, prefix + dimension->prefix, dimension->suffix); 230 if(! packet){ 244 *packet = packet_get_4_remote(packet_phone, length, dimension->addr_len, 245 prefix + dimension->prefix, dimension->suffix); 246 if (!packet) 231 247 return ENOMEM; 232 } 248 233 249 // allocate space in the packet 234 250 data = packet_suffix(*packet, length); 235 if (! data){251 if (!data) { 236 252 pq_release_remote(packet_phone, packet_get_id(*packet)); 237 253 return ENOMEM; 238 254 } 255 239 256 // read the data into the packet 240 if(ERROR_OCCURRED(async_data_write_finalize(callid, data, length)) 241 // set the packet destination address 242 || ERROR_OCCURRED(packet_set_addr(*packet, NULL, (uint8_t *) addr, addrlen))){ 257 if (ERROR_OCCURRED(async_data_write_finalize(callid, data, length)) || 258 // set the packet destination address 259 ERROR_OCCURRED(packet_set_addr(*packet, NULL, (uint8_t *) addr, 260 addrlen))) { 243 261 pq_release_remote(packet_phone, packet_get_id(*packet)); 244 262 return ERROR_CODE; 245 263 } 264 246 265 return (int) length; 247 266 }
Note:
See TracChangeset
for help on using the changeset viewer.