ref: 8f00b7096e4e5e370e89c0a594891c0235ae8857
parent: 7aac23b02baedfcaec2066da5b137fcbb97b3efe
author: cinap_lenrek <cinap_lenrek@felloff.net>
date: Sun Mar 17 01:44:55 EDT 2019
ip/ipconfig: use defaults for loopback - do not write /net/ndb for loopback medium unless -p is specified - use defmask() instead of hardcoded /64 for v6 to get correct /128 mask for ::1 - only do duplicate address detection on ethernet
--- a/sys/src/cmd/ip/ipconfig/dhcp.c
+++ b/sys/src/cmd/ip/ipconfig/dhcp.c
@@ -264,8 +264,7 @@
* leave everything we've learned somewhere that
* other procs can find it.
*/
- if(beprimary)
- putndb();
+ putndb();
refresh();
}
}
--- a/sys/src/cmd/ip/ipconfig/ipconfig.h
+++ b/sys/src/cmd/ip/ipconfig/ipconfig.h
@@ -98,7 +98,6 @@
extern Conf conf;
extern int myifc;
-extern int beprimary;
extern int noconfig;
extern int debug;
@@ -120,6 +119,7 @@
void adddefroute(uchar*, uchar*, uchar*, uchar*);
void removedefroute(uchar*, uchar*, uchar*, uchar*);
+int isether(void);
long jitter(void);
void catch(void*, char*);
int countaddrs(uchar *a, int len);
--- a/sys/src/cmd/ip/ipconfig/ipv6.c
+++ b/sys/src/cmd/ip/ipconfig/ipv6.c
@@ -151,12 +151,6 @@
0xff, 0, 0, 0,
};
-uchar v6defmask[IPaddrlen] = {
- 0xff, 0xff, 0xff, 0xff,
- 0xff, 0xff, 0xff, 0xff,
- 0, 0, 0, 0,
- 0, 0, 0, 0
-};
void
v6paraminit(Conf *cf)
@@ -366,7 +360,7 @@
if(!validip(conf.laddr) || isv4(conf.laddr))
return -1;
- tentative = dupl_disc;
+ tentative = dupl_disc && isether();
Again:
if(tentative)
@@ -376,7 +370,7 @@
n += snprint(buf+n, sizeof buf-n, " %I", conf.laddr);
if(!validip(conf.mask))
- ipmove(conf.mask, v6defmask);
+ ipmove(conf.mask, defmask(conf.laddr));
n += snprint(buf+n, sizeof buf-n, " %M", conf.mask);
if(validip(conf.raddr)){
n += snprint(buf+n, sizeof buf-n, " %I", conf.raddr);
@@ -770,8 +764,7 @@
if(noconfig)
continue;
- if(beprimary)
- putndb();
+ putndb();
refresh();
}
}
--- a/sys/src/cmd/ip/ipconfig/main.c
+++ b/sys/src/cmd/ip/ipconfig/main.c
@@ -211,11 +211,11 @@
switch(verb){
case Vether:
case Vgbe:
- case Vppp:
case Vloopback:
+ case Vpkt:
+ case Vppp:
case Vtorus:
case Vtree:
- case Vpkt:
conf.type = *argv++;
argc--;
if(argc > 0){
@@ -283,10 +283,15 @@
return -1;
}
-static int
+int
isether(void)
{
- return strcmp(conf.type, "ether") == 0 || strcmp(conf.type, "gbe") == 0;
+ switch(parseverb(conf.type)){
+ case Vether:
+ case Vgbe:
+ return 1;
+ }
+ return 0;
}
/* create a client id */
@@ -394,6 +399,9 @@
action = parseargs(argc, argv);
+ if(beprimary == -1 && (ipv6auto || parseverb(conf.type) == Vloopback))
+ beprimary = 0;
+
myifc = findifc(conf.mpoint, conf.dev);
if(myifc < 0) {
switch(action){
@@ -420,6 +428,7 @@
mkclientid();
if(dondbconfig){
dodhcp = 0;
+ beprimary = 0;
ndbconfig();
break;
}
@@ -457,7 +466,7 @@
dhcpquery(!noconfig, Sselecting);
}
- if(!validip(conf.laddr))
+ if(!validip(conf.laddr)){
if(rflag && dodhcp && !noconfig){
warning("couldn't determine ip address, retrying");
dhcpwatch(1);
@@ -464,7 +473,7 @@
return;
} else
sysfatal("no success with DHCP");
-
+ }
DEBUG("adding address %I %M on %s", conf.laddr, conf.mask, conf.dev);
if(noconfig)
return;
@@ -480,8 +489,7 @@
}
/* leave everything we've learned somewhere other procs can find it */
- if(beprimary && !dondbconfig && !ipv6auto)
- putndb();
+ putndb();
refresh();
}
@@ -660,6 +668,9 @@
Ndbtuple *t, *nt;
Ndb *db;
int fd;
+
+ if(beprimary == 0)
+ return;
p = buf;
e = buf + sizeof buf;