summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRoy Marples <roy@marples.name>2009-07-11 18:54:43 +0000
committerRoy Marples <roy@marples.name>2009-07-11 18:54:43 +0000
commitdecc33d0b200f965fa6ec78256628fd73318637e (patch)
treeb3374d13b8781bf7db129b5f5f6359b8b4b2d0e7
parent0df26ea85b56b98fe13a246c3703b5e6d759c566 (diff)
downloaddhcpcd-decc33d0b200f965fa6ec78256628fd73318637e.tar.xz
Allow testing of INFORM and REQUEST messages.
-rw-r--r--dhcpcd.8.in7
-rw-r--r--dhcpcd.c47
2 files changed, 32 insertions, 22 deletions
diff --git a/dhcpcd.8.in b/dhcpcd.8.in
index 7e712456..823be8dc 100644
--- a/dhcpcd.8.in
+++ b/dhcpcd.8.in
@@ -22,7 +22,7 @@
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
-.Dd July 5, 2009
+.Dd July 11, 2009
.Dt DHCPCD 8 SMM
.Os
.Sh NAME
@@ -454,12 +454,15 @@ Here is an example which configures a static address, routes and dns.
.D1 -S domain_name_servers=192.168.0.1 \e
.D1 eth0
.It Fl T, -test
-On receipt of OFFER messages just call
+On receipt of DHCP messages just call
.Pa @SCRIPT@
with the reason of TEST which echo's the DHCP variables found in the message
to the console.
The interface configuration isn't touched and neither are any configuration
files.
+To test INFORM the interface needs to be configured with the desired address
+before starting
+.Nm .
.It Fl V, -variables
Display a list of option codes and the associated variable for use in
.Xr dhcpcd-run-hooks 8 .
diff --git a/dhcpcd.c b/dhcpcd.c
index d94d606f..6df84b39 100644
--- a/dhcpcd.c
+++ b/dhcpcd.c
@@ -253,7 +253,7 @@ stop_interface(struct interface *iface)
else
ifaces = ifp->next;
free_interface(ifp);
- if (!(options & DHCPCD_MASTER))
+ if (!(options & (DHCPCD_MASTER | DHCPCD_TEST)))
exit(EXIT_FAILURE);
}
@@ -984,9 +984,13 @@ start_inform(struct interface *iface)
if (handle_3rdparty(iface))
return;
- iface->state->options->options |= DHCPCD_STATIC;
- start_static(iface);
- iface->state->options->options &= ~DHCPCD_STATIC;
+ if (options & DHCPCD_TEST) {
+ iface->addr.s_addr = iface->state->options->req_addr.s_addr;
+ iface->net.s_addr = iface->state->options->req_mask.s_addr;
+ } else {
+ iface->state->options->options |= DHCPCD_STATIC;
+ start_static(iface);
+ }
iface->state->state = DHS_INFORM;
iface->state->xid = arc4random();
@@ -1065,10 +1069,6 @@ start_interface(void *arg)
free(iface->state->offer);
iface->state->offer = NULL;
- if (options & DHCPCD_TEST) {
- start_discover(iface);
- return;
- }
if (iface->state->arping_index < ifo->arping_len) {
start_arping(iface);
return;
@@ -1328,6 +1328,9 @@ handle_signal(_unused void *arg)
return;
}
+ if (options & DHCPCD_TEST)
+ exit(EXIT_FAILURE);
+
/* As drop_config could re-arrange the order, we do it like this. */
for (;;) {
/* Be sane and drop the last config first */
@@ -1593,9 +1596,11 @@ main(int argc, char **argv)
exit(EXIT_FAILURE);
}
options = ifo->options;
- if (i)
+ if (i != 0) {
options |= DHCPCD_TEST | DHCPCD_PERSISTENT;
-
+ options &= ~DHCPCD_DAEMONISE;
+ }
+
#ifdef THERE_IS_NO_FORK
options &= ~DHCPCD_DAEMONISE;
#endif
@@ -1605,22 +1610,24 @@ main(int argc, char **argv)
else if (options & DHCPCD_QUIET)
setlogmask(LOG_UPTO(LOG_WARNING));
- /* If we have any other args, we should run as a single dhcpcd instance
- * for that interface. */
- len = strlen(PIDFILE) + IF_NAMESIZE + 2;
- pidfile = xmalloc(len);
- if (optind == argc - 1 && !(options & DHCPCD_TEST)) {
- snprintf(pidfile, len, PIDFILE, "-", argv[optind]);
- } else {
- snprintf(pidfile, len, PIDFILE, "", "");
- options |= DHCPCD_MASTER;
+ if (!(options & DHCPCD_TEST)) {
+ /* If we have any other args, we should run as a single dhcpcd
+ * instance for that interface. */
+ len = strlen(PIDFILE) + IF_NAMESIZE + 2;
+ pidfile = xmalloc(len);
+ if (optind == argc - 1)
+ snprintf(pidfile, len, PIDFILE, "-", argv[optind]);
+ else {
+ snprintf(pidfile, len, PIDFILE, "", "");
+ options |= DHCPCD_MASTER;
+ }
}
if (chdir("/") == -1)
syslog(LOG_ERR, "chdir `/': %m");
atexit(cleanup);
- if (!(options & DHCPCD_MASTER)) {
+ if (!(options & (DHCPCD_MASTER | DHCPCD_TEST))) {
control_fd = open_control();
if (control_fd != -1) {
syslog(LOG_INFO,