Package: dhcping
Version: 1.2-4
Severity: wishlist
Tags: patch
In at least the Netherlands, many ISPs offer a fixed IP address on DSL
lines. However, DHCP is still used to register the fact that you're
online and to set routing info in the DSL system, so simply not doing
DHCP is not an option, as the routers "lose" the route to your IP (I'm
not sure of the exact details, but this is the effect).
Using the normal DHCP clients is also not always that convenient, as
then you need to take steps to prevent it overwriting your resolv.conf;
also if the DHCP server fails to respond for a while and your lease
expires (remember you have a fixed IP!) the DHCP client will remove the
IP address from the interface, and any explicit routes you may have set
over that IP also get dropped. Also other IP addresses on the same
interface (e.g. to communicate with the administrator's interface on
your DSL modem) are dropped.
I've patched dhclient to enable it to not release the requested lease
(chosen via an option -n), so that I can simply configure the interface
statically and run dhclient every halfhour from cron. I can report that
this works perfectly :-) I'm sure many other people could make use of
this option, hence I'm now supplying the patch for my change. Please
consider forwarding it upstream and implementing it.
Thanks,
Paul Slootman
-- System Information:
Debian Release: lenny/sid
APT prefers testing
APT policy: (650, 'testing'), (625, 'stable'), (600, 'unstable')
Architecture: amd64 (x86_64)
Kernel: Linux 2.6.22.15 (SMP w/2 CPU cores)
Locale: LANG=en_US.UTF-8, LC_CTYPE=en_US.UTF-8 (charmap=UTF-8)
Shell: /bin/sh linked to /bin/bash
diff -ru dhcping-1.2.orig/dhcping.8 dhcping-1.2/dhcping.8
--- dhcping-1.2.orig/dhcping.8 2009-02-11 17:36:52.000000000 +0100
+++ dhcping-1.2/dhcping.8 2009-01-30 16:55:11.046079921 +0100
@@ -191,7 +191,7 @@
\fBdhcping\fR \- send a DHCP request to DHCP server to see if it's up and
running
.SH "SYNOPSIS"
\fBdhcping\fR
-[\fB\-v\fR] [\fB\-q\fR] [\fB\-i\fR] [\fB\-r\fR]
+[\fB\-v\fR] [\fB\-q\fR] [\fB\-i\fR] [\fB\-r\fR] [\fB\-n\fR]
\fB\-t\fR \fImaxwait\fR
\fB\-c\fR \fIclient-IP\-address\fR
\fB\-s\fR \fIserver-IP\-address\fR
@@ -210,6 +210,8 @@
Use \s-1DHCPINFORM\s0 packets.
.Ip "\fB\-r\fR" 5
Use \s-1DHCPREQUEST\s0 packets (default behaviour).
+.Ip "\fB\-n\fR" 5
+Do not release the lease after requesting it (depends on \fB\-r\fR option)
.Ip "\fB\-q\fR" 5
Quiet, print nothing on the screen.
.Ip "\fB\-t\fR \fImaxwait\fR" 5
@@ -268,7 +270,14 @@
.SH "HOW IT WORKS"
The client either sends a DHCPREQUEST or DHCPINFORM packet to the
server and waits for an answer. Then, if a DHCPREQUEST was send,
-it will send a DHCPRELEASE back to the server.
+it will send a DHCPRELEASE back to the server,
+unless the -n option is passed. This can be used to eliminate the need
+for a full-fledged DHCP client on links where the IP address is essentially
+static, but the ISP requires use of DHCP to keep the routing alive.
+The problem with a full-fledged DHCP client is that if the DHCP server is
+down for some time (i'm sure I'm not alone with such an ISP...),
+it will remove the IP address and all associated routes
+from the interface, which is a pain.
.SH "SECURITY"
This program is installed setuid root as it requires the privileges
to bind itself to port 68 (bootpc). Root privileges are dropped as
diff -ru dhcping-1.2.orig/dhcping.c dhcping-1.2/dhcping.c
--- dhcping-1.2.orig/dhcping.c 2009-02-11 17:36:52.000000000 +0100
+++ dhcping-1.2/dhcping.c 2009-01-30 16:59:45.096316253 +0100
@@ -64,7 +64,7 @@
int _serveripaddress;
-int inform,request,verbose,VERBOSE,quiet;
+int inform,request,verbose,VERBOSE,quiet,norelease;
char *ci,*gi,*server,*hw;
unsigned char serveridentifier[4];
int maxwait=3;
@@ -72,16 +72,16 @@
void doargs(int argc,char **argv) {
int ch;
- inform=request=verbose=VERBOSE=quiet=0;
+ inform=request=verbose=VERBOSE=quiet=norelease=0;
ci=gi=server="0.0.0.0";
hw="00:00:00:00:00:00";
if (argc==1) {
- printf("dhcping -c ciaddr -g giaddr -h chaddr -r -s server -t maxwait
-i -v -q\n");
+ printf("dhcping -c ciaddr -g giaddr -h chaddr -r -s server -t maxwait
-i -n -v -q\n");
exit(1);
}
- while ((ch = getopt(argc,argv,"c:g:h:iqrs:t:vV"))>0) {
+ while ((ch = getopt(argc,argv,"c:g:h:iqrs:t:vVn"))>0) {
switch (ch) {
case 'c': ci=optarg;break;
case 'g': gi=optarg;break;
@@ -93,6 +93,7 @@
case 't': maxwait=atoi(optarg);break;
case 'v': verbose=1;break;
case 'V': VERBOSE=1;break;
+ case 'n': norelease=1;break;
}
}
@@ -103,6 +104,11 @@
// DHCPREQUEST is by default.
if (!inform) request=1;
+
+ if (!request && norelease) {
+ fprintf(stderr,"Error: -n needs -r option to make sense.\n");
+ exit(1);
+ }
}
int main(int argc,char **argv) {
@@ -149,7 +155,7 @@
if (VERBOSE) puts("read");
/* If a expected packet was found, then also release it. */
if ((foundpacket=dhcp_read())!=0) {
- if (request) {
+ if (request && !norelease) {
if (VERBOSE) puts("release");
dhcp_release(ci,gi,hw);
}