summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--sbin/route/route.c33
-rw-r--r--sbin/route/show.c16
-rw-r--r--sbin/route/show.h4
3 files changed, 40 insertions, 13 deletions
diff --git a/sbin/route/route.c b/sbin/route/route.c
index 99e21794541..4e76e0a8892 100644
--- a/sbin/route/route.c
+++ b/sbin/route/route.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: route.c,v 1.150 2010/09/21 10:58:23 krw Exp $ */
+/* $OpenBSD: route.c,v 1.151 2010/10/11 11:45:00 claudio Exp $ */
/* $NetBSD: route.c,v 1.16 1996/04/15 18:27:05 cgd Exp $ */
/*
@@ -68,7 +68,7 @@ union sockunion so_dst, so_gate, so_mask, so_genmask, so_ifa, so_ifp, so_label,
typedef union sockunion *sup;
pid_t pid;
int rtm_addrs, s;
-int forcehost, forcenet, Fflag, nflag, af, qflag, tflag;
+int forcehost, forcenet, Fflag, nflag, af, qflag, tflag, Tflag;
int iflag, verbose, aflen = sizeof(struct sockaddr_in);
int locking, lockrest, debugonly;
u_long mpls_flags = MPLS_OP_LOCAL;
@@ -134,6 +134,7 @@ main(int argc, char **argv)
if (argc < 2)
usage(NULL);
+ tableid = getrtable();
while ((ch = getopt(argc, argv, "dnqtT:v")) != -1)
switch (ch) {
case 'n':
@@ -150,6 +151,7 @@ main(int argc, char **argv)
break;
case 'T':
gettable(optarg);
+ Tflag = 1;
break;
case 'd':
debugonly = 1;
@@ -180,6 +182,10 @@ main(int argc, char **argv)
s = socket(PF_ROUTE, SOCK_RAW, 0);
if (s == -1)
err(1, "socket");
+ /* force socket onto table user requested */
+ if (Tflag && setsockopt(s, AF_ROUTE, ROUTE_TABLEFILTER,
+ &tableid, sizeof(tableid)) == -1)
+ err(1, "setsockopt(ROUTE_TABLEFILTER)");
break;
}
switch (kw) {
@@ -688,7 +694,7 @@ show(int argc, char *argv[])
usage(*argv);
}
- p_rttables(af, tableid);
+ p_rttables(af, tableid, Tflag);
}
void
@@ -1046,7 +1052,10 @@ monitor(int argc, char *argv[])
if (setsockopt(s, AF_ROUTE, ROUTE_MSGFILTER, &filter,
sizeof(filter)) == -1)
- err(1, "setsockopt");
+ err(1, "setsockopt(ROUTE_MSGFILTER)");
+ if (Tflag && setsockopt(s, AF_ROUTE, ROUTE_TABLEFILTER, &tableid,
+ sizeof(tableid)) == -1)
+ err(1, "setsockopt(ROUTE_TABLEFILTER)");
verbose = 1;
if (debugonly) {
@@ -1617,11 +1626,25 @@ getlabel(char *name)
void
gettable(const char *s)
{
- const char *errstr;
+ const char *errstr;
+ struct rt_tableinfo info;
+ int mib[6];
+ size_t len;
tableid = strtonum(s, 0, RT_TABLEID_MAX, &errstr);
if (errstr)
errx(1, "invalid table id: %s", errstr);
+
+ mib[0] = CTL_NET;
+ mib[1] = AF_ROUTE;
+ mib[2] = 0;
+ mib[3] = 0;
+ mib[4] = NET_RT_TABLE;
+ mib[5] = tableid;
+
+ len = sizeof(info);
+ if (sysctl(mib, 6, &info, &len, NULL, 0) == -1)
+ err(1, "routing table %i", tableid);
}
int
diff --git a/sbin/route/show.c b/sbin/route/show.c
index 68e788cedba..3cd8c1eb039 100644
--- a/sbin/route/show.c
+++ b/sbin/route/show.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: show.c,v 1.88 2010/09/21 10:58:23 krw Exp $ */
+/* $OpenBSD: show.c,v 1.89 2010/10/11 11:45:00 claudio Exp $ */
/* $NetBSD: show.c,v 1.1 1996/11/15 18:01:41 gwr Exp $ */
/*
@@ -123,13 +123,13 @@ void index_pfk(struct sadb_msg *, void **);
* Print routing tables.
*/
void
-p_rttables(int af, u_int tableid)
+p_rttables(int af, u_int tableid, int hastable)
{
struct rt_msghdr *rtm;
struct sadb_msg *msg;
char *buf = NULL, *next, *lim = NULL;
size_t needed;
- int mib[7];
+ int mib[7], mcnt;
struct sockaddr *sa;
mib[0] = CTL_NET;
@@ -138,14 +138,18 @@ p_rttables(int af, u_int tableid)
mib[3] = af;
mib[4] = NET_RT_DUMP;
mib[5] = 0;
- mib[6] = tableid;
+ if (hastable) {
+ mib[6] = tableid;
+ mcnt = 7;
+ } else
+ mcnt = 6;
- if (sysctl(mib, 7, NULL, &needed, NULL, 0) < 0)
+ if (sysctl(mib, mcnt, NULL, &needed, NULL, 0) < 0)
err(1, "route-sysctl-estimate");
if (needed > 0) {
if ((buf = malloc(needed)) == 0)
err(1, NULL);
- if (sysctl(mib, 7, buf, &needed, NULL, 0) < 0)
+ if (sysctl(mib, mcnt, buf, &needed, NULL, 0) < 0)
err(1, "sysctl of routing table");
lim = buf + needed;
}
diff --git a/sbin/route/show.h b/sbin/route/show.h
index 95f48800503..9edfb545311 100644
--- a/sbin/route/show.h
+++ b/sbin/route/show.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: show.h,v 1.8 2010/09/21 10:58:23 krw Exp $ */
+/* $OpenBSD: show.h,v 1.9 2010/10/11 11:45:00 claudio Exp $ */
/*
* Copyright (c) 2004 Claudio Jeker <claudio@openbsd.org>
@@ -28,7 +28,7 @@ union sockunion {
struct sockaddr_mpls smpls;
};
-void p_rttables(int, u_int);
+void p_rttables(int, u_int, int);
char *routename(struct sockaddr *);
char *netname(struct sockaddr *, struct sockaddr *);
char *mpls_op(u_int32_t);