aboutsummaryrefslogtreecommitdiff
path: root/networking/udhcp
diff options
context:
space:
mode:
Diffstat (limited to 'networking/udhcp')
-rw-r--r--networking/udhcp/ChangeLog5
-rw-r--r--networking/udhcp/README151
-rw-r--r--networking/udhcp/README.dumpleases17
-rw-r--r--networking/udhcp/README.udhcpc139
-rw-r--r--networking/udhcp/README.udhcpd59
-rw-r--r--networking/udhcp/TODO7
-rw-r--r--networking/udhcp/clientpacket.c16
-rw-r--r--networking/udhcp/dhcpc.c9
8 files changed, 243 insertions, 160 deletions
diff --git a/networking/udhcp/ChangeLog b/networking/udhcp/ChangeLog
index 9c269d85d..34cfe16f9 100644
--- a/networking/udhcp/ChangeLog
+++ b/networking/udhcp/ChangeLog
@@ -1,4 +1,7 @@
-0.9.8 (pending)
+0.9.8 (021031)
++ split up README files (me)
++ use /dev/urandom to seed xid's (instead of time(0)) (me)
++ fixed renew behavior (me)
+ udhcp now fits nicely into busybox
(Glenn McGrath <bug1@optushome.com.au> as well as myself)
+ updated client manpage (me)
diff --git a/networking/udhcp/README b/networking/udhcp/README
index d3e5e3fbc..5f4bb78a8 100644
--- a/networking/udhcp/README
+++ b/networking/udhcp/README
@@ -5,155 +5,6 @@ The udhcp server/client package is primarily geared towards embedded
systems. It does however, strive to be fully functional, and RFC
compliant.
-udhcp server (udhcpd)
---------------------
-
-The only command line argument to udhcpd is an optional specifed
-config file. If no config file is specified, udhcpd uses the default
-config file, /etc/udhcpd.conf. Ex:
-
-udhcpd /etc/udhcpd.eth1.conf
-
-The udhcp server employs a number of simple config files:
-
-udhcpd.leases
-------------
-
-The udhcpd.leases behavior is designed for an embedded system. The
-file is written either every auto_time seconds, or when a SIGUSR1
-is received (the auto_time timer restarts if a SIGUSR1 is received).
-If you send a SIGTERM to udhcpd directly after a SIGUSR1, udhcpd will
-finish writing the leases file and wait for the aftermentioned script
-to be executed and finish before quiting, so you do not need to sleep
-between sending signals. When the file is written, a script can be
-optionally called to commit the file to flash. Lease times are stored
-in the file by time remaining in lease (for systems without clock
-that works when there is no power), or by the absolute time that it
-expires in seconds from epoch. In the remainig format, expired leases
-are stored as zero. The file is of the format:
-
-16 byte MAC
-4 byte ip address
-u32 expire time
-16 byte MAC
-4 byte ip address
-u32 expire time
-.
-etc.
-
-example: hexdump udhcpd.leases
-
-0000000 1000 c95a 27d9 0000 0000 0000 0000 0000
-0000010 a8c0 150a 0d00 2d29 5000 23fc 8566 0000
-0000020 0000 0000 0000 0000 a8c0 140a 0d00 4e29
-0000030
-
-
-udhcpd.conf
-----------
-
-The format is fairly simple, there is a sample file with all the
-available options and comments describing them in samples/udhcpd.conf
-
-
-udhcp client (udhcpc)
---------------------
-
-The udhcp client negotiates a lease with the DHCP server and notifies
-a set of scripts when a leases is obtained or lost. The command line
-options for the udhcp client are:
-
--c, --clientid=CLIENTID Client identifier
--H, --hostname=HOSTNAME Client hostname
--h, Alias for -H
--f, --foreground Do not fork after getting lease
--b, --background Fork to background if lease cannot be
- immediately negotiated.
--i, --interface=INTERFACE Interface to use (default: eth0)
--n, --now Exit with failure if lease cannot be
- immediately negotiated.
--p, --pidfile=file Store process ID of daemon in file
--q, --quit Quit after obtaining lease
--r, --request=IP IP address to request (default: none)
--s, --script=file Run file at dhcp events (default:
- /usr/share/udhcpc/default.script)
--v, --version Display version
-
-If the requested IP address cannot be obtained, the client accepts the
-address that the server offers.
-
-When an event occurs, udhcpc calls the action script. The script by
-default is /usr/share/udhcpc/default.script but this can be changed via
-the command line arguments. The three possible arguments to the script
-are:
-
- deconfig: This argument is used when udhcpc starts, and
- when a leases is lost. The script should put the interface in an
- up, but deconfigured state, ie: ifconfig $interface 0.0.0.0.
-
- bound: This argument is used when udhcpc moves from an
- unbound, to a bound state. All of the paramaters are set in
- enviromental variables, The script should configure the interface,
- and set any other relavent parameters (default gateway, dns server,
- etc).
-
- renew: This argument is used when a DHCP lease is renewed. All of
- the paramaters are set in enviromental variables. This argument is
- used when the interface is already configured, so the IP address,
- will not change, however, the other DHCP paramaters, such as the
- default gateway, subnet mask, and dns server may change.
-
- nak: This argument is used with udhcpc receives a NAK message.
- The script with the deconfig argument will be called directly
- afterwards, so no changes to the network interface are neccessary.
- This hook is provided for purely informational purposes (the
- message option may contain a reason for the NAK).
-
-The paramaters for enviromental variables are as follows:
-
- $HOME - The set $HOME env or "/"
- $PATH - the set $PATH env or "/bin:/usr/bin:/sbin:/usr/sbin"
- $1 - What action the script should perform
- interface - The interface this was obtained on
- ip - The obtained IP
- siaddr - The bootp next server option
- sname - The bootp server name option
- boot_file - The bootp boot file option
- subnet - The assigend subnet mask
- timezone - Offset in seconds from UTC
- router - A list of routers
- timesvr - A list of time servers
- namesvr - A list of IEN 116 name servers
- dns - A list of DNS server
- logsvr - A list of MIT-LCS UDP log servers
- cookiesvr - A list of RFC 865 cookie servers
- lprsvr - A list of LPR servers
- hostname - The assigned hostname
- bootsize - The length in 512 octect blocks of the bootfile
- domain - The domain name of the network
- swapsvr - The IP address of the client's swap server
- rootpath - The path name of the client's root disk
- ipttl - The TTL to use for this network
- mtu - The MTU to use for this network
- broadcast - The broadcast address for this network
- ntpsrv - A list of NTP servers
- wins - A list of WINS servers
- lease - The lease time, in seconds
- dhcptype - DHCP message type (safely ignored)
- serverid - The IP of the server
- message - Reason for a DHCPNAK
- tftp - The TFTP server name
- bootfile - The bootfile name
-
-additional options are easily added in options.c.
-
-udhcpc also responds to SIGUSR1 and SIGUSR2. SIGUSR1 will force a renew state,
-and SIGUSR2 will force a release of the current lease, and cause udhcpc to
-go into an inactive state (until it is killed, or receives a SIGUSR1). You do
-not need to sleep between sending signals, as signals received are processed
-sequencially in the order they are received.
-
-
compile time options
-------------------
@@ -185,6 +36,7 @@ options.c contains a set of dhcp options for the client:
code: The DHCP code for this option
+
busybox drop-in
--------------
udhcp is now a drop-in component for busybox (http://busybox.net).
@@ -195,3 +47,4 @@ cp *.[ch] README AUTHORS COPYING ChangeLog TODO \
The only two files udhcp does not provide are config.in and
Makefile.in, so these may need to be updated from time to time.
+
diff --git a/networking/udhcp/README.dumpleases b/networking/udhcp/README.dumpleases
new file mode 100644
index 000000000..6367710c4
--- /dev/null
+++ b/networking/udhcp/README.dumpleases
@@ -0,0 +1,17 @@
+udhcp lease dump (dumpleases)
+----------------------------
+
+dumpleases displays the leases written out by the udhcpd server. Lease
+times are stored in the file by time remaining in lease (for systems
+without clock that works when there is no power), or by the absolute
+time that it expires in seconds from epoch. dumpleases accepts the
+following command line options:
+
+-a, --absolute Interpret lease times as expiration time.
+-r, --remaining Interpret lease times as remaining time.
+-f, --file=FILE Read lease information from FILE.
+-h, --help Display help.
+
+Note that if udhcpd has not written a leases file recently, the output
+of may not be up to date.
+
diff --git a/networking/udhcp/README.udhcpc b/networking/udhcp/README.udhcpc
new file mode 100644
index 000000000..3591605e3
--- /dev/null
+++ b/networking/udhcp/README.udhcpc
@@ -0,0 +1,139 @@
+udhcp client (udhcpc)
+--------------------
+
+The udhcp client negotiates a lease with the DHCP server and notifies
+a set of scripts when a leases is obtained or lost.
+
+
+command line options
+-------------------
+
+The command line options for the udhcp client are:
+
+-c, --clientid=CLIENTID Client identifier
+-H, --hostname=HOSTNAME Client hostname
+-h, Alias for -H
+-f, --foreground Do not fork after getting lease
+-b, --background Fork to background if lease cannot be
+ immediately negotiated.
+-i, --interface=INTERFACE Interface to use (default: eth0)
+-n, --now Exit with failure if lease cannot be
+ immediately negotiated.
+-p, --pidfile=file Store process ID of daemon in file
+-q, --quit Quit after obtaining lease
+-r, --request=IP IP address to request (default: none)
+-s, --script=file Run file at dhcp events (default:
+ /usr/share/udhcpc/default.script)
+-v, --version Display version
+
+
+If the requested IP address cannot be obtained, the client accepts the
+address that the server offers.
+
+
+udhcp client scripts
+-------------------
+
+When an event occurs, udhcpc calls the action script. The script by
+default is /usr/share/udhcpc/default.script but this can be changed via
+the command line arguments. The three possible arguments to the script
+are:
+
+ deconfig: This argument is used when udhcpc starts, and
+ when a leases is lost. The script should put the interface in an
+ up, but deconfigured state, ie: ifconfig $interface 0.0.0.0.
+
+ bound: This argument is used when udhcpc moves from an
+ unbound, to a bound state. All of the paramaters are set in
+ enviromental variables, The script should configure the interface,
+ and set any other relavent parameters (default gateway, dns server,
+ etc).
+
+ renew: This argument is used when a DHCP lease is renewed. All of
+ the paramaters are set in enviromental variables. This argument is
+ used when the interface is already configured, so the IP address,
+ will not change, however, the other DHCP paramaters, such as the
+ default gateway, subnet mask, and dns server may change.
+
+ nak: This argument is used with udhcpc receives a NAK message.
+ The script with the deconfig argument will be called directly
+ afterwards, so no changes to the network interface are neccessary.
+ This hook is provided for purely informational purposes (the
+ message option may contain a reason for the NAK).
+
+The paramaters for enviromental variables are as follows:
+
+ $HOME - The set $HOME env or "/"
+ $PATH - the set $PATH env or "/bin:/usr/bin:/sbin:/usr/sbin"
+ $1 - What action the script should perform
+ interface - The interface this was obtained on
+ ip - The obtained IP
+ siaddr - The bootp next server option
+ sname - The bootp server name option
+ boot_file - The bootp boot file option
+ subnet - The assigend subnet mask
+ timezone - Offset in seconds from UTC
+ router - A list of routers
+ timesvr - A list of time servers
+ namesvr - A list of IEN 116 name servers
+ dns - A list of DNS server
+ logsvr - A list of MIT-LCS UDP log servers
+ cookiesvr - A list of RFC 865 cookie servers
+ lprsvr - A list of LPR servers
+ hostname - The assigned hostname
+ bootsize - The length in 512 octect blocks of the bootfile
+ domain - The domain name of the network
+ swapsvr - The IP address of the client's swap server
+ rootpath - The path name of the client's root disk
+ ipttl - The TTL to use for this network
+ mtu - The MTU to use for this network
+ broadcast - The broadcast address for this network
+ ntpsrv - A list of NTP servers
+ wins - A list of WINS servers
+ lease - The lease time, in seconds
+ dhcptype - DHCP message type (safely ignored)
+ serverid - The IP of the server
+ message - Reason for a DHCPNAK
+ tftp - The TFTP server name
+ bootfile - The bootfile name
+
+additional options are easily added in options.c.
+
+
+note on udhcpc's random seed
+---------------------------
+
+udhcpc will seed its random number generator (used for generating xid's)
+by reading /dev/urandom. If you have a lot of embedded systems on the same
+network, with no entropy, you can either seed /dev/urandom by a method of
+your own, or doing the following on startup:
+
+ifconfig eth0 > /dev/urandom
+
+in order to seed /dev/urandom with some data (mac address) unique to your
+system. If reading /dev/urandom fails, udhcpc will fall back to its old
+behavior of seeding with time(0).
+
+
+signals accepted by udhcpc
+-------------------------
+
+udhcpc also responds to SIGUSR1 and SIGUSR2. SIGUSR1 will force a renew state,
+and SIGUSR2 will force a release of the current lease, and cause udhcpc to
+go into an inactive state (until it is killed, or receives a SIGUSR1). You do
+not need to sleep between sending signals, as signals received are processed
+sequencially in the order they are received.
+
+
+compile time options
+-------------------
+
+options.c contains a set of dhcp options for the client:
+
+ name[10]: The name of the option as it will appear in scripts
+
+ flags: The type of option, as well as if it will be requested
+ by the client (OPTION_REQ)
+
+ code: The DHCP code for this option
+
diff --git a/networking/udhcp/README.udhcpd b/networking/udhcp/README.udhcpd
new file mode 100644
index 000000000..bc6137de3
--- /dev/null
+++ b/networking/udhcp/README.udhcpd
@@ -0,0 +1,59 @@
+udhcp server (udhcpd)
+--------------------
+
+The only command line argument to udhcpd is an optional specifed
+config file. If no config file is specified, udhcpd uses the default
+config file, /etc/udhcpd.conf. Ex:
+
+udhcpd /etc/udhcpd.eth1.conf
+
+The udhcp server employs a number of simple config files:
+
+udhcpd.leases
+------------
+
+The udhcpd.leases behavior is designed for an embedded system. The
+file is written either every auto_time seconds, or when a SIGUSR1
+is received (the auto_time timer restarts if a SIGUSR1 is received).
+If you send a SIGTERM to udhcpd directly after a SIGUSR1, udhcpd will
+finish writing the leases file and wait for the aftermentioned script
+to be executed and finish before quiting, so you do not need to sleep
+between sending signals. When the file is written, a script can be
+optionally called to commit the file to flash. Lease times are stored
+in the file by time remaining in lease (for systems without clock
+that works when there is no power), or by the absolute time that it
+expires in seconds from epoch. In the remaining format, expired leases
+are stored as zero. The file is of the format:
+
+16 byte MAC
+4 byte ip address
+u32 expire time
+16 byte MAC
+4 byte ip address
+u32 expire time
+.
+etc.
+
+example: hexdump udhcpd.leases
+
+0000000 1000 c95a 27d9 0000 0000 0000 0000 0000
+0000010 a8c0 150a 0d00 2d29 5000 23fc 8566 0000
+0000020 0000 0000 0000 0000 a8c0 140a 0d00 4e29
+0000030
+
+
+udhcpd.conf
+----------
+
+The format is fairly simple, there is a sample file with all the
+available options and comments describing them in samples/udhcpd.conf
+
+compile time options
+-------------------
+
+dhcpd.h contains the other two compile time options:
+
+ LEASE_TIME: The default lease time if not specified in the config
+ file.
+
+ DHCPD_CONFIG_FILE: The defualt config file to use.
diff --git a/networking/udhcp/TODO b/networking/udhcp/TODO
index 47e451213..f88694a86 100644
--- a/networking/udhcp/TODO
+++ b/networking/udhcp/TODO
@@ -1,17 +1,14 @@
TODO
----
++ Integrade README.*'s with manpages
++ using time(0) breaks if the system clock changes, find a portable solution
+ make failure of reading functions revert to previous value, not the default
+ sanity code for option[OPT_LEN]
+ fix aliasing (ie: eth0:0)
-+ DONE: Make sure get_raw_packet only accepts packets on the specified interface
+ better standard linux distro support
-+ DONE: make config file a command line option for server
-+ IMPLEMENTED: make forking a command line option
+ make sure packet generation works on a wide varitey of arches
+ Interoperability testing
+ Hooks within the DHCP server
+ Additional bootp support in client/server
+ Make serverid option in server configurable
-+ DONE: cause client to generate DHCP_VENDOR option
+ Possibly add failure message to DHCP NAK
-+ Possibly log DHCP NAK failure message in client \ No newline at end of file
diff --git a/networking/udhcp/clientpacket.c b/networking/udhcp/clientpacket.c
index ecbd7953f..86faec925 100644
--- a/networking/udhcp/clientpacket.c
+++ b/networking/udhcp/clientpacket.c
@@ -35,6 +35,10 @@
#include <unistd.h>
#include <netinet/in.h>
#include <arpa/inet.h>
+#include <errno.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
#include "dhcpd.h"
@@ -49,7 +53,17 @@ unsigned long random_xid(void)
{
static int initialized;
if (!initialized) {
- srand(time(0));
+ int fd;
+ unsigned long seed;
+
+ fd = open("/dev/urandom", 0);
+ if (fd < 0 || read(fd, &seed, sizeof(seed)) < 0) {
+ LOG(LOG_WARNING, "Could not load seed from /dev/urandom: %s",
+ strerror(errno));
+ seed = time(0);
+ }
+ if (fd >= 0) close(fd);
+ srand(seed);
initialized++;
}
return rand();
diff --git a/networking/udhcp/dhcpc.c b/networking/udhcp/dhcpc.c
index ae40ec9c2..295486c98 100644
--- a/networking/udhcp/dhcpc.c
+++ b/networking/udhcp/dhcpc.c
@@ -118,14 +118,14 @@ static void perform_renew(void)
{
LOG(LOG_INFO, "Performing a DHCP renew");
switch (state) {
- case RENEWING:
- run_script(NULL, "deconfig");
case BOUND:
- case REBINDING:
change_mode(LISTEN_KERNEL);
+ case RENEWING:
+ case REBINDING:
state = RENEW_REQUESTED;
break;
- case RENEW_REQUESTED:
+ case RENEW_REQUESTED: /* impatient are we? fine, square 1 */
+ run_script(NULL, "deconfig");
case REQUESTING:
case RELEASED:
change_mode(LISTEN_RAW);
@@ -387,6 +387,7 @@ int main(int argc, char *argv[])
packet_num++;
} else {
/* timed out, go back to init state */
+ if (state == RENEW_REQUESTED) run_script(NULL, "deconfig");
state = INIT_SELECTING;
timeout = now;
packet_num = 0;