Changes in uspace/srv/net/inetsrv/inet_link.c [b8b1adb1:b417559] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/srv/net/inetsrv/inet_link.c
rb8b1adb1 rb417559 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); 58 static inet_link_t *inet_link_get_by_id_locked(sysarg_t); 59 59 60 60 static iplink_ev_ops_t inet_iplink_ev_ops = { … … 62 62 }; 63 63 64 static LIST_INITIALIZE(inet_link _list);65 static FIBRIL_MUTEX_INITIALIZE(inet_ discovery_lock);64 static LIST_INITIALIZE(inet_links); 65 static FIBRIL_MUTEX_INITIALIZE(inet_links_lock); 66 66 67 67 static addr128_t link_local_node_ip = … … 113 113 } 114 114 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 115 static inet_link_t *inet_link_new(void) 163 116 { … … 183 136 } 184 137 185 staticint inet_link_open(service_id_t sid)138 int inet_link_open(service_id_t sid) 186 139 { 187 140 inet_link_t *ilink; … … 231 184 232 185 log_msg(LOG_DEFAULT, LVL_DEBUG, "Opened IP link '%s'", ilink->svc_name); 233 list_append(&ilink->link_list, &inet_link_list); 186 187 fibril_mutex_lock(&inet_links_lock); 188 189 if (inet_link_get_by_id_locked(sid) != NULL) { 190 fibril_mutex_unlock(&inet_links_lock); 191 log_msg(LOG_DEFAULT, LVL_DEBUG, "Link %zu already open", 192 sid); 193 rc = EEXIST; 194 goto error; 195 } 196 197 list_append(&ilink->link_list, &inet_links); 198 fibril_mutex_unlock(&inet_links_lock); 234 199 235 200 inet_addrobj_t *addr = NULL; … … 299 264 } 300 265 266 log_msg(LOG_DEFAULT, LVL_DEBUG, "Configured link '%s'.", ilink->svc_name); 301 267 return EOK; 302 268 … … 307 273 inet_link_delete(ilink); 308 274 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 275 } 329 276 … … 478 425 } 479 426 427 static inet_link_t *inet_link_get_by_id_locked(sysarg_t link_id) 428 { 429 assert(fibril_mutex_is_locked(&inet_links_lock)); 430 431 list_foreach(inet_links, link_list, inet_link_t, ilink) { 432 if (ilink->svc_id == link_id) 433 return ilink; 434 } 435 436 return NULL; 437 } 438 480 439 inet_link_t *inet_link_get_by_id(sysarg_t link_id) 481 440 { 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; 441 inet_link_t *ilink; 442 443 fibril_mutex_lock(&inet_links_lock); 444 ilink = inet_link_get_by_id_locked(link_id); 445 fibril_mutex_unlock(&inet_links_lock); 446 447 return ilink; 493 448 } 494 449 … … 499 454 size_t count, i; 500 455 501 fibril_mutex_lock(&inet_ discovery_lock);502 count = list_count(&inet_link _list);456 fibril_mutex_lock(&inet_links_lock); 457 count = list_count(&inet_links); 503 458 504 459 id_list = calloc(count, sizeof(sysarg_t)); 505 460 if (id_list == NULL) { 506 fibril_mutex_unlock(&inet_ discovery_lock);461 fibril_mutex_unlock(&inet_links_lock); 507 462 return ENOMEM; 508 463 } 509 464 510 465 i = 0; 511 list_foreach(inet_link _list, link_list, inet_link_t, ilink) {466 list_foreach(inet_links, link_list, inet_link_t, ilink) { 512 467 id_list[i++] = ilink->svc_id; 513 468 log_msg(LOG_DEFAULT, LVL_NOTE, "add link to list"); 514 469 } 515 470 516 fibril_mutex_unlock(&inet_ discovery_lock);471 fibril_mutex_unlock(&inet_links_lock); 517 472 518 473 log_msg(LOG_DEFAULT, LVL_NOTE, "return %zu links", count);
Note:
See TracChangeset
for help on using the changeset viewer.