Changes in uspace/lib/net/tl/tl_common.c [609243f4:28a3e74] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/net/tl/tl_common.c
r609243f4 r28a3e74 43 43 #include <ip_interface.h> 44 44 #include <tl_remote.h> 45 45 46 #include <net/socket_codes.h> 46 47 #include <net/in.h> … … 49 50 #include <net/device.h> 50 51 #include <net/packet.h> 52 51 53 #include <async.h> 52 54 #include <ipc/services.h> … … 105 107 * The reply is cached then. 106 108 * 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, 121 packet_dimensions_t *packet_dimensions, nic_device_id_t device_id, 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, 122 123 packet_dimension_t **packet_dimension) 123 124 { 125 int rc; 126 124 127 if (!packet_dimension) 125 128 return EBADMEM; … … 130 133 /* Ask for and remember them if not found */ 131 134 *packet_dimension = malloc(sizeof(**packet_dimension)); 132 if 135 if(!*packet_dimension) 133 136 return ENOMEM; 134 137 135 int rc = ip_packet_size_req(sess, device_id, *packet_dimension);138 rc = ip_packet_size_req(ip_phone, device_id, *packet_dimension); 136 139 if (rc != EOK) { 137 140 free(*packet_dimension); … … 160 163 int 161 164 tl_update_ip_packet_dimension(packet_dimensions_t *packet_dimensions, 162 nic_device_id_t device_id, size_t content)165 device_id_t device_id, size_t content) 163 166 { 164 167 packet_dimension_t *packet_dimension; … … 170 173 packet_dimension->content = content; 171 174 172 if (device_id != NIC_DEVICE_INVALID_ID) {175 if (device_id != DEVICE_INVALID_ID) { 173 176 packet_dimension = packet_dimensions_find(packet_dimensions, 174 NIC_DEVICE_INVALID_ID);177 DEVICE_INVALID_ID); 175 178 176 179 if (packet_dimension) { … … 179 182 else 180 183 packet_dimensions_exclude(packet_dimensions, 181 NIC_DEVICE_INVALID_ID, free);184 DEVICE_INVALID_ID, free); 182 185 } 183 186 } … … 233 236 /** Prepares the packet for ICMP error notification. 234 237 * 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 { 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; 254 uint8_t *src; 255 int length; 256 251 257 /* Detach the first packet and release the others */ 252 packet_t *next = pq_detach(packet);258 next = pq_detach(packet); 253 259 if (next) 254 pq_release_remote(packet_sess, packet_get_id(next)); 255 256 uint8_t *src; 257 int length = packet_get_addr(packet, &src, NULL); 258 if ((length > 0) && (!error) && (icmp_sess) && 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) && 259 264 /* 260 265 * Set both addresses to the source one (avoids the source address … … 264 269 return EOK; 265 270 } else 266 pq_release_remote(packet_ sess, packet_get_id(packet));267 271 pq_release_remote(packet_phone, packet_get_id(packet)); 272 268 273 return ENOENT; 269 274 } … … 271 276 /** Receives data from the socket into a packet. 272 277 * 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) 278 * @param[in] packet_phone The packet server module phone. 279 * @param[out] packet The new created packet. 280 * @param[in] prefix Reserved packet data prefix length. 281 * @param[in] dimension The packet dimension. 282 * @param[in] addr The destination address. 283 * @param[in] addrlen The address length. 284 * @return Number of bytes received. 285 * @return EINVAL if the client does not send data. 286 * @return ENOMEM if there is not enough memory left. 287 * @return Other error codes as defined for the 288 * async_data_read_finalize() function. 289 */ 290 int 291 tl_socket_read_packet_data(int packet_phone, packet_t **packet, size_t prefix, 292 const packet_dimension_t *dimension, const struct sockaddr *addr, 293 socklen_t addrlen) 290 294 { 291 295 ipc_callid_t callid; … … 302 306 303 307 /* Get a new packet */ 304 *packet = packet_get_4_remote( sess, length, dimension->addr_len,308 *packet = packet_get_4_remote(packet_phone, length, dimension->addr_len, 305 309 prefix + dimension->prefix, dimension->suffix); 306 310 if (!packet) … … 310 314 data = packet_suffix(*packet, length); 311 315 if (!data) { 312 pq_release_remote( sess, packet_get_id(*packet));316 pq_release_remote(packet_phone, packet_get_id(*packet)); 313 317 return ENOMEM; 314 318 } … … 317 321 rc = async_data_write_finalize(callid, data, length); 318 322 if (rc != EOK) { 319 pq_release_remote( sess, packet_get_id(*packet));323 pq_release_remote(packet_phone, packet_get_id(*packet)); 320 324 return rc; 321 325 } … … 324 328 rc = packet_set_addr(*packet, NULL, (uint8_t *) addr, addrlen); 325 329 if (rc != EOK) { 326 pq_release_remote( sess, packet_get_id(*packet));330 pq_release_remote(packet_phone, packet_get_id(*packet)); 327 331 return rc; 328 332 }
Note:
See TracChangeset
for help on using the changeset viewer.