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