From ca313087c1715a0331a58c01ad104632d366f057 Mon Sep 17 00:00:00 2001 From: cinap_lenrek Date: Mon, 14 Mar 2022 18:45:27 +0000 Subject: [PATCH] ip(3): use flags instead of tag for 8 column route add/remove This avoids ipconfig having to explicitely specify the tag when we want to set route type, as the tag can be provided implicitely thru the "tag" command. --- sys/man/3/ip | 13 ++++++++----- sys/src/9/ip/ipifc.c | 1 - sys/src/9/ip/iproute.c | 26 +++++++++++++------------- sys/src/cmd/ip/ipconfig/ipconfig.h | 1 - sys/src/cmd/ip/ipconfig/ipv6.c | 2 +- sys/src/cmd/ip/ipconfig/main.c | 17 ++++------------- 6 files changed, 26 insertions(+), 34 deletions(-) diff --git a/sys/man/3/ip b/sys/man/3/ip index d502aeb54..c3836395f 100644 --- a/sys/man/3/ip +++ b/sys/man/3/ip @@ -191,7 +191,8 @@ does this to make remote machines appear to be connected to the local Ethernet. The .I trans -argument enables source address translation on interface. +argument enables source address translation +for packets routed to the interface. Adding the special null-address .B "0.0.0.0" or @@ -420,7 +421,7 @@ multicast route point-to-point route .TP .B t -network address translation on source +network source address translation .PD .PP The tag is an arbitrary, up to 4 character, string. It is normally used to @@ -450,14 +451,16 @@ with all subsequent routes added via this file descriptor. .TP .BI add\ "target mask nexthop interface source smask" .TP -.BI add\ "target mask nexthop tag interface source smask" +.BI add\ "target mask nexthop flags interface source smask" .TP .BI add\ "target mask nexthop flags tag interface source smask" Add the route to the table. If one already exists with the same target and mask, replace it. The .I interface can be given as either the interface number or a local -IP address on the desired interface. +IP address on the desired interface or as a +.B "-" +when unspecified. .TP .BI remove\ "target mask" .TP @@ -469,7 +472,7 @@ IP address on the desired interface. .TP .BI remove\ "target mask nexthop interface source smask" .TP -.BI remove\ "target mask nexthop tag interface source smask" +.BI remove\ "target mask nexthop flags interface source smask" .TP .BI remove\ "target mask nexthop flags tag interface source smask" Remove the matching route. diff --git a/sys/src/9/ip/ipifc.c b/sys/src/9/ip/ipifc.c index 6e03a6257..653fd1117 100644 --- a/sys/src/9/ip/ipifc.c +++ b/sys/src/9/ip/ipifc.c @@ -909,7 +909,6 @@ addselfcache(Fs *f, Ipifc *ifc, Iplifc *lifc, uchar *a, int type) int h; type |= (lifc->type & Rv4); - type &= ~Rtrans; qlock(f->self); if(waserror()){ diff --git a/sys/src/9/ip/iproute.c b/sys/src/9/ip/iproute.c index 4e3d57e44..c84a36070 100644 --- a/sys/src/9/ip/iproute.c +++ b/sys/src/9/ip/iproute.c @@ -1035,14 +1035,14 @@ routeread(Fs *f, char *p, ulong offset, int n) * 5 add addr mask gate ifc * 6 add addr mask gate src smask * 7 add addr mask gate ifc src smask - * 8 add addr mask gate tag ifc src smask + * 8 add addr mask gate type ifc src smask * 9 add addr mask gate type tag ifc src smask * 3 remove addr mask * 4 remove addr mask gate * 5 remove addr mask src smask * 6 remove addr mask gate src smask * 7 remove addr mask gate ifc src smask - * 8 remove addr mask gate tag ifc src smask + * 8 remove addr mask gate type ifc src smask * 9 remove addr mask gate type tag ifc src smask */ static Route @@ -1064,6 +1064,7 @@ parseroute(Fs *f, char **argv, int argc) if(argc < 3) error(Ebadctl); + if(parseipandmask(addr, mask, argv[1], argv[2]) == -1) error(Ebadip); @@ -1073,29 +1074,28 @@ parseroute(Fs *f, char **argv, int argc) if(parseip(gate, argv[3]) == -1) error(Ebadip); } + if(argc > 4 && (strcmp(argv[0], "add") != 0 || argc != 5)){ if(parseipandmask(src, smask, argv[argc-2], argv[argc-1]) == -1) error(Ebadip); } + if(argc == 5 && strcmp(argv[0], "add") == 0) ifc = findipifcstr(f, argv[4]); if(argc > 6) ifc = findipifcstr(f, argv[argc-3]); - if(argc > 7) - tag = argv[argc-4]; - if(argc > 8){ - if((type = parseroutetype(argv[argc-5])) < 0) - error(Ebadctl); - } else { - if(isv4(addr)) - type |= Rv4; - } + + if(argc > 7 && (type = parseroutetype(argv[4])) < 0) + error(Ebadctl); + if(isv4(addr)) + type |= Rv4; + + if(argc > 8) + tag = argv[5]; if(argc > 9) error(Ebadctl); if(type & Rv4){ - if(!isv4(addr)) - error(Ebadip); if(ipcmp(smask, IPnoaddr) != 0 && !isv4(src)) error(Ebadip); if(ipcmp(gate, IPnoaddr) != 0 && !isv4(gate)) diff --git a/sys/src/cmd/ip/ipconfig/ipconfig.h b/sys/src/cmd/ip/ipconfig/ipconfig.h index 9c4bdd922..9445e4965 100644 --- a/sys/src/cmd/ip/ipconfig/ipconfig.h +++ b/sys/src/cmd/ip/ipconfig/ipconfig.h @@ -116,7 +116,6 @@ void usage(void); int ip4cfg(void); void ipunconfig(void); -void setroutetag(char*); void adddefroute(uchar*, uchar*, uchar*, uchar*); void removedefroute(uchar*, uchar*, uchar*, uchar*); diff --git a/sys/src/cmd/ip/ipconfig/ipv6.c b/sys/src/cmd/ip/ipconfig/ipv6.c index b16beadf2..068da9693 100644 --- a/sys/src/cmd/ip/ipconfig/ipv6.c +++ b/sys/src/cmd/ip/ipconfig/ipv6.c @@ -1134,7 +1134,7 @@ startra6(void) void doipv6(int what) { - setroutetag("ra6"); + fprint(conf.rfd, "tag ra6"); switch (what) { default: sysfatal("unknown IPv6 verb"); diff --git a/sys/src/cmd/ip/ipconfig/main.c b/sys/src/cmd/ip/ipconfig/main.c index 560b759a1..c1c20b4c5 100644 --- a/sys/src/cmd/ip/ipconfig/main.c +++ b/sys/src/cmd/ip/ipconfig/main.c @@ -466,7 +466,7 @@ doadd(void) /* run dhcp if we need something */ if(dodhcp){ - setroutetag("dhcp"); + fprint(conf.rfd, "tag dhcp"); dhcpquery(!noconfig, Sselecting); } @@ -735,15 +735,6 @@ putndb(void) close(fd); } -static char *routetag = "none"; - -void -setroutetag(char *tag) -{ - routetag = tag; - fprint(conf.rfd, "tag %s", routetag); -} - static int issrcspec(uchar *src, uchar *smask) { @@ -764,9 +755,9 @@ routectl(char *cmd, uchar *dst, uchar *mask, uchar *gate, char *flags, uchar *ia fprint(conf.rfd, ctl, cmd, dst, mask, gate, ia, src, smask); return; } - ctl = "%s %I %M %I %s %s %I %I %M"; - DEBUG(ctl, cmd, dst, mask, gate, flags, routetag, ia, src, smask); - fprint(conf.rfd, ctl, cmd, dst, mask, gate, flags, routetag, ia, src, smask); + ctl = "%s %I %M %I %s %I %I %M"; + DEBUG(ctl, cmd, dst, mask, gate, flags, ia, src, smask); + fprint(conf.rfd, ctl, cmd, dst, mask, gate, flags, ia, src, smask); } static void