Changes in uspace/lib/net/tl/tl_common.c [46d4d9f:e526f08] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/net/tl/tl_common.c
r46d4d9f re526f08 27 27 */ 28 28 29 /** @addtogroup libnet30 * @{29 /** @addtogroup net_tl 30 * @{ 31 31 */ 32 32 33 33 /** @file 34 * Transport layer common functions implementation. 35 * @see tl_common.h 36 */ 37 38 #include <tl_common.h> 34 * Transport layer common functions implementation. 35 * @see tl_common.h 36 */ 37 38 #include <net/socket_codes.h> 39 #include <net/in.h> 40 #include <net/in6.h> 41 #include <net/inet.h> 42 #include <async.h> 43 #include <ipc/services.h> 44 #include <errno.h> 45 #include <err.h> 46 47 #include <net/packet.h> 39 48 #include <packet_client.h> 40 49 #include <packet_remote.h> 50 #include <net/device.h> 41 51 #include <icmp_interface.h> 42 52 #include <ip_remote.h> 43 53 #include <ip_interface.h> 44 54 #include <tl_interface.h> 45 46 #include <net/socket_codes.h> 47 #include <net/in.h> 48 #include <net/in6.h> 49 #include <net/inet.h> 50 #include <net/device.h> 51 #include <net/packet.h> 52 53 #include <async.h> 54 #include <ipc/services.h> 55 #include <errno.h> 55 #include <tl_common.h> 56 56 57 57 DEVICE_MAP_IMPLEMENT(packet_dimensions, packet_dimension_t); 58 58 59 /** Gets the address port.60 *61 * Supports AF_INET and AF_INET6 address families.62 *63 * @param[in,out] addr The address to be updated.64 * @param[in] addrlen The address length.65 * @param[out] port The set port.66 * @return EOK on success.67 * @return EINVAL if the address length does not match the address68 * family.69 * @return EAFNOSUPPORT if the address family is not supported.70 */71 59 int 72 60 tl_get_address_port(const struct sockaddr *addr, int addrlen, uint16_t *port) … … 86 74 *port = ntohs(address_in->sin_port); 87 75 break; 88 89 76 case AF_INET6: 90 77 if (addrlen != sizeof(struct sockaddr_in6)) 91 return EINVAL;78 return EINVAL; 92 79 93 80 address_in6 = (struct sockaddr_in6 *) addr; 94 81 *port = ntohs(address_in6->sin6_port); 95 82 break; 96 97 83 default: 98 84 return EAFNOSUPPORT; … … 107 93 * The reply is cached then. 108 94 * 109 * @param[in] ip_phoneThe IP moduel phone for (semi)remote calls.110 * @param[in] packet_dimensions The packet dimensions cache.111 * @param[in] device_idThe device identifier.112 * @param[out] packet_dimension The IP packet dimensions.113 * @return EOK on success.114 * @return EBADMEM if the packet_dimension parameter is NULL.115 * @return ENOMEM if there is not enough memory left.116 * @return EINVAL if the packet_dimensions cache is not valid.117 * @return Other codes as defined for the ip_packet_size_req()118 * 119 * /120 int 121 tl_get_ip_packet_dimension(int ip_phone,122 packet_dimensions_ t *packet_dimensions, device_id_t device_id,123 packet_dimension_ t **packet_dimension)124 { 125 int rc;95 * @param[in] ip_phone The IP moduel phone for (semi)remote calls. 96 * @param[in] packet_dimensions The packet dimensions cache. 97 * @param[in] device_id The device identifier. 98 * @param[out] packet_dimension The IP packet dimensions. 99 * 100 * @return EOK on success. 101 * @return EBADMEM if the packet_dimension parameter is NULL. 102 * @return ENOMEM if there is not enough memory left. 103 * @return EINVAL if the packet_dimensions cache is not valid. 104 * @return Other codes as defined for the ip_packet_size_req() function. 105 * 106 */ 107 int tl_get_ip_packet_dimension(int ip_phone, 108 packet_dimensions_ref packet_dimensions, device_id_t device_id, 109 packet_dimension_ref *packet_dimension) 110 { 111 ERROR_DECLARE; 126 112 127 113 if (!packet_dimension) … … 136 122 return ENOMEM; 137 123 138 rc = ip_packet_size_req(ip_phone, device_id, *packet_dimension);139 if (rc != EOK) {124 if (ERROR_OCCURRED(ip_packet_size_req(ip_phone, device_id, 125 *packet_dimension))) { 140 126 free(*packet_dimension); 141 return rc;127 return ERROR_CODE; 142 128 } 143 129 144 rc= packet_dimensions_add(packet_dimensions, device_id,130 ERROR_CODE = packet_dimensions_add(packet_dimensions, device_id, 145 131 *packet_dimension); 146 if ( rc< 0) {132 if (ERROR_CODE < 0) { 147 133 free(*packet_dimension); 148 return rc;134 return ERROR_CODE; 149 135 } 150 136 } … … 153 139 } 154 140 155 /** Updates IP device packet dimensions cache. 156 * 157 * @param[in,out] packet_dimensions The packet dimensions cache. 158 * @param[in] device_id The device identifier. 159 * @param[in] content The new maximum content size. 160 * @return EOK on success. 161 * @return ENOENT if the packet dimension is not cached. 162 */ 163 int 164 tl_update_ip_packet_dimension(packet_dimensions_t *packet_dimensions, 141 int 142 tl_update_ip_packet_dimension(packet_dimensions_ref packet_dimensions, 165 143 device_id_t device_id, size_t content) 166 144 { 167 packet_dimension_ t *packet_dimension;145 packet_dimension_ref packet_dimension; 168 146 169 147 packet_dimension = packet_dimensions_find(packet_dimensions, device_id); 170 148 if (!packet_dimension) 171 149 return ENOENT; 172 173 150 packet_dimension->content = content; 174 151 … … 183 160 packet_dimensions_exclude(packet_dimensions, 184 161 DEVICE_INVALID_ID); 162 185 163 } 186 164 } … … 189 167 } 190 168 191 /** Sets the address port.192 *193 * Supports AF_INET and AF_INET6 address families.194 *195 * @param[in,out] addr The address to be updated.196 * @param[in] addrlen The address length.197 * @param[in] port The port to be set.198 * @return EOK on success.199 * @return EINVAL if the address length does not match the address200 * family.201 * @return EAFNOSUPPORT if the address family is not supported.202 */203 169 int tl_set_address_port(struct sockaddr * addr, int addrlen, uint16_t port) 204 170 { … … 221 187 address_in->sin_port = htons(port); 222 188 return EOK; 223 224 189 case AF_INET6: 225 190 if (length != sizeof(struct sockaddr_in6)) … … 228 193 address_in6->sin6_port = htons(port); 229 194 return EOK; 230 231 195 default: 232 196 return EAFNOSUPPORT; … … 234 198 } 235 199 236 /** Prepares the packet for ICMP error notification. 237 * 238 * Keeps the first packet and releases all the others. 239 * Releases all the packets on error. 240 * 241 * @param[in] packet_phone The packet server module phone. 242 * @param[in] icmp_phone The ICMP module phone. 243 * @param[in] packet The packet to be send. 244 * @param[in] error The packet error reporting service. Prefixes the 245 * received packet. 246 * @return EOK on success. 247 * @return ENOENT if no packet may be sent. 248 */ 249 int 250 tl_prepare_icmp_packet(int packet_phone, int icmp_phone, packet_t *packet, 200 int 201 tl_prepare_icmp_packet(int packet_phone, int icmp_phone, packet_t packet, 251 202 services_t error) 252 203 { 253 packet_t *next;204 packet_t next; 254 205 uint8_t *src; 255 206 int length; … … 272 223 } 273 224 274 /** Receives data from the socket into a packet. 275 * 276 * @param[in] packet_phone The packet server module phone. 277 * @param[out] packet The new created packet. 278 * @param[in] prefix Reserved packet data prefix length. 279 * @param[in] dimension The packet dimension. 280 * @param[in] addr The destination address. 281 * @param[in] addrlen The address length. 282 * @return Number of bytes received. 283 * @return EINVAL if the client does not send data. 284 * @return ENOMEM if there is not enough memory left. 285 * @return Other error codes as defined for the 286 * async_data_read_finalize() function. 287 */ 288 int 289 tl_socket_read_packet_data(int packet_phone, packet_t **packet, size_t prefix, 290 const packet_dimension_t *dimension, const struct sockaddr *addr, 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, 291 228 socklen_t addrlen) 292 229 { 230 ERROR_DECLARE; 231 293 232 ipc_callid_t callid; 294 233 size_t length; 295 void *data; 296 int rc; 234 void * data; 297 235 298 236 if (!dimension) … … 317 255 318 256 // read the data into the packet 319 rc = async_data_write_finalize(callid, data, length); 320 if (rc != EOK) { 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))) { 321 261 pq_release_remote(packet_phone, packet_get_id(*packet)); 322 return rc; 323 } 324 325 // set the packet destination address 326 rc = packet_set_addr(*packet, NULL, (uint8_t *) addr, addrlen); 327 if (rc != EOK) { 328 pq_release_remote(packet_phone, packet_get_id(*packet)); 329 return rc; 262 return ERROR_CODE; 330 263 } 331 264
Note:
See TracChangeset
for help on using the changeset viewer.