From: Roy Marples Date: Fri, 4 Jul 2008 13:02:33 +0000 (+0000) Subject: Remove ENABLE_DUID and introduce MINIMAL, which removes all non essential userland... X-Git-Tag: v4.0.2~241 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=b953fded8ba0795e58a6a49b8cd4ecccce1ca2c8;p=thirdparty%2Fdhcpcd.git Remove ENABLE_DUID and introduce MINIMAL, which removes all non essential userland options, knocking around 6k off the binary size. --- diff --git a/README b/README index 8a19f7ca..2fc1dc35 100644 --- 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. diff --git a/client.c b/client.c index 982df4fd..977ed194 100644 --- 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; } diff --git a/config.h b/config.h index a18e3c27..2bb86891 100644 --- 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. */ @@ -52,16 +49,6 @@ # 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 451881c2..a4c4ce02 100644 --- 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; diff --git a/dhcpcd.c b/dhcpcd.c index 663785e5..9f2f3b32 100644 --- 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] \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; diff --git a/dhcpcd.h b/dhcpcd.h index 4f2c841c..10d23ffb 100644 --- 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 5f98b526..0be56cf5 100644 --- a/net.h +++ b/net.h @@ -40,11 +40,9 @@ #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