]> git.ipfire.org Git - thirdparty/dhcpcd.git/commitdiff
Compile and work on OpenBSD.
authorRoy Marples <roy@marples.name>
Wed, 5 Mar 2014 18:11:22 +0000 (18:11 +0000)
committerRoy Marples <roy@marples.name>
Wed, 5 Mar 2014 18:11:22 +0000 (18:11 +0000)
However, there is a problem deleting both IPv4 and IPv6 subnet routes.
Also, there is a problem opening a BPF fd in non blocking mode directly and
posix_spawn(3) fails to work so we block that in configure.

README
bpf.c
configure
dhcpcd.c
if-bsd.c
ipv6.c
ipv6.h
platform-bsd.c

diff --git a/README b/README
index 7f416382d089c02a028623a7e5c60fcea25f439e..6ee3f04234e2371d6dc94f989de3525113c2673e 100644 (file)
--- a/README
+++ b/README
@@ -47,6 +47,10 @@ BSD systems where this is known to be a problem
     Occured in NetBSD-5.0, fixed in NetBSD-6.99.29
     Occured in OpenBSD-4.2, fixed in OpenBSD-5.0
 
+On FreeBSD-10 dhcpcd cannot delete IPv4 subnet routes
+On OpenBSD-5.4 dhcpcd cannot delete IPv4 subnet routes and the kernel allows
+the addition of duplicate routes.
+
 We try and detect how dhcpcd should interact with system services at runtime.
 If we cannot auto-detect how do to this, or it is wrong then
 you can change this by passing shell commands to --serviceexists,
diff --git a/bpf.c b/bpf.c
index 7e48efb15d52ff60a17c0ec6226cdafea6bed20a..8ec6dfe78c320a9ba93fe256dc6af7244f7148c5 100644 (file)
--- a/bpf.c
+++ b/bpf.c
@@ -119,6 +119,14 @@ ipv4_opensocket(struct interface *ifp, int protocol)
        }
        if (ioctl(fd, BIOCSETF, &pf) == -1)
                goto eexit;
+
+#ifdef __OpenBSD__
+       /* For some reason OpenBSD fails to open the fd as non blocking */
+       if ((flags = fcntl(fd, F_GETFL, 0)) == -1 ||
+           fcntl(fd, F_SETFL, flags | O_NONBLOCK) == -1)
+               goto eexit;
+#endif
+
        return fd;
 
 eexit:
index 9e67d33ea751e150b83be6a4f7e5667ffcadcc02..2c7640be78fdbd81b55024c993b3b3d27e167c59 100755 (executable)
--- a/configure
+++ b/configure
@@ -280,11 +280,15 @@ if [ "$DEBUG" != no -a "$DEBUG" != false ]; then
 CFLAGS+=       -g -Wall -Wextra -Wshadow -Wformat=2
 CFLAGS+=       -Wmissing-prototypes -Wmissing-declarations
 CFLAGS+=       -Wmissing-noreturn -Wmissing-format-attribute
-CFLAGS+=       -Wredundant-decls  -Wnested-externs
+CFLAGS+=       -Wnested-externs
 CFLAGS+=       -Winline -Wwrite-strings -Wcast-align -Wcast-qual
 CFLAGS+=       -Wpointer-arith -Wstrict-overflow
 CFLAGS+=       -Wdeclaration-after-statement
 EOF
+       case "$OS" in
+       openbsd)        ;; # OpenBSD has many redundant decs in system headers
+       *)              echo "CFLAGS+=  -Wredundant-decls" >>$CONFIG_MK;;
+       esac
 fi
 
 if [ -z "$EMBEDDED" -o "$EMBEDDED" = yes ]; then
@@ -495,6 +499,38 @@ if [ "$TAILQ_FOREACH_SAFE" = no ]; then
 EOF
 fi
 
+if [ -z "$TAILQ_CONCAT" ]; then
+       printf "Testing for TAILQ_CONCAT ..."
+       cat <<EOF >_queue.c
+#include <sys/queue.h>
+int main(void) {
+#ifndef TAILQ_CONCAT
+#error TAILQ_CONCAT
+#endif
+       return 0;
+}
+EOF
+       if $XCC _queue.c -o _queue 2>/dev/null; then
+               TAILQ_CONCAT=yes
+       else
+               TAILQ_CONCAT=no
+       fi
+       echo "$TAILQ_CONCAT"
+       rm -f _queue.c _queue
+fi
+if [ "$TAILQ_CONCAT" = no ]; then
+       cat <<EOF >>$CONFIG_H
+#define TAILQ_CONCAT(head1, head2, field) do {                         \\
+       if (!TAILQ_EMPTY(head2)) {                                      \\
+               *(head1)->tqh_last = (head2)->tqh_first;                \\
+               (head2)->tqh_first->field.tqe_prev = (head1)->tqh_last; \\
+               (head1)->tqh_last = (head2)->tqh_last;                  \\
+               TAILQ_INIT((head2));                                    \\
+       }                                                               \\
+} while (/*CONSTCOND*/0)
+EOF
+fi
+
 if [ -z "$POSIX_SPAWN" ]; then
        printf "Testing for posix_spawn ... "
        cat <<EOF >_posix_spawn.c
@@ -506,7 +542,10 @@ int main(void) {
 }
 EOF
        if $XCC _posix_spawn.c -o _posix_spawn 2>/dev/null; then
-               POSIX_SPAWN=yes
+               case "$OS" in
+               openbsd) printf "broken OpenBSD ... "; POSIX_SPAWN=no;;
+               *) POSIX_SPAWN=yes;;
+               esac
        else
                POSIX_SPAWN=no
        fi
index 7bd9124e78256162710462d243c3d3a19f350aa2..5ac26c74d4ad7f993f6bd3a0ffbb377751f337e1 100644 (file)
--- a/dhcpcd.c
+++ b/dhcpcd.c
@@ -1403,6 +1403,17 @@ main(int argc, char **argv)
        }
 #endif
 
+#ifdef __FreeBSD__
+       syslog(LOG_WARNING, "FreeBSD errors that are worked around:");
+       syslog(LOG_WARNING, "IPv4 subnet routes cannot be deleted");
+#endif
+#ifdef __OpenBSD__
+       syslog(LOG_WARNING, "OpenBSD errors that need to be fixed:");
+       syslog(LOG_WARNING,
+           "IPv4 subnet routes and IPv6 prefixes cannot be deleted");
+       syslog(LOG_WARNING, "duplicate IPv4 subnet routes will be created");
+#endif
+
        ctx.ifc = argc - optind;
        ctx.ifv = argv + optind;
 
index 076be3b4589cb74331fcb906a8837685ce0ebcef..8d33cb50b95c07d8eb1a5dc6260f240f21464fc2 100644 (file)
--- a/if-bsd.c
+++ b/if-bsd.c
@@ -47,6 +47,7 @@
 #elif __APPLE__
   /* FIXME: Add apple includes so we can work out SSID */
 #else
+#  include <net80211/ieee80211.h>
 #  include <net80211/ieee80211_ioctl.h>
 #endif
 
diff --git a/ipv6.c b/ipv6.c
index 51c8d66b684177f48a358dff7b10dbf63713a19e..018a62a7ee18f9e4aa026098efbc5d68471d86a9 100644 (file)
--- a/ipv6.c
+++ b/ipv6.c
@@ -39,8 +39,8 @@
 #  define IN6_IFF_TENTATIVE    (IFA_F_TENTATIVE | IFA_F_OPTIMISTIC)
 #  define IN6_IFF_DUPLICATED   IFA_F_DADFAILED
 #else
-#ifdef __FreeBSD__ /* Needed so that including netinet6/in6_var.h works */
 #  include <net/if.h>
+#ifdef __FreeBSD__ /* Needed so that including netinet6/in6_var.h works */
 #  include <net/if_var.h>
 #endif
 #  include <netinet6/in6_var.h>
diff --git a/ipv6.h b/ipv6.h
index b94cdf8aa89b0d7064091610d98e4134b104f0de..12367ad9e1974cebf211c44c5f1327f70916c1e5 100644 (file)
--- a/ipv6.h
+++ b/ipv6.h
@@ -29,6 +29,7 @@
 #define IPV6_H
 
 #include <sys/queue.h>
+#include <sys/uio.h>
 
 #include <netinet/in.h>
 
@@ -140,6 +141,7 @@ struct ipv6_state {
 #define IP6BUFLEN      (CMSG_SPACE(sizeof(struct in6_pktinfo)) + \
                        CMSG_SPACE(sizeof(int)))
 
+#ifdef INET6
 struct ipv6_ctx {
        struct sockaddr_in6 from;
        struct msghdr sndhdr;
@@ -164,6 +166,7 @@ struct ipv6_ctx {
 
        int dhcp_fd;
 };
+#endif
 
 #ifdef INET6
 struct ipv6_ctx *ipv6_init(struct dhcpcd_ctx *);
index 925b74ea709139f82ddee3fdab9ea40e7a31dcc7..f6088f8c0233b5def79ccf6deed863937cad4358 100644 (file)
 #  define SYS_NMLN 256
 #endif
 
+#ifndef HW_MACHINE_ARCH
+#  ifdef HW_MODEL      /* OpenBSD */
+#    define HW_MACHINE_ARCH HW_MODEL
+#  endif
+#endif
+
 int
 hardware_platform(char *str, size_t len)
 {