Deleted Added
full compact
ndp.c (66865) ndp.c (78064)
1/* $FreeBSD: head/usr.sbin/ndp/ndp.c 66865 2000-10-09 09:28:49Z sumikawa $ */
2/* $KAME: ndp.c,v 1.46 2000/10/09 09:17:10 sumikawa Exp $ */
1/* $FreeBSD: head/usr.sbin/ndp/ndp.c 78064 2001-06-11 12:39:29Z ume $ */
2/* $KAME: ndp.c,v 1.65 2001/05/08 04:36:34 itojun Exp $ */
3
4/*
5 * Copyright (C) 1995, 1996, 1997, 1998, and 1999 WIDE Project.
6 * All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:

--- 68 unchanged lines hidden (view full) ---

79
80
81#include <sys/param.h>
82#include <sys/file.h>
83#include <sys/ioctl.h>
84#include <sys/socket.h>
85#include <sys/sysctl.h>
86#include <sys/time.h>
3
4/*
5 * Copyright (C) 1995, 1996, 1997, 1998, and 1999 WIDE Project.
6 * All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:

--- 68 unchanged lines hidden (view full) ---

79
80
81#include <sys/param.h>
82#include <sys/file.h>
83#include <sys/ioctl.h>
84#include <sys/socket.h>
85#include <sys/sysctl.h>
86#include <sys/time.h>
87#include <sys/queue.h>
87
88#include <net/if.h>
89#include <net/if_var.h>
90#include <net/if_dl.h>
91#include <net/if_types.h>
92#include <net/route.h>
93
94#include <netinet/in.h>

--- 28 unchanged lines hidden (view full) ---

123
124static int pid;
125static int cflag;
126static int nflag;
127static int tflag;
128static int32_t thiszone; /* time difference with gmt */
129static int s = -1;
130static int repeat = 0;
88
89#include <net/if.h>
90#include <net/if_var.h>
91#include <net/if_dl.h>
92#include <net/if_types.h>
93#include <net/route.h>
94
95#include <netinet/in.h>

--- 28 unchanged lines hidden (view full) ---

124
125static int pid;
126static int cflag;
127static int nflag;
128static int tflag;
129static int32_t thiszone; /* time difference with gmt */
130static int s = -1;
131static int repeat = 0;
131static int lflag = 0;
132
133char ntop_buf[INET6_ADDRSTRLEN]; /* inet_ntop() */
134char host_buf[NI_MAXHOST]; /* getnameinfo() */
135char ifix_buf[IFNAMSIZ]; /* if_indextoname() */
136
137int main __P((int, char **));
138int file __P((char *));
139void getsocket __P((void));

--- 17 unchanged lines hidden (view full) ---

157#ifdef SIOCSDEFIFACE_IN6 /* XXX: check SIOCGDEFIFACE_IN6 as well? */
158static void getdefif __P((void));
159static void setdefif __P((char *));
160#endif
161static char *sec2str __P((time_t t));
162static char *ether_str __P((struct sockaddr_dl *sdl));
163static void ts_print __P((const struct timeval *));
164
132
133char ntop_buf[INET6_ADDRSTRLEN]; /* inet_ntop() */
134char host_buf[NI_MAXHOST]; /* getnameinfo() */
135char ifix_buf[IFNAMSIZ]; /* if_indextoname() */
136
137int main __P((int, char **));
138int file __P((char *));
139void getsocket __P((void));

--- 17 unchanged lines hidden (view full) ---

