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.
This commit is contained in:
parent
d4e89fe76a
commit
ca313087c1
6 changed files with 26 additions and 34 deletions
13
sys/man/3/ip
13
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.
|
||||
|
|
|
@ -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()){
|
||||
|
|
|
@ -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))
|
||||
|
|
|
@ -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*);
|
||||
|
||||
|
|
|
@ -1134,7 +1134,7 @@ startra6(void)
|
|||
void
|
||||
doipv6(int what)
|
||||
{
|
||||
setroutetag("ra6");
|
||||
fprint(conf.rfd, "tag ra6");
|
||||
switch (what) {
|
||||
default:
|
||||
sysfatal("unknown IPv6 verb");
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue