* Receive a control message */
| 470 | * Receive a control message |
| 471 | */ |
| 472 | static int |
| 473 | ng_eiface_rcvmsg(node_p node, item_p item, hook_p lasthook) |
| 474 | { |
| 475 | const priv_p priv = NG_NODE_PRIVATE(node); |
| 476 | struct ifnet *const ifp = priv->ifp; |
| 477 | struct ng_mesg *resp = NULL; |
| 478 | int error = 0; |
| 479 | struct ng_mesg *msg; |
| 480 | |
| 481 | NGI_GET_MSG(item, msg); |
| 482 | switch (msg->header.typecookie) { |
| 483 | case NGM_EIFACE_COOKIE: |
| 484 | switch (msg->header.cmd) { |
| 485 | case NGM_EIFACE_SET: |
| 486 | { |
| 487 | if (msg->header.arglen != ETHER_ADDR_LEN) { |
| 488 | error = EINVAL; |
| 489 | break; |
| 490 | } |
| 491 | error = if_setlladdr(priv->ifp, |
| 492 | (u_char *)msg->data, ETHER_ADDR_LEN); |
| 493 | break; |
| 494 | } |
| 495 | |
| 496 | case NGM_EIFACE_GET_IFNAME: |
| 497 | NG_MKRESPONSE(resp, msg, IFNAMSIZ, M_NOWAIT); |
| 498 | if (resp == NULL) { |
| 499 | error = ENOMEM; |
| 500 | break; |
| 501 | } |
| 502 | strlcpy(resp->data, ifp->if_xname, IFNAMSIZ); |
| 503 | break; |
| 504 | |
| 505 | case NGM_EIFACE_GET_IFADDRS: |
| 506 | { |
| 507 | struct epoch_tracker et; |
| 508 | struct ifaddr *ifa; |
| 509 | caddr_t ptr; |
| 510 | int buflen; |
| 511 | |
| 512 | /* Determine size of response and allocate it */ |
| 513 | buflen = 0; |
| 514 | NET_EPOCH_ENTER(et); |
| 515 | CK_STAILQ_FOREACH(ifa, &ifp->if_addrhead, ifa_link) |
| 516 | buflen += SA_SIZE(ifa->ifa_addr); |
| 517 | NG_MKRESPONSE(resp, msg, buflen, M_NOWAIT); |
| 518 | if (resp == NULL) { |
| 519 | NET_EPOCH_EXIT(et); |
| 520 | error = ENOMEM; |
| 521 | break; |
| 522 | } |
| 523 | |
| 524 | /* Add addresses */ |
| 525 | ptr = resp->data; |
| 526 | CK_STAILQ_FOREACH(ifa, &ifp->if_addrhead, ifa_link) { |
| 527 | const int len = SA_SIZE(ifa->ifa_addr); |
| 528 | |
| 529 | if (buflen < len) { |
nothing calls this directly
no test coverage detected