From: Roy Marples Date: Fri, 9 Sep 2016 09:56:26 +0000 (+0000) Subject: Add the --small configure option which currently removes non essential options X-Git-Tag: v6.11.4~33 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=98cc5e0b723fa5b40711f5529d240510dfdb09bb;p=thirdparty%2Fdhcpcd.git Add the --small configure option which currently removes non essential options from being parsed out into dhcpcd-run-hooks and removes support for DHCPv6 Prefix Delegation. This is mainly to build a tiny dhcpcd for install media size there are more extreme space limitations. --- diff --git a/Makefile b/Makefile index b960a120..a73fd34d 100644 --- a/Makefile +++ b/Makefile @@ -15,6 +15,7 @@ CSTD?= c99 CFLAGS+= -std=${CSTD} SRCS+= ${DHCPCD_SRCS} +DHCPCD_DEFS?= dhcpcd-definitions.conf SRCS+= auth.c CPPFLAGS+= -I./crypt @@ -85,10 +86,10 @@ dev: CLEANFILES+= dhcpcd-embedded.h dhcpcd-embedded.c -dhcpcd-embedded.h: genembedh dhcpcd-definitions.conf dhcpcd-embedded.h.in +dhcpcd-embedded.h: genembedh ${DHCPCD_DEFS} dhcpcd-embedded.h.in ${HOST_SH} ${.ALLSRC} $^ > $@ -dhcpcd-embedded.c: genembedc dhcpcd-definitions.conf dhcpcd-embedded.h +dhcpcd-embedded.c: genembedc ${DHCPCD_DEFS} dhcpcd-embedded.h ${HOST_SH} ${.ALLSRC} $^ > $@ if-options.c: dhcpcd-embedded.h @@ -104,9 +105,9 @@ ${PROG}: ${DEPEND} ${OBJS} test: cd $@; ${MAKE} $@; ./$@ -_embeddedinstall: dhcpcd-definitions.conf +_embeddedinstall: ${DHCPCD_DEFS} ${INSTALL} -d ${DESTDIR}${SCRIPTSDIR} - ${INSTALL} -m ${CONFMODE} dhcpcd-definitions.conf ${DESTDIR}${SCRIPTSDIR} + ${INSTALL} -m ${CONFMODE} ${DHCPCD_DEFS} ${DESTDIR}${SCRIPTSDIR} _proginstall: ${PROG} ${INSTALL} -d ${DESTDIR}${SBINDIR} diff --git a/README b/README index b9d7517d..ec3e0df8 100644 --- a/README +++ b/README @@ -12,6 +12,13 @@ man dhcpcd-run-hooks to learn how to hook scripts into dhcpcd events Notes ----- +To compile small dhcpcd, maybe to be used for installation media where +size is a concern, you can use the --small configure option to enable +a reduced feature set within dhcpcd. +Currently this just removes non important options out of +dhcpcd-definitions.conf and removes support for DHCPv6 Prefix Delegation. +Other features maybe dropped as and when required. + If you're cross compiling you may need set the platform if OS is different from the host. --target=sparc-sun-netbsd5.0 diff --git a/arp.c b/arp.c index 04cfc17b..330ea092 100644 --- a/arp.c +++ b/arp.c @@ -445,6 +445,8 @@ arp_handleifa(int cmd, struct ipv4_addr *addr) struct iarp_state *state; struct arp_state *astate, *asn; + /* If the address is deleted, the ARP state should be freed by the + * state owner, such as DHCP or IPv4LL. */ if (cmd != RTM_NEWADDR || (state = ARP_STATE(addr->iface)) == NULL) return; diff --git a/configure b/configure index a6ed2f29..0f2e2341 100755 --- a/configure +++ b/configure @@ -24,8 +24,11 @@ STATIC= DEVS= EMBEDDED= POLL= +SMALL= STATUSARG= +DHCPCD_DEFS=dhcpcd-definitions.conf + for x do opt=${x%%=*} var=${x#*=} @@ -81,6 +84,7 @@ for x do --serviceexists) SERVICEEXISTS=$var;; --servicecmd) SERVICECMD=$var;; --servicestatus) SERVICESTATUS=$var;; + --small) SMALL=yes;; --statusarg) STATUSARG=$var;; --infodir|--includedir) ;; # ignore autotools --disable-maintainer-mode|--disable-dependency-tracking) ;; @@ -372,6 +376,13 @@ if [ -n "$FORK" -a "$FORK" != yes -a "$FORK" != true ]; then echo "CPPFLAGS+= -DTHERE_IS_NO_FORK" >>$CONFIG_MK fi +if [ "$SMALL" = yes ]; then + echo "Building with -DSMALL" + echo "CPPFLAGS+= -DSMALL" >>$CONFIG_MK + DHCPCD_DEFS=dhcpcd-definitions-small.conf + echo "DHCPCD_DEFS= $DHCPCD_DEFS" >>$CONFIG_MK +fi + case "$OS" in freebsd*|kfreebsd*) # FreeBSD hide some newer POSIX APIs behind _GNU_SOURCE ... @@ -461,10 +472,10 @@ fi $CC --version | $SED -e '1!d' if [ -z "$EMBEDDED" -o "$EMBEDDED" = yes ]; then - echo "dhcpcd-definitions.conf will be embedded in dhcpcd itself" + echo "$DHCPCD_DEFS will be embedded in dhcpcd itself" echo "DHCPCD_SRCS+= dhcpcd-embedded.c" >>$CONFIG_MK else - echo "dhcpcd-definitions.conf will be installed to $LIBEXECDIR" + echo "$DHCPCD_DEFS will be installed to $LIBEXECDIR" echo "CPPFLAGS+= -DEMBEDDED_CONFIG=\\\"$LIBEXECDIR/dhcpcd-definitions.conf\\\"" >>$CONFIG_MK echo "EMBEDDEDINSTALL= _embeddedinstall" >>$CONFIG_MK fi diff --git a/dhcp6.c b/dhcp6.c index 5f183e56..233a5f23 100644 --- a/dhcp6.c +++ b/dhcp6.c @@ -357,6 +357,7 @@ dhcp6_newxid(const struct interface *ifp, struct dhcp6_message *m) m->xid[2] = xid & 0xff; } +#ifndef SMALL static const struct if_sla * dhcp6_findselfsla(struct interface *ifp, const uint8_t *iaid) { @@ -489,28 +490,33 @@ dhcp6_delegateaddr(struct in6_addr *addr, struct interface *ifp, return sla->prefix_len; } +#endif static int dhcp6_makemessage(struct interface *ifp) { struct dhcp6_state *state; struct dhcp6_message *m; - struct dhcp6_option *o, *so, *eo; + struct dhcp6_option *o, *so; const struct dhcp6_option *si, *unicast; size_t l, n, len, ml; - uint8_t u8, type; + uint8_t type; uint16_t u16, n_options, auth_len; struct if_options *ifo; const struct dhcp_opt *opt, *opt2; uint8_t IA, *p; - const uint8_t *pp; uint32_t u32; const struct ipv6_addr *ap; char hbuf[HOSTNAME_MAX_LEN + 1]; const char *hostname; int fqdn; struct dhcp6_ia_addr *iap; +#ifndef SMALL + struct dhcp6_option *eo; struct dhcp6_pd_addr *pdp; + uint8_t u8; + const uint8_t *pp; +#endif state = D6_STATE(ifp); if (state->send) { @@ -558,6 +564,7 @@ dhcp6_makemessage(struct interface *ifp) len += sizeof(u16); } } +#ifndef SMALL for (l = 0, opt = ifo->dhcp6_override; l < ifo->dhcp6_override_len; l++, opt++) @@ -574,6 +581,7 @@ dhcp6_makemessage(struct interface *ifp) n_options++; len += sizeof(u16); } +#endif if (len) len += sizeof(*o); @@ -627,6 +635,7 @@ dhcp6_makemessage(struct interface *ifp) !(ap->flags & IPV6_AF_REQUEST)) continue; if (ap->ia_type == D6_OPTION_IA_PD) { +#ifndef SMALL len += sizeof(*o) + sizeof(u8) + sizeof(u32) + sizeof(u32) + sizeof(ap->prefix); @@ -634,6 +643,7 @@ dhcp6_makemessage(struct interface *ifp) len += sizeof(*o) + 1 + (uint8_t)((ap->prefix_exclude_len - ap->prefix_len - 1) / NBBY) + 1; +#endif } else len += sizeof(*o) + sizeof(ap->addr) + sizeof(u32) + sizeof(u32); @@ -768,6 +778,7 @@ dhcp6_makemessage(struct interface *ifp) continue; so = D6_NEXT_OPTION(o); if (ap->ia_type == D6_OPTION_IA_PD) { +#ifndef SMALL so->code = htons(D6_OPTION_IAPREFIX); so->len = htons(sizeof(ap->prefix) + sizeof(u32) + sizeof(u32) + sizeof(u8)); @@ -806,6 +817,7 @@ dhcp6_makemessage(struct interface *ifp) u16 = (uint16_t)(ntohs(o->len) + sizeof(*so) + ntohs(so->len)); o->len = htons(u16); +#endif } else { so->code = htons(D6_OPTION_IA_ADDR); so->len = sizeof(ap->addr) + @@ -862,6 +874,7 @@ dhcp6_makemessage(struct interface *ifp) l < ifp->ctx->dhcp6_opts_len; l++, opt++) { +#ifndef SMALL for (n = 0, opt2 = ifo->dhcp6_override; n < ifo->dhcp6_override_len; n++, opt2++) @@ -871,6 +884,7 @@ dhcp6_makemessage(struct interface *ifp) } if (n < ifo->dhcp6_override_len) continue; +#endif if (!(opt->type & OT_NOREQ) && (opt->type & OT_REQUEST || has_option_mask(ifo->requestmask6, @@ -882,6 +896,7 @@ dhcp6_makemessage(struct interface *ifp) o->len = (uint16_t)(o->len+sizeof(u16)); } } +#ifndef SMALL for (l = 0, opt = ifo->dhcp6_override; l < ifo->dhcp6_override_len; l++, opt++) @@ -902,6 +917,7 @@ dhcp6_makemessage(struct interface *ifp) memcpy(p, &u16, sizeof(u16)); o->len = (uint16_t)(o->len + sizeof(u16)); } +#endif o->len = htons(o->len); } } @@ -942,6 +958,7 @@ dhcp6_freedrop_addrs(struct interface *ifp, int drop, } } +#ifndef SMALL static void dhcp6_delete_delegates(struct interface *ifp) { struct interface *ifp0; @@ -953,6 +970,7 @@ static void dhcp6_delete_delegates(struct interface *ifp) } } } +#endif static ssize_t dhcp6_update_auth(struct interface *ifp, struct dhcp6_message *m, size_t len) @@ -1371,7 +1389,9 @@ dhcp6_startdiscover(void *arg) struct dhcp6_state *state; ifp = arg; +#ifndef SMALL dhcp6_delete_delegates(ifp); +#endif logger(ifp->ctx, LOG_INFO, "%s: soliciting a DHCPv6 lease", ifp->name); state = D6_STATE(ifp); state->state = DH6S_DISCOVER; @@ -1426,6 +1446,9 @@ dhcp6_failrequest(void *arg) dhcp6_startdiscover(ifp); } +#ifdef SMALL +#define dhcp6_hasprefixdelegation(a) (0) +#else static void dhcp6_failrebind(void *arg) { @@ -1441,7 +1464,6 @@ dhcp6_failrebind(void *arg) dhcp6_startdiscover(ifp); } - static int dhcp6_hasprefixdelegation(struct interface *ifp) { @@ -1459,13 +1481,16 @@ dhcp6_hasprefixdelegation(struct interface *ifp) } return t == D6_OPTION_IA_PD ? 1 : 0; } +#endif static void dhcp6_startrebind(void *arg) { struct interface *ifp; struct dhcp6_state *state; +#ifndef SMALL int pd; +#endif ifp = arg; eloop_timeout_delete(ifp->ctx->eloop, dhcp6_sendrenew, ifp); @@ -1480,13 +1505,16 @@ dhcp6_startrebind(void *arg) state->RTC = 0; state->MRC = 0; +#ifndef SMALL /* RFC 3633 section 12.1 */ pd = dhcp6_hasprefixdelegation(ifp); if (pd) { state->IMD = CNF_MAX_DELAY; state->IRT = CNF_TIMEOUT; state->MRT = CNF_MAX_RT; - } else { + } else +#endif + { state->IRT = REB_TIMEOUT; state->MRT = REB_MAX_RT; } @@ -1497,10 +1525,12 @@ dhcp6_startrebind(void *arg) else dhcp6_sendrebind(ifp); +#ifndef SMALL /* RFC 3633 section 12.1 */ if (pd) eloop_timeout_add_sec(ifp->ctx->eloop, CNF_MAX_RD, dhcp6_failrebind, ifp); +#endif } @@ -1587,7 +1617,9 @@ dhcp6_startexpire(void *arg) logger(ifp->ctx, LOG_ERR, "%s: DHCPv6 lease expired", ifp->name); dhcp6_freedrop_addrs(ifp, 1, NULL); +#ifndef SMALL dhcp6_delete_delegates(ifp); +#endif script_runreason(ifp, "EXPIRE6"); if (ipv6nd_hasradhcp(ifp) || dhcp6_hasprefixdelegation(ifp)) dhcp6_startdiscover(ifp); @@ -1823,6 +1855,7 @@ dhcp6_findna(struct interface *ifp, uint16_t ot, const uint8_t *iaid, return i; } +#ifndef SMALL static int dhcp6_findpd(struct interface *ifp, const uint8_t *iaid, const uint8_t *d, size_t l, const struct timespec *acquired) @@ -1965,6 +1998,7 @@ dhcp6_findpd(struct interface *ifp, const uint8_t *iaid, } return i; } +#endif static int dhcp6_findia(struct interface *ifp, const struct dhcp6_message *m, size_t l, @@ -2077,12 +2111,14 @@ dhcp6_findia(struct interface *ifp, const struct dhcp6_message *m, size_t l, continue; } if (code == D6_OPTION_IA_PD) { +#ifndef SMALL if (dhcp6_findpd(ifp, iaid, p, ol, acquired) == 0) { logger(ifp->ctx, LOG_WARNING, "%s: %s: DHCPv6 REPLY missing Prefix", ifp->name, sfrom); continue; } +#endif } else { if (dhcp6_findna(ifp, code, iaid, p, ol, acquired) == 0) { @@ -2326,9 +2362,11 @@ dhcp6_startinit(struct interface *ifp) ifp->name, state->leasefile); } else if (r != 0) { /* RFC 3633 section 12.1 */ +#ifndef SMALL if (dhcp6_hasprefixdelegation(ifp)) dhcp6_startrebind(ifp); else +#endif dhcp6_startconfirm(ifp); return; } @@ -2336,6 +2374,7 @@ dhcp6_startinit(struct interface *ifp) dhcp6_startdiscover(ifp); } +#ifndef SMALL static struct ipv6_addr * dhcp6_ifdelegateaddr(struct interface *ifp, struct ipv6_addr *prefix, const struct if_sla *sla, struct if_ia *if_ia) @@ -2429,6 +2468,7 @@ dhcp6_ifdelegateaddr(struct interface *ifp, struct ipv6_addr *prefix, return ia; } +#endif static void dhcp6_script_try_run(struct interface *ifp, int delegated) @@ -2465,6 +2505,14 @@ dhcp6_script_try_run(struct interface *ifp, int delegated) "%s: waiting for DHCPv6 DAD to complete", ifp->name); } +#ifdef SMALL +size_t +dhcp6_find_delegates(__unused struct interface *ifp) +{ + + return 0; +} +#else static void dhcp6_delegate_prefix(struct interface *ifp) { @@ -2621,6 +2669,7 @@ dhcp6_find_delegates(struct interface *ifp) } return k; } +#endif /* ARGSUSED */ static void @@ -2848,11 +2897,13 @@ dhcp6_handledata(void *arg) if (dhcp6_validatelease(ifp, r, len, ctx->sfrom, NULL) == -1) { +#ifndef SMALL /* PD doesn't use CONFIRM, so REBIND could * throw up an invalid prefix if we * changed link */ if (dhcp6_hasprefixdelegation(ifp)) dhcp6_startdiscover(ifp); +#endif return; } break; @@ -3124,7 +3175,9 @@ recv: if_initrt6(ifp->ctx); ipv6_buildroutes(ifp->ctx); dhcp6_writelease(ifp); +#ifndef SMALL dhcp6_delegate_prefix(ifp); +#endif dhcp6_script_try_run(ifp, 0); } @@ -3207,6 +3260,7 @@ errexit: return -1; } +#ifndef SMALL static void dhcp6_activateinterfaces(struct interface *ifp) { @@ -3236,6 +3290,7 @@ dhcp6_activateinterfaces(struct interface *ifp) } } } +#endif static void dhcp6_start1(void *arg) @@ -3267,9 +3322,11 @@ dhcp6_start1(void *arg) add_option_mask(ifo->requestmask6, D6_OPTION_FQDN); } +#ifndef SMALL /* Rapid commit won't work with Prefix Delegation Exclusion */ if (dhcp6_findselfsla(ifp, NULL)) del_option_mask(ifo->requestmask6, D6_OPTION_RAPID_COMMIT); +#endif if (state->state == DH6S_INFORM) { add_option_mask(ifo->requestmask6, D6_OPTION_INFO_REFRESH_TIME); @@ -3279,7 +3336,9 @@ dhcp6_start1(void *arg) dhcp6_startinit(ifp); } +#ifndef SMALL dhcp6_activateinterfaces(ifp); +#endif } int @@ -3306,7 +3365,9 @@ dhcp6_start(struct interface *ifp, enum DH6S init_state) } /* We're already running DHCP6 */ /* XXX: What if the managed flag vanishes from all RA? */ +#ifndef SMALL dhcp6_activateinterfaces(ifp); +#endif return 0; } @@ -3365,7 +3426,9 @@ dhcp6_freedrop(struct interface *ifp, int drop, const char *reason) struct dhcp6_state *state; struct dhcpcd_ctx *ctx; unsigned long long options; +#ifndef SMALL int dropdele; +#endif /* * As the interface is going away from dhcpcd we need to @@ -3387,14 +3450,18 @@ dhcp6_freedrop(struct interface *ifp, int drop, const char *reason) options = ifp->options->options; else options = ifp->ctx->options; +#ifndef SMALL dropdele = (options & (DHCPCD_STOPPING | DHCPCD_RELEASE) && (options & DHCPCD_NODROP) != DHCPCD_NODROP); +#endif if (ifp->ctx->eloop) eloop_timeout_delete(ifp->ctx->eloop, NULL, ifp); +#ifndef SMALL if (dropdele) dhcp6_delete_delegates(ifp); +#endif state = D6_STATE(ifp); if (state) { @@ -3468,8 +3535,10 @@ dhcp6_free(struct interface *ifp) dhcp6_freedrop(ifp, 0, NULL); } -void dhcp6_dropnondelegates(struct interface *ifp) +void +dhcp6_dropnondelegates(struct interface *ifp) { +#ifndef SMALL struct dhcp6_state *state; struct ipv6_addr *ia; @@ -3479,6 +3548,7 @@ void dhcp6_dropnondelegates(struct interface *ifp) if (ia->flags & (IPV6_AF_DELEGATED | IPV6_AF_DELEGATEDPFX)) return; } +#endif dhcp6_drop(ifp, "EXPIRE6"); } diff --git a/dhcpcd-definitions-small.conf b/dhcpcd-definitions-small.conf new file mode 100644 index 00000000..04c446b9 --- /dev/null +++ b/dhcpcd-definitions-small.conf @@ -0,0 +1,125 @@ +# Copyright (c) 2006-2016 Roy Marples +# All rights reserved + +# Bare essentials for automatic IP configuration + +############################################################################## +# DHCP RFC2132 options unless otheriwse stated +define 1 request ipaddress subnet_mask +# RFC3442 states that the CSR has to come before all other routes +# For completeness we also specify static routes then routers +define 121 rfc3442 classless_static_routes +# Option 249 is an IANA assigned private number used by Windows DHCP servers +# to provide the exact same information as option 121, classless static routes +define 249 rfc3442 ms_classless_static_routes +define 33 request array ipaddress static_routes +define 3 request array ipaddress routers +define 6 array ipaddress domain_name_servers +define 12 dname host_name +define 15 array dname domain_name +define 28 request ipaddress broadcast_address +define 50 ipaddress dhcp_requested_address +define 51 request uint32 dhcp_lease_time +define 52 byte dhcp_option_overload +define 53 byte dhcp_message_type +define 54 ipaddress dhcp_server_identifier +define 55 array byte dhcp_parameter_request_list +define 56 string dhcp_message +define 57 uint16 dhcp_max_message_size +define 58 request uint32 dhcp_renewal_time +define 59 request uint32 dhcp_rebinding_time +define 60 string vendor_class_identifier +define 61 binhex dhcp_client_identifier + +# DHCP Rapid Commit, RFC4039 +define 80 norequest flag rapid_commit + +# DHCP Fully Qualified Domain Name, RFC4702 +define 81 embed fqdn +embed bitflags=0000NEOS flags +embed byte rcode1 +embed byte rcode2 +# dhcpcd always sets the E bit which means the fqdn itself is always +# RFC1035 encoded. +# The server MUST use the encoding as specified by the client as noted +# in RFC4702 Section 2.1. +embed optional domain fqdn + +# DHCP Domain Search, RFC3397 +define 119 array domain domain_search + +############################################################################## +# ND6 options, RFC4861 +definend 1 binhex source_address +definend 2 binhex target_address + +definend 3 index embed prefix_information +embed byte length +embed bitflags=LA flags +embed uint32 vltime +embed uint32 pltime +embed uint32 reserved +embed array ip6address prefix + +# option 4 is only for Redirect messages + +definend 5 embed mtu +embed uint16 reserved +embed uint32 mtu + +# ND6 options, RFC6101 +definend 25 index embed rdnss +embed uint16 reserved +embed uint32 lifetime +embed array ip6address servers + +definend 31 index embed dnssl +embed uint16 reserved +embed uint32 lifetime +embed domain search + +############################################################################## +# DHCPv6 options, RFC3315 +define6 1 binhex client_id +define6 2 binhex server_id + +define6 3 norequest index embed ia_na +embed binhex:4 iaid +embed uint32 t1 +embed uint32 t2 +encap 5 option +encap 13 option + +define6 4 norequest index embed ia_ta +embed uint32 iaid +encap 5 option +encap 13 option + +define6 5 norequest index embed ia_addr +embed ip6address ia_addr +embed uint32 pltime +embed uint32 vltime +encap 13 option + +define6 12 ip6address unicast + +define6 13 norequest embed status_code +embed uint16 status_code +embed string message + +define6 18 binhex interface_id +define6 19 byte reconfigure_msg +define6 20 flag reconfigure_accept + +# DHCPv6 DNS Configuration Options, RFC3646 +define6 23 array ip6address name_servers +define6 24 array domain domain_search + +# DHCPv6 Fully Qualified Domain Name, RFC4704 +define6 39 embed fqdn +embed bitflags=00000NOS flags +embed optional domain fqdn + +# DHCPv6 SOL_MAX_RT, RFC7083 +define6 82 request uint32 sol_max_rt +define6 83 request uint32 inf_max_rt