ipconfig: fix dhcp watch
in dhcpwatch, the sleep time "secs" could become zero potentially freezing the lease time. give up when in Sinit state in dhcpquery() as this is a terminal state.
This commit is contained in:
parent
48a644aa31
commit
c994152a90
2 changed files with 10 additions and 16 deletions
|
@ -103,7 +103,7 @@ void controldevice(void);
|
||||||
void dhcpquery(int, int);
|
void dhcpquery(int, int);
|
||||||
void dhcprecv(void);
|
void dhcprecv(void);
|
||||||
void dhcpsend(int);
|
void dhcpsend(int);
|
||||||
int dhcptimer(void);
|
void dhcptimer(void);
|
||||||
void dhcpwatch(int);
|
void dhcpwatch(int);
|
||||||
void doadd(int);
|
void doadd(int);
|
||||||
void doremove(void);
|
void doremove(void);
|
||||||
|
|
|
@ -182,7 +182,7 @@ void controldevice(void);
|
||||||
void dhcpquery(int, int);
|
void dhcpquery(int, int);
|
||||||
void dhcprecv(void);
|
void dhcprecv(void);
|
||||||
void dhcpsend(int);
|
void dhcpsend(int);
|
||||||
int dhcptimer(void);
|
void dhcptimer(void);
|
||||||
void dhcpwatch(int);
|
void dhcpwatch(int);
|
||||||
void doadd(int);
|
void doadd(int);
|
||||||
void doremove(void);
|
void doremove(void);
|
||||||
|
@ -933,10 +933,9 @@ dhcpquery(int needconfig, int startstate)
|
||||||
conf.resend = 0;
|
conf.resend = 0;
|
||||||
conf.timeout = time(0) + 4;
|
conf.timeout = time(0) + 4;
|
||||||
|
|
||||||
while(conf.state != Sbound){
|
while(conf.state != Sbound && conf.state != Sinit){
|
||||||
dhcprecv();
|
dhcprecv();
|
||||||
if(dhcptimer() < 0)
|
dhcptimer();
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
close(conf.fd);
|
close(conf.fd);
|
||||||
|
|
||||||
|
@ -956,8 +955,7 @@ enum {
|
||||||
void
|
void
|
||||||
dhcpwatch(int needconfig)
|
dhcpwatch(int needconfig)
|
||||||
{
|
{
|
||||||
int secs, s;
|
ulong secs, s, t;
|
||||||
ulong t;
|
|
||||||
|
|
||||||
if(nodhcpwatch)
|
if(nodhcpwatch)
|
||||||
return;
|
return;
|
||||||
|
@ -973,10 +971,9 @@ dhcpwatch(int needconfig)
|
||||||
procsetname("dhcpwatch");
|
procsetname("dhcpwatch");
|
||||||
/* keep trying to renew the lease */
|
/* keep trying to renew the lease */
|
||||||
for(;;){
|
for(;;){
|
||||||
if(conf.lease == 0)
|
secs = conf.lease/2;
|
||||||
|
if(secs < 5)
|
||||||
secs = 5;
|
secs = 5;
|
||||||
else
|
|
||||||
secs = conf.lease >> 1;
|
|
||||||
|
|
||||||
/* avoid overflows */
|
/* avoid overflows */
|
||||||
for(s = secs; s > 0; s -= t){
|
for(s = secs; s > 0; s -= t){
|
||||||
|
@ -1022,14 +1019,14 @@ dhcpwatch(int needconfig)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
void
|
||||||
dhcptimer(void)
|
dhcptimer(void)
|
||||||
{
|
{
|
||||||
ulong now;
|
ulong now;
|
||||||
|
|
||||||
now = time(0);
|
now = time(0);
|
||||||
if(now < conf.timeout)
|
if(now < conf.timeout)
|
||||||
return 0;
|
return;
|
||||||
|
|
||||||
switch(conf.state) {
|
switch(conf.state) {
|
||||||
default:
|
default:
|
||||||
|
@ -1042,10 +1039,8 @@ dhcptimer(void)
|
||||||
case Srebinding:
|
case Srebinding:
|
||||||
dhcpsend(conf.state == Sselecting? Discover: Request);
|
dhcpsend(conf.state == Sselecting? Discover: Request);
|
||||||
conf.timeout = now + 4;
|
conf.timeout = now + 4;
|
||||||
if(++conf.resend > 5) {
|
if(++conf.resend > 5)
|
||||||
conf.state = Sinit;
|
conf.state = Sinit;
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
case Srenewing:
|
case Srenewing:
|
||||||
dhcpsend(Request);
|
dhcpsend(Request);
|
||||||
|
@ -1056,7 +1051,6 @@ dhcptimer(void)
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
|
Loading…
Reference in a new issue