]> git.ipfire.org Git - thirdparty/dhcpcd.git/commitdiff
It's now possible to compile out IPv4 and IPv6 support by passing
authorRoy Marples <roy@marples.name>
Mon, 4 Feb 2013 13:30:35 +0000 (13:30 +0000)
committerRoy Marples <roy@marples.name>
Mon, 4 Feb 2013 13:30:35 +0000 (13:30 +0000)
--disable-ipv4 or --disable-ipv6 to configure.

22 files changed:
Makefile
README
configure
dhcp-common.c
dhcp.c
dhcp.h
dhcp6.h
dhcpcd.c
if-linux.c
if-options.c
if-pref.c
ipv4.c
ipv4.h
ipv6.h
ipv6ns.c
ipv6ns.h
ipv6rs.c
ipv6rs.h
lpf.c
net.c
net.h
script.c

index b811d92528db00068c66caf1ca1e04f86de80199..b941c6e76e6fcd096a11d6e861383e26de9378ca 100644 (file)
--- 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 32ae27a5d6fa153901194006ff28507a222275cf..c85432a2860325bfee42966093361802777f3d12 100644 (file)
--- a/README
+++ b/README
@@ -1,5 +1,5 @@
 dhcpcd - DHCP client daemon
-Copyright (c) 2006-2012 Roy Marples <roy@marples.name>
+Copyright (c) 2006-2013 Roy Marples <roy@marples.name>
 
 
 Installation
