Changes in uspace/srv/net/ethip/ethip_nic.c [02a09ed:f9b2cb4c] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/srv/net/ethip/ethip_nic.c
r02a09ed rf9b2cb4c 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 } … … 130 127 } 131 128 132 link_initialize(&laddr-> addr_list);129 link_initialize(&laddr->link); 133 130 laddr->addr = *addr; 134 131 … … 140 137 if (nic->svc_name != NULL) 141 138 free(nic->svc_name); 139 142 140 free(nic); 143 141 } … … 164 162 } 165 163 166 nic->sess = loc_service_connect( EXCHANGE_SERIALIZE, sid, 0);164 nic->sess = loc_service_connect(sid, INTERFACE_DDF, 0); 167 165 if (nic->sess == NULL) { 168 166 log_msg(LOG_DEFAULT, LVL_ERROR, "Failed connecting '%s'", nic->svc_name); … … 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 … … 203 201 } 204 202 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 205 210 log_msg(LOG_DEFAULT, LVL_DEBUG, "Initialized IP link service,"); 206 211 … … 209 214 error: 210 215 if (in_list) 211 list_remove(&nic->nic_list); 216 list_remove(&nic->link); 217 212 218 if (nic->sess != NULL) 213 219 async_hangup(nic->sess); 220 214 221 ethip_nic_delete(nic); 215 222 return rc; … … 224 231 ipc_call_t *call) 225 232 { 226 log_msg(LOG_DEFAULT, LVL_DEBUG, "ethip_nic_addr_changed()"); 227 async_answer_0(callid, ENOTSUP); 233 uint8_t *addr; 234 size_t size; 235 int rc; 236 237 rc = async_data_write_accept((void **)&addr, false, 0, 0, 0, &size); 238 if (rc != EOK) { 239 log_msg(LOG_DEFAULT, LVL_DEBUG, "data_write_accept() failed"); 240 return; 241 } 242 243 log_msg(LOG_DEFAULT, LVL_DEBUG, "ethip_nic_addr_changed(): " 244 "new addr=%02x:%02x:%02x:%02x:%02x:%02x", 245 addr[0], addr[1], addr[2], addr[3], addr[4], addr[5]); 246 247 memcpy(&nic->mac_addr, addr, sizeof(nic->mac_addr)); 248 249 rc = iplink_ev_change_addr(&nic->iplink, &nic->mac_addr); 250 if (rc != EOK) { 251 log_msg(LOG_DEFAULT, LVL_DEBUG, "iplink_ev_change_addr() failed"); 252 return; 253 } 254 255 free(addr); 256 async_answer_0(callid, EOK); 228 257 } 229 258 … … 288 317 break; 289 318 default: 319 log_msg(LOG_DEFAULT, LVL_DEBUG, "unknown IPC method: %" PRIun, IPC_GET_IMETHOD(call)); 290 320 async_answer_0(callid, ENOTSUP); 291 321 } … … 310 340 (unsigned) iplink_sid); 311 341 312 list_foreach(ethip_nic_list, link ) {342 list_foreach(ethip_nic_list, link, ethip_nic_t, nic) { 313 343 log_msg(LOG_DEFAULT, LVL_DEBUG, "ethip_nic_find_by_iplink_sid - element"); 314 ethip_nic_t *nic = list_get_instance(link, ethip_nic_t,315 nic_list);316 317 344 if (nic->iplink_sid == iplink_sid) { 318 345 log_msg(LOG_DEFAULT, LVL_DEBUG, "ethip_nic_find_by_iplink_sid - found %p", nic); … … 334 361 } 335 362 363 /** Setup accepted multicast addresses 364 * 365 * Currently the set of accepted multicast addresses is 366 * determined only based on IPv6 addresses. 367 * 368 */ 369 static int ethip_nic_setup_multicast(ethip_nic_t *nic) 370 { 371 log_msg(LOG_DEFAULT, LVL_DEBUG, "ethip_nic_setup_multicast()"); 372 373 /* Count the number of multicast addresses */ 374 375 size_t count = 0; 376 377 list_foreach(nic->addr_list, link, ethip_link_addr_t, laddr) { 378 ip_ver_t ver = inet_addr_get(&laddr->addr, NULL, NULL); 379 if (ver == ip_v6) 380 count++; 381 } 382 383 if (count == 0) 384 return nic_multicast_set_mode(nic->sess, NIC_MULTICAST_BLOCKED, 385 NULL, 0); 386 387 nic_address_t *mac_list = calloc(count, sizeof(nic_address_t)); 388 if (mac_list == NULL) 389 return ENOMEM; 390 391 /* Create the multicast MAC list */ 392 393 size_t i = 0; 394 395 list_foreach(nic->addr_list, link, ethip_link_addr_t, laddr) { 396 addr128_t v6; 397 ip_ver_t ver = inet_addr_get(&laddr->addr, NULL, &v6); 398 if (ver != ip_v6) 399 continue; 400 401 assert(i < count); 402 403 addr48_t mac; 404 addr48_solicited_node(v6, mac); 405 406 /* Avoid duplicate addresses in the list */ 407 408 bool found = false; 409 410 for (size_t j = 0; j < i; j++) { 411 if (addr48_compare(mac_list[j].address, mac)) { 412 found = true; 413 break; 414 } 415 } 416 417 if (!found) { 418 addr48(mac, mac_list[i].address); 419 i++; 420 } else 421 count--; 422 } 423 424 /* Setup the multicast MAC list */ 425 426 int rc = nic_multicast_set_mode(nic->sess, NIC_MULTICAST_LIST, 427 mac_list, count); 428 429 free(mac_list); 430 return rc; 431 } 432 336 433 int ethip_nic_addr_add(ethip_nic_t *nic, inet_addr_t *addr) 337 434 { … … 342 439 return ENOMEM; 343 440 344 list_append(&laddr->addr_list, &nic->addr_list); 345 return EOK; 441 list_append(&laddr->link, &nic->addr_list); 442 443 return ethip_nic_setup_multicast(nic); 346 444 } 347 445 … … 354 452 return ENOENT; 355 453 356 list_remove(&laddr-> addr_list);454 list_remove(&laddr->link); 357 455 ethip_link_addr_delete(laddr); 358 return EOK; 456 457 return ethip_nic_setup_multicast(nic); 359 458 } 360 459 … … 364 463 log_msg(LOG_DEFAULT, LVL_DEBUG, "ethip_nic_addr_find()"); 365 464 366 list_foreach(nic->addr_list, link) { 367 ethip_link_addr_t *laddr = list_get_instance(link, 368 ethip_link_addr_t, addr_list); 369 465 list_foreach(nic->addr_list, link, ethip_link_addr_t, laddr) { 370 466 if (inet_addr_compare(addr, &laddr->addr)) 371 467 return laddr;
Note:
See TracChangeset
for help on using the changeset viewer.