summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorClaudio Jeker <claudio@cvs.openbsd.org>2012-09-23 13:46:30 +0000
committerClaudio Jeker <claudio@cvs.openbsd.org>2012-09-23 13:46:30 +0000
commit96e3ebb906b3f6eb2b8671c428a41c82b4a617ab (patch)
tree03a2fc856da3990749237b9adff62c7569a20930
parent2c725639fbf3fbc5db690be9a0af259c52b534b5 (diff)
Allow route -T 3 add to create a table even if the table does not exist
yet. This is the only way to create alternate routing tables. Reminded by and OK jsg@
-rw-r--r--sbin/route/route.c20
1 files changed, 14 insertions, 6 deletions
diff --git a/sbin/route/route.c b/sbin/route/route.c
index 90fcfc57cd6..c14f17cdc48 100644
--- a/sbin/route/route.c
+++ b/sbin/route/route.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: route.c,v 1.158 2012/08/14 08:49:56 chl Exp $ */
+/* $OpenBSD: route.c,v 1.159 2012/09/23 13:46:29 claudio Exp $ */
/* $NetBSD: route.c,v 1.16 1996/04/15 18:27:05 cgd Exp $ */
/*
@@ -102,7 +102,7 @@ void set_metric(char *, int);
void inet_makenetandmask(u_int32_t, struct sockaddr_in *, int);
void interfaces(void);
void getlabel(char *);
-void gettable(const char *);
+int gettable(const char *);
int rdomain(int, char **);
__dead void
@@ -130,6 +130,7 @@ main(int argc, char **argv)
int ch;
int rval = 0;
int kw;
+ int Terr = 0;
if (argc < 2)
usage(NULL);
@@ -150,7 +151,7 @@ main(int argc, char **argv)
tflag = 1;
break;
case 'T':
- gettable(optarg);
+ Terr = gettable(optarg);
Tflag = 1;
break;
case 'd':
@@ -169,6 +170,10 @@ main(int argc, char **argv)
usage(NULL);
kw = keyword(*argv);
+ if (Tflag && Terr != 0 && kw != K_ADD) {
+ errno = Terr;
+ err(1, "routing table %i", tableid);
+ }
switch (kw) {
case K_EXEC:
break;
@@ -183,7 +188,8 @@ main(int argc, char **argv)
if (s == -1)
err(1, "socket");
/* force socket onto table user requested */
- if (Tflag && setsockopt(s, AF_ROUTE, ROUTE_TABLEFILTER,
+ if (Tflag == 1 && Terr == 0 &&
+ setsockopt(s, AF_ROUTE, ROUTE_TABLEFILTER,
&tableid, sizeof(tableid)) == -1)
err(1, "setsockopt(ROUTE_TABLEFILTER)");
break;
@@ -1651,7 +1657,7 @@ getlabel(char *name)
rtm_addrs |= RTA_LABEL;
}
-void
+int
gettable(const char *s)
{
const char *errstr;
@@ -1672,7 +1678,9 @@ gettable(const char *s)
len = sizeof(info);
if (sysctl(mib, 6, &info, &len, NULL, 0) == -1)
- err(1, "routing table %i", tableid);
+ return (errno);
+ else
+ return (0);
}
int