ref: ca313087c1715a0331a58c01ad104632d366f057
parent: d4e89fe76a24ab08aae50f0918cf3e65efbc779b
author: cinap_lenrek <cinap_lenrek@felloff.net>
date: Mon Mar 14 14:45:27 EDT 2022
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.
--- a/sys/man/3/ip
+++ b/sys/man/3/ip
@@ -191,7 +191,8 @@
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 @@
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,7 +451,7 @@
.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
@@ -457,7 +458,9 @@
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 @@
.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.
--- a/sys/src/9/ip/ipifc.c
+++ b/sys/src/9/ip/ipifc.c
@@ -909,7 +909,6 @@
int h;
type |= (lifc->type & Rv4);
- type &= ~Rtrans;
qlock(f->self);
if(waserror()){
--- a/sys/src/9/ip/iproute.c
+++ b/sys/src/9/ip/iproute.c
@@ -1035,7 +1035,7 @@
* 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
@@ -1042,7 +1042,7 @@
* 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 @@
if(argc < 3)
error(Ebadctl);
+
if(parseipandmask(addr, mask, argv[1], argv[2]) == -1)
error(Ebadip);
@@ -1073,29 +1074,28 @@
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))
--- a/sys/src/cmd/ip/ipconfig/ipconfig.h
+++ b/sys/src/cmd/ip/ipconfig/ipconfig.h
@@ -116,7 +116,6 @@
int ip4cfg(void);
void ipunconfig(void);
-void setroutetag(char*);
void adddefroute(uchar*, uchar*, uchar*, uchar*);
void removedefroute(uchar*, uchar*, uchar*, uchar*);
--- a/sys/src/cmd/ip/ipconfig/ipv6.c
+++ b/sys/src/cmd/ip/ipconfig/ipv6.c
@@ -1134,7 +1134,7 @@
void
doipv6(int what)
{
- setroutetag("ra6");
+ fprint(conf.rfd, "tag ra6");
switch (what) {
default:
sysfatal("unknown IPv6 verb");
--- a/sys/src/cmd/ip/ipconfig/main.c
+++ b/sys/src/cmd/ip/ipconfig/main.c
@@ -466,7 +466,7 @@
/* run dhcp if we need something */
if(dodhcp){
- setroutetag("dhcp");
+ fprint(conf.rfd, "tag dhcp");
dhcpquery(!noconfig, Sselecting);
}
@@ -735,15 +735,6 @@
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 @@
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