From: Roy Marples Date: Wed, 23 Jul 2008 17:06:42 +0000 (+0000) Subject: Remove #ifdefs to disable specific bits of code. We now build everything - we're... X-Git-Tag: v4.0.2~135 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=b8b4be9a39e91342c91e493ce2e08c00d0177aa8;p=thirdparty%2Fdhcpcd.git Remove #ifdefs to disable specific bits of code. We now build everything - we're small enough :) --- diff --git a/README b/README index 27aadf05..5e47faad 100644 --- a/README +++ b/README @@ -15,10 +15,6 @@ 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 CPPFLAGS. 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 CPPFLAGS. diff --git a/bpf.c b/bpf.c index f661fe9b..96e53a16 100644 --- a/bpf.c +++ b/bpf.c @@ -108,11 +108,9 @@ open_socket(struct interface *iface, int protocol) /* Install the DHCP filter */ if (protocol == ETHERTYPE_ARP) { -#ifdef ENABLE_ARP pf.bf_insns = UNCONST(arp_bpf_filter); pf.bf_len = arp_bpf_filter_len; fdp = &iface->arp_fd; -#endif } else { pf.bf_insns = UNCONST(dhcp_bpf_filter); pf.bf_len = dhcp_bpf_filter_len; @@ -151,11 +149,9 @@ send_raw_packet(const struct interface *iface, int protocol, iov[0].iov_len = ETHER_HDR_LEN; iov[1].iov_base = UNCONST(data); iov[1].iov_len = len; -#ifdef ENABLE_ARP if (protocol == ETHERTYPE_ARP) fd = iface->arp_fd; else -#endif fd = iface->raw_fd; return writev(fd, iov, 2); } @@ -171,11 +167,9 @@ get_raw_packet(struct interface *iface, int protocol, ssize_t bytes; const unsigned char *payload; - if (protocol == ETHERTYPE_ARP) { -#ifdef ENABLE_ARP + if (protocol == ETHERTYPE_ARP) fd = iface->arp_fd; -#endif - } else + else fd = iface->raw_fd; for (;;) { diff --git a/client.c b/client.c index 51cceca3..f8b5e22a 100644 --- a/client.c +++ b/client.c @@ -53,12 +53,7 @@ #include "logger.h" #include "signals.h" -#ifdef ENABLE_IPV4LL -# ifndef ENABLE_ARP - # error "IPv4LL requires ENABLE_ARP to work" -# endif -# define IPV4LL_LEASETIME 2 -#endif +#define IPV4LL_LEASETIME 2 /* Some platforms don't define INFTIM */ #ifndef INFTIM @@ -139,13 +134,11 @@ struct if_state { int *pid_fd; int signal_fd; int carrier; -#ifdef ENABLE_ARP int probes; int claims; int conflicts; time_t defend; struct in_addr fail; -#endif }; #define LINK_UP 1 @@ -279,7 +272,6 @@ daemonise(struct if_state *state, const struct options *options) return -1; } -#ifndef MINIMAL #define THIRTY_YEARS_IN_SECONDS 946707779 static size_t get_duid(unsigned char *duid, const struct interface *iface) @@ -348,9 +340,7 @@ get_duid(unsigned char *duid, const struct interface *iface) } return len; } -#endif -#ifdef ENABLE_IPV4LL static struct dhcp_message* ipv4ll_get_dhcp(uint32_t old_addr) { @@ -383,7 +373,6 @@ ipv4ll_get_dhcp(uint32_t old_addr) } return dhcp; } -#endif static void get_lease(struct dhcp_lease *lease, const struct dhcp_message *dhcp) @@ -520,16 +509,10 @@ client_setup(struct if_state *state, const struct options *options) state->offer = NULL; get_option_addr(&lease->server.s_addr, state->new, DHCP_SERVERID); -#ifdef ENABLE_ARP open_socket(iface, ETHERTYPE_ARP); state->state = STATE_ANNOUNCING; tv.tv_sec = ANNOUNCE_INTERVAL; timeradd(&state->start, &tv, &state->timeout); -#else - state->state = STATE_BOUND; - tv.tv_sec = state->lease.renewaltime; - timeradd(&state->start, &tv, &state->stop); -#endif } #endif } else { @@ -645,12 +628,10 @@ do_socket(struct if_state *state, int mode) close(state->interface->udp_fd); state->interface->udp_fd = -1; } -#ifdef ENABLE_ARP if (state->interface->arp_fd != -1) { close(state->interface->arp_fd); state->interface->arp_fd = -1; } -#endif } if (mode == SOCKET_OPEN && @@ -798,13 +779,11 @@ wait_for_packet(struct if_state *state) fds[nfds].events = POLLIN; nfds++; } -#ifdef ENABLE_ARP if (state->interface->arp_fd != -1) { fds[nfds].fd = state->interface->arp_fd; fds[nfds].events = POLLIN; nfds++; } -#endif } wait_again: @@ -907,10 +886,8 @@ static int bind_dhcp(struct if_state *state, const struct options *options) state->offer = NULL; state->messages = 0; timerclear(&state->exit); -#ifdef ENABLE_ARP state->conflicts = 0; state->defend = 0; -#endif if (options->options & DHCPCD_INFORM) { if (options->request_address.s_addr != 0) @@ -1047,7 +1024,6 @@ handle_timeout_fail(struct if_state *state, const struct options *options) state->options & DHCPCD_LASTLEASE)) gotlease = get_old_lease(state); -#ifdef ENABLE_IPV4LL if (state->carrier != LINK_DOWN && state->options & DHCPCD_IPV4LL && gotlease != 0) @@ -1057,9 +1033,7 @@ handle_timeout_fail(struct if_state *state, const struct options *options) state->offer = ipv4ll_get_dhcp(0); gotlease = 0; } -#endif -#ifdef ENABLE_ARP if (gotlease == 0 && state->offer->yiaddr != iface->addr.s_addr) { @@ -1069,7 +1043,6 @@ handle_timeout_fail(struct if_state *state, const struct options *options) state->conflicts = 0; return 1; } -#endif if (gotlease == 0) return bind_dhcp(state, options); @@ -1132,7 +1105,6 @@ handle_timeout(struct if_state *state, const struct options *options) struct interface *iface = state->interface; int i = 0; struct timeval tv; -#ifdef ENABLE_ARP struct in_addr addr; timerclear(&state->timeout); @@ -1143,7 +1115,6 @@ handle_timeout(struct if_state *state, const struct options *options) } timerclear(&tv); -#ifdef ENABLE_IPV4LL if (state->state == STATE_RENEW_REQUESTED && IN_LINKLOCAL(ntohl(lease->addr.s_addr))) { @@ -1153,9 +1124,7 @@ handle_timeout(struct if_state *state, const struct options *options) state->probes = 0; state->claims = 0; } -#endif switch (state->state) { -#ifdef ENABLE_IPV4LL case STATE_INIT_IPV4LL: logger(LOG_INFO, "probing for an IPV4LL address"); state->state = STATE_PROBING; @@ -1164,7 +1133,6 @@ handle_timeout(struct if_state *state, const struct options *options) state->claims = 0; state->probes = 0; /* FALLTHROUGH */ -#endif case STATE_PROBING: if (iface->arp_fd == -1) open_socket(iface, ETHERTYPE_ARP); @@ -1235,7 +1203,6 @@ handle_timeout(struct if_state *state, const struct options *options) timeradd(&state->timeout, &tv, &state->timeout); return i; } -#endif if (timerisset(&state->stop)) { get_time(&tv); @@ -1315,9 +1282,7 @@ handle_timeout(struct if_state *state, const struct options *options) break; } -#ifdef ENABLE_ARP dhcp_timeout: -#endif if (state->carrier == LINK_DOWN) { timerclear(&state->timeout); return 0; @@ -1451,7 +1416,6 @@ handle_dhcp(struct if_state *state, struct dhcp_message **dhcpp, state->offer = dhcp; *dhcpp = NULL; -#ifdef ENABLE_ARP if (state->options & DHCPCD_ARP && iface->addr.s_addr != state->offer->yiaddr) { @@ -1463,7 +1427,6 @@ handle_dhcp(struct if_state *state, struct dhcp_message **dhcpp, timerclear(&state->stop); return 1; } -#endif return bind_dhcp(state, options); } @@ -1533,7 +1496,6 @@ handle_dhcp_packet(struct if_state *state, const struct options *options) return retval; } -#ifdef ENABLE_ARP static int handle_arp_packet(struct if_state *state) { @@ -1656,7 +1618,6 @@ handle_arp_fail(struct if_state *state, const struct options *options) timeradd(&state->timeout, &tv, &state->timeout); return 0; } -#endif static int handle_link(struct if_state *state) @@ -1750,14 +1711,11 @@ dhcp_run(const struct options *options, int *pid_fd) retval = handle_link(state); } else if (fd_hasdata(iface->raw_fd) == 1) { retval = handle_dhcp_packet(state, options); -#ifdef ENABLE_ARP } else if (fd_hasdata(iface->arp_fd) == 1) { retval = handle_arp_packet(state); if (retval == -1) retval = handle_arp_fail(state, options); - } -#endif - else + } else retval = 0; } if (retval == -1) diff --git a/config.h b/config.h index 918bc00b..1222271e 100644 --- a/config.h +++ b/config.h @@ -30,33 +30,6 @@ #define PACKAGE "dhcpcd" #define VERSION "4.0.0-rc2" -/* You can enable/disable various chunks of optional code here. - * You would only do this to try and shrink the end binary if dhcpcd - * was running on a low memory device */ - -/* Disable everything we possibly can. */ -#ifdef MINIMAL -# ifndef DISABLE_ARP -# define DISABLE_ARP -# endif -# ifndef DISABLE_IPV4LL -# define DISABLE_IPV4LL -# endif -#endif - -/* Enable ARP by default. */ -#ifndef DISABLE_ARP -# define ENABLE_ARP -#endif - -/* IPV4LL, aka ZeroConf, aka APIPA, aka RFC 3927. - * Needs ARP. */ -#ifndef DISABLE_IPV4LL -# ifdef ENABLE_ARP -# define ENABLE_IPV4LL -# endif -#endif - /* * By default we don't add a local link route if we got a routeable address. * This is because dhcpcd can't really decide which interface should allow @@ -64,7 +37,7 @@ * Ideally the host network scripts should add the link local route for us. * If not, you can define this to get dhcpcd to always add the link local route. */ -// #define ENABLE_IPV4LL_ALWAYSROUTE +// #define IPV4LL_ALWAYSROUTE /* Some systems do not have a working fork. */ /* #define THERE_IS_NO_FORK */ diff --git a/configure.c b/configure.c index ec53ab31..536fd1fc 100644 --- a/configure.c +++ b/configure.c @@ -259,7 +259,7 @@ configure_routes(struct interface *iface, const struct dhcp_message *dhcp, ort = get_option_routes(dhcp); -#ifdef ENABLE_IPV4LL_ALWAYSROUTE +#ifdef IPV4LL_ALWAYSROUTE if (options->options & DHCPCD_IPV4LL && IN_PRIVATE(ntohl(dhcp->yiaddr))) { diff --git a/dhcpcd.c b/dhcpcd.c index dfa435a1..46e39a37 100644 --- a/dhcpcd.c +++ b/dhcpcd.c @@ -621,23 +621,13 @@ main(int argc, char **argv) setlogprefix(PACKAGE ": "); options = xzalloc(sizeof(*options)); - options->options |= DHCPCD_GATEWAY | DHCPCD_DAEMONISE; + options->options |= DHCPCD_CLIENTID | DHCPCD_GATEWAY | DHCPCD_DAEMONISE; + options->options |= DHCPCD_ARP | DHCPCD_IPV4LL | DHCPCD_LINK; options->timeout = DEFAULT_TIMEOUT; strlcpy(options->script, SCRIPT, sizeof(options->script)); -#ifndef MINIMAL - options->options |= DHCPCD_CLIENTID; options->classid[0] = snprintf((char *)options->classid + 1, CLASSID_MAX_LEN, "%s %s", PACKAGE, VERSION); -#endif -#ifdef ENABLE_ARP - options->options |= DHCPCD_ARP; - #ifdef ENABLE_IPV4LL - options->options |= DHCPCD_IPV4LL; - #endif -#endif - - options->options |= DHCPCD_LINK; #ifdef CMDLINE_COMPAT add_reqmask(options->reqmask, DHCP_DNSSERVER); @@ -676,13 +666,11 @@ 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) @@ -706,23 +694,8 @@ main(int argc, char **argv) } } - if (doversion) { + if (doversion) printf(""PACKAGE" "VERSION"\n%s\n", copyright); - printf("Compile time options:" -#ifdef ENABLE_ARP - " ARP" -#endif -#ifdef ENABLE_IPV4LL - " IPV4LL" -#endif -#ifdef MINIMAL - " MINIMAL" -#endif -#ifdef THERE_IS_NO_FORK - " THERE_IS_NO_FORK" -#endif - "\n"); - } if (dohelp) usage(); @@ -869,7 +842,6 @@ main(int argc, char **argv) } } -#ifndef MINIMAL if ((p = strchr(options->hostname, '.'))) { if (options->fqdn == FQDN_DISABLE) *p = '\0'; @@ -882,7 +854,6 @@ 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 || @@ -991,13 +962,11 @@ 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 a46c6fc7..b06f5da1 100644 --- a/dhcpcd.h +++ b/dhcpcd.h @@ -87,14 +87,11 @@ struct options { 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/lpf.c b/lpf.c index 98521871..ae5dd036 100644 --- a/lpf.c +++ b/lpf.c @@ -89,13 +89,10 @@ open_socket(struct interface *iface, int protocol) } /* Install the DHCP filter */ memset(&pf, 0, sizeof(pf)); -#ifdef ENABLE_ARP if (protocol == ETHERTYPE_ARP) { pf.filter = UNCONST(arp_bpf_filter); pf.len = arp_bpf_filter_len; - } else -#endif - { + } else { pf.filter = UNCONST(dhcp_bpf_filter); pf.len = dhcp_bpf_filter_len; } @@ -107,11 +104,9 @@ open_socket(struct interface *iface, int protocol) goto eexit; if (bind(s, &su.sa, sizeof(su)) == -1) goto eexit; -#ifdef ENABLE_ARP if (protocol == ETHERTYPE_ARP) fd = &iface->arp_fd; else -#endif fd = &iface->raw_fd; if (*fd != -1) close(*fd); @@ -148,11 +143,9 @@ send_raw_packet(const struct interface *iface, int protocol, &ipv4_bcast_addr, sizeof(ipv4_bcast_addr)); else memset(&su.sll.sll_addr, 0xff, iface->hwlen); -#ifdef ENABLE_ARP if (protocol == ETHERTYPE_ARP) fd = iface->arp_fd; else -#endif fd = iface->raw_fd; return sendto(fd, data, len, 0, &su.sa, sizeof(su)); @@ -164,11 +157,9 @@ get_raw_packet(struct interface *iface, int protocol, void *data, ssize_t len) ssize_t bytes; int fd = -1; - if (protocol == ETHERTYPE_ARP) { -#ifdef ENABLE_ARP + if (protocol == ETHERTYPE_ARP) fd = iface->arp_fd; -#endif - } else + else fd = iface->raw_fd; bytes = read(fd, data, len); if (bytes == -1) diff --git a/net.c b/net.c index 312989a6..9f1b7adb 100644 --- a/net.c +++ b/net.c @@ -434,9 +434,7 @@ read_interface(const char *ifname, _unused int metric) /* 0 is a valid fd, so init to -1 */ iface->raw_fd = -1; iface->udp_fd = -1; -#ifdef ENABLE_ARP iface->arp_fd = -1; -#endif iface->link_fd = -1; eexit: @@ -662,7 +660,6 @@ valid_udp_packet(const uint8_t *data) return retval; } -#ifdef ENABLE_ARP int send_arp(const struct interface *iface, int op, in_addr_t sip, in_addr_t tip) { @@ -694,5 +691,3 @@ send_arp(const struct interface *iface, int op, in_addr_t sip, in_addr_t tip) free(arp); return retval; } -#endif - diff --git a/net.h b/net.h index f2b3dbe1..3ade0257 100644 --- a/net.h +++ b/net.h @@ -103,9 +103,7 @@ struct interface int raw_fd; int udp_fd; -#ifdef ENABLE_ARP int arp_fd; -#endif int link_fd; size_t buffer_size, buffer_len, buffer_pos; unsigned char *buffer; @@ -170,9 +168,7 @@ ssize_t send_raw_packet(const struct interface *, int, const void *, ssize_t); ssize_t get_raw_packet(struct interface *, int, void *, ssize_t); -#ifdef ENABLE_ARP int send_arp(const struct interface *, int, in_addr_t, in_addr_t); -#endif int open_link_socket(struct interface *); int link_changed(struct interface *);