1. Added a 'Z' option to specify the length of a statically allocated lease. 2. Added a 'default' clause to the options switch so as to catch invalid options. 3. Added options 'S' and 'r' to the usage() description. In retrospect, a static lease time would have been unnecessary if the tests of StaticLease against 'minlease' had been in the opposite direction. There are four of these and it's not altogether clear what their purpose is. As the code stands now, it seems to resolve everything except the unfortunate choice of option letter, 'S" having been already taken. Also, there is such a thing as MCLT (I don't want to look it up) in recent RFC(s) and no implementation that I can see in this server. It may be worth looking into. And... Thanks for such easy source to modify :-) Notes: Sat Mar 3 16:33:26 EST 2007 geoff declined in favour of dhcpd_take_2 Reference: /n/sources/patch/sorry/dhcpd_staticlease Date: Sat Mar 3 06:47:32 CET 2007 Signed-off-by: lucio@proxima.alt.za Reviewed-by: geoff --- /sys/src/cmd/ip/dhcpd/dhcpd.c Sat Mar 3 06:36:45 2007 +++ /sys/src/cmd/ip/dhcpd/dhcpd.c Sat Mar 3 06:35:01 2007 @@ -57,6 +57,7 @@ int pptponly; // only answer request that came from the pptp server int mute, mutestat; int minlease = MinLease; +int staticlease = StaticLease; ulong start; @@ -199,7 +200,7 @@ void usage(void) { - fprint(2, "usage: dhcp [-dmsnp] [-f directory] [-x netmtpt] [-M minlease] addr n [addr n ...]\n"); + fprint(2, "usage: dhcp [-dmsnprS] [-f directory] [-x netmtpt] [-M minlease] [-Z staticlease] addr n [addr n ...]\n"); exits("usage"); } @@ -259,6 +260,17 @@ if(minlease <= 0) minlease = MinLease; break; + case 'Z': + p = ARGF(); + if(p == nil) + usage(); + staticlease = atoi(p); + if(staticlease <= 0) + staticlease = StaticLease; + break; + default: + usage(); + break; } ARGEND; while(argc > 1){ @@ -428,7 +440,7 @@ Binding *b, *nb; if(rp->staticbinding){ - sendoffer(rp, rp->ii.ipaddr, (StaticLease > minlease ? StaticLease : minlease)); + sendoffer(rp, rp->ii.ipaddr, (staticlease > minlease ? staticlease : minlease)); return; } @@ -486,7 +498,7 @@ /* check for hard assignment */ if(rp->staticbinding){ if(forme(rp->server)) - sendack(rp, rp->ii.ipaddr, (StaticLease > minlease ? StaticLease : minlease), 1); + sendack(rp, rp->ii.ipaddr, (staticlease > minlease ? staticlease : minlease), 1); else warning(0, "!Request(%s via %I): for server %I not me", rp->id, rp->gii.ipaddr, rp->server); @@ -543,7 +555,7 @@ rp->id, rp->gii.ipaddr, rp->ip, rp->bp->chaddr); sendnak(rp, "not valid"); } - sendack(rp, rp->ii.ipaddr, (StaticLease > minlease ? StaticLease : minlease), 1); + sendack(rp, rp->ii.ipaddr, (staticlease > minlease ? staticlease : minlease), 1); return; } @@ -585,7 +597,7 @@ rp->id, rp->gii.ipaddr, rp->ciaddr); sendnak(rp, "not valid"); } - sendack(rp, rp->ii.ipaddr, (StaticLease > minlease ? StaticLease : minlease), 1); + sendack(rp, rp->ii.ipaddr, (staticlease > minlease ? staticlease : minlease), 1); return; }