* Delete a neighbor cache entry */
| 567 | * Delete a neighbor cache entry |
| 568 | */ |
| 569 | static int |
| 570 | delete(char *host) |
| 571 | { |
| 572 | struct sockaddr_in6 *sin = &sin_m; |
| 573 | register struct rt_msghdr *rtm = &m_rtmsg.m_rtm; |
| 574 | register char *cp = m_rtmsg.m_space; |
| 575 | struct sockaddr_dl *sdl; |
| 576 | struct addrinfo hints, *res; |
| 577 | int gai_error; |
| 578 | |
| 579 | getsocket(); |
| 580 | sin_m = blank_sin; |
| 581 | |
| 582 | bzero(&hints, sizeof(hints)); |
| 583 | hints.ai_family = AF_INET6; |
| 584 | gai_error = getaddrinfo(host, NULL, &hints, &res); |
| 585 | if (gai_error) { |
| 586 | fprintf(stderr, "ndp: %s: %s\n", host, |
| 587 | gai_strerror(gai_error)); |
| 588 | return 1; |
| 589 | } |
| 590 | sin->sin6_addr = ((struct sockaddr_in6 *)res->ai_addr)->sin6_addr; |
| 591 | sin->sin6_scope_id = |
| 592 | ((struct sockaddr_in6 *)res->ai_addr)->sin6_scope_id; |
| 593 | if (rtmsg(RTM_GET) < 0) { |
| 594 | errx(1, "RTM_GET(%s) failed", host); |
| 595 | /* NOTREACHED */ |
| 596 | } |
| 597 | sin = (struct sockaddr_in6 *)(rtm + 1); |
| 598 | sdl = (struct sockaddr_dl *)(ALIGN(sin->sin6_len) + (char *)sin); |
| 599 | if (IN6_ARE_ADDR_EQUAL(&sin->sin6_addr, &sin_m.sin6_addr)) { |
| 600 | if (sdl->sdl_family == AF_LINK && |
| 601 | !(rtm->rtm_flags & RTF_GATEWAY)) { |
| 602 | goto delete; |
| 603 | } |
| 604 | fprintf(stderr, "delete: cannot delete non-NDP entry\n"); |
| 605 | return 1; |
| 606 | } |
| 607 | |
| 608 | delete: |
| 609 | if (sdl->sdl_family != AF_LINK) { |
| 610 | printf("cannot locate %s\n", host); |
| 611 | return (1); |
| 612 | } |
| 613 | /* |
| 614 | * need to reinit the field because it has rt_key |
| 615 | * but we want the actual address |
| 616 | */ |
| 617 | NEXTADDR(RTA_DST, sin_m); |
| 618 | rtm->rtm_flags |= RTF_LLDATA; |
| 619 | if (rtmsg(RTM_DELETE) == 0) { |
| 620 | #ifndef FSTACK |
| 621 | getnameinfo((struct sockaddr *)sin, |
| 622 | sin->sin6_len, host_buf, |
| 623 | sizeof(host_buf), NULL, 0, |
| 624 | (nflag ? NI_NUMERICHOST : 0)); |
| 625 | #else |
| 626 | inet_ntop(AF_INET6_LINUX, &sin->sin6_addr, host_buf, sizeof(host_buf)); |
no test coverage detected