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
This commit is contained in:
cinap_lenrek 2019-03-17 05:44:55 +01:00
parent 7aac23b02b
commit 8f00b7096e
4 changed files with 24 additions and 21 deletions

View file

@ -264,7 +264,6 @@ dhcpwatch(int needconfig)
* leave everything we've learned somewhere that * leave everything we've learned somewhere that
* other procs can find it. * other procs can find it.
*/ */
if(beprimary)
putndb(); putndb();
refresh(); refresh();
} }

View file

@ -98,7 +98,6 @@ struct Ctl
extern Conf conf; extern Conf conf;
extern int myifc; extern int myifc;
extern int beprimary;
extern int noconfig; extern int noconfig;
extern int debug; extern int debug;
@ -120,6 +119,7 @@ void ipunconfig(void);
void adddefroute(uchar*, uchar*, uchar*, uchar*); void adddefroute(uchar*, uchar*, uchar*, uchar*);
void removedefroute(uchar*, uchar*, uchar*, uchar*); void removedefroute(uchar*, uchar*, uchar*, uchar*);
int isether(void);
long jitter(void); long jitter(void);
void catch(void*, char*); void catch(void*, char*);
int countaddrs(uchar *a, int len); int countaddrs(uchar *a, int len);

View file

@ -151,12 +151,6 @@ uchar v6solpfx[IPaddrlen] = {
0xff, 0, 0, 0, 0xff, 0, 0, 0,
}; };
uchar v6defmask[IPaddrlen] = {
0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff,
0, 0, 0, 0,
0, 0, 0, 0
};
void void
v6paraminit(Conf *cf) v6paraminit(Conf *cf)
@ -366,7 +360,7 @@ ip6cfg(void)
if(!validip(conf.laddr) || isv4(conf.laddr)) if(!validip(conf.laddr) || isv4(conf.laddr))
return -1; return -1;
tentative = dupl_disc; tentative = dupl_disc && isether();
Again: Again:
if(tentative) if(tentative)
@ -376,7 +370,7 @@ Again:
n += snprint(buf+n, sizeof buf-n, " %I", conf.laddr); n += snprint(buf+n, sizeof buf-n, " %I", conf.laddr);
if(!validip(conf.mask)) if(!validip(conf.mask))
ipmove(conf.mask, v6defmask); ipmove(conf.mask, defmask(conf.laddr));
n += snprint(buf+n, sizeof buf-n, " %M", conf.mask); n += snprint(buf+n, sizeof buf-n, " %M", conf.mask);
if(validip(conf.raddr)){ if(validip(conf.raddr)){
n += snprint(buf+n, sizeof buf-n, " %I", conf.raddr); n += snprint(buf+n, sizeof buf-n, " %I", conf.raddr);
@ -770,7 +764,6 @@ recvrahost(uchar buf[], int pktlen)
if(noconfig) if(noconfig)
continue; continue;
if(beprimary)
putndb(); putndb();
refresh(); refresh();
} }

View file

@ -211,11 +211,11 @@ parseargs(int argc, char **argv)
switch(verb){ switch(verb){
case Vether: case Vether:
case Vgbe: case Vgbe:
case Vppp:
case Vloopback: case Vloopback:
case Vpkt:
case Vppp:
case Vtorus: case Vtorus:
case Vtree: case Vtree:
case Vpkt:
conf.type = *argv++; conf.type = *argv++;
argc--; argc--;
if(argc > 0){ if(argc > 0){
@ -283,10 +283,15 @@ findifc(char *net, char *dev)
return -1; return -1;
} }
static int int
isether(void) 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 */ /* create a client id */
@ -394,6 +399,9 @@ main(int argc, char **argv)
action = parseargs(argc, argv); action = parseargs(argc, argv);
if(beprimary == -1 && (ipv6auto || parseverb(conf.type) == Vloopback))
beprimary = 0;
myifc = findifc(conf.mpoint, conf.dev); myifc = findifc(conf.mpoint, conf.dev);
if(myifc < 0) { if(myifc < 0) {
switch(action){ switch(action){
@ -420,6 +428,7 @@ main(int argc, char **argv)
mkclientid(); mkclientid();
if(dondbconfig){ if(dondbconfig){
dodhcp = 0; dodhcp = 0;
beprimary = 0;
ndbconfig(); ndbconfig();
break; break;
} }
@ -457,14 +466,14 @@ doadd(void)
dhcpquery(!noconfig, Sselecting); dhcpquery(!noconfig, Sselecting);
} }
if(!validip(conf.laddr)) if(!validip(conf.laddr)){
if(rflag && dodhcp && !noconfig){ if(rflag && dodhcp && !noconfig){
warning("couldn't determine ip address, retrying"); warning("couldn't determine ip address, retrying");
dhcpwatch(1); dhcpwatch(1);
return; return;
} else } else
sysfatal("no success with DHCP"); sysfatal("no success with DHCP");
}
DEBUG("adding address %I %M on %s", conf.laddr, conf.mask, conf.dev); DEBUG("adding address %I %M on %s", conf.laddr, conf.mask, conf.dev);
if(noconfig) if(noconfig)
return; return;
@ -480,7 +489,6 @@ doadd(void)
} }
/* leave everything we've learned somewhere other procs can find it */ /* leave everything we've learned somewhere other procs can find it */
if(beprimary && !dondbconfig && !ipv6auto)
putndb(); putndb();
refresh(); refresh();
} }
@ -661,6 +669,9 @@ putndb(void)
Ndb *db; Ndb *db;
int fd; int fd;
if(beprimary == 0)
return;
p = buf; p = buf;
e = buf + sizeof buf; e = buf + sizeof buf;
p = seprint(p, e, "ip=%I ipmask=%M ipgw=%I\n", p = seprint(p, e, "ip=%I ipmask=%M ipgw=%I\n",