Changeset 83781a22 in mainline for uspace/srv/net/ethip/ethip_nic.c
- Timestamp:
- 2013-07-25T13:20:03Z (11 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- ccdc63e
- Parents:
- b323a3a
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/srv/net/ethip/ethip_nic.c
rb323a3a r83781a22 45 45 #include <device/nic.h> 46 46 #include <stdlib.h> 47 47 #include <net/socket_codes.h> 48 #include <mem.h> 48 49 #include "ethip.h" 49 50 #include "ethip_nic.h" … … 108 109 { 109 110 ethip_nic_t *nic = calloc(1, sizeof(ethip_nic_t)); 110 111 111 if (nic == NULL) { 112 112 log_msg(LOG_DEFAULT, LVL_ERROR, "Failed allocating NIC structure. " … … 114 114 return NULL; 115 115 } 116 116 117 117 link_initialize(&nic->link); 118 118 list_initialize(&nic->addr_list); 119 119 120 120 return nic; 121 121 } … … 140 140 if (nic->svc_name != NULL) 141 141 free(nic->svc_name); 142 142 143 free(nic); 143 144 } … … 335 336 } 336 337 338 /** Setup accepted multicast addresses 339 * 340 * Currently the set of accepted multicast addresses is 341 * determined only based on IPv6 addresses. 342 * 343 */ 344 static int ethip_nic_setup_multicast(ethip_nic_t *nic) 345 { 346 log_msg(LOG_DEFAULT, LVL_DEBUG, "ethip_nic_setup_multicast()"); 347 348 /* Count the number of multicast addresses */ 349 350 size_t count = 0; 351 352 list_foreach(nic->addr_list, link) { 353 ethip_link_addr_t *laddr = list_get_instance(link, 354 ethip_link_addr_t, link); 355 356 uint16_t af = inet_addr_get(&laddr->addr, NULL, NULL); 357 if (af == AF_INET6) 358 count++; 359 } 360 361 if (count == 0) 362 return nic_multicast_set_mode(nic->sess, NIC_MULTICAST_BLOCKED, 363 NULL, 0); 364 365 nic_address_t *mac_list = calloc(count, sizeof(nic_address_t)); 366 if (mac_list == NULL) 367 return ENOMEM; 368 369 /* Create the multicast MAC list */ 370 371 size_t i = 0; 372 373 list_foreach(nic->addr_list, link) { 374 assert(i < count); 375 376 ethip_link_addr_t *laddr = list_get_instance(link, 377 ethip_link_addr_t, link); 378 379 addr128_t v6; 380 uint16_t af = inet_addr_get(&laddr->addr, NULL, &v6); 381 if (af != AF_INET6) 382 continue; 383 384 addr48_t mac; 385 addr48_solicited_node(v6, mac); 386 387 /* Avoid duplicate addresses in the list */ 388 389 bool found = false; 390 391 for (size_t j = 0; j < i; j++) { 392 if (addr48_compare(mac_list[j].address, mac)) { 393 found = true; 394 break; 395 } 396 } 397 398 if (!found) { 399 addr48(mac, mac_list[i].address); 400 i++; 401 } else 402 count--; 403 } 404 405 /* Setup the multicast MAC list */ 406 407 int rc = nic_multicast_set_mode(nic->sess, NIC_MULTICAST_LIST, 408 mac_list, count); 409 410 free(mac_list); 411 return rc; 412 } 413 337 414 int ethip_nic_addr_add(ethip_nic_t *nic, inet_addr_t *addr) 338 415 { … … 344 421 345 422 list_append(&laddr->link, &nic->addr_list); 346 return EOK; 423 424 return ethip_nic_setup_multicast(nic); 347 425 } 348 426 … … 357 435 list_remove(&laddr->link); 358 436 ethip_link_addr_delete(laddr); 359 return EOK; 437 438 return ethip_nic_setup_multicast(nic); 360 439 } 361 440
Note:
See TracChangeset
for help on using the changeset viewer.