diff options
author | cinap_lenrek <cinap_lenrek@felloff.net> | 2014-05-18 19:20:31 +0200 |
---|---|---|
committer | cinap_lenrek <cinap_lenrek@felloff.net> | 2014-05-18 19:20:31 +0200 |
commit | c994152a90f479a5f3165590f72b749017b6af3e (patch) | |
tree | b288ad14fe7bc178f2957d29c6c3ed7c97d78916 /sys/src/cmd | |
parent | 48a644aa316c7d12a77c9dc1d788ad0ef08b93f1 (diff) |
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.
Diffstat (limited to 'sys/src/cmd')
-rw-r--r-- | sys/src/cmd/ip/ipconfig/ipconfig.h | 2 | ||||
-rw-r--r-- | sys/src/cmd/ip/ipconfig/main.c | 24 |
2 files changed, 10 insertions, 16 deletions
diff --git a/sys/src/cmd/ip/ipconfig/ipconfig.h b/sys/src/cmd/ip/ipconfig/ipconfig.h index 555073c14..5a6073688 100644 --- a/sys/src/cmd/ip/ipconfig/ipconfig.h +++ b/sys/src/cmd/ip/ipconfig/ipconfig.h @@ -103,7 +103,7 @@ void controldevice(void); void dhcpquery(int, int); void dhcprecv(void); void dhcpsend(int); -int dhcptimer(void); +void dhcptimer(void); void dhcpwatch(int); void doadd(int); void doremove(void); diff --git a/sys/src/cmd/ip/ipconfig/main.c b/sys/src/cmd/ip/ipconfig/main.c index aea004dfe..6d61db431 100644 --- a/sys/src/cmd/ip/ipconfig/main.c +++ b/sys/src/cmd/ip/ipconfig/main.c @@ -182,7 +182,7 @@ void controldevice(void); void dhcpquery(int, int); void dhcprecv(void); void dhcpsend(int); -int dhcptimer(void); +void dhcptimer(void); void dhcpwatch(int); void doadd(int); void doremove(void); @@ -933,10 +933,9 @@ dhcpquery(int needconfig, int startstate) conf.resend = 0; conf.timeout = time(0) + 4; - while(conf.state != Sbound){ + while(conf.state != Sbound && conf.state != Sinit){ dhcprecv(); - if(dhcptimer() < 0) - break; + dhcptimer(); } close(conf.fd); @@ -956,8 +955,7 @@ enum { void dhcpwatch(int needconfig) { - int secs, s; - ulong t; + ulong secs, s, t; if(nodhcpwatch) return; @@ -973,10 +971,9 @@ dhcpwatch(int needconfig) procsetname("dhcpwatch"); /* keep trying to renew the lease */ for(;;){ - if(conf.lease == 0) + secs = conf.lease/2; + if(secs < 5) secs = 5; - else - secs = conf.lease >> 1; /* avoid overflows */ for(s = secs; s > 0; s -= t){ @@ -1022,14 +1019,14 @@ dhcpwatch(int needconfig) } } -int +void dhcptimer(void) { ulong now; now = time(0); if(now < conf.timeout) - return 0; + return; switch(conf.state) { default: @@ -1042,10 +1039,8 @@ dhcptimer(void) case Srebinding: dhcpsend(conf.state == Sselecting? Discover: Request); conf.timeout = now + 4; - if(++conf.resend > 5) { + if(++conf.resend > 5) conf.state = Sinit; - return -1; - } break; case Srenewing: dhcpsend(Request); @@ -1056,7 +1051,6 @@ dhcptimer(void) } break; } - return 0; } void |