157#ifdef SIOCSDEFIFACE_IN6 /* XXX: check SIOCGDEFIFACE_IN6 as well? */
158static void getdefif __P((void));
159static void setdefif __P((char *));
160#endif
161static char *sec2str __P((time_t t));
162static char *ether_str __P((struct sockaddr_dl *sdl));
163static void ts_print __P((const struct timeval *));
164
165static char *rtpref_str[] = {
166 "medium", /* 00 */
167 "high", /* 01 */
168 "rsv", /* 10 */
169 "low" /* 11 */
170};
171
165int
166main(argc, argv)
167 int argc;
168 char **argv;
169{
170 int ch;
171 int aflag = 0, dflag = 0, sflag = 0, Hflag = 0,
172 pflag = 0, rflag = 0, Pflag = 0, Rflag = 0;
173
174 pid = getpid();
175 thiszone = gmt2local(0);
172int
173main(argc, argv)
174 int argc;
175 char **argv;
176{
177 int ch;
178 int aflag = 0, dflag = 0, sflag = 0, Hflag = 0,
179 pflag = 0, rflag = 0, Pflag = 0, Rflag = 0;
180
181 pid = getpid();
182 thiszone = gmt2local(0);
176 while ((ch = getopt(argc, argv, "acndfIilprstA:HPR")) != EOF)
183 while ((ch = getopt(argc, argv, "acndfIilprstA:HPR")) != -1)
177 switch ((char)ch) {
178 case 'a':
179 aflag = 1;
180 break;
181 case 'c':
182 cflag = 1;
183 break;
184 case 'd':

--- 23 unchanged lines hidden (view full) ---

208 pflag = 1;
209 break;
210 case 'f' :
211 if (argc != 3)
212 usage();
213 file(argv[2]);
214 exit(0);
215 case 'l' :
184 switch ((char)ch) {
185 case 'a':
186 aflag = 1;
187 break;
188 case 'c':
189 cflag = 1;
190 break;
191 case 'd':

--- 23 unchanged lines hidden (view full) ---

215 pflag = 1;
216 break;
217 case 'f' :
218 if (argc != 3)
219 usage();
220 file(argv[2]);
221 exit(0);
222 case 'l' :
216 lflag = 1;
223 /* obsolete, ignored */
217 break;
218 case 'r' :
219 rflag = 1;
220 break;
221 case 's':
222 sflag = 1;
223 break;
224 case 't':

--- 274 unchanged lines hidden (view full) ---

499 return (1);
500 }
501 sin = (struct sockaddr_in6 *)(rtm + 1);
502 sdl = (struct sockaddr_dl *)(ROUNDUP(sin->sin6_len) + (char *)sin);
503 if (IN6_ARE_ADDR_EQUAL(&sin->sin6_addr, &sin_m.sin6_addr)) {
504 if (sdl->sdl_family == AF_LINK &&
505 (rtm->rtm_flags & RTF_LLINFO) &&
506 !(rtm->rtm_flags & RTF_GATEWAY)) {
224 break;
225 case 'r' :
226 rflag = 1;
227 break;
228 case 's':
229 sflag = 1;
230 break;
231 case 't':

--- 274 unchanged lines hidden (view full) ---

506 return (1);
507 }
508 sin = (struct sockaddr_in6 *)(rtm + 1);
509 sdl = (struct sockaddr_dl *)(ROUNDUP(sin->sin6_len) + (char *)sin);
510 if (IN6_ARE_ADDR_EQUAL(&sin->sin6_addr, &sin_m.sin6_addr)) {
511 if (sdl->sdl_family == AF_LINK &&
512 (rtm->rtm_flags & RTF_LLINFO) &&
513 !(rtm->rtm_flags & RTF_GATEWAY)) {
507 switch (sdl->sdl_type) {
508 case IFT_ETHER: case IFT_FDDI: case IFT_ISO88023:
509 case IFT_ISO88024: case IFT_ISO88025:
510 goto delete;
511 }
514 goto delete;
512 }
513 /*
514 * IPv4 arp command retries with sin_other = SIN_PROXY here.
515 */
516 fprintf(stderr, "delete: cannot delete non-NDP entry\n");
517 return 1;
518 }
519

--- 16 unchanged lines hidden (view full) ---

536 sizeof(host_buf), NULL, 0,
537 NI_WITHSCOPEID | (nflag ? NI_NUMERICHOST : 0));
538 printf("%s (%s) deleted\n", host, host_buf);
539 }
540
541 return 0;
542}
543
515 }
516 /*
517 * IPv4 arp command retries with sin_other = SIN_PROXY here.
518 */
519 fprintf(stderr, "delete: cannot delete non-NDP entry\n");
520 return 1;
521 }
522

--- 16 unchanged lines hidden (view full) ---

