From: Roy Marples Date: Mon, 4 Feb 2013 13:30:35 +0000 (+0000) Subject: It's now possible to compile out IPv4 and IPv6 support by passing X-Git-Tag: v5.99.6~78 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=aae24feb3d75af5ac07a97959c944f3d5537fdd6;p=thirdparty%2Fdhcpcd.git It's now possible to compile out IPv4 and IPv6 support by passing --disable-ipv4 or --disable-ipv6 to configure. --- diff --git a/Makefile b/Makefile index b811d925..b941c6e7 100644 --- a/Makefile +++ b/Makefile @@ -1,11 +1,9 @@ # dhcpcd Makefile PROG= dhcpcd -SRCS= arp.c common.c control.c dhcpcd.c duid.c eloop.c +SRCS= common.c control.c dhcpcd.c duid.c eloop.c SRCS+= if-options.c if-pref.c net.c script.c signals.c SRCS+= dhcp-common.c -SRCS+= ipv4.c dhcp.c ipv4ll.c -SRCS+= ipv6.c ipv6rs.c ipv6ns.c dhcp6.c CFLAGS?= -O2 CSTD?= c99 diff --git a/README b/README index 32ae27a5..c85432a2 100644 --- a/README +++ b/README @@ -1,5 +1,5 @@ dhcpcd - DHCP client daemon -Copyright (c) 2006-2012 Roy Marples +Copyright (c) 2006-2013 Roy Marples Installation diff --git a/configure b/configure index a0bee323..02225f3c 100755 --- a/configure +++ b/configure @@ -3,6 +3,8 @@ # Ensure that we do not inherit these from env HOOKSET=false +INET= +INET6= ARC4RANDOM= CLOSEFROM= GETLINE= @@ -30,6 +32,10 @@ for x do --enable-fork) FORK=yes;; --disable-static) STATIC=no;; --enable-static) STATIC=yes;; + --disable-ipv4) INET=no;; + --enable-ipv4) INET=yes;; + --disable-ipv6) INET6=no;; + --enable-ipv6) INET6=yes;; --prefix) prefix=$var;; --sysconfdir) SYSCONFDIR=$var;; --bindir|--sbindir) SBINDIR=$var;; @@ -241,21 +247,39 @@ fi case "$OS" in linux) echo "CPPFLAGS+= -D_BSD_SOURCE -D_XOPEN_SOURCE=700" >>$CONFIG_MK - echo "SRCS+= if-linux.c if-linux-wireless.c lpf.c" >>$CONFIG_MK + if [ -z "$INET" -o "$INET" = yes ]; then + echo "SRCS+= lpf.c" >>$CONFIG_MK + fi + echo "SRCS+= if-linux.c if-linux-wireless.c" >>$CONFIG_MK echo "SRCS+= platform-linux.c" >>$CONFIG_MK echo "LDADD+= -lrt" >>$CONFIG_MK ;; kfreebsd) echo "CPPFLAGS+= -D_GNU_SOURCE" >>$CONFIG_MK - echo "SRCS+= bpf.c if-bsd.c platform-bsd.c" >>$CONFIG_MK + if [ -z "$INET" -o "$INET" = yes ]; then + echo "SRCS+= bpf.c" >>$CONFIG_MK + fi + echo "SRCS+= if-bsd.c platform-bsd.c" >>$CONFIG_MK echo "COMPAT_SRCS+= compat/linkaddr.c" >>$CONFIG_MK echo "LDADD+= -lrt" >>$CONFIG_MK ;; *) - echo "SRCS+= bpf.c if-bsd.c platform-bsd.c" >>$CONFIG_MK + if [ -z "$INET" -o "$INET" = yes ]; then + echo "SRCS+= bpf.c" >>$CONFIG_MK + fi + echo "SRCS+= if-bsd.c platform-bsd.c" >>$CONFIG_MK ;; esac +if [ -z "$INET" -o "$INET" = yes ]; then + echo "CPPFLAGS+= -DINET" >>$CONFIG_MK + echo "SRCS+= arp.c dhcp.c ipv4.c ipv4ll.c" >>$CONFIG_MK +fi +if [ -z "$INET6" -o "$INET6" = yes ]; then + echo "CPPFLAGS+= -DINET6" >>$CONFIG_MK + echo "SRCS+= ipv6.c ipv6rs.c ipv6ns.c dhcp6.c" >>$CONFIG_MK +fi + # NetBSD: Even if we build for $PREFIX, the clueless user might move us to / LDELF=/libexec/ld.elf_so if [ -e "$LDELF" ]; then diff --git a/dhcp-common.c b/dhcp-common.c index be2d0fac..d8dcf0fd 100644 --- a/dhcp-common.c +++ b/dhcp-common.c @@ -1,6 +1,6 @@ /* * dhcpcd - DHCP client daemon - * Copyright (c) 2006-2012 Roy Marples + * Copyright (c) 2006-2013 Roy Marples * All rights reserved * Redistribution and use in source and binary forms, with or without @@ -249,6 +249,7 @@ print_option(char *s, ssize_t len, int type, int dl, const uint8_t *data, return l; } +#ifdef INET if (type & RFC3361) { if ((tmp = decode_rfc3361(dl, data)) == NULL) return -1; @@ -263,6 +264,7 @@ print_option(char *s, ssize_t len, int type, int dl, const uint8_t *data, if (type & RFC5969) return decode_rfc5969(s, len, dl, data); +#endif if (type & STRING) { /* Some DHCP servers return NULL strings */ @@ -305,7 +307,9 @@ print_option(char *s, ssize_t len, int type, int dl, const uint8_t *data, } else if (type & ADDRIPV4) { l = 16; dl /= 4; - } else if (type & ADDRIPV6) { + } +#ifdef INET6 + else if (type & ADDRIPV6) { e = data + dl; l = 0; while (data < e) { @@ -317,7 +321,9 @@ print_option(char *s, ssize_t len, int type, int dl, const uint8_t *data, data += 16; } return l + 1; - } else if (type & BINHEX) { + } +#endif + else if (type & BINHEX) { l = 2; } else { errno = EINVAL; @@ -361,14 +367,18 @@ print_option(char *s, ssize_t len, int type, int dl, const uint8_t *data, memcpy(&addr.s_addr, data, sizeof(addr.s_addr)); l = snprintf(s, len, "%s", inet_ntoa(addr)); data += sizeof(addr.s_addr); - } else if (type & ADDRIPV6) { + } +#ifdef INET6 + else if (type & ADDRIPV6) { dl = ipv6_printaddr(s, len, data, ifname); if (dl != -1) l = dl; else l = 0; data += 16; - } else if (type & BINHEX) { + } +#endif + else if (type & BINHEX) { l = snprintf(s, len, "%.2x", data[0]); data++; } else diff --git a/dhcp.c b/dhcp.c index 3d4da3b0..6cd52ed8 100644 --- a/dhcp.c +++ b/dhcp.c @@ -217,7 +217,7 @@ static const size_t udp_dhcp_len = sizeof(struct udp_dhcp_packet); static int dhcp_open(struct interface *); void -print_options(void) +dhcp_printoptions(void) { const struct dhcp_opt *opt; const char **p; @@ -1114,7 +1114,7 @@ read_lease(const struct interface *ifp) } ssize_t -configure_env(char **env, const char *prefix, const struct dhcp_message *dhcp, +dhcp_env(char **env, const char *prefix, const struct dhcp_message *dhcp, const struct interface *ifp) { const struct if_options *ifo; diff --git a/dhcp.h b/dhcp.h index d5bab1cd..68cfa811 100644 --- a/dhcp.h +++ b/dhcp.h @@ -225,13 +225,14 @@ struct dhcp_state { #include "if-options.h" #include "net.h" +#ifdef INET extern const struct dhcp_opt const dhcp_opts[]; char *decode_rfc3361(int dl, const uint8_t *data); ssize_t decode_rfc3442(char *out, ssize_t len, int pl, const uint8_t *p); ssize_t decode_rfc5969(char *out, ssize_t len, int pl, const uint8_t *p); -void print_options(void); +void dhcp_printoptions(void); char *get_option_string(const struct dhcp_message *, uint8_t); int get_option_addr(struct in_addr *, const struct dhcp_message *, uint8_t); int get_option_uint32(uint32_t *, const struct dhcp_message *, uint8_t); @@ -241,7 +242,7 @@ int get_option_uint8(uint8_t *, const struct dhcp_message *, uint8_t); !IN_LINKLOCAL(htonl((m)->yiaddr)) && \ get_option_uint8(NULL, m, DHO_MESSAGETYPE) == -1) struct rt *get_option_routes(struct interface *, const struct dhcp_message *); -ssize_t configure_env(char **, const char *, const struct dhcp_message *, +ssize_t dhcp_env(char **, const char *, const struct dhcp_message *, const struct interface *); uint32_t dhcp_xid(const struct interface *); @@ -268,5 +269,15 @@ void dhcp_reboot(struct interface *, int); void dhcp_close(struct interface *); void dhcp_free(struct interface *); int dhcp_dump(const char *); +#else +#define dhcp_printoptions +#define dhcp_drop(a, b) +#define dhcp_start(a) {} +#define dhcp_release(a) {} +#define dhcp_reboot(a, b) b = b +#define dhcp_close(a) +#define dhcp_free(a) +#define dhcp_dump(a) -1 +#endif #endif diff --git a/dhcp6.h b/dhcp6.h index 8b2c9d54..65dfd09d 100644 --- a/dhcp6.h +++ b/dhcp6.h @@ -1,6 +1,6 @@ /* * dhcpcd - DHCP client daemon - * Copyright (c) 2006-2012 Roy Marples + * Copyright (c) 2006-2013 Roy Marples * All rights reserved * Redistribution and use in source and binary forms, with or without @@ -198,6 +198,7 @@ struct dhcp6_state { #define D6_COPTION_DATA(o) \ ((const uint8_t *)(o) + sizeof(struct dhcp6_option)) +#ifdef INET6 void dhcp6_printoptions(void); int dhcp6_addrexists(const struct ipv6_addr *); int dhcp6_start(struct interface *, int); @@ -205,5 +206,13 @@ ssize_t dhcp6_env(char **, const char *, const struct interface *, const struct dhcp6_message *, ssize_t); void dhcp6_free(struct interface *); void dhcp6_drop(struct interface *, const char *); +#else +#define dhcp6_printoptions() +#define dhcp6_addrexists(a) +#define dhcp6_start(a, b) 0 +#define dhcp6_env(a, b, c, d, e) +#define dhcp6_free(a) +#define dhcp6_drop(a, b) +#endif #endif diff --git a/dhcpcd.c b/dhcpcd.c index 6f9e32a4..bb3441d5 100644 --- a/dhcpcd.c +++ b/dhcpcd.c @@ -84,7 +84,7 @@ sigset_t dhcpcd_sigset; static char *cffile; static char *pidfile; -static int linkfd = -1, ipv6rsfd = -1, ipv6nsfd = -1; +static int linkfd = -1; static char **ifv; static int ifc; static char **margv; @@ -912,14 +912,18 @@ main(int argc, char **argv) case 'V': printf("Interface options:\n"); if_printoptions(); +#ifdef INET if (family == 0 || family == AF_INET) { printf("\nDHCPv4 options:\n"); - print_options(); + dhcp_printoptions(); } +#endif +#ifdef INET6 if (family == 0 || family == AF_INET6) { printf("\nDHCPv6 options:\n"); dhcp6_printoptions(); } +#endif exit(EXIT_SUCCESS); case '?': usage(); @@ -1116,26 +1120,8 @@ main(int argc, char **argv) } if (options & DHCPCD_IPV6RS && !check_ipv6(NULL)) options &= ~DHCPCD_IPV6RS; - if (options & DHCPCD_IPV6RS) { - ipv6rsfd = ipv6rs_open(); - if (ipv6rsfd == -1) { - syslog(LOG_ERR, "ipv6rs: %m"); - options &= ~(DHCPCD_IPV6RS | - DHCPCD_IPV6RA_OWN | DHCPCD_IPV6RA_OWN_DEFAULT); - } else { - eloop_event_add(ipv6rsfd, ipv6rs_handledata, NULL); -// atexit(restore_rtadv); - } - if (options & DHCPCD_IPV6RA_OWN || - options & DHCPCD_IPV6RA_OWN_DEFAULT) - { - ipv6nsfd = ipv6ns_open(); - if (ipv6nsfd == -1) - syslog(LOG_ERR, "ipv6nd: %m"); - else - eloop_event_add(ipv6nsfd, ipv6ns_handledata, NULL); - } - } + if (options & DHCPCD_IPV6RS) + ipv6rs_init(); ifc = argc - optind; ifv = argv + optind; diff --git a/if-linux.c b/if-linux.c index 606a5aab..e1c1ff6b 100644 --- a/if-linux.c +++ b/if-linux.c @@ -293,8 +293,10 @@ link_route(struct nlmsghdr *nlm) } if (rt.iface != NULL) { if (metric == rt.iface->metric) { +#ifdef INET inet_cidrtoaddr(rtm->rtm_dst_len, &rt.net); ipv4_routedeleted(&rt); +#endif } } return 1; @@ -303,6 +305,7 @@ link_route(struct nlmsghdr *nlm) static int link_addr(struct nlmsghdr *nlm) { +#ifdef INET int len; struct rtattr *rta; struct ifaddrmsg *ifa; @@ -347,6 +350,7 @@ link_addr(struct nlmsghdr *nlm) rta = RTA_NEXT(rta, len); } ipv4_handleifa(nlm->nlmsg_type, ifn, &addr, &net, &dest); +#endif return 1; } @@ -503,6 +507,7 @@ struct nlmr char buffer[256]; }; +#ifdef INET int if_address(const struct interface *iface, const struct in_addr *address, const struct in_addr *netmask, @@ -599,7 +604,9 @@ if_route(const struct rt *rt, int action) free(nlm); return retval; } +#endif +#ifdef INET6 int if_address6(const struct interface *ifp, const struct ipv6_addr *ap, int action) { @@ -720,3 +727,4 @@ if_route6(const struct rt6 *rt, int action) errno = ENOTSUP; return -1; } +#endif diff --git a/if-options.c b/if-options.c index 89f0b051..ebabb5dd 100644 --- a/if-options.c +++ b/if-options.c @@ -1,6 +1,6 @@ /* * dhcpcd - DHCP client daemon - * Copyright (c) 2006-2012 Roy Marples + * Copyright (c) 2006-2013 Roy Marples * All rights reserved * Redistribution and use in source and binary forms, with or without @@ -306,6 +306,7 @@ splitv(int *argc, char **argv, const char *arg) static int parse_addr(struct in_addr *addr, struct in_addr *net, const char *arg) { +#ifdef INET char *p; int i; @@ -336,6 +337,10 @@ parse_addr(struct in_addr *addr, struct in_addr *net, const char *arg) else if (net != NULL) net->s_addr = ipv4_getnetmask(addr->s_addr); return 0; +#else + syslog(LOG_ERR, "No IPv4 support"); + return -1; +#endif } static const char * @@ -344,6 +349,7 @@ set_option_space(const char *arg, const struct dhcp_opt **d, uint8_t *request[], uint8_t *require[], uint8_t *no[]) { +#ifdef INET6 if (strncmp(arg, "dhcp6_", strlen("dhcp6_")) == 0) { *d = dhcp6_opts; *request = ifo->requestmask6; @@ -351,7 +357,13 @@ set_option_space(const char *arg, const struct dhcp_opt **d, *no = ifo->nomask6; return arg + strlen("dhcp6_"); } +#endif + +#ifdef INET *d = dhcp_opts; +#else + *d = NULL; +#endif *request = ifo->requestmask; *require = ifo->requiremask; *no = ifo->nomask; @@ -777,6 +789,7 @@ parse_option(struct if_options *ifo, int opt, const char *arg) ifo->options &= ~DHCPCD_IPV4; ifo->options |= DHCPCD_IPV6 | DHCPCD_IPV6RS; break; +#ifdef INET case O_ARPING: if (parse_addr(&addr, NULL, arg) != 0) return -1; @@ -798,6 +811,7 @@ parse_option(struct if_options *ifo, int opt, const char *arg) free(ifo->fallback); ifo->fallback = xstrdup(arg); break; +#endif case O_IPV6RS: ifo->options |= DHCPCD_IPV6RS; break; @@ -855,10 +869,14 @@ read_config(const char *file, /* Seed our default options */ ifo = xzalloc(sizeof(*ifo)); + ifo->options |= DHCPCD_DAEMONISE | DHCPCD_LINK; +#ifdef INET ifo->options |= DHCPCD_IPV4 | DHCPCD_IPV4LL; - ifo->options |= DHCPCD_GATEWAY | DHCPCD_DAEMONISE | DHCPCD_LINK; - ifo->options |= DHCPCD_ARP; + ifo->options |= DHCPCD_GATEWAY | DHCPCD_ARP; +#endif +#ifdef INET6 ifo->options |= DHCPCD_IPV6 | DHCPCD_IPV6RS | DHCPCD_IPV6RA_REQRDNSS; +#endif ifo->timeout = DEFAULT_TIMEOUT; ifo->reboot = DEFAULT_REBOOT; ifo->metric = -1; diff --git a/if-pref.c b/if-pref.c index 9e95fba5..7b7fed84 100644 --- a/if-pref.c +++ b/if-pref.c @@ -1,6 +1,6 @@ /* * dhcpcd - DHCP client daemon - * Copyright (c) 2006-2012 Roy Marples + * Copyright (c) 2006-2013 Roy Marples * All rights reserved * Redistribution and use in source and binary forms, with or without diff --git a/ipv4.c b/ipv4.c index eee8ec4a..9b3c2dca 100644 --- a/ipv4.c +++ b/ipv4.c @@ -1,6 +1,6 @@ /* * dhcpcd - DHCP client daemon - * Copyright (c) 2006-2012 Roy Marples + * Copyright (c) 2006-2013 Roy Marples * All rights reserved * Redistribution and use in source and binary forms, with or without @@ -50,8 +50,6 @@ #include "net.h" #include "script.h" -int socket_afnet = -1; - static struct rt *routes; int diff --git a/ipv4.h b/ipv4.h index 574222fb..ff0fbe86 100644 --- a/ipv4.h +++ b/ipv4.h @@ -40,6 +40,7 @@ struct rt { struct rt *next; }; +#ifdef INET int inet_ntocidr(struct in_addr); int inet_cidrtoaddr(int, struct in_addr *); uint32_t ipv4_getnetmask(uint32_t); @@ -76,5 +77,9 @@ int ipv4_opensocket(struct interface *, int); ssize_t ipv4_sendrawpacket(const struct interface *, int, const void *, ssize_t); ssize_t ipv4_getrawpacket(struct interface *, int, void *, ssize_t, int *); +#else +#define ipv4_applyaddr(a) {} +#define ipv4_freeroutes(a) {} +#endif #endif diff --git a/ipv6.h b/ipv6.h index e4d28221..5ab9ff51 100644 --- a/ipv6.h +++ b/ipv6.h @@ -1,6 +1,6 @@ /* * dhcpcd - DHCP client daemon - * Copyright (c) 2006-2012 Roy Marples + * Copyright (c) 2006-2013 Roy Marples * All rights reserved * Redistribution and use in source and binary forms, with or without @@ -62,6 +62,7 @@ struct rt6 { }; TAILQ_HEAD(rt6head, rt6); +#ifdef INET6 int ipv6_init(void); ssize_t ipv6_printaddr(char *, ssize_t, const uint8_t *, const char *); struct in6_addr *ipv6_linklocal(const char *); @@ -73,5 +74,8 @@ ssize_t ipv6_addaddrs(const struct interface *, struct ipv6_addrhead *); int ipv6_removesubnet(const struct interface *, struct ipv6_addr *); void ipv6_buildroutes(void); void ipv6_drop(struct interface *); +#else +#define ipv6_init() -1 +#endif #endif diff --git a/ipv6ns.c b/ipv6ns.c index 120ec2a1..62dde878 100644 --- a/ipv6ns.c +++ b/ipv6ns.c @@ -80,7 +80,7 @@ ipv6ns_cleanup(void) } #endif -int +static int ipv6ns_open(void) { int on; @@ -237,7 +237,7 @@ ipv6ns_sendprobe(void *arg) } /* ARGSUSED */ -void +static void ipv6ns_handledata(_unused void *arg) { ssize_t len; @@ -358,3 +358,17 @@ ipv6ns_handledata(_unused void *arg) eloop_timeout_delete(ipv6ns_unreachable, rap); } } + +int +ipv6ns_init(void) +{ + int fd; + + fd = ipv6ns_open(); + if (fd == -1) { + syslog(LOG_ERR, "ipv6ns_open: %m"); + return -1; + } + eloop_event_add(fd, ipv6ns_handledata, NULL); + return 0; +} diff --git a/ipv6ns.h b/ipv6ns.h index e71a6e79..2a63d3b0 100644 --- a/ipv6ns.h +++ b/ipv6ns.h @@ -1,6 +1,6 @@ /* * dhcpcd - DHCP client daemon - * Copyright (c) 2006-2011 Roy Marples + * Copyright (c) 2006-2013 Roy Marples * All rights reserved * Redistribution and use in source and binary forms, with or without @@ -36,7 +36,6 @@ #define RETRANS_TIMER 1 /* second */ #define DELAY_FIRST_PROBE_TIME 5 /* seconds */ -int ipv6ns_open(void); +int ipv6ns_init(void); void ipv6ns_sendprobe(void *); -void ipv6ns_handledata(void *); #endif diff --git a/ipv6rs.c b/ipv6rs.c index cbf93b6c..67d6dfcf 100644 --- a/ipv6rs.c +++ b/ipv6rs.c @@ -125,7 +125,7 @@ ipv6rs_cleanup(void) } #endif -int +static int ipv6rs_open(void) { int on; @@ -379,7 +379,7 @@ add_router(struct ra *router) } /* ARGSUSED */ -void +static void ipv6rs_handledata(_unused void *arg) { ssize_t len, l, m, n, olen; @@ -1127,3 +1127,26 @@ ipv6rs_drop(struct interface *ifp) script_runreason(ifp, "ROUTERADVERT"); } } + +int +ipv6rs_init(void) +{ + int fd; + + fd = ipv6rs_open(); + if (fd == -1) { + syslog(LOG_ERR, "ipv6rs: %m"); + options &= ~(DHCPCD_IPV6RS | + DHCPCD_IPV6RA_OWN | DHCPCD_IPV6RA_OWN_DEFAULT); + return -1; + } + + eloop_event_add(fd, ipv6rs_handledata, NULL); + // atexit(restore_rtadv); + + if (options & DHCPCD_IPV6RA_OWN || + options & DHCPCD_IPV6RA_OWN_DEFAULT) + return ipv6ns_init(); + + return 0; +} diff --git a/ipv6rs.h b/ipv6rs.h index eeff3ce7..b78abf66 100644 --- a/ipv6rs.h +++ b/ipv6rs.h @@ -1,6 +1,6 @@ /* * dhcpcd - DHCP client daemon - * Copyright (c) 2006-2011 Roy Marples + * Copyright (c) 2006-2013 Roy Marples * All rights reserved * Redistribution and use in source and binary forms, with or without @@ -75,8 +75,8 @@ struct rs_state { #define RS_STATE(a) ((struct rs_state *)(ifp)->if_data[IF_DATA_IPV6RS]) -int ipv6rs_open(void); -void ipv6rs_handledata(void *); +#ifdef INET6 +int ipv6rs_init(void); int ipv6rs_start(struct interface *); ssize_t ipv6rs_env(char **, const char *, const struct interface *); const struct ipv6_addr * ipv6rs_findprefix(const struct ipv6_addr *); @@ -88,4 +88,12 @@ ssize_t ipv6rs_free(struct interface *); void ipv6rs_expire(void *arg); int ipv6rs_has_ra(const struct interface *); void ipv6rs_drop(struct interface *); +#else +#define ipv6rs_init() {} +#define ipv6rs_start(a) {} +#define ipv6rs_free(a) +#define ipv6rs_has_ra(a) 0 +#define ipv6rs_drop(a) +#endif + #endif diff --git a/lpf.c b/lpf.c index 407ef4a8..099fb58f 100644 --- a/lpf.c +++ b/lpf.c @@ -1,6 +1,6 @@ /* * dhcpcd - DHCP client daemon - * Copyright (c) 2006-2011 Roy Marples + * Copyright (c) 2006-2013 Roy Marples * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -64,6 +64,7 @@ static const uint8_t ipv4_bcast_addr[] = { 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff }; +#ifdef INET int ipv4_opensocket(struct interface *ifp, int protocol) { @@ -212,3 +213,4 @@ ipv4_getrawpacket(struct interface *ifp, int protocol, } return bytes; } +#endif diff --git a/net.c b/net.c index 0eed0699..e66b609b 100644 --- a/net.c +++ b/net.c @@ -1,6 +1,6 @@ /* * dhcpcd - DHCP client daemon - * Copyright (c) 2006-2011 Roy Marples + * Copyright (c) 2006-2013 Roy Marples * All rights reserved * Redistribution and use in source and binary forms, with or without @@ -61,6 +61,8 @@ #include "ipv6rs.h" #include "net.h" +int socket_afnet = -1; + static char hwaddr_buffer[(HWADDR_LEN * 3) + 1 + 1024]; char * diff --git a/net.h b/net.h index cf52e7da..ca789525 100644 --- a/net.h +++ b/net.h @@ -1,6 +1,6 @@ /* * dhcpcd - DHCP client daemon - * Copyright (c) 2006-2011 Roy Marples + * Copyright (c) 2006-2013 Roy Marples * All rights reserved * Redistribution and use in source and binary forms, with or without diff --git a/script.c b/script.c index 895c1964..7240dde9 100644 --- a/script.c +++ b/script.c @@ -106,6 +106,7 @@ exec_script(char *const *argv, char *const *env) return pid; } +#ifdef INET static char * make_var(const char *prefix, const char *var) { @@ -151,6 +152,7 @@ append_config(char ***env, ssize_t *len, } *env = ne; } +#endif static size_t arraytostr(const char *const *argv, char **s) @@ -183,17 +185,23 @@ make_env(const struct interface *ifp, const char *reason, char ***argv) const struct interface *ifp2; int dhcp, dhcp6, ra; const struct dhcp_state *state; +#ifdef INET6 const struct dhcp6_state *d6_state; +#endif dhcp = dhcp6 = ra = 0; state = D_STATE(ifp); +#ifdef INET6 d6_state = D6_CSTATE(ifp); +#endif if (strcmp(reason, "TEST") == 0) { +#ifdef INET6 if (d6_state && d6_state->new) dhcp6 = 1; else if (ipv6rs_has_ra(ifp)) ra = 1; else +#endif dhcp = 1; } else if (reason[strlen(reason) - 1] == '6') dhcp6 = 1; @@ -249,9 +257,12 @@ make_env(const struct interface *ifp, const char *reason, char ***argv) if (strcmp(reason, "TEST") == 0) { env[8] = strdup("if_up=false"); env[9] = strdup("if_down=false"); - } else if ((dhcp && state && state->new) || - (dhcp6 && d6_state && d6_state->new) || - (ra && ipv6rs_has_ra(ifp))) + } else if ((dhcp && state && state->new) +#ifdef INET6 + || (dhcp6 && d6_state && d6_state->new) + || (ra && ipv6rs_has_ra(ifp)) +#endif + ) { env[8] = strdup("if_up=true"); env[9] = strdup("if_down=false"); @@ -277,16 +288,19 @@ make_env(const struct interface *ifp, const char *reason, char ***argv) snprintf(env[elen++], e, "old_ssid=%s", ifp->ssid); } } +#ifdef INET if (dhcp && state && state->old) { - e = configure_env(NULL, NULL, state->old, ifp); + e = dhcp_env(NULL, NULL, state->old, ifp); if (e > 0) { env = xrealloc(env, sizeof(char *) * (elen + e + 1)); - elen += configure_env(env + elen, "old", + elen += dhcp_env(env + elen, "old", state->old, ifp); } append_config(&env, &elen, "old", (const char *const *)ifo->config); } +#endif +#ifdef INET6 if (dhcp6 && d6_state && d6_state->old) { e = dhcp6_env(NULL, NULL, ifp, d6_state->old, d6_state->old_len); @@ -296,18 +310,22 @@ make_env(const struct interface *ifp, const char *reason, char ***argv) d6_state->old, d6_state->old_len); } } +#endif dumplease: +#ifdef INET if (dhcp && state && state->new) { - e = configure_env(NULL, NULL, state->new, ifp); + e = dhcp_env(NULL, NULL, state->new, ifp); if (e > 0) { env = xrealloc(env, sizeof(char *) * (elen + e + 1)); - elen += configure_env(env + elen, "new", + elen += dhcp_env(env + elen, "new", state->new, ifp); } append_config(&env, &elen, "new", (const char *const *)ifo->config); } +#endif +#ifdef INET6 if (dhcp6 && d6_state && d6_state->new) { e = dhcp6_env(NULL, NULL, ifp, d6_state->new, d6_state->new_len); @@ -324,6 +342,7 @@ dumplease: elen += ipv6rs_env(env + elen, NULL, ifp); } } +#endif /* Add our base environment */ if (ifo->environ) { @@ -371,10 +390,14 @@ int send_interface(int fd, const struct interface *iface) { int retval = 0; +#ifdef INET const struct dhcp_state *state = D_CSTATE(iface); if (state && send_interface1(fd, iface, state->reason) == -1) retval = -1; +#endif + +#ifdef INET6 if (ipv6rs_has_ra(iface)) { if (send_interface1(fd, iface, "ROUTERADVERT") == -1) retval = -1; @@ -383,6 +406,7 @@ send_interface(int fd, const struct interface *iface) if (send_interface1(fd, iface, "INFORM6") == -1) retval = -1; } +#endif return retval; } @@ -402,12 +426,7 @@ script_runreason(const struct interface *ifp, const char *reason) ifp->options->script[0] == '\0' || strcmp(ifp->options->script, "/dev/null") == 0) return 0; - - if (reason == NULL) { - const struct dhcp_state *state = D_CSTATE(ifp); - if (state) - reason = state->reason; - } + syslog(LOG_DEBUG, "%s: executing `%s', reason %s", ifp->name, argv[0], reason);