]> git.ipfire.org Git - thirdparty/dhcpcd.git/commitdiff
Allow testing of INFORM and REQUEST messages.
authorRoy Marples <roy@marples.name>
Sat, 11 Jul 2009 18:54:43 +0000 (18:54 +0000)
committerRoy Marples <roy@marples.name>
Sat, 11 Jul 2009 18:54:43 +0000 (18:54 +0000)
dhcpcd.8.in
dhcpcd.c

index 7e71245680d7f1d182b63afed6e717c784721e65..823be8dcd16293509d87b8c2e8c2c7a677df9b2a 100644 (file)
@@ -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 .
index d94d606f36e3e7c931240cc7abea69bc7eb0f8d8..6df84b394d4f90d7aa065c83ac96af6a52422f7a 100644 (file)
--- 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,