Retire most of the classful network behaviour of netstat -r output, for IPv4.

Without -n, we now only print a "network name" without the prefix length
 under the following conditions:
  1) the network address and mask matches a classful network prefix;
  2) getnetbyaddr(3) returns a network name for this network address.

 With -n, we unconditionally print the full unabbreviated CIDR network
 prefix in the form "a.b.c.d/p". 0.0.0.0/0 is still printed as "default".

This change is in preparation for changes such as equal-cost multipath, and
to more generally assist operational deployment of FreeBSD as a modern IPv4
router. There are currently no plans to backport this change.

Discussed on:	freebsd-net
This commit is contained in:
Bruce M Simpson 2007-02-14 14:17:01 +00:00
parent 46a1d9bfe8
commit d092c06c3a
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=166711
2 changed files with 20 additions and 52 deletions

View File

@ -21,6 +21,17 @@ NOTE TO PEOPLE WHO THINK THAT FreeBSD 7.x IS SLOW:
developers choose to disable these features on build machines developers choose to disable these features on build machines
to maximize performance. to maximize performance.
20070214:
The output of netstat -r has changed. Without -n, we now only
print a "network name" without the prefix length if the network
address and mask exactly match a Class A/B/C network, and an entry
exists in the nsswitch "networks" map.
With -n, we print the full unabbreviated CIDR network prefix in
the form "a.b.c.d/p". 0.0.0.0/0 is always printed as "default".
This change is in preparation for changes such as equal-cost
multipath, and to more generally assist operational deployment
of FreeBSD as a modern IPv4 router.
20070210: 20070210:
PIM has been turned on by default in the IPv4 multicast PIM has been turned on by default in the IPv4 multicast
routing code. The kernel option 'PIM' has now been removed. routing code. The kernel option 'PIM' has now been removed.

View File

@ -134,7 +134,6 @@ static const char *fmt_sockaddr (struct sockaddr *sa, struct sockaddr *mask,
static void p_flags (int, const char *); static void p_flags (int, const char *);
static const char *fmt_flags(int f); static const char *fmt_flags(int f);
static void p_rtentry (struct rtentry *); static void p_rtentry (struct rtentry *);
static u_long forgemask (u_long);
static void domask (char *, u_long, u_long); static void domask (char *, u_long, u_long);
/* /*
@ -801,26 +800,18 @@ routename(u_long in)
return (line); return (line);
} }
static u_long #define NSHIFT(m) ( \
forgemask(u_long a) (m) == IN_CLASSA_NET ? IN_CLASSA_NSHIFT : \
{ (m) == IN_CLASSB_NET ? IN_CLASSB_NSHIFT : \
u_long m; (m) == IN_CLASSC_NET ? IN_CLASSC_NSHIFT : \
0)
if (IN_CLASSA(a))
m = IN_CLASSA_NET;
else if (IN_CLASSB(a))
m = IN_CLASSB_NET;
else
m = IN_CLASSC_NET;
return (m);
}
static void static void
domask(char *dst, u_long addr, u_long mask) domask(char *dst, u_long addr, u_long mask)
{ {
int b, i; int b, i;
if (!mask || (forgemask(addr) == mask)) { if (mask == 0 || (!numeric_addr && NSHIFT(mask) != 0)) {
*dst = '\0'; *dst = '\0';
return; return;
} }
@ -853,62 +844,28 @@ netname(u_long in, u_long mask)
char *cp = 0; char *cp = 0;
static char line[MAXHOSTNAMELEN]; static char line[MAXHOSTNAMELEN];
struct netent *np = 0; struct netent *np = 0;
u_long dmask;
u_long i; u_long i;
#define NSHIFT(m) ( \
(m) == IN_CLASSA_NET ? IN_CLASSA_NSHIFT : \
(m) == IN_CLASSB_NET ? IN_CLASSB_NSHIFT : \
(m) == IN_CLASSC_NET ? IN_CLASSC_NSHIFT : \
0)
i = ntohl(in); i = ntohl(in);
dmask = forgemask(i);
if (!numeric_addr && i) { if (!numeric_addr && i) {
np = getnetbyaddr(i >> NSHIFT(mask), AF_INET); np = getnetbyaddr(i >> NSHIFT(mask), AF_INET);
if (np == NULL && mask == 0)
np = getnetbyaddr(i >> NSHIFT(dmask), AF_INET);
if (np != NULL) { if (np != NULL) {
cp = np->n_name; cp = np->n_name;
trimdomain(cp, strlen(cp)); trimdomain(cp, strlen(cp));
} }
} }
#undef NSHIFT
if (cp != NULL) { if (cp != NULL) {
strncpy(line, cp, sizeof(line) - 1); strncpy(line, cp, sizeof(line) - 1);
line[sizeof(line) - 1] = '\0'; line[sizeof(line) - 1] = '\0';
} else { } else {
switch (dmask) { inet_ntop(AF_INET, (char *)&in, line, sizeof(line) - 1);
case IN_CLASSA_NET:
if ((i & IN_CLASSA_HOST) == 0) {
sprintf(line, "%lu", C(i >> 24));
break;
}
/* FALLTHROUGH */
case IN_CLASSB_NET:
if ((i & IN_CLASSB_HOST) == 0) {
sprintf(line, "%lu.%lu",
C(i >> 24), C(i >> 16));
break;
}
/* FALLTHROUGH */
case IN_CLASSC_NET:
if ((i & IN_CLASSC_HOST) == 0) {
sprintf(line, "%lu.%lu.%lu",
C(i >> 24), C(i >> 16), C(i >> 8));
break;
}
/* FALLTHROUGH */
default:
sprintf(line, "%lu.%lu.%lu.%lu",
C(i >> 24), C(i >> 16), C(i >> 8), C(i));
break;
}
} }
domask(line + strlen(line), i, mask); domask(line + strlen(line), i, mask);
return (line); return (line);
} }
#undef NSHIFT
#ifdef INET6 #ifdef INET6
const char * const char *
netname6(struct sockaddr_in6 *sa6, struct in6_addr *mask) netname6(struct sockaddr_in6 *sa6, struct in6_addr *mask)