Changes in uspace/srv/net/inetsrv/inet_link.c [1f97352:417a2ba1] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/srv/net/inetsrv/inet_link.c
r1f97352 r417a2ba1 43 43 #include <stdlib.h> 44 44 #include <str.h> 45 #include <net/socket_codes.h>46 45 #include "addrobj.h" 47 46 #include "inetsrv.h" … … 55 54 static uint16_t ip_ident = 0; 56 55 57 static int inet_ link_open(service_id_t);58 static in t inet_iplink_recv(iplink_t *, iplink_recv_sdu_t *, uint16_t);56 static int inet_iplink_recv(iplink_t *, iplink_recv_sdu_t *, ip_ver_t); 57 static inet_link_t *inet_link_get_by_id_locked(sysarg_t); 59 58 60 59 static iplink_ev_ops_t inet_iplink_ev_ops = { … … 62 61 }; 63 62 64 static LIST_INITIALIZE(inet_link _list);65 static FIBRIL_MUTEX_INITIALIZE(inet_ discovery_lock);63 static LIST_INITIALIZE(inet_links); 64 static FIBRIL_MUTEX_INITIALIZE(inet_links_lock); 66 65 67 66 static addr128_t link_local_node_ip = … … 81 80 } 82 81 83 static int inet_iplink_recv(iplink_t *iplink, iplink_recv_sdu_t *sdu, uint16_t af)82 static int inet_iplink_recv(iplink_t *iplink, iplink_recv_sdu_t *sdu, ip_ver_t ver) 84 83 { 85 84 log_msg(LOG_DEFAULT, LVL_DEBUG, "inet_iplink_recv()"); … … 88 87 inet_packet_t packet; 89 88 90 switch ( af) {91 case AF_INET:89 switch (ver) { 90 case ip_v4: 92 91 rc = inet_pdu_decode(sdu->data, sdu->size, &packet); 93 92 break; 94 case AF_INET6:93 case ip_v6: 95 94 rc = inet_pdu_decode6(sdu->data, sdu->size, &packet); 96 95 break; 97 96 default: 98 log_msg(LOG_DEFAULT, LVL_DEBUG, "invalid address family");97 log_msg(LOG_DEFAULT, LVL_DEBUG, "invalid IP version"); 99 98 return EINVAL; 100 99 } … … 113 112 } 114 113 115 static int inet_link_check_new(void)116 {117 bool already_known;118 category_id_t iplink_cat;119 service_id_t *svcs;120 size_t count, i;121 int rc;122 123 fibril_mutex_lock(&inet_discovery_lock);124 125 rc = loc_category_get_id("iplink", &iplink_cat, IPC_FLAG_BLOCKING);126 if (rc != EOK) {127 log_msg(LOG_DEFAULT, LVL_ERROR, "Failed resolving category 'iplink'.");128 fibril_mutex_unlock(&inet_discovery_lock);129 return ENOENT;130 }131 132 rc = loc_category_get_svcs(iplink_cat, &svcs, &count);133 if (rc != EOK) {134 log_msg(LOG_DEFAULT, LVL_ERROR, "Failed getting list of IP links.");135 fibril_mutex_unlock(&inet_discovery_lock);136 return EIO;137 }138 139 for (i = 0; i < count; i++) {140 already_known = false;141 142 list_foreach(inet_link_list, ilink_link) {143 inet_link_t *ilink = list_get_instance(ilink_link,144 inet_link_t, link_list);145 if (ilink->svc_id == svcs[i]) {146 already_known = true;147 break;148 }149 }150 151 if (!already_known) {152 log_msg(LOG_DEFAULT, LVL_DEBUG, "Found IP link '%lu'",153 (unsigned long) svcs[i]);154 rc = inet_link_open(svcs[i]);155 if (rc != EOK)156 log_msg(LOG_DEFAULT, LVL_ERROR, "Could not open IP link.");157 }158 }159 160 fibril_mutex_unlock(&inet_discovery_lock);161 return EOK;162 }163 164 114 static inet_link_t *inet_link_new(void) 165 115 { … … 185 135 } 186 136 187 staticint inet_link_open(service_id_t sid)137 int inet_link_open(service_id_t sid) 188 138 { 189 139 inet_link_t *ilink; … … 233 183 234 184 log_msg(LOG_DEFAULT, LVL_DEBUG, "Opened IP link '%s'", ilink->svc_name); 235 list_append(&ilink->link_list, &inet_link_list); 185 186 fibril_mutex_lock(&inet_links_lock); 187 188 if (inet_link_get_by_id_locked(sid) != NULL) { 189 fibril_mutex_unlock(&inet_links_lock); 190 log_msg(LOG_DEFAULT, LVL_DEBUG, "Link %zu already open", 191 sid); 192 rc = EEXIST; 193 goto error; 194 } 195 196 list_append(&ilink->link_list, &inet_links); 197 fibril_mutex_unlock(&inet_links_lock); 236 198 237 199 inet_addrobj_t *addr = NULL; 238 200 201 /* XXX FIXME Cannot rely on loopback being the first IP link service!! */ 239 202 if (first_link) { 240 203 addr = inet_addrobj_new(); … … 242 205 inet_naddr(&addr->naddr, 127, 0, 0, 1, 24); 243 206 first_link = false; 244 } else {245 /*246 * FIXME247 * Setting static IPv4 address for testing purposes:248 * 10.0.2.15/24249 */250 addr = inet_addrobj_new();251 252 inet_naddr(&addr->naddr, 10, 0, 2, 15, 24);253 207 } 254 208 … … 309 263 } 310 264 265 log_msg(LOG_DEFAULT, LVL_DEBUG, "Configured link '%s'.", ilink->svc_name); 311 266 return EOK; 312 267 … … 317 272 inet_link_delete(ilink); 318 273 return rc; 319 }320 321 static void inet_link_cat_change_cb(void)322 {323 (void) inet_link_check_new();324 }325 326 int inet_link_discovery_start(void)327 {328 int rc;329 330 rc = loc_register_cat_change_cb(inet_link_cat_change_cb);331 if (rc != EOK) {332 log_msg(LOG_DEFAULT, LVL_ERROR, "Failed registering callback for IP link "333 "discovery (%d).", rc);334 return rc;335 }336 337 return inet_link_check_new();338 274 } 339 275 … … 357 293 { 358 294 addr32_t src_v4; 359 uint16_t src_af= inet_addr_get(&dgram->src, &src_v4, NULL);360 if (src_ af != AF_INET)295 ip_ver_t src_ver = inet_addr_get(&dgram->src, &src_v4, NULL); 296 if (src_ver != ip_v4) 361 297 return EINVAL; 362 298 363 299 addr32_t dest_v4; 364 uint16_t dest_af= inet_addr_get(&dgram->dest, &dest_v4, NULL);365 if (dest_ af != AF_INET)300 ip_ver_t dest_ver = inet_addr_get(&dgram->dest, &dest_v4, NULL); 301 if (dest_ver != ip_v4) 366 302 return EINVAL; 367 303 … … 432 368 { 433 369 addr128_t src_v6; 434 uint16_t src_af= inet_addr_get(&dgram->src, NULL, &src_v6);435 if (src_ af != AF_INET6)370 ip_ver_t src_ver = inet_addr_get(&dgram->src, NULL, &src_v6); 371 if (src_ver != ip_v6) 436 372 return EINVAL; 437 373 438 374 addr128_t dest_v6; 439 uint16_t dest_af= inet_addr_get(&dgram->dest, NULL, &dest_v6);440 if (dest_ af != AF_INET6)375 ip_ver_t dest_ver = inet_addr_get(&dgram->dest, NULL, &dest_v6); 376 if (dest_ver != ip_v6) 441 377 return EINVAL; 442 378 … … 488 424 } 489 425 426 static inet_link_t *inet_link_get_by_id_locked(sysarg_t link_id) 427 { 428 assert(fibril_mutex_is_locked(&inet_links_lock)); 429 430 list_foreach(inet_links, link_list, inet_link_t, ilink) { 431 if (ilink->svc_id == link_id) 432 return ilink; 433 } 434 435 return NULL; 436 } 437 490 438 inet_link_t *inet_link_get_by_id(sysarg_t link_id) 491 439 { 492 fibril_mutex_lock(&inet_discovery_lock); 493 494 list_foreach(inet_link_list, elem) { 495 inet_link_t *ilink = list_get_instance(elem, inet_link_t, 496 link_list); 497 498 if (ilink->svc_id == link_id) { 499 fibril_mutex_unlock(&inet_discovery_lock); 500 return ilink; 501 } 502 } 503 504 fibril_mutex_unlock(&inet_discovery_lock); 505 return NULL; 440 inet_link_t *ilink; 441 442 fibril_mutex_lock(&inet_links_lock); 443 ilink = inet_link_get_by_id_locked(link_id); 444 fibril_mutex_unlock(&inet_links_lock); 445 446 return ilink; 447 } 448 449 /** Get IDs of all links. */ 450 int inet_link_get_id_list(sysarg_t **rid_list, size_t *rcount) 451 { 452 sysarg_t *id_list; 453 size_t count, i; 454 455 fibril_mutex_lock(&inet_links_lock); 456 count = list_count(&inet_links); 457 458 id_list = calloc(count, sizeof(sysarg_t)); 459 if (id_list == NULL) { 460 fibril_mutex_unlock(&inet_links_lock); 461 return ENOMEM; 462 } 463 464 i = 0; 465 list_foreach(inet_links, link_list, inet_link_t, ilink) { 466 id_list[i++] = ilink->svc_id; 467 log_msg(LOG_DEFAULT, LVL_NOTE, "add link to list"); 468 } 469 470 fibril_mutex_unlock(&inet_links_lock); 471 472 log_msg(LOG_DEFAULT, LVL_NOTE, "return %zu links", count); 473 *rid_list = id_list; 474 *rcount = count; 475 476 return EOK; 506 477 } 507 478
Note:
See TracChangeset
for help on using the changeset viewer.