Networking Forums

Networking Forums > Computer Networking > Linux Networking > What signal tells my app that my DHCP lease just renewed?

Reply
Thread Tools Display Modes

What signal tells my app that my DHCP lease just renewed?

 
 
Rich Grise
Guest
Posts: n/a

 
      06-05-2004, 02:05 AM
I think that says it all - I decided I'm not a newbie any more, at
least at Slack[0]; I have a dynamic IP, and Tripod says that it's
OK to point domain name at a directory on their server, which
has cgi. So I write a script that redirects their browser to
my server here; it knows the IP because my box curl'd it its
IP right after the DHCP lease got renewed.

So I need to know what signal to have my quasi-daemon wait for.
Or would that be a full-on daemon, if I like run it in the
background?

I guess that's two questions -
Thanks!

[0] nor at programming - my first class was in high school, 11th
grade, 1965-66, Control Data (nee Bendix) G-15, running Intercom
500, or Intercom 550 if you wanted alphanumerics, (i.e. strings)
or Intercom 1000 for double-precision arithmetic. You could
actually watch the neon lights on the front panel flash, just like
in the movies. :-) I think it took 5 to 10 seconds to do a square
root. It used tubes, which are quick, yes, but its main memory,
both program memory and data memory; registers, and accumulator
were all on a magnetic drum! There was no static memory, except
for paper tape. :-) And starting it up and shutting it down were
quite the ritual as well.

:-) R


 
Reply With Quote
 
 
 
 
Bit Twister
Guest
Posts: n/a

 
      06-05-2004, 02:29 AM
On Sat, 05 Jun 2004 02:05:42 GMT, Rich Grise wrote:
> I think that says it all - I decided I'm not a newbie any more, at
> least at Slack[0]; I have a dynamic IP, and Tripod says that it's
> OK to point domain name at a directory on their server, which
> has cgi. So I write a script that redirects their browser to
> my server here; it knows the IP because my box curl'd it its
> IP right after the DHCP lease got renewed.
>
> So I need to know what signal to have my quasi-daemon wait for.
> Or would that be a full-on daemon, if I like run it in the
> background?


Depends on your dhcp client. Found with
ps aux | grep dhc

man your_dhcp_client_name_here for what it will do.

http://www.tldp.org/LDP/abs/html/index.html for script language refreash

On Mandrakelinux a
tail /sbin/ifup
shows an
exec /etc/sysconfig/network-scripts/ifup-post ${CONFIG} ${2}
which runs ifup-port after the interface is up.

 
Reply With Quote
 
James Knott
Guest
Posts: n/a

 
      06-05-2004, 02:37 AM
Rich Grise wrote:

> I think that says it all - I decided I'm not a newbie any more, at
> least at Slack[0]; I have a dynamic IP, and Tripod says that it's
> OK to point domain name at a directory on their server, which
> has cgi. So I write a script that redirects their browser to
> my server here; it knows the IP because my box curl'd it its
> IP right after the DHCP lease got renewed.
>
> So I need to know what signal to have my quasi-daemon wait for.
> Or would that be a full-on daemon, if I like run it in the
> background?


Your dhcp client likely can run an executable script, whenever the IP
changes.

Also, you may not need an external DNS, if your connection has a static host
name. For example, while my IP is dhcp, the host name is derived from my
computer and cable modem MAC addresses, which never change. Also, my IP
changes so seldom, it's essentially static.



--

Fundamentalism is fundamentally wrong.

To reply to this message, replace everything to the left of "@" with
james.knott.
 
Reply With Quote
 
Cameron Kerr
Guest
Posts: n/a

 
      06-07-2004, 01:28 AM
Rich Grise <(E-Mail Removed)> wrote:

> So I need to know what signal to have my quasi-daemon wait for.


There is no standard signal that is used to tell applications that the
address they are bound to has changed, and you usually won't need to
know this unless you are

1) A client application that has a long-established connection. In this
case, it is much better to program reconnection/timeout logic in
your application, with keepalive set to on. This helps make your
program resilient to other classes of network errors.

You could use such a method to good effect in your application
actually. The redirection server would maintain a TCP connection
to the dynamic server, with a heartbeat, and when it detects that
the connection has broken, it will do its reconfiguration. This
also has the benefit of being able not-redirect when it detects
your webserver is down.

