Changeset 2989c7e in mainline for uspace/srv/net/udp


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

Association map / portrange prototype.

Location:
uspace/srv/net/udp
Files:
1 deleted
5 edited

Legend:

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

    r58e9dec r2989c7e  
    2828
    2929USPACE_PREFIX = ../../..
     30
     31LIBS = \
     32        $(LIBNETTL_PREFIX)/libnettl.a
     33
     34EXTRA_CFLAGS += \
     35        -I$(LIBNETTL_PREFIX)/include
     36
    3037BINARY = udp
    3138
     
    3542        pdu.c \
    3643        service.c \
    37         ucall.c \
    3844        udp.c \
    3945        udp_inet.c
  • uspace/srv/net/udp/assoc.c

    r58e9dec r2989c7e  
    4141#include <inet/endpoint.h>
    4242#include <io/log.h>
     43#include <nettl/amap.h>
    4344#include <stdlib.h>
    4445
     
    4647#include "msg.h"
    4748#include "pdu.h"
    48 #include "ucall.h"
    4949#include "udp_inet.h"
    5050#include "udp_type.h"
    5151
    52 LIST_INITIALIZE(assoc_list);
    53 FIBRIL_MUTEX_INITIALIZE(assoc_list_lock);
     52static LIST_INITIALIZE(assoc_list);
     53static FIBRIL_MUTEX_INITIALIZE(assoc_list_lock);
     54static amap_t *amap;
    5455
    5556static udp_assoc_t *udp_assoc_find_ref(inet_ep2_t *);
     
    5758static bool udp_ep_match(inet_ep_t *, inet_ep_t *);
    5859static bool udp_ep2_match(inet_ep2_t *, inet_ep2_t *);
     60
     61/** Initialize associations. */
     62int udp_assocs_init(void)
     63{
     64        int rc;
     65
     66        rc = amap_create(&amap);
     67        if (rc != EOK) {
     68                assert(rc == ENOMEM);
     69                return ENOMEM;
     70        }
     71
     72        return EOK;
     73}
    5974
    6075/** Create new association structure.
     
    168183 * Add association to the association map.
    169184 */
    170 void udp_assoc_add(udp_assoc_t *assoc)
    171 {
     185int udp_assoc_add(udp_assoc_t *assoc)
     186{
     187        inet_ep2_t aepp;
     188        int rc;
     189
    172190        udp_assoc_addref(assoc);
    173191        fibril_mutex_lock(&assoc_list_lock);
     192
     193        rc = amap_insert(amap, &assoc->ident, assoc, af_allow_system, &aepp);
     194        if (rc != EOK) {
     195                udp_assoc_delref(assoc);
     196                fibril_mutex_unlock(&assoc_list_lock);
     197                return rc;
     198        }
     199
     200        assoc->ident = aepp;
    174201        list_append(&assoc->link, &assoc_list);
    175202        fibril_mutex_unlock(&assoc_list_lock);
     203
     204        return EOK;
    176205}
    177206
     
    183212{
    184213        fibril_mutex_lock(&assoc_list_lock);
     214        amap_remove(amap, &assoc->ident);
    185215        list_remove(&assoc->link);
    186216        fibril_mutex_unlock(&assoc_list_lock);
     
    199229        fibril_mutex_lock(&assoc->lock);
    200230        assoc->ident.local_link = iplink;
    201         fibril_mutex_unlock(&assoc->lock);
    202 }
    203 
    204 /** Set remote endpoint in association.
    205  *
    206  * @param assoc         Association
    207  * @param remote        Remote endpoint (deeply copied)
    208  */
    209 void udp_assoc_set_remote(udp_assoc_t *assoc, inet_ep_t *remote)
    210 {
    211         log_msg(LOG_DEFAULT, LVL_DEBUG, "udp_assoc_set_remote(%p, %p)", assoc, remote);
    212         fibril_mutex_lock(&assoc->lock);
    213         assoc->ident.remote = *remote;
    214         fibril_mutex_unlock(&assoc->lock);
    215 }
    216 
    217 /** Set local endpoint in association.
    218  *
    219  * @param assoc Association
    220  * @param local Local endpoint (deeply copied)
    221  *
    222  */
    223 void udp_assoc_set_local(udp_assoc_t *assoc, inet_ep_t *local)
    224 {
    225         log_msg(LOG_DEFAULT, LVL_DEBUG, "udp_assoc_set_local(%p, %p)", assoc, local);
    226         fibril_mutex_lock(&assoc->lock);
    227         assoc->ident.local = *local;
    228         fibril_mutex_unlock(&assoc->lock);
    229 }
    230 
    231 /** Set local port in association.
    232  *
    233  * @param assoc Association
    234  * @param lport Local port
    235  *
    236  */
    237 void udp_assoc_set_local_port(udp_assoc_t *assoc, uint16_t lport)
    238 {
    239         log_msg(LOG_DEFAULT, LVL_DEBUG, "udp_assoc_set_local(%p, %" PRIu16 ")", assoc, lport);
    240         fibril_mutex_lock(&assoc->lock);
    241         assoc->ident.local.port = lport;
    242231        fibril_mutex_unlock(&assoc->lock);
    243232}
  • uspace/srv/net/udp/assoc.h

    r58e9dec r2989c7e  
    4141#include "udp_type.h"
    4242
     43extern int udp_assocs_init(void);
    4344extern udp_assoc_t *udp_assoc_new(inet_ep2_t *, udp_assoc_cb_t *, void *);
    4445extern void udp_assoc_delete(udp_assoc_t *);
    45 extern void udp_assoc_add(udp_assoc_t *);
     46extern int udp_assoc_add(udp_assoc_t *);
    4647extern void udp_assoc_remove(udp_assoc_t *);
    4748extern void udp_assoc_addref(udp_assoc_t *);
    4849extern void udp_assoc_delref(udp_assoc_t *);
    4950extern void udp_assoc_set_iplink(udp_assoc_t *, service_id_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 extern void udp_assoc_set_local_port(udp_assoc_t *, uint16_t);
    5351extern int udp_assoc_send(udp_assoc_t *, inet_ep_t *, udp_msg_t *);
    5452extern int udp_assoc_recv(udp_assoc_t *, udp_msg_t **, inet_ep_t *);
  • uspace/srv/net/udp/service.c

    r58e9dec r2989c7e  
    178178        assoc->cb_arg = cassoc;
    179179
    180         udp_assoc_add(assoc);
     180        rc = udp_assoc_add(assoc);
     181        if (rc != EOK) {
     182                udp_cassoc_destroy(cassoc);
     183                udp_assoc_delete(assoc);
     184                return rc;
     185        }
    181186
    182187        *rassoc_id = cassoc->id;
  • uspace/srv/net/udp/udp.c

    r58e9dec r2989c7e  
    4141#include <task.h>
    4242
     43#include "assoc.h"
    4344#include "service.h"
    4445#include "udp_inet.h"
     
    5152
    5253        log_msg(LOG_DEFAULT, LVL_DEBUG, "udp_init()");
     54
     55        rc = udp_assocs_init();
     56        if (rc != EOK) {
     57                log_msg(LOG_DEFAULT, LVL_ERROR, "Failed initializing associations.");
     58                return ENOMEM;
     59        }
    5360
    5461        rc = udp_inet_init();
Note: See TracChangeset for help on using the changeset viewer.