]> git.ipfire.org Git - thirdparty/dhcpcd.git/commitdiff
Move net.c to if.c.
authorRoy Marples <roy@marples.name>
Fri, 25 Apr 2014 10:42:37 +0000 (10:42 +0000)
committerRoy Marples <roy@marples.name>
Fri, 25 Apr 2014 10:42:37 +0000 (10:42 +0000)
Ensure that if.c and if-KERNEL.c are namespaced correctly.

27 files changed:
Makefile
arp.c
common.c
common.h
dhcp-common.c
dhcp.c
dhcp.h
dhcp6.c
dhcpcd.c
duid.c
duid.h
if-bsd.c
if-linux-wireless.c
if-linux.c
if-options.c
if-options.h
if-pref.c
if.c [moved from net.c with 87% similarity]
if.h [moved from net.h with 59% similarity]
ipv4.c
ipv4.h
ipv4ll.c
ipv6.c
ipv6.h
platform.h [deleted file]
script.c
script.h

index 0e018f5766c7394b3d3e71450f1accfcb839b790..f9dadfe25e7110f1bb9542036ff53e6e970b8ab7 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -2,7 +2,7 @@
 
 PROG=          dhcpcd
 SRCS=          common.c control.c dhcpcd.c duid.c eloop.c
-SRCS+=         if-options.c if-pref.c net.c script.c
+SRCS+=         if.c if-options.c if-pref.c script.c
 SRCS+=         dhcp-common.c
 
 CFLAGS?=       -O2
diff --git a/arp.c b/arp.c
index 656dbbea87dc1eef62571793cfb8fad80cb665ac..83745f46d6d7c7d49d378c3a7c365ebc4c150b3f 100644 (file)
--- a/arp.c
+++ b/arp.c
@@ -25,6 +25,8 @@
  * SUCH DAMAGE.
  */
 
+#include <netinet/if_ether.h>
+
 #include <errno.h>
 #include <signal.h>
 #include <stdlib.h>
@@ -39,9 +41,9 @@
 #include "dhcp.h"
 #include "dhcpcd.h"
 #include "eloop.h"
+#include "if.h"
 #include "if-options.h"
 #include "ipv4ll.h"
-#include "net.h"
 
 #define ARP_LEN                                                                      \
        (sizeof(struct arphdr) + (2 * sizeof(uint32_t)) + (2 * HWADDR_LEN))
@@ -79,7 +81,7 @@ arp_send(const struct interface *ifp, int op, in_addr_t sip, in_addr_t tip)
        APPEND(&sip, sizeof(sip));
        ZERO(ifp->hwlen);
        APPEND(&tip, sizeof(tip));
-       return ipv4_sendrawpacket(ifp, ETHERTYPE_ARP, arp_buffer, len);
+       return if_sendrawpacket(ifp, ETHERTYPE_ARP, arp_buffer, len);
 
 eexit:
        errno = ENOBUFS;
@@ -132,7 +134,7 @@ arp_packet(void *arg)
        state = D_STATE(ifp);
        state->fail.s_addr = 0;
        for(;;) {
-               bytes = ipv4_getrawpacket(ifp, ETHERTYPE_ARP,
+               bytes = if_readrawpacket(ifp, ETHERTYPE_ARP,
                    arp_buffer, sizeof(arp_buffer), NULL);
                if (bytes == 0 || bytes == -1)
                        return;
@@ -232,7 +234,7 @@ arp_announce(void *arg)
        if (state->new == NULL)
                return;
        if (state->arp_fd == -1) {
-               state->arp_fd = ipv4_opensocket(ifp, ETHERTYPE_ARP);
+               state->arp_fd = if_openrawsocket(ifp, ETHERTYPE_ARP);
                if (state->arp_fd == -1) {
                        syslog(LOG_ERR, "%s: %s: %m", __func__, ifp->name);
                        return;
@@ -288,7 +290,7 @@ arp_probe(void *arg)
        int arping = 0;
 
        if (state->arp_fd == -1) {
-               state->arp_fd = ipv4_opensocket(ifp, ETHERTYPE_ARP);
+               state->arp_fd = if_openrawsocket(ifp, ETHERTYPE_ARP);
                if (state->arp_fd == -1) {
                        syslog(LOG_ERR, "%s: %s: %m", __func__, ifp->name);
                        return;
index a4a6a8bbd2843db58c41c079861bbe6ecdc35c44..dfb4f697e028f8085f1ae1050b714e9756f11c44 100644 (file)
--- a/common.c
+++ b/common.c
@@ -40,6 +40,7 @@
 #include <sys/param.h>
 #include <sys/time.h>
 
+#include <ctype.h>
 #include <errno.h>
 #include <fcntl.h>
 #include <limits.h>
@@ -180,3 +181,65 @@ uptime(void)
        return tv.tv_sec;
 }
 
+char *
+hwaddr_ntoa(const unsigned char *hwaddr, size_t hwlen, char *buf, size_t buflen)
+{
+       char *p;
+       size_t i;
+
+       if (buf == NULL) {
+               return NULL;
+       }
+
+       if (hwlen * 3 > buflen) {
+               errno = ENOBUFS;
+               return 0;
+       }
+
+       p = buf;
+       for (i = 0; i < hwlen; i++) {
+               if (i > 0)
+                       *p ++= ':';
+               p += snprintf(p, 3, "%.2x", hwaddr[i]);
+       }
+       *p ++= '\0';
+       return buf;
+}
+
+size_t
+hwaddr_aton(unsigned char *buffer, const char *addr)
+{
+       char c[3];
+       const char *p = addr;
+       unsigned char *bp = buffer;
+       size_t len = 0;
+
+       c[2] = '\0';
+       while (*p) {
+               c[0] = *p++;
+               c[1] = *p++;
+               /* Ensure that digits are hex */
+               if (isxdigit((unsigned char)c[0]) == 0 ||
+                   isxdigit((unsigned char)c[1]) == 0)
+               {
+                       errno = EINVAL;
+                       return 0;
+               }
+               /* We should have at least two entries 00:01 */
+               if (len == 0 && *p == '\0') {
+                       errno = EINVAL;
+                       return 0;
+               }
+               /* Ensure that next data is EOL or a seperator with data */
+               if (!(*p == '\0' || (*p == ':' && *(p + 1) != '\0'))) {
+                       errno = EINVAL;
+                       return 0;
+               }
+               if (*p)
+                       p++;
+               if (bp)
+                       *bp++ = (unsigned char)strtol(c, NULL, 16);
+               len++;
+       }
+       return len;
+}
index 823a112445feadcf54036a2d4c6ce90dbda723ff..59473fa232475fa7110448b1e2d93e5b29c0f261 100644 (file)
--- a/common.h
+++ b/common.h
@@ -108,4 +108,6 @@ ssize_t setvar(char ***, const char *, const char *, const char *);
 ssize_t setvard(char ***, const char *, const char *, size_t);
 time_t uptime(void);
 
+char *hwaddr_ntoa(const unsigned char *, size_t, char *, size_t);
+size_t hwaddr_aton(unsigned char *, const char *);
 #endif
index bb27028b8c54d17cddaee2672db97e82da315a80..5b8d15f470a0eee2f6b2fab90ca9f57b73729ed8 100644 (file)
@@ -39,7 +39,8 @@
 #include "common.h"
 #include "dhcp-common.h"
 #include "dhcp.h"
-#include "platform.h"
+#include "if.h"
+#include "ipv6.h"
 
 struct dhcp_opt *
 vivso_find(uint32_t iana_en, const void *arg)
@@ -78,7 +79,7 @@ dhcp_vendor(char *str, size_t len)
            utn.sysname, utn.release, utn.machine);
        p += l;
        len -= (size_t)l;
-       l = hardware_platform(p, len);
+       l = if_machinearch(p, len);
        return (size_t)(p - str);
 }
 
diff --git a/dhcp.c b/dhcp.c
index 2480b8155460e336615da2d57427153a813ca6d6..b55240003c179e47ba9f792f00812a1de271df46 100644 (file)
--- a/dhcp.c
+++ b/dhcp.c
@@ -37,6 +37,7 @@
 #include <arpa/inet.h>
 #include <net/route.h>
 
+#include <netinet/if_ether.h>
 #include <netinet/in_systm.h>
 #include <netinet/in.h>
 #include <netinet/ip.h>
@@ -62,6 +63,7 @@
 #include "dhcp-common.h"
 #include "duid.h"
 #include "eloop.h"
+#include "if.h"
 #include "ipv4.h"
 #include "ipv4ll.h"
 #include "script.h"
@@ -783,9 +785,9 @@ make_message(struct dhcp_message **message,
 
                *p++ = DHO_MAXMESSAGESIZE;
                *p++ = 2;
-               mtu = get_mtu(iface->name);
+               mtu = if_getmtu(iface->name);
                if (mtu < MTU_MIN) {
-                       if (set_mtu(iface->name, MTU_MIN) == 0)
+                       if (if_setmtu(iface->name, MTU_MIN) == 0)
                                sz = MTU_MIN;
                } else if (mtu > MTU_MAX) {
                        /* Even though our MTU could be greater than
@@ -1590,7 +1592,7 @@ send_message(struct interface *iface, uint8_t type,
                if (udp == NULL) {
                        syslog(LOG_ERR, "dhcp_makeudppacket: %m");
                } else {
-                       r = ipv4_sendrawpacket(iface, ETHERTYPE_IP,
+                       r = if_sendrawpacket(iface, ETHERTYPE_IP,
                            (uint8_t *)udp, ulen);
                        free(udp);
                }
@@ -1600,7 +1602,7 @@ send_message(struct interface *iface, uint8_t type,
                 * As such we remove it from consideration without actually
                 * stopping the interface. */
                if (r == -1) {
-                       syslog(LOG_ERR, "%s: ipv4_sendrawpacket: %m",
+                       syslog(LOG_ERR, "%s: if_sendrawpacket: %m",
                            iface->name);
                        if (!(iface->ctx->options & DHCPCD_TEST))
                                dhcp_drop(iface, "FAIL");
@@ -2558,7 +2560,7 @@ dhcp_handlepacket(void *arg)
         * The benefit is that if we get >1 DHCP packet in our buffer and
         * the first one fails for any reason, we can use the next. */
        for(;;) {
-               bytes = (size_t)ipv4_getrawpacket(iface, ETHERTYPE_IP,
+               bytes = (size_t)if_readrawpacket(iface, ETHERTYPE_IP,
                    iface->ctx->packet, udp_dhcp_len, &partialcsum);
                if (bytes == 0 || (ssize_t)bytes == -1)
                        break;
@@ -2679,7 +2681,7 @@ dhcp_open(struct interface *ifp)
 
        state = D_STATE(ifp);
        if (state->raw_fd == -1) {
-               state->raw_fd = ipv4_opensocket(ifp, ETHERTYPE_IP);
+               state->raw_fd = if_openrawsocket(ifp, ETHERTYPE_IP);
                if (state->raw_fd == -1) {
                        syslog(LOG_ERR, "%s: %s: %m", __func__, ifp->name);
                        return -1;
diff --git a/dhcp.h b/dhcp.h
index 365daefffdbb826295696b3acf5720509ca8fd1b..7ff8f9f8d04d0c28ef492cf53ea0fc2cc2ad5e88 100644 (file)
--- a/dhcp.h
+++ b/dhcp.h
@@ -243,7 +243,6 @@ struct dhcp_state {
 
 #include "dhcpcd.h"
 #include "if-options.h"
-#include "net.h"
 
 #ifdef INET
 char *decode_rfc3361(const uint8_t *, size_t);
diff --git a/dhcp6.c b/dhcp6.c
index e2f47301e2719471171c99b065faa800cc5537c3..ebc3c6a7d9a6dc3c01ce87e09b9e02f6e0707679 100644 (file)
--- a/dhcp6.c
+++ b/dhcp6.c
@@ -54,7 +54,6 @@
 #include "duid.h"
 #include "eloop.h"
 #include "ipv6nd.h"
-#include "platform.h"
 #include "script.h"
 
 #ifndef __UNCONST
index 8c6739970579110d73db3fa2c921bd76f098fd9b..9415331ed92f1c6ea6c067cf5b3d51efacd2ea78 100644 (file)
--- a/dhcpcd.c
+++ b/dhcpcd.c
@@ -60,13 +60,12 @@ const char dhcpcd_copyright[] = "Copyright (c) 2006-2014 Roy Marples";
 #include "dhcp6.h"
 #include "duid.h"
 #include "eloop.h"
+#include "if.h"
 #include "if-options.h"
 #include "if-pref.h"
 #include "ipv4.h"
 #include "ipv6.h"
 #include "ipv6nd.h"
-#include "net.h"
-#include "platform.h"
 #include "script.h"
 
 #ifdef USE_SIGNALS
@@ -325,7 +324,7 @@ stop_interface(struct interface *ifp)
        eloop_timeout_delete(ctx->eloop, NULL, ifp);
        if (ifp->options->options & DHCPCD_DEPARTED)
                script_runreason(ifp, "DEPARTED");
-       free_interface(ifp);
+       if_free(ifp);
        if (!(ctx->options & (DHCPCD_MASTER | DHCPCD_TEST)))
                eloop_exit(ctx->eloop, EXIT_FAILURE);
 }
@@ -351,7 +350,7 @@ configure_interface1(struct interface *ifp)
                ifo->options &= ~(DHCPCD_ARP | DHCPCD_IPV4LL);
        if (!(ifp->flags & (IFF_POINTOPOINT | IFF_LOOPBACK | IFF_MULTICAST)))
                ifo->options &= ~DHCPCD_IPV6RS;
-       if (ifo->options & DHCPCD_LINK && carrier_status(ifp) == LINK_UNKNOWN)
+       if (ifo->options & DHCPCD_LINK && if_carrier(ifp) == LINK_UNKNOWN)
                ifo->options &= ~DHCPCD_LINK;
 
        if (ifo->metric != -1)
@@ -362,9 +361,9 @@ configure_interface1(struct interface *ifp)
 
        /* We want to disable kernel interface RA as early as possible. */
        if (ifo->options & DHCPCD_IPV6RS) {
-               ra_global = check_ipv6(ifp->ctx, NULL,
+               ra_global = if_checkipv6(ifp->ctx, NULL,
                    ifp->ctx->options & DHCPCD_IPV6RA_OWN ? 1 : 0);
-               ra_iface = check_ipv6(ifp->ctx, ifp->name,
+               ra_iface = if_checkipv6(ifp->ctx, ifp->name,
                    ifp->options->options & DHCPCD_IPV6RA_OWN ? 1 : 0);
                if (ra_global == -1 || ra_iface == -1)
                        ifo->options &= ~DHCPCD_IPV6RS;
@@ -504,7 +503,7 @@ handle_carrier(struct dhcpcd_ctx *ctx, int carrier, unsigned int flags,
                return;
 
        if (carrier == LINK_UNKNOWN)
-               carrier = carrier_status(ifp); /* will set ifp->flags */
+               carrier = if_carrier(ifp); /* will set ifp->flags */
        else
                ifp->flags = flags;
 
@@ -537,7 +536,7 @@ handle_carrier(struct dhcpcd_ctx *ctx, int carrier, unsigned int flags,
                        handle_interface(ctx, 0, ifp->name);
 #endif
                        if (ifp->wireless)
-                               getifssid(ifp->name, ifp->ssid);
+                               if_getssid(ifp->name, ifp->ssid);
                        configure_interface(ifp, ctx->argc, ctx->argv);
                        script_runreason(ifp, "CARRIER");
                        start_interface(ifp);
@@ -657,8 +656,8 @@ handle_link(void *arg)
        struct dhcpcd_ctx *ctx;
 
        ctx = arg;
-       if (manage_link(ctx) == -1 && errno != ENXIO && errno != ENODEV)
-               syslog(LOG_ERR, "manage_link: %m");
+       if (if_managelink(ctx) == -1 && errno != ENXIO && errno != ENODEV)
+               syslog(LOG_ERR, "if_managelink: %m");
 }
 
 static void
@@ -681,7 +680,7 @@ init_state(struct interface *ifp, int argc, char **argv)
 
        reason = NULL; /* appease gcc */
        if (ifo->options & DHCPCD_LINK) {
-               switch (carrier_status(ifp)) {
+               switch (if_carrier(ifp)) {
                case LINK_DOWN:
                        ifp->carrier = LINK_DOWN;
                        reason = "NOCARRIER";
@@ -732,7 +731,7 @@ handle_interface(void *arg, int action, const char *ifname)
                        return;
        }
 
-       ifs = discover_interfaces(ctx, -1, UNCONST(argv));
+       ifs = if_discover(ctx, -1, UNCONST(argv));
        TAILQ_FOREACH_SAFE(ifp, ifs, next, ifn) {
                if (strcmp(ifp->name, ifname) != 0)
                        continue;
@@ -757,7 +756,7 @@ handle_interface(void *arg, int action, const char *ifname)
        /* Free our discovered list */
        while ((ifp = TAILQ_FIRST(ifs))) {
                TAILQ_REMOVE(ifs, ifp, next);
-               free_interface(ifp);
+               if_free(ifp);
        }
        free(ifs);
 }
@@ -807,7 +806,7 @@ reconf_reboot(struct dhcpcd_ctx *ctx, int action, int argc, char **argv, int oi)
        struct if_head *ifs;
        struct interface *ifn, *ifp;
 
-       ifs = discover_interfaces(ctx, argc - oi, argv + oi);
+       ifs = if_discover(ctx, argc - oi, argv + oi);
        if (ifs == NULL)
                return;
 
@@ -819,7 +818,7 @@ reconf_reboot(struct dhcpcd_ctx *ctx, int action, int argc, char **argv, int oi)
                                if_reboot(ifn, argc, argv);
                        else
                                ipv4_applyaddr(ifn);
-                       free_interface(ifp);
+                       if_free(ifp);
                } else {
                        init_state(ifp, argc, argv);
                        TAILQ_INSERT_TAIL(ctx->ifaces, ifp, next);
@@ -1442,7 +1441,7 @@ main(int argc, char **argv)
         * instead.
         * We also need to open this before checking for interfaces below
         * so that we pickup any new addresses during the discover phase. */
-       ctx.link_fd = open_link_socket();
+       ctx.link_fd = if_openlinksocket();
        if (ctx.link_fd == -1)
                syslog(LOG_ERR, "open_link_socket: %m");
        else
@@ -1454,7 +1453,7 @@ main(int argc, char **argv)
            (DHCPCD_MASTER | DHCPCD_DEV))
                dev_start(&ctx);
 
-       ctx.ifaces = discover_interfaces(&ctx, ctx.ifc, ctx.ifv);
+       ctx.ifaces = if_discover(&ctx, ctx.ifc, ctx.ifv);
        for (i = 0; i < ctx.ifc; i++) {
                if (find_interface(&ctx, ctx.ifv[i]) == NULL)
                        syslog(LOG_ERR, "%s: interface not found or invalid",
@@ -1545,7 +1544,7 @@ exit1:
        if (ctx.ifaces) {
                while ((ifp = TAILQ_FIRST(ctx.ifaces))) {
                        TAILQ_REMOVE(ctx.ifaces, ifp, next);
-                       free_interface(ifp);
+                       if_free(ifp);
                }
                free(ctx.ifaces);
        }
@@ -1557,7 +1556,7 @@ exit1:
 
        free_options(ifo);
        free_globals(&ctx);
-       restore_kernel_ra(&ctx);
+       if_rarestore(&ctx);
        ipv4_ctxfree(&ctx);
        ipv6_ctxfree(&ctx);
        dev_stop(&ctx, !(ctx.options & DHCPCD_FORKED));
diff --git a/duid.c b/duid.c
index 8f99617dd056c41cc0e556f6befa7bb70c4b549d..fa607bc11afa091364c9bada9edb16393f9f00ed 100644 (file)
--- a/duid.c
+++ b/duid.c
@@ -48,8 +48,8 @@
 #endif
 
 #include "common.h"
+#include "dhcpcd.h"
 #include "duid.h"
-#include "net.h"
 
 static size_t
 duid_make(unsigned char *d, const struct interface *ifp, uint16_t type)
diff --git a/duid.h b/duid.h
index b2f5eed4a73ea09e8991030b847a3b0bc2743810..139ce421f4baa5896397e51f377e692829b311f2 100644 (file)
--- a/duid.h
+++ b/duid.h
 #ifndef DUID_H
 #define DUID_H
 
-#include "net.h"
-
-#ifndef DUID_LEN
-#  define DUID_LEN     128 + 2
-#endif
+#define DUID_LEN       128 + 2
 
 size_t duid_init(const struct interface *);
 
index 0c5686d7e84bdf35659550b5d2ebb1ae919ca3af..50001adc0f9d2594208dadb3912b30199bf029c0 100644 (file)
--- a/if-bsd.c
+++ b/if-bsd.c
@@ -42,6 +42,7 @@
 #ifdef __FreeBSD__ /* Needed so that including netinet6/in6_var.h works */
 #  include <net/if_var.h>
 #endif
+#include <net/if_ether.h>
 #include <net/if_media.h>
 #include <net/route.h>
 #include <netinet/in.h>
 #include "config.h"
 #include "common.h"
 #include "dhcp.h"
+#include "if.h"
 #include "if-options.h"
 #include "ipv4.h"
 #include "ipv6.h"
-#include "platform.h"
 
 #include "bpf-filter.h"
 
@@ -109,7 +110,7 @@ if_conf(__unused struct interface *iface)
 }
 
 int
-open_link_socket(void)
+if_openlinksocket(void)
 {
 
 #ifdef SOCK_CLOEXEC
@@ -136,7 +137,7 @@ open_link_socket(void)
 }
 
 int
-getifssid(const char *ifname, char *ssid)
+if_getssid(const char *ifname, char *ssid)
 {
        int s, retval = -1;
 #if defined(SIOCG80211NWID)
@@ -206,7 +207,7 @@ if_vimaster(const char *ifname)
        if (ifmr.ifm_status & IFM_AVALID &&
            IFM_TYPE(ifmr.ifm_active) == IFM_IEEE80211)
        {
-               if (getifssid(ifname, NULL) == -1)
+               if (if_getssid(ifname, NULL) == -1)
                        return 1;
        }
        return 0;
@@ -214,7 +215,7 @@ if_vimaster(const char *ifname)
 
 #ifdef INET
 int
-ipv4_opensocket(struct interface *ifp, int protocol)
+if_openrawsocket(struct interface *ifp, int protocol)
 {
        struct dhcp_state *state;
        int fd = -1;
@@ -303,7 +304,7 @@ eexit:
 }
 
 ssize_t
-ipv4_sendrawpacket(const struct interface *ifp, int protocol,
+if_sendrawpacket(const struct interface *ifp, int protocol,
     const void *data, size_t len)
 {
        struct iovec iov[2];
@@ -329,7 +330,7 @@ ipv4_sendrawpacket(const struct interface *ifp, int protocol,
 /* BPF requires that we read the entire buffer.
  * So we pass the buffer in the API so we can loop on >1 packet. */
 ssize_t
-ipv4_getrawpacket(struct interface *ifp, int protocol,
+if_readrawpacket(struct interface *ifp, int protocol,
     void *data, size_t len, int *partialcsum)
 {
        int fd = -1;
@@ -380,6 +381,7 @@ next:
                        return bytes;
        }
 }
+
 int
 if_address(const struct interface *iface, const struct in_addr *address,
     const struct in_addr *netmask, const struct in_addr *broadcast,
@@ -728,7 +730,7 @@ get_addrs(int type, char *cp, struct sockaddr **sa)
 
 #ifdef INET6
 int
-in6_addr_flags(const char *ifname, const struct in6_addr *addr)
+if_addrflags6(const char *ifname, const struct in6_addr *addr)
 {
        int s, flags;
        struct in6_ifreq ifr6;
@@ -749,7 +751,7 @@ in6_addr_flags(const char *ifname, const struct in6_addr *addr)
 #endif
 
 int
-manage_link(struct dhcpcd_ctx *ctx)
+if_managelink(struct dhcpcd_ctx *ctx)
 {
        /* route and ifwatchd like a msg buf size of 2048 */
        char msg[2048], *p, *e, *cp, ifname[IF_NAMESIZE];
@@ -891,7 +893,7 @@ manage_link(struct dhcpcd_ctx *ctx)
                                            sin6->sin6_addr.s6_addr,
                                            sizeof(ia6.s6_addr));
                                        if (rtm->rtm_type == RTM_NEWADDR) {
-                                               ifa_flags = in6_addr_flags(
+                                               ifa_flags = if_addrflags6(
                                                                ifname,
                                                                &ia6);
                                                if (ifa_flags == -1)
@@ -918,7 +920,7 @@ manage_link(struct dhcpcd_ctx *ctx)
 #  endif
 #endif
 int
-hardware_platform(char *str, size_t len)
+if_machinearch(char *str, size_t len)
 {
        int mib[2] = { CTL_HW, HW_MACHINE_ARCH };
        char march[SYS_NMLN];
@@ -989,7 +991,7 @@ eexit:
 }
 
 void
-restore_kernel_ra(struct dhcpcd_ctx *ctx)
+if_rarestore(struct dhcpcd_ctx *ctx)
 {
 
        if (ctx->options & DHCPCD_FORKED)
@@ -1018,7 +1020,7 @@ restore_kernel_ra(struct dhcpcd_ctx *ctx)
 }
 
 static int
-ipv6_ra_flush(void)
+if_raflush(void)
 {
        int s;
        char dummy[IFNAMSIZ + 8];
@@ -1036,7 +1038,7 @@ ipv6_ra_flush(void)
 }
 
 int
-check_ipv6(struct dhcpcd_ctx *ctx, const char *ifname, int own)
+if_checkipv6(struct dhcpcd_ctx *ctx, const char *ifname, int own)
 {
        int ra;
 
@@ -1120,19 +1122,10 @@ check_ipv6(struct dhcpcd_ctx *ctx, const char *ifname, int own)
                /* Flush the kernel knowledge of advertised routers
                 * and prefixes so the kernel does not expire prefixes
                 * and default routes we are trying to own. */
-               ipv6_ra_flush();
+               if_raflush();
        }
 
        ctx->ra_global = ra;
        return ra;
 }
-
-int
-ipv6_dadtransmits(__unused const char *ifname)
-{
-       int r;
-
-       r = get_inet6_sysctl(IPV6CTL_DAD_COUNT);
-       return r < 0 ? 0 : r;
-}
 #endif
index 2d9519e26f745394870388419d1ba6d0de4d01a1..9733517d8986ab376f20b2b85c65a773ba60ba77 100644 (file)
@@ -1,6 +1,6 @@
 /*
  * dhcpcd - DHCP client daemon
- * Copyright (c) 2009-2013 Roy Marples <roy@marples.name>
+ * Copyright (c) 2009-2014 Roy Marples <roy@marples.name>
  * All rights reserved
 
  * Redistribution and use in source and binary forms, with or without
 #include "common.h"
 #include "config.h"
 
-/* We can't include net.h or dhcpcd.h because
+/* We can't include if.h or dhcpcd.h because
  * they would pull in net/if.h, which defeats the purpose of this hack. */
 #define IF_SSIDSIZE 33
-int getifssid(const char *ifname, char *ssid);
+int if_getssid(const char *ifname, char *ssid);
 
 int
-getifssid(const char *ifname, char *ssid)
+if_getssid(const char *ifname, char *ssid)
 {
 #ifdef SIOCGIWESSID
        int s, retval;
index 9690ea8877a00109f8f958e85bc20256ea2c183f..178f6cc667b15876070b36d6d8ac6886f1bc861e 100644 (file)
@@ -39,6 +39,7 @@
 
 #include <arpa/inet.h>
 #include <net/if.h>
+#include <net/if_ether.h>
 #include <netinet/in_systm.h>
 #include <netinet/in.h>
 #include <net/route.h>
 #include "common.h"
 #include "dev.h"
 #include "dhcp.h"
+#include "if.h"
 #include "ipv4.h"
 #include "ipv6.h"
-#include "net.h"
-#include "platform.h"
 
 #define bpf_insn               sock_filter
 #define BPF_SKIPTYPE
 #define BPF_ETHCOOK            -ETH_HLEN
 #define BPF_WHOLEPACKET        0x0fffffff /* work around buggy LPF filters */
 
-#include "config.h"
-#include "common.h"
-#include "dhcp.h"
-#include "ipv4.h"
 #include "bpf-filter.h"
 
 /* Broadcast address for IPoIB */
@@ -136,7 +132,7 @@ static const char *mproc =
        ;
 
 int
-hardware_platform(char *str, size_t len)
+if_machinearch(char *str, size_t len)
 {
        FILE *fp;
        char buf[256];
@@ -241,7 +237,7 @@ _open_link_socket(struct sockaddr_nl *nl)
 }
 
 int
-open_link_socket(void)
+if_openlinksocket(void)
 {
        struct sockaddr_nl snl;
 
@@ -640,7 +636,7 @@ link_netlink(struct dhcpcd_ctx *ctx, struct nlmsghdr *nlm)
 }
 
 int
-manage_link(struct dhcpcd_ctx *ctx)
+if_managelink(struct dhcpcd_ctx *ctx)
 {
 
        return get_netlink(ctx, ctx->link_fd, MSG_DONTWAIT, &link_netlink);
@@ -739,7 +735,7 @@ struct nlmr
 
 #ifdef INET
 int
-ipv4_opensocket(struct interface *ifp, int protocol)
+if_openrawsocket(struct interface *ifp, int protocol)
 {
        int s;
        union sockunion {
@@ -806,7 +802,7 @@ eexit:
 }
 
 ssize_t
-ipv4_sendrawpacket(const struct interface *ifp, int protocol,
+if_sendrawpacket(const struct interface *ifp, int protocol,
     const void *data, size_t len)
 {
        const struct dhcp_state *state;
@@ -838,7 +834,7 @@ ipv4_sendrawpacket(const struct interface *ifp, int protocol,
 }
 
 ssize_t
-ipv4_getrawpacket(struct interface *ifp, int protocol,
+if_readrawpacket(struct interface *ifp, int protocol,
     void *data, size_t len, int *partialcsum)
 {
        struct iovec iov = {
@@ -1110,7 +1106,7 @@ if_route6(const struct rt6 *rt, int action)
 }
 
 int
-in6_addr_flags(const char *ifname, const struct in6_addr *addr)
+if_addrflags6(const char *ifname, const struct in6_addr *addr)
 {
        FILE *fp;
        char *p, ifaddress[33], address[33], name[IF_NAMESIZE + 1];
@@ -1180,7 +1176,7 @@ write_path(const char *path, const char *val)
 static const char *prefix = "/proc/sys/net/ipv6/conf";
 
 void
-restore_kernel_ra(struct dhcpcd_ctx *ctx)
+if_rarestore(struct dhcpcd_ctx *ctx)
 {
        char path[256];
 
@@ -1200,7 +1196,7 @@ restore_kernel_ra(struct dhcpcd_ctx *ctx)
 }
 
 int
-check_ipv6(struct dhcpcd_ctx *ctx, const char *ifname, int own)
+if_checkipv6(struct dhcpcd_ctx *ctx, const char *ifname, int own)
 {
        int ra;
        size_t i;
@@ -1255,18 +1251,4 @@ check_ipv6(struct dhcpcd_ctx *ctx, const char *ifname, int own)
 
        return ra;
 }
-
-int
-ipv6_dadtransmits(const char *ifname)
-{
-       char path[256];
-       int r;
-
-       if (ifname == NULL)
-               ifname = "default";
-
-       snprintf(path, sizeof(path), "%s/%s/dad_transmits", prefix, ifname);
-       r = check_proc_int(path);
-       return r < 0 ? 0 : r;
-}
 #endif
index 3ff8cdcb060c60bbbcfd84ccbc1b5cfa274ddcc6..69fcf3b4967b5168f8a19577550a8e1fb59e4741 100644 (file)
@@ -52,7 +52,6 @@
 #include "dhcpcd-embedded.h"
 #include "if-options.h"
 #include "ipv4.h"
-#include "platform.h"
 
 /* These options only make sense in the config file, so don't use any
    valid short options for them */
@@ -1861,7 +1860,6 @@ read_config(struct dhcpcd_ctx *ctx,
 #ifdef INET6
        ifo->options |= DHCPCD_IPV6 | DHCPCD_IPV6RS | DHCPCD_IPV6RA_REQRDNSS;
        ifo->options |= DHCPCD_DHCP6;
-       ifo->dadtransmits = ipv6_dadtransmits(ifname);
 #endif
        ifo->timeout = DEFAULT_TIMEOUT;
        ifo->reboot = DEFAULT_REBOOT;
index 9624fd2d3bf23c16c7ed0130a3e56ae7564ba817..abab3f2ec3a442d1834328695722d2aa4daef405 100644 (file)
@@ -166,9 +166,6 @@ struct if_options {
        uint16_t ia_type;
        struct if_ia *ia;
        size_t ia_len;
-#ifdef INET6
-       int dadtransmits;
-#endif
 
        struct dhcp_opt *dhcp_override;
        size_t dhcp_override_len;
index 47694457485351a8ad3631058ae5cf4093fadd0c..ce0752ffef88fa50b184e2bf4271781e254d05dc 100644 (file)
--- a/if-pref.c
+++ b/if-pref.c
@@ -29,8 +29,8 @@
 
 #include "config.h"
 #include "dhcp.h"
+#include "dhcpcd.h"
 #include "if-pref.h"
-#include "net.h"
 
 /* Interface comparer for working out ordering. */
 static int
diff --git a/net.c b/if.c
similarity index 87%
rename from net.c
rename to if.c
index 96f1b0bd040ab54843e0844bda24228b2854e3cc..3ea370b793e08637c48ead280aadd010b872caec 100644 (file)
--- a/net.c
+++ b/if.c
 #include "dev.h"
 #include "dhcp.h"
 #include "dhcp6.h"
+#include "if.h"
 #include "if-options.h"
 #include "ipv4.h"
 #include "ipv6nd.h"
-#include "net.h"
-
-char *
-hwaddr_ntoa(const unsigned char *hwaddr, size_t hwlen, char *buf, size_t buflen)
-{
-       char *p;
-       size_t i;
-
-       if (buf == NULL) {
-               return NULL;
-       }
-
-       if (hwlen * 3 > buflen) {
-               errno = ENOBUFS;
-               return 0;
-       }
-
-       p = buf;
-       for (i = 0; i < hwlen; i++) {
-               if (i > 0)
-                       *p ++= ':';
-               p += snprintf(p, 3, "%.2x", hwaddr[i]);
-       }
-       *p ++= '\0';
-       return buf;
-}
-
-size_t
-hwaddr_aton(unsigned char *buffer, const char *addr)
-{
-       char c[3];
-       const char *p = addr;
-       unsigned char *bp = buffer;
-       size_t len = 0;
-
-       c[2] = '\0';
-       while (*p) {
-               c[0] = *p++;
-               c[1] = *p++;
-               /* Ensure that digits are hex */
-               if (isxdigit((unsigned char)c[0]) == 0 ||
-                   isxdigit((unsigned char)c[1]) == 0)
-               {
-                       errno = EINVAL;
-                       return 0;
-               }
-               /* We should have at least two entries 00:01 */
-               if (len == 0 && *p == '\0') {
-                       errno = EINVAL;
-                       return 0;
-               }
-               /* Ensure that next data is EOL or a seperator with data */
-               if (!(*p == '\0' || (*p == ':' && *(p + 1) != '\0'))) {
-                       errno = EINVAL;
-                       return 0;
-               }
-               if (*p)
-                       p++;
-               if (bp)
-                       *bp++ = (unsigned char)strtol(c, NULL, 16);
-               len++;
-       }
-       return len;
-}
 
 void
-free_interface(struct interface *ifp)
+if_free(struct interface *ifp)
 {
 
        if (ifp == NULL)
@@ -154,7 +91,7 @@ free_interface(struct interface *ifp)
 }
 
 int
-carrier_status(struct interface *iface)
+if_carrier(struct interface *iface)
 {
        int s, r;
        struct ifreq ifr;
@@ -229,7 +166,7 @@ up_interface(struct interface *iface)
 }
 
 struct if_head *
-discover_interfaces(struct dhcpcd_ctx *ctx, int argc, char * const *argv)
+if_discover(struct dhcpcd_ctx *ctx, int argc, char * const *argv)
 {
        struct ifaddrs *ifaddrs, *ifa;
        char *p;
@@ -363,7 +300,7 @@ discover_interfaces(struct dhcpcd_ctx *ctx, int argc, char * const *argv)
                /* Bring the interface up if not already */
                if (!(ifp->flags & IFF_UP)
 #ifdef SIOCGIFMEDIA
-                   && carrier_status(ifp) != LINK_UNKNOWN
+                   && if_carrier(ifp) != LINK_UNKNOWN
 #endif
                   )
                {
@@ -378,7 +315,7 @@ discover_interfaces(struct dhcpcd_ctx *ctx, int argc, char * const *argv)
                /* Don't allow loopback unless explicit */
                if (ifp->flags & IFF_LOOPBACK) {
                        if (argc == 0 && ctx->ifac == 0) {
-                               free_interface(ifp);
+                               if_free(ifp);
                                continue;
                        }
                } else if (ifa->ifa_addr != NULL) {
@@ -396,7 +333,7 @@ discover_interfaces(struct dhcpcd_ctx *ctx, int argc, char * const *argv)
                        if (ioctl(s_link, SIOCGLIFADDR, &iflr) == -1 ||
                            !(iflr.flags & IFLR_ACTIVE))
                        {
-                               free_interface(ifp);
+                               if_free(ifp);
                                continue;
                        }
 #endif
@@ -444,7 +381,7 @@ discover_interfaces(struct dhcpcd_ctx *ctx, int argc, char * const *argv)
                    ifp->family != ARPHRD_ETHER)
                {
                        if (argc == 0 && ctx->ifac == 0) {
-                               free_interface(ifp);
+                               if_free(ifp);
                                continue;
                        }
                        switch (ifp->family) {
@@ -465,16 +402,16 @@ discover_interfaces(struct dhcpcd_ctx *ctx, int argc, char * const *argv)
                /* Handle any platform init for the interface */
                if (if_init(ifp) == -1) {
                        syslog(LOG_ERR, "%s: if_init: %m", p);
-                       free_interface(ifp);
+                       if_free(ifp);
                        continue;
                }
 
                /* Ensure that the MTU is big enough for DHCP */
-               if (get_mtu(ifp->name) < MTU_MIN &&
-                   set_mtu(ifp->name, MTU_MIN) == -1)
+               if (if_getmtu(ifp->name) < MTU_MIN &&
+                   if_setmtu(ifp->name, MTU_MIN) == -1)
                {
                        syslog(LOG_ERR, "%s: set_mtu: %m", p);
-                       free_interface(ifp);
+                       if_free(ifp);
                        continue;
                }
 
@@ -488,7 +425,7 @@ discover_interfaces(struct dhcpcd_ctx *ctx, int argc, char * const *argv)
                /* We reserve the 100 range for virtual interfaces, if and when
                 * we can work them out. */
                ifp->metric = 200 + ifp->index;
-               if (getifssid(ifp->name, ifp->ssid) != -1) {
+               if (if_getssid(ifp->name, ifp->ssid) != -1) {
                        ifp->wireless = 1;
                        ifp->metric += 100;
                }
@@ -522,7 +459,7 @@ discover_interfaces(struct dhcpcd_ctx *ctx, int argc, char * const *argv)
                case AF_INET6:
                        sin6 = (const struct sockaddr_in6 *)
                            (void *)ifa->ifa_addr;
-                       ifa_flags = in6_addr_flags(ifa->ifa_name,
+                       ifa_flags = if_addrflags6(ifa->ifa_name,
                            &sin6->sin6_addr);
                        if (ifa_flags != -1)
                                ipv6_handleifa(ctx, RTM_NEWADDR, ifs,
@@ -546,7 +483,7 @@ discover_interfaces(struct dhcpcd_ctx *ctx, int argc, char * const *argv)
 }
 
 int
-do_mtu(const char *ifname, short int mtu)
+if_domtu(const char *ifname, short int mtu)
 {
        int s, r;
        struct ifreq ifr;
diff --git a/net.h b/if.h
similarity index 59%
rename from net.h
rename to if.h
index 087e28d7045a403bf64316cd4e99ad9f1fe6c06d..6c7772333bf707f4dc46142e04504e6655a96b65 100644 (file)
--- a/net.h
+++ b/if.h
 
 #include <net/if.h>
 #include <netinet/in.h>
-#include <netinet/if_ether.h>
 
 #include "config.h"
-#include "dhcp.h"
 #include "dhcpcd.h"
+#include "ipv4.h"
 #include "ipv6.h"
 
 /* Some systems have route metrics */
 # define IN_LINKLOCAL(addr) ((addr & IN_CLASSB_NET) == LINKLOCAL_ADDR)
 #endif
 
-char *hwaddr_ntoa(const unsigned char *, size_t, char *, size_t);
-size_t hwaddr_aton(unsigned char *, const char *);
-
-int getifssid(const char *, char *);
-int if_vimaster(const char *);
-struct if_head *discover_interfaces(struct dhcpcd_ctx *, int, char * const *);
-void free_interface(struct interface *);
-int do_mtu(const char *, short int);
-#define get_mtu(iface) do_mtu(iface, 0)
-#define set_mtu(iface, mtu) do_mtu(iface, mtu)
+struct if_head *if_discover(struct dhcpcd_ctx *, int, char * const *);
+void if_free(struct interface *);
+int if_domtu(const char *, short int);
+#define if_getmtu(iface) if_domtu(iface, 0)
+#define if_setmtu(iface, mtu) if_domtu(iface, mtu)
+int if_carrier(struct interface *);
 
+/* The below functions are provided by if-KERNEL.c */
 int if_conf(struct interface *);
 int if_init(struct interface *);
+int if_getssid(const char *, char *);
+int if_vimaster(const char *);
+int if_openlinksocket(void);
+int if_managelink(struct dhcpcd_ctx *);
+
+#ifdef INET
+int if_openrawsocket(struct interface *, int);
+ssize_t if_sendrawpacket(const struct interface *,
+    int, const void *, size_t);
+ssize_t if_readrawpacket(struct interface *, int, void *, size_t, int *);
+
+int if_address(const struct interface *,
+    const struct in_addr *, const struct in_addr *,
+    const struct in_addr *, int);
+#define if_addaddress(iface, addr, net, brd)                                 \
+       if_address(iface, addr, net, brd, 1)
+#define if_setaddress(iface, addr, net, brd)                                 \
+       if_address(iface, addr, net, brd, 2)
+#define if_deladdress(iface, addr, net)                                      \
+       if_address(iface, addr, net, NULL, -1)
+
+int if_route(const struct rt *rt, int);
+#define if_addroute(rt) if_route(rt, 1)
+#define if_chgroute(rt) if_route(rt, 0)
+#define if_delroute(rt) if_route(rt, -1)
+#endif
+
+#ifdef INET6
+int if_checkipv6(struct dhcpcd_ctx *ctx, const char *, int);
+void if_rarestore(struct dhcpcd_ctx *);
+
+int if_address6(const struct ipv6_addr *, int);
+#define if_addaddress6(a) if_address6(a, 1)
+#define if_deladdress6(a) if_address6(a, -1)
+int if_addrflags6(const char *, const struct in6_addr *);
+
+int if_route6(const struct rt6 *rt, int);
+#define if_addroute6(rt) if_route6(rt, 1)
+#define if_chgroute6(rt) if_route6(rt, 0)
+#define if_delroute6(rt) if_route6(rt, -1)
+#else
+#define if_checkipv6(a, b, c) (-1)
+#define if_rarestore(a)
+#endif
 
-int open_link_socket(void);
-int manage_link(struct dhcpcd_ctx *);
-int carrier_status(struct interface *);
+int if_machinearch(char *, size_t);
 #endif
diff --git a/ipv4.c b/ipv4.c
index 317cfff9db45d4161ee101b633934a610d5fdf32..7e8f5eaabc788ed818cec18f8f6400ecc53481aa 100644 (file)
--- a/ipv4.c
+++ b/ipv4.c
 #include "common.h"
 #include "dhcpcd.h"
 #include "dhcp.h"
+#include "if.h"
 #include "if-options.h"
 #include "if-pref.h"
 #include "ipv4.h"
-#include "net.h"
 #include "script.h"
 
 #define IPV4_LOOPBACK_ROUTE
@@ -259,11 +259,11 @@ nc_route(int add, struct rt *ort, struct rt *nrt)
         * prefer the interface.
         * This also has the nice side effect of flushing ARP entries so
         * we don't have to do that manually. */
-       if (ipv4_deleteroute(ort) == -1 && errno != ESRCH)
-               syslog(LOG_ERR, "%s: ipv4_deleteroute: %m", ort->iface->name);
-       if (!ipv4_addroute(nrt))
+       if (if_delroute(ort) == -1 && errno != ESRCH)
+               syslog(LOG_ERR, "%s: ipv4_delroute: %m", ort->iface->name);
+       if (!if_addroute(nrt))
                return 0;
-       syslog(LOG_ERR, "%s: ipv4_addroute: %m", nrt->iface->name);
+       syslog(LOG_ERR, "%s: if_addroute: %m", nrt->iface->name);
        return -1;
 }
 
@@ -273,9 +273,9 @@ d_route(struct rt *rt)
        int retval;
 
        desc_route("deleting", rt);
-       retval = ipv4_deleteroute(rt);
+       retval = if_delroute(rt);
        if (retval != 0 && errno != ENOENT && errno != ESRCH)
-               syslog(LOG_ERR,"%s: ipv4_deleteroute: %m", rt->iface->name);
+               syslog(LOG_ERR,"%s: if_delroute: %m", rt->iface->name);
        return retval;
 }
 
@@ -564,7 +564,7 @@ delete_address1(struct interface *ifp,
 
        syslog(LOG_DEBUG, "%s: deleting IP address %s/%d",
            ifp->name, inet_ntoa(*addr), inet_ntocidr(*net));
-       r = ipv4_deleteaddress(ifp, addr, net);
+       r = if_deladdress(ifp, addr, net);
        if (r == -1 && errno != EADDRNOTAVAIL && errno != ENXIO &&
            errno != ENODEV)
                syslog(LOG_ERR, "%s: %s: %m", ifp->name, __func__);
@@ -666,13 +666,13 @@ ipv4_applyaddr(void *arg)
                    ifp->name, inet_ntoa(lease->addr),
                    inet_ntocidr(lease->net));
                if (ifo->options & DHCPCD_NOALIAS)
-                       r = ipv4_setaddress(ifp,
+                       r = if_setaddress(ifp,
                            &lease->addr, &lease->net, &lease->brd);
                else
-                       r = ipv4_addaddress(ifp,
+                       r = if_addaddress(ifp,
                            &lease->addr, &lease->net, &lease->brd);
                if (r == -1 && errno != EEXIST) {
-                       syslog(LOG_ERR, "%s: ipv4_addaddress: %m", __func__);
+                       syslog(LOG_ERR, "%s: if_addaddress: %m", __func__);
                        return;
                }
                istate = ipv4_getstate(ifp);
@@ -698,7 +698,7 @@ ipv4_applyaddr(void *arg)
                rt->iface = ifp;
                rt->metric = 0;
                if (!find_route(ifp->ctx->ipv4_routes, rt, NULL))
-                       ipv4_deleteroute(rt);
+                       if_delroute(rt);
                free(rt);
        }
 
diff --git a/ipv4.h b/ipv4.h
index c048cb6d4de59407f5800fe1dd8b4b37eb960f15..12f47c681ccfb3fff8c2dd4bdee034aead31c541 100644 (file)
--- a/ipv4.h
+++ b/ipv4.h
@@ -74,27 +74,8 @@ struct ipv4_addr *ipv4_findaddr(struct interface *,
 void ipv4_handleifa(struct dhcpcd_ctx *, int, struct if_head *, const char *,
     const struct in_addr *, const struct in_addr *, const struct in_addr *);
 
-int if_address(const struct interface *,
-    const struct in_addr *, const struct in_addr *,
-    const struct in_addr *, int);
-#define ipv4_addaddress(iface, addr, net, brd)                               \
-       if_address(iface, addr, net, brd, 1)
-#define ipv4_setaddress(iface, addr, net, brd)                               \
-       if_address(iface, addr, net, brd, 2)
-#define ipv4_deleteaddress(iface, addr, net)                                 \
-       if_address(iface, addr, net, NULL, -1)
-
-int if_route(const struct rt *rt, int);
-#define ipv4_addroute(rt) if_route(rt, 1)
-#define ipv4_changeroute(rt) if_route(rt, 0)
-#define ipv4_deleteroute(rt) if_route(rt, -1)
-#define del_src_route(rt) i_route(rt, -2);
 void ipv4_freeroutes(struct rt_head *);
 
-int ipv4_opensocket(struct interface *, int);
-ssize_t ipv4_sendrawpacket(const struct interface *,
-    int, const void *, size_t);
-ssize_t ipv4_getrawpacket(struct interface *, int, void *, size_t, int *);
 void ipv4_free(struct interface *);
 void ipv4_ctxfree(struct dhcpcd_ctx *);
 #else
index 83d96cb923d6df3faa8f9768938a28955d5da0ff..645f0aa33da65eb93b64c4c38bd4b0aa911eb18c 100644 (file)
--- a/ipv4ll.c
+++ b/ipv4ll.c
@@ -37,9 +37,9 @@
 #include "common.h"
 #include "dhcp.h"
 #include "eloop.h"
+#include "if.h"
 #include "if-options.h"
 #include "ipv4ll.h"
-#include "net.h"
 
 static struct dhcp_message *
 ipv4ll_make_lease(uint32_t addr)
diff --git a/ipv6.c b/ipv6.c
index 9002d0c33ce446af6b753e5d4c6cf5596aac87f1..0c5f9b357877b904198c080dbb90f9840037ea40 100644 (file)
--- a/ipv6.c
+++ b/ipv6.c
@@ -67,6 +67,7 @@
 #include "dhcpcd.h"
 #include "dhcp6.h"
 #include "eloop.h"
+#include "if.h"
 #include "ipv6.h"
 #include "ipv6nd.h"
 
@@ -406,8 +407,8 @@ ipv6_addaddr(struct ipv6_addr *ap)
        if (!(ap->flags & IPV6_AF_DADCOMPLETED) &&
            ipv6_findaddr(ap->iface, &ap->addr))
                ap->flags |= IPV6_AF_DADCOMPLETED;
-       if (add_address6(ap) == -1) {
-               syslog(LOG_ERR, "add_address6 %m");
+       if (if_addaddress6(ap) == -1) {
+               syslog(LOG_ERR, "if_addaddress6: %m");
                return -1;
        }
        ap->flags &= ~IPV6_AF_NEW;
@@ -416,7 +417,7 @@ ipv6_addaddr(struct ipv6_addr *ap)
                ap->flags |= IPV6_AF_DELEGATED;
        if (ap->iface->options->options & DHCPCD_IPV6RA_OWN &&
            ipv6_removesubnet(ap->iface, ap) == -1)
-               syslog(LOG_ERR,"ipv6_removesubnet %m");
+               syslog(LOG_ERR,"ipv6_removesubnet: %m");
        if (ap->prefix_pltime == ND6_INFINITE_LIFETIME &&
            ap->prefix_vltime == ND6_INFINITE_LIFETIME)
                syslog(LOG_DEBUG,
@@ -465,9 +466,9 @@ ipv6_addaddrs(struct ipv6_addrhead *addrs)
                                    ap->iface->name, ap->saddr);
                                i++;
                                if (!IN6_IS_ADDR_UNSPECIFIED(&ap->addr) &&
-                                   del_address6(ap) == -1 &&
+                                   if_deladdress6(ap) == -1 &&
                                    errno != EADDRNOTAVAIL && errno != ENXIO)
-                                       syslog(LOG_ERR, "del_address6 %m");
+                                       syslog(LOG_ERR, "if_deladdress6: %m");
                        }
                        eloop_q_timeout_delete(ap->iface->ctx->eloop,
                            0, NULL, ap);
@@ -506,9 +507,9 @@ ipv6_freedrop_addrs(struct ipv6_addrhead *addrs, int drop,
                {
                        syslog(LOG_INFO, "%s: deleting address %s",
                            ap->iface->name, ap->saddr);
-                       if (del_address6(ap) == -1 &&
+                       if (if_deladdress6(ap) == -1 &&
                            errno != EADDRNOTAVAIL && errno != ENXIO)
-                               syslog(LOG_ERR, "del_address6 %m");
+                               syslog(LOG_ERR, "if_deladdress6: :%m");
                }
                free(ap);
        }
@@ -820,11 +821,11 @@ nc_route(int add, struct rt6 *ort, struct rt6 *nrt)
        desc_route(add ? "adding" : "changing", nrt);
        /* We delete and add the route so that we can change metric and
         * prefer the interface. */
-       if (del_route6(ort) == -1 && errno != ESRCH)
-               syslog(LOG_ERR, "%s: del_route6: %m", ort->iface->name);
-       if (add_route6(nrt) == 0)
+       if (if_delroute6(ort) == -1 && errno != ESRCH)
+               syslog(LOG_ERR, "%s: if_delroute6: %m", ort->iface->name);
+       if (if_addroute6(nrt) == 0)
                return 0;
-       syslog(LOG_ERR, "%s: add_route6: %m", nrt->iface->name);
+       syslog(LOG_ERR, "%s: if_addroute6: %m", nrt->iface->name);
        return -1;
 }
 
@@ -834,9 +835,9 @@ d_route(struct rt6 *rt)
        int retval;
 
        desc_route("deleting", rt);
-       retval = del_route6(rt);
+       retval = if_delroute6(rt);
        if (retval != 0 && errno != ENOENT && errno != ESRCH)
-               syslog(LOG_ERR,"%s: del_route6: %m", rt->iface->name);
+               syslog(LOG_ERR,"%s: if_delroute6: %m", rt->iface->name);
        return retval;
 }
 
@@ -938,7 +939,7 @@ ipv6_removesubnet(struct interface *ifp, struct ipv6_addr *addr)
                if (!find_route6(ifp->ctx->ipv6->routes, rt))
 #endif
                {
-                       r = del_route6(rt);
+                       r = if_delroute6(rt);
                        if (r == -1 && errno == ESRCH)
                                r = 0;
                }
diff --git a/ipv6.h b/ipv6.h
index e2d4183bf40129c7d97ca66ae452b8dcd8527c6f..3c234557ce6a17fcba36266106011bf8f398793e 100644 (file)
--- a/ipv6.h
+++ b/ipv6.h
@@ -186,17 +186,6 @@ void ipv6_ctxfree(struct dhcpcd_ctx *);
 int ipv6_removesubnet(struct interface *, struct ipv6_addr *);
 void ipv6_buildroutes(struct dhcpcd_ctx *);
 
-int if_address6(const struct ipv6_addr *, int);
-#define add_address6(a) if_address6(a, 1)
-#define del_address6(a) if_address6(a, -1)
-int in6_addr_flags(const char *, const struct in6_addr *);
-
-int if_route6(const struct rt6 *rt, int);
-#define add_route6(rt) if_route6(rt, 1)
-#define change_route6(rt) if_route6(rt, 0)
-#define del_route6(rt) if_route6(rt, -1)
-#define del_src_route6(rt) if_route6(rt, -2);
-
 #else
 #define ipv6_init(a) NULL
 #define ipv6_free_ll_callbacks(a)
diff --git a/platform.h b/platform.h
deleted file mode 100644 (file)
index 8011b1b..0000000
+++ /dev/null
@@ -1,41 +0,0 @@
-/*
- * dhcpcd - DHCP client daemon
- * Copyright (c) 2006-2014 Roy Marples <roy@marples.name>
- * All rights reserved
-
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-#ifndef PLATFORM_H
-#define PLATFORM_H
-
-int hardware_platform(char *, size_t);
-#ifdef INET6
-int check_ipv6(struct dhcpcd_ctx *ctx, const char *, int);
-int ipv6_dadtransmits(const char *);
-void restore_kernel_ra(struct dhcpcd_ctx *);
-#else
-#define check_ipv6(a, b,c ) -1
-#define restore_kernel_ra(a)
-#endif
-
-#endif
index cbcf68c7a45da631f4d4a3577d42a7e765696d08..d5afb65e74378c08242edf8a645a41f50cb519da 100644 (file)
--- a/script.c
+++ b/script.c
 #include "common.h"
 #include "dhcp.h"
 #include "dhcp6.h"
+#include "if.h"
 #include "if-options.h"
 #include "if-pref.h"
 #include "ipv6nd.h"
-#include "net.h"
 #include "script.h"
 
 #ifdef HAVE_SPAWN_H
@@ -303,7 +303,7 @@ make_env(const struct interface *ifp, const char *reason, char ***argv)
        EMALLOC(6, e);
        snprintf(env[6], e, "ifflags=%u", ifp->flags);
        EMALLOC(7, e);
-       snprintf(env[7], e, "ifmtu=%d", get_mtu(ifp->name));
+       snprintf(env[7], e, "ifmtu=%d", if_getmtu(ifp->name));
        l = e = strlen("interface_order=");
        TAILQ_FOREACH(ifp2, ifp->ctx->ifaces, next) {
                e += strlen(ifp2->name) + 1;
index 4f9a085aef2daf44b2f79ae88e522eafcbc30efa..e1862e83c7de09589d63ab42676b637fd9347b0c 100644 (file)
--- a/script.h
+++ b/script.h
@@ -28,8 +28,6 @@
 #ifndef SCRIPT_H
 #define SCRIPT_H
 
-#include "net.h"
-
 void if_printoptions(void);
 int send_interface(int, const struct interface *);
 int script_runreason(const struct interface *, const char *);