Source-Changes-HG archive

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

[src/trunk]: src/external/bsd/dhcpcd/dist Sync



details:   https://anonhg.NetBSD.org/src/rev/7beb85f42630
branches:  trunk
changeset: 325710:7beb85f42630
user:      roy <roy%NetBSD.org@localhost>
date:      Fri Jan 03 22:24:41 2014 +0000

description:
Sync

diffstat:

 external/bsd/dhcpcd/dist/dhcp.c           |  540 +++++++++-----------
 external/bsd/dhcpcd/dist/dhcpcd.8.in      |   23 +-
 external/bsd/dhcpcd/dist/dhcpcd.conf.5.in |  201 +++++++-
 external/bsd/dhcpcd/dist/if-bsd.c         |    4 +-
 external/bsd/dhcpcd/dist/if-options.c     |  762 ++++++++++++++++++++++++-----
 external/bsd/dhcpcd/dist/ipv6nd.c         |   39 +-
 external/bsd/dhcpcd/dist/net.c            |    4 +-
 7 files changed, 1117 insertions(+), 456 deletions(-)

diffs (truncated from 2412 to 300 lines):

diff -r 655fec849b2a -r 7beb85f42630 external/bsd/dhcpcd/dist/dhcp.c
--- a/external/bsd/dhcpcd/dist/dhcp.c   Fri Jan 03 22:10:42 2014 +0000
+++ b/external/bsd/dhcpcd/dist/dhcp.c   Fri Jan 03 22:24:41 2014 +0000
@@ -1,5 +1,5 @@
 #include <sys/cdefs.h>
