]> git.ipfire.org Git - thirdparty/dhcp.git/commitdiff
[v4_2] Some small client changes
authorShawn Routhier <sar@isc.org>
Wed, 7 May 2014 15:33:10 +0000 (08:33 -0700)
committerShawn Routhier <sar@isc.org>
Wed, 7 May 2014 15:33:10 +0000 (08:33 -0700)
18933 - add an extra server by name call
26735 - when requested via a command line option
        have client exit afer 1 failure per the docs
33098 - expose next-server option to dhclient script

RELNOTES
client/dhclient.c
includes/dhcpd.h

index f1b2bf4e8d047e5a47959db45033892aa47994d4..97e9a1bf7dcbedecd0de8357deb36f651dc3d4d1 100644 (file)
--- a/RELNOTES
+++ b/RELNOTES
@@ -93,6 +93,21 @@ by Eric Young (eay@cryptsoft.com).
   Thanks to Jiri Popelka at Red Hat for the bug and fix.
   [ISC-Bugs #21238
 
+- Some minor cleanups in the client code
+  In addition to checking for dhcpc check for bootpc in the services list
+  [ISC-Bugs #18933]
+  Correct the client code to only try to get a lease once when the
+  given the "-1" argument.
+  Thanks to Jiri Popelka at Red Hat for the bug and fix.
+  [ISC-Bugs #26735]
+  When asked for the version don't send the output to syslog.
+  [ISC-Bugs #29772]
+  Add the next server information to the environment variables for
+  use by the client script.  In order to avoid changing the client
+  lease file the next server information isn't written to it.
+  Thanks to Tomas Hozza at Red Hat for the suggestion and a prototype fix.
+  [ISC-Bugs #33098]
+
                        Changes since 4.2.6rc1
 
 - None
index 52121bebdcfc4d1a80ccd5e030703894c5cc1295..0eedab6afcd1991ef2938cd45076dcfdd01119fc 100644 (file)
@@ -308,7 +308,13 @@ main(int argc, char **argv) {
                } else if (!strcmp(argv[i], "-v")) {
                        quiet = 0;
                } else if (!strcmp(argv[i], "--version")) {
-                       log_info("isc-dhclient-%s", PACKAGE_VERSION);
+                       const char vstring[] = "isc-dhclient-";
+                       IGNORE_RET(write(STDERR_FILENO, vstring,
+                                        strlen(vstring)));
+                       IGNORE_RET(write(STDERR_FILENO,
+                                        PACKAGE_VERSION,
+                                        strlen(PACKAGE_VERSION)));
+                       IGNORE_RET(write(STDERR_FILENO, "\n", 1));
                        exit(0);
                } else if (argv[i][0] == '-') {
                    usage();
@@ -1202,33 +1208,38 @@ void bind_lease (client)
        struct timeval tv;
 
        /* Remember the medium. */
-       client -> new -> medium = client -> medium;
+       client->new->medium = client->medium;
 
        /* Run the client script with the new parameters. */
-       script_init (client, (client -> state == S_REQUESTING
-                         ? "BOUND"
-                         : (client -> state == S_RENEWING
-                            ? "RENEW"
-                            : (client -> state == S_REBOOTING
-                               ? "REBOOT" : "REBIND"))),
-                    client -> new -> medium);
-       if (client -> active && client -> state != S_REBOOTING)
-               script_write_params (client, "old_", client -> active);
-       script_write_params (client, "new_", client -> new);
+       script_init(client, (client->state == S_REQUESTING ? "BOUND" :
+                            (client->state == S_RENEWING ? "RENEW" : 
+                             (client->state == S_REBOOTING ? "REBOOT" :
+                              "REBIND"))),
+                   client->new->medium);
+       if (client->active && client->state != S_REBOOTING)
+               script_write_params(client, "old_", client->active);
+       script_write_params (client, "new_", client->new);
        script_write_requested(client);
-       if (client -> alias)
-               script_write_params (client, "alias_", client -> alias);
+       if (client->alias)
+               script_write_params(client, "alias_", client->alias);
 
        /* If the BOUND/RENEW code detects another machine using the
           offered address, it exits nonzero.  We need to send a
           DHCPDECLINE and toss the lease. */
-       if (script_go (client)) {
-               make_decline (client, client -> new);
-               send_decline (client);
-               destroy_client_lease (client -> new);
-               client -> new = (struct client_lease *)0;
-               state_init (client);
-               return;
+       if (script_go(client)) {
+               make_decline(client, client->new);
+               send_decline(client);
+               destroy_client_lease(client->new);
+               client->new = NULL;
+               if (onetry) {
+                       if (!quiet)
+                               log_info("Unable to obtain a lease on first "
+                                        "try (declined).  Exiting.");
+                       exit(2);
+               } else {
+                       state_init(client);
+                       return;
+               }
        }
 
        /* Write out the new lease if it has been long enough. */
@@ -1237,10 +1248,10 @@ void bind_lease (client)
                write_client_lease(client, client->new, 0, 0);
 
        /* Replace the old active lease with the new one. */
-       if (client -> active)
-               destroy_client_lease (client -> active);
-       client -> active = client -> new;
-       client -> new = (struct client_lease *)0;
+       if (client->active)
+               destroy_client_lease(client->active);
+       client->active = client->new;
+       client->new = NULL;
 
        /* Set up a timeout to start the renewal process. */
        tv.tv_sec = client->active->renewal;
@@ -1248,12 +1259,12 @@ void bind_lease (client)
                        random() % 1000000 : cur_tv.tv_usec;
        add_timeout(&tv, state_bound, client, 0, 0);
 
-       log_info ("bound to %s -- renewal in %ld seconds.",
-             piaddr (client -> active -> address),
-             (long)(client -> active -> renewal - cur_time));
-       client -> state = S_BOUND;
-       reinitialize_interfaces ();
-       go_daemon ();
+       log_info("bound to %s -- renewal in %ld seconds.",
+             piaddr(client->active->address),
+             (long)(client->active->renewal - cur_time));
+       client->state = S_BOUND;
+       reinitialize_interfaces();
+       go_daemon();
 #if defined (NSUPDATE)
        if (client->config->do_forward_update)
                dhclient_schedule_updates(client, &client->active->address, 1);
@@ -1638,20 +1649,24 @@ struct client_lease *packet_to_lease (packet, client)
        lease = (struct client_lease *)new_client_lease (MDL);
 
        if (!lease) {
-               log_error ("packet_to_lease: no memory to record lease.\n");
-               return (struct client_lease *)0;
+               log_error("packet_to_lease: no memory to record lease.\n");
+               return NULL;
        }
 
-       memset (lease, 0, sizeof *lease);
+       memset(lease, 0, sizeof(*lease));
 
        /* Copy the lease options. */
-       option_state_reference (&lease -> options, packet -> options, MDL);
+       option_state_reference(&lease->options, packet->options, MDL);
 
-       lease -> address.len = sizeof (packet -> raw -> yiaddr);
-       memcpy (lease -> address.iabuf, &packet -> raw -> yiaddr,
-               lease -> address.len);
+       lease->address.len = sizeof(packet->raw->yiaddr);
+       memcpy(lease->address.iabuf, &packet->raw->yiaddr,
+              lease->address.len);
 
-       memset (&data, 0, sizeof data);
+       lease->next_srv_addr.len = sizeof(packet->raw->siaddr);
+       memcpy(lease->next_srv_addr.iabuf, &packet->raw->siaddr,
+              lease->next_srv_addr.len);
+       
+       memset(&data, 0, sizeof(data));
 
        if (client -> config -> vendor_space_name) {
                i = DHO_VENDOR_ENCAPSULATED_OPTIONS;
@@ -3191,6 +3206,13 @@ void script_write_params (client, prefix, lease)
        client_envadd (client,
                       prefix, "ip_address", "%s", piaddr (lease -> address));
 
+       /* If we've set the next server address in the lease structure
+          put it into an environment variable for the script */
+       if (lease->next_srv_addr.len != 0) {
+               client_envadd(client, prefix, "next_server", "%s",
+                             piaddr(lease->next_srv_addr));
+       }
+
        /* For the benefit of Linux (and operating systems which may
           have similar needs), compute the network address based on
           the supplied ip address and netmask, if provided.  Also
@@ -4194,14 +4216,16 @@ dhcpv4_client_assignments(void)
        if (!local_port) {
                /* If we're faking a relay agent, and we're not using loopback,
                   use the server port, not the client port. */
-               if (mockup_relay && giaddr.s_addr != htonl (INADDR_LOOPBACK)) {
+               if (mockup_relay && giaddr.s_addr != htonl(INADDR_LOOPBACK)) {
                        local_port = htons(67);
                } else {
-                       ent = getservbyname ("dhcpc", "udp");
-                       if (!ent)
-                               local_port = htons (68);
+                       ent = getservbyname("dhcpc", "udp");
+                       if (ent == NULL)
+                               ent = getservbyname("bootpc", "udp");
+                       if (ent == NULL)
+                               local_port = htons(68);
                        else
-                               local_port = ent -> s_port;
+                               local_port = ent->s_port;
 #ifndef __CYGWIN32__
                        endservent ();
 #endif
@@ -4210,10 +4234,10 @@ dhcpv4_client_assignments(void)
 
        /* If we're faking a relay agent, and we're not using loopback,
           we're using the server port, not the client port. */
-       if (mockup_relay && giaddr.s_addr != htonl (INADDR_LOOPBACK)) {
+       if (mockup_relay && giaddr.s_addr != htonl(INADDR_LOOPBACK)) {
                remote_port = local_port;
        } else
-               remote_port = htons (ntohs (local_port) - 1);   /* XXX */
+               remote_port = htons(ntohs(local_port) - 1);   /* XXX */
 }
 
 /*
index b0f73fb47c94ea766d06e3455786a3e3feb016e7..55aa621243eb7f181f60dd21b8df5b6e1c9f19b2 100644 (file)
@@ -1026,6 +1026,7 @@ struct client_lease {
        unsigned int is_bootp: 1;  /* If set, lease was acquired with BOOTP. */
 
        struct option_state *options;        /* Options supplied with lease. */
+       struct iaddr next_srv_addr;     /* Address of the next server to use */
 };
 
 /* DHCPv6 lease structures */