Allow IPv4LL to be compiled out.

This commit is contained in:
Roy Marples 2016-09-20 09:29:39 +00:00
parent c131061425
commit 8113e962fb
7 changed files with 61 additions and 23 deletions

8
README
View File

@ -19,8 +19,12 @@ Currently this just removes non important options out of
dhcpcd-definitions.conf, the custom logger and
support for DHCPv6 Prefix Delegation.
Other features maybe dropped as and when required.
dhcpcd can also be made smaller by removing Authentication support with
--disable-auth.
dhcpcd can also be made smaller by removing the IPv4 or IPv6 stack:
* --disable-inet
* --disable-inet6
Or by removing the following features
* --disable-auth
* --disable-ipv4ll
If you're cross compiling you may need set the platform if OS is different
from the host.

9
configure vendored
View File

@ -7,6 +7,7 @@ exec 3>config.log
# Ensure that we do not inherit these from env
HOOKSET=false
INET=
IPV4LL=
INET6=
ARC4RANDOM=
CLOSEFROM=
@ -45,6 +46,8 @@ for x do
--enable-static) STATIC=yes;;
--disable-ipv4) INET=no;;
--enable-ipv4) INET=yes;;
--disable-ipv4ll) IPV4LL=no;;
--enable-ipv4ll) IPV4LL=yes; INET=yes;;
--disable-ipv6) INET6=no;;
--enable-ipv6) INET6=yes;;
--disable-embedded) EMBEDDED=no;;
@ -438,7 +441,11 @@ esac
if [ -z "$INET" -o "$INET" = yes ]; then
echo "CPPFLAGS+= -DINET" >>$CONFIG_MK
echo "DHCPCD_SRCS+= arp.c dhcp.c ipv4.c ipv4ll.c" >>$CONFIG_MK
echo "DHCPCD_SRCS+= arp.c dhcp.c ipv4.c" >>$CONFIG_MK
fi
if [ -z "$IPV4LL" -o "$IPV4LL" = yes ]; then
echo "CPPFLAGS+= -DIPV4LL" >>$CONFIG_MK
echo "DHCPCD_SRCS+= ipv4ll.c" >>$CONFIG_MK
fi
if [ -z "$INET6" -o "$INET6" = yes ]; then
echo "CPPFLAGS+= -DINET6" >>$CONFIG_MK

8
dhcp.c
View File

@ -1845,9 +1845,11 @@ dhcp_discover(void *arg)
if (ifo->fallback)
eloop_timeout_add_sec(ifp->ctx->eloop,
ifo->reboot, dhcp_fallback, ifp);
#ifdef IPV4LL
else if (ifo->options & DHCPCD_IPV4LL)
eloop_timeout_add_sec(ifp->ctx->eloop,
ifo->reboot, ipv4ll_start, ifp);
#endif
if (ifo->options & DHCPCD_REQUEST)
logger(ifp->ctx, LOG_INFO,
"%s: soliciting a DHCP lease (requesting %s)",
@ -2510,10 +2512,12 @@ dhcp_reboot(struct interface *ifp)
state->lease.server.s_addr = 0;
eloop_timeout_delete(ifp->ctx->eloop, NULL, ifp);
#ifdef IPV4LL
/* Need to add this before dhcp_expire and friends. */
if (!ifo->fallback && ifo->options & DHCPCD_IPV4LL)
eloop_timeout_add_sec(ifp->ctx->eloop,
ifo->reboot, ipv4ll_start, ifp);
#endif
if (ifo->options & DHCPCD_LASTLEASE && state->lease.frominfo)
eloop_timeout_add_sec(ifp->ctx->eloop,
@ -2907,6 +2911,7 @@ dhcp_handledhcp(struct interface *ifp, struct bootp *bootp, size_t bootp_len,
"%s: message: %s", ifp->name, msg);
free(msg);
}
#ifdef IPV4LL
if (state->state == DHS_DISCOVER &&
get_option_uint8(ifp->ctx, &tmp, bootp, bootp_len,
DHO_AUTOCONFIGURE) == 0)
@ -2931,6 +2936,7 @@ dhcp_handledhcp(struct interface *ifp, struct bootp *bootp, size_t bootp_len,
eloop_timeout_add_sec(ifp->ctx->eloop,
DHCP_MAX, dhcp_discover, ifp);
}
#endif
return;
}
@ -3581,11 +3587,13 @@ dhcp_start1(void *arg)
}
}
#ifdef IPV4LL
if (!(ifo->options & DHCPCD_DHCP)) {
if (ifo->options & DHCPCD_IPV4LL)
ipv4ll_start(ifp);
return;
}
#endif
if (state->offer == NULL || !IS_DHCP(state->offer))
dhcp_discover(ifp);