- __RCSID("$NetBSD: dhcp.c,v 1.7 2013/09/20 10:56:32 roy Exp $");
+ __RCSID("$NetBSD: dhcp.c,v 1.8 2014/01/03 22:24:41 roy Exp $");
 
 /*
  * dhcpcd - DHCP client daemon
@@ -107,107 +107,6 @@
        { 0, NULL }
 };
 
-const struct dhcp_opt dhcp_opts[] = {
-       { 1,    ADDRIPV4 | REQUEST,     "subnet_mask" },
-               /* RFC 3442 states that the CSR has to come before all other
-                * routes. For completeness, we also specify static routes,
-                * then routers. */
-       { 121,  RFC3442,        "classless_static_routes" },
-       { 249,  RFC3442,        "ms_classless_static_routes" },
-       { 33,   IPV4A | REQUEST,        "static_routes" },
-       { 3,    IPV4A | REQUEST,        "routers" },
-       { 2,    UINT32,         "time_offset" },
-       { 4,    IPV4A,          "time_servers" },
-       { 5,    IPV4A,          "ien116_name_servers" },
-       { 6,    IPV4A,          "domain_name_servers" },
-       { 7,    IPV4A,          "log_servers" },
-       { 8,    IPV4A,          "cookie_servers" },
-       { 9,    IPV4A,          "lpr_servers" },
-       { 10,   IPV4A,          "impress_servers" },
-       { 11,   IPV4A,          "resource_location_servers" },
-       { 12,   STRING,         "host_name" },
-       { 13,   UINT16,         "boot_size" },
-       { 14,   STRING,         "merit_dump" },
-       { 15,   STRING,         "domain_name" },
-       { 16,   ADDRIPV4,       "swap_server" },
-       { 17,   STRING,         "root_path" },
-       { 18,   STRING,         "extensions_path" },
-       { 19,   UINT8,          "ip_forwarding" },
-       { 20,   UINT8,          "non_local_source_routing" },
-       { 21,   IPV4A,  "policy_filter" },
-       { 22,   SINT16,         "max_dgram_reassembly" },
-       { 23,   UINT16,         "default_ip_ttl" },
-       { 24,   UINT32,         "path_mtu_aging_timeout" },
-       { 25,   UINT16 | ARRAY, "path_mtu_plateau_table" },
-       { 26,   UINT16,         "interface_mtu" },
-       { 27,   UINT8,          "all_subnets_local" },
-       { 28,   ADDRIPV4 | REQUEST,     "broadcast_address" },
-       { 29,   UINT8,          "perform_mask_discovery" },
-       { 30,   UINT8,          "mask_supplier" },
-       { 31,   UINT8,          "router_discovery" },
-       { 32,   ADDRIPV4,       "router_solicitation_address" },
-       { 34,   UINT8,          "trailer_encapsulation" },
-       { 35,   UINT32,         "arp_cache_timeout" },
-       { 36,   UINT16,         "ieee802_3_encapsulation" },
-       { 37,   UINT8,          "default_tcp_ttl" },
-       { 38,   UINT32,         "tcp_keepalive_interval" },
-       { 39,   UINT8,          "tcp_keepalive_garbage" },
-       { 40,   STRING,         "nis_domain" },
-       { 41,   IPV4A,          "nis_servers" },
-       { 42,   IPV4A,          "ntp_servers" },
-       { 43,   STRING,         "vendor_encapsulated_options" },
-       { 44,   IPV4A,          "netbios_name_servers" },
-       { 45,   ADDRIPV4,       "netbios_dd_server" },
-       { 46,   UINT8,          "netbios_node_type" },
-       { 47,   STRING,         "netbios_scope" },
-       { 48,   IPV4A,          "font_servers" },
-       { 49,   IPV4A,          "x_display_manager" },
-       { 50,   ADDRIPV4,       "dhcp_requested_address" },
-       { 51,   UINT32 | REQUEST,       "dhcp_lease_time" },
-       { 52,   UINT8,          "dhcp_option_overload" },
-       { 53,   UINT8,          "dhcp_message_type" },
-       { 54,   ADDRIPV4,       "dhcp_server_identifier" },
-       { 55,   UINT8 | ARRAY,  "dhcp_parameter_request_list" },
-       { 56,   STRING,         "dhcp_message" },
-       { 57,   UINT16,         "dhcp_max_message_size" },
-       { 58,   UINT32 | REQUEST,       "dhcp_renewal_time" },
-       { 59,   UINT32 | REQUEST,       "dhcp_rebinding_time" },
-       { 64,   STRING,         "nisplus_domain" },
-       { 65,   IPV4A,          "nisplus_servers" },
-       { 66,   STRING,         "tftp_server_name" },
-       { 67,   STRING,         "bootfile_name" },
-       { 68,   IPV4A,          "mobile_ip_home_agent" },
-       { 69,   IPV4A,          "smtp_server" },
-       { 70,   IPV4A,          "pop_server" },
-       { 71,   IPV4A,          "nntp_server" },
-       { 72,   IPV4A,          "www_server" },
-       { 73,   IPV4A,          "finger_server" },
-       { 74,   IPV4A,          "irc_server" },
-       { 75,   IPV4A,          "streettalk_server" },
-       { 76,   IPV4A,          "streettalk_directory_assistance_server" },
-       { 77,   STRING,         "user_class" },
-       { 80,   FLAG | NOREQ,   "rapid_commit" },
-       { 81,   STRING | RFC3397,       "fqdn" },
-       { 85,   IPV4A,          "nds_servers" },
-       { 86,   STRING,         "nds_tree_name" },
-       { 87,   STRING,         "nds_context" },
-       { 88,   STRING | RFC3397,       "bcms_controller_names" },
-       { 89,   IPV4A,          "bcms_controller_address" },
-       { 91,   UINT32,         "client_last_transaction_time" },
-       { 92,   IPV4A,          "associated_ip" },
-       { 98,   STRING,         "uap_servers" },
-       { 100,  STRING,         "posix_timezone" },
-       { 101,  STRING,         "tzdb_timezone" },
-       { 112,  IPV4A,          "netinfo_server_address" },
-       { 113,  STRING,         "netinfo_server_tag" },
-       { 114,  STRING,         "default_url" },
-       { 118,  ADDRIPV4,       "subnet_selection" },
-       { 119,  STRING | RFC3397,       "domain_search" },
-       { 120,  STRING | RFC3361,       "sip_server" },
-       { 212,  RFC5969,        "sixrd" },
-       { 0, 0, NULL }
-};
-
 static const char *dhcp_params[] = {
        "ip_address",
        "subnet_cidr",
@@ -223,6 +122,10 @@
        struct udphdr udp;
        struct dhcp_message dhcp;
 };
+
+struct dhcp_opt *dhcp_opts = NULL;
+size_t dhcp_opts_len = 0;
+
 static const size_t udp_dhcp_len = sizeof(struct udp_dhcp_packet);
 
 static int dhcp_open(struct interface *);
@@ -230,63 +133,20 @@
 void
 dhcp_printoptions(void)
 {
+       const char **p;
+       size_t i;
        const struct dhcp_opt *opt;
-       const char **p;
 
        for (p = dhcp_params; *p; p++)
                printf("    %s\n", *p);
 
-       for (opt = dhcp_opts; opt->option; opt++)
-               if (opt->var)
-                       printf("%03d %s\n", opt->option, opt->var);
-}
-
-static int
-validate_length(uint8_t option, int dl, int *type)
-{
-       const struct dhcp_opt *opt;
-       ssize_t sz;
-
-       if (dl == 0)
-               return -1;
-
-       for (opt = dhcp_opts; opt->option; opt++) {
-               if (opt->option != option)
-                       continue;
-
-               if (type)
-                       *type = opt->type;
-
-               if (opt->type == 0 ||
-                   opt->type & (STRING | RFC3442 | RFC5969))
-                       return dl;
-
-               if (opt->type & ADDRIPV4 && opt->type & ARRAY) {
-                       if (dl < (int)sizeof(uint32_t))
-                               return -1;
-                       return dl - (dl % sizeof(uint32_t));
-               }
-
-               sz = 0;
-               if (opt->type & (UINT32 | ADDRIPV4))
-                       sz = sizeof(uint32_t);
-               if (opt->type & UINT16)
-                       sz = sizeof(uint16_t);
-               if (opt->type & UINT8)
-                       sz = sizeof(uint8_t);
-               /* If we don't know the size, assume it's valid */
-               if (sz == 0)
-                       return dl;
-               return (dl < sz ? -1 : sz);
-       }
-
-       /* unknown option, so let it pass */
-       return dl;
+       for (i = 0, opt = dhcp_opts; i < dhcp_opts_len; i++, opt++)
+               printf("%03d %s\n", opt->option, opt->var);
 }
 
 #ifdef DEBUG_MEMORY
 static void
-free_option_buffer(void)
+dhcp_cleanup(void)
 {
 
        free(packet);
@@ -294,9 +154,9 @@
 }
 #endif
 
-#define get_option_raw(dhcp, opt) get_option(dhcp, opt, NULL, NULL)
+#define get_option_raw(dhcp, opt) get_option(dhcp, opt, NULL)
 static const uint8_t *
-get_option(const struct dhcp_message *dhcp, uint8_t opt, int *len, int *type)
+get_option(const struct dhcp_message *dhcp, uint8_t opt, int *len)
 {
        const uint8_t *p = dhcp->options;
        const uint8_t *e = p + sizeof(dhcp->options);
@@ -305,7 +165,7 @@
        uint8_t overl = 0;
        uint8_t *bp = NULL;
        const uint8_t *op = NULL;
-       ssize_t bl = 0;
+       int bl = 0;
 
        while (p < e) {
                o = *p++;
@@ -315,9 +175,6 @@
                                        opt_buffer = malloc(sizeof(*dhcp));
                                        if (opt_buffer == NULL)
                                                return NULL;
-#ifdef DEBUG_MEMORY
-                                       atexit(free_option_buffer);
-#endif
                                }
                                if (!bp)
                                        bp = opt_buffer;
@@ -325,6 +182,10 @@
                                bp += ol;
                        }
                        ol = *p;
+                       if (p + ol > e) {
+                               errno = EINVAL;
+                               return NULL;
+                       }
                        op = p + 1;
                        bl += ol;
                }
@@ -356,12 +217,6 @@
        }
 
 exit:
-
-       bl = validate_length(opt, bl, type);
-       if (bl == -1) {
-               errno = EINVAL;
-               return NULL;
-       }
        if (len)
                *len = bl;
        if (bp) {
@@ -378,46 +233,40 @@
 get_option_addr(struct in_addr *a, const struct dhcp_message *dhcp,
     uint8_t option)
 {
-       const uint8_t *p = get_option_raw(dhcp, option);
+       const uint8_t *p;
+       int len;
 
-       if (!p)
+       p = get_option(dhcp, option, &len);
+       if (!p || len < (ssize_t)sizeof(a->s_addr))
                return -1;
        memcpy(&a->s_addr, p, sizeof(a->s_addr));
        return 0;
 }
 
-int
+static int
 get_option_uint32(uint32_t *i, const struct dhcp_message *dhcp, uint8_t option)
 {
-       const uint8_t *p = get_option_raw(dhcp, option);
+       const uint8_t *p;
+       int len;
        uint32_t d;
 
-       if (!p)
+       p = get_option(dhcp, option, &len);
+       if (!p || len < (ssize_t)sizeof(d))
                return -1;
        memcpy(&d, p, sizeof(d));
-       *i = ntohl(d);
+       if (i)
+               *i = ntohl(d);
        return 0;
 }
 
-int
-get_option_uint16(uint16_t *i, const struct dhcp_message *dhcp, uint8_t option)
-{
-       const uint8_t *p = get_option_raw(dhcp, option);
-       uint16_t d;
-
-       if (!p)
-               return -1;
-       memcpy(&d, p, sizeof(d));
-       *i = ntohs(d);
-       return 0;



Home | Main Index | Thread Index | Old Index