Changeset 2f19103 in mainline for uspace/srv/net/udp
- Timestamp:
- 2015-05-22T07:21:37Z (10 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 58e9dec
- Parents:
- bf7587b0
- Location:
- uspace/srv/net/udp
- Files:
-
- 9 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/srv/net/udp/assoc.c
rbf7587b0 r2f19103 1 1 /* 2 * Copyright (c) 201 2Jiri Svoboda2 * Copyright (c) 2015 Jiri Svoboda 3 3 * All rights reserved. 4 4 * … … 52 52 FIBRIL_MUTEX_INITIALIZE(assoc_list_lock); 53 53 54 static udp_assoc_t *udp_assoc_find_ref( udp_sockpair_t *);55 static int udp_assoc_queue_msg(udp_assoc_t *, udp_sockpair_t *, udp_msg_t *);56 static bool udp_ socket_match(udp_sock_t *, udp_sock_t *);57 static bool udp_ sockpair_match(udp_sockpair_t *, udp_sockpair_t *);54 static udp_assoc_t *udp_assoc_find_ref(inet_ep2_t *); 55 static int udp_assoc_queue_msg(udp_assoc_t *, inet_ep2_t *, udp_msg_t *); 56 static bool udp_ep_match(inet_ep_t *, inet_ep_t *); 57 static bool udp_ep2_match(inet_ep2_t *, inet_ep2_t *); 58 58 59 59 /** Create new association structure. 60 60 * 61 * @param lsock Local socket (will be deeply copied) 62 * @param fsock Foreign socket (will be deeply copied) 61 * @param epp Endpoint pair (will be copied) 62 * @param cb Callbacks 63 * @param cb_arg Callback argument 63 64 * @return New association or NULL 64 65 */ 65 udp_assoc_t *udp_assoc_new(udp_sock_t *lsock, udp_sock_t *fsock, 66 udp_assoc_cb_t *cb, void *cb_arg) 66 udp_assoc_t *udp_assoc_new(inet_ep2_t *epp, udp_assoc_cb_t *cb, void *cb_arg) 67 67 { 68 68 udp_assoc_t *assoc = NULL; … … 82 82 fibril_condvar_initialize(&assoc->rcv_queue_cv); 83 83 84 if (lsock != NULL) 85 assoc->ident.local = *lsock; 86 87 if (fsock != NULL) 88 assoc->ident.foreign = *fsock; 84 if (epp != NULL) 85 assoc->ident = *epp; 89 86 90 87 assoc->cb = cb; … … 200 197 assoc, iplink); 201 198 fibril_mutex_lock(&assoc->lock); 202 assoc->ident. iplink = iplink;203 fibril_mutex_unlock(&assoc->lock); 204 } 205 206 /** Set foreign socket in association.207 * 208 * @param assoc Association 209 * @param fsock Foreign socket (deeply copied)210 */ 211 void udp_assoc_set_ foreign(udp_assoc_t *assoc, udp_sock_t *fsock)212 { 213 log_msg(LOG_DEFAULT, LVL_DEBUG, "udp_assoc_set_ foreign(%p, %p)", assoc, fsock);214 fibril_mutex_lock(&assoc->lock); 215 assoc->ident. foreign = *fsock;216 fibril_mutex_unlock(&assoc->lock); 217 } 218 219 /** Set local socket in association.199 assoc->ident.local_link = iplink; 200 fibril_mutex_unlock(&assoc->lock); 201 } 202 203 /** Set remote endpoint in association. 204 * 205 * @param assoc Association 206 * @param remote Remote endpoint (deeply copied) 207 */ 208 void udp_assoc_set_remote(udp_assoc_t *assoc, inet_ep_t *remote) 209 { 210 log_msg(LOG_DEFAULT, LVL_DEBUG, "udp_assoc_set_remote(%p, %p)", assoc, remote); 211 fibril_mutex_lock(&assoc->lock); 212 assoc->ident.remote = *remote; 213 fibril_mutex_unlock(&assoc->lock); 214 } 215 216 /** Set local endpoint in association. 220 217 * 221 218 * @param assoc Association 222 * @param l sock Local socket (deeply copied)223 * 224 */ 225 void udp_assoc_set_local(udp_assoc_t *assoc, udp_sock_t *lsock)226 { 227 log_msg(LOG_DEFAULT, LVL_DEBUG, "udp_assoc_set_local(%p, %p)", assoc, l sock);228 fibril_mutex_lock(&assoc->lock); 229 assoc->ident.local = *l sock;219 * @param local Local endpoint (deeply copied) 220 * 221 */ 222 void udp_assoc_set_local(udp_assoc_t *assoc, inet_ep_t *local) 223 { 224 log_msg(LOG_DEFAULT, LVL_DEBUG, "udp_assoc_set_local(%p, %p)", assoc, local); 225 fibril_mutex_lock(&assoc->lock); 226 assoc->ident.local = *local; 230 227 fibril_mutex_unlock(&assoc->lock); 231 228 } … … 248 245 * 249 246 * @param assoc Association 250 * @param fsock Foreign socket or NULL not to override @a assoc247 * @param remote Remote endpoint or NULL not to override @a assoc 251 248 * @param msg Message 252 249 * 253 250 * @return EOK on success 254 * EINVAL if foreign socket is not set251 * EINVAL if remote endpoint is not set 255 252 * ENOMEM if out of resources 256 253 * EIO if no route to destination exists 257 254 */ 258 int udp_assoc_send(udp_assoc_t *assoc, udp_sock_t *fsock, udp_msg_t *msg)255 int udp_assoc_send(udp_assoc_t *assoc, inet_ep_t *remote, udp_msg_t *msg) 259 256 { 260 257 udp_pdu_t *pdu; 261 udp_sockpair_t sp;258 inet_ep2_t epp; 262 259 int rc; 263 260 264 261 log_msg(LOG_DEFAULT, LVL_NOTE, "udp_assoc_send(%p, %p, %p)", 265 assoc, fsock, msg);266 267 /* @a fsock can be used to override the foreign socket */268 sp = assoc->ident;269 if ( fsock!= NULL)270 sp.foreign = *fsock;262 assoc, remote, msg); 263 264 /* @a remote can be used to override the remote endpoint */ 265 epp = assoc->ident; 266 if (remote != NULL) 267 epp.remote = *remote; 271 268 272 269 log_msg(LOG_DEFAULT, LVL_NOTE, "udp_assoc_send - check addr any"); 273 270 274 if ((inet_addr_is_any(& sp.foreign.addr)) ||275 ( sp.foreign.port == UDP_PORT_ANY))271 if ((inet_addr_is_any(&epp.remote.addr)) || 272 (epp.remote.port == UDP_PORT_ANY)) 276 273 return EINVAL; 277 274 278 275 log_msg(LOG_DEFAULT, LVL_NOTE, "udp_assoc_send - check version"); 279 276 280 if ( sp.foreign.addr.version != sp.local.addr.version)277 if (epp.remote.addr.version != epp.local.addr.version) 281 278 return EINVAL; 282 279 283 280 log_msg(LOG_DEFAULT, LVL_NOTE, "udp_assoc_send - encode pdu"); 284 281 285 rc = udp_pdu_encode(& sp, msg, &pdu);282 rc = udp_pdu_encode(&epp, msg, &pdu); 286 283 if (rc != EOK) 287 284 return ENOMEM; … … 303 300 * Pull one message from the association's receive queue. 304 301 */ 305 int udp_assoc_recv(udp_assoc_t *assoc, udp_msg_t **msg, udp_sock_t *fsock)302 int udp_assoc_recv(udp_assoc_t *assoc, udp_msg_t **msg, inet_ep_t *remote) 306 303 { 307 304 link_t *link; … … 329 326 330 327 *msg = rqe->msg; 331 * fsock = rqe->sp.foreign;328 *remote = rqe->epp.remote; 332 329 free(rqe); 333 330 … … 339 336 * Find the association to which the message belongs and queue it. 340 337 */ 341 void udp_assoc_received( udp_sockpair_t *rsp, udp_msg_t *msg)338 void udp_assoc_received(inet_ep2_t *repp, udp_msg_t *msg) 342 339 { 343 340 udp_assoc_t *assoc; 344 341 int rc; 345 342 346 log_msg(LOG_DEFAULT, LVL_NOTE, "udp_assoc_received(%p, %p)", r sp, msg);347 348 assoc = udp_assoc_find_ref(r sp);343 log_msg(LOG_DEFAULT, LVL_NOTE, "udp_assoc_received(%p, %p)", repp, msg); 344 345 assoc = udp_assoc_find_ref(repp); 349 346 if (assoc == NULL) { 350 347 log_msg(LOG_DEFAULT, LVL_NOTE, "No association found. Message dropped."); … … 356 353 357 354 if (0) { 358 rc = udp_assoc_queue_msg(assoc, r sp, msg);355 rc = udp_assoc_queue_msg(assoc, repp, msg); 359 356 if (rc != EOK) { 360 357 log_msg(LOG_DEFAULT, LVL_DEBUG, "Out of memory. Message dropped."); … … 364 361 365 362 log_msg(LOG_DEFAULT, LVL_NOTE, "call assoc->cb->recv_msg"); 366 assoc->cb->recv_msg(assoc->cb_arg, r sp, msg);363 assoc->cb->recv_msg(assoc->cb_arg, repp, msg); 367 364 udp_assoc_delref(assoc); 368 365 } … … 381 378 } 382 379 383 static int udp_assoc_queue_msg(udp_assoc_t *assoc, udp_sockpair_t *sp,380 static int udp_assoc_queue_msg(udp_assoc_t *assoc, inet_ep2_t *epp, 384 381 udp_msg_t *msg) 385 382 { … … 387 384 388 385 log_msg(LOG_DEFAULT, LVL_DEBUG, "udp_assoc_queue_msg(%p, %p, %p)", 389 assoc, sp, msg);386 assoc, epp, msg); 390 387 391 388 rqe = calloc(1, sizeof(udp_rcv_queue_entry_t)); … … 394 391 395 392 link_initialize(&rqe->link); 396 rqe-> sp = *sp;393 rqe->epp = *epp; 397 394 rqe->msg = msg; 398 395 … … 406 403 } 407 404 408 /** Match socket with pattern. */409 static bool udp_ socket_match(udp_sock_t *sock, udp_sock_t *patt)405 /** Match endpoint with pattern. */ 406 static bool udp_ep_match(inet_ep_t *ep, inet_ep_t *patt) 410 407 { 411 408 char *sa, *pa; 412 409 413 410 sa = pa = (char *)"?"; 414 (void) inet_addr_format(& sock->addr, &sa);411 (void) inet_addr_format(&ep->addr, &sa); 415 412 (void) inet_addr_format(&patt->addr, &pa); 416 413 417 414 log_msg(LOG_DEFAULT, LVL_NOTE, 418 "udp_ socket_match(sock=(%s,%u), pat=(%s,%u))",419 sa, sock->port, pa, patt->port);420 415 "udp_ep_match(ep=(%s,%u), pat=(%s,%u))", 416 sa, ep->port, pa, patt->port); 417 421 418 if ((!inet_addr_is_any(&patt->addr)) && 422 (!inet_addr_compare(&patt->addr, & sock->addr)))419 (!inet_addr_compare(&patt->addr, &ep->addr))) 423 420 return false; 424 421 425 422 log_msg(LOG_DEFAULT, LVL_NOTE, "addr OK"); 426 423 427 424 if ((patt->port != UDP_PORT_ANY) && 428 (patt->port != sock->port))425 (patt->port != ep->port)) 429 426 return false; 430 427 431 428 log_msg(LOG_DEFAULT, LVL_NOTE, " -> match"); 432 429 433 430 return true; 434 431 } 435 432 436 /** Match socket pair with pattern. */437 static bool udp_ sockpair_match(udp_sockpair_t *sp, udp_sockpair_t *pattern)438 { 439 log_msg(LOG_DEFAULT, LVL_DEBUG, "udp_ sockpair_match(%p, %p)", sp, pattern);440 441 if (!udp_ socket_match(&sp->local, &pattern->local))433 /** Match endpoint pair with pattern. */ 434 static bool udp_ep2_match(inet_ep2_t *epp, inet_ep2_t *pattern) 435 { 436 log_msg(LOG_DEFAULT, LVL_DEBUG, "udp_ep2_match(%p, %p)", epp, pattern); 437 438 if (!udp_ep_match(&epp->local, &pattern->local)) 442 439 return false; 443 440 444 if (!udp_ socket_match(&sp->foreign, &pattern->foreign))441 if (!udp_ep_match(&epp->remote, &pattern->remote)) 445 442 return false; 446 443 447 log_msg(LOG_DEFAULT, LVL_DEBUG, " Socket pair matched.");444 log_msg(LOG_DEFAULT, LVL_DEBUG, "Endpoint pair matched."); 448 445 return true; 449 446 } 450 447 451 448 452 /** Find association structure for specified socket pair.453 * 454 * An association is uniquely identified by a socket pair. Look up our455 * association map and return association structure based on socket pair.449 /** Find association structure for specified endpoint pair. 450 * 451 * An association is uniquely identified by an endpoint pair. Look up our 452 * association map and return association structure based on endpoint pair. 456 453 * The association reference count is bumped by one. 457 454 * 458 * @param sp Socket pair455 * @param epp Endpoint pair 459 456 * @return Association structure or NULL if not found. 460 457 */ 461 static udp_assoc_t *udp_assoc_find_ref( udp_sockpair_t *sp)458 static udp_assoc_t *udp_assoc_find_ref(inet_ep2_t *epp) 462 459 { 463 460 char *la, *ra; 464 461 465 log_msg(LOG_DEFAULT, LVL_NOTE, "udp_assoc_find_ref(%p)", sp);466 462 log_msg(LOG_DEFAULT, LVL_NOTE, "udp_assoc_find_ref(%p)", epp); 463 467 464 fibril_mutex_lock(&assoc_list_lock); 468 465 469 466 log_msg(LOG_DEFAULT, LVL_NOTE, "associations:"); 470 467 list_foreach(assoc_list, link, udp_assoc_t, assoc) { 471 udp_sockpair_t *asp = &assoc->ident;472 468 inet_ep2_t *aepp = &assoc->ident; 469 473 470 la = ra = NULL; 474 471 475 (void) inet_addr_format(&a sp->local.addr, &la);476 (void) inet_addr_format(&a sp->foreign.addr, &ra);477 478 log_msg(LOG_DEFAULT, LVL_NOTE, "find_ref:a sp=%p la=%s ra=%s",479 a sp, la, ra);472 (void) inet_addr_format(&aepp->local.addr, &la); 473 (void) inet_addr_format(&aepp->remote.addr, &ra); 474 475 log_msg(LOG_DEFAULT, LVL_NOTE, "find_ref:aepp=%p la=%s ra=%s", 476 aepp, la, ra); 480 477 /* Skip unbound associations */ 481 if (a sp->local.port == UDP_PORT_ANY) {478 if (aepp->local.port == UDP_PORT_ANY) { 482 479 log_msg(LOG_DEFAULT, LVL_NOTE, "skip unbound"); 483 480 continue; 484 481 } 485 486 if (udp_ sockpair_match(sp, asp)) {482 483 if (udp_ep2_match(epp, aepp)) { 487 484 log_msg(LOG_DEFAULT, LVL_DEBUG, "Returning assoc %p", assoc); 488 485 udp_assoc_addref(assoc); … … 493 490 } 494 491 } 495 492 496 493 log_msg(LOG_DEFAULT, LVL_NOTE, "associations END"); 497 494 fibril_mutex_unlock(&assoc_list_lock); -
uspace/srv/net/udp/assoc.h
rbf7587b0 r2f19103 1 1 /* 2 * Copyright (c) 201 2Jiri Svoboda2 * Copyright (c) 2015 Jiri Svoboda 3 3 * All rights reserved. 4 4 * … … 36 36 #define ASSOC_H 37 37 38 #include <inet/endpoint.h> 38 39 #include <ipc/loc.h> 39 40 #include <sys/types.h> 40 41 #include "udp_type.h" 41 42 42 extern udp_assoc_t *udp_assoc_new(udp_sock_t *, udp_sock_t *, udp_assoc_cb_t *, 43 void *); 43 extern udp_assoc_t *udp_assoc_new(inet_ep2_t *, udp_assoc_cb_t *, void *); 44 44 extern void udp_assoc_delete(udp_assoc_t *); 45 45 extern void udp_assoc_add(udp_assoc_t *); … … 48 48 extern void udp_assoc_delref(udp_assoc_t *); 49 49 extern void udp_assoc_set_iplink(udp_assoc_t *, service_id_t); 50 extern void udp_assoc_set_ foreign(udp_assoc_t *, udp_sock_t *);51 extern void udp_assoc_set_local(udp_assoc_t *, udp_sock_t *);50 extern void udp_assoc_set_remote(udp_assoc_t *, inet_ep_t *); 51 extern void udp_assoc_set_local(udp_assoc_t *, inet_ep_t *); 52 52 extern void udp_assoc_set_local_port(udp_assoc_t *, uint16_t); 53 extern int udp_assoc_send(udp_assoc_t *, udp_sock_t *, udp_msg_t *);54 extern int udp_assoc_recv(udp_assoc_t *, udp_msg_t **, udp_sock_t *);55 extern void udp_assoc_received( udp_sockpair_t *, udp_msg_t *);53 extern int udp_assoc_send(udp_assoc_t *, inet_ep_t *, udp_msg_t *); 54 extern int udp_assoc_recv(udp_assoc_t *, udp_msg_t **, inet_ep_t *); 55 extern void udp_assoc_received(inet_ep2_t *, udp_msg_t *); 56 56 extern void udp_assoc_reset(udp_assoc_t *); 57 57 -
uspace/srv/net/udp/pdu.c
rbf7587b0 r2f19103 1 1 /* 2 * Copyright (c) 201 2Jiri Svoboda2 * Copyright (c) 2015 Jiri Svoboda 3 3 * All rights reserved. 4 4 * … … 162 162 163 163 /** Decode incoming PDU */ 164 int udp_pdu_decode(udp_pdu_t *pdu, udp_sockpair_t *sp, udp_msg_t **msg)164 int udp_pdu_decode(udp_pdu_t *pdu, inet_ep2_t *epp, udp_msg_t **msg) 165 165 { 166 166 udp_msg_t *nmsg; … … 179 179 hdr = (udp_header_t *)pdu->data; 180 180 181 sp->foreign.port = uint16_t_be2host(hdr->src_port);182 sp->foreign.addr = pdu->src;183 sp->local.port = uint16_t_be2host(hdr->dest_port);184 sp->local.addr = pdu->dest;181 epp->remote.port = uint16_t_be2host(hdr->src_port); 182 epp->remote.addr = pdu->src; 183 epp->local.port = uint16_t_be2host(hdr->dest_port); 184 epp->local.addr = pdu->dest; 185 185 186 186 length = uint16_t_be2host(hdr->length); … … 208 208 209 209 /** Encode outgoing PDU */ 210 int udp_pdu_encode( udp_sockpair_t *sp, udp_msg_t *msg, udp_pdu_t **pdu)210 int udp_pdu_encode(inet_ep2_t *epp, udp_msg_t *msg, udp_pdu_t **pdu) 211 211 { 212 212 udp_pdu_t *npdu; … … 218 218 return ENOMEM; 219 219 220 npdu->iplink = sp->iplink;221 npdu->src = sp->local.addr;222 npdu->dest = sp->foreign.addr;220 npdu->iplink = epp->local_link; 221 npdu->src = epp->local.addr; 222 npdu->dest = epp->remote.addr; 223 223 224 224 npdu->data_size = sizeof(udp_header_t) + msg->data_size; … … 230 230 231 231 hdr = (udp_header_t *)npdu->data; 232 hdr->src_port = host2uint16_t_be( sp->local.port);233 hdr->dest_port = host2uint16_t_be( sp->foreign.port);232 hdr->src_port = host2uint16_t_be(epp->local.port); 233 hdr->dest_port = host2uint16_t_be(epp->remote.port); 234 234 hdr->length = host2uint16_t_be(npdu->data_size); 235 235 hdr->checksum = 0; -
uspace/srv/net/udp/pdu.h
rbf7587b0 r2f19103 1 1 /* 2 * Copyright (c) 201 2Jiri Svoboda2 * Copyright (c) 2015 Jiri Svoboda 3 3 * All rights reserved. 4 4 * … … 36 36 #define PDU_H 37 37 38 #include <inet/endpoint.h> 38 39 #include <sys/types.h> 39 40 #include "std.h" … … 42 43 extern udp_pdu_t *udp_pdu_new(void); 43 44 extern void udp_pdu_delete(udp_pdu_t *); 44 extern int udp_pdu_decode(udp_pdu_t *, udp_sockpair_t *, udp_msg_t **);45 extern int udp_pdu_encode( udp_sockpair_t *, udp_msg_t *, udp_pdu_t **);45 extern int udp_pdu_decode(udp_pdu_t *, inet_ep2_t *, udp_msg_t **); 46 extern int udp_pdu_encode(inet_ep2_t *, udp_msg_t *, udp_pdu_t **); 46 47 47 48 #endif -
uspace/srv/net/udp/service.c
rbf7587b0 r2f19103 54 54 #define MAX_MSG_SIZE DATA_XFER_LIMIT 55 55 56 static void udp_cassoc_recv_msg(void *, udp_sockpair_t *, udp_msg_t *);56 static void udp_cassoc_recv_msg(void *, inet_ep2_t *, udp_msg_t *); 57 57 58 58 static udp_assoc_cb_t udp_cassoc_cb = { … … 60 60 }; 61 61 62 static int udp_cassoc_queue_msg(udp_cassoc_t *cassoc, udp_sockpair_t *sp,62 static int udp_cassoc_queue_msg(udp_cassoc_t *cassoc, inet_ep2_t *epp, 63 63 udp_msg_t *msg) 64 64 { … … 66 66 67 67 log_msg(LOG_DEFAULT, LVL_DEBUG, "udp_cassoc_queue_msg(%p, %p, %p)", 68 cassoc, sp, msg);68 cassoc, epp, msg); 69 69 70 70 rqe = calloc(1, sizeof(udp_crcv_queue_entry_t)); … … 73 73 74 74 link_initialize(&rqe->link); 75 rqe-> sp = *sp;75 rqe->epp = *epp; 76 76 rqe->msg = msg; 77 77 rqe->cassoc = cassoc; … … 144 144 } 145 145 146 static void udp_cassoc_recv_msg(void *arg, udp_sockpair_t *sp, udp_msg_t *msg)146 static void udp_cassoc_recv_msg(void *arg, inet_ep2_t *epp, udp_msg_t *msg) 147 147 { 148 148 udp_cassoc_t *cassoc = (udp_cassoc_t *) arg; 149 149 150 udp_cassoc_queue_msg(cassoc, sp, msg);150 udp_cassoc_queue_msg(cassoc, epp, msg); 151 151 udp_ev_data(cassoc->client); 152 152 } … … 157 157 udp_assoc_t *assoc; 158 158 udp_cassoc_t *cassoc; 159 udp_sock_t local;160 udp_sock_t remote;161 159 int rc; 162 160 163 161 log_msg(LOG_DEFAULT, LVL_DEBUG, "udp_assoc_create_impl"); 164 162 165 local.addr = epp->local.addr; 166 local.port = epp->local.port; 167 remote.addr = epp->remote.addr; 168 remote.port = epp->remote.port; 169 170 assoc = udp_assoc_new(&local, &remote, NULL, NULL); 163 assoc = udp_assoc_new(epp, NULL, NULL); 171 164 if (assoc == NULL) 172 165 return EIO; … … 213 206 { 214 207 udp_msg_t msg; 215 udp_sock_t remote;216 208 udp_cassoc_t *cassoc; 217 209 int rc; … … 221 213 return rc; 222 214 223 remote.addr = dest->addr;224 remote.port = dest->port;225 226 215 msg.data = data; 227 216 msg.data_size = size; 228 rc = udp_assoc_send(cassoc->assoc, &remote, &msg);217 rc = udp_assoc_send(cassoc->assoc, dest, &msg); 229 218 if (rc != EOK) 230 219 return rc; … … 390 379 ipc_callid_t callid; 391 380 size_t size; 392 inet_ep_t ep;393 381 udp_crcv_queue_entry_t *enext; 394 382 sysarg_t assoc_id; … … 410 398 } 411 399 412 inet_ep_init(&ep); 413 ep.addr = enext->sp.foreign.addr; 414 ep.port = enext->sp.foreign.port; 415 416 rc = async_data_read_finalize(callid, &ep, max(size, (ssize_t)sizeof(ep))); 400 rc = async_data_read_finalize(callid, &enext->epp.remote, 401 max(size, (ssize_t)sizeof(inet_ep_t))); 417 402 if (rc != EOK) { 418 403 async_answer_0(iid, rc); -
uspace/srv/net/udp/ucall.c
rbf7587b0 r2f19103 1 1 /* 2 * Copyright (c) 201 2Jiri Svoboda2 * Copyright (c) 2015 Jiri Svoboda 3 3 * All rights reserved. 4 4 * … … 50 50 51 51 log_msg(LOG_DEFAULT, LVL_DEBUG, "udp_uc_create()"); 52 nassoc = udp_assoc_new(NULL, NULL, NULL , NULL);52 nassoc = udp_assoc_new(NULL, NULL, NULL); 53 53 if (nassoc == NULL) 54 54 return UDP_ENORES; … … 67 67 } 68 68 69 udp_error_t udp_uc_set_ foreign(udp_assoc_t *assoc, udp_sock_t *fsock)69 udp_error_t udp_uc_set_remote(udp_assoc_t *assoc, inet_ep_t *ep) 70 70 { 71 log_msg(LOG_DEFAULT, LVL_DEBUG, "udp_uc_set_ foreign(%p, %p)", assoc, fsock);71 log_msg(LOG_DEFAULT, LVL_DEBUG, "udp_uc_set_remote(%p, %p)", assoc, ep); 72 72 73 udp_assoc_set_ foreign(assoc, fsock);73 udp_assoc_set_remote(assoc, ep); 74 74 return UDP_EOK; 75 75 } 76 76 77 udp_error_t udp_uc_set_local(udp_assoc_t *assoc, udp_sock_t *lsock)77 udp_error_t udp_uc_set_local(udp_assoc_t *assoc, inet_ep_t *ep) 78 78 { 79 log_msg(LOG_DEFAULT, LVL_DEBUG, "udp_uc_set_local(%p, %p)", assoc, lsock);80 81 udp_assoc_set_local(assoc, lsock);79 log_msg(LOG_DEFAULT, LVL_DEBUG, "udp_uc_set_local(%p, %p)", assoc, ep); 80 81 udp_assoc_set_local(assoc, ep); 82 82 return UDP_EOK; 83 83 } … … 86 86 { 87 87 log_msg(LOG_DEFAULT, LVL_DEBUG, "udp_uc_set_local(%p, %" PRIu16 ")", assoc, lport); 88 88 89 89 udp_assoc_set_local_port(assoc, lport); 90 90 return UDP_EOK; 91 91 } 92 92 93 udp_error_t udp_uc_send(udp_assoc_t *assoc, udp_sock_t *fsock, void *data,93 udp_error_t udp_uc_send(udp_assoc_t *assoc, inet_ep_t *remote, void *data, 94 94 size_t size, xflags_t flags) 95 95 { … … 102 102 msg.data_size = size; 103 103 104 rc = udp_assoc_send(assoc, fsock, &msg);104 rc = udp_assoc_send(assoc, remote, &msg); 105 105 switch (rc) { 106 106 case ENOMEM: … … 115 115 116 116 udp_error_t udp_uc_receive(udp_assoc_t *assoc, void *buf, size_t size, 117 size_t *rcvd, xflags_t *xflags, udp_sock_t *fsock)117 size_t *rcvd, xflags_t *xflags, inet_ep_t *remote) 118 118 { 119 119 size_t xfer_size; … … 122 122 123 123 log_msg(LOG_DEFAULT, LVL_DEBUG, "%s: udp_uc_receive()", assoc->name); 124 rc = udp_assoc_recv(assoc, &msg, fsock);124 rc = udp_assoc_recv(assoc, &msg, remote); 125 125 log_msg(LOG_DEFAULT, LVL_DEBUG, "udp_assoc_recv -> %d", rc); 126 126 switch (rc) { -
uspace/srv/net/udp/ucall.h
rbf7587b0 r2f19103 1 1 /* 2 * Copyright (c) 201 2Jiri Svoboda2 * Copyright (c) 2015 Jiri Svoboda 3 3 * All rights reserved. 4 4 * … … 42 42 extern udp_error_t udp_uc_create(udp_assoc_t **); 43 43 extern void udp_uc_set_iplink(udp_assoc_t *, service_id_t); 44 extern udp_error_t udp_uc_set_ foreign(udp_assoc_t *, udp_sock_t *);45 extern udp_error_t udp_uc_set_local(udp_assoc_t *, udp_sock_t *);44 extern udp_error_t udp_uc_set_remote(udp_assoc_t *, inet_ep_t *); 45 extern udp_error_t udp_uc_set_local(udp_assoc_t *, inet_ep_t *); 46 46 extern udp_error_t udp_uc_set_local_port(udp_assoc_t *, uint16_t); 47 extern udp_error_t udp_uc_send(udp_assoc_t *, udp_sock_t *, void *, size_t,47 extern udp_error_t udp_uc_send(udp_assoc_t *, inet_ep_t *, void *, size_t, 48 48 xflags_t); 49 49 extern udp_error_t udp_uc_receive(udp_assoc_t *, void *, size_t, size_t *, 50 xflags_t *, udp_sock_t *);50 xflags_t *, inet_ep_t *); 51 51 extern void udp_uc_status(udp_assoc_t *, udp_assoc_status_t *); 52 52 extern void udp_uc_destroy(udp_assoc_t *); -
uspace/srv/net/udp/udp_inet.c
rbf7587b0 r2f19103 1 1 /* 2 * Copyright (c) 201 2Jiri Svoboda2 * Copyright (c) 2015 Jiri Svoboda 3 3 * All rights reserved. 4 4 * … … 105 105 { 106 106 udp_msg_t *dmsg; 107 udp_sockpair_t rident;107 inet_ep2_t rident; 108 108 109 109 log_msg(LOG_DEFAULT, LVL_DEBUG, "udp_received_pdu()"); -
uspace/srv/net/udp/udp_type.h
rbf7587b0 r2f19103 1 1 /* 2 * Copyright (c) 201 2Jiri Svoboda2 * Copyright (c) 2015 Jiri Svoboda 3 3 * All rights reserved. 4 4 * … … 39 39 #include <fibril.h> 40 40 #include <fibril_synch.h> 41 #include <inet/endpoint.h> 41 42 #include <ipc/loc.h> 42 43 #include <sys/types.h> … … 49 50 /* Insufficient resources */ 50 51 UDP_ENORES, 51 /* Foreign socket unspecified */52 /* Remote endpoint unspecified */ 52 53 UDP_EUNSPEC, 53 54 /* No route to destination */ … … 64 65 UDP_PORT_ANY = 0 65 66 }; 66 67 typedef struct {68 inet_addr_t addr;69 uint16_t port;70 } udp_sock_t;71 72 typedef struct {73 service_id_t iplink;74 udp_sock_t local;75 udp_sock_t foreign;76 } udp_sockpair_t;77 67 78 68 /** Unencoded UDP message (datagram) */ … … 99 89 100 90 typedef struct { 101 void (*recv_msg)(void *, udp_sockpair_t *, udp_msg_t *);91 void (*recv_msg)(void *, inet_ep2_t *, udp_msg_t *); 102 92 } udp_assoc_cb_t; 103 93 … … 106 96 * This is a rough equivalent of a TCP connection endpoint. It allows 107 97 * sending and receiving UDP datagrams and it is uniquely identified 108 * by a socket pair.98 * by an endpoint pair. 109 99 */ 110 100 typedef struct { … … 112 102 link_t link; 113 103 114 /** Association identification ( local and foreign socket) */115 udp_sockpair_t ident;104 /** Association identification (endpoint pair) */ 105 inet_ep2_t ident; 116 106 117 107 /** True if association was reset by user */ … … 141 131 /** Link to receive queue */ 142 132 link_t link; 143 /** Socket pair */144 udp_sockpair_t sp;133 /** Endpoint pair */ 134 inet_ep2_t epp; 145 135 /** Message */ 146 136 udp_msg_t *msg; … … 160 150 /** Link to receive queue */ 161 151 link_t link; 162 /** Socket pair */163 udp_sockpair_t sp;152 /** Endpoint pair */ 153 inet_ep2_t epp; 164 154 /** Message */ 165 155 udp_msg_t *msg;
Note:
See TracChangeset
for help on using the changeset viewer.
