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

View file

@ -98,7 +98,6 @@ struct Ctl
extern Conf conf;
extern int myifc;
extern int beprimary;
extern int noconfig;
extern int debug;
@ -120,6 +119,7 @@ void ipunconfig(void);
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);

View file

@ -151,12 +151,6 @@ uchar v6solpfx[IPaddrlen] = {
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 @@ ip6cfg(void)
if(!validip(conf.laddr) || isv4(conf.laddr))
return -1;
tentative = dupl_disc;
tentative = dupl_disc && isether();
Again:
if(tentative)
@ -376,7 +370,7 @@ Again:
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 @@ recvrahost(uchar buf[], int pktlen)
if(noconfig)
continue;
if(beprimary)
putndb();
putndb();
refresh();
}
}

View file

@ -211,11 +211,11 @@ parseargs(int argc, char **argv)
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 @@ findifc(char *net, char *dev)
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 @@ main(int argc, char **argv)
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 @@ main(int argc, char **argv)
mkclientid();
if(dondbconfig){
dodhcp = 0;
beprimary = 0;
ndbconfig();
break;
}
@ -457,14 +466,14 @@ doadd(void)
dhcpquery(!noconfig, Sselecting);
}
if(!validip(conf.laddr))
if(!validip(conf.laddr)){
if(rflag && dodhcp && !noconfig){
warning("couldn't determine ip address, retrying");
dhcpwatch(1);
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 @@ doadd(void)
}
/* leave everything we've learned somewhere other procs can find it */
if(beprimary && !dondbconfig && !ipv6auto)
putndb();
putndb();
refresh();
}
@ -661,6 +669,9 @@ putndb(void)
Ndb *db;
int fd;
if(beprimary == 0)
return;
p = buf;
e = buf + sizeof buf;
p = seprint(p, e, "ip=%I ipmask=%M ipgw=%I\n",