* Set an individual neighbor cache entry */
| 456 | * Set an individual neighbor cache entry |
| 457 | */ |
| 458 | static int |
| 459 | set(int argc, char **argv) |
| 460 | { |
| 461 | register struct sockaddr_in6 *sin = &sin_m; |
| 462 | register struct sockaddr_dl *sdl; |
| 463 | register struct rt_msghdr *rtm = &(m_rtmsg.m_rtm); |
| 464 | struct addrinfo hints, *res; |
| 465 | int gai_error; |
| 466 | u_char *ea; |
| 467 | char *host = argv[0], *eaddr = argv[1]; |
| 468 | |
| 469 | getsocket(); |
| 470 | argc -= 2; |
| 471 | argv += 2; |
| 472 | sdl_m = blank_sdl; |
| 473 | sin_m = blank_sin; |
| 474 | |
| 475 | bzero(&hints, sizeof(hints)); |
| 476 | hints.ai_family = AF_INET6; |
| 477 | gai_error = getaddrinfo(host, NULL, &hints, &res); |
| 478 | if (gai_error) { |
| 479 | fprintf(stderr, "ndp: %s: %s\n", host, |
| 480 | gai_strerror(gai_error)); |
| 481 | return 1; |
| 482 | } |
| 483 | sin->sin6_addr = ((struct sockaddr_in6 *)res->ai_addr)->sin6_addr; |
| 484 | sin->sin6_scope_id = |
| 485 | ((struct sockaddr_in6 *)res->ai_addr)->sin6_scope_id; |
| 486 | ea = (u_char *)LLADDR(&sdl_m); |
| 487 | if (ndp_ether_aton(eaddr, ea) == 0) |
| 488 | sdl_m.sdl_alen = 6; |
| 489 | flags = expire_time = 0; |
| 490 | while (argc-- > 0) { |
| 491 | if (strncmp(argv[0], "temp", 4) == 0) { |
| 492 | struct timeval now; |
| 493 | |
| 494 | gettimeofday(&now, 0); |
| 495 | expire_time = now.tv_sec + 20 * 60; |
| 496 | } else if (strncmp(argv[0], "proxy", 5) == 0) |
| 497 | flags |= RTF_ANNOUNCE; |
| 498 | argv++; |
| 499 | } |
| 500 | if (rtmsg(RTM_GET) < 0) { |
| 501 | errx(1, "RTM_GET(%s) failed", host); |
| 502 | /* NOTREACHED */ |
| 503 | } |
| 504 | sin = (struct sockaddr_in6 *)(rtm + 1); |
| 505 | sdl = (struct sockaddr_dl *)(ALIGN(sin->sin6_len) + (char *)sin); |
| 506 | if (IN6_ARE_ADDR_EQUAL(&sin->sin6_addr, &sin_m.sin6_addr)) { |
| 507 | if (sdl->sdl_family == AF_LINK && |
| 508 | !(rtm->rtm_flags & RTF_GATEWAY)) { |
| 509 | switch (sdl->sdl_type) { |
| 510 | case IFT_ETHER: case IFT_FDDI: case IFT_ISO88023: |
| 511 | case IFT_ISO88024: case IFT_ISO88025: |
| 512 | case IFT_L2VLAN: case IFT_BRIDGE: |
| 513 | goto overwrite; |
| 514 | } |
| 515 | } |