]> git.ipfire.org Git - thirdparty/dhcpcd.git/commitdiff
Remove ENABLE_DUID and introduce MINIMAL, which removes all non essential userland...
authorRoy Marples <roy@marples.name>
Fri, 4 Jul 2008 13:02:33 +0000 (13:02 +0000)
committerRoy Marples <roy@marples.name>
Fri, 4 Jul 2008 13:02:33 +0000 (13:02 +0000)
README
client.c
config.h
dhcp.c
dhcpcd.c
dhcpcd.h
net.h

diff --git a/README b/README
index 8a19f7cad7259ff10b65ee0ff645cea706d69853..2fc1dc35f62237471c747ef9cc7099aa0bede66e 100644 (file)
--- a/README
+++ b/README
@@ -15,6 +15,10 @@ If you're cross compiling you may need to set the below knobs to avoid
 automatic tests.
 OS=BSD | Linux
 
+If size is your thing, you can remove all non-essential userland options
+by adding -DMINIMAL to your CFLAGS. This currently shaves off around 6k.
+You can save a futher 600 bytes or so by using the small make target.
+
 If you're building for a NOMMU system where fork() does not work, you should
 add -DTHERE_IS_NO_FORK to your CFLAGS.
 
index 982df4fd495ee1e7da4be4a7512ff7b532d8d5ff..977ed19407f4a857a18320fc1e7726f8a03e75db 100644 (file)
--- a/client.c
+++ b/client.c
@@ -264,7 +264,7 @@ daemonise(struct if_state *state, const struct options *options)
        return -1;
 }
 
-#ifdef ENABLE_DUID
+#ifndef MINIMAL
 #define THIRTY_YEARS_IN_SECONDS    946707779
 static size_t
 get_duid(unsigned char *duid, const struct interface *iface)
@@ -465,8 +465,8 @@ client_setup(struct if_state *state, const struct options *options)
        struct interface *iface = state->interface;
        struct dhcp_lease *lease = &state->lease;
        struct in_addr addr;
+#ifndef MINIMAL
        size_t len = 0;
-#ifdef ENABLE_DUID
        unsigned char *duid = NULL;
        uint32_t ul;
 #endif
@@ -522,12 +522,12 @@ client_setup(struct if_state *state, const struct options *options)
                iface->net.s_addr = lease->net.s_addr;
        }
 
+#ifndef MINIMAL
        if (*options->clientid) {
                iface->clientid = xmalloc(options->clientid[0] + 1);
                memcpy(iface->clientid,
                       options->clientid, options->clientid[0] + 1);
        } else if (options->options & DHCPCD_CLIENTID) {
-#ifdef ENABLE_DUID
                if (options->options & DHCPCD_DUID) {
                        duid = xmalloc(DUID_LEN);
                        if ((len = get_duid(duid, iface)) == 0)
@@ -556,7 +556,6 @@ client_setup(struct if_state *state, const struct options *options)
                        memcpy(iface->clientid + 6, duid, len);
                        free(duid);
                }
-#endif
                if (len == 0) {
                        len = iface->hwlen + 1;
                        iface->clientid = xmalloc(len + 1);
@@ -565,6 +564,7 @@ client_setup(struct if_state *state, const struct options *options)
                        memcpy(iface->clientid + 2, iface->hwaddr, iface->hwlen);
                }
        }
+#endif
 
        return 0;
 }
index a18e3c2798be6a832d8e4a9c5a357ac8e0e82dea..2bb8689131da191c1d7231c958b4c1ca2640d7cf 100644 (file)
--- a/config.h
+++ b/config.h
@@ -42,9 +42,6 @@
 # ifndef DISABLE_IPV4LL
 #  define DISABLE_IPV4LL
 # endif
-# ifndef DISABLE_DUID
-#  define DISABLE_DUID
-# endif
 #endif
 
 /* Enable ARP by default. */
 # define ENABLE_ARP
 #endif
 
-/* Allow dhcpcd to create a DUID (LLT) and use it to make an IAID for the
- * ClientID. Even enabled here, we need a config directive to actually use it
- * so this toggle is just to remove it from dhcpcd to make the binary smaller.
- * You can always create your own DUID file that just contains the
- * hex string that represents the DUID.
- * See RFC 3315 for details on this. */
-#ifndef DISABLE_DUID
-# define ENABLE_DUID
-#endif
-
 /* IPV4LL, aka ZeroConf, aka APIPA, aka RFC 3927.
  * Needs ARP. */
 #ifndef DISABLE_IPV4LL