539 sizeof(host_buf), NULL, 0,
540 NI_WITHSCOPEID | (nflag ? NI_NUMERICHOST : 0));
541 printf("%s (%s) deleted\n", host, host_buf);
542 }
543
544 return 0;
545}
546
547#define W_ADDR 31
548#define W_LL 17
549#define W_IF 6
550
544/*
545 * Dump the entire neighbor cache
546 */
547void
548dump(addr)
549 struct in6_addr *addr;
550{
551 int mib[6];
552 size_t needed;
553 char *lim, *buf, *next;
554 struct rt_msghdr *rtm;
555 struct sockaddr_in6 *sin;
556 struct sockaddr_dl *sdl;
557 extern int h_errno;
558 struct in6_nbrinfo *nbi;
559 struct timeval time;
560 int addrwidth;
551/*
552 * Dump the entire neighbor cache
553 */
554void
555dump(addr)
556 struct in6_addr *addr;
557{
558 int mib[6];
559 size_t needed;
560 char *lim, *buf, *next;
561 struct rt_msghdr *rtm;
562 struct sockaddr_in6 *sin;
563 struct sockaddr_dl *sdl;
564 extern int h_errno;
565 struct in6_nbrinfo *nbi;
566 struct timeval time;
567 int addrwidth;
568 int llwidth;
569 int ifwidth;
561 char flgbuf[8];
570 char flgbuf[8];
571 char *ifname;
562
563 /* Print header */
564 if (!tflag && !cflag)
572
573 /* Print header */
574 if (!tflag && !cflag)
565 printf("%-31.31s %-17.17s %6.6s %-9.9s %2s %4s %4s\n",
566 "Neighbor", "Linklayer Address", "Netif", "Expire",
567 "St", "Flgs", "Prbs");
575 printf("%-*.*s %-*.*s %*.*s %-9.9s %2s %4s %4s\n",
576 W_ADDR, W_ADDR, "Neighbor", W_LL, W_LL, "Linklayer Address",
577 W_IF, W_IF, "Netif", "Expire", "St", "Flgs", "Prbs");
568
569again:;
570 mib[0] = CTL_NET;
571 mib[1] = PF_ROUTE;
572 mib[2] = 0;
573 mib[3] = AF_INET6;
574 mib[4] = NET_RT_FLAGS;
575 mib[5] = RTF_LLINFO;

--- 9 unchanged lines hidden (view full) ---

585 buf = lim = NULL;
586
587 for (next = buf; next && next < lim; next += rtm->rtm_msglen) {
588 int isrouter = 0, prbs = 0;
589
590 rtm = (struct rt_msghdr *)next;
591 sin = (struct sockaddr_in6 *)(rtm + 1);
592 sdl = (struct sockaddr_dl *)((char *)sin + ROUNDUP(sin->sin6_len));
578
579again:;
580 mib[0] = CTL_NET;
581 mib[1] = PF_ROUTE;
582 mib[2] = 0;
583 mib[3] = AF_INET6;
584 mib[4] = NET_RT_FLAGS;
585 mib[5] = RTF_LLINFO;

--- 9 unchanged lines hidden (view full) ---

595 buf = lim = NULL;
596
597 for (next = buf; next && next < lim; next += rtm->rtm_msglen) {
598 int isrouter = 0, prbs = 0;
599
600 rtm = (struct rt_msghdr *)next;
601 sin = (struct sockaddr_in6 *)(rtm + 1);
602 sdl = (struct sockaddr_dl *)((char *)sin + ROUNDUP(sin->sin6_len));
603
604 /*
605 * Some OSes can produce a route that has the LINK flag but
606 * has a non-AF_LINK gateway (e.g. fe80::xx%lo0 on FreeBSD
607 * and BSD/OS, where xx is not the interface identifier on
608 * lo0). Such routes entry would annoy getnbrinfo() below,
609 * so we skip them.
610 * XXX: such routes should have the GATEWAY flag, not the
611 * LINK flag. However, there are rotten routing software
612 * that advertises all routes that have the GATEWAY flag.
613 * Thus, KAME kernel intentionally does not set the LINK flag.
614 * What is to be fixed is not ndp, but such routing software
615 * (and the kernel workaround)...
616 */
617 if (sdl->sdl_family != AF_LINK)
618 continue;
619
593 if (addr) {
594 if (!IN6_ARE_ADDR_EQUAL(addr, &sin->sin6_addr))
595 continue;
596 found_entry = 1;
597 } else if (IN6_IS_ADDR_MULTICAST(&sin->sin6_addr))
598 continue;
599 if (IN6_IS_ADDR_LINKLOCAL(&sin->sin6_addr) ||
600 IN6_IS_ADDR_MC_LINKLOCAL(&sin->sin6_addr)) {

--- 11 unchanged lines hidden (view full) ---

612 if (cflag == 1) {
613 delete(host_buf);
614 continue;
615 }
616 gettimeofday(&time, 0);
617 if (tflag)
618 ts_print(&time);
619
620 if (addr) {
621 if (!IN6_ARE_ADDR_EQUAL(addr, &sin->sin6_addr))
622 continue;
623 found_entry = 1;
624 } else if (IN6_IS_ADDR_MULTICAST(&sin->sin6_addr))
625 continue;
626 if (IN6_IS_ADDR_LINKLOCAL(&sin->sin6_addr) ||
627 IN6_IS_ADDR_MC_LINKLOCAL(&sin->sin6_addr)) {

--- 11 unchanged lines hidden (view full) ---

639 if (cflag == 1) {
640 delete(host_buf);
641 continue;
642 }
643 gettimeofday(&time, 0);
644 if (tflag)
645 ts_print(&time);
646
620 if (lflag) {
621 addrwidth = strlen(host_buf);
622 if (addrwidth < 31)
623 addrwidth = 31;
624 } else
625 addrwidth = 31;
647 addrwidth = strlen(host_buf);
648 if (addrwidth < W_ADDR)
649 addrwidth = W_ADDR;
650 llwidth = strlen(ether_str(sdl));
651 if (W_ADDR + W_LL - addrwidth > llwidth)
652 llwidth = W_ADDR + W_LL - addrwidth;
653 ifname = if_indextoname(sdl->sdl_index, ifix_buf);
654 if (!ifname)
655 ifname = "?";
656 ifwidth = strlen(ifname);
657 if (W_ADDR + W_LL + W_IF - addrwidth - llwidth > ifwidth)
658 ifwidth = W_ADDR + W_LL + W_IF - addrwidth - llwidth;
626
659
627 printf("%-*.*s %-17.17s %6.6s", addrwidth, addrwidth, host_buf,
628 ether_str(sdl),
629 if_indextoname(sdl->sdl_index, ifix_buf));
660 printf("%-*.*s %-*.*s %*.*s", addrwidth, addrwidth, host_buf,
661 llwidth, llwidth, ether_str(sdl), ifwidth, ifwidth, ifname);
630
631 /* Print neighbor discovery specific informations */
632 nbi = getnbrinfo(&sin->sin6_addr, sdl->sdl_index, 1);
633 if (nbi) {
634 if (nbi->expire > time.tv_sec) {
635 printf(" %-9.9s",
636 sec2str(nbi->expire - time.tv_sec));
662
663 /* Print neighbor discovery specific informations */
664 nbi = getnbrinfo(&sin->sin6_addr, sdl->sdl_index, 1);
665 if (nbi) {
666 if (nbi->expire > time.tv_sec) {
667 printf(" %-9.9s",
668 sec2str(nbi->expire - time.tv_sec));
637 }
638 else if (nbi->expire == 0)
669 } else if (nbi->expire == 0)
639 printf(" %-9.9s", "permanent");
640 else
641 printf(" %-9.9s", "expired");
642
643 switch(nbi->state) {
644 case ND6_LLINFO_NOSTATE:
645 printf(" N");
646 break;
670 printf(" %-9.9s", "permanent");
671 else
672 printf(" %-9.9s", "expired");
673
674 switch(nbi->state) {
675 case ND6_LLINFO_NOSTATE:
676 printf(" N");
677 break;
678#ifdef ND6_LLINFO_WAITDELETE
647 case ND6_LLINFO_WAITDELETE:
648 printf(" W");
649 break;
679 case ND6_LLINFO_WAITDELETE:
680 printf(" W");
681 break;
682#endif
650 case ND6_LLINFO_INCOMPLETE:
651 printf(" I");
652 break;
653 case ND6_LLINFO_REACHABLE:
654 printf(" R");
655 break;
656 case ND6_LLINFO_STALE:
657 printf(" S");

--- 6 unchanged lines hidden (view full) ---

664 break;
665 default:
666 printf(" ?");
667 break;
668 }
669
670 isrouter = nbi->isrouter;
671 prbs = nbi->asked;
683 case ND6_LLINFO_INCOMPLETE:
684 printf(" I");
685 break;
686 case ND6_LLINFO_REACHABLE:
687 printf(" R");
688 break;
689 case ND6_LLINFO_STALE:
690 printf(" S");

--- 6 unchanged lines hidden (view full) ---

697 break;
698 default:
699 printf(" ?");
700 break;
701 }
702
703 isrouter = nbi->isrouter;
704 prbs = nbi->asked;
672 }
673 else {
705 } else {
674 warnx("failed to get neighbor information");
675 printf(" ");
676 }
677 putchar(' ');
678
679 /*
680 * other flags. R: router, P: proxy, W: ??
681 */

--- 14 unchanged lines hidden (view full) ---

696 }
697 printf(" %-4.4s", flgbuf);
698
699 if (prbs)
700 printf(" %4d", prbs);
701
702 printf("\n");
703 }
706 warnx("failed to get neighbor information");
707 printf(" ");
708 }
709 putchar(' ');
710
711 /*
712 * other flags. R: router, P: proxy, W: ??
713 */

--- 14 unchanged lines hidden (view full) ---

728 }
729 printf(" %-4.4s", flgbuf);
730
731 if (prbs)
732 printf(" %4d", prbs);
733
734 printf("\n");
735 }
736 if (buf != NULL)
737 free(buf);
704
705 if (repeat) {
706 printf("\n");
707 sleep(repeat);
708 goto again;
709 }
710}
711

--- 29 unchanged lines hidden (view full) ---

741{
742 static char ebuf[32];
743 u_char *cp;
744
745 if (sdl->sdl_alen) {
746 cp = (u_char *)LLADDR(sdl);
747 sprintf(ebuf, "%x:%x:%x:%x:%x:%x",
748 cp[0], cp[1], cp[2], cp[3], cp[4], cp[5]);
738
739 if (repeat) {
740 printf("\n");
741 sleep(repeat);
742 goto again;
743 }
744}
745

--- 29 unchanged lines hidden (view full) ---

775{
776 static char ebuf[32];
777 u_char *cp;
778
779 if (sdl->sdl_alen) {
780 cp = (u_char *)LLADDR(sdl);
781 sprintf(ebuf, "%x:%x:%x:%x:%x:%x",
782 cp[0], cp[1], cp[2], cp[3], cp[4], cp[5]);
749 }
750 else {
783 } else {
751 sprintf(ebuf, "(incomplete)");
752 }
753
754 return(ebuf);
755}
756
757int
758ndp_ether_aton(a, n)

--- 12 unchanged lines hidden (view full) ---

771 n[i] = o[i];
772 return (0);
773}
774
775void
776usage()
777{
778 printf("usage: ndp hostname\n");
784 sprintf(ebuf, "(incomplete)");
785 }
786
787 return(ebuf);
788}
789
790int
791ndp_ether_aton(a, n)

