Changes in uspace/srv/net/ethip/ethip_nic.c [695b6ff:3e6a98c5] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/srv/net/ethip/ethip_nic.c
r695b6ff r3e6a98c5 45 45 #include <device/nic.h> 46 46 #include <stdlib.h> 47 #include <net/socket_codes.h> 48 #include <mem.h> 47 49 48 #include "ethip.h" 50 49 #include "ethip_nic.h" … … 84 83 already_known = false; 85 84 86 list_foreach(ethip_nic_list, link, ethip_nic_t, nic) { 85 list_foreach(ethip_nic_list, nic_link) { 86 ethip_nic_t *nic = list_get_instance(nic_link, 87 ethip_nic_t, nic_list); 87 88 if (nic->svc_id == svcs[i]) { 88 89 already_known = true; … … 107 108 { 108 109 ethip_nic_t *nic = calloc(1, sizeof(ethip_nic_t)); 110 109 111 if (nic == NULL) { 110 112 log_msg(LOG_DEFAULT, LVL_ERROR, "Failed allocating NIC structure. " … … 112 114 return NULL; 113 115 } 114 115 link_initialize(&nic-> link);116 117 link_initialize(&nic->nic_list); 116 118 list_initialize(&nic->addr_list); 117 119 118 120 return nic; 119 121 } 120 122 121 static ethip_link_addr_t *ethip_nic_addr_new(i net_addr_t *addr)123 static ethip_link_addr_t *ethip_nic_addr_new(iplink_srv_addr_t *addr) 122 124 { 123 125 ethip_link_addr_t *laddr = calloc(1, sizeof(ethip_link_addr_t)); 126 124 127 if (laddr == NULL) { 125 128 log_msg(LOG_DEFAULT, LVL_ERROR, "Failed allocating NIC address structure. " … … 127 130 return NULL; 128 131 } 129 130 link_initialize(&laddr->link); 131 laddr->addr = *addr; 132 132 133 link_initialize(&laddr->addr_list); 134 laddr->addr.ipv4 = addr->ipv4; 133 135 return laddr; 134 136 } … … 138 140 if (nic->svc_name != NULL) 139 141 free(nic->svc_name); 140 141 142 free(nic); 142 143 } … … 179 180 180 181 log_msg(LOG_DEFAULT, LVL_DEBUG, "Opened NIC '%s'", nic->svc_name); 181 list_append(&nic-> link, ðip_nic_list);182 list_append(&nic->nic_list, ðip_nic_list); 182 183 in_list = true; 183 184 … … 192 193 goto error; 193 194 } 194 195 addr48(nic_address.address,nic->mac_addr);195 196 mac48_decode(nic_address.address, &nic->mac_addr); 196 197 197 198 rc = nic_set_state(nic->sess, NIC_STATE_ACTIVE); … … 202 203 } 203 204 204 rc = nic_broadcast_set_mode(nic->sess, NIC_BROADCAST_ACCEPTED); 205 if (rc != EOK) { 206 log_msg(LOG_DEFAULT, LVL_ERROR, "Error enabling " 207 "reception of broadcast frames on '%s'.", nic->svc_name); 208 goto error; 209 } 210 211 log_msg(LOG_DEFAULT, LVL_DEBUG, "Initialized IP link service,"); 205 log_msg(LOG_DEFAULT, LVL_DEBUG, "Initialized IP link service, MAC = 0x%" PRIx64, 206 nic->mac_addr.addr); 212 207 213 208 return EOK; … … 215 210 error: 216 211 if (in_list) 217 list_remove(&nic->link); 218 212 list_remove(&nic->nic_list); 219 213 if (nic->sess != NULL) 220 214 async_hangup(nic->sess); 221 222 215 ethip_nic_delete(nic); 223 216 return rc; … … 318 311 (unsigned) iplink_sid); 319 312 320 list_foreach(ethip_nic_list, link , ethip_nic_t, nic) {313 list_foreach(ethip_nic_list, link) { 321 314 log_msg(LOG_DEFAULT, LVL_DEBUG, "ethip_nic_find_by_iplink_sid - element"); 315 ethip_nic_t *nic = list_get_instance(link, ethip_nic_t, 316 nic_list); 317 322 318 if (nic->iplink_sid == iplink_sid) { 323 319 log_msg(LOG_DEFAULT, LVL_DEBUG, "ethip_nic_find_by_iplink_sid - found %p", nic); … … 339 335 } 340 336 341 /** Setup accepted multicast addresses 342 * 343 * Currently the set of accepted multicast addresses is 344 * determined only based on IPv6 addresses. 345 * 346 */ 347 static int ethip_nic_setup_multicast(ethip_nic_t *nic) 348 { 349 log_msg(LOG_DEFAULT, LVL_DEBUG, "ethip_nic_setup_multicast()"); 350 351 /* Count the number of multicast addresses */ 352 353 size_t count = 0; 354 355 list_foreach(nic->addr_list, link, ethip_link_addr_t, laddr) { 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, ethip_link_addr_t, laddr) { 374 addr128_t v6; 375 uint16_t af = inet_addr_get(&laddr->addr, NULL, &v6); 376 if (af != AF_INET6) 377 continue; 378 379 assert(i < count); 380 381 addr48_t mac; 382 addr48_solicited_node(v6, mac); 383 384 /* Avoid duplicate addresses in the list */ 385 386 bool found = false; 387 388 for (size_t j = 0; j < i; j++) { 389 if (addr48_compare(mac_list[j].address, mac)) { 390 found = true; 391 break; 392 } 393 } 394 395 if (!found) { 396 addr48(mac, mac_list[i].address); 397 i++; 398 } else 399 count--; 400 } 401 402 /* Setup the multicast MAC list */ 403 404 int rc = nic_multicast_set_mode(nic->sess, NIC_MULTICAST_LIST, 405 mac_list, count); 406 407 free(mac_list); 408 return rc; 409 } 410 411 int ethip_nic_addr_add(ethip_nic_t *nic, inet_addr_t *addr) 412 { 337 int ethip_nic_addr_add(ethip_nic_t *nic, iplink_srv_addr_t *addr) 338 { 339 ethip_link_addr_t *laddr; 340 413 341 log_msg(LOG_DEFAULT, LVL_DEBUG, "ethip_nic_addr_add()"); 414 415 ethip_link_addr_t *laddr = ethip_nic_addr_new(addr); 342 laddr = ethip_nic_addr_new(addr); 416 343 if (laddr == NULL) 417 344 return ENOMEM; 418 419 list_append(&laddr->link, &nic->addr_list); 420 421 return ethip_nic_setup_multicast(nic); 422 } 423 424 int ethip_nic_addr_remove(ethip_nic_t *nic, inet_addr_t *addr) 425 { 345 346 list_append(&laddr->addr_list, &nic->addr_list); 347 return EOK; 348 } 349 350 int ethip_nic_addr_remove(ethip_nic_t *nic, iplink_srv_addr_t *addr) 351 { 352 ethip_link_addr_t *laddr; 353 426 354 log_msg(LOG_DEFAULT, LVL_DEBUG, "ethip_nic_addr_remove()"); 427 428 ethip_link_addr_t *laddr = ethip_nic_addr_find(nic, addr);355 356 laddr = ethip_nic_addr_find(nic, addr); 429 357 if (laddr == NULL) 430 358 return ENOENT; 431 432 list_remove(&laddr-> link);359 360 list_remove(&laddr->addr_list); 433 361 ethip_link_addr_delete(laddr); 434 435 return ethip_nic_setup_multicast(nic); 362 return EOK; 436 363 } 437 364 438 365 ethip_link_addr_t *ethip_nic_addr_find(ethip_nic_t *nic, 439 i net_addr_t *addr)366 iplink_srv_addr_t *addr) 440 367 { 441 368 log_msg(LOG_DEFAULT, LVL_DEBUG, "ethip_nic_addr_find()"); 442 443 list_foreach(nic->addr_list, link, ethip_link_addr_t, laddr) { 444 if (inet_addr_compare(addr, &laddr->addr)) 369 370 list_foreach(nic->addr_list, link) { 371 ethip_link_addr_t *laddr = list_get_instance(link, 372 ethip_link_addr_t, addr_list); 373 374 if (addr->ipv4 == laddr->addr.ipv4) 445 375 return laddr; 446 376 } 447 377 448 378 return NULL; 449 379 }
Note:
See TracChangeset
for help on using the changeset viewer.