diff options
author | Martin Pieuchot <mpi@cvs.openbsd.org> | 2015-07-18 21:26:04 +0000 |
---|---|---|
committer | Martin Pieuchot <mpi@cvs.openbsd.org> | 2015-07-18 21:26:04 +0000 |
commit | 16f341da31a7b7362018cc9d409859fa69c42ce5 (patch) | |
tree | 54b330492b16465ab3f3d86e753be69cca6174c1 /sbin | |
parent | 28fbde7fb45950153e1735d39139081002753067 (diff) |
Make all commands accepting the "-priority" switch recognize aliases
for common priorities.
ok deraadt@, claudio@
Diffstat (limited to 'sbin')
-rw-r--r-- | sbin/route/route.c | 91 |
1 files changed, 45 insertions, 46 deletions
diff --git a/sbin/route/route.c b/sbin/route/route.c index 4983b89139d..36e7e69bf4c 100644 --- a/sbin/route/route.c +++ b/sbin/route/route.c @@ -1,4 +1,4 @@ -/* $OpenBSD: route.c,v 1.175 2015/07/18 00:05:02 phessler Exp $ */ +/* $OpenBSD: route.c,v 1.176 2015/07/18 21:26:03 mpi Exp $ */ /* $NetBSD: route.c,v 1.16 1996/04/15 18:27:05 cgd Exp $ */ /* @@ -85,7 +85,8 @@ void monitor(int, char *[]); int prefixlen(char *); void sockaddr(char *, struct sockaddr *); void sodump(sup, char *); -char *priorityname(u_int8_t); +char *priorityname(uint8_t); +uint8_t getpriority(char *); void print_getmsg(struct rt_msghdr *, int); const char *get_linkstate(int, int); void print_rtmsg(struct rt_msghdr *, int); @@ -96,7 +97,7 @@ void mask_addr(union sockunion *, union sockunion *, int); int inet6_makenetandmask(struct sockaddr_in6 *, char *); int getaddr(int, char *, struct hostent **); void getmplslabel(char *, int); -int rtmsg(int, int, int, u_char); +int rtmsg(int, int, int, uint8_t); __dead void usage(char *); void set_metric(char *, int); void inet_makenetandmask(u_int32_t, struct sockaddr_in *, int); @@ -230,13 +231,12 @@ main(int argc, char **argv) void flushroutes(int argc, char **argv) { - const char *errstr; size_t needed; int mib[7], rlen, seqno; char *buf = NULL, *next, *lim = NULL; struct rt_msghdr *rtm; struct sockaddr *sa; - u_char prio = 0; + uint8_t prio = 0; unsigned int ifindex = 0; if (uid) @@ -268,10 +268,7 @@ flushroutes(int argc, char **argv) case K_PRIORITY: if (!--argc) usage(1+*argv); - prio = strtonum(*++argv, 0, RTP_MAX, &errstr); - if (errstr) - errx(1, "priority is %s: %s", errstr, - *argv); + prio = getpriority(*++argv); break; default: usage(*argv); @@ -403,12 +400,11 @@ set_metric(char *value, int key) int newroute(int argc, char **argv) { - const char *errstr; char *cmd, *dest = "", *gateway = "", *error; int ishost = 0, ret = 0, attempts, oerrno, flags = RTF_STATIC; int fmask = 0; int key; - u_char prio = 0; + uint8_t prio = 0; struct hostent *hp = NULL; if (uid) @@ -581,10 +577,7 @@ newroute(int argc, char **argv) case K_PRIORITY: if (!--argc) usage(1+*argv); - prio = strtonum(*++argv, 0, RTP_MAX, &errstr); - if (errstr) - errx(1, "priority is %s: %s", errstr, - *argv); + prio = getpriority(*++argv); break; default: usage(1+*argv); @@ -663,8 +656,6 @@ show(int argc, char *argv[]) { int af = 0; char prio = 0; - char *priostr; - const char *errstr; while (--argc > 0) { if (**(++argv)== '-') @@ -692,33 +683,7 @@ show(int argc, char *argv[]) case K_PRIORITY: if (!--argc) usage(1+*argv); - priostr = *++argv; - switch (keyword(priostr)) { - case K_LOCAL: - prio = RTP_LOCAL; - break; - case K_CONNECTED: - prio = RTP_CONNECTED; - break; - case K_STATIC: - prio = RTP_STATIC; - break; - case K_OSPF: - prio = RTP_OSPF; - break; - case K_RIP: - prio = RTP_RIP; - break; - case K_BGP: - prio = RTP_BGP; - break; - default: - prio = strtonum(priostr, -RTP_MAX, RTP_MAX, - &errstr); - if (errstr) - errx(1, "priority is %s: %s", - errstr, *argv); - } + prio = getpriority(*++argv); break; default: usage(*argv); @@ -1146,7 +1111,7 @@ struct { } m_rtmsg; int -rtmsg(int cmd, int flags, int fmask, u_char prio) +rtmsg(int cmd, int flags, int fmask, uint8_t prio) { static int seq; char *cp = m_rtmsg.m_space; @@ -1379,7 +1344,7 @@ print_rtmsg(struct rt_msghdr *rtm, int msglen) } char * -priorityname(u_int8_t prio) +priorityname(uint8_t prio) { switch (prio) { case RTP_NONE: @@ -1405,6 +1370,40 @@ priorityname(u_int8_t prio) } } +uint8_t +getpriority(char *priostr) +{ + const char *errstr; + uint8_t prio; + + switch (keyword(priostr)) { + case K_LOCAL: + prio = RTP_LOCAL; + break; + case K_CONNECTED: + prio = RTP_CONNECTED; + break; + case K_STATIC: + prio = RTP_STATIC; + break; + case K_OSPF: + prio = RTP_OSPF; + break; + case K_RIP: + prio = RTP_RIP; + break; + case K_BGP: + prio = RTP_BGP; + break; + default: + prio = strtonum(priostr, -RTP_MAX, RTP_MAX, &errstr); + if (errstr) + errx(1, "priority is %s: %s", errstr, priostr); + } + + return (prio); +} + void print_getmsg(struct rt_msghdr *rtm, int msglen) { |