Changes in uspace/srv/net/inetsrv/inet_link.c [417a2ba1:1f97352] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/srv/net/inetsrv/inet_link.c
r417a2ba1 r1f97352 43 43 #include <stdlib.h> 44 44 #include <str.h> 45 #include <net/socket_codes.h> 45 46 #include "addrobj.h" 46 47 #include "inetsrv.h" … … 54 55 static uint16_t ip_ident = 0; 55 56 56 static int inet_ iplink_recv(iplink_t *, iplink_recv_sdu_t *, ip_ver_t);57 static in et_link_t *inet_link_get_by_id_locked(sysarg_t);57 static int inet_link_open(service_id_t); 58 static int inet_iplink_recv(iplink_t *, iplink_recv_sdu_t *, uint16_t); 58 59 59 60 static iplink_ev_ops_t inet_iplink_ev_ops = { … … 61 62 }; 62 63 63 static LIST_INITIALIZE(inet_link s);64 static FIBRIL_MUTEX_INITIALIZE(inet_ links_lock);64 static LIST_INITIALIZE(inet_link_list); 65 static FIBRIL_MUTEX_INITIALIZE(inet_discovery_lock); 65 66 66 67 static addr128_t link_local_node_ip = … … 80 81 } 81 82 82 static int inet_iplink_recv(iplink_t *iplink, iplink_recv_sdu_t *sdu, ip_ver_t ver)83 static int inet_iplink_recv(iplink_t *iplink, iplink_recv_sdu_t *sdu, uint16_t af) 83 84 { 84 85 log_msg(LOG_DEFAULT, LVL_DEBUG, "inet_iplink_recv()"); … … 87 88 inet_packet_t packet; 88 89 89 switch ( ver) {90 case ip_v4:90 switch (af) { 91 case AF_INET: 91 92 rc = inet_pdu_decode(sdu->data, sdu->size, &packet); 92 93 break; 93 case ip_v6:94 case AF_INET6: 94 95 rc = inet_pdu_decode6(sdu->data, sdu->size, &packet); 95 96 break; 96 97 default: 97 log_msg(LOG_DEFAULT, LVL_DEBUG, "invalid IP version");98 log_msg(LOG_DEFAULT, LVL_DEBUG, "invalid address family"); 98 99 return EINVAL; 99 100 } … … 112 113 } 113 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, 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 114 164 static inet_link_t *inet_link_new(void) 115 165 { … … 135 185 } 136 186 137 int inet_link_open(service_id_t sid)187 static int inet_link_open(service_id_t sid) 138 188 { 139 189 inet_link_t *ilink; … … 183 233 184 234 log_msg(LOG_DEFAULT, LVL_DEBUG, "Opened IP link '%s'", ilink->svc_name); 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); 235 list_append(&ilink->link_list, &inet_link_list); 198 236 199 237 inet_addrobj_t *addr = NULL; 200 238 201 /* XXX FIXME Cannot rely on loopback being the first IP link service!! */202 239 if (first_link) { 203 240 addr = inet_addrobj_new(); … … 205 242 inet_naddr(&addr->naddr, 127, 0, 0, 1, 24); 206 243 first_link = false; 244 } else { 245 /* 246 * FIXME 247 * Setting static IPv4 address for testing purposes: 248 * 10.0.2.15/24 249 */ 250 addr = inet_addrobj_new(); 251 252 inet_naddr(&addr->naddr, 10, 0, 2, 15, 24); 207 253 } 208 254 … … 263 309 } 264 310 265 log_msg(LOG_DEFAULT, LVL_DEBUG, "Configured link '%s'.", ilink->svc_name);266 311 return EOK; 267 312 … … 272 317 inet_link_delete(ilink); 273 318 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(); 274 338 } 275 339 … … 293 357 { 294 358 addr32_t src_v4; 295 ip_ver_t src_ver= inet_addr_get(&dgram->src, &src_v4, NULL);296 if (src_ ver != ip_v4)359 uint16_t src_af = inet_addr_get(&dgram->src, &src_v4, NULL); 360 if (src_af != AF_INET) 297 361 return EINVAL; 298 362 299 363 addr32_t dest_v4; 300 ip_ver_t dest_ver= inet_addr_get(&dgram->dest, &dest_v4, NULL);301 if (dest_ ver != ip_v4)364 uint16_t dest_af = inet_addr_get(&dgram->dest, &dest_v4, NULL); 365 if (dest_af != AF_INET) 302 366 return EINVAL; 303 367 … … 368 432 { 369 433 addr128_t src_v6; 370 ip_ver_t src_ver= inet_addr_get(&dgram->src, NULL, &src_v6);371 if (src_ ver != ip_v6)434 uint16_t src_af = inet_addr_get(&dgram->src, NULL, &src_v6); 435 if (src_af != AF_INET6) 372 436 return EINVAL; 373 437 374 438 addr128_t dest_v6; 375 ip_ver_t dest_ver= inet_addr_get(&dgram->dest, NULL, &dest_v6);376 if (dest_ ver != ip_v6)439 uint16_t dest_af = inet_addr_get(&dgram->dest, NULL, &dest_v6); 440 if (dest_af != AF_INET6) 377 441 return EINVAL; 378 442 … … 424 488 } 425 489 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) 490 inet_link_t *inet_link_get_by_id(sysarg_t link_id) 491 { 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); 432 500 return ilink; 433 } 434 501 } 502 } 503 504 fibril_mutex_unlock(&inet_discovery_lock); 435 505 return NULL; 436 }437 438 inet_link_t *inet_link_get_by_id(sysarg_t link_id)439 {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;477 506 } 478 507
Note:
See TracChangeset
for help on using the changeset viewer.