Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/netbsd-1-5]: src/usr.sbin/dhcp/client Pull up revision 1.35 (requested b...



details:   https://anonhg.NetBSD.org/src/rev/3d62de5b8bfa
branches:  netbsd-1-5
changeset: 491091:3d62de5b8bfa
user:      he <he%NetBSD.org@localhost>
date:      Wed Apr 04 20:55:28 2001 +0000

description:
Pull up revision 1.35 (requested by mellon):
  Update DHCP software to ISC version 3, Beta 2, Patchlevel 23.

diffstat:

 usr.sbin/dhcp/client/dhclient.c |  314 +++++++++++++++++++++++++++++----------
 1 files changed, 235 insertions(+), 79 deletions(-)

diffs (truncated from 696 to 300 lines):

diff -r 70d9ff957dae -r 3d62de5b8bfa usr.sbin/dhcp/client/dhclient.c
--- a/usr.sbin/dhcp/client/dhclient.c   Wed Apr 04 20:55:20 2001 +0000
+++ b/usr.sbin/dhcp/client/dhclient.c   Wed Apr 04 20:55:28 2001 +0000
@@ -3,7 +3,7 @@
    DHCP Client. */
 
 /*
- * Copyright (c) 1995-2000 Internet Software Consortium.
+ * Copyright (c) 1995-2001 Internet Software Consortium.
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
@@ -41,7 +41,7 @@
 
 #ifndef lint
 static char ocopyright[] =
-"$Id: dhclient.c,v 1.26.2.7 2000/10/18 04:10:57 tv Exp $ Copyright (c) 1995, 1996, 1997, 1998, 1999 Internet Software Consortium.  All rights reserved.\n";
+"$Id: dhclient.c,v 1.26.2.8 2001/04/04 20:55:28 he Exp $ Copyright (c) 1995-2001 Internet Software Consortium.  All rights reserved.\n";
 #endif /* not lint */
 
 #include "dhcpd.h"
@@ -54,6 +54,8 @@
 const char *path_dhclient_conf = _PATH_DHCLIENT_CONF;
 const char *path_dhclient_db = _PATH_DHCLIENT_DB;
 const char *path_dhclient_pid = _PATH_DHCLIENT_PID;
+static char path_dhclient_script_array [] = _PATH_DHCLIENT_SCRIPT;
+char *path_dhclient_script = path_dhclient_script_array;
 
 int dhcp_max_agent_option_packet_length = 0;
 
@@ -69,15 +71,19 @@
    assert (state_is == state_shouldbe). */
 #define ASSERT_STATE(state_is, state_shouldbe) {}
 
-static const char copyright[] = "Copyright 1995-2000 Internet Software Consortium.";
-static const char arr [] = "All rights reserved.";
-static const char message [] = "Internet Software Consortium DHCP Client";
-static const char url [] = "For info, please visit http://www.isc.org/products/DHCP";;
+static char copyright[] = "Copyright 1995-2001 Internet Software Consortium.";
+static char arr [] = "All rights reserved.";
+static char message [] = "Internet Software Consortium DHCP Client";
+static char url [] = "For info, please visit http://www.isc.org/products/DHCP";;
 
 u_int16_t local_port;
 u_int16_t remote_port;
 int no_daemon;
 int save_scripts;
+struct string_list *client_env;
+int client_env_count;
+int onetry;
+int quiet;
 
 static void usage PROTO ((void));
 
@@ -92,7 +98,6 @@
        struct interface_info *ip;
        struct client_state *client;
        unsigned seed;
-       int quiet = 0;
        char *server = (char *)0;
        char *relay = (char *)0;
        isc_result_t status;
@@ -104,6 +109,7 @@
        int no_dhclient_conf = 0;
        int no_dhclient_db = 0;
        int no_dhclient_pid = 0;
+       int no_dhclient_script = 0;
        char *s;
 
 #ifdef SYSLOG_4_2
@@ -159,6 +165,13 @@
                                 usage ();
                         path_dhclient_db = argv [i];
                        no_dhclient_db = 1;
+               } else if (!strcmp (argv [i], "-sf")) {
+                       if (++i == argc)
+                               usage ();
+                        path_dhclient_script = argv [i];
+                       no_dhclient_script = 1;
+               } else if (!strcmp (argv [i], "-1")) {
+                       onetry = 1;
                } else if (!strcmp (argv [i], "-q")) {
                        quiet = 1;
                        quiet_interface_discovery = 1;
@@ -178,6 +191,20 @@
                        persist = 1;
                } else if (argv [i][0] == '-') {
                    usage ();
+               } else if (!strcmp (argv [i], "-e")) {
+                       struct string_list *tmp;
+                       if (++i == argc)
+                               usage ();
+                       tmp = dmalloc (strlen (argv [i]) + sizeof *tmp, MDL);
+                       if (!tmp)
+                               log_fatal ("No memory for %s", argv [i]);
+                       strcpy (tmp -> string, argv [i]);
+                       tmp -> next = client_env;
+                       client_env = tmp;
+                       client_env_count++;
+               } else if (!strcmp (argv [i], "--version")) {
+                       log_info ("isc-dhclient-%s", DHCP_VERSION);
+                       exit (0);
                } else {
                    struct interface_info *tmp = (struct interface_info *)0;
                    status = interface_allocate (&tmp, MDL);
@@ -185,8 +212,8 @@
                        log_fatal ("Can't record interface %s:%s",
                                   argv [i], isc_result_totext (status));
                    if (strlen (argv [i]) > sizeof tmp -> name)
-                           log_fatal ("%s: interface name too long (max %d)",
-                                      argv [i], strlen (argv [i]));
+                           log_fatal ("%s: interface name too long (max %ld)",
+                                      argv [i], (long)strlen (argv [i]));
                    strcpy (tmp -> name, argv [i]);
                    if (interfaces) {
                            interface_reference (&tmp -> next,
@@ -208,6 +235,9 @@
        if (!no_dhclient_pid && (s = getenv ("PATH_DHCLIENT_PID"))) {
                path_dhclient_pid = s;
        }
+       if (!no_dhclient_script && (s = getenv ("PATH_DHCLIENT_SCRIPT"))) {
+               path_dhclient_script = s;
+       }
 
        /* first kill of any currently running client */
        if (release_mode) {
@@ -248,8 +278,8 @@
 
        /* Default to the DHCP/BOOTP port. */
        if (!local_port) {
-               if (relay && giaddr.s_addr != INADDR_LOOPBACK) {
-                       local_port = 67;
+               if (relay && giaddr.s_addr != htonl (INADDR_LOOPBACK)) {
+                       local_port = htons (67);
                } else {
                        ent = getservbyname ("dhcpc", "udp");
                        if (!ent)
@@ -264,9 +294,10 @@
 
        /* If we're faking a relay agent, and we're not using loopback,
           use the server port, not the client port. */
-       if (relay && giaddr.s_addr != INADDR_LOOPBACK)
-               remote_port = 67;
-       else
+       if (relay && giaddr.s_addr != htonl (INADDR_LOOPBACK)) {
+               local_port = htons (ntohs (local_port) - 1);
+               remote_port = local_port;
+       } else
                remote_port = htons (ntohs (local_port) - 1);   /* XXX */
   
        /* Get the current time... */
@@ -403,6 +434,17 @@
        /* Set up the bootp packet handler... */
        bootp_packet_handler = do_packet;
 
+#if defined (DEBUG_MEMORY_LEAKAGE) || defined (DEBUG_MALLOC_POOL)
+       dmalloc_cutoff_generation = dmalloc_generation;
+       dmalloc_longterm = dmalloc_outstanding;
+       dmalloc_outstanding = 0;
+#endif
+
+       /* If we're not going to daemonize, write the pid file
+          now. */
+       if (no_daemon)
+               write_client_pid_file ();
+
        /* Start dispatching packets and timeouts... */
        dispatch ();
 
@@ -417,10 +459,11 @@
        log_info (arr);
        log_info (url);
 
-       log_error ("Usage: dhclient [-d] [-D] [-q] [-p <port>] %s",
+       log_error ("Usage: dhclient [-1dDqr] [-p <port>] %s",
                   "[-s server]");
-       log_fatal ("                [-lf lease-file] [-pf pid-file]%s",
-                  "[-cf config-file] [interface]");
+       log_error ("                [-cf config-file] [-lf lease-file]%s",
+                  "[-pf pid-file] [-e VAR=val]");
+       log_fatal ("                [-sf script-file] [interface]");
 }
 
 isc_result_t find_class (struct class **c,
@@ -679,7 +722,7 @@
                            DHO_DHCP_LEASE_TIME);
        memset (&ds, 0, sizeof ds);
        if (oc &&
-           evaluate_option_cache (&ds, packet, (struct lease *)0,
+           evaluate_option_cache (&ds, packet, (struct lease *)0, client,
                                   packet -> options, client -> new -> options,
                                   &global_scope, oc, MDL)) {
                if (ds.len > 3)
@@ -709,7 +752,7 @@
        oc = lookup_option (&dhcp_universe, client -> new -> options,
                            DHO_DHCP_RENEWAL_TIME);
        if (oc &&
-           evaluate_option_cache (&ds, packet, (struct lease *)0,
+           evaluate_option_cache (&ds, packet, (struct lease *)0, client,
                                   packet -> options, client -> new -> options,
                                   &global_scope, oc, MDL)) {
                if (ds.len > 3)
@@ -734,7 +777,7 @@
        oc = lookup_option (&dhcp_universe, client -> new -> options,
                            DHO_DHCP_REBINDING_TIME);
        if (oc &&
-           evaluate_option_cache (&ds, packet, (struct lease *)0,
+           evaluate_option_cache (&ds, packet, (struct lease *)0, client,
                                   packet -> options, client -> new -> options,
                                   &global_scope, oc, MDL)) {
                if (ds.len > 3)
@@ -847,7 +890,7 @@
                            DHO_DHCP_SERVER_IDENTIFIER);
        if (oc &&
            evaluate_option_cache (&ds, (struct packet *)0, (struct lease *)0,
-                                  (struct option_state *)0,
+                                  client, (struct option_state *)0,
                                   client -> active -> options,
                                   &global_scope, oc, MDL)) {
                if (ds.len > 3) {
@@ -1070,7 +1113,7 @@
        struct client_state *client;
 {
        struct client_lease *lease;
-       int i;
+       unsigned i;
        struct option_cache *oc;
        struct data_string data;
 
@@ -1090,12 +1133,35 @@
        memcpy (lease -> address.iabuf, &packet -> raw -> yiaddr,
                lease -> address.len);
 
+       if (client -> config -> vendor_space_name) {
+               i = DHO_VENDOR_ENCAPSULATED_OPTIONS;
+
+               /* See if there was a vendor encapsulation option. */
+               oc = lookup_option (&dhcp_universe, lease -> options, i);
+               memset (&data, 0, sizeof data);
+               if (oc &&
+                   client -> config -> vendor_space_name &&
+                   evaluate_option_cache (&data, packet,
+                                          (struct lease *)0, client,
+                                          packet -> options, lease -> options,
+                                          &global_scope, oc, MDL)) {
+                       if (data.len) {
+                               parse_encapsulated_suboptions
+                                       (packet -> options, &dhcp_options [i],
+                                        data.data, data.len, &dhcp_universe,
+                                        client -> config -> vendor_space_name
+                                               );
+                       }
+                       data_string_forget (&data, MDL);
+               }
+       } else
+               i = 0;
+
        /* Figure out the overload flag. */
        oc = lookup_option (&dhcp_universe, lease -> options,
                            DHO_DHCP_OPTION_OVERLOAD);
-       memset (&data, 0, sizeof data);
        if (oc &&
-           evaluate_option_cache (&data, packet, (struct lease *)0,
+           evaluate_option_cache (&data, packet, (struct lease *)0, client,
                                   packet -> options, lease -> options,
                                   &global_scope, oc, MDL)) {
                if (data.len > 0)
@@ -1146,8 +1212,9 @@
 
        execute_statements_in_scope ((struct binding_value **)0,
                                     (struct packet *)packet,
-                                    (struct lease *)0, lease -> options,
-                                    lease -> options, &global_scope,
+                                    (struct lease *)0, client,
+                                    lease -> options, lease -> options,
+                                    &global_scope,
                                     client -> config -> on_receipt,
                                     (struct group *)0);
 
@@ -1251,9 +1318,10 @@
                }
                        
                log_info ("Trying medium \"%s\" %d",
-                     client -> medium -> string, increase);
+                         client -> medium -> string, increase);
                script_init (client, "MEDIUM", client -> medium);
                if (script_go (client)) {
+                       fail = 1;
                        goto again;
                }
        }
@@ -1267,11 +1335,9 @@
                if (!client -> interval)
                        client -> interval =
                                client -> config -> initial_interval;
-               else {
-                       client -> interval +=
-                               ((random () >> 2) %
-                                (2 * client -> interval));
-               }



Home | Main Index | Thread Index | Old Index