Changeset 4c14b88 in mainline for uspace/srv/net/inetsrv/inet_link.c
- Timestamp:
- 2013-12-31T07:57:14Z (11 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 1b973dc
- Parents:
- 6297465 (diff), 208b5f5 (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. - File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/srv/net/inetsrv/inet_link.c
r6297465 r4c14b88 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, link_list, inet_link_t, ilink) {143 if (ilink->svc_id == svcs[i]) {144 already_known = true;145 break;146 }147 }148 149 if (!already_known) {150 log_msg(LOG_DEFAULT, LVL_DEBUG, "Found IP link '%lu'",151 (unsigned long) svcs[i]);152 rc = inet_link_open(svcs[i]);153 if (rc != EOK)154 log_msg(LOG_DEFAULT, LVL_ERROR, "Could not open IP link.");155 }156 }157 158 fibril_mutex_unlock(&inet_discovery_lock);159 return EOK;160 }161 162 114 static inet_link_t *inet_link_new(void) 163 115 { … … 183 135 } 184 136 185 staticint inet_link_open(service_id_t sid)137 int inet_link_open(service_id_t sid) 186 138 { 187 139 inet_link_t *ilink; … … 231 183 232 184 log_msg(LOG_DEFAULT, LVL_DEBUG, "Opened IP link '%s'", ilink->svc_name); 233 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); 234 198 235 199 inet_addrobj_t *addr = NULL; … … 299 263 } 300 264 265 log_msg(LOG_DEFAULT, LVL_DEBUG, "Configured link '%s'.", ilink->svc_name); 301 266 return EOK; 302 267 … … 307 272 inet_link_delete(ilink); 308 273 return rc; 309 }310 311 static void inet_link_cat_change_cb(void)312 {313 (void) inet_link_check_new();314 }315 316 int inet_link_discovery_start(void)317 {318 int rc;319 320 rc = loc_register_cat_change_cb(inet_link_cat_change_cb);321 if (rc != EOK) {322 log_msg(LOG_DEFAULT, LVL_ERROR, "Failed registering callback for IP link "323 "discovery (%d).", rc);324 return rc;325 }326 327 return inet_link_check_new();328 274 } 329 275 … … 347 293 { 348 294 addr32_t src_v4; 349 uint16_t src_af= inet_addr_get(&dgram->src, &src_v4, NULL);350 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) 351 297 return EINVAL; 352 298 353 299 addr32_t dest_v4; 354 uint16_t dest_af= inet_addr_get(&dgram->dest, &dest_v4, NULL);355 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) 356 302 return EINVAL; 357 303 … … 422 368 { 423 369 addr128_t src_v6; 424 uint16_t src_af= inet_addr_get(&dgram->src, NULL, &src_v6);425 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) 426 372 return EINVAL; 427 373 428 374 addr128_t dest_v6; 429 uint16_t dest_af= inet_addr_get(&dgram->dest, NULL, &dest_v6);430 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) 431 377 return EINVAL; 432 378 … … 478 424 } 479 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 480 438 inet_link_t *inet_link_get_by_id(sysarg_t link_id) 481 439 { 482 fibril_mutex_lock(&inet_discovery_lock); 483 484 list_foreach(inet_link_list, link_list, inet_link_t, ilink) { 485 if (ilink->svc_id == link_id) { 486 fibril_mutex_unlock(&inet_discovery_lock); 487 return ilink; 488 } 489 } 490 491 fibril_mutex_unlock(&inet_discovery_lock); 492 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; 493 447 } 494 448 … … 499 453 size_t count, i; 500 454 501 fibril_mutex_lock(&inet_ discovery_lock);502 count = list_count(&inet_link _list);455 fibril_mutex_lock(&inet_links_lock); 456 count = list_count(&inet_links); 503 457 504 458 id_list = calloc(count, sizeof(sysarg_t)); 505 459 if (id_list == NULL) { 506 fibril_mutex_unlock(&inet_ discovery_lock);460 fibril_mutex_unlock(&inet_links_lock); 507 461 return ENOMEM; 508 462 } 509 463 510 464 i = 0; 511 list_foreach(inet_link _list, link_list, inet_link_t, ilink) {465 list_foreach(inet_links, link_list, inet_link_t, ilink) { 512 466 id_list[i++] = ilink->svc_id; 513 467 log_msg(LOG_DEFAULT, LVL_NOTE, "add link to list"); 514 468 } 515 469 516 fibril_mutex_unlock(&inet_ discovery_lock);470 fibril_mutex_unlock(&inet_links_lock); 517 471 518 472 log_msg(LOG_DEFAULT, LVL_NOTE, "return %zu links", count);
Note:
See TracChangeset
for help on using the changeset viewer.