]> git.ipfire.org Git - thirdparty/dhcpcd.git/commitdiff
Namespace all public dhcpcd.c functions.
authorRoy Marples <roy@marples.name>
Mon, 28 Apr 2014 12:02:12 +0000 (12:02 +0000)
committerRoy Marples <roy@marples.name>
Mon, 28 Apr 2014 12:02:12 +0000 (12:02 +0000)
Add ipv4, ipv6, dhcp and dhcp6 options to re-enable if disabled globally.
Try and load a delegated interface if not running on all interfaces.
Fix delegated interfaces without a prefix set.

15 files changed:
arp.c
control.c
dhcp.c
dhcp6.c
dhcpcd.c
dhcpcd.conf.5.in
dhcpcd.h
if-bsd.c
if-linux.c
if-options.c
if.c
if.h
ipv6.c
ipv6nd.c
script.c

diff --git a/arp.c b/arp.c
index 93f266346d22fbc70f463d175e1b83ab3f82c19c..22ff194fc4771c9921fe918e0290651440994285 100644 (file)
--- a/arp.c
+++ b/arp.c
@@ -113,10 +113,10 @@ arp_failure(struct interface *ifp)
                dhcp_decline(ifp);
        eloop_timeout_delete(ifp->ctx->eloop, NULL, ifp);
        if (state->lease.frominfo)
-               start_interface(ifp);
+               dhcpcd_startinterface(ifp);
        else
                eloop_timeout_add_sec(ifp->ctx->eloop,
-                   DHCP_ARP_FAIL, start_interface, ifp);
+                   DHCP_ARP_FAIL, dhcpcd_startinterface, ifp);
 }
 
 static void
@@ -183,8 +183,8 @@ arp_packet(void *arg)
                        syslog(LOG_INFO,
                            "%s: found %s on hardware address %s",
                            ifp->name, inet_ntoa(ina), hwaddr);
-                       if (select_profile(ifp, hwaddr) == -1 &&
-                           select_profile(ifp, inet_ntoa(ina)) == -1)
+                       if (dhcpcd_selectprofile(ifp, hwaddr) == -1 &&
+                           dhcpcd_selectprofile(ifp, inet_ntoa(ina)) == -1)
                        {
                                state->probes = 0;
                                /* We didn't find a profile for this
@@ -199,7 +199,7 @@ arp_packet(void *arg)
                        }
                        dhcp_close(ifp);
                        eloop_timeout_delete(ifp->ctx->eloop, NULL, ifp);
-                       start_interface(ifp);
+                       dhcpcd_startinterface(ifp);
                        return;
                }
 
@@ -337,7 +337,7 @@ arp_probe(void *arg)
                                    &tv, arp_probe, ifp);
                        else
                                eloop_timeout_add_tv(ifp->ctx->eloop,
-                                   &tv, start_interface, ifp);
+                                   &tv, dhcpcd_startinterface, ifp);
                } else
                        eloop_timeout_add_tv(ifp->ctx->eloop,
                            &tv, dhcp_bind, ifp);
index 4b4758a1e8bea2aa08e46b5b4795001566cd9a4c..c28d790518c68db9eb3a38bc288228df7a68896a 100644 (file)
--- a/control.c
+++ b/control.c
@@ -85,7 +85,7 @@ control_handle_data(void *arg)
                *ap++ = p;
                p += strlen(p) + 1;
        }
-       handle_args(l->ctx, l, argc, argvp);
+       dhcpcd_handleargs(l->ctx, l, argc, argvp);
 }
 
 static void
diff --git a/dhcp.c b/dhcp.c
index f2ff32c39114b18f2b38415455fbc3515a96061f..e9f73ecf4350cf6888a60d522443a531bbf12bf6 100644 (file)
--- a/dhcp.c
+++ b/dhcp.c
@@ -1317,8 +1317,8 @@ dhcp_fallback(void *arg)
        struct interface *iface;
 
        iface = (struct interface *)arg;
-       select_profile(iface, iface->options->fallback);
-       start_interface(iface);
+       dhcpcd_selectprofile(iface, iface->options->fallback);
+       dhcpcd_startinterface(iface);
 }
 
 uint32_t
@@ -1882,7 +1882,7 @@ dhcp_bind(void *arg)
                    iface->name, lease->renewaltime, lease->rebindtime);
        }
        ipv4_applyaddr(iface);
-       if (daemonise(iface->ctx) == 0) {
+       if (dhcpcd_daemonise(iface->ctx) == 0) {
                if (!ipv4ll)
                        arp_close(iface);
                state->state = DHS_BOUND;
diff --git a/dhcp6.c b/dhcp6.c
index 24dac1860966a9179a7a17de167ff9684fa82296..b9970e7bf245a11af9b478163261aa216b710abf 100644 (file)
--- a/dhcp6.c
+++ b/dhcp6.c
@@ -53,6 +53,8 @@
 #include "dhcp6.h"
 #include "duid.h"
 #include "eloop.h"
+#include "if.h"
+#include "if-options.h"
 #include "ipv6nd.h"
 #include "script.h"
 
@@ -1288,7 +1290,7 @@ dhcp6_dadcallback(void *arg)
                                syslog(LOG_DEBUG, "%s: DHCPv6 DAD completed",
                                    ifp->name);
                                script_runreason(ifp, state->reason);
-                               daemonise(ifp->ctx);
+                               dhcpcd_daemonise(ifp->ctx);
                        }
                }
        }
@@ -1756,7 +1758,7 @@ dhcp6_delegate_addr(struct interface *ifp, struct ipv6_addr *prefix,
                state->reason = "DELEGATED6";
        }
 
-       if (sla == NULL) {
+       if (sla == NULL || sla->sla_set == 0) {
                struct interface *ifi;
                unsigned int idx;
                int bits;
@@ -1780,6 +1782,7 @@ dhcp6_delegate_addr(struct interface *ifp, struct ipv6_addr *prefix,
                                asla.prefix_len = 64;
                        else
                                asla.prefix_len = ROUNDUP8(asla.prefix_len);
+
                }
                sla = &asla;
        }
@@ -1846,6 +1849,30 @@ dhcp6_delegate_prefix(struct interface *ifp)
 
        ifo = ifp->options;
        state = D6_STATE(ifp);
+
+       /* Try to load configured interfaces for delegation that do not exist */
+       for (i = 0; i < ifo->ia_len; i++) {
+               ia = &ifo->ia[i];
+               for (j = 0; j < ia->sla_len; j++) {
+                       sla = &ia->sla[j];
+                       for (k = 0; k < i; j++)
+                               if (strcmp(sla->ifname, ia->sla[j].ifname) == 0)
+                                       break;
+                       if (j >= i &&
+                           if_find(ifp->ctx, sla->ifname) == NULL)
+                       {
+                               syslog(LOG_INFO,
+                                   "%s: loading for delegation", sla->ifname);
+                               if (dhcpcd_handleinterface(ifp->ctx, 2,
+                                   sla->ifname) == -1)
+                                       syslog(LOG_ERR,
+                                           "%s: interface does not exist"
+                                           " for delegation",
+                                           sla->ifname);
+                       }
+               }
+       }
+
        TAILQ_FOREACH(ifd, ifp->ctx->ifaces, next) {
                k = 0;
                carrier_warned = abrt = 0;
@@ -1917,23 +1944,6 @@ dhcp6_delegate_prefix(struct interface *ifp)
                        ipv6_addaddrs(&ifd_state->addrs);
                }
        }
