Changes in uspace/lib/net/tl/tl_common.c [e526f08:46d4d9f] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/net/tl/tl_common.c
re526f08 r46d4d9f 27 27 */ 28 28 29 /** @addtogroup net_tl30 * 29 /** @addtogroup libnet 30 * @{ 31 31 */ 32 32 33 33 /** @file 34 * Transport layer common functions implementation. 35 * @see tl_common.h 36 */ 34 * Transport layer common functions implementation. 35 * @see tl_common.h 36 */ 37 38 #include <tl_common.h> 39 #include <packet_client.h> 40 #include <packet_remote.h> 41 #include <icmp_interface.h> 42 #include <ip_remote.h> 43 #include <ip_interface.h> 44 #include <tl_interface.h> 37 45 38 46 #include <net/socket_codes.h> … … 40 48 #include <net/in6.h> 41 49 #include <net/inet.h> 50 #include <net/device.h> 51 #include <net/packet.h> 52 42 53 #include <async.h> 43 54 #include <ipc/services.h> 44 55 #include <errno.h> 45 #include <err.h>46 47 #include <net/packet.h>48 #include <packet_client.h>49 #include <packet_remote.h>50 #include <net/device.h>51 #include <icmp_interface.h>52 #include <ip_remote.h>53 #include <ip_interface.h>54 #include <tl_interface.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 address 68 * family. 69 * @return EAFNOSUPPORT if the address family is not supported. 70 */ 59 71 int 60 72 tl_get_address_port(const struct sockaddr *addr, int addrlen, uint16_t *port) … … 74 86 *port = ntohs(address_in->sin_port); 75 87 break; 88 76 89 case AF_INET6: 77 90 if (addrlen != sizeof(struct sockaddr_in6)) 78 91 return EINVAL; 79 92 80 93 address_in6 = (struct sockaddr_in6 *) addr; 81 94 *port = ntohs(address_in6->sin6_port); 82 95 break; 96 83 97 default: 84 98 return EAFNOSUPPORT; … … 93 107 * The reply is cached then. 94 108 * 95 * @param[in] ip_phoneThe IP moduel phone for (semi)remote calls.96 * @param[in] 97 * @param[in] device_idThe device identifier.98 * @param[out] packet_dimension 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 inttl_get_ip_packet_dimension(int ip_phone,108 packet_dimensions_ refpacket_dimensions, device_id_t device_id,109 packet_dimension_ ref*packet_dimension)110 { 111 ERROR_DECLARE;109 * @param[in] ip_phone The IP moduel phone for (semi)remote calls. 110 * @param[in] packet_dimensions The packet dimensions cache. 111 * @param[in] device_id The 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 * function. 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; 112 126 113 127 if (!packet_dimension) … … 122 136 return ENOMEM; 123 137 124 if (ERROR_OCCURRED(ip_packet_size_req(ip_phone, device_id,125 *packet_dimension))) {138 rc = ip_packet_size_req(ip_phone, device_id, *packet_dimension); 139 if (rc != EOK) { 126 140 free(*packet_dimension); 127 return ERROR_CODE;141 return rc; 128 142 } 129 143 130 ERROR_CODE= packet_dimensions_add(packet_dimensions, device_id,144 rc = packet_dimensions_add(packet_dimensions, device_id, 131 145 *packet_dimension); 132 if ( ERROR_CODE< 0) {146 if (rc < 0) { 133 147 free(*packet_dimension); 134 return ERROR_CODE;148 return rc; 135 149 } 136 150 } … … 139 153 } 140 154 141 int 142 tl_update_ip_packet_dimension(packet_dimensions_ref packet_dimensions, 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, 143 165 device_id_t device_id, size_t content) 144 166 { 145 packet_dimension_ refpacket_dimension;167 packet_dimension_t *packet_dimension; 146 168 147 169 packet_dimension = packet_dimensions_find(packet_dimensions, device_id); 148 170 if (!packet_dimension) 149 171 return ENOENT; 172 150 173 packet_dimension->content = content; 151 174 … … 160 183 packet_dimensions_exclude(packet_dimensions, 161 184 DEVICE_INVALID_ID); 162 163 185 } 164 186 } … … 167 189 } 168 190 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 address 200 * family. 201 * @return EAFNOSUPPORT if the address family is not supported. 202 */ 169 203 int tl_set_address_port(struct sockaddr * addr, int addrlen, uint16_t port) 170 204 { … … 187 221 address_in->sin_port = htons(port); 188 222 return EOK; 223 189 224 case AF_INET6: 190 225 if (length != sizeof(struct sockaddr_in6)) … … 193 228 address_in6->sin6_port = htons(port); 194 229 return EOK; 230 195 231 default: 196 232 return EAFNOSUPPORT; … … 198 234 } 199 235 200 int 201 tl_prepare_icmp_packet(int packet_phone, int icmp_phone, packet_t packet, 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, 202 251 services_t error) 203 252 { 204 packet_t next;253 packet_t *next; 205 254 uint8_t *src; 206 255 int length; … … 223 272 } 224 273 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, 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, 228 291 socklen_t addrlen) 229 292 { 230 ERROR_DECLARE;231 232 293 ipc_callid_t callid; 233 294 size_t length; 234 void * data; 295 void *data; 296 int rc; 235 297 236 298 if (!dimension) … … 255 317 256 318 // read the data into the packet 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))) { 319 rc = async_data_write_finalize(callid, data, length); 320 if (rc != EOK) { 261 321 pq_release_remote(packet_phone, packet_get_id(*packet)); 262 return ERROR_CODE; 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; 263 330 } 264 331
Note:
See TracChangeset
for help on using the changeset viewer.