]> git.ipfire.org Git - thirdparty/dhcp.git/commitdiff
If interfaces are specified, don't configure any that weren't. In INIT-REBOOT state...
authorTed Lemon <source@isc.org>
Sun, 15 Mar 1998 21:04:52 +0000 (21:04 +0000)
committerTed Lemon <source@isc.org>
Sun, 15 Mar 1998 21:04:52 +0000 (21:04 +0000)
client/dhclient.c

index 363b4303fe110de3d56908d3725e8a4c1430ea22..d7231b7e7f699cad3e6ac56ae8cf6a7cea74f2c7 100644 (file)
@@ -3,7 +3,7 @@
    DHCP Client. */
 
 /*
- * Copyright (c) 1995, 1996, 1997 The Internet Software Consortium.
+ * Copyright (c) 1995, 1996, 1997, 1998 The Internet Software Consortium.
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
@@ -56,7 +56,7 @@
 
 #ifndef lint
 static char copyright[] =
-"$Id: dhclient.c,v 1.46 1998/02/06 00:58:36 mellon Exp $ Copyright (c) 1995, 1996 The Internet Software Consortium.  All rights reserved.\n";
+"$Id: dhclient.c,v 1.47 1998/03/15 21:04:52 mellon Exp $ Copyright (c) 1995, 1996 The Internet Software Consortium.  All rights reserved.\n";
 #endif /* not lint */
 
 #include "dhcpd.h"
@@ -193,6 +193,13 @@ int main (argc, argv, envp)
        } else {
                /* Call the script with the list of interfaces. */
                for (ip = interfaces; ip; ip = ip -> next) {
+                       /* If interfaces were specified, don't configure
+                          interfaces that weren't specified! */
+                       if (interfaces_requested &&
+                           ((ip -> flags & (INTERFACE_REQUESTED |
+                                            INTERFACE_AUTOMATIC)) ==
+                            INTERFACE_AUTOMATIC))
+                               continue;
                        script_init (ip, "PREINIT", (struct string_list *)0);
                        if (ip -> client -> alias)
                                script_write_params (ip, "alias_",
@@ -296,10 +303,14 @@ void state_reboot (ipp)
        /* We are in the rebooting state. */
        ip -> client -> state = S_REBOOTING;
 
+       /* make_request doesn't initialize xid because it normally comes
+          from the DHCPDISCOVER, but we haven't sent a DHCPDISCOVER,
+          so pick an xid now. */
+       ip -> client -> xid = random ();
+
        /* Make a DHCPREQUEST packet, and set appropriate per-interface
           flags. */
        make_request (ip, ip -> client -> active);
-       ip -> client -> xid = ip -> client -> packet.xid;
        ip -> client -> destination = iaddr_broadcast;
        ip -> client -> first_sending = cur_time;
        ip -> client -> interval = ip -> client -> config -> initial_interval;
@@ -437,7 +448,11 @@ void dhcpack (packet)
        
        /* If we're not receptive to an offer right now, or if the offer
           has an unrecognizable transaction id, then just drop it. */
-       if (packet -> interface -> client -> xid != packet -> raw -> xid) {
+       if (packet -> interface -> client -> xid != packet -> raw -> xid ||
+           (packet -> interface -> client -> hw_address.hlen !=
+            packet -> raw -> hlen) ||
+           (memcmp (packet -> interface -> client -> hw_address.haddr,
+                    packet -> raw -> chaddr))) {
                debug ("DHCPACK in wrong transaction.");
                return;
        }
@@ -503,7 +518,7 @@ void bind_lease (ip)
        ip -> client -> new -> medium = ip -> client -> medium;
 
        /* Write out the new lease. */
-       write_client_lease (ip, ip -> client -> new);
+       write_client_lease (ip, ip -> client -> new, 0);
 
        /* Run the client script with the new parameters. */
        script_init (ip, (ip -> client -> state == S_REQUESTING
@@ -1641,7 +1656,7 @@ void make_release (ip, lease)
        ip -> client -> packet.htype = ip -> hw_address.htype;
        ip -> client -> packet.hlen = ip -> hw_address.hlen;
        ip -> client -> packet.hops = 0;
-       ip -> client -> packet.xid = ip -> client -> packet.xid;
+       ip -> client -> packet.xid = ip -> client -> xid;
        ip -> client -> packet.secs = 0;
        ip -> client -> packet.flags = 0;
        memcpy (&ip -> client -> packet.ciaddr,
@@ -1695,30 +1710,39 @@ void rewrite_client_leases ()
           we know about. */
        for (ip = interfaces; ip; ip = ip -> next) {
                for (lp = ip -> client -> leases; lp; lp = lp -> next) {
-                       write_client_lease (ip, lp);
+                       write_client_lease (ip, lp, 1);
                }
                if (ip -> client -> active)
-                       write_client_lease (ip, ip -> client -> active);
+                       write_client_lease (ip, ip -> client -> active, 1);
        }
 
        /* Write out any leases that are attached to interfaces that aren't
           currently configured. */
        for (ip = dummy_interfaces; ip; ip = ip -> next) {
                for (lp = ip -> client -> leases; lp; lp = lp -> next) {
-                       write_client_lease (ip, lp);
+                       write_client_lease (ip, lp, 1);
                }
                if (ip -> client -> active)
-                       write_client_lease (ip, ip -> client -> active);
+                       write_client_lease (ip, ip -> client -> active, 1);
        }
        fflush (leaseFile);
 }
 
-void write_client_lease (ip, lease)
+void write_client_lease (ip, lease, rewrite)
        struct interface_info *ip;
        struct client_lease *lease;
+       int rewrite;
 {
        int i;
        struct tm *t;
+       static int leases_written;
+
+       if (!rewrite) {
+               if (leases_written++ > 20) {
+                       rewrite_client_leases ();
+                       leases_written = 0;
+               }
+       }
 
        /* If the lease came from the config file, we don't need to stash
           a copy in the lease database. */
@@ -1756,6 +1780,10 @@ void write_client_lease (ip, lease)
                                  lease -> options [i].len, 1, 1));
                }
        }
+
+       /* Note: the following is not a Y2K bug - it's a Y1.9K bug.   Until
+          somebody invents a time machine, I think we can safely disregard
+          it. */
        t = gmtime (&lease -> renewal);
        fprintf (leaseFile,
                 "  renew %d %d/%d/%d %02d:%02d:%02d;\n",