-
-       /* Warn about configured interfaces for delegation that do not exist */
-       for (i = 0; i < ifo->ia_len; i++) {
-               ia = &ifo->ia[i];
-               for (j = 0; j < ia->sla_len; j++) {
-                       sla = &ia->sla[j];
-                       for (k = 0; k < i; j++)
-                               if (strcmp(sla->ifname, ia->sla[j].ifname) == 0)
-                                       break;
-                       if (j >= i &&
-                           find_interface(ifp->ctx, sla->ifname) == NULL)
-                               syslog(LOG_ERR,
-                                   "%s: interface does not exist"
-                                   " for delegation",
-                                   sla->ifname);
-               }
-       }
 }
 
 static void
@@ -2449,7 +2459,7 @@ recv:
                }
                if (len) {
                        script_runreason(ifp, state->reason);
-                       daemonise(ifp->ctx);
+                       dhcpcd_daemonise(ifp->ctx);
                } else
                        syslog(LOG_DEBUG,
                            "%s: waiting for DHCPv6 DAD to complete",
index 9415331ed92f1c6ea6c067cf5b3d51efacd2ea78..4da9ab44a0941c1b1c021d0d4f97004daa08b885 100644 (file)
--- a/dhcpcd.c
+++ b/dhcpcd.c
@@ -69,7 +69,7 @@ const char dhcpcd_copyright[] = "Copyright (c) 2006-2014 Roy Marples";
 #include "script.h"
 
 #ifdef USE_SIGNALS
-const int handle_sigs[] = {
+const int dhcpcd_handlesigs[] = {
        SIGALRM,
        SIGHUP,
        SIGINT,
@@ -199,7 +199,7 @@ handle_exit_timeout(void *arg)
                         * an infinite timeout. */
                        ctx->options &=
                            ~(DHCPCD_WAITIP | DHCPCD_WAITIP4 | DHCPCD_WAITIP6);
-                       daemonise(ctx);
+                       dhcpcd_daemonise(ctx);
                } else
                        eloop_exit(ctx->eloop, EXIT_FAILURE);
                return;
@@ -212,7 +212,7 @@ handle_exit_timeout(void *arg)
 
 /* Returns the pid of the child, otherwise 0. */
 pid_t
-daemonise(struct dhcpcd_ctx *ctx)
+dhcpcd_daemonise(struct dhcpcd_ctx *ctx)
 {
 #ifdef THERE_IS_NO_FORK
        eloop_timeout_delete(ctx->eloop, handle_exit_timeout, ctx);
@@ -293,20 +293,6 @@ daemonise(struct dhcpcd_ctx *ctx)
 #endif
 }
 
-struct interface *
-find_interface(struct dhcpcd_ctx *ctx, const char *ifname)
-{
-       struct interface *ifp;
-
-       if (ctx != NULL && ctx->ifaces != NULL) {
-               TAILQ_FOREACH(ifp, ctx->ifaces, next) {
-                       if (strcmp(ifp->name, ifname) == 0)
-                               return ifp;
-               }
-       }
-       return NULL;
-}
-
 static void
 stop_interface(struct interface *ifp)
 {
@@ -461,7 +447,7 @@ configure_interface1(struct interface *ifp)
 }
 
 int
-select_profile(struct interface *ifp, const char *profile)
+dhcpcd_selectprofile(struct interface *ifp, const char *profile)
 {
        struct if_options *ifo;
 
@@ -487,18 +473,18 @@ static void
 configure_interface(struct interface *ifp, int argc, char **argv)
 {
 
-       select_profile(ifp, NULL);
+       dhcpcd_selectprofile(ifp, NULL);
        add_options(ifp->ctx, ifp->name, ifp->options, argc, argv);
        configure_interface1(ifp);
 }
 
 void
-handle_carrier(struct dhcpcd_ctx *ctx, int carrier, unsigned int flags,
+dhcpcd_handlecarrier(struct dhcpcd_ctx *ctx, int carrier, unsigned int flags,
     const char *ifname)
 {
        struct interface *ifp;
 
-       ifp = find_interface(ctx, ifname);
+       ifp = if_find(ctx, ifname);
        if (ifp == NULL || !(ifp->options->options & DHCPCD_LINK))
                return;
 
@@ -533,13 +519,13 @@ handle_carrier(struct dhcpcd_ctx *ctx, int carrier, unsigned int flags,
                        /* BSD does not emit RTM_NEWADDR or RTM_CHGADDR when the
                         * hardware address changes so we have to go
                         * through the disovery process to work it out. */
-                       handle_interface(ctx, 0, ifp->name);
+                       dhcpcd_handleinterface(ctx, 0, ifp->name);
 #endif
                        if (ifp->wireless)
                                if_getssid(ifp->name, ifp->ssid);
                        configure_interface(ifp, ctx->argc, ctx->argv);
                        script_runreason(ifp, "CARRIER");
-                       start_interface(ifp);
+                       dhcpcd_startinterface(ifp);
                }
        }
 }
@@ -571,7 +557,7 @@ warn_iaid_conflict(struct interface *ifp, uint8_t *iaid)
 }
 
 void
-start_interface(void *arg)
+dhcpcd_startinterface(void *arg)
 {
        struct interface *ifp = arg;
        struct if_options *ifo = ifp->options;
@@ -579,7 +565,7 @@ start_interface(void *arg)
        char buf[DUID_LEN * 3];
 
        if (ifp->carrier == LINK_UNKNOWN)
-               handle_carrier(ifp->ctx, LINK_UNKNOWN, 0, ifp->name);
+               dhcpcd_handlecarrier(ifp->ctx, LINK_UNKNOWN, 0, ifp->name);
        if (ifp->carrier == LINK_DOWN) {
                syslog(LOG_INFO, "%s: waiting for carrier", ifp->name);
                return;
@@ -703,8 +689,8 @@ init_state(struct interface *ifp, int argc, char **argv)
                script_runreason(ifp, reason);
 }
 
-void
-handle_interface(void *arg, int action, const char *ifname)
+int
+dhcpcd_handleinterface(void *arg, int action, const char *ifname)
 {
        struct dhcpcd_ctx *ctx;
        struct if_head *ifs;
@@ -714,29 +700,33 @@ handle_interface(void *arg, int action, const char *ifname)
 
        ctx = arg;
        if (action == -1) {
-               ifp = find_interface(ctx, ifname);
-               if (ifp != NULL) {
-                       ifp->options->options |= DHCPCD_DEPARTED;
-                       stop_interface(ifp);
+               ifp = if_find(ctx, ifname);
+               if (ifp == NULL) {
+                       errno = ESRCH;
+                       return -1;
                }
-               return;
+               ifp->options->options |= DHCPCD_DEPARTED;
+               stop_interface(ifp);
+               return 0;
        }
 
        /* If running off an interface list, check it's in it. */
-       if (ctx->ifc) {
+       if (ctx->ifc && action != 2) {
                for (i = 0; i < ctx->ifc; i++)
                        if (strcmp(ctx->ifv[i], ifname) == 0)
                                break;
                if (i >= ctx->ifc)
-                       return;
+                       return 0;
        }
 
+       i = -1;
        ifs = if_discover(ctx, -1, UNCONST(argv));
        TAILQ_FOREACH_SAFE(ifp, ifs, next, ifn) {
                if (strcmp(ifp->name, ifname) != 0)
                        continue;
+               i = 0;
                /* Check if we already have the interface */
-               ifl = find_interface(ctx, ifp->name);
+               ifl = if_find(ctx, ifp->name);
                if (ifl) {
                        /* The flags and hwaddr could have changed */
                        ifl->flags = ifp->flags;
@@ -747,9 +737,9 @@ handle_interface(void *arg, int action, const char *ifname)
                        TAILQ_REMOVE(ifs, ifp, next);
                        TAILQ_INSERT_TAIL(ctx->ifaces, ifp, next);
                }
-               if (action == 1) {
+               if (action > 0) {
                        init_state(ifp, ctx->argc, ctx->argv);
-                       start_interface(ifp);
+                       dhcpcd_startinterface(ifp);
                }
        }
 
@@ -759,16 +749,20 @@ handle_interface(void *arg, int action, const char *ifname)
                if_free(ifp);
        }
        free(ifs);
+
+       if (i == -1)
+               errno = ENOENT;
+       return i;
 }
 
 void
-handle_hwaddr(struct dhcpcd_ctx *ctx, const char *ifname,
+dhcpcd_handlehwaddr(struct dhcpcd_ctx *ctx, const char *ifname,
     const uint8_t *hwaddr, uint8_t hwlen)
 {
        struct interface *ifp;
        char buf[sizeof(ifp->hwaddr) * 3];
 
-       ifp = find_interface(ctx, ifname);
+       ifp = if_find(ctx, ifname);
        if (ifp == NULL)
                return;
 
@@ -797,7 +791,7 @@ if_reboot(struct interface *ifp, int argc, char **argv)
        configure_interface(ifp, argc, argv);
        dhcp_reboot_newopts(ifp, oldopts);
        dhcp6_reboot(ifp);
-       start_interface(ifp);
+       dhcpcd_startinterface(ifp);
 }
 
 static void
@@ -812,7 +806,7 @@ reconf_reboot(struct dhcpcd_ctx *ctx, int action, int argc, char **argv, int oi)
 
        while ((ifp = TAILQ_FIRST(ifs))) {
                TAILQ_REMOVE(ifs, ifp, next);
-               ifn = find_interface(ctx, ifp->name);
+               ifn = if_find(ctx, ifp->name);
                if (ifn) {
                        if (action)
                                if_reboot(ifn, argc, argv);
@@ -822,7 +816,7 @@ reconf_reboot(struct dhcpcd_ctx *ctx, int action, int argc, char **argv, int oi)
                } else {
                        init_state(ifp, argc, argv);
                        TAILQ_INSERT_TAIL(ctx->ifaces, ifp, next);
-                       start_interface(ifp);
+                       dhcpcd_startinterface(ifp);
                }
        }
        free(ifs);
@@ -948,8 +942,8 @@ signal_init(void (*func)(int, siginfo_t *, void *), sigset_t *oldset)
        sa.sa_flags = SA_SIGINFO;
        sigemptyset(&sa.sa_mask);
 
-       for (i = 0; handle_sigs[i]; i++) {
-               if (sigaction(handle_sigs[i], &sa, NULL) == -1)
+       for (i = 0; dhcpcd_handlesigs[i]; i++) {
+               if (sigaction(dhcpcd_handlesigs[i], &sa, NULL) == -1)
                        return -1;
        }
        return 0;
@@ -957,7 +951,8 @@ signal_init(void (*func)(int, siginfo_t *, void *), sigset_t *oldset)
 #endif
 
 int
-handle_args(struct dhcpcd_ctx *ctx, struct fd_list *fd, int argc, char **argv)
+dhcpcd_handleargs(struct dhcpcd_ctx *ctx, struct fd_list *fd,
+    int argc, char **argv)
 {
        struct interface *ifp;
        int do_exit = 0, do_release = 0, do_reboot = 0;
@@ -1083,7 +1078,7 @@ handle_args(struct dhcpcd_ctx *ctx, struct fd_list *fd, int argc, char **argv)
                        return 0;
                }
                for (oi = optind; oi < argc; oi++) {
-                       if ((ifp = find_interface(ctx, argv[oi])) == NULL)
+                       if ((ifp = if_find(ctx, argv[oi])) == NULL)
                                continue;
                        if (do_release) {
                                ifp->options->options |= DHCPCD_RELEASE;
@@ -1455,7 +1450,7 @@ main(int argc, char **argv)
 
        ctx.ifaces = if_discover(&ctx, ctx.ifc, ctx.ifv);
        for (i = 0; i < ctx.ifc; i++) {
-               if (find_interface(&ctx, ctx.ifv[i]) == NULL)
+               if (if_find(&ctx, ctx.ifv[i]) == NULL)
                        syslog(LOG_ERR, "%s: interface not found or invalid",
                            ctx.ifv[i]);
        }
@@ -1471,7 +1466,7 @@ main(int argc, char **argv)
                }
        }
 
-       if (ctx.options & DHCPCD_BACKGROUND && daemonise(&ctx))
+       if (ctx.options & DHCPCD_BACKGROUND && dhcpcd_daemonise(&ctx))
                goto exit_success;
 
        opt = 0;
@@ -1493,7 +1488,7 @@ main(int argc, char **argv)
                        ts.tv_nsec = 0;
                        nanosleep(&ts, NULL);
                        TAILQ_FOREACH(ifp, ctx.ifaces, next) {
-                               handle_carrier(&ctx, LINK_UNKNOWN, 0,
+                               dhcpcd_handlecarrier(&ctx, LINK_UNKNOWN, 0,
                                    ifp->name);
                                if (ifp->carrier != LINK_DOWN) {
                                        opt = 1;
@@ -1512,7 +1507,7 @@ main(int argc, char **argv)
                    !(ctx.options & DHCPCD_WAITIP))
                {
                        syslog(LOG_WARNING, "no interfaces have a carrier");
-                       if (daemonise(&ctx))
+                       if (dhcpcd_daemonise(&ctx))
                                goto exit_success;
                } else if (t > 0) {
                        if (ctx.options & DHCPCD_IPV4LL)
@@ -1526,7 +1521,7 @@ main(int argc, char **argv)
 
        sort_interfaces(&ctx);
        TAILQ_FOREACH(ifp, ctx.ifaces, next) {
-               eloop_timeout_add_sec(ctx.eloop, 0, start_interface, ifp);
+               eloop_timeout_add_sec(ctx.eloop, 0, dhcpcd_startinterface, ifp);
        }
 
        i = eloop_start(&ctx);
index 39ff0827cb45cfb8e54addee588772cb5422188c..b75af9494597f1d60d52bbeb980581c3868f261d 100644 (file)
@@ -22,7 +22,7 @@
 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 .\" SUCH DAMAGE.
 .\"
-.Dd April 6, 2014
+.Dd April 28, 2014
 .Dt DHCPCD.CONF 5
 .Os
 .Sh NAME
@@ -173,6 +173,14 @@ Each instance of this should be unique within the scope of the client and
 warns if a conflict is detected.
 If there is a conflict, it is only a problem if the conflicted IAIDs are
 used on the same network.
+.It Ic dhcp
+Enable DHCP on the interface, on by default.
+.It Ic dhcp6
+Enable DHCPv6 on the interface, on by default.
+.It Ic ipv4
+Enable IPv4 on the interface, on by default.
+.It Ic ipv6
+Enable IPv6 on the interface, on by default.
 .It Ic persistent
 .Nm dhcpcd
 normally de-configures the interface and configuration when it exits.
@@ -263,6 +271,8 @@ per
 space separated.
 IPv6RS should be disabled globally when requesting a Prefix Delegation like so:
 .Pp
+.D1 # Global settings, disable IPv4 and IPv6RS
+.D1 noipv4
 .D1 noipv6rs
 .D1 # Don't touch eth3 at all
 .D1 denyinterfaces eth3 
@@ -270,11 +280,11 @@ IPv6RS should be disabled globally when requesting a Prefix Delegation like so:
 .D1 interface eth0
 .D1 ia_pd 1 eth1/1 eth2/2
 .Pp
-.D1 # Disable automatic address configuration for eth1
+.D1 # Enable automatic address configuration for eth1
 .D1 # eth1 still gets a delegated prefix
 .D1 interface eth1
-.D1 noipv4
-.D1 noipv6
+.D1 ipv4
+.D1 ipv6rs
 .It Ic ipv4only
 Only configure IPv4.
 .It Ic ipv6only
index d1fc19a3ad5b3200694c54b4991aa25c56c4fe82..6554f6935786bc016981af4cf6bb72e942a7f60a 100644 (file)
--- a/dhcpcd.h
+++ b/dhcpcd.h
@@ -135,20 +135,19 @@ struct dhcpcd_ctx {
 };
 
 #ifdef USE_SIGNALS
-extern const int handle_sigs[];
+extern const int dhcpcd_handlesigs[];
 #endif
 
-pid_t daemonise(struct dhcpcd_ctx *);
+pid_t dhcpcd_daemonise(struct dhcpcd_ctx *);
 
-struct interface *find_interface(struct dhcpcd_ctx *, const char *);
-int handle_args(struct dhcpcd_ctx *, struct fd_list *, int, char **);
-void handle_carrier(struct dhcpcd_ctx *, int, unsigned int, const char *);
-void handle_interface(void *, int, const char *);
-void handle_hwaddr(struct dhcpcd_ctx *, const char *,
+int dhcpcd_handleargs(struct dhcpcd_ctx *, struct fd_list *, int, char **);
+void dhcpcd_handlecarrier(struct dhcpcd_ctx *, int, unsigned int, const char *);
+int dhcpcd_handleinterface(void *, int, const char *);
+void dhcpcd_handlehwaddr(struct dhcpcd_ctx *, const char *,
     const unsigned char *, uint8_t);
-void drop_interface(struct interface *, const char *);
-int select_profile(struct interface *, const char *);
+void dhcpcd_dropinterface(struct interface *, const char *);
+int dhcpcd_selectprofile(struct interface *, const char *);
 
-void start_interface(void *);
+void dhcpcd_startinterface(void *);
 
 #endif
index 64229b0b9689b898139a54c9fa26b71aaa11f60b..74d7bbedb6b6884ae1b6fd453d02cba4d20c652f 100644 (file)
--- a/if-bsd.c
+++ b/if-bsd.c
@@ -793,11 +793,11 @@ if_managelink(struct dhcpcd_ctx *ctx)
                                ifan = (struct if_announcemsghdr *)(void *)p;
                                switch(ifan->ifan_what) {
                                case IFAN_ARRIVAL:
-                                       handle_interface(ctx, 1,
+                                       dhcpcd_handleinterface(ctx, 1,
                                            ifan->ifan_name);
                                        break;
                                case IFAN_DEPARTURE:
-                                       handle_interface(ctx, -1,
+                                       dhcpcd_handleinterface(ctx, -1,
                                            ifan->ifan_name);
                                        break;
                                }
@@ -826,7 +826,7 @@ if_managelink(struct dhcpcd_ctx *ctx)
                                        len = LINK_UNKNOWN;
                                        break;
                                }
-                               handle_carrier(ctx, len,
+                               dhcpcd_handlecarrier(ctx, len,
                                    (unsigned int)ifm->ifm_flags, ifname);
                                break;
                        case RTM_DELETE:
@@ -870,7 +870,7 @@ if_managelink(struct dhcpcd_ctx *ctx)
 #endif
                                        memcpy(&sdl, rti_info[RTAX_IFA],
                                            rti_info[RTAX_IFA]->sa_len);
-                                       handle_hwaddr(ctx, ifname,
+                                       dhcpcd_handlehwaddr(ctx, ifname,
                                            (const unsigned char*)CLLADDR(&sdl),
                                            sdl.sdl_alen);
                                        break;
index 7fe227f641828858c3b798331667fc73620ca85a..4ef0c7cf65d4a46c0008d202308bbb73ced84f24 100644 (file)
@@ -412,7 +412,7 @@ link_route(struct dhcpcd_ctx *ctx, struct nlmsghdr *nlm)
                case RTA_OIF:
                        idx = *(unsigned int *)RTA_DATA(rta);
                        if (if_indextoname(idx, ifn))
-                               rt.iface = find_interface(ctx, ifn);
+                               rt.iface = if_find(ctx, ifn);
                        break;
                case RTA_PRIORITY:
                        metric = *(unsigned int *)RTA_DATA(rta);
@@ -457,7 +457,7 @@ link_addr(struct dhcpcd_ctx *ctx, struct nlmsghdr *nlm)
        ifa = NLMSG_DATA(nlm);
        if (if_indextoname(ifa->ifa_index, ifn) == NULL)
                return -1;
-       iface = find_interface(ctx, ifn);
+       iface = if_find(ctx, ifn);
        if (iface == NULL)
                return 1;
        rta = (struct rtattr *) IFA_RTA(ifa);
@@ -533,10 +533,10 @@ handle_rename(struct dhcpcd_ctx *ctx, unsigned int ifindex, const char *ifname)
 
        TAILQ_FOREACH(ifp, ctx->ifaces, next) {
                if (ifp->index == ifindex && strcmp(ifp->name, ifname)) {
-                       handle_interface(ctx, -1, ifp->name);
+                       dhcpcd_handleinterface(ctx, -1, ifp->name);
                        /* Let dev announce the interface for renaming */
                        if (!dev_listening(ctx))
-                               handle_interface(ctx, 1, ifname);
+                               dhcpcd_handleinterface(ctx, 1, ifname);
                        return 1;
                }
        }
@@ -594,7 +594,7 @@ link_netlink(struct dhcpcd_ctx *ctx, struct nlmsghdr *nlm)
        }
 
        if (nlm->nlmsg_type == RTM_DELLINK) {
-               handle_interface(ctx, -1, ifn);
+               dhcpcd_handleinterface(ctx, -1, ifn);
                return 1;
        }
 
@@ -603,7 +603,7 @@ link_netlink(struct dhcpcd_ctx *ctx, struct nlmsghdr *nlm)
         * To trigger a valid hardware address pickup we need to pretend
         * that that don't exist until they have one. */
        if (ifi->ifi_flags & IFF_MASTER && !hwaddr) {
-               handle_interface(ctx, -1, ifn);
+               dhcpcd_handleinterface(ctx, -1, ifn);
                return 1;
        }
 
@@ -612,12 +612,12 @@ link_netlink(struct dhcpcd_ctx *ctx, struct nlmsghdr *nlm)
                    return 1;
 
        /* Check for a new interface */
-       ifp = find_interface(ctx, ifn);
+       ifp = if_find(ctx, ifn);
        if (ifp == NULL) {
                /* If are listening to a dev manager, let that announce
                 * the interface rather than the kernel. */
                if (dev_listening(ctx) < 1)
-                       handle_interface(ctx, 1, ifn);
+                       dhcpcd_handleinterface(ctx, 1, ifn);
                return 1;
        }
 
@@ -630,7 +630,8 @@ link_netlink(struct dhcpcd_ctx *ctx, struct nlmsghdr *nlm)
                        handle_hwaddr(ctx, ifn, RTA_DATA(hwaddr), l);
        }
 
-       handle_carrier(ctx, ifi->ifi_flags & IFF_RUNNING ? LINK_UP : LINK_DOWN,
+       dhcpcd_handlecarrier(ctx,
+           ifi->ifi_flags & IFF_RUNNING ? LINK_UP : LINK_DOWN,
            ifi->ifi_flags, ifn);
        return 1;
 }
index 69fcf3b4967b5168f8a19577550a8e1fb59e4741..087d2af0bceddb1f68d056237db379b9cbf584a2 100644 (file)
 #define O_AUTHNOTREQUIRED      O_BASE + 27
 #define O_NODHCP               O_BASE + 28
 #define O_NODHCP6              O_BASE + 29
+#define O_DHCP                 O_BASE + 30
+#define O_DHCP6                        O_BASE + 31
+#define O_IPV4                 O_BASE + 32
+#define O_IPV6                 O_BASE + 33
 
 const struct option cf_options[] = {
        {"background",      no_argument,       NULL, 'b'},
@@ -143,7 +147,9 @@ const struct option cf_options[] = {
        {"ipv6ra_own_default", no_argument,    NULL, O_IPV6RA_OWN_D},
        {"ipv4only",        no_argument,       NULL, '4'},
        {"ipv6only",        no_argument,       NULL, '6'},
+       {"ipv4",            no_argument,       NULL, O_IPV4},
        {"noipv4",          no_argument,       NULL, O_NOIPV4},
+       {"ipv6",            no_argument,       NULL, O_IPV6},
        {"noipv6",          no_argument,       NULL, O_NOIPV6},
        {"noalias",         no_argument,       NULL, O_NOALIAS},
        {"iaid",            required_argument, NULL, O_IAID},
@@ -162,7 +168,9 @@ const struct option cf_options[] = {
        {"authprotocol",    required_argument, NULL, O_AUTHPROTOCOL},
        {"authtoken",       required_argument, NULL, O_AUTHTOKEN},
        {"noauthrequired",  no_argument,       NULL, O_AUTHNOTREQUIRED},
+       {"dhcp",            no_argument,       NULL, O_DHCP},
        {"nodhcp",          no_argument,       NULL, O_NODHCP},
+       {"dhcp6",           no_argument,       NULL, O_DHCP6},
        {"nodhcp6",         no_argument,       NULL, O_NODHCP6},
        {NULL,              0,                 NULL, '\0'}
 };
@@ -1100,9 +1108,15 @@ parse_option(struct dhcpcd_ctx *ctx, const char *ifname, struct if_options *ifo,
                ifo->options &= ~DHCPCD_IPV4;
                ifo->options |= DHCPCD_IPV6;
                break;
+       case O_IPV4:
+               ifo->options |= DHCPCD_IPV4;
+               break;
        case O_NOIPV4:
                ifo->options &= ~DHCPCD_IPV4;
                break;
+       case O_IPV6:
+               ifo->options |= DHCPCD_IPV6;
+               break;
        case O_NOIPV6:
                ifo->options &= ~DHCPCD_IPV6;
                break;
@@ -1746,9 +1760,15 @@ err_sla:
        case O_AUTHNOTREQUIRED:
                ifo->auth.options &= ~DHCPCD_AUTH_REQUIRE;
                break;
+       case O_DHCP:
+               ifo->options |= DHCPCD_DHCP | DHCPCD_IPV4;
+               break;
        case O_NODHCP:
                ifo->options &= ~DHCPCD_DHCP;
                break;
+       case O_DHCP6:
+               ifo->options |= DHCPCD_DHCP6 | DHCPCD_IPV6;
+               break;
        case O_NODHCP6:
                ifo->options &= ~DHCPCD_DHCP6;
                break;
diff --git a/if.c b/if.c
index 3ea370b793e08637c48ead280aadd010b872caec..ef6d0503acbd431d37c6d87e764e11ceed07d6bb 100644 (file)
--- a/if.c
+++ b/if.c
@@ -482,6 +482,20 @@ if_discover(struct dhcpcd_ctx *ctx, int argc, char * const *argv)
        return ifs;
 }
 
+struct interface *
+if_find(struct dhcpcd_ctx *ctx, const char *ifname)
+{
+       struct interface *ifp;
+
+       if (ctx != NULL && ctx->ifaces != NULL) {
+               TAILQ_FOREACH(ifp, ctx->ifaces, next) {
+                       if (strcmp(ifp->name, ifname) == 0)
+                               return ifp;
+               }
+       }
+       return NULL;
+}
+
 int
 if_domtu(const char *ifname, short int mtu)
 {
diff --git a/if.h b/if.h
index 6c7772333bf707f4dc46142e04504e6655a96b65..32c05ccda11224414afba61c7450f0a930c3a7be 100644 (file)
--- a/if.h
+++ b/if.h
@@ -81,6 +81,7 @@
 #endif
 
 struct if_head *if_discover(struct dhcpcd_ctx *, int, char * const *);
+struct interface *if_find(struct dhcpcd_ctx *, const char *);
 void if_free(struct interface *);
 int if_domtu(const char *, short int);
 #define if_getmtu(iface) if_domtu(iface, 0)
diff --git a/ipv6.c b/ipv6.c
index b77e75906a3152924af1ad9c78fbc7e9584e68a0..7d04f4a01e5b282db9a1047590add472f0f35341 100644 (file)
--- a/ipv6.c
+++ b/ipv6.c
@@ -746,7 +746,7 @@ ipv6_handleifa_addrs(int cmd,
                        break;
                case RTM_NEWADDR:
                        /* Safety - ignore tentative announcements */
-                       if (flags & IN6_IFF_TENTATIVE)
+                       if (flags & (IN6_IFF_DETACHED |IN6_IFF_TENTATIVE))
                                break;
                        if ((ap->flags & IPV6_AF_DADCOMPLETED) == 0) {
                                found++;
index 53893a154090a66d46c3abee202f858dc0f54c78..48deac7357f0bb3b49dbbcdaa1db80f9635be09c 100644 (file)
--- a/ipv6nd.c
+++ b/ipv6nd.c
@@ -483,7 +483,7 @@ ipv6nd_scriptrun(struct ra *rap)
        pid = 0;
        if (hasdns && (hasaddress ||
            !(rap->flags & (ND_RA_FLAG_MANAGED | ND_RA_FLAG_OTHER))))
-               pid = daemonise(rap->iface->ctx);
+               pid = dhcpcd_daemonise(rap->iface->ctx);
 #if 0
        else if (options & DHCPCD_DAEMONISE &&
            !(options & DHCPCD_DAEMONISED) && new_data)
index d5afb65e74378c08242edf8a645a41f50cb519da..8ac4dd984c89b9bbef7b8fdc3f5852bc139a2b16 100644 (file)
--- a/script.c
+++ b/script.c
@@ -108,8 +108,8 @@ exec_script(U const struct dhcpcd_ctx *ctx, char *const *argv, char *const *env)
        flags = POSIX_SPAWN_SETSIGMASK | POSIX_SPAWN_SETSIGDEF;
        posix_spawnattr_setflags(&attr, flags);
        sigemptyset(&defsigs);
-       for (i = 0; i < handle_sigs[i]; i++)
-               sigaddset(&defsigs, handle_sigs[i]);
+       for (i = 0; i < dhcpcd_handlesigs[i]; i++)
+               sigaddset(&defsigs, dhcpcd_handlesigs[i]);
        posix_spawnattr_setsigdefault(&attr, &defsigs);
        posix_spawnattr_setsigmask(&attr, &ctx->sigset);
 #endif