2) A server application that is bound to a specific interface.
Most server network applications bind themselves to INADDR_ANY,
meaning they will accept connections coming in on any interface
(when I say interface here, I'm talking about the IP address, not
the device (such as eth0)).

Servers shouldn't be configured via DHCP though (in theory), or
at least, they shouldn't be configured with a _changing_ addresss.
But we don't like in a perfect world, and static addresses are a
luxury for most people, esp. when you're on an ISPs plan.

When an address changes, two things of note will happen.

1) Any existing connections will get lost. The client and server will
eventually detect that the connection is no more (timeout), and
will do whatever it is it does in that failure mode, whether it be
exit or reconnect.

2) If a server (the end doing accept() ) is bound to a specific IP
address, then it will cease to accept connections. AFAIK, it
will not receive any error notification. I think this is where your
problem comes into play. You want to find out when such an event
occurs. Correct?


There are three approaches I can think of off the top of my head. The
first, and most classical approach would be for the server to register a
handler for SIGHUP, which will reread it's configuration file (if any),
and reinitialise listening network sockets (meaning you must close them
first). You would need to set up your dhcp client to send your program
the HUP signal when this happens.

If you're operating a forked server, one simple approach would
be to exec over yourself. I beleive sendmail does this (or at least, it
did at one stage, from what I've been told.


Another, most portable method, would be to poll for changes. So in your
accept loop, you would do something like the following pseudocode.

recreate listening socket
bind listening socket to new address
record current address bound to
while true
select on listening socket, timeout after 30s
if address has changed
close listening socket
recreate listening socket
bind listening socket to new address
record current address bound to
...

You'll notice that there is part there that can be factorised into a
function or two. The disadvantage of this method is that you have to
poll every so often (in this example, every 30 seconds). Depending on
how fast your DNS entry gets updated after an update (and it usually
takes a fair while), this will do well, esp in a scripting language
which is nice and portable.

Note that your problem is even simpler, as you've already uploaded a
file with the new IP address inside it, so all your program needs to do
is detect when the file has changed (timestamp).

************************************************** *******************
Actually, its even easier than that, as your application is a CGI
app, so is started afresh for every request, so the IP you pull out
of your config file is really the latest one!
************************************************** *******************

But if you wanted something that was lightning fast (and I say this just
for reference, as its unlikely to concern your problem), then you would
need some platform-dependent way of being notified of certain events.
In the case of network reconfiguration (such as an interface being
configured with a new address), then under Linux you could use a
rtnetlink socket to watch for routing table updates. However, this is
probably far more work than you really ought to be spending.

A simpler way under linux would be to popen "/sbin/ip monitor address",
and do reconfiguration checks on output, taking care to make the file
handle line-buffered. This will require that the iproute tools be
available. Normal users can do this too (reading netlink doesn't require
root priviledge).

> Or would that be a full-on daemon, if I like run it in the background?


It's not a deamon at all, its a CGI application.


So in summary:

1) Either: maintain a TCP connection with heartbeat, and reconfigure
on consistent heartbeat failure.

OR

2) Poll for change in your control file (although your application
has the correct information when it starts anyway).

OR

3) Monitor for change using some platform-specific method.

4) I write too much. But hey, in defence its useful for the Googlers,
and it helps me to think of what I'm teaching my students. And its
kind of fun too.

5) I still write too much. ;^)

--
Cameron Kerr
(E-Mail Removed) : http://nzgeeks.org/cameron/
Empowered by Perl!
 
Reply With Quote
 
 
 
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
PPTP VPN lost when DHCP lease renewed Rob Windows Networking 3 05-26-2010 03:39 PM
DHCP Option : Release DHCP Lease on Shutdown (1) doesn't work Antoine Golio Windows Networking 0 12-06-2005 08:10 AM
DHCP Option : Release DHCP Lease on Shutdown (1) doesn't work Antoine Golio Windows Networking 2 11-30-2005 08:49 AM
DHCP sever available, DHCP lease available on the client computer didace Windows Networking 0 11-13-2003 12:11 PM
DHCP lease WenbinChen Linux Networking 7 07-23-2003 02:43 AM



1 2 3 4 5 6 7 8 9 10 11