Changes in uspace/srv/net/inetsrv/inet_link.c [b417559:b8b1adb1] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/srv/net/inetsrv/inet_link.c
rb417559 rb8b1adb1 55 55 static uint16_t ip_ident = 0; 56 56 57 static int inet_link_open(service_id_t); 57 58 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 s);65 static FIBRIL_MUTEX_INITIALIZE(inet_ links_lock);64 static LIST_INITIALIZE(inet_link_list); 65 static FIBRIL_MUTEX_INITIALIZE(inet_discovery_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 115 162 static inet_link_t *inet_link_new(void) 116 163 { … … 136 183 } 137 184 138 int inet_link_open(service_id_t sid)185 static int inet_link_open(service_id_t sid) 139 186 { 140 187 inet_link_t *ilink; … … 184 231 185 232 log_msg(LOG_DEFAULT, LVL_DEBUG, "Opened IP link '%s'", ilink->svc_name); 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); 233 list_append(&ilink->link_list, &inet_link_list); 199 234 200 235 inet_addrobj_t *addr = NULL; … … 264 299 } 265 300 266 log_msg(LOG_DEFAULT, LVL_DEBUG, "Configured link '%s'.", ilink->svc_name);267 301 return EOK; 268 302 … … 273 307 inet_link_delete(ilink); 274 308 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(); 275 328 } 276 329 … … 425 478 } 426 479 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) 480 inet_link_t *inet_link_get_by_id(sysarg_t link_id) 481 { 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); 433 487 return ilink; 434 } 435 488 } 489 } 490 491 fibril_mutex_unlock(&inet_discovery_lock); 436 492 return NULL; 437 }438 439 inet_link_t *inet_link_get_by_id(sysarg_t link_id)440 {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;448 493 } 449 494 … … 454 499 size_t count, i; 455 500 456 fibril_mutex_lock(&inet_ links_lock);457 count = list_count(&inet_link s);501 fibril_mutex_lock(&inet_discovery_lock); 502 count = list_count(&inet_link_list); 458 503 459 504 id_list = calloc(count, sizeof(sysarg_t)); 460 505 if (id_list == NULL) { 461 fibril_mutex_unlock(&inet_ links_lock);506 fibril_mutex_unlock(&inet_discovery_lock); 462 507 return ENOMEM; 463 508 } 464 509 465 510 i = 0; 466 list_foreach(inet_link s, link_list, inet_link_t, ilink) {511 list_foreach(inet_link_list, link_list, inet_link_t, ilink) { 467 512 id_list[i++] = ilink->svc_id; 468 513 log_msg(LOG_DEFAULT, LVL_NOTE, "add link to list"); 469 514 } 470 515 471 fibril_mutex_unlock(&inet_ links_lock);516 fibril_mutex_unlock(&inet_discovery_lock); 472 517 473 518 log_msg(LOG_DEFAULT, LVL_NOTE, "return %zu links", count);
Note:
See TracChangeset
for help on using the changeset viewer.