use new SIOCGIFINFO_IN6. random other cleanups.

This commit is contained in:
itojun 2002-05-29 08:04:39 +00:00
parent 5c1df51d53
commit b09ce00be9
2 changed files with 113 additions and 58 deletions

View File

@ -1,5 +1,5 @@
.\" $NetBSD: ndp.8,v 1.13 2002/02/08 01:38:51 ross Exp $
.\" $KAME: ndp.8,v 1.15 2001/02/08 07:17:03 itojun Exp $
.\" $NetBSD: ndp.8,v 1.14 2002/05/29 08:04:39 itojun Exp $
.\" $KAME: ndp.8,v 1.19 2002/05/29 07:34:01 itojun Exp $
.\"
.\" Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
.\" All rights reserved.
@ -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
@ -122,6 +151,7 @@ If additional arguments
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

View File

@ -1,5 +1,5 @@
/* $NetBSD: ndp.c,v 1.18 2001/11/08 09:45:34 itojun Exp $ */
/* $KAME: ndp.c,v 1.69 2001/07/23 14:46:31 itojun Exp $ */
/* $NetBSD: ndp.c,v 1.19 2002/05/29 08:04:40 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.
@ -87,17 +87,11 @@
#include <sys/queue.h>
#include <net/if.h>
#if defined(__FreeBSD__) && __FreeBSD__ >= 3
#include <net/if_var.h>
#endif /* __FreeBSD__ >= 3 */
#include <net/if_dl.h>
#include <net/if_types.h>
#include <net/route.h>
#include <netinet/in.h>
#ifndef __NetBSD__
#include <netinet/if_ether.h>
#endif
#include <netinet/icmp6.h>
#include <netinet6/in6_var.h>
@ -118,16 +112,12 @@
#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))
#define ADVANCE(x, n) (x += ROUNDUP((n)->sa_len))
static int pid;
static pid_t pid;
static int cflag;
static int nflag;
static int tflag;
@ -471,7 +461,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);
}
@ -544,14 +534,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
@ -579,9 +569,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;
@ -624,6 +614,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;
@ -642,9 +635,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);
@ -679,30 +680,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;
}
@ -713,7 +714,6 @@ again:;
warnx("failed to get neighbor information");
printf(" ");
}
putchar(' ');
/*
* other flags. R: router, P: proxy, W: ??
@ -725,6 +725,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)
@ -732,11 +733,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");
}
@ -785,9 +791,9 @@ ether_str(sdl)
if (sdl->sdl_alen) {
if (getnameinfo((struct sockaddr *)sdl, sdl->sdl_len,
hbuf, sizeof(hbuf), NULL, 0, NI_NUMERICHOST) != 0)
strcpy(hbuf, "<invalid>");
snprintf(hbuf, sizeof(hbuf), "<invalid>");
} else {
strcpy(hbuf, "(incomplete)");
snprintf(hbuf, sizeof(hbuf), "(incomplete)");
}
return(hbuf);
@ -856,8 +862,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 +948,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 +963,7 @@ ifinfo(argc, argv)
#undef SETFLAG
}
if (!ND.linkmtu) {
if (!ND.initialized) {
errx(1, "%s: not initialized yet", ifname);
/* NOTREACHED */
}
@ -988,8 +1002,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 +1053,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 +1097,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 +1126,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 +1175,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 +1197,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 +1277,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 +1315,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 +1372,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 +1508,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 +1518,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);
}