index a0bee323f808251d78d4a96ea167d3714a19051a..02225f3c8464f98c8439b81166a3c98e1f315e92 100755 (executable)
--- 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
index be2d0fac6e63c68783273210f7dffe0e37efcfc5..d8dcf0fd071bb9a47c65c5acfd4cfa87a3fd6084 100644 (file)
@@ -1,6 +1,6 @@
 /* 
  * dhcpcd - DHCP client daemon
- * Copyright (c) 2006-2012 Roy Marples <roy@marples.name>
+ * Copyright (c) 2006-2013 Roy Marples <roy@marples.name>
  * 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 3d4da3b0f3f4bc54699bccb6da023147ef8728fd..6cd52ed8165d59f5396a7b0f8d7ceab7e30f296f 100644 (file)
--- 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 d5bab1cd68820830716dcc8b4fed73dea3721e39..68cfa81130e864e5031ceb3afc24b680fde509a6 100644 (file)
--- 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 8b2c9d544b745c92525b244af1aa6f25510f08a2..65dfd09de72df203fff7093c87c3e89c67245e27 100644 (file)
--- a/dhcp6.h
+++ b/dhcp6.h
@@ -1,6 +1,6 @@
 /* 
  * dhcpcd - DHCP client daemon
- * Copyright (c) 2006-2012 Roy Marples <roy@marples.name>
+ * Copyright (c) 2006-2013 Roy Marples <roy@marples.name>
  * 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
index 6f9e32a411e6d7e797d02362e5a8295ed590d187..bb3441d5bfedcbd9e38af93beb30e3b0583ff63e 100644 (file)
--- 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;
index 606a5aabe4e4c18da92e045322d40341f0c6fc77..e1c1ff6b05278a8d9db4d19eebfaab3ec6f632eb 100644 (file)
@@ -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
index 89f0b051fe1f87ad3b9e3659036663821acd86ed..ebabb5dde3b31076487b22192f9fd4f9a16b71c3 100644 (file)
@@ -1,6 +1,6 @@
 /* 
  * dhcpcd - DHCP client daemon
- * Copyright (c) 2006-2012 Roy Marples <roy@marples.name>
+ * Copyright (c) 2006-2013 Roy Marples <roy@marples.name>
  * 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;
index 9e95fba58bfd07bb814d07d9c46348993ea7d5cd..7b7fed843afb8a5d49016684cda0f8acaf07c213 100644 (file)
--- a/if-pref.c
+++ b/if-pref.c
@@ -1,6 +1,6 @@
 /* 
  * dhcpcd - DHCP client daemon
- * Copyright (c) 2006-2012 Roy Marples <roy@marples.name>
+ * Copyright (c) 2006-2013 Roy Marples <roy@marples.name>
  * All rights reserved
 
  * Redistribution and use in source and binary forms, with or without
diff --git a/ipv4.c b/ipv4.c
index eee8ec4a96bd4c0f52d85def7c892db922c03904..9b3c2dcae35a87d22d88c273cff6b0dbfdf770f4 100644 (file)
--- a/ipv4.c
+++ b/ipv4.c
@@ -1,6 +1,6 @@
 /* 
  * dhcpcd - DHCP client daemon
- * Copyright (c) 2006-2012 Roy Marples <roy@marples.name>
+ * Copyright (c) 2006-2013 Roy Marples <roy@marples.name>
  * 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 574222fb704d7868ab00337ff5975ffad5f683f2..ff0fbe86f3980e1ee68d5a390318f59f5dc52a05 100644 (file)
--- 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 e4d282212cbc40d3c0619bb00856b15f0a694903..5ab9ff5196d640c62e4554e7a4be1ae40b791523 100644 (file)
--- a/ipv6.h
+++ b/ipv6.h
@@ -1,6 +1,6 @@
 /* 
  * dhcpcd - DHCP client daemon
- * Copyright (c) 2006-2012 Roy Marples <roy@marples.name>
+ * Copyright (c) 2006-2013 Roy Marples <roy@marples.name>
  * 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
index 120ec2a1142009cd09506dedc8e19ec8ce1e5c71..62dde8787d9ac4329d9c5c6008c86b497ac426a2 100644 (file)
--- 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;
+}
index e71a6e790a1578b45374a93c19c4f97c43060578..2a63d3b00a3f3015a033f50a7ee292f6e3f7020a 100644 (file)
--- a/ipv6ns.h
+++ b/ipv6ns.h
@@ -1,6 +1,6 @@
 /* 
  * dhcpcd - DHCP client daemon
- * Copyright (c) 2006-2011 Roy Marples <roy@marples.name>
+ * Copyright (c) 2006-2013 Roy Marples <roy@marples.name>
  * 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
index cbf93b6c6d0deab6639bbb114658328892672307..67d6dfcfaffeadfa6c60f516c44818284024fd5f 100644 (file)
--- 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;
+}
index eeff3ce79b40982e873261018a8a231d97bf87ea..b78abf660a1c4a74b3ea29012024d74f3f32b291 100644 (file)
--- a/ipv6rs.h
+++ b/ipv6rs.h
@@ -1,6 +1,6 @@
 /* 
  * dhcpcd - DHCP client daemon
- * Copyright (c) 2006-2011 Roy Marples <roy@marples.name>
+ * Copyright (c) 2006-2013 Roy Marples <roy@marples.name>
  * 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 407ef4a87cac159bbaf1899ce212e6c3ee005cb3..099fb58f4019b24ca66088864e5f3ec958663688 100644 (file)
--- a/lpf.c
+++ b/lpf.c
@@ -1,6 +1,6 @@
 /*
  * dhcpcd - DHCP client daemon
- * Copyright (c) 2006-2011 Roy Marples <roy@marples.name>
+ * Copyright (c) 2006-2013 Roy Marples <roy@marples.name>
  *
  * 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 0eed069985fdca818465a9082d421467cc92d634..e66b609b5a76be55fc4e7186a0c86dac636d903e 100644 (file)
--- a/net.c
+++ b/net.c
@@ -1,6 +1,6 @@
 /* 
  * dhcpcd - DHCP client daemon
- * Copyright (c) 2006-2011 Roy Marples <roy@marples.name>
+ * Copyright (c) 2006-2013 Roy Marples <roy@marples.name>
  * 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 cf52e7dac80b3c05703f400ff7bc680ae9614909..ca789525b452ac4eeb31155d80b05bf1f8692cfc 100644 (file)
--- a/net.h
+++ b/net.h
@@ -1,6 +1,6 @@
 /* 
  * dhcpcd - DHCP client daemon
- * Copyright (c) 2006-2011 Roy Marples <roy@marples.name>
+ * Copyright (c) 2006-2013 Roy Marples <roy@marples.name>
  * All rights reserved
 
  * Redistribution and use in source and binary forms, with or without
index 895c19640fd1e64ef18690323f19c2412721bb36..7240dde906355c0a15d17ec5d4c110fb710030be 100644 (file)
--- 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);