Changeset 048cd69 in mainline for uspace/srv/net/udp


Ignore:
Timestamp:
2015-06-07T15:41:04Z (11 years ago)
Author:
Jiri Svoboda <jiri@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
204ba47
Parents:
4d11204 (diff), c3f7d37 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Merge network transport layer API rewrite.

Location:
uspace/srv/net/udp
Files:
1 added
3 deleted
9 edited
1 moved

Legend:

Unmodified
Added
Removed
  • uspace/srv/net/udp/Makefile

    r4d11204 r048cd69  
    2828
    2929USPACE_PREFIX = ../../..
    30 LIBS = $(LIBNET_PREFIX)/libnet.a
    31 EXTRA_CFLAGS = -I$(LIBNET_PREFIX)/include
     30
     31LIBS = \
     32        $(LIBNETTL_PREFIX)/libnettl.a
     33
     34EXTRA_CFLAGS += \
     35        -I$(LIBNETTL_PREFIX)/include
     36
    3237BINARY = udp
    3338
     
    3540        assoc.c \
    3641        msg.c \
    37         sock.c \
    3842        pdu.c \
    39         ucall.c \
     43        service.c \
    4044        udp.c \
    4145        udp_inet.c
  • uspace/srv/net/udp/assoc.c

    r4d11204 r048cd69  
    11/*
    2  * Copyright (c) 2012 Jiri Svoboda
     2 * Copyright (c) 2015 Jiri Svoboda
    33 * All rights reserved.
    44 *
     
    3636
    3737#include <adt/list.h>
     38#include <errno.h>
    3839#include <stdbool.h>
    3940#include <fibril_synch.h>
     41#include <inet/endpoint.h>
    4042#include <io/log.h>
     43#include <nettl/amap.h>
    4144#include <stdlib.h>
    4245
     
    4447#include "msg.h"
    4548#include "pdu.h"
    46 #include "ucall.h"
    4749#include "udp_inet.h"
    4850#include "udp_type.h"
    4951
    50 LIST_INITIALIZE(assoc_list);
    51 FIBRIL_MUTEX_INITIALIZE(assoc_list_lock);
    52 
    53 static udp_assoc_t *udp_assoc_find_ref(udp_sockpair_t *);
    54 static int udp_assoc_queue_msg(udp_assoc_t *, udp_sockpair_t *, udp_msg_t *);
    55 static bool udp_socket_match(udp_sock_t *, udp_sock_t *);
    56 static bool udp_sockpair_match(udp_sockpair_t *, udp_sockpair_t *);
     52static LIST_INITIALIZE(assoc_list);
     53static FIBRIL_MUTEX_INITIALIZE(assoc_list_lock);
     54static amap_t *amap;
     55
     56static udp_assoc_t *udp_assoc_find_ref(inet_ep2_t *);
     57static int udp_assoc_queue_msg(udp_assoc_t *, inet_ep2_t *, udp_msg_t *);
     58
     59/** Initialize associations. */
     60int udp_assocs_init(void)
     61{
     62        int rc;
     63
     64        rc = amap_create(&amap);
     65        if (rc != EOK) {
     66                assert(rc == ENOMEM);
     67                return ENOMEM;
     68        }
     69
     70        return EOK;
     71}
    5772
    5873/** Create new association structure.
    5974 *
    60  * @param lsock         Local socket (will be deeply copied)
    61  * @param fsock         Foreign socket (will be deeply copied)
     75 * @param epp           Endpoint pair (will be copied)
     76 * @param cb            Callbacks
     77 * @param cb_arg        Callback argument
    6278 * @return              New association or NULL
    6379 */
    64 udp_assoc_t *udp_assoc_new(udp_sock_t *lsock, udp_sock_t *fsock)
     80udp_assoc_t *udp_assoc_new(inet_ep2_t *epp, udp_assoc_cb_t *cb, void *cb_arg)
    6581{
    6682        udp_assoc_t *assoc = NULL;
     
    8096        fibril_condvar_initialize(&assoc->rcv_queue_cv);
    8197
    82         if (lsock != NULL)
    83                 assoc->ident.local = *lsock;
    84        
    85         if (fsock != NULL)
    86                 assoc->ident.foreign = *fsock;
    87 
     98        if (epp != NULL)
     99                assoc->ident = *epp;
     100
     101        assoc->cb = cb;
     102        assoc->cb_arg = cb_arg;
    88103        return assoc;
    89104error:
     
    166181 * Add association to the association map.
    167182 */
    168 void udp_assoc_add(udp_assoc_t *assoc)
    169 {
     183int udp_assoc_add(udp_assoc_t *assoc)
     184{
     185        inet_ep2_t aepp;
     186        int rc;
     187
    170188        udp_assoc_addref(assoc);
    171189        fibril_mutex_lock(&assoc_list_lock);
     190
     191        rc = amap_insert(amap, &assoc->ident, assoc, af_allow_system, &aepp);
     192        if (rc != EOK) {
     193                udp_assoc_delref(assoc);
     194                fibril_mutex_unlock(&assoc_list_lock);
     195                return rc;
     196        }
     197
     198        assoc->ident = aepp;
    172199        list_append(&assoc->link, &assoc_list);
    173200        fibril_mutex_unlock(&assoc_list_lock);
     201
     202        return EOK;
    174203}
    175204
     
    181210{
    182211        fibril_mutex_lock(&assoc_list_lock);
     212        amap_remove(amap, &assoc->ident);
    183213        list_remove(&assoc->link);
    184214        fibril_mutex_unlock(&assoc_list_lock);
     
    196226            assoc, iplink);
    197227        fibril_mutex_lock(&assoc->lock);
    198         assoc->ident.iplink = iplink;
     228        assoc->ident.local_link = iplink;
    199229        fibril_mutex_unlock(&assoc->lock);
    200230}
    201231
    202 /** Set foreign socket in association.
    203  *
    204  * @param assoc         Association
    205  * @param fsock         Foreign socket (deeply copied)
    206  */
    207 void udp_assoc_set_foreign(udp_assoc_t *assoc, udp_sock_t *fsock)
    208 {
    209         log_msg(LOG_DEFAULT, LVL_DEBUG, "udp_assoc_set_foreign(%p, %p)", assoc, fsock);
    210         fibril_mutex_lock(&assoc->lock);
    211         assoc->ident.foreign = *fsock;
    212         fibril_mutex_unlock(&assoc->lock);
    213 }
    214 
    215 /** Set local socket in association.
    216  *
    217  * @param assoc Association
    218  * @param lsock Local socket (deeply copied)
    219  *
    220  */
    221 void udp_assoc_set_local(udp_assoc_t *assoc, udp_sock_t *lsock)
    222 {
    223         log_msg(LOG_DEFAULT, LVL_DEBUG, "udp_assoc_set_local(%p, %p)", assoc, lsock);
    224         fibril_mutex_lock(&assoc->lock);
    225         assoc->ident.local = *lsock;
    226         fibril_mutex_unlock(&assoc->lock);
    227 }
    228 
    229 /** Set local port in association.
    230  *
    231  * @param assoc Association
    232  * @param lport Local port
    233  *
    234  */
    235 void udp_assoc_set_local_port(udp_assoc_t *assoc, uint16_t lport)
    236 {
    237         log_msg(LOG_DEFAULT, LVL_DEBUG, "udp_assoc_set_local(%p, %" PRIu16 ")", assoc, lport);
    238         fibril_mutex_lock(&assoc->lock);
    239         assoc->ident.local.port = lport;
    240         fibril_mutex_unlock(&assoc->lock);
    241 }
    242 
    243232/** Send message to association.
    244233 *
    245234 * @param assoc         Association
    246  * @param fsock         Foreign socket or NULL not to override @a assoc
     235 * @param remote        Remote endpoint or NULL not to override @a assoc
    247236 * @param msg           Message
    248237 *
    249238 * @return              EOK on success
    250  *                      EINVAL if foreign socket is not set
     239 *                      EINVAL if remote endpoint is not set
    251240 *                      ENOMEM if out of resources
    252241 *                      EIO if no route to destination exists
    253242 */
    254 int udp_assoc_send(udp_assoc_t *assoc, udp_sock_t *fsock, udp_msg_t *msg)
     243int udp_assoc_send(udp_assoc_t *assoc, inet_ep_t *remote, udp_msg_t *msg)
    255244{
    256245        udp_pdu_t *pdu;
    257         udp_sockpair_t sp;
     246        inet_ep2_t epp;
    258247        int rc;
    259248
    260249        log_msg(LOG_DEFAULT, LVL_DEBUG, "udp_assoc_send(%p, %p, %p)",
    261             assoc, fsock, msg);
    262 
    263         /* @a fsock can be used to override the foreign socket */
    264         sp = assoc->ident;
    265         if (fsock != NULL)
    266                 sp.foreign = *fsock;
    267 
    268         if ((inet_addr_is_any(&sp.foreign.addr)) ||
    269             (sp.foreign.port == UDP_PORT_ANY))
     250            assoc, remote, msg);
     251
     252        /* @a remote can be used to override the remote endpoint */
     253        epp = assoc->ident;
     254        if (remote != NULL)
     255                epp.remote = *remote;
     256
     257        log_msg(LOG_DEFAULT, LVL_DEBUG, "udp_assoc_send - check addr any");
     258
     259        if ((inet_addr_is_any(&epp.remote.addr)) ||
     260            (epp.remote.port == inet_port_any))
    270261                return EINVAL;
    271262
    272         rc = udp_pdu_encode(&sp, msg, &pdu);
     263        log_msg(LOG_DEFAULT, LVL_DEBUG, "udp_assoc_send - check version");
     264
     265        if (epp.remote.addr.version != epp.local.addr.version)
     266                return EINVAL;
     267
     268        log_msg(LOG_DEFAULT, LVL_DEBUG, "udp_assoc_send - encode pdu");
     269
     270        rc = udp_pdu_encode(&epp, msg, &pdu);
    273271        if (rc != EOK)
    274272                return ENOMEM;
    275273
     274        log_msg(LOG_DEFAULT, LVL_DEBUG, "udp_assoc_send - transmit");
     275
    276276        rc = udp_transmit_pdu(pdu);
    277277        udp_pdu_delete(pdu);
     
    280280                return EIO;
    281281
     282        log_msg(LOG_DEFAULT, LVL_DEBUG, "udp_assoc_send - success");
    282283        return EOK;
    283284}
     
    287288 * Pull one message from the association's receive queue.
    288289 */
    289 int udp_assoc_recv(udp_assoc_t *assoc, udp_msg_t **msg, udp_sock_t *fsock)
     290int udp_assoc_recv(udp_assoc_t *assoc, udp_msg_t **msg, inet_ep_t *remote)
    290291{
    291292        link_t *link;
     
    303304                log_msg(LOG_DEFAULT, LVL_DEBUG, "udp_assoc_recv() - association was reset");
    304305                fibril_mutex_unlock(&assoc->lock);
    305                 return ECONNABORTED;
     306                return ENXIO;
    306307        }
    307308
     
    313314
    314315        *msg = rqe->msg;
    315         *fsock = rqe->sp.foreign;
     316        *remote = rqe->epp.remote;
    316317        free(rqe);
    317318
     
    323324 * Find the association to which the message belongs and queue it.
    324325 */
    325 void udp_assoc_received(udp_sockpair_t *rsp, udp_msg_t *msg)
     326void udp_assoc_received(inet_ep2_t *repp, udp_msg_t *msg)
    326327{
    327328        udp_assoc_t *assoc;
    328329        int rc;
    329330
    330         log_msg(LOG_DEFAULT, LVL_DEBUG, "udp_assoc_received(%p, %p)", rsp, msg);
    331 
    332         assoc = udp_assoc_find_ref(rsp);
     331        log_msg(LOG_DEFAULT, LVL_DEBUG, "udp_assoc_received(%p, %p)", repp, msg);
     332
     333        assoc = udp_assoc_find_ref(repp);
    333334        if (assoc == NULL) {
    334335                log_msg(LOG_DEFAULT, LVL_DEBUG, "No association found. Message dropped.");
     
    339340        }
    340341
    341         rc = udp_assoc_queue_msg(assoc, rsp, msg);
    342         if (rc != EOK) {
    343                 log_msg(LOG_DEFAULT, LVL_DEBUG, "Out of memory. Message dropped.");
     342        if (0) {
     343                rc = udp_assoc_queue_msg(assoc, repp, msg);
     344                if (rc != EOK) {
     345                        log_msg(LOG_DEFAULT, LVL_DEBUG, "Out of memory. Message dropped.");
    344346                /* XXX Generate ICMP error? */
    345         }
     347                }
     348        }
     349
     350        log_msg(LOG_DEFAULT, LVL_DEBUG, "call assoc->cb->recv_msg");
     351        assoc->cb->recv_msg(assoc->cb_arg, repp, msg);
     352        udp_assoc_delref(assoc);
    346353}
    347354
     
    359366}
    360367
    361 static int udp_assoc_queue_msg(udp_assoc_t *assoc, udp_sockpair_t *sp,
     368static int udp_assoc_queue_msg(udp_assoc_t *assoc, inet_ep2_t *epp,
    362369    udp_msg_t *msg)
    363370{
     
    365372
    366373        log_msg(LOG_DEFAULT, LVL_DEBUG, "udp_assoc_queue_msg(%p, %p, %p)",
    367             assoc, sp, msg);
     374            assoc, epp, msg);
    368375
    369376        rqe = calloc(1, sizeof(udp_rcv_queue_entry_t));
     
    372379
    373380        link_initialize(&rqe->link);
    374         rqe->sp = *sp;
     381        rqe->epp = *epp;
    375382        rqe->msg = msg;
    376383
     
    384391}
    385392
    386 /** Match socket with pattern. */
    387 static bool udp_socket_match(udp_sock_t *sock, udp_sock_t *patt)
    388 {
    389         log_msg(LOG_DEFAULT, LVL_DEBUG,
    390             "udp_socket_match(sock=(%u), pat=(%u))", sock->port, patt->port);
    391        
    392         if ((!inet_addr_is_any(&patt->addr)) &&
    393             (!inet_addr_compare(&patt->addr, &sock->addr)))
    394                 return false;
    395        
    396         if ((patt->port != UDP_PORT_ANY) &&
    397             (patt->port != sock->port))
    398                 return false;
    399        
    400         log_msg(LOG_DEFAULT, LVL_DEBUG, " -> match");
    401        
    402         return true;
    403 }
    404 
    405 /** Match socket pair with pattern. */
    406 static bool udp_sockpair_match(udp_sockpair_t *sp, udp_sockpair_t *pattern)
    407 {
    408         log_msg(LOG_DEFAULT, LVL_DEBUG, "udp_sockpair_match(%p, %p)", sp, pattern);
    409 
    410         if (!udp_socket_match(&sp->local, &pattern->local))
    411                 return false;
    412 
    413         if (!udp_socket_match(&sp->foreign, &pattern->foreign))
    414                 return false;
    415 
    416         log_msg(LOG_DEFAULT, LVL_DEBUG, "Socket pair matched.");
    417         return true;
    418 }
    419 
    420 
    421 /** Find association structure for specified socket pair.
    422  *
    423  * An association is uniquely identified by a socket pair. Look up our
    424  * association map and return association structure based on socket pair.
     393/** Find association structure for specified endpoint pair.
     394 *
     395 * An association is uniquely identified by an endpoint pair. Look up our
     396 * association map and return association structure based on endpoint pair.
    425397 * The association reference count is bumped by one.
    426398 *
    427  * @param sp    Socket pair
     399 * @param epp   Endpoint pair
    428400 * @return      Association structure or NULL if not found.
    429401 */
    430 static udp_assoc_t *udp_assoc_find_ref(udp_sockpair_t *sp)
    431 {
    432         log_msg(LOG_DEFAULT, LVL_DEBUG, "udp_assoc_find_ref(%p)", sp);
    433        
     402static udp_assoc_t *udp_assoc_find_ref(inet_ep2_t *epp)
     403{
     404        int rc;
     405        void *arg;
     406        udp_assoc_t *assoc;
     407
     408        log_msg(LOG_DEFAULT, LVL_DEBUG, "udp_assoc_find_ref(%p)", epp);
    434409        fibril_mutex_lock(&assoc_list_lock);
    435        
    436         list_foreach(assoc_list, link, udp_assoc_t, assoc) {
    437                 udp_sockpair_t *asp = &assoc->ident;
    438                
    439                 /* Skip unbound associations */
    440                 if (asp->local.port == UDP_PORT_ANY)
    441                         continue;
    442                
    443                 if (udp_sockpair_match(sp, asp)) {
    444                         log_msg(LOG_DEFAULT, LVL_DEBUG, "Returning assoc %p", assoc);
    445                         udp_assoc_addref(assoc);
    446                         fibril_mutex_unlock(&assoc_list_lock);
    447                         return assoc;
    448                 }
    449         }
    450        
     410
     411        rc = amap_find_match(amap, epp, &arg);
     412        if (rc != EOK) {
     413                assert(rc == ENOMEM);
     414                fibril_mutex_unlock(&assoc_list_lock);
     415                return NULL;
     416        }
     417
     418        assoc = (udp_assoc_t *)arg;
     419        udp_assoc_addref(assoc);
     420
    451421        fibril_mutex_unlock(&assoc_list_lock);
    452         return NULL;
     422        return assoc;
    453423}
    454424
  • uspace/srv/net/udp/assoc.h

    r4d11204 r048cd69  
    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 *);
     43extern int udp_assocs_init(void);
     44extern udp_assoc_t *udp_assoc_new(inet_ep2_t *, udp_assoc_cb_t *, void *);
    4345extern void udp_assoc_delete(udp_assoc_t *);
    44 extern void udp_assoc_add(udp_assoc_t *);
     46extern int udp_assoc_add(udp_assoc_t *);
    4547extern void udp_assoc_remove(udp_assoc_t *);
    4648extern void udp_assoc_addref(udp_assoc_t *);
    4749extern void udp_assoc_delref(udp_assoc_t *);
    4850extern void udp_assoc_set_iplink(udp_assoc_t *, service_id_t);
    49 extern void udp_assoc_set_foreign(udp_assoc_t *, udp_sock_t *);
    50 extern void udp_assoc_set_local(udp_assoc_t *, udp_sock_t *);
    51 extern void udp_assoc_set_local_port(udp_assoc_t *, uint16_t);
    52 extern int udp_assoc_send(udp_assoc_t *, udp_sock_t *, udp_msg_t *);
    53 extern int udp_assoc_recv(udp_assoc_t *, udp_msg_t **, udp_sock_t *);
    54 extern void udp_assoc_received(udp_sockpair_t *, udp_msg_t *);
     51extern int udp_assoc_send(udp_assoc_t *, inet_ep_t *, udp_msg_t *);
     52extern int udp_assoc_recv(udp_assoc_t *, udp_msg_t **, inet_ep_t *);
     53extern void udp_assoc_received(inet_ep2_t *, udp_msg_t *);
    5554extern void udp_assoc_reset(udp_assoc_t *);
    5655
  • uspace/srv/net/udp/msg.c

    r4d11204 r048cd69  
    5050void udp_msg_delete(udp_msg_t *msg)
    5151{
     52        free(msg->data);
    5253        free(msg);
    5354}
  • uspace/srv/net/udp/pdu.c

    r4d11204 r048cd69  
    11/*
    2  * Copyright (c) 2012 Jiri Svoboda
     2 * Copyright (c) 2015 Jiri Svoboda
    33 * All rights reserved.
    44 *
     
    4141#include <stdlib.h>
    4242#include <inet/addr.h>
    43 #include <net/socket_codes.h>
    4443#include "msg.h"
    4544#include "pdu.h"
     
    163162
    164163/** Decode incoming PDU */
    165 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)
    166165{
    167166        udp_msg_t *nmsg;
     
    180179        hdr = (udp_header_t *)pdu->data;
    181180
    182         sp->foreign.port = uint16_t_be2host(hdr->src_port);
    183         sp->foreign.addr = pdu->src;
    184         sp->local.port = uint16_t_be2host(hdr->dest_port);
    185         sp->local.addr = pdu->dest;
     181        epp->local_link = pdu->iplink;
     182        epp->remote.port = uint16_t_be2host(hdr->src_port);
     183        epp->remote.addr = pdu->src;
     184        epp->local.port = uint16_t_be2host(hdr->dest_port);
     185        epp->local.addr = pdu->dest;
    186186
    187187        length = uint16_t_be2host(hdr->length);
     
    197197                return ENOMEM;
    198198
    199         nmsg->data = text;
    200199        nmsg->data_size = length - sizeof(udp_header_t);
     200        nmsg->data = malloc(nmsg->data_size);
     201        if (nmsg->data == NULL)
     202                return ENOMEM;
     203
     204        memcpy(nmsg->data, text, nmsg->data_size);
    201205
    202206        *msg = nmsg;
     
    205209
    206210/** Encode outgoing PDU */
    207 int udp_pdu_encode(udp_sockpair_t *sp, udp_msg_t *msg, udp_pdu_t **pdu)
     211int udp_pdu_encode(inet_ep2_t *epp, udp_msg_t *msg, udp_pdu_t **pdu)
    208212{
    209213        udp_pdu_t *npdu;
     
    215219                return ENOMEM;
    216220
    217         npdu->iplink = sp->iplink;
    218         npdu->src = sp->local.addr;
    219         npdu->dest = sp->foreign.addr;
     221        npdu->iplink = epp->local_link;
     222        npdu->src = epp->local.addr;
     223        npdu->dest = epp->remote.addr;
    220224
    221225        npdu->data_size = sizeof(udp_header_t) + msg->data_size;
     
    227231
    228232        hdr = (udp_header_t *)npdu->data;
    229         hdr->src_port = host2uint16_t_be(sp->local.port);
    230         hdr->dest_port = host2uint16_t_be(sp->foreign.port);
     233        hdr->src_port = host2uint16_t_be(epp->local.port);
     234        hdr->dest_port = host2uint16_t_be(epp->remote.port);
    231235        hdr->length = host2uint16_t_be(npdu->data_size);
    232236        hdr->checksum = 0;
  • uspace/srv/net/udp/pdu.h

    r4d11204 r048cd69  
    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.h

    r4d11204 r048cd69  
    11/*
    2  * Copyright (c) 2012 Jiri Svoboda
     2 * Copyright (c) 2015 Jiri Svoboda
    33 * All rights reserved.
    44 *
     
    3030 * @{
    3131 */
    32 /** @file Socket provider
     32/** @file HelenOS service implementation
    3333 */
    3434
    35 #ifndef SOCK_H
    36 #define SOCK_H
     35#ifndef SERVICE_H
     36#define SERVICE_H
    3737
    38 #include <async.h>
    39 
    40 extern int udp_sock_init(void);
     38extern int udp_service_init(void);
    4139
    4240#endif
  • uspace/srv/net/udp/udp.c

    r4d11204 r048cd69  
    4141#include <task.h>
    4242
     43#include "assoc.h"
     44#include "service.h"
    4345#include "udp_inet.h"
    44 #include "sock.h"
    4546
    4647#define NAME       "udp"
     
    5253        log_msg(LOG_DEFAULT, LVL_DEBUG, "udp_init()");
    5354
     55        rc = udp_assocs_init();
     56        if (rc != EOK) {
     57                log_msg(LOG_DEFAULT, LVL_ERROR, "Failed initializing associations.");
     58                return ENOMEM;
     59        }
     60
    5461        rc = udp_inet_init();
    5562        if (rc != EOK) {
     
    5865        }
    5966
    60         rc = udp_sock_init();
     67        rc = udp_service_init();
    6168        if (rc != EOK) {
    62                 log_msg(LOG_DEFAULT, LVL_ERROR, "Failed initializing socket service.");
     69                log_msg(LOG_DEFAULT, LVL_ERROR, "Failed initializing UDP service.");
    6370                return ENOENT;
    6471        }
  • uspace/srv/net/udp/udp_inet.c

    r4d11204 r048cd69  
    11/*
    2  * Copyright (c) 2012 Jiri Svoboda
     2 * Copyright (c) 2015 Jiri Svoboda
    33 * All rights reserved.
    44 *
     
    6464
    6565        pdu = udp_pdu_new();
     66        pdu->iplink = dgram->iplink;
    6667        pdu->data = dgram->data;
    6768        pdu->data_size = dgram->size;
     
    105106{
    106107        udp_msg_t *dmsg;
    107         udp_sockpair_t rident;
     108        inet_ep2_t rident;
    108109
    109110        log_msg(LOG_DEFAULT, LVL_DEBUG, "udp_received_pdu()");
  • uspace/srv/net/udp/udp_type.h

    r4d11204 r048cd69  
    11/*
    2  * Copyright (c) 2012 Jiri Svoboda
     2 * Copyright (c) 2015 Jiri Svoboda
    33 * All rights reserved.
    44 *
     
    3636#define UDP_TYPE_H
    3737
     38#include <async.h>
    3839#include <fibril.h>
    3940#include <fibril_synch.h>
     41#include <inet/endpoint.h>
    4042#include <ipc/loc.h>
    41 #include <socket_core.h>
    4243#include <sys/types.h>
    4344#include <inet/addr.h>
     
    4950        /* Insufficient resources */
    5051        UDP_ENORES,
    51         /* Foreign socket unspecified */
     52        /* Remote endpoint unspecified */
    5253        UDP_EUNSPEC,
    5354        /* No route to destination */
     
    6061        XF_DUMMY = 0x1
    6162} xflags_t;
    62 
    63 enum udp_port {
    64         UDP_PORT_ANY = 0
    65 };
    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;
    7763
    7864/** Unencoded UDP message (datagram) */
     
    9985
    10086typedef struct {
    101         async_sess_t *sess;
    102         socket_cores_t sockets;
    103 } udp_client_t;
     87        void (*recv_msg)(void *, inet_ep2_t *, udp_msg_t *);
     88} udp_assoc_cb_t;
    10489
    10590/** UDP association
     
    10792 * This is a rough equivalent of a TCP connection endpoint. It allows
    10893 * sending and receiving UDP datagrams and it is uniquely identified
    109  * by a socket pair.
     94 * by an endpoint pair.
    11095 */
    11196typedef struct {
     
    11398        link_t link;
    11499
    115         /** Association identification (local and foreign socket) */
    116         udp_sockpair_t ident;
     100        /** Association identification (endpoint pair) */
     101        inet_ep2_t ident;
    117102
    118103        /** True if association was reset by user */
     
    131116        /** Receive queue CV. Broadcast when new datagram is inserted */
    132117        fibril_condvar_t rcv_queue_cv;
     118
     119        udp_assoc_cb_t *cb;
     120        void *cb_arg;
    133121} udp_assoc_t;
    134122
     
    136124} udp_assoc_status_t;
    137125
    138 typedef struct udp_sockdata {
    139         /** Lock */
    140         fibril_mutex_t lock;
    141         /** Socket core */
    142         socket_core_t *sock_core;
     126typedef struct {
     127        /** Link to receive queue */
     128        link_t link;
     129        /** Endpoint pair */
     130        inet_ep2_t epp;
     131        /** Message */
     132        udp_msg_t *msg;
     133} udp_rcv_queue_entry_t;
     134
     135typedef struct udp_cassoc {
     136        /** Association */
     137        udp_assoc_t *assoc;
     138        /** Association ID for the client */
     139        sysarg_t id;
    143140        /** Client */
    144         udp_client_t *client;
    145         /** Connection */
    146         udp_assoc_t *assoc;
    147         /** User-configured IP link */
    148         service_id_t iplink;
    149         /** Receiving fibril */
    150         fid_t recv_fibril;
    151         uint8_t recv_buffer[UDP_FRAGMENT_SIZE];
    152         size_t recv_buffer_used;
    153         udp_sock_t recv_fsock;
    154         fibril_mutex_t recv_buffer_lock;
    155         fibril_condvar_t recv_buffer_cv;
    156         udp_error_t recv_error;
    157 } udp_sockdata_t;
     141        struct udp_client *client;
     142        link_t lclient;
     143} udp_cassoc_t;
    158144
    159145typedef struct {
    160146        /** Link to receive queue */
    161147        link_t link;
    162         /** Socket pair */
    163         udp_sockpair_t sp;
     148        /** Endpoint pair */
     149        inet_ep2_t epp;
    164150        /** Message */
    165151        udp_msg_t *msg;
    166 } udp_rcv_queue_entry_t;
     152        /** Client association */
     153        udp_cassoc_t *cassoc;
     154} udp_crcv_queue_entry_t;
     155
     156typedef struct udp_client {
     157        /** Client callback session */
     158        async_sess_t *sess;
     159        /** Client assocations */
     160        list_t cassoc; /* of udp_cassoc_t */
     161        /** Client receive queue */
     162        list_t crcv_queue;
     163} udp_client_t;
    167164
    168165#endif
Note: See TracChangeset for help on using the changeset viewer.