Changeset 2f19103 in mainline for uspace/srv/net/udp


Ignore:
Timestamp:
2015-05-22T07:21:37Z (10 years ago)
Author:
Jiri Svoboda <jiri@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
58e9dec
Parents:
bf7587b0
Message:

TCP and UDP servers can make use of inet/endpoint.h types internally.

Location:
uspace/srv/net/udp
Files:
9 edited

Legend:

Unmodified
Added
Removed
  • uspace/srv/net/udp/assoc.c

    rbf7587b0 r2f19103  
    11/*
    2  * Copyright (c) 2012 Jiri Svoboda
     2 * Copyright (c) 2015 Jiri Svoboda
    33 * All rights reserved.
    44 *
     
    5252FIBRIL_MUTEX_INITIALIZE(assoc_list_lock);
    5353
    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 *);
     54static udp_assoc_t *udp_assoc_find_ref(inet_ep2_t *);
     55static int udp_assoc_queue_msg(udp_assoc_t *, inet_ep2_t *, udp_msg_t *);
     56static bool udp_ep_match(inet_ep_t *, inet_ep_t *);
     57static bool udp_ep2_match(inet_ep2_t *, inet_ep2_t *);
    5858
    5959/** Create new association structure.
    6060 *
    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
    6364 * @return              New association or NULL
    6465 */
    65 udp_assoc_t *udp_assoc_new(udp_sock_t *lsock, udp_sock_t *fsock,
    66     udp_assoc_cb_t *cb, void *cb_arg)
     66udp_assoc_t *udp_assoc_new(inet_ep2_t *epp, udp_assoc_cb_t *cb, void *cb_arg)
    6767{
    6868        udp_assoc_t *assoc = NULL;
     
    8282        fibril_condvar_initialize(&assoc->rcv_queue_cv);
    8383
    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;
    8986
    9087        assoc->cb = cb;
     
    200197            assoc, iplink);
    201198        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 */
     208void 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.
    220217 *
    221218 * @param assoc Association
    222  * @param lsock 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, lsock);
    228         fibril_mutex_lock(&assoc->lock);
    229         assoc->ident.local = *lsock;
     219 * @param local Local endpoint (deeply copied)
     220 *
     221 */
     222void 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;
    230227        fibril_mutex_unlock(&assoc->lock);
    231228}
     
    248245 *
    249246 * @param assoc         Association
    250  * @param fsock         Foreign socket or NULL not to override @a assoc
     247 * @param remote        Remote endpoint or NULL not to override @a assoc
    251248 * @param msg           Message
    252249 *
    253250 * @return              EOK on success
    254  *                      EINVAL if foreign socket is not set
     251 *                      EINVAL if remote endpoint is not set
    255252 *                      ENOMEM if out of resources
    256253 *                      EIO if no route to destination exists
    257254 */
    258 int udp_assoc_send(udp_assoc_t *assoc, udp_sock_t *fsock, udp_msg_t *msg)
     255int udp_assoc_send(udp_assoc_t *assoc, inet_ep_t *remote, udp_msg_t *msg)
    259256{
    260257        udp_pdu_t *pdu;
    261         udp_sockpair_t sp;
     258        inet_ep2_t epp;
    262259        int rc;
    263260
    264261        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;
    271268
    272269        log_msg(LOG_DEFAULT, LVL_NOTE, "udp_assoc_send - check addr any");
    273270
    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))
    276273                return EINVAL;
    277274
    278275        log_msg(LOG_DEFAULT, LVL_NOTE, "udp_assoc_send - check version");
    279276
    280         if (sp.foreign.addr.version != sp.local.addr.version)
     277        if (epp.remote.addr.version != epp.local.addr.version)
    281278                return EINVAL;
    282279
    283280        log_msg(LOG_DEFAULT, LVL_NOTE, "udp_assoc_send - encode pdu");
    284281
    285         rc = udp_pdu_encode(&sp, msg, &pdu);
     282        rc = udp_pdu_encode(&epp, msg, &pdu);
    286283        if (rc != EOK)
    287284                return ENOMEM;
     
    303300 * Pull one message from the association's receive queue.
    304301 */
    305 int udp_assoc_recv(udp_assoc_t *assoc, udp_msg_t **msg, udp_sock_t *fsock)
     302int udp_assoc_recv(udp_assoc_t *assoc, udp_msg_t **msg, inet_ep_t *remote)
    306303{
    307304        link_t *link;
     
    329326
    330327        *msg = rqe->msg;
    331         *fsock = rqe->sp.foreign;
     328        *remote = rqe->epp.remote;
    332329        free(rqe);
    333330
     
    339336 * Find the association to which the message belongs and queue it.
    340337 */
    341 void udp_assoc_received(udp_sockpair_t *rsp, udp_msg_t *msg)
     338void udp_assoc_received(inet_ep2_t *repp, udp_msg_t *msg)
    342339{
    343340        udp_assoc_t *assoc;
    344341        int rc;
    345342
    346         log_msg(LOG_DEFAULT, LVL_NOTE, "udp_assoc_received(%p, %p)", rsp, msg);
    347 
    348         assoc = udp_assoc_find_ref(rsp);
     343        log_msg(LOG_DEFAULT, LVL_NOTE, "udp_assoc_received(%p, %p)", repp, msg);
     344
     345        assoc = udp_assoc_find_ref(repp);
    349346        if (assoc == NULL) {
    350347                log_msg(LOG_DEFAULT, LVL_NOTE, "No association found. Message dropped.");
     
    356353
    357354        if (0) {
    358                 rc = udp_assoc_queue_msg(assoc, rsp, msg);
     355                rc = udp_assoc_queue_msg(assoc, repp, msg);
    359356                if (rc != EOK) {
    360357                        log_msg(LOG_DEFAULT, LVL_DEBUG, "Out of memory. Message dropped.");
     
    364361
    365362        log_msg(LOG_DEFAULT, LVL_NOTE, "call assoc->cb->recv_msg");
    366         assoc->cb->recv_msg(assoc->cb_arg, rsp, msg);
     363        assoc->cb->recv_msg(assoc->cb_arg, repp, msg);
    367364        udp_assoc_delref(assoc);
    368365}
     
    381378}
    382379
    383 static int udp_assoc_queue_msg(udp_assoc_t *assoc, udp_sockpair_t *sp,
     380static int udp_assoc_queue_msg(udp_assoc_t *assoc, inet_ep2_t *epp,
    384381    udp_msg_t *msg)
    385382{
     
    387384
    388385        log_msg(LOG_DEFAULT, LVL_DEBUG, "udp_assoc_queue_msg(%p, %p, %p)",
    389             assoc, sp, msg);
     386            assoc, epp, msg);
    390387
    391388        rqe = calloc(1, sizeof(udp_rcv_queue_entry_t));
     
    394391
    395392        link_initialize(&rqe->link);
    396         rqe->sp = *sp;
     393        rqe->epp = *epp;
    397394        rqe->msg = msg;
    398395
     
    406403}
    407404
    408 /** Match socket with pattern. */
    409 static bool udp_socket_match(udp_sock_t *sock, udp_sock_t *patt)
     405/** Match endpoint with pattern. */
     406static bool udp_ep_match(inet_ep_t *ep, inet_ep_t *patt)
    410407{
    411408        char *sa, *pa;
    412409
    413410        sa = pa = (char *)"?";
    414         (void) inet_addr_format(&sock->addr, &sa);
     411        (void) inet_addr_format(&ep->addr, &sa);
    415412        (void) inet_addr_format(&patt->addr, &pa);
    416413
    417414        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
    421418        if ((!inet_addr_is_any(&patt->addr)) &&
    422             (!inet_addr_compare(&patt->addr, &sock->addr)))
     419            (!inet_addr_compare(&patt->addr, &ep->addr)))
    423420                return false;
    424        
     421
    425422        log_msg(LOG_DEFAULT, LVL_NOTE, "addr OK");
    426        
     423
    427424        if ((patt->port != UDP_PORT_ANY) &&
    428             (patt->port != sock->port))
     425            (patt->port != ep->port))
    429426                return false;
    430        
     427
    431428        log_msg(LOG_DEFAULT, LVL_NOTE, " -> match");
    432        
     429
    433430        return true;
    434431}
    435432
    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. */
     434static 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))
    442439                return false;
    443440
    444         if (!udp_socket_match(&sp->foreign, &pattern->foreign))
     441        if (!udp_ep_match(&epp->remote, &pattern->remote))
    445442                return false;
    446443
    447         log_msg(LOG_DEFAULT, LVL_DEBUG, "Socket pair matched.");
     444        log_msg(LOG_DEFAULT, LVL_DEBUG, "Endpoint pair matched.");
    448445        return true;
    449446}
    450447
    451448
    452 /** Find association structure for specified socket pair.
    453  *
    454  * An association is uniquely identified by a socket pair. Look up our
    455  * 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.
    456453 * The association reference count is bumped by one.
    457454 *
    458  * @param sp    Socket pair
     455 * @param epp   Endpoint pair
    459456 * @return      Association structure or NULL if not found.
    460457 */
    461 static udp_assoc_t *udp_assoc_find_ref(udp_sockpair_t *sp)
     458static udp_assoc_t *udp_assoc_find_ref(inet_ep2_t *epp)
    462459{
    463460        char *la, *ra;
    464461
    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
    467464        fibril_mutex_lock(&assoc_list_lock);
    468        
     465
    469466        log_msg(LOG_DEFAULT, LVL_NOTE, "associations:");
    470467        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
    473470                la = ra = NULL;
    474471
    475                 (void) inet_addr_format(&asp->local.addr, &la);
    476                 (void) inet_addr_format(&asp->foreign.addr, &ra);
    477 
    478                 log_msg(LOG_DEFAULT, LVL_NOTE, "find_ref:asp=%p la=%s ra=%s",
    479                     asp, 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);
    480477                /* Skip unbound associations */
    481                 if (asp->local.port == UDP_PORT_ANY) {
     478                if (aepp->local.port == UDP_PORT_ANY) {
    482479                        log_msg(LOG_DEFAULT, LVL_NOTE, "skip unbound");
    483480                        continue;
    484481                }
    485                
    486                 if (udp_sockpair_match(sp, asp)) {
     482
     483                if (udp_ep2_match(epp, aepp)) {
    487484                        log_msg(LOG_DEFAULT, LVL_DEBUG, "Returning assoc %p", assoc);
    488485                        udp_assoc_addref(assoc);
     
    493490                }
    494491        }
    495        
     492
    496493        log_msg(LOG_DEFAULT, LVL_NOTE, "associations END");
    497494        fibril_mutex_unlock(&assoc_list_lock);
  • uspace/srv/net/udp/assoc.h

    rbf7587b0 r2f19103  
    11/*
    2  * Copyright (c) 2012 Jiri Svoboda
     2 * Copyright (c) 2015 Jiri Svoboda
    33 * All rights reserved.
    44 *
     
    3636#define ASSOC_H
    3737
     38#include <inet/endpoint.h>
    3839#include <ipc/loc.h>
    3940#include <sys/types.h>
    4041#include "udp_type.h"
    4142
    42 extern udp_assoc_t *udp_assoc_new(udp_sock_t *, udp_sock_t *, udp_assoc_cb_t *,
    43     void *);
     43extern udp_assoc_t *udp_assoc_new(inet_ep2_t *, udp_assoc_cb_t *, void *);
    4444extern void udp_assoc_delete(udp_assoc_t *);
    4545extern void udp_assoc_add(udp_assoc_t *);
     
    4848extern void udp_assoc_delref(udp_assoc_t *);
    4949extern 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 *);
     50extern void udp_assoc_set_remote(udp_assoc_t *, inet_ep_t *);
     51extern void udp_assoc_set_local(udp_assoc_t *, inet_ep_t *);
    5252extern 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 *);
     53extern int udp_assoc_send(udp_assoc_t *, inet_ep_t *, udp_msg_t *);
     54extern int udp_assoc_recv(udp_assoc_t *, udp_msg_t **, inet_ep_t *);
     55extern void udp_assoc_received(inet_ep2_t *, udp_msg_t *);
    5656extern void udp_assoc_reset(udp_assoc_t *);
    5757
  • uspace/srv/net/udp/pdu.c

    rbf7587b0 r2f19103  
    11/*
    2  * Copyright (c) 2012 Jiri Svoboda
     2 * Copyright (c) 2015 Jiri Svoboda
    33 * All rights reserved.
    44 *
     
    162162
    163163/** Decode incoming PDU */
    164 int udp_pdu_decode(udp_pdu_t *pdu, udp_sockpair_t *sp, udp_msg_t **msg)
     164int udp_pdu_decode(udp_pdu_t *pdu, inet_ep2_t *epp, udp_msg_t **msg)
    165165{
    166166        udp_msg_t *nmsg;
     
    179179        hdr = (udp_header_t *)pdu->data;
    180180
    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;
    185185
    186186        length = uint16_t_be2host(hdr->length);
     
    208208
    209209/** Encode outgoing PDU */
    210 int udp_pdu_encode(udp_sockpair_t *sp, udp_msg_t *msg, udp_pdu_t **pdu)
     210int udp_pdu_encode(inet_ep2_t *epp, udp_msg_t *msg, udp_pdu_t **pdu)
    211211{
    212212        udp_pdu_t *npdu;
     
    218218                return ENOMEM;
    219219
    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;
    223223
    224224        npdu->data_size = sizeof(udp_header_t) + msg->data_size;
     
    230230
    231231        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);
    234234        hdr->length = host2uint16_t_be(npdu->data_size);
    235235        hdr->checksum = 0;
  • uspace/srv/net/udp/pdu.h

    rbf7587b0 r2f19103  
    11/*
    2  * Copyright (c) 2012 Jiri Svoboda
     2 * Copyright (c) 2015 Jiri Svoboda
    33 * All rights reserved.
    44 *
     
    3636#define PDU_H
    3737
     38#include <inet/endpoint.h>
    3839#include <sys/types.h>
    3940#include "std.h"
     
    4243extern udp_pdu_t *udp_pdu_new(void);
    4344extern 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 **);
     45extern int udp_pdu_decode(udp_pdu_t *, inet_ep2_t *, udp_msg_t **);
     46extern int udp_pdu_encode(inet_ep2_t *, udp_msg_t *, udp_pdu_t **);
    4647
    4748#endif
  • uspace/srv/net/udp/service.c

    rbf7587b0 r2f19103  
    5454#define MAX_MSG_SIZE DATA_XFER_LIMIT
    5555
    56 static void udp_cassoc_recv_msg(void *, udp_sockpair_t *, udp_msg_t *);
     56static void udp_cassoc_recv_msg(void *, inet_ep2_t *, udp_msg_t *);
    5757
    5858static udp_assoc_cb_t udp_cassoc_cb = {
     
    6060};
    6161
    62 static int udp_cassoc_queue_msg(udp_cassoc_t *cassoc, udp_sockpair_t *sp,
     62static int udp_cassoc_queue_msg(udp_cassoc_t *cassoc, inet_ep2_t *epp,
    6363    udp_msg_t *msg)
    6464{
     
    6666
    6767        log_msg(LOG_DEFAULT, LVL_DEBUG, "udp_cassoc_queue_msg(%p, %p, %p)",
    68             cassoc, sp, msg);
     68            cassoc, epp, msg);
    6969
    7070        rqe = calloc(1, sizeof(udp_crcv_queue_entry_t));
     
    7373
    7474        link_initialize(&rqe->link);
    75         rqe->sp = *sp;
     75        rqe->epp = *epp;
    7676        rqe->msg = msg;
    7777        rqe->cassoc = cassoc;
     
    144144}
    145145
    146 static void udp_cassoc_recv_msg(void *arg, udp_sockpair_t *sp, udp_msg_t *msg)
     146static void udp_cassoc_recv_msg(void *arg, inet_ep2_t *epp, udp_msg_t *msg)
    147147{
    148148        udp_cassoc_t *cassoc = (udp_cassoc_t *) arg;
    149149
    150         udp_cassoc_queue_msg(cassoc, sp, msg);
     150        udp_cassoc_queue_msg(cassoc, epp, msg);
    151151        udp_ev_data(cassoc->client);
    152152}
     
    157157        udp_assoc_t *assoc;
    158158        udp_cassoc_t *cassoc;
    159         udp_sock_t local;
    160         udp_sock_t remote;
    161159        int rc;
    162160
    163161        log_msg(LOG_DEFAULT, LVL_DEBUG, "udp_assoc_create_impl");
    164162
    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);
    171164        if (assoc == NULL)
    172165                return EIO;
     
    213206{
    214207        udp_msg_t msg;
    215         udp_sock_t remote;
    216208        udp_cassoc_t *cassoc;
    217209        int rc;
     
    221213                return rc;
    222214
    223         remote.addr = dest->addr;
    224         remote.port = dest->port;
    225 
    226215        msg.data = data;
    227216        msg.data_size = size;
    228         rc = udp_assoc_send(cassoc->assoc, &remote, &msg);
     217        rc = udp_assoc_send(cassoc->assoc, dest, &msg);
    229218        if (rc != EOK)
    230219                return rc;
     
    390379        ipc_callid_t callid;
    391380        size_t size;
    392         inet_ep_t ep;
    393381        udp_crcv_queue_entry_t *enext;
    394382        sysarg_t assoc_id;
     
    410398        }
    411399
    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)));
    417402        if (rc != EOK) {
    418403                async_answer_0(iid, rc);
  • uspace/srv/net/udp/ucall.c

    rbf7587b0 r2f19103  
    11/*
    2  * Copyright (c) 2012 Jiri Svoboda
     2 * Copyright (c) 2015 Jiri Svoboda
    33 * All rights reserved.
    44 *
     
    5050
    5151        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);
    5353        if (nassoc == NULL)
    5454                return UDP_ENORES;
     
    6767}
    6868
    69 udp_error_t udp_uc_set_foreign(udp_assoc_t *assoc, udp_sock_t *fsock)
     69udp_error_t udp_uc_set_remote(udp_assoc_t *assoc, inet_ep_t *ep)
    7070{
    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);
    7272
    73         udp_assoc_set_foreign(assoc, fsock);
     73        udp_assoc_set_remote(assoc, ep);
    7474        return UDP_EOK;
    7575}
    7676
    77 udp_error_t udp_uc_set_local(udp_assoc_t *assoc, udp_sock_t *lsock)
     77udp_error_t udp_uc_set_local(udp_assoc_t *assoc, inet_ep_t *ep)
    7878{
    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);
    8282        return UDP_EOK;
    8383}
     
    8686{
    8787        log_msg(LOG_DEFAULT, LVL_DEBUG, "udp_uc_set_local(%p, %" PRIu16 ")", assoc, lport);
    88        
     88
    8989        udp_assoc_set_local_port(assoc, lport);
    9090        return UDP_EOK;
    9191}
    9292
    93 udp_error_t udp_uc_send(udp_assoc_t *assoc, udp_sock_t *fsock, void *data,
     93udp_error_t udp_uc_send(udp_assoc_t *assoc, inet_ep_t *remote, void *data,
    9494    size_t size, xflags_t flags)
    9595{
     
    102102        msg.data_size = size;
    103103
    104         rc = udp_assoc_send(assoc, fsock, &msg);
     104        rc = udp_assoc_send(assoc, remote, &msg);
    105105        switch (rc) {
    106106        case ENOMEM:
     
    115115
    116116udp_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)
    118118{
    119119        size_t xfer_size;
     
    122122
    123123        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);
    125125        log_msg(LOG_DEFAULT, LVL_DEBUG, "udp_assoc_recv -> %d", rc);
    126126        switch (rc) {
  • uspace/srv/net/udp/ucall.h

    rbf7587b0 r2f19103  
    11/*
    2  * Copyright (c) 2012 Jiri Svoboda
     2 * Copyright (c) 2015 Jiri Svoboda
    33 * All rights reserved.
    44 *
     
    4242extern udp_error_t udp_uc_create(udp_assoc_t **);
    4343extern 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 *);
     44extern udp_error_t udp_uc_set_remote(udp_assoc_t *, inet_ep_t *);
     45extern udp_error_t udp_uc_set_local(udp_assoc_t *, inet_ep_t *);
    4646extern 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,
     47extern udp_error_t udp_uc_send(udp_assoc_t *, inet_ep_t *, void *, size_t,
    4848    xflags_t);
    4949extern 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 *);
    5151extern void udp_uc_status(udp_assoc_t *, udp_assoc_status_t *);
    5252extern void udp_uc_destroy(udp_assoc_t *);
  • uspace/srv/net/udp/udp_inet.c

    rbf7587b0 r2f19103  
    11/*
    2  * Copyright (c) 2012 Jiri Svoboda
     2 * Copyright (c) 2015 Jiri Svoboda
    33 * All rights reserved.
    44 *
     
    105105{
    106106        udp_msg_t *dmsg;
    107         udp_sockpair_t rident;
     107        inet_ep2_t rident;
    108108
    109109        log_msg(LOG_DEFAULT, LVL_DEBUG, "udp_received_pdu()");
  • uspace/srv/net/udp/udp_type.h

    rbf7587b0 r2f19103  
    11/*
    2  * Copyright (c) 2012 Jiri Svoboda
     2 * Copyright (c) 2015 Jiri Svoboda
    33 * All rights reserved.
    44 *
     
    3939#include <fibril.h>
    4040#include <fibril_synch.h>
     41#include <inet/endpoint.h>
    4142#include <ipc/loc.h>
    4243#include <sys/types.h>
     
    4950        /* Insufficient resources */
    5051        UDP_ENORES,
    51         /* Foreign socket unspecified */
     52        /* Remote endpoint unspecified */
    5253        UDP_EUNSPEC,
    5354        /* No route to destination */
     
    6465        UDP_PORT_ANY = 0
    6566};
    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;
    7767
    7868/** Unencoded UDP message (datagram) */
     
    9989
    10090typedef struct {
    101         void (*recv_msg)(void *, udp_sockpair_t *, udp_msg_t *);
     91        void (*recv_msg)(void *, inet_ep2_t *, udp_msg_t *);
    10292} udp_assoc_cb_t;
    10393
     
    10696 * This is a rough equivalent of a TCP connection endpoint. It allows
    10797 * sending and receiving UDP datagrams and it is uniquely identified
    108  * by a socket pair.
     98 * by an endpoint pair.
    10999 */
    110100typedef struct {
     
    112102        link_t link;
    113103
    114         /** Association identification (local and foreign socket) */
    115         udp_sockpair_t ident;
     104        /** Association identification (endpoint pair) */
     105        inet_ep2_t ident;
    116106
    117107        /** True if association was reset by user */
     
    141131        /** Link to receive queue */
    142132        link_t link;
    143         /** Socket pair */
    144         udp_sockpair_t sp;
     133        /** Endpoint pair */
     134        inet_ep2_t epp;
    145135        /** Message */
    146136        udp_msg_t *msg;
     
    160150        /** Link to receive queue */
    161151        link_t link;
    162         /** Socket pair */
    163         udp_sockpair_t sp;
     152        /** Endpoint pair */
     153        inet_ep2_t epp;
    164154        /** Message */
    165155        udp_msg_t *msg;
Note: See TracChangeset for help on using the changeset viewer.