diff --git a/dhcp.c b/dhcp.c
index 451881c254c9c5da47ae31035502e71ff4225deb..a4c4ce0264af5cf04fd049c8d00c146d656400d7 100644 (file)
--- a/dhcp.c
+++ b/dhcp.c
@@ -707,13 +707,16 @@ make_message(struct dhcp_message **message,
             uint32_t xid, uint8_t type, const struct options *options)
 {
        struct dhcp_message *dhcp;
-       uint8_t *d, *m, *p;
-       const char *c;
+       uint8_t *m, *p;
        uint8_t *n_params = NULL;
        time_t up = uptime() - iface->start_uptime;
        uint32_t ul;
        uint16_t sz;
        const struct dhcp_opt *opt;
+#ifndef MINIMAL
+       uint8_t *d;
+       const char *c;
+#endif
 
        dhcp = xzalloc(sizeof (*dhcp));
        m = (uint8_t *)dhcp;
@@ -774,6 +777,7 @@ make_message(struct dhcp_message **message,
                p += 2;
        }
 
+#ifndef MINIMAL
        if (iface->clientid) {
                *p++ = DHCP_CLIENTID;
                memcpy(p, iface->clientid, iface->clientid[0] + 1);
@@ -793,6 +797,7 @@ make_message(struct dhcp_message **message,
                        p += options->classid[0] + 1;
                }
        }
+#endif
 
        if (type == DHCP_DISCOVER || type == DHCP_REQUEST) {
 #define PUTADDR(_type, _val) \
@@ -825,6 +830,7 @@ make_message(struct dhcp_message **message,
            type == DHCP_INFORM ||
            type == DHCP_REQUEST)
        {
+#ifndef MINIMAL
                if (options->hostname[0]) {
                        if (options->fqdn == FQDN_DISABLE) {
                                *p++ = DHCP_HOSTNAME;
@@ -867,6 +873,7 @@ make_message(struct dhcp_message **message,
                        memcpy(p, options->vendor, options->vendor[0] + 1);
                        p += options->vendor[0] + 1;
                }
+#endif
 
                *p++ = DHCP_PARAMETERREQUESTLIST;
                n_params = p;
index 663785e5554057383ef25e77357559fc80c153ef..9f2f3b324e5f3d874e582e1eaccebcc4c14c8b6b 100644 (file)
--- a/dhcpcd.c
+++ b/dhcpcd.c
@@ -158,10 +158,12 @@ read_pid(const char *pidfile)
 static void
 usage(void)
 {
+#ifndef MINIMAL
        printf("usage: "PACKAGE" [-dknpqxADEGHKLOTV] [-c script] [-f file ] [-h hostname]\n"
               "              [-i classID ] [-l leasetime] [-m metric] [-o option] [-r ipaddr]\n"
               "              [-s ipaddr] [-t timeout] [-u userclass] [-F none|ptr|both]\n"
               "              [-I clientID] [-C hookscript] <interface>\n");
+#endif
 }
 
 static char * 
@@ -206,6 +208,7 @@ add_environ(struct options *options, const char *value, int uniq)
        return newlist[i];
 }
 
+#ifndef MINIMAL
 #define parse_string(buf, len, arg) parse_string_hwaddr(buf, len, arg, 0)
 static ssize_t
 parse_string_hwaddr(char *sbuf, ssize_t slen, char *str, int clid)
@@ -303,6 +306,7 @@ parse_string_hwaddr(char *sbuf, ssize_t slen, char *str, int clid)
        }
        return l;
 }
+#endif
 
 static int
 parse_option(int opt, char *oarg, struct options *options)
@@ -310,13 +314,16 @@ parse_option(int opt, char *oarg, struct options *options)
        int i;
        char *p;
        ssize_t s;
+#ifndef MINIMAL
        struct in_addr addr;
+#endif
 
        switch(opt) {
        case 'c':
                strlcpy(options->script, oarg, sizeof(options->script));
                break;
        case 'h':
+#ifndef MINIMAL
                if (oarg)
                        s = parse_string(options->hostname + 1,
                                         MAXHOSTNAMELEN, oarg);
@@ -327,8 +334,10 @@ parse_option(int opt, char *oarg, struct options *options)
                        return -1;
                }
                options->hostname[0] = (uint8_t)s;
+#endif
                break;
        case 'i':
+#ifndef MINIMAL
                if (oarg)
                        s = parse_string((char *)options->classid + 1,
                                         CLASSID_MAX_LEN, oarg);
@@ -339,8 +348,10 @@ parse_option(int opt, char *oarg, struct options *options)
                        return -1;
                }
                *options->classid = (uint8_t)s;
+#endif
                break;
        case 'l':
+#ifndef MINIMAL
                if (*oarg == '-') {
                        logger(LOG_ERR,
                               "leasetime must be a positive value");
@@ -352,6 +363,7 @@ parse_option(int opt, char *oarg, struct options *options)
                        logger(LOG_ERR, "`%s' out of range", oarg);
                        return -1;
                }
+#endif
                break;
        case 'm':
                options->metric = atoint(oarg);
@@ -412,6 +424,7 @@ parse_option(int opt, char *oarg, struct options *options)
                }
                break;
        case 'u':