--- 12 unchanged lines hidden (view full) ---

804 n[i] = o[i];
805 return (0);
806}
807
808void
809usage()
810{
811 printf("usage: ndp hostname\n");
779 printf(" ndp -a[ntl]\n");
780 printf(" ndp [-ntl] -A wait\n");
812 printf(" ndp -a[nt]\n");
813 printf(" ndp [-nt] -A wait\n");
781 printf(" ndp -c[nt]\n");
782 printf(" ndp -d[nt] hostname\n");
783 printf(" ndp -f[nt] filename\n");
784 printf(" ndp -i interface [flags...]\n");
785#ifdef SIOCSDEFIFACE_IN6
786 printf(" ndp -I [interface|delete]\n");
787#endif
788 printf(" ndp -p\n");

--- 72 unchanged lines hidden (view full) ---

861ifinfo(argc, argv)
862 int argc;
863 char **argv;
864{
865 struct in6_ndireq nd;
866 int i, s;
867 char *ifname = argv[0];
868 u_int32_t newflags;
814 printf(" ndp -c[nt]\n");
815 printf(" ndp -d[nt] hostname\n");
816 printf(" ndp -f[nt] filename\n");
817 printf(" ndp -i interface [flags...]\n");
818#ifdef SIOCSDEFIFACE_IN6
819 printf(" ndp -I [interface|delete]\n");
820#endif
821 printf(" ndp -p\n");

--- 72 unchanged lines hidden (view full) ---

894ifinfo(argc, argv)
895 int argc;
896 char **argv;
897{
898 struct in6_ndireq nd;
899 int i, s;
900 char *ifname = argv[0];
901 u_int32_t newflags;
902#ifdef IPV6CTL_USETEMPADDR
903 u_int8_t nullbuf[8];
904#endif
869
870 if ((s = socket(AF_INET6, SOCK_DGRAM, 0)) < 0) {
871 perror("ndp: socket");
872 exit(1);
873 }
874 bzero(&nd, sizeof(nd));
875 strcpy(nd.ifname, ifname);
876 if (ioctl(s, SIOCGIFINFO_IN6, (caddr_t)&nd) < 0) {

--- 31 unchanged lines hidden (view full) ---

908 }
909
910 printf("linkmtu=%d", ND.linkmtu);
911 printf(", curhlim=%d", ND.chlim);
912 printf(", basereachable=%ds%dms",
913 ND.basereachable / 1000, ND.basereachable % 1000);
914 printf(", reachable=%ds", ND.reachable);
915 printf(", retrans=%ds%dms", ND.retrans / 1000, ND.retrans % 1000);
905
906 if ((s = socket(AF_INET6, SOCK_DGRAM, 0)) < 0) {
907 perror("ndp: socket");
908 exit(1);
909 }
910 bzero(&nd, sizeof(nd));
911 strcpy(nd.ifname, ifname);
912 if (ioctl(s, SIOCGIFINFO_IN6, (caddr_t)&nd) < 0) {

--- 31 unchanged lines hidden (view full) ---

944 }
945
946 printf("linkmtu=%d", ND.linkmtu);
947 printf(", curhlim=%d", ND.chlim);
948 printf(", basereachable=%ds%dms",
949 ND.basereachable / 1000, ND.basereachable % 1000);
950 printf(", reachable=%ds", ND.reachable);
951 printf(", retrans=%ds%dms", ND.retrans / 1000, ND.retrans % 1000);
952#ifdef IPV6CTL_USETEMPADDR
953 memset(nullbuf, 0, sizeof(nullbuf));
954 if (memcmp(nullbuf, ND.randomid, sizeof(nullbuf)) != 0) {
955 int j;
956 u_int8_t *rbuf;
957
958 for (i = 0; i < 3; i++) {
959 switch(i) {
960 case 0:
961 printf("\nRandom seed(0): ");
962 rbuf = ND.randomseed0;
963 break;
964 case 1:
965 printf("\nRandom seed(1): ");
966 rbuf = ND.randomseed1;
967 break;
968 case 2:
969 printf("\nRandom ID: ");
970 rbuf = ND.randomid;
971 break;
972 }
973 for (j = 0; j < 8; j++)
974 printf("%02x", rbuf[j]);
975 }
976 }
977#endif
916 if (ND.flags) {
917 printf("\nFlags: ");
918 if ((ND.flags & ND6_IFF_PERFORMNUD) != 0)
919 printf("PERFORMNUD ");
920 }
921 putc('\n', stdout);
922#undef ND
923
924 close(s);
925}
926
978 if (ND.flags) {
979 printf("\nFlags: ");
980 if ((ND.flags & ND6_IFF_PERFORMNUD) != 0)
981 printf("PERFORMNUD ");
982 }
983 putc('\n', stdout);
984#undef ND
985
986 close(s);
987}
988
989#ifndef ND_RA_FLAG_RTPREF_MASK /* XXX: just for compilation on *BSD release */
990#define ND_RA_FLAG_RTPREF_MASK 0x18 /* 00011000 */
991#endif
992
927void
928rtrlist()
929{
993void
994rtrlist()
995{
996#ifdef ICMPV6CTL_ND6_DRLIST
997 int mib[] = { CTL_NET, PF_INET6, IPPROTO_ICMPV6, ICMPV6CTL_ND6_DRLIST };
998 char *buf;
999 struct in6_defrouter *p, *ep;
1000 size_t l;
1001 struct timeval time;
1002
1003 if (sysctl(mib, sizeof(mib) / sizeof(mib[0]), NULL, &l, NULL, 0) < 0) {
1004 err(1, "sysctl(ICMPV6CTL_ND6_DRLIST)");
1005 /*NOTREACHED*/
1006 }
1007 buf = malloc(l);
1008 if (!buf) {
1009 errx(1, "not enough core");
1010 /*NOTREACHED*/
1011 }
1012 if (sysctl(mib, sizeof(mib) / sizeof(mib[0]), buf, &l, NULL, 0) < 0) {
1013 err(1, "sysctl(ICMPV6CTL_ND6_DRLIST)");
1014 /*NOTREACHED*/
1015 }
1016
1017 ep = (struct in6_defrouter *)(buf + l);
1018 for (p = (struct in6_defrouter *)buf; p < ep; p++) {
1019 int rtpref;
1020
1021 if (getnameinfo((struct sockaddr *)&p->rtaddr,
1022 p->rtaddr.sin6_len, host_buf, sizeof(host_buf), NULL, 0,
1023 NI_WITHSCOPEID | (nflag ? NI_NUMERICHOST : 0)) != 0)
1024 strlcpy(host_buf, "?", sizeof(host_buf));
1025
1026 printf("%s if=%s", host_buf,
1027 if_indextoname(p->if_index, ifix_buf));
1028 printf(", flags=%s%s",
1029 p->flags & ND_RA_FLAG_MANAGED ? "M" : "",
1030 p->flags & ND_RA_FLAG_OTHER ? "O" : "");
1031 rtpref = ((p->flags & ND_RA_FLAG_RTPREF_MASK) >> 3) & 0xff;
1032 printf(", pref=%s", rtpref_str[rtpref]);
1033
1034 gettimeofday(&time, 0);
1035 if (p->expire == 0)
1036 printf(", expire=Never\n");
1037 else
1038 printf(", expire=%s\n",
1039 sec2str(p->expire - time.tv_sec));
1040 }
1041 free(buf);
1042#else
930 struct in6_drlist dr;
931 int s, i;
932 struct timeval time;
933
934 if ((s = socket(AF_INET6, SOCK_DGRAM, 0)) < 0) {
935 perror("ndp: socket");
936 exit(1);
937 }
938 bzero(&dr, sizeof(dr));
939 strcpy(dr.ifname, "lo0"); /* dummy */
940 if (ioctl(s, SIOCGDRLST_IN6, (caddr_t)&dr) < 0) {
941 perror("ioctl (SIOCGDRLST_IN6)");
942 exit(1);
943 }
944#define DR dr.defrouter[i]
1043 struct in6_drlist dr;
1044 int s, i;
1045 struct timeval time;
1046
1047 if ((s = socket(AF_INET6, SOCK_DGRAM, 0)) < 0) {
1048 perror("ndp: socket");
1049 exit(1);
1050 }
1051 bzero(&dr, sizeof(dr));
1052 strcpy(dr.ifname, "lo0"); /* dummy */
1053 if (ioctl(s, SIOCGDRLST_IN6, (caddr_t)&dr) < 0) {
1054 perror("ioctl (SIOCGDRLST_IN6)");
1055 exit(1);
1056 }
1057#define DR dr.defrouter[i]
945 for (i = 0 ; DR.if_index && i < PRLSTSIZ ; i++) {
1058 for (i = 0 ; DR.if_index && i < DRLSTSIZ ; i++) {
946 struct sockaddr_in6 sin6;
947
948 bzero(&sin6, sizeof(sin6));
949 sin6.sin6_family = AF_INET6;
950 sin6.sin6_len = sizeof(sin6);
951 sin6.sin6_addr = DR.rtaddr;
952 getnameinfo((struct sockaddr *)&sin6, sin6.sin6_len, host_buf,
953 sizeof(host_buf), NULL, 0,

--- 8 unchanged lines hidden (view full) ---

962 if (DR.expire == 0)
963 printf(", expire=Never\n");
964 else
965 printf(", expire=%s\n",
966 sec2str(DR.expire - time.tv_sec));
967 }
968#undef DR
969 close(s);
1059 struct sockaddr_in6 sin6;
1060
1061 bzero(&sin6, sizeof(sin6));
1062 sin6.sin6_family = AF_INET6;
1063 sin6.sin6_len = sizeof(sin6);
1064 sin6.sin6_addr = DR.rtaddr;
1065 getnameinfo((struct sockaddr *)&sin6, sin6.sin6_len, host_buf,
1066 sizeof(host_buf), NULL, 0,

--- 8 unchanged lines hidden (view full) ---

1075 if (DR.expire == 0)
1076 printf(", expire=Never\n");
1077 else
1078 printf(", expire=%s\n",
1079 sec2str(DR.expire - time.tv_sec));
1080 }
1081#undef DR
1082 close(s);
1083#endif
970}
971
972void
973plist()
974{
1084}
1085
1086void
1087plist()
1088{
1089#ifdef ICMPV6CTL_ND6_PRLIST
1090 int mib[] = { CTL_NET, PF_INET6, IPPROTO_ICMPV6, ICMPV6CTL_ND6_PRLIST };
1091 char *buf;
1092 struct in6_prefix *p, *ep, *n;
1093 struct sockaddr_in6 *advrtr;
1094 size_t l;
1095 struct timeval time;
1096#ifdef NI_WITHSCOPEID
1097 const int niflags = NI_NUMERICHOST | NI_WITHSCOPEID;
1098 int ninflags = (nflag ? NI_NUMERICHOST : 0) | NI_WITHSCOPEID;
1099#else
1100 const int niflags = NI_NUMERICHOST;
1101 int ninflags = nflag ? NI_NUMERICHOST : 0;
1102#endif
1103 char namebuf[NI_MAXHOST];
1104
1105 if (sysctl(mib, sizeof(mib) / sizeof(mib[0]), NULL, &l, NULL, 0) < 0) {
1106 err(1, "sysctl(ICMPV6CTL_ND6_PRLIST)");
1107 /*NOTREACHED*/
1108 }
1109 buf = malloc(l);
1110 if (!buf) {
1111 errx(1, "not enough core");
1112 /*NOTREACHED*/
1113 }
1114 if (sysctl(mib, sizeof(mib) / sizeof(mib[0]), buf, &l, NULL, 0) < 0) {
1115 err(1, "sysctl(ICMPV6CTL_ND6_PRLIST)");
1116 /*NOTREACHED*/
1117 }
1118
1119 ep = (struct in6_prefix *)(buf + l);
1120 for (p = (struct in6_prefix *)buf; p < ep; p = n) {
1121 advrtr = (struct sockaddr_in6 *)(p + 1);
1122 n = (struct in6_prefix *)&advrtr[p->advrtrs];
1123
1124 if (getnameinfo((struct sockaddr *)&p->prefix,
1125 p->prefix.sin6_len, namebuf, sizeof(namebuf),
1126 NULL, 0, niflags) != 0)
1127 strlcpy(namebuf, "?", sizeof(namebuf));
1128 printf("%s/%d if=%s\n", namebuf, p->prefixlen,
1129 if_indextoname(p->if_index, ifix_buf));
1130
1131 gettimeofday(&time, 0);
1132 /*
1133 * meaning of fields, especially flags, is very different
1134 * by origin. notify the difference to the users.
1135 */
1136 printf("flags=%s%s%s%s%s",
1137 p->raflags.onlink ? "L" : "",
1138 p->raflags.autonomous ? "A" : "",
1139 (p->flags & NDPRF_ONLINK) != 0 ? "O" : "",
1140 (p->flags & NDPRF_DETACHED) != 0 ? "D" : "",
1141#ifdef NDPRF_HOME
1142 (p->flags & NDPRF_HOME) != 0 ? "H" : ""
1143#else
1144 ""
1145#endif
1146 );
1147 if (p->vltime == ND6_INFINITE_LIFETIME)
1148 printf(" vltime=infinity");
1149 else
1150 printf(" vltime=%ld", (long)p->vltime);
1151 if (p->pltime == ND6_INFINITE_LIFETIME)
1152 printf(", pltime=infinity");
1153 else
1154 printf(", pltime=%ld", (long)p->pltime);
1155 if (p->expire == 0)
1156 printf(", expire=Never");
1157 else if (p->expire >= time.tv_sec)
1158 printf(", expire=%s",
1159 sec2str(p->expire - time.tv_sec));
1160 else
1161 printf(", expired");
1162 printf(", ref=%d", p->refcnt);
1163 printf("\n");
1164 /*
1165 * "advertising router" list is meaningful only if the prefix
1166 * information is from RA.
1167 */
1168 if (p->advrtrs) {
1169 int j;
1170 struct sockaddr_in6 *sin6;
1171
1172 sin6 = (struct sockaddr_in6 *)(p + 1);
1173 printf(" advertised by\n");
1174 for (j = 0; j < p->advrtrs; j++) {
1175 struct in6_nbrinfo *nbi;
1176
1177 if (getnameinfo((struct sockaddr *)sin6,
1178 sin6->sin6_len, namebuf, sizeof(namebuf),
1179 NULL, 0, ninflags) != 0)
1180 strlcpy(namebuf, "?", sizeof(namebuf));
1181 printf(" %s", namebuf);
1182
1183 nbi = getnbrinfo(&sin6->sin6_addr, p->if_index,
1184 0);
1185 if (nbi) {
1186 switch(nbi->state) {
1187 case ND6_LLINFO_REACHABLE:
1188 case ND6_LLINFO_STALE:
1189 case ND6_LLINFO_DELAY:
1190 case ND6_LLINFO_PROBE:
1191 printf(" (reachable)\n");
1192 break;
1193 default:
1194 printf(" (unreachable)\n");
1195 }
1196 } else
1197 printf(" (no neighbor state)\n");
1198 sin6++;
1199 }
1200 } else
1201 printf(" No advertising router\n");
1202 }
1203 free(buf);
1204#else
975 struct in6_prlist pr;
976 int s, i;
977 struct timeval time;
978
979 gettimeofday(&time, 0);
980
981 if ((s = socket(AF_INET6, SOCK_DGRAM, 0)) < 0) {
982 perror("ndp: socket");
983 exit(1);
984 }
985 bzero(&pr, sizeof(pr));
986 strcpy(pr.ifname, "lo0"); /* dummy */
987 if (ioctl(s, SIOCGPRLST_IN6, (caddr_t)&pr) < 0) {
988 perror("ioctl (SIOCGPRLST_IN6)");
989 exit(1);
990 }
991#define PR pr.prefix[i]
992 for (i = 0; PR.if_index && i < PRLSTSIZ ; i++) {
1205 struct in6_prlist pr;
1206 int s, i;
1207 struct timeval time;
1208
1209 gettimeofday(&time, 0);
1210
1211 if ((s = socket(AF_INET6, SOCK_DGRAM, 0)) < 0) {
1212 perror("ndp: socket");
1213 exit(1);
1214 }
1215 bzero(&pr, sizeof(pr));
1216 strcpy(pr.ifname, "lo0"); /* dummy */
1217 if (ioctl(s, SIOCGPRLST_IN6, (caddr_t)&pr) < 0) {
1218 perror("ioctl (SIOCGPRLST_IN6)");
1219 exit(1);
1220 }
1221#define PR pr.prefix[i]
1222 for (i = 0; PR.if_index && i < PRLSTSIZ ; i++) {
993 printf("%s/%d if=%s\n",
994 inet_ntop(AF_INET6, &PR.prefix, ntop_buf,
995 sizeof(ntop_buf)), PR.prefixlen,
1223 struct sockaddr_in6 p6;
1224 char namebuf[NI_MAXHOST];
1225 int niflags;
1226
1227#ifdef NDPRF_ONLINK
1228 p6 = PR.prefix;
1229#else
1230 memset(&p6, 0, sizeof(p6));
1231 p6.sin6_family = AF_INET6;
1232 p6.sin6_len = sizeof(p6);
1233 p6.sin6_addr = PR.prefix;
1234#endif
1235
1236 /*
1237 * copy link index to sin6_scope_id field.
1238 * XXX: KAME specific.
1239 */
1240 if (IN6_IS_ADDR_LINKLOCAL(&p6.sin6_addr)) {
1241 u_int16_t linkid;
1242
1243 memcpy(&linkid, &p6.sin6_addr.s6_addr[2],
1244 sizeof(linkid));
1245 linkid = ntohs(linkid);
1246 p6.sin6_scope_id = linkid;
1247 p6.sin6_addr.s6_addr[2] = 0;
1248 p6.sin6_addr.s6_addr[3] = 0;
1249 }
1250
1251 niflags = NI_NUMERICHOST;
1252#ifdef __KAME__
1253 niflags |= NI_WITHSCOPEID;
1254#endif
1255 if (getnameinfo((struct sockaddr *)&p6,
1256 sizeof(p6), namebuf, sizeof(namebuf),
1257 NULL, 0, niflags)) {
1258 warnx("getnameinfo failed");
1259 continue;
1260 }
1261 printf("%s/%d if=%s\n", namebuf, PR.prefixlen,
996 if_indextoname(PR.if_index, ifix_buf));
1262 if_indextoname(PR.if_index, ifix_buf));
1263
997 gettimeofday(&time, 0);
998 /*
999 * meaning of fields, especially flags, is very different
1000 * by origin. notify the difference to the users.
1001 */
1264 gettimeofday(&time, 0);
1265 /*
1266 * meaning of fields, especially flags, is very different
1267 * by origin. notify the difference to the users.
1268 */
1002 printf(" %s", PR.origin == PR_ORIG_RA ? "" : "advertise: ");
1269#if 0
1270 printf(" %s",
1271 PR.origin == PR_ORIG_RA ? "" : "advertise: ");
1272#endif
1273#ifdef NDPRF_ONLINK
1274 printf("flags=%s%s%s%s%s",
1275 PR.raflags.onlink ? "L" : "",
1276 PR.raflags.autonomous ? "A" : "",
1277 (PR.flags & NDPRF_ONLINK) != 0 ? "O" : "",
1278 (PR.flags & NDPRF_DETACHED) != 0 ? "D" : "",
1279#ifdef NDPRF_HOME
1280 (PR.flags & NDPRF_HOME) != 0 ? "H" : ""
1281#else
1282 ""
1283#endif
1284 );
1285#else
1003 printf("flags=%s%s",
1004 PR.raflags.onlink ? "L" : "",
1005 PR.raflags.autonomous ? "A" : "");
1286 printf("flags=%s%s",
1287 PR.raflags.onlink ? "L" : "",
1288 PR.raflags.autonomous ? "A" : "");
1289#endif
1006 if (PR.vltime == ND6_INFINITE_LIFETIME)
1007 printf(" vltime=infinity");
1008 else
1009 printf(" vltime=%ld", (long)PR.vltime);
1010 if (PR.pltime == ND6_INFINITE_LIFETIME)
1011 printf(", pltime=infinity");
1012 else
1013 printf(", pltime=%ld", (long)PR.pltime);
1014 if (PR.expire == 0)
1015 printf(", expire=Never");
1016 else if (PR.expire >= time.tv_sec)
1017 printf(", expire=%s",
1018 sec2str(PR.expire - time.tv_sec));
1019 else
1020 printf(", expired");
1290 if (PR.vltime == ND6_INFINITE_LIFETIME)
1291 printf(" vltime=infinity");
1292 else
1293 printf(" vltime=%ld", (long)PR.vltime);
1294 if (PR.pltime == ND6_INFINITE_LIFETIME)
1295 printf(", pltime=infinity");
1296 else
1297 printf(", pltime=%ld", (long)PR.pltime);
1298 if (PR.expire == 0)
1299 printf(", expire=Never");
1300 else if (PR.expire >= time.tv_sec)
1301 printf(", expire=%s",
1302 sec2str(PR.expire - time.tv_sec));
1303 else
1304 printf(", expired");
1305#ifdef NDPRF_ONLINK
1306 printf(", ref=%d", PR.refcnt);
1307#endif
1308#if 0
1021 switch (PR.origin) {
1022 case PR_ORIG_RA:
1023 printf(", origin=RA");
1024 break;
1025 case PR_ORIG_RR:
1026 printf(", origin=RR");
1027 break;
1028 case PR_ORIG_STATIC:
1029 printf(", origin=static");
1030 break;
1031 case PR_ORIG_KERNEL:
1032 printf(", origin=kernel");
1033 break;
1034 default:
1035 printf(", origin=?");
1036 break;
1037 }
1309 switch (PR.origin) {
1310 case PR_ORIG_RA:
1311 printf(", origin=RA");
1312 break;
1313 case PR_ORIG_RR:
1314 printf(", origin=RR");
1315 break;
1316 case PR_ORIG_STATIC:
1317 printf(", origin=static");
1318 break;
1319 case PR_ORIG_KERNEL:
1320 printf(", origin=kernel");
1321 break;
1322 default:
1323 printf(", origin=?");
1324 break;
1325 }
1326#endif
1038 printf("\n");
1039 /*
1040 * "advertising router" list is meaningful only if the prefix
1041 * information is from RA.
1042 */
1327 printf("\n");
1328 /*
1329 * "advertising router" list is meaningful only if the prefix
1330 * information is from RA.
1331 */
1043 if (PR.origin != PR_ORIG_RA)
1332 if (0 && /* prefix origin is almost obsolted */
1333 PR.origin != PR_ORIG_RA)
1044 ;
1045 else if (PR.advrtrs) {
1046 int j;
1047 printf(" advertised by\n");
1048 for (j = 0; j < PR.advrtrs; j++) {
1049 struct sockaddr_in6 sin6;
1050 struct in6_nbrinfo *nbi;
1051

--- 16 unchanged lines hidden (view full) ---

1068 case ND6_LLINFO_STALE:
1069 case ND6_LLINFO_DELAY:
1070 case ND6_LLINFO_PROBE:
1071 printf(" (reachable)\n");
1072 break;
1073 default:
1074 printf(" (unreachable)\n");
1075 }
1334 ;
1335 else if (PR.advrtrs) {
1336 int j;
1337 printf(" advertised by\n");
1338 for (j = 0; j < PR.advrtrs; j++) {
1339 struct sockaddr_in6 sin6;
1340 struct in6_nbrinfo *nbi;
1341

--- 16 unchanged lines hidden (view full) ---

1358 case ND6_LLINFO_STALE:
1359 case ND6_LLINFO_DELAY:
1360 case ND6_LLINFO_PROBE:
1361 printf(" (reachable)\n");
1362 break;
1363 default:
1364 printf(" (unreachable)\n");
1365 }
1076 }
1077 else
1366 } else
1078 printf(" (no neighbor state)\n");
1079 }
1080 if (PR.advrtrs > DRLSTSIZ)
1081 printf(" and %d routers\n",
1082 PR.advrtrs - DRLSTSIZ);
1083 } else
1084 printf(" No advertising router\n");
1085 }
1086#undef PR
1087 close(s);
1367 printf(" (no neighbor state)\n");
1368 }
1369 if (PR.advrtrs > DRLSTSIZ)
1370 printf(" and %d routers\n",
1371 PR.advrtrs - DRLSTSIZ);
1372 } else
1373 printf(" No advertising router\n");
1374 }
1375#undef PR
1376 close(s);
1377#endif
1088}
1089
1090void
1091pfx_flush()
1092{
1093 char dummyif[IFNAMSIZ+8];
1094 int s;
1095

--- 138 unchanged lines hidden ---
1378}
1379
1380void
1381pfx_flush()
1382{
1383 char dummyif[IFNAMSIZ+8];
1384 int s;
1385

--- 138 unchanged lines hidden ---