Changeset 7af0cc5 in mainline for uspace/srv/net/inetsrv/inet_link.c
- Timestamp:
- 2013-09-20T16:46:56Z (11 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- bd88bee
- Parents:
- 947e2ef
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/srv/net/inetsrv/inet_link.c
r947e2ef r7af0cc5 55 55 static uint16_t ip_ident = 0; 56 56 57 static int inet_link_open(service_id_t);58 57 static int inet_iplink_recv(iplink_t *, iplink_recv_sdu_t *, uint16_t); 59 58 … … 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 = … … 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 list_append(&ilink->link_list, &inet_links); 234 186 235 187 inet_addrobj_t *addr = NULL; … … 309 261 } 310 262 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 }329 330 263 /** Send IPv4 datagram over Internet link 331 264 * … … 480 413 inet_link_t *inet_link_get_by_id(sysarg_t link_id) 481 414 { 482 fibril_mutex_lock(&inet_ discovery_lock);483 484 list_foreach(inet_link _list, link_list, inet_link_t, ilink) {415 fibril_mutex_lock(&inet_links_lock); 416 417 list_foreach(inet_links, link_list, inet_link_t, ilink) { 485 418 if (ilink->svc_id == link_id) { 486 fibril_mutex_unlock(&inet_ discovery_lock);419 fibril_mutex_unlock(&inet_links_lock); 487 420 return ilink; 488 421 } 489 422 } 490 423 491 fibril_mutex_unlock(&inet_ discovery_lock);424 fibril_mutex_unlock(&inet_links_lock); 492 425 return NULL; 493 426 } … … 499 432 size_t count, i; 500 433 501 fibril_mutex_lock(&inet_ discovery_lock);502 count = list_count(&inet_link _list);434 fibril_mutex_lock(&inet_links_lock); 435 count = list_count(&inet_links); 503 436 504 437 id_list = calloc(count, sizeof(sysarg_t)); 505 438 if (id_list == NULL) { 506 fibril_mutex_unlock(&inet_ discovery_lock);439 fibril_mutex_unlock(&inet_links_lock); 507 440 return ENOMEM; 508 441 } 509 442 510 443 i = 0; 511 list_foreach(inet_link _list, link_list, inet_link_t, ilink) {444 list_foreach(inet_links, link_list, inet_link_t, ilink) { 512 445 id_list[i++] = ilink->svc_id; 513 446 log_msg(LOG_DEFAULT, LVL_NOTE, "add link to list"); 514 447 } 515 448 516 fibril_mutex_unlock(&inet_ discovery_lock);449 fibril_mutex_unlock(&inet_links_lock); 517 450 518 451 log_msg(LOG_DEFAULT, LVL_NOTE, "return %zu links", count);
Note:
See TracChangeset
for help on using the changeset viewer.