summaryrefslogtreecommitdiff
path: root/usr.sbin
diff options
context:
space:
mode:
authorJun-ichiro itojun Hagino <itojun@cvs.openbsd.org>2002-05-29 08:05:40 +0000
committerJun-ichiro itojun Hagino <itojun@cvs.openbsd.org>2002-05-29 08:05:40 +0000
commitb45a740441978cca11578cac7315576b053d520f (patch)
tree33cf344cbf138d7ef3795bbb02d4501a1fc0fc50 /usr.sbin
parent0c16805fafc1c4948896949b53a45cd12b23c792 (diff)
use new SIOCGIFINFO_IN6. random other cleanups. sync w/kame.
Diffstat (limited to 'usr.sbin')
-rw-r--r--usr.sbin/ndp/ndp.838
-rw-r--r--usr.sbin/ndp/ndp.c129
2 files changed, 114 insertions, 53 deletions
diff --git a/usr.sbin/ndp/ndp.8 b/usr.sbin/ndp/ndp.8
index 2f0e89cb081..e3d29ea197e 100644
--- a/usr.sbin/ndp/ndp.8
+++ b/usr.sbin/ndp/ndp.8
@@ -1,5 +1,5 @@
-.\" $OpenBSD: ndp.8,v 1.9 2001/02/08 08:35:17 itojun Exp $
-.\" $KAME: ndp.8,v 1.15 2001/02/08 07:17:03 itojun Exp $
+.\" $OpenBSD: ndp.8,v 1.10 2002/05/29 08:05:39 itojun Exp $
+.\" $KAME: ndp.8,v 1.20 2002/05/29 07:37:51 itojun Exp $
.\"
.\" Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
.\" All rights reserved.
@@ -62,7 +62,7 @@
.Nm ndp
.Fl i
.Ar interface
-.Op Ar flags...
+.Op Ar flags ...
.Nm ndp
.Fl p
.Nm ndp
@@ -87,6 +87,35 @@ used by Neighbor Discovery Protocol (NDP).
.Bl -tag -width Ds
.It Fl a
Dump the currently existing NDP entries.
+The following information will be printed:
+.Bl -tag -width Ds
+.It Neighbor
+IPv6 address of the neighbor.
+.It Linklayer Address
+Linklayer address of the neighbor.
+It could be
+.Dq Li (incomplete)
+when the address is not available.
+.It Netif
+Network interface associated with the neighbor cache entry.
+.It Expire
+The time until the expiry of the entry.
+The entry could become
+.Dq Li permanent
+when it will never expire.
+.It S
+State of the neighbor cache entry, in a single letter.
+They are:
+Nostate, Waitdelete, Incomplete, Reachable, Stale, Delay and Probe.
+.Dq Li ?
+indicates unknown state, which should never happen.
+.It Flgs
+Flags on the neighbor cache entry, in a single letter.
+They are: Router, proxy neighbor advertisement
+.Pq Dq p .
+The field could be followed by a decimal number,
+which means the number of NS probes the node have sent during the current state.
+.El
.It Fl A Ar wait
Repeat
.Fl a
@@ -115,13 +144,14 @@ is specified, the interface will be used as the default.
If a special keyword
.Ic delete
is specified, the current default interface will be deleted from the kernel.
-.It Fl i Ar interface Op Ar flags...
+.It Fl i Ar interface Op Ar flags ...
View ND information for the specified interface.
If additional arguments
.Ar flags
are given,
.Nm
sets or clears the specified flags for the interface.
+Each flag should be separated by white spaces or tab characters.
Possible flags are as follows.
All of the flags can begin with the
special character
diff --git a/usr.sbin/ndp/ndp.c b/usr.sbin/ndp/ndp.c
index 685d7294876..b929c85bad1 100644
--- a/usr.sbin/ndp/ndp.c
+++ b/usr.sbin/ndp/ndp.c
@@ -1,5 +1,5 @@
-/* $OpenBSD: ndp.c,v 1.15 2002/05/26 01:21:12 deraadt Exp $ */
-/* $KAME: ndp.c,v 1.69 2001/07/23 14:46:31 itojun Exp $ */
+/* $OpenBSD: ndp.c,v 1.16 2002/05/29 08:05:39 itojun Exp $ */
+/* $KAME: ndp.c,v 1.86 2002/05/26 01:16:10 itojun Exp $ */
/*
* Copyright (C) 1995, 1996, 1997, 1998, and 1999 WIDE Project.
@@ -118,10 +118,6 @@
#include <err.h>
#include "gmt2local.h"
-#ifndef NI_WITHSCOPEID
-#define NI_WITHSCOPEID 0
-#endif
-
/* packing rule for routing socket */
#define ROUNDUP(a) \
((a) > 0 ? (1 + (((a) - 1) | (sizeof(long) - 1))) : sizeof(long))
@@ -470,7 +466,7 @@ get(host)
if (found_entry == 0) {
getnameinfo((struct sockaddr *)sin, sin->sin6_len, host_buf,
sizeof(host_buf), NULL ,0,
- NI_WITHSCOPEID | (nflag ? NI_NUMERICHOST : 0));
+ (nflag ? NI_NUMERICHOST : 0));
printf("%s (%s) -- no entry\n", host, host_buf);
exit(1);
}
@@ -543,14 +539,14 @@ delete:
getnameinfo((struct sockaddr *)&s6,
s6.sin6_len, host_buf,
sizeof(host_buf), NULL, 0,
- NI_WITHSCOPEID | (nflag ? NI_NUMERICHOST : 0));
+ (nflag ? NI_NUMERICHOST : 0));
printf("%s (%s) deleted\n", host, host_buf);
}
return 0;
}
-#define W_ADDR 31
+#define W_ADDR 36
#define W_LL 17
#define W_IF 6
@@ -578,9 +574,9 @@ dump(addr)
/* Print header */
if (!tflag && !cflag)
- printf("%-*.*s %-*.*s %*.*s %-9.9s %2s %4s %4s\n",
+ printf("%-*.*s %-*.*s %*.*s %-9.9s %1s %4s\n",
W_ADDR, W_ADDR, "Neighbor", W_LL, W_LL, "Linklayer Address",
- W_IF, W_IF, "Netif", "Expire", "St", "Flgs", "Prbs");
+ W_IF, W_IF, "Netif", "Expire", "S", "Flgs");
again:;
mib[0] = CTL_NET;
@@ -623,6 +619,9 @@ again:;
if (sdl->sdl_family != AF_LINK)
continue;
+ if (!(rtm->rtm_flags & RTF_HOST))
+ continue;
+
if (addr) {
if (!IN6_ARE_ADDR_EQUAL(addr, &sin->sin6_addr))
continue;
@@ -641,9 +640,17 @@ again:;
}
getnameinfo((struct sockaddr *)sin, sin->sin6_len, host_buf,
sizeof(host_buf), NULL, 0,
- NI_WITHSCOPEID | (nflag ? NI_NUMERICHOST : 0));
+ (nflag ? NI_NUMERICHOST : 0));
if (cflag == 1) {
+#ifdef RTF_WASCLONED
+ if (rtm->rtm_flags & RTF_WASCLONED)
+ delete(host_buf);
+#elif defined(RTF_CLONED)
+ if (rtm->rtm_flags & RTF_CLONED)
+ delete(host_buf);
+#else
delete(host_buf);
+#endif
continue;
}
gettimeofday(&time, 0);
@@ -678,30 +685,30 @@ again:;
printf(" %-9.9s", "expired");
switch(nbi->state) {
- case ND6_LLINFO_NOSTATE:
+ case ND6_LLINFO_NOSTATE:
printf(" N");
break;
#ifdef ND6_LLINFO_WAITDELETE
- case ND6_LLINFO_WAITDELETE:
+ case ND6_LLINFO_WAITDELETE:
printf(" W");
break;
#endif
- case ND6_LLINFO_INCOMPLETE:
+ case ND6_LLINFO_INCOMPLETE:
printf(" I");
break;
- case ND6_LLINFO_REACHABLE:
+ case ND6_LLINFO_REACHABLE:
printf(" R");
break;
- case ND6_LLINFO_STALE:
+ case ND6_LLINFO_STALE:
printf(" S");
break;
- case ND6_LLINFO_DELAY:
+ case ND6_LLINFO_DELAY:
printf(" D");
break;
- case ND6_LLINFO_PROBE:
+ case ND6_LLINFO_PROBE:
printf(" P");
break;
- default:
+ default:
printf(" ?");
break;
}
@@ -712,7 +719,6 @@ again:;
warnx("failed to get neighbor information");
printf(" ");
}
- putchar(' ');
/*
* other flags. R: router, P: proxy, W: ??
@@ -724,6 +730,7 @@ again:;
} else {
sin = (struct sockaddr_in6 *)
(sdl->sdl_len + (char *)sdl);
+#if 0 /* W and P are mystery even for us */
snprintf(flgbuf, sizeof(flgbuf), "%s%s%s%s",
isrouter ? "R" : "",
!IN6_IS_ADDR_UNSPECIFIED(&sin->sin6_addr)
@@ -731,11 +738,16 @@ again:;
(sin->sin6_len != sizeof(struct sockaddr_in6))
? "W" : "",
(rtm->rtm_flags & RTF_ANNOUNCE) ? "p" : "");
+#else
+ snprintf(flgbuf, sizeof(flgbuf), "%s%s",
+ isrouter ? "R" : "",
+ (rtm->rtm_flags & RTF_ANNOUNCE) ? "p" : "");
+#endif
}
- printf(" %-4.4s", flgbuf);
+ printf(" %s", flgbuf);
if (prbs)
- printf(" %4d", prbs);
+ printf(" %d", prbs);
printf("\n");
}
@@ -784,10 +796,10 @@ ether_str(sdl)
if (sdl->sdl_alen) {
cp = (u_char *)LLADDR(sdl);
- sprintf(ebuf, "%x:%x:%x:%x:%x:%x",
+ snprintf(ebuf, sizeof(ebuf), "%x:%x:%x:%x:%x:%x",
cp[0], cp[1], cp[2], cp[3], cp[4], cp[5]);
} else {
- sprintf(ebuf, "(incomplete)");
+ snprintf(ebuf, sizeof(ebuf), "(incomplete)");
}
return(ebuf);
@@ -856,8 +868,10 @@ rtmsg(cmd)
exit(1);
case RTM_ADD:
rtm->rtm_addrs |= RTA_GATEWAY;
- rtm->rtm_rmx.rmx_expire = expire_time;
- rtm->rtm_inits = RTV_EXPIRE;
+ if (expire_time) {
+ rtm->rtm_rmx.rmx_expire = expire_time;
+ rtm->rtm_inits = RTV_EXPIRE;
+ }
rtm->rtm_flags |= (RTF_HOST | RTF_STATIC);
if (rtm->rtm_flags & RTF_ANNOUNCE) {
rtm->rtm_flags &= ~RTF_HOST;
@@ -940,6 +954,12 @@ ifinfo(argc, argv)
}\
} while (0)
SETFLAG("nud", ND6_IFF_PERFORMNUD);
+#ifdef ND6_IFF_ACCEPT_RTADV
+ SETFLAG("accept_rtadv", ND6_IFF_ACCEPT_RTADV);
+#endif
+#ifdef ND6_IFF_PREFER_SOURCE
+ SETFLAG("prefer_source", ND6_IFF_PREFER_SOURCE);
+#endif
ND.flags = newflags;
if (ioctl(s, SIOCSIFINFO_FLAGS, (caddr_t)&nd) < 0) {
@@ -949,7 +969,7 @@ ifinfo(argc, argv)
#undef SETFLAG
}
- if (!ND.linkmtu) {
+ if (!ND.initialized) {
errx(1, "%s: not initialized yet", ifname);
/* NOTREACHED */
}
@@ -988,8 +1008,16 @@ ifinfo(argc, argv)
#endif
if (ND.flags) {
printf("\nFlags: ");
- if ((ND.flags & ND6_IFF_PERFORMNUD) != 0)
+ if ((ND.flags & ND6_IFF_PERFORMNUD))
printf("PERFORMNUD ");
+#ifdef ND6_IFF_ACCEPT_RTADV
+ if ((ND.flags & ND6_IFF_ACCEPT_RTADV))
+ printf("ACCEPT_RA ");
+#endif
+#ifdef ND6_IFF_PREFER_SOURCE
+ if ((ND.flags & ND6_IFF_PREFER_SOURCE))
+ printf("PREFER_SRC ");
+#endif
}
putc('\n', stdout);
#undef ND
@@ -1031,7 +1059,7 @@ rtrlist()
if (getnameinfo((struct sockaddr *)&p->rtaddr,
p->rtaddr.sin6_len, host_buf, sizeof(host_buf), NULL, 0,
- NI_WITHSCOPEID | (nflag ? NI_NUMERICHOST : 0)) != 0)
+ (nflag ? NI_NUMERICHOST : 0)) != 0)
strlcpy(host_buf, "?", sizeof(host_buf));
printf("%s if=%s", host_buf,
@@ -1075,7 +1103,7 @@ rtrlist()
sin6.sin6_addr = DR.rtaddr;
getnameinfo((struct sockaddr *)&sin6, sin6.sin6_len, host_buf,
sizeof(host_buf), NULL, 0,
- NI_WITHSCOPEID | (nflag ? NI_NUMERICHOST : 0));
+ (nflag ? NI_NUMERICHOST : 0));
printf("%s if=%s", host_buf,
if_indextoname(DR.if_index, ifix_buf));
@@ -1104,13 +1132,8 @@ plist()
struct sockaddr_in6 *advrtr;
size_t l;
struct timeval time;
-#ifdef NI_WITHSCOPEID
- const int niflags = NI_NUMERICHOST | NI_WITHSCOPEID;
- int ninflags = (nflag ? NI_NUMERICHOST : 0) | NI_WITHSCOPEID;
-#else
const int niflags = NI_NUMERICHOST;
int ninflags = nflag ? NI_NUMERICHOST : 0;
-#endif
char namebuf[NI_MAXHOST];
if (sysctl(mib, sizeof(mib) / sizeof(mib[0]), NULL, &l, NULL, 0) < 0) {
@@ -1158,11 +1181,11 @@ plist()
if (p->vltime == ND6_INFINITE_LIFETIME)
printf(" vltime=infinity");
else
- printf(" vltime=%ld", (long)p->vltime);
+ printf(" vltime=%lu", (unsigned long)p->vltime);
if (p->pltime == ND6_INFINITE_LIFETIME)
printf(", pltime=infinity");
else
- printf(", pltime=%ld", (long)p->pltime);
+ printf(", pltime=%lu", (unsigned long)p->pltime);
if (p->expire == 0)
printf(", expire=Never");
else if (p->expire >= time.tv_sec)
@@ -1180,7 +1203,7 @@ plist()
int j;
struct sockaddr_in6 *sin6;
- sin6 = (struct sockaddr_in6 *)(p + 1);
+ sin6 = advrtr;
printf(" advertised by\n");
for (j = 0; j < p->advrtrs; j++) {
struct in6_nbrinfo *nbi;
@@ -1260,9 +1283,6 @@ plist()
}
niflags = NI_NUMERICHOST;
-#ifdef __KAME__
- niflags |= NI_WITHSCOPEID;
-#endif
if (getnameinfo((struct sockaddr *)&p6,
sizeof(p6), namebuf, sizeof(namebuf),
NULL, 0, niflags)) {
@@ -1301,11 +1321,11 @@ plist()
if (PR.vltime == ND6_INFINITE_LIFETIME)
printf(" vltime=infinity");
else
- printf(" vltime=%ld", (long)PR.vltime);
+ printf(" vltime=%lu", PR.vltime);
if (PR.pltime == ND6_INFINITE_LIFETIME)
printf(", pltime=infinity");
else
- printf(", pltime=%ld", (long)PR.pltime);
+ printf(", pltime=%lu", PR.pltime);
if (PR.expire == 0)
printf(", expire=Never");
else if (PR.expire >= time.tv_sec)
@@ -1358,7 +1378,7 @@ plist()
getnameinfo((struct sockaddr *)&sin6,
sin6.sin6_len, host_buf,
sizeof(host_buf), NULL, 0,
- NI_WITHSCOPEID | (nflag ? NI_NUMERICHOST : 0));
+ (nflag ? NI_NUMERICHOST : 0));
printf(" %s", host_buf);
nbi = getnbrinfo(&sin6.sin6_addr, PR.if_index,
@@ -1494,6 +1514,8 @@ sec2str(total)
int days, hours, mins, secs;
int first = 1;
char *p = result;
+ char *ep = &result[sizeof(result)];
+ int n;
days = total / 3600 / 24;
hours = (total / 3600) % 24;
@@ -1502,17 +1524,26 @@ sec2str(total)
if (days) {
first = 0;
- p += sprintf(p, "%dd", days);
+ n = snprintf(p, ep - p, "%dd", days);
+ if (n < 0 || n >= ep - p)
+ return "?";
+ p += n;
}
if (!first || hours) {
first = 0;
- p += sprintf(p, "%dh", hours);
+ n = snprintf(p, ep - p, "%dh", hours);
+ if (n < 0 || n >= ep - p)
+ return "?";
+ p += n;
}
if (!first || mins) {
first = 0;
- p += sprintf(p, "%dm", mins);
+ n = snprintf(p, ep - p, "%dm", mins);
+ if (n < 0 || n >= ep - p)
+ return "?";
+ p += n;
}
- sprintf(p, "%ds", secs);
+ snprintf(p, ep - p, "%ds", secs);
return(result);
}