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.
/* 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;
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);
}
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 (;;) {
#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
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
return -1;
}
-#ifndef MINIMAL
#define THIRTY_YEARS_IN_SECONDS 946707779
static size_t
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)
{
}
return dhcp;
}
-#endif
static void
get_lease(struct dhcp_lease *lease, const struct dhcp_message *dhcp)
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 {
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 &&
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:
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)
state->options & DHCPCD_LASTLEASE))
gotlease = get_old_lease(state);
-#ifdef ENABLE_IPV4LL
if (state->carrier != LINK_DOWN &&
state->options & DHCPCD_IPV4LL &&
gotlease != 0)
state->offer = ipv4ll_get_dhcp(0);
gotlease = 0;
}
-#endif
-#ifdef ENABLE_ARP
if (gotlease == 0 &&
state->offer->yiaddr != iface->addr.s_addr)
{
state->conflicts = 0;
return 1;
}
-#endif
if (gotlease == 0)
return bind_dhcp(state, options);
struct interface *iface = state->interface;
int i = 0;
struct timeval tv;
-#ifdef ENABLE_ARP
struct in_addr addr;
timerclear(&state->timeout);
}
timerclear(&tv);
-#ifdef ENABLE_IPV4LL
if (state->state == STATE_RENEW_REQUESTED &&
IN_LINKLOCAL(ntohl(lease->addr.s_addr)))
{
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;
state->claims = 0;
state->probes = 0;
/* FALLTHROUGH */
-#endif
case STATE_PROBING:
if (iface->arp_fd == -1)
open_socket(iface, ETHERTYPE_ARP);
timeradd(&state->timeout, &tv, &state->timeout);
return i;
}
-#endif
if (timerisset(&state->stop)) {
get_time(&tv);
break;
}
-#ifdef ENABLE_ARP
dhcp_timeout:
-#endif
if (state->carrier == LINK_DOWN) {
timerclear(&state->timeout);
return 0;
state->offer = dhcp;
*dhcpp = NULL;
-#ifdef ENABLE_ARP
if (state->options & DHCPCD_ARP &&
iface->addr.s_addr != state->offer->yiaddr)
{
timerclear(&state->stop);
return 1;
}
-#endif
return bind_dhcp(state, options);
}
return retval;
}
-#ifdef ENABLE_ARP
static int
handle_arp_packet(struct if_state *state)
{
timeradd(&state->timeout, &tv, &state->timeout);
return 0;
}
-#endif
static int
handle_link(struct if_state *state)
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)
#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
* 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 */
ort = get_option_routes(dhcp);
-#ifdef ENABLE_IPV4LL_ALWAYSROUTE
+#ifdef IPV4LL_ALWAYSROUTE
if (options->options & DHCPCD_IPV4LL &&
IN_PRIVATE(ntohl(dhcp->yiaddr)))
{
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);
}
#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)
}
}
- 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();
}
}
-#ifndef MINIMAL
if ((p = strchr(options->hostname, '.'))) {
if (options->fqdn == FQDN_DISABLE)
*p = '\0';
}
if (options->fqdn != FQDN_DISABLE)
del_reqmask(options->reqmask, DHCP_HOSTNAME);
-#endif
if (options->request_address.s_addr == 0 &&
(options->options & DHCPCD_INFORM ||
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;
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
}
/* 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;
}
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);
&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));
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)
/* 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:
return retval;
}
-#ifdef ENABLE_ARP
int
send_arp(const struct interface *iface, int op, in_addr_t sip, in_addr_t tip)
{
free(arp);
return retval;
}
-#endif
-
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;
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 *);