Changeset fab2746 in mainline for uspace/srv/net/udp


Ignore:
Timestamp:
2015-04-08T21:25:30Z (10 years ago)
Author:
Jiri Svoboda <jiri@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
99ea91b2
Parents:
ba0eac5
Message:

New transport layer API. Only UDP implemented.

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

Legend:

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

    rba0eac5 rfab2746  
    2828
    2929USPACE_PREFIX = ../../..
    30 LIBS = $(LIBNET_PREFIX)/libnet.a
    31 EXTRA_CFLAGS = -I$(LIBNET_PREFIX)/include
    3230BINARY = udp
    3331
     
    3533        assoc.c \
    3634        msg.c \
    37         sock.c \
    3835        pdu.c \
     36        service.c \
    3937        ucall.c \
    4038        udp.c \
  • uspace/srv/net/udp/assoc.c

    rba0eac5 rfab2746  
    3636
    3737#include <adt/list.h>
     38#include <errno.h>
    3839#include <stdbool.h>
    3940#include <fibril_synch.h>
     
    6263 * @return              New association or NULL
    6364 */
    64 udp_assoc_t *udp_assoc_new(udp_sock_t *lsock, udp_sock_t *fsock)
     65udp_assoc_t *udp_assoc_new(udp_sock_t *lsock, udp_sock_t *fsock,
     66    udp_assoc_cb_t *cb, void *cb_arg)
    6567{
    6668        udp_assoc_t *assoc = NULL;
     
    8284        if (lsock != NULL)
    8385                assoc->ident.local = *lsock;
    84        
     86
    8587        if (fsock != NULL)
    8688                assoc->ident.foreign = *fsock;
    8789
     90        assoc->cb = cb;
     91        assoc->cb_arg = cb_arg;
    8892        return assoc;
    8993error:
     
    258262        int rc;
    259263
    260         log_msg(LOG_DEFAULT, LVL_DEBUG, "udp_assoc_send(%p, %p, %p)",
     264        log_msg(LOG_DEFAULT, LVL_NOTE, "udp_assoc_send(%p, %p, %p)",
    261265            assoc, fsock, msg);
    262266
     
    266270                sp.foreign = *fsock;
    267271
     272        log_msg(LOG_DEFAULT, LVL_NOTE, "udp_assoc_send - check addr any");
     273
    268274        if ((inet_addr_is_any(&sp.foreign.addr)) ||
    269275            (sp.foreign.port == UDP_PORT_ANY))
    270276                return EINVAL;
    271277
     278        log_msg(LOG_DEFAULT, LVL_NOTE, "udp_assoc_send - check version");
     279
     280        if (sp.foreign.addr.version != sp.local.addr.version)
     281                return EINVAL;
     282
     283        log_msg(LOG_DEFAULT, LVL_NOTE, "udp_assoc_send - encode pdu");
     284
    272285        rc = udp_pdu_encode(&sp, msg, &pdu);
    273286        if (rc != EOK)
    274287                return ENOMEM;
    275288
     289        log_msg(LOG_DEFAULT, LVL_NOTE, "udp_assoc_send - transmit");
     290
    276291        rc = udp_transmit_pdu(pdu);
    277292        udp_pdu_delete(pdu);
     
    280295                return EIO;
    281296
     297        log_msg(LOG_DEFAULT, LVL_NOTE, "udp_assoc_send - success");
    282298        return EOK;
    283299}
     
    292308        udp_rcv_queue_entry_t *rqe;
    293309
    294         log_msg(LOG_DEFAULT, LVL_DEBUG, "udp_assoc_recv()");
     310        log_msg(LOG_DEFAULT, LVL_NOTE, "udp_assoc_recv()");
    295311
    296312        fibril_mutex_lock(&assoc->lock);
     
    303319                log_msg(LOG_DEFAULT, LVL_DEBUG, "udp_assoc_recv() - association was reset");
    304320                fibril_mutex_unlock(&assoc->lock);
    305                 return ECONNABORTED;
     321                return ENXIO;
    306322        }
    307323
    308         log_msg(LOG_DEFAULT, LVL_DEBUG, "udp_assoc_recv() - got a message");
     324        log_msg(LOG_DEFAULT, LVL_NOTE, "udp_assoc_recv() - got a message");
    309325        link = list_first(&assoc->rcv_queue);
    310326        rqe = list_get_instance(link, udp_rcv_queue_entry_t, link);
     
    328344        int rc;
    329345
    330         log_msg(LOG_DEFAULT, LVL_DEBUG, "udp_assoc_received(%p, %p)", rsp, msg);
     346        log_msg(LOG_DEFAULT, LVL_NOTE, "udp_assoc_received(%p, %p)", rsp, msg);
    331347
    332348        assoc = udp_assoc_find_ref(rsp);
    333349        if (assoc == NULL) {
    334                 log_msg(LOG_DEFAULT, LVL_DEBUG, "No association found. Message dropped.");
     350                log_msg(LOG_DEFAULT, LVL_NOTE, "No association found. Message dropped.");
    335351                /* XXX Generate ICMP error. */
    336352                /* XXX Might propagate error directly by error return. */
     
    339355        }
    340356
    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.");
     357        if (0) {
     358                rc = udp_assoc_queue_msg(assoc, rsp, msg);
     359                if (rc != EOK) {
     360                        log_msg(LOG_DEFAULT, LVL_DEBUG, "Out of memory. Message dropped.");
    344361                /* XXX Generate ICMP error? */
     362                }
    345363        }
     364
     365        log_msg(LOG_DEFAULT, LVL_NOTE, "call assoc->cb->recv_msg");
     366        assoc->cb->recv_msg(assoc->cb_arg, rsp, msg);
    346367}
    347368
     
    387408static bool udp_socket_match(udp_sock_t *sock, udp_sock_t *patt)
    388409{
    389         log_msg(LOG_DEFAULT, LVL_DEBUG,
    390             "udp_socket_match(sock=(%u), pat=(%u))", sock->port, patt->port);
     410        char *sa, *pa;
     411
     412        sa = pa = (char *)"?";
     413        (void) inet_addr_format(&sock->addr, &sa);
     414        (void) inet_addr_format(&patt->addr, &pa);
     415
     416        log_msg(LOG_DEFAULT, LVL_NOTE,
     417            "udp_socket_match(sock=(%s,%u), pat=(%s,%u))",
     418            sa, sock->port, pa, patt->port);
    391419       
    392420        if ((!inet_addr_is_any(&patt->addr)) &&
     
    394422                return false;
    395423       
     424        log_msg(LOG_DEFAULT, LVL_NOTE, "addr OK");
     425       
    396426        if ((patt->port != UDP_PORT_ANY) &&
    397427            (patt->port != sock->port))
    398428                return false;
    399429       
    400         log_msg(LOG_DEFAULT, LVL_DEBUG, " -> match");
     430        log_msg(LOG_DEFAULT, LVL_NOTE, " -> match");
    401431       
    402432        return true;
     
    430460static udp_assoc_t *udp_assoc_find_ref(udp_sockpair_t *sp)
    431461{
    432         log_msg(LOG_DEFAULT, LVL_DEBUG, "udp_assoc_find_ref(%p)", sp);
     462        char *la, *ra;
     463
     464        log_msg(LOG_DEFAULT, LVL_NOTE, "udp_assoc_find_ref(%p)", sp);
    433465       
    434466        fibril_mutex_lock(&assoc_list_lock);
    435467       
     468        log_msg(LOG_DEFAULT, LVL_NOTE, "associations:");
    436469        list_foreach(assoc_list, link, udp_assoc_t, assoc) {
    437470                udp_sockpair_t *asp = &assoc->ident;
    438471               
     472                la = ra = NULL;
     473
     474                (void) inet_addr_format(&asp->local.addr, &la);
     475                (void) inet_addr_format(&asp->foreign.addr, &ra);
     476
     477                log_msg(LOG_DEFAULT, LVL_NOTE, "find_ref:asp=%p la=%s ra=%s",
     478                    asp, la, ra);
    439479                /* Skip unbound associations */
    440                 if (asp->local.port == UDP_PORT_ANY)
     480                if (asp->local.port == UDP_PORT_ANY) {
     481                        log_msg(LOG_DEFAULT, LVL_NOTE, "skip unbound");
    441482                        continue;
     483                }
    442484               
    443485                if (udp_sockpair_match(sp, asp)) {
     
    446488                        fibril_mutex_unlock(&assoc_list_lock);
    447489                        return assoc;
     490                } else {
     491                        log_msg(LOG_DEFAULT, LVL_NOTE, "not matched");
    448492                }
    449493        }
    450494       
     495        log_msg(LOG_DEFAULT, LVL_NOTE, "associations END");
    451496        fibril_mutex_unlock(&assoc_list_lock);
    452497        return NULL;
  • uspace/srv/net/udp/assoc.h

    rba0eac5 rfab2746  
    4040#include "udp_type.h"
    4141
    42 extern udp_assoc_t *udp_assoc_new(udp_sock_t *, udp_sock_t *);
     42extern udp_assoc_t *udp_assoc_new(udp_sock_t *, udp_sock_t *, udp_assoc_cb_t *,
     43    void *);
    4344extern void udp_assoc_delete(udp_assoc_t *);
    4445extern void udp_assoc_add(udp_assoc_t *);
  • uspace/srv/net/udp/pdu.c

    rba0eac5 rfab2746  
    4141#include <stdlib.h>
    4242#include <inet/addr.h>
    43 #include <net/socket_codes.h>
    4443#include "msg.h"
    4544#include "pdu.h"
  • uspace/srv/net/udp/service.h

    rba0eac5 rfab2746  
    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/ucall.c

    rba0eac5 rfab2746  
    3535 */
    3636
     37#include <errno.h>
    3738#include <io/log.h>
    3839#include <macros.h>
     40#include <mem.h>
    3941
    4042#include "assoc.h"
     
    4850
    4951        log_msg(LOG_DEFAULT, LVL_DEBUG, "udp_uc_create()");
    50         nassoc = udp_assoc_new(NULL, NULL);
     52        nassoc = udp_assoc_new(NULL, NULL, NULL, NULL);
    5153        if (nassoc == NULL)
    5254                return UDP_ENORES;
     
    125127        case EOK:
    126128                break;
    127         case ECONNABORTED:
     129        case ENXIO:
    128130                return UDP_ERESET;
    129131        default:
  • uspace/srv/net/udp/udp.c

    rba0eac5 rfab2746  
    4141#include <task.h>
    4242
     43#include "service.h"
    4344#include "udp_inet.h"
    44 #include "sock.h"
    4545
    4646#define NAME       "udp"
     
    5858        }
    5959
    60         rc = udp_sock_init();
     60        rc = udp_service_init();
    6161        if (rc != EOK) {
    62                 log_msg(LOG_DEFAULT, LVL_ERROR, "Failed initializing socket service.");
     62                log_msg(LOG_DEFAULT, LVL_ERROR, "Failed initializing UDP service.");
    6363                return ENOENT;
    6464        }
  • uspace/srv/net/udp/udp_type.h

    rba0eac5 rfab2746  
    3636#define UDP_TYPE_H
    3737
     38#include <async.h>
    3839#include <fibril.h>
    3940#include <fibril_synch.h>
    4041#include <ipc/loc.h>
    41 #include <socket_core.h>
    4242#include <sys/types.h>
    4343#include <inet/addr.h>
     
    9999
    100100typedef struct {
    101         async_sess_t *sess;
    102         socket_cores_t sockets;
    103 } udp_client_t;
     101        void (*recv_msg)(void *, udp_sockpair_t *, udp_msg_t *);
     102} udp_assoc_cb_t;
    104103
    105104/** UDP association
     
    131130        /** Receive queue CV. Broadcast when new datagram is inserted */
    132131        fibril_condvar_t rcv_queue_cv;
     132
     133        udp_assoc_cb_t *cb;
     134        void *cb_arg;
    133135} udp_assoc_t;
    134136
    135137typedef struct {
    136138} udp_assoc_status_t;
    137 
    138 typedef struct udp_sockdata {
    139         /** Lock */
    140         fibril_mutex_t lock;
    141         /** Socket core */
    142         socket_core_t *sock_core;
    143         /** 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;
    158139
    159140typedef struct {
     
    166147} udp_rcv_queue_entry_t;
    167148
     149typedef struct udp_cassoc {
     150        /** Association */
     151        udp_assoc_t *assoc;
     152        /** Association ID for the client */
     153        sysarg_t id;
     154        /** Client */
     155        struct udp_client *client;
     156        link_t lclient;
     157} udp_cassoc_t;
     158
     159typedef struct {
     160        /** Link to receive queue */
     161        link_t link;
     162        /** Socket pair */
     163        udp_sockpair_t sp;
     164        /** Message */
     165        udp_msg_t *msg;
     166        /** Client association */
     167        udp_cassoc_t *cassoc;
     168} udp_crcv_queue_entry_t;
     169
     170typedef struct udp_client {
     171        /** Client callback session */
     172        async_sess_t *sess;
     173        /** Client assocations */
     174        list_t cassoc; /* of udp_cassoc_t */
     175        /** Client receive queue */
     176        list_t crcv_queue;
     177} udp_client_t;
     178
    168179#endif
    169180
Note: See TracChangeset for help on using the changeset viewer.