Changes in uspace/lib/net/tl/tl_common.c [f1938c6:6b82009] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/net/tl/tl_common.c
rf1938c6 r6b82009 43 43 #include <ip_interface.h> 44 44 #include <tl_remote.h> 45 46 45 #include <net/socket_codes.h> 47 46 #include <net/in.h> … … 50 49 #include <net/device.h> 51 50 #include <net/packet.h> 52 53 51 #include <async.h> 54 52 #include <ipc/services.h> … … 107 105 * The reply is cached then. 108 106 * 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, 107 * @param[in] sess IP module session. 108 * @param[in] packet_dimensions Packet dimensions cache. 109 * @param[in] device_id Device identifier. 110 * @param[out] packet_dimension IP packet dimensions. 111 * 112 * @return EOK on success. 113 * @return EBADMEM if the packet_dimension parameter is NULL. 114 * @return ENOMEM if there is not enough memory left. 115 * @return EINVAL if the packet_dimensions cache is not valid. 116 * @return Other codes as defined for the ip_packet_size_req() 117 * function. 118 * 119 */ 120 int tl_get_ip_packet_dimension(async_sess_t *sess, 122 121 packet_dimensions_t *packet_dimensions, device_id_t device_id, 123 122 packet_dimension_t **packet_dimension) 124 123 { 125 int rc;126 127 124 if (!packet_dimension) 128 125 return EBADMEM; … … 133 130 /* Ask for and remember them if not found */ 134 131 *packet_dimension = malloc(sizeof(**packet_dimension)); 135 if (!*packet_dimension)132 if (!*packet_dimension) 136 133 return ENOMEM; 137 134 138 rc = ip_packet_size_req(ip_phone, device_id, *packet_dimension);135 int rc = ip_packet_size_req(sess, device_id, *packet_dimension); 139 136 if (rc != EOK) { 140 137 free(*packet_dimension); … … 182 179 else 183 180 packet_dimensions_exclude(packet_dimensions, 184 DEVICE_INVALID_ID );181 DEVICE_INVALID_ID, free); 185 182 } 186 183 } … … 236 233 /** Prepares the packet for ICMP error notification. 237 234 * 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, 251 services_t error) 252 { 253 packet_t *next; 235 * Keep the first packet and release all the others. 236 * Release all the packets on error. 237 * 238 * @param[in] packet_sess Packet server module session. 239 * @param[in] icmp_sess ICMP module phone. 240 * @param[in] packet Packet to be send. 241 * @param[in] error Packet error reporting service. Prefixes the 242 * received packet. 243 * 244 * @return EOK on success. 245 * @return ENOENT if no packet may be sent. 246 * 247 */ 248 int tl_prepare_icmp_packet(async_sess_t *packet_sess, async_sess_t *icmp_sess, 249 packet_t *packet, services_t error) 250 { 251 /* Detach the first packet and release the others */ 252 packet_t *next = pq_detach(packet); 253 if (next) 254 pq_release_remote(packet_sess, packet_get_id(next)); 255 254 256 uint8_t *src; 255 int length; 256 257 // detach the first packet and release the others 258 next = pq_detach(packet); 259 if (next) 260 pq_release_remote(packet_phone, packet_get_id(next)); 261 262 length = packet_get_addr(packet, &src, NULL); 263 if ((length > 0) && (!error) && (icmp_phone >= 0) && 264 // set both addresses to the source one (avoids the source address 265 // deletion before setting the destination one) 257 int length = packet_get_addr(packet, &src, NULL); 258 if ((length > 0) && (!error) && (icmp_sess) && 259 /* 260 * Set both addresses to the source one (avoids the source address 261 * deletion before setting the destination one) 262 */ 266 263 (packet_set_addr(packet, src, src, (size_t) length) == EOK)) { 267 264 return EOK; 268 265 } else 269 pq_release_remote(packet_ phone, packet_get_id(packet));270 266 pq_release_remote(packet_sess, packet_get_id(packet)); 267 271 268 return ENOENT; 272 269 } … … 274 271 /** Receives data from the socket into a packet. 275 272 * 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, 291 socklen_t addrlen) 273 * @param[in] sess Packet server module session. 274 * @param[out] packet New created packet. 275 * @param[in] prefix Reserved packet data prefix length. 276 * @param[in] dimension Packet dimension. 277 * @param[in] addr Destination address. 278 * @param[in] addrlen Address length. 279 * 280 * @return Number of bytes received. 281 * @return EINVAL if the client does not send data. 282 * @return ENOMEM if there is not enough memory left. 283 * @return Other error codes as defined for the 284 * async_data_read_finalize() function. 285 * 286 */ 287 int tl_socket_read_packet_data(async_sess_t *sess, packet_t **packet, 288 size_t prefix, const packet_dimension_t *dimension, 289 const struct sockaddr *addr, socklen_t addrlen) 292 290 { 293 291 ipc_callid_t callid; … … 299 297 return EINVAL; 300 298 301 / / get the data length299 /* Get the data length */ 302 300 if (!async_data_write_receive(&callid, &length)) 303 301 return EINVAL; 304 302 305 / / get a new packet306 *packet = packet_get_4_remote( packet_phone, length, dimension->addr_len,303 /* Get a new packet */ 304 *packet = packet_get_4_remote(sess, length, dimension->addr_len, 307 305 prefix + dimension->prefix, dimension->suffix); 308 306 if (!packet) 309 307 return ENOMEM; 310 308 311 / / allocate space in the packet309 /* Allocate space in the packet */ 312 310 data = packet_suffix(*packet, length); 313 311 if (!data) { 314 pq_release_remote( packet_phone, packet_get_id(*packet));312 pq_release_remote(sess, packet_get_id(*packet)); 315 313 return ENOMEM; 316 314 } 317 315 318 / / read the data into the packet316 /* Read the data into the packet */ 319 317 rc = async_data_write_finalize(callid, data, length); 320 318 if (rc != EOK) { 321 pq_release_remote( packet_phone, packet_get_id(*packet));319 pq_release_remote(sess, packet_get_id(*packet)); 322 320 return rc; 323 321 } 324 322 325 / / set the packet destination address323 /* Set the packet destination address */ 326 324 rc = packet_set_addr(*packet, NULL, (uint8_t *) addr, addrlen); 327 325 if (rc != EOK) { 328 pq_release_remote( packet_phone, packet_get_id(*packet));326 pq_release_remote(sess, packet_get_id(*packet)); 329 327 return rc; 330 328 }
Note:
See TracChangeset
for help on using the changeset viewer.