Changeset 83781a22 in mainline
- 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
- Location:
- uspace
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/c/generic/inet/addr.c
rb323a3a r83781a22 52 52 }; 53 53 54 static const addr48_t inet_addr48_solicited_node = { 55 0x33, 0x33, 0xff, 0, 0, 0 56 }; 57 54 58 static const inet_addr_t inet_addr_any_addr = { 55 59 .family = AF_INET, … … 72 76 } 73 77 78 int addr48_compare(const addr48_t a, const addr48_t b) 79 { 80 return memcmp(a, b, 6); 81 } 82 74 83 int addr128_compare(const addr128_t a, const addr128_t b) 75 84 { 76 85 return memcmp(a, b, 16); 86 } 87 88 /** Compute solicited node MAC multicast address from target IPv6 address 89 * 90 * @param ip Target IPv6 address 91 * @param mac Solicited MAC address to be assigned 92 * 93 */ 94 void addr48_solicited_node(const addr128_t ip, addr48_t mac) 95 { 96 memcpy(mac, inet_addr48_solicited_node, 3); 97 memcpy(mac + 3, ip + 13, 3); 77 98 } 78 99 -
uspace/lib/c/include/inet/addr.h
rb323a3a r83781a22 73 73 extern void addr128(const addr128_t, addr128_t); 74 74 75 extern int addr48_compare(const addr48_t, const addr48_t); 75 76 extern int addr128_compare(const addr128_t, const addr128_t); 77 78 extern void addr48_solicited_node(const addr128_t, addr48_t); 76 79 77 80 extern void host2addr128_t_be(const addr128_t, addr128_t); -
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 -
uspace/srv/net/inetsrv/ndp.c
rb323a3a r83781a22 49 49 #define NDP_REQUEST_TIMEOUT (3 * 1000 * 1000) 50 50 51 static addr48_t solicited_node_mac =52 {0x33, 0x33, 0xff, 0, 0, 0};53 54 51 static addr128_t solicited_node_ip = 55 52 {0xff, 0x02, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x01, 0xff, 0, 0, 0}; 56 57 /** Compute solicited node MAC multicast address from target IPv6 address58 *59 * @param ip_addr Target IPv6 address60 * @param mac_addr Solicited MAC address to be assigned61 *62 */63 static void ndp_solicited_node_mac(addr128_t ip_addr, addr48_t mac_addr)64 {65 memcpy(mac_addr, solicited_node_mac, 3);66 memcpy(mac_addr + 3, ip_addr + 13, 3);67 }68 53 69 54 /** Compute solicited node IPv6 multicast address from target IPv6 address … … 186 171 addr128(src_addr, packet.sender_proto_addr); 187 172 addr128(ip_addr, packet.solicited_ip); 188 ndp_solicited_node_mac(ip_addr, packet.target_hw_addr);173 addr48_solicited_node(ip_addr, packet.target_hw_addr); 189 174 ndp_solicited_node_ip(ip_addr, packet.target_proto_addr); 190 175
Note:
See TracChangeset
for help on using the changeset viewer.