Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/netbsd-7]: src Pull up following revision(s) (requested by prlw1 in tick...
details: https://anonhg.NetBSD.org/src/rev/4df08524306f
branches: netbsd-7
changeset: 798799:4df08524306f
user: martin <martin%NetBSD.org@localhost>
date: Thu Jan 08 11:01:01 2015 +0000
description:
Pull up following revision(s) (requested by prlw1 in ticket #390):
usr.bin/netstat/mroute.c: revision 1.25
usr.bin/netstat/Makefile: revision 1.40
sbin/route/prog_ops.h: revision 1.3
sbin/route/rtutil.c: revision 1.1
sbin/route/rtutil.h: revision 1.1
usr.bin/netstat/mroute6.c: revision 1.15
sbin/route/extern.h: revision 1.15
usr.bin/netstat/show.c: file removal
usr.bin/netstat/main.c: revision 1.93
usr.bin/netstat/route.c: revision 1.83
usr.bin/netstat/netstat.h: revision 1.51
distrib/utils/x_route/Makefile: revision 1.18
sbin/route/show.c: revision 1.46
usr.bin/netstat/if.c: revision 1.80
sbin/route/route.c: revision 1.145
sbin/route/Makefile: revision 1.26
Factor out the netstat route printing code and use it here. There is no
point in having 2 different copies; fixes PR/49371
diffstat:
distrib/utils/x_route/Makefile | 4 +-
sbin/route/Makefile | 4 +-
sbin/route/extern.h | 8 +-
sbin/route/prog_ops.h | 8 +-
sbin/route/route.c | 459 ++---------------------
sbin/route/rtutil.c | 786 +++++++++++++++++++++++++++++++++++++++++
sbin/route/rtutil.h | 58 +++
sbin/route/show.c | 299 +---------------
usr.bin/netstat/Makefile | 10 +-
usr.bin/netstat/if.c | 15 +-
usr.bin/netstat/main.c | 9 +-
usr.bin/netstat/mroute.c | 13 +-
usr.bin/netstat/mroute6.c | 7 +-
usr.bin/netstat/netstat.h | 22 +-
usr.bin/netstat/route.c | 43 +-
usr.bin/netstat/show.c | 727 -------------------------------------
16 files changed, 953 insertions(+), 1519 deletions(-)
diffs (truncated from 2965 to 300 lines):
diff -r 20df2bf46c5c -r 4df08524306f distrib/utils/x_route/Makefile
--- a/distrib/utils/x_route/Makefile Thu Jan 08 08:27:27 2015 +0000
+++ b/distrib/utils/x_route/Makefile Thu Jan 08 11:01:01 2015 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: Makefile,v 1.17 2010/12/13 19:19:10 pooka Exp $
+# $NetBSD: Makefile,v 1.17.26.1 2015/01/08 11:01:01 martin Exp $
# @(#)Makefile 8.1 (Berkeley) 6/5/93
SRCDIR= ${.CURDIR}/../../../sbin/route
@@ -8,7 +8,7 @@
.include <bsd.own.mk>
-SRCS= route.c show.c keywords.c
+SRCS= keywords.c route.c rtutil.c show.c
CPPFLAGS+= -DSMALL -I${SRCDIR} -DCRUNCHOPS
.if defined(SMALLPROG_INET6) && (${USE_INET6} != "no")
diff -r 20df2bf46c5c -r 4df08524306f sbin/route/Makefile
--- a/sbin/route/Makefile Thu Jan 08 08:27:27 2015 +0000
+++ b/sbin/route/Makefile Thu Jan 08 11:01:01 2015 +0000
@@ -1,11 +1,11 @@
-# $NetBSD: Makefile,v 1.25 2010/12/13 17:39:47 pooka Exp $
+# $NetBSD: Makefile,v 1.25.24.1 2015/01/08 11:01:01 martin Exp $
# @(#)Makefile 8.1 (Berkeley) 6/5/93
.include <bsd.own.mk>
RUMPPRG=route
MAN= route.8
-SRCS= route.c show.c keywords.c
+SRCS= route.c show.c keywords.c rtutil.c
.if (${USE_INET6} != "no")
CPPFLAGS+=-DINET6
diff -r 20df2bf46c5c -r 4df08524306f sbin/route/extern.h
--- a/sbin/route/extern.h Thu Jan 08 08:27:27 2015 +0000
+++ b/sbin/route/extern.h Thu Jan 08 11:01:01 2015 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: extern.h,v 1.14 2009/10/21 01:07:46 snj Exp $ */
+/* $NetBSD: extern.h,v 1.14.24.1 2015/01/08 11:01:01 martin Exp $ */
/*
* Copyright (c) 1997 Christos Zoulas. All rights reserved.
@@ -30,15 +30,11 @@
void parse_show_opts(int, char * const *, int *, int *, const char **, bool);
/* show.c */
-void show(int, char * const *);
+void show(int, char * const *, int);
/* route.c */
extern int nflag, Sflag;
#define NOTDEFSTRING "0.0.0.0/xxx.xxx.xxx.xxx\0"
int keyword(const char *);
-int netmask_length(struct sockaddr *, int);
-char *netmask_string(const struct sockaddr *, int, int);
-const char *routename(const struct sockaddr *, struct sockaddr *, int);
-const char *netname(const struct sockaddr *, struct sockaddr *);
const char *ns_print(struct sockaddr_ns *);
void usage(const char *)__attribute__((__noreturn__));
diff -r 20df2bf46c5c -r 4df08524306f sbin/route/prog_ops.h
--- a/sbin/route/prog_ops.h Thu Jan 08 08:27:27 2015 +0000
+++ b/sbin/route/prog_ops.h Thu Jan 08 11:01:01 2015 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: prog_ops.h,v 1.2 2010/12/13 19:19:10 pooka Exp $ */
+/* $NetBSD: prog_ops.h,v 1.2.24.1 2015/01/08 11:01:01 martin Exp $ */
/*
* Copyright (c) 2010 The NetBSD Foundation, Inc.
@@ -32,9 +32,13 @@
#include <sys/types.h>
#ifndef CRUNCHOPS
+/* XXX: Keep same order with netstat! */
struct prog_ops {
int (*op_init)(void);
+ int (*op_sysctl)(const int *, u_int, void *, size_t *,
+ const void *, size_t);
+
int (*op_socket)(int, int, int);
int (*op_open)(const char *, int, ...);
pid_t (*op_getpid)(void);
@@ -42,8 +46,6 @@
ssize_t (*op_read)(int, void *, size_t);
ssize_t (*op_write)(int, const void *, size_t);
- int (*op_sysctl)(const int *, u_int, void *, size_t *,
- const void *, size_t);
int (*op_shutdown)(int, int);
};
diff -r 20df2bf46c5c -r 4df08524306f sbin/route/route.c
--- a/sbin/route/route.c Thu Jan 08 08:27:27 2015 +0000
+++ b/sbin/route/route.c Thu Jan 08 11:01:01 2015 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: route.c,v 1.144.4.1 2014/12/29 17:27:28 martin Exp $ */
+/* $NetBSD: route.c,v 1.144.4.2 2015/01/08 11:01:01 martin Exp $ */
/*
* Copyright (c) 1983, 1989, 1991, 1993
@@ -39,7 +39,7 @@
#if 0
static char sccsid[] = "@(#)route.c 8.6 (Berkeley) 4/28/95";
#else
-__RCSID("$NetBSD: route.c,v 1.144.4.1 2014/12/29 17:27:28 martin Exp $");
+__RCSID("$NetBSD: route.c,v 1.144.4.2 2015/01/08 11:01:01 martin Exp $");
#endif
#endif /* not lint */
@@ -73,6 +73,7 @@
#include "keywords.h"
#include "extern.h"
#include "prog_ops.h"
+#include "rtutil.h"
union sockunion {
struct sockaddr sa;
@@ -95,7 +96,6 @@
*so_ifp, *so_mpls;
};
-static char *any_ntoa(const struct sockaddr *);
static const char *route_strerror(int);
static void set_metric(const char *, int);
static int newroute(int, char *const *);
@@ -105,6 +105,7 @@
#endif
static int getaddr(int, const char *, struct hostent **, struct sou *);
static int flushroutes(int, char *const [], int);
+static char *netmask_string(const struct sockaddr *, int, int);
static int prefixlen(const char *, struct sou *);
#ifndef SMALL
static void interfaces(void);
@@ -168,7 +169,7 @@
doflush = 1;
break;
case 'n':
- nflag = 1;
+ nflag = RT_NFLAG;
break;
case 'q':
qflag = 1;
@@ -224,7 +225,7 @@
return newroute(argc, argv);
case K_SHOW:
- show(argc, argv);
+ show(argc, argv, nflag);
return 0;
#ifndef SMALL
@@ -245,6 +246,36 @@
}
}
+static char *
+netmask_string(const struct sockaddr *mask, int len, int family)
+{
+ static char smask[INET6_ADDRSTRLEN];
+ struct sockaddr_in nsin;
+ struct sockaddr_in6 nsin6;
+
+ if (len >= 0)
+ snprintf(smask, sizeof(smask), "%d", len);
+ else {
+ switch (family) {
+ case AF_INET:
+ memset(&nsin, 0, sizeof(nsin));
+ memcpy(&nsin, mask, mask->sa_len);
+ snprintf(smask, sizeof(smask), "%s",
+ inet_ntoa(nsin.sin_addr));
+ break;
+ case AF_INET6:
+ memset(&nsin6, 0, sizeof(nsin6));
+ memcpy(&nsin6, mask, mask->sa_len);
+ inet_ntop(family, &nsin6.sin6_addr, smask,
+ sizeof(smask));
+ break;
+ default:
+ snprintf(smask, sizeof(smask), "%s", any_ntoa(mask));
+ }
+ }
+
+ return smask;
+}
/*
* Purge all entries in the routing tables not
* associated with network interfaces.
@@ -320,12 +351,10 @@
if (verbose)
print_rtmsg(rtm, rlen);
else {
- (void)printf("%-20.20s ",
- routename(sa, NULL, rtm->rtm_flags));
+ (void)printf("%-20.20s ", netname(sa, NULL, nflag));
sa = (struct sockaddr *)(RT_ROUNDUP(sa->sa_len) +
(char *)sa);
- (void)printf("%-20.20s ",
- routename(sa, NULL, RTF_HOST));
+ (void)printf("%-20.20s ", routename(sa, nflag));
(void)printf("done\n");
}
}
@@ -333,402 +362,6 @@
return 0;
}
-
-static char hexlist[] = "0123456789abcdef";
-
-static char *
-any_ntoa(const struct sockaddr *sa)
-{
- static char obuf[3 * 256];
- const char *in;
- char *out;
- int len;
-
-#if __GNUC__ > 2
- len = sa->sa_len - offsetof(struct sockaddr, sa_data);
-#else
- len = sa->sa_len - ((struct sockaddr*)&sa->sa_data - sa);
-#endif
- in = sa->sa_data;
- out = obuf;
-
- do {
- *out++ = hexlist[(*in >> 4) & 15];
- *out++ = hexlist[(*in++) & 15];
- *out++ = '.';
- } while (--len > 0);
- out[-1] = '\0';
- return obuf;
-}
-
-int
-netmask_length(struct sockaddr *nm, int family)
-{
- static int
- /* number of bits in a nibble */
- _t[] = { 0,1,1,2,1,2,2,3,1,2,2,3,2,3,3,4 },
- /* good nibbles are 1111, 1110, 1100, 1000, 0000 */
- _g[] = { 1,0,0,0,0,0,0,0,1,0,0,0,1,0,1,1 };
- int mask, good, zeroes, maskbytes, bit, i;
- unsigned char *maskdata;
-
- if (nm == NULL)
- return 0;
-
- mask = 0;
- good = 1;
- zeroes = 0;
-
- switch (family) {
- case AF_INET: {
- struct sockaddr_in *nsin = (struct sockaddr_in *)nm;
- maskdata = (unsigned char *)&nsin->sin_addr;
- maskbytes = nsin->sin_len -
- ((caddr_t)&nsin->sin_addr - (caddr_t)nsin);
- break;
- }
- case AF_INET6: {
- struct sockaddr_in6 *sin6 = (struct sockaddr_in6 *)nm;
- maskdata = (unsigned char *)&sin6->sin6_addr;
- maskbytes = sin6->sin6_len -
- ((caddr_t)&sin6->sin6_addr - (caddr_t)sin6);
- break;
- }
- default:
- return 0;
- }
-
- /*
- * Count the bits in the nibbles of the mask, and marking the
- * netmask as not good (or at best, non-standard and very
- * discouraged, in the case of AF_INET) if we find either of
- * a nibble with non-contiguous bits, or a non-zero nibble
- * after we've found a zero nibble.
- */
- for (i = 0; i < maskbytes; i++) {
- /* high nibble */
- mask += bit = _t[maskdata[i] >> 4];
- good &= _g[maskdata[i] >> 4];
- if (zeroes && bit)
- good = 0;
- if (bit == 0)
- zeroes = 1;
- /* low nibble */
- mask += bit = _t[maskdata[i] & 0xf];
- good &= _g[maskdata[i] & 0xf];
- if (zeroes && bit)
- good = 0;
- if (bit == 0)
- zeroes = 1;
- }
-
- /*
- * Always return the number of bits found, but as a negative
Home |
Main Index |
Thread Index |
Old Index