10
ipv4.c
View File

@ -196,14 +196,14 @@ int
ipv4_hasaddr(const struct interface *ifp)
{
const struct dhcp_state *dstate;
const struct ipv4ll_state *istate;
if (IPV4LL_STATE_RUNNING(ifp))
return 1;
dstate = D_CSTATE(ifp);
istate = IPV4LL_CSTATE(ifp);
return ((dstate &&
return (dstate &&
dstate->added == STATE_ADDED &&
dstate->addr != NULL) ||
(istate && istate->addr));
dstate->addr != NULL);
}
void

View File

@ -52,6 +52,7 @@ static const struct in_addr inaddr_llbcast = {
.s_addr = HTONL(LINKLOCAL_BCAST)
};
#ifdef IPV4LL
static in_addr_t
ipv4ll_pickaddr(struct arp_state *astate)
{
@ -490,3 +491,4 @@ ipv4ll_handlert(struct dhcpcd_ctx *ctx, __unused int cmd, const struct rt *rt)
return 0;
}
#endif
#endif

View File

@ -28,17 +28,17 @@
#ifndef IPV4LL_H
#define IPV4LL_H
#ifdef INET
#include "arp.h"
#define LINKLOCAL_ADDR 0xa9fe0000
#define LINKLOCAL_MASK IN_CLASSB_NET
#define LINKLOCAL_BCAST (LINKLOCAL_ADDR | ~LINKLOCAL_MASK)
#define LINKLOCAL_ADDR 0xa9fe0000
#define LINKLOCAL_MASK IN_CLASSB_NET
#define LINKLOCAL_BCAST (LINKLOCAL_ADDR | ~LINKLOCAL_MASK)
#ifndef IN_LINKLOCAL
# define IN_LINKLOCAL(addr) ((addr & IN_CLASSB_NET) == LINKLOCAL_ADDR)
#endif
#ifdef IPV4LL
#include "arp.h"
struct ipv4ll_state {
struct ipv4_addr *addr;
struct arp_state *arp;
@ -48,11 +48,11 @@ struct ipv4ll_state {
uint8_t down;
};
#define IPV4LL_STATE(ifp) \
#define IPV4LL_STATE(ifp) \
((struct ipv4ll_state *)(ifp)->if_data[IF_DATA_IPV4LL])
#define IPV4LL_CSTATE(ifp) \
#define IPV4LL_CSTATE(ifp) \
((const struct ipv4ll_state *)(ifp)->if_data[IF_DATA_IPV4LL])
#define IPV4LL_STATE_RUNNING(ifp) \
#define IPV4LL_STATE_RUNNING(ifp) \
(IPV4LL_CSTATE((ifp)) && !IPV4LL_CSTATE((ifp))->down && \
(IPV4LL_CSTATE((ifp))->addr != NULL))
@ -65,16 +65,19 @@ void ipv4ll_handle_failure(void *);
#ifdef HAVE_ROUTE_METRIC
int ipv4ll_handlert(struct dhcpcd_ctx *, int, const struct rt *);
#else
#define ipv4ll_handlert(a, b, c) (0)
#define ipv4ll_handlert(a, b, c) (0)
#endif
#define ipv4ll_free(ifp) ipv4ll_freedrop((ifp), 0);
#define ipv4ll_drop(ifp) ipv4ll_freedrop((ifp), 1);
#define ipv4ll_free(ifp) ipv4ll_freedrop((ifp), 0);
#define ipv4ll_drop(ifp) ipv4ll_freedrop((ifp), 1);
void ipv4ll_freedrop(struct interface *, int);
#else
#define IPV4LL_STATE_RUNNING(ifp) (0)
#define ipv4ll_free(a) {}
#define ipv4ll_drop(a) {}
#define IPV4LL_STATE_RUNNING(ifp) (0)
#define ipv4ll_subnet_route(ifp) (NULL)
#define ipv4ll_default_route(ifp) (NULL)
#define ipv4ll_handlert(a, b, c) (0)
#define ipv4ll_free(a) {}
#define ipv4ll_drop(a) {}
#endif
#endif

View File

@ -236,8 +236,10 @@ make_env(const struct interface *ifp, const char *reason, char ***argv)
#ifdef INET
int dhcp, ipv4ll;
const struct dhcp_state *state;
#ifdef IPV4LL
const struct ipv4ll_state *istate;
#endif
#endif
#ifdef INET6
const struct dhcp6_state *d6_state;
int static6, dhcp6, ra;
@ -246,8 +248,10 @@ make_env(const struct interface *ifp, const char *reason, char ***argv)
#ifdef INET
dhcp = ipv4ll = 0;
state = D_STATE(ifp);
#ifdef IPV4LL
istate = IPV4LL_CSTATE(ifp);
#endif
#endif
#ifdef INET6
static6 = dhcp6 = ra = 0;
d6_state = D6_CSTATE(ifp);
@ -261,8 +265,10 @@ make_env(const struct interface *ifp, const char *reason, char ***argv)
ra = 1;
#endif
#ifdef INET
#ifdef IPV4LL
else if (istate && istate->addr != NULL)
ipv4ll = 1;
#endif
else
dhcp = 1;
#endif
@ -285,8 +291,10 @@ make_env(const struct interface *ifp, const char *reason, char ***argv)
/* This space left intentionally blank */
}
#ifdef INET
#ifdef IPV4LL
else if (strcmp(reason, "IPV4LL") == 0)
ipv4ll = 1;
#endif
else
dhcp = 1;
#endif
@ -359,8 +367,10 @@ make_env(const struct interface *ifp, const char *reason, char ***argv)
} else if (1 == 2 /* appease ifdefs */
#ifdef INET
|| (dhcp && state && state->new)
#ifdef IPV4LL
|| (ipv4ll && IPV4LL_STATE_RUNNING(ifp))
#endif
#endif
#ifdef INET6
|| (static6 && IPV6_STATE_RUNNING(ifp))
|| (dhcp6 && d6_state && d6_state->new)
@ -462,6 +472,7 @@ make_env(const struct interface *ifp, const char *reason, char ***argv)
dumplease:
#ifdef INET
#ifdef IPV4LL
if (ipv4ll) {
n = ipv4ll_env(NULL, NULL, ifp);
if (n > 0) {
@ -476,6 +487,7 @@ dumplease:
elen += (size_t)n;
}
}
#endif
if (dhcp && state && state->new) {
n = dhcp_env(NULL, NULL, state->new, state->new_len, ifp);
if (n > 0) {
@ -631,11 +643,13 @@ send_interface(struct fd_list *fd, const struct interface *ifp)
if (send_interface1(fd, ifp, d->reason) == -1)
retval = -1;
}
#ifdef IPV4LL
if (IPV4LL_STATE_RUNNING(ifp)) {
if (send_interface1(fd, ifp, "IPV4LL") == -1)
retval = -1;
}
#endif
#endif
#ifdef INET6
if (IPV6_STATE_RUNNING(ifp)) {