+#ifndef MINIMAL
                s = USERCLASS_MAX_LEN - options->userclass[0] - 1;
                s = parse_string((char *)options->userclass + options->userclass[0] + 2,
                                 s, oarg);
@@ -423,8 +436,10 @@ parse_option(int opt, char *oarg, struct options *options)
                        options->userclass[options->userclass[0] + 1] = s;
                        options->userclass[0] += s + 1;
                }
+#endif
                break;
        case 'v':
+#ifndef MINIMAL
                p = strchr(oarg, ',');
                if (!p || !p[1]) {
                        logger(LOG_ERR, "invalid vendor format");
@@ -459,6 +474,7 @@ parse_option(int opt, char *oarg, struct options *options)
                        options->vendor[options->vendor[0] + 2] = s;
                        options->vendor[0] += s + 2;
                }
+#endif
                break;
        case 'A':
                options->options &= ~DHCPCD_ARP;
@@ -482,6 +498,7 @@ parse_option(int opt, char *oarg, struct options *options)
                options->options |= DHCPCD_LASTLEASE;
                break;
        case 'F':
+#ifndef MINIMAL
                if (!oarg) {
                        options->fqdn = FQDN_BOTH;
                        break;
@@ -497,11 +514,13 @@ parse_option(int opt, char *oarg, struct options *options)
                               oarg);
                        return -1;
                }
+#endif
                break;
        case 'G':
                options->options &= ~DHCPCD_GATEWAY;
                break;
        case 'I':
+#ifndef MINIMAL
                /* Strings have a type of 0 */;
                options->classid[1] = 0;
                if (oarg)
@@ -518,6 +537,7 @@ parse_option(int opt, char *oarg, struct options *options)
                        options->options &= ~DHCPCD_DUID;
                        options->options &= ~DHCPCD_CLIENTID;
                }
+#endif
                break;
        case 'K':
                options->options &= ~DHCPCD_DAEMONISE;
@@ -579,11 +599,14 @@ main(int argc, char **argv)
        openlog(PACKAGE, LOG_PID, LOG_LOCAL0);
 
        options = xzalloc(sizeof(*options));
+       options->options |= DHCPCD_GATEWAY | DHCPCD_DAEMONISE;
+#ifndef MINIMAL
+       options->options |= DHCPCD_CLIENTID;
        strlcpy(options->script, SCRIPT, sizeof(options->script));
        options->classid[0] = snprintf((char *)options->classid + 1, CLASSID_MAX_LEN,
                                       "%s %s", PACKAGE, VERSION);
 
-       options->options |= DHCPCD_CLIENTID | DHCPCD_GATEWAY | DHCPCD_DAEMONISE;
+#endif
 #ifdef ENABLE_ARP
        options->options |= DHCPCD_ARP;
  #ifdef ENABLE_IPV4LL
@@ -602,12 +625,10 @@ main(int argc, char **argv)
 
        /* If the duid file exists, then enable duid by default
         * This means we don't break existing clients that easily :) */
-# ifdef ENABLE_DUID
        if ((f = fopen(DUID, "r"))) {
                options->options |= DHCPCD_DUID;
                fclose(f);
        }
-# endif
 #endif
 
 #ifdef THERE_IS_NO_FORK
@@ -620,11 +641,13 @@ main(int argc, char **argv)
        }
 #endif
 
+#ifndef MINIMAL
        gethostname(options->hostname + 1, sizeof(options->hostname));
        if (strcmp(options->hostname + 1, "(none)") == 0 ||
            strcmp(options->hostname + 1, "localhost") == 0)
                options->hostname[1] = '\0';
        *options->hostname = strlen(options->hostname + 1);
+#endif
 
        while ((opt = getopt_long(argc, argv, OPTS EXTRA_OPTS,
                                  longopts, &option_index)) != -1)
@@ -654,12 +677,12 @@ main(int argc, char **argv)
 #ifdef ENABLE_ARP
                       " ARP"
 #endif
-#ifdef ENABLE_DUID
-                      " DUID"
-#endif
 #ifdef ENABLE_IPV4LL
                       " IPV4LL"
 #endif
+#ifdef MINIMAL
+                      " MINIMAL"
+#endif
 #ifdef THERE_IS_NO_FORK
                       " THERE_IS_NO_FORK"
 #endif
@@ -821,6 +844,7 @@ main(int argc, char **argv)
                }
        }
 
+#ifndef MINIMAL
        if ((p = strchr(options->hostname, '.'))) {
                if (options->fqdn == FQDN_DISABLE)
                        *p = '\0';
@@ -833,6 +857,7 @@ main(int argc, char **argv)
        }
        if (options->fqdn != FQDN_DISABLE)
                del_reqmask(options->reqmask, DHCP_HOSTNAME);
+#endif
 
        if (options->request_address.s_addr == 0 &&
            (options->options & DHCPCD_INFORM ||
@@ -947,11 +972,13 @@ main(int argc, char **argv)
                logger(LOG_INFO, PACKAGE " " VERSION " starting");
        }
 
+#ifndef MINIMAL
        /* Terminate the encapsulated options */
        if (options->vendor[0]) {
                options->vendor[0]++;
                options->vendor[options->vendor[0]] = DHCP_END;
        }
+#endif
 
        if (dhcp_run(options, &pid_fd) == 0)
                retval = EXIT_SUCCESS;
index 4f2c841c607f4399cf185dba36d36309657367d8..10d23ffb97603fa3671b3b857a6d9015b849c4c7 100644 (file)
--- a/dhcpcd.h
+++ b/dhcpcd.h
@@ -71,17 +71,11 @@ extern char *dhcpcd_skiproutes;
 
 struct options {
        char interface[IF_NAMESIZE];
-       char hostname[MAXHOSTNAMELEN];
-       int fqdn;
-       uint8_t classid[CLASSID_MAX_LEN + 1];
-       char clientid[CLIENTID_MAX_LEN + 1];
-       uint8_t userclass[USERCLASS_MAX_LEN + 1];
-       uint8_t vendor[VENDOR_MAX_LEN + 1];
+       int metric;
        uint8_t reqmask[256 / 8];
        uint8_t nomask[256 / 8];
        uint32_t leasetime;
        time_t timeout;
-       int metric;
        int options;
 
        struct in_addr request_address;
@@ -90,6 +84,15 @@ struct options {
        char **environ;
        char script[PATH_MAX];
        char pidfile[PATH_MAX];
+
+#ifndef MINIMAL
+       char hostname[MAXHOSTNAMELEN];
+       int fqdn;
+       uint8_t classid[CLASSID_MAX_LEN + 1];
+       char clientid[CLIENTID_MAX_LEN + 1];
+       uint8_t userclass[USERCLASS_MAX_LEN + 1];
+       uint8_t vendor[VENDOR_MAX_LEN + 1];
+#endif
 };
 
 #endif
diff --git a/net.h b/net.h
index 5f98b5261121bed84081efe93165eac399e294d6..0be56cf542b9517aef985f5844df9e12d30f36e0 100644 (file)
--- a/net.h
+++ b/net.h
 
 #include "config.h"
 
-#ifdef ENABLE_DUID
 #ifndef DUID_LEN
 #  define DUID_LEN                     128 + 2
 #endif
-#endif
 
 #define EUI64_ADDR_LEN                 8
 #define INFINIBAND_ADDR_LEN            20