Changeset 2989c7e in mainline
- Timestamp:
- 2015-05-25T21:04:33Z (10 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- ab6326bc
- Parents:
- 58e9dec
- Location:
- uspace
- Files:
-
- 4 added
- 1 deleted
- 13 edited
- 1 moved
Legend:
- Unmodified
- Added
- Removed
-
uspace/Makefile
r58e9dec r2989c7e 221 221 lib/draw \ 222 222 lib/math \ 223 lib/nettl \ 223 224 lib/nic \ 224 225 lib/ext4 \ -
uspace/Makefile.common
r58e9dec r2989c7e 155 155 LIBMBR_PREFIX = $(LIB_PREFIX)/mbr 156 156 LIBGPT_PREFIX = $(LIB_PREFIX)/gpt 157 LIBNETTL_PREFIX = $(LIB_PREFIX)/nettl 157 158 158 159 LIBURCU_PREFIX = $(LIB_PREFIX)/urcu -
uspace/lib/nettl/include/nettl/portrng.h
r58e9dec r2989c7e 27 27 */ 28 28 29 /** @addtogroup udp29 /** @addtogroup libnettl 30 30 * @{ 31 31 */ 32 /** @file UDP user calls 32 /** 33 * @file Port range allocator. 33 34 */ 34 35 35 #ifndef UCALL_H36 #define UCALL_H36 #ifndef LIBNETTL_PORTRNG_H_ 37 #define LIBNETTL_PORTRNG_H_ 37 38 38 #include <ipc/loc.h> 39 #include <sys/types.h> 40 #include "udp_type.h" 39 #include <stdint.h> 41 40 42 extern udp_error_t udp_uc_create(udp_assoc_t **); 43 extern void udp_uc_set_iplink(udp_assoc_t *, service_id_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 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 *, inet_ep_t *, void *, size_t, 48 xflags_t); 49 extern udp_error_t udp_uc_receive(udp_assoc_t *, void *, size_t, size_t *, 50 xflags_t *, inet_ep_t *); 51 extern void udp_uc_status(udp_assoc_t *, udp_assoc_status_t *); 52 extern void udp_uc_destroy(udp_assoc_t *); 53 extern void udp_uc_reset(udp_assoc_t *); 41 typedef struct { 42 } portrng_t; 43 44 typedef enum { 45 pf_allow_system = 0x1 46 } portrng_flags_t; 47 48 extern int portrng_create(portrng_t **); 49 extern void portrng_destroy(portrng_t *); 50 extern int portrng_alloc_specific(portrng_t *, uint16_t, void *, 51 portrng_flags_t); 52 extern int portrng_alloc_dynamic(portrng_t *, void *, uint16_t *); 53 extern void portrng_free_port(portrng_t *, uint16_t); 54 54 55 55 #endif -
uspace/srv/net/tcp/Makefile
r58e9dec r2989c7e 28 28 29 29 USPACE_PREFIX = ../../.. 30 31 LIBS = \ 32 $(LIBNETTL_PREFIX)/libnettl.a 33 34 EXTRA_CFLAGS += \ 35 -I$(LIBNETTL_PREFIX)/include 36 30 37 BINARY = tcp 31 38 -
uspace/srv/net/tcp/conn.c
r58e9dec r2989c7e 36 36 37 37 #include <adt/list.h> 38 #include <stdbool.h>39 38 #include <errno.h> 40 39 #include <inet/endpoint.h> 41 40 #include <io/log.h> 42 41 #include <macros.h> 42 #include <nettl/amap.h> 43 #include <stdbool.h> 43 44 #include <stdlib.h> 44 45 #include "conn.h" … … 56 57 #define TIME_WAIT_TIMEOUT (2*MAX_SEGMENT_LIFETIME) 57 58 58 LIST_INITIALIZE(conn_list); 59 FIBRIL_MUTEX_INITIALIZE(conn_list_lock); 59 static LIST_INITIALIZE(conn_list); 60 static FIBRIL_MUTEX_INITIALIZE(conn_list_lock); 61 static amap_t *amap; 60 62 61 63 static void tcp_conn_seg_process(tcp_conn_t *conn, tcp_segment_t *seg); 62 64 static void tcp_conn_tw_timer_set(tcp_conn_t *conn); 63 65 static void tcp_conn_tw_timer_clear(tcp_conn_t *conn); 66 67 /** Initialize connections. */ 68 int tcp_conns_init(void) 69 { 70 int rc; 71 72 rc = amap_create(&amap); 73 if (rc != EOK) { 74 assert(rc == ENOMEM); 75 return ENOMEM; 76 } 77 78 return EOK; 79 } 64 80 65 81 /** Create new connection structure. … … 246 262 * Add connection to the connection map. 247 263 */ 248 void tcp_conn_add(tcp_conn_t *conn) 249 { 264 int tcp_conn_add(tcp_conn_t *conn) 265 { 266 inet_ep2_t aepp; 267 int rc; 268 250 269 tcp_conn_addref(conn); 251 270 fibril_mutex_lock(&conn_list_lock); 271 272 rc = amap_insert(amap, &conn->ident, conn, af_allow_system, &aepp); 273 if (rc != EOK) { 274 tcp_conn_delref(conn); 275 fibril_mutex_unlock(&conn_list_lock); 276 return rc; 277 } 278 279 conn->ident = aepp; 252 280 list_append(&conn->link, &conn_list); 253 281 fibril_mutex_unlock(&conn_list_lock); 282 283 return EOK; 254 284 } 255 285 … … 261 291 { 262 292 fibril_mutex_lock(&conn_list_lock); 293 amap_remove(amap, &conn->ident); 263 294 list_remove(&conn->link); 264 295 fibril_mutex_unlock(&conn_list_lock); -
uspace/srv/net/tcp/conn.h
r58e9dec r2989c7e 40 40 #include "tcp_type.h" 41 41 42 extern int tcp_conns_init(void); 42 43 extern tcp_conn_t *tcp_conn_new(inet_ep2_t *); 43 44 extern void tcp_conn_delete(tcp_conn_t *); 44 extern voidtcp_conn_add(tcp_conn_t *);45 extern int tcp_conn_add(tcp_conn_t *); 45 46 extern void tcp_conn_remove(tcp_conn_t *); 46 47 extern void tcp_conn_reset(tcp_conn_t *conn); -
uspace/srv/net/tcp/service.c
r58e9dec r2989c7e 335 335 tcp_conn_t *conn; 336 336 tcp_cconn_t *cconn; 337 inet_ep2_t cepp;338 337 int rc; 339 338 tcp_error_t trc; … … 343 342 log_msg(LOG_DEFAULT, LVL_DEBUG, "tcp_conn_create_impl"); 344 343 345 cepp = *epp; 346 347 /* Fill in local address? */ 348 if (inet_addr_is_any(&epp->local.addr)) { 349 log_msg(LOG_DEFAULT, LVL_DEBUG, "tcp_conn_create_impl: " 350 "determine local address"); 351 rc = inet_get_srcaddr(&epp->remote.addr, 0, &cepp.local.addr); 352 if (rc != EOK) { 353 log_msg(LOG_DEFAULT, LVL_DEBUG, "tcp_conn_create_impl: " 354 "cannot determine local address"); 355 return rc; 356 } 357 } else { 358 log_msg(LOG_DEFAULT, LVL_DEBUG, "tcp_conn_create_impl: " 359 "local address specified"); 360 } 361 362 /* Allocate local port? */ 363 if (cepp.local.port == 0) { 364 cepp.local.port = 49152; /* XXX */ 365 log_msg(LOG_DEFAULT, LVL_DEBUG, "tcp_conn_create_impl: " 366 "allocated local port %" PRIu16, cepp.local.port); 367 } else { 368 log_msg(LOG_DEFAULT, LVL_DEBUG, "tcp_conn_create_impl: " 369 "local port %" PRIu16 " specified", cepp.local.port); 370 } 371 372 inet_addr_format(&cepp.local.addr, &slocal); 373 inet_addr_format(&cepp.remote.addr, &sremote); 344 inet_addr_format(&epp->local.addr, &slocal); 345 inet_addr_format(&epp->remote.addr, &sremote); 374 346 log_msg(LOG_DEFAULT, LVL_DEBUG, "tcp_conn_create: local=%s remote=%s", 375 347 slocal, sremote); … … 377 349 free(sremote); 378 350 379 trc = tcp_uc_open( &cepp, ap_active, tcp_open_nonblock, &conn);351 trc = tcp_uc_open(epp, ap_active, tcp_open_nonblock, &conn); 380 352 if (trc != TCP_EOK) 381 353 return EIO; -
uspace/srv/net/tcp/tcp.c
r58e9dec r2989c7e 45 45 #include <task.h> 46 46 47 #include "conn.h" 47 48 #include "ncsim.h" 48 49 #include "pdu.h" … … 179 180 log_msg(LOG_DEFAULT, LVL_DEBUG, "tcp_init()"); 180 181 182 rc = tcp_conns_init(); 183 if (rc != EOK) { 184 assert(rc == ENOMEM); 185 log_msg(LOG_DEFAULT, LVL_ERROR, "Failed initializing connections"); 186 return ENOMEM; 187 } 188 181 189 tcp_rqueue_init(); 182 190 tcp_rqueue_fibril_start(); -
uspace/srv/net/tcp/ucall.c
r58e9dec r2989c7e 35 35 */ 36 36 37 #include <errno.h> 37 38 #include <fibril_synch.h> 38 39 #include <io/log.h> … … 68 69 { 69 70 tcp_conn_t *nconn; 71 int rc; 70 72 71 73 log_msg(LOG_DEFAULT, LVL_DEBUG, "tcp_uc_open(%p, %s, %s, %p)", … … 74 76 75 77 nconn = tcp_conn_new(epp); 76 tcp_conn_add(nconn); 78 rc = tcp_conn_add(nconn); 79 if (rc != EOK) { 80 tcp_conn_delete(nconn); 81 return TCP_EEXISTS; 82 } 83 77 84 tcp_conn_lock(nconn); 78 85 -
uspace/srv/net/udp/Makefile
r58e9dec r2989c7e 28 28 29 29 USPACE_PREFIX = ../../.. 30 31 LIBS = \ 32 $(LIBNETTL_PREFIX)/libnettl.a 33 34 EXTRA_CFLAGS += \ 35 -I$(LIBNETTL_PREFIX)/include 36 30 37 BINARY = udp 31 38 … … 35 42 pdu.c \ 36 43 service.c \ 37 ucall.c \38 44 udp.c \ 39 45 udp_inet.c -
uspace/srv/net/udp/assoc.c
r58e9dec r2989c7e 41 41 #include <inet/endpoint.h> 42 42 #include <io/log.h> 43 #include <nettl/amap.h> 43 44 #include <stdlib.h> 44 45 … … 46 47 #include "msg.h" 47 48 #include "pdu.h" 48 #include "ucall.h"49 49 #include "udp_inet.h" 50 50 #include "udp_type.h" 51 51 52 LIST_INITIALIZE(assoc_list); 53 FIBRIL_MUTEX_INITIALIZE(assoc_list_lock); 52 static LIST_INITIALIZE(assoc_list); 53 static FIBRIL_MUTEX_INITIALIZE(assoc_list_lock); 54 static amap_t *amap; 54 55 55 56 static udp_assoc_t *udp_assoc_find_ref(inet_ep2_t *); … … 57 58 static bool udp_ep_match(inet_ep_t *, inet_ep_t *); 58 59 static bool udp_ep2_match(inet_ep2_t *, inet_ep2_t *); 60 61 /** Initialize associations. */ 62 int 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 } 59 74 60 75 /** Create new association structure. … … 168 183 * Add association to the association map. 169 184 */ 170 void udp_assoc_add(udp_assoc_t *assoc) 171 { 185 int udp_assoc_add(udp_assoc_t *assoc) 186 { 187 inet_ep2_t aepp; 188 int rc; 189 172 190 udp_assoc_addref(assoc); 173 191 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; 174 201 list_append(&assoc->link, &assoc_list); 175 202 fibril_mutex_unlock(&assoc_list_lock); 203 204 return EOK; 176 205 } 177 206 … … 183 212 { 184 213 fibril_mutex_lock(&assoc_list_lock); 214 amap_remove(amap, &assoc->ident); 185 215 list_remove(&assoc->link); 186 216 fibril_mutex_unlock(&assoc_list_lock); … … 199 229 fibril_mutex_lock(&assoc->lock); 200 230 assoc->ident.local_link = iplink; 201 fibril_mutex_unlock(&assoc->lock);202 }203 204 /** Set remote endpoint in association.205 *206 * @param assoc Association207 * @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 Association220 * @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 Association234 * @param lport Local port235 *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;242 231 fibril_mutex_unlock(&assoc->lock); 243 232 } -
uspace/srv/net/udp/assoc.h
r58e9dec r2989c7e 41 41 #include "udp_type.h" 42 42 43 extern int udp_assocs_init(void); 43 44 extern udp_assoc_t *udp_assoc_new(inet_ep2_t *, udp_assoc_cb_t *, void *); 44 45 extern void udp_assoc_delete(udp_assoc_t *); 45 extern voidudp_assoc_add(udp_assoc_t *);46 extern int udp_assoc_add(udp_assoc_t *); 46 47 extern void udp_assoc_remove(udp_assoc_t *); 47 48 extern void udp_assoc_addref(udp_assoc_t *); 48 49 extern void udp_assoc_delref(udp_assoc_t *); 49 50 extern 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);53 51 extern int udp_assoc_send(udp_assoc_t *, inet_ep_t *, udp_msg_t *); 54 52 extern int udp_assoc_recv(udp_assoc_t *, udp_msg_t **, inet_ep_t *); -
uspace/srv/net/udp/service.c
r58e9dec r2989c7e 178 178 assoc->cb_arg = cassoc; 179 179 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 } 181 186 182 187 *rassoc_id = cassoc->id; -
uspace/srv/net/udp/udp.c
r58e9dec r2989c7e 41 41 #include <task.h> 42 42 43 #include "assoc.h" 43 44 #include "service.h" 44 45 #include "udp_inet.h" … … 51 52 52 53 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 } 53 60 54 61 rc = udp_inet_init();
Note:
See TracChangeset
for help on using the changeset viewer.