From: Roy Marples Date: Wed, 5 Mar 2014 18:11:22 +0000 (+0000) Subject: Compile and work on OpenBSD. X-Git-Tag: v6.3.2~31 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=c8b42ae14db4a7d6a3fc52dcf4ceefef5308d357;p=thirdparty%2Fdhcpcd.git Compile and work on OpenBSD. 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. --- diff --git a/README b/README index 7f416382..6ee3f042 100644 --- 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 7e48efb1..8ec6dfe7 100644 --- 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: diff --git a/configure b/configure index 9e67d33e..2c7640be 100755 --- 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 <_queue.c +#include +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 <>$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 <_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 diff --git a/dhcpcd.c b/dhcpcd.c index 7bd9124e..5ac26c74 100644 --- 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; diff --git a/if-bsd.c b/if-bsd.c index 076be3b4..8d33cb50 100644 --- 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 # include #endif diff --git a/ipv6.c b/ipv6.c index 51c8d66b..018a62a7 100644 --- 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 +#ifdef __FreeBSD__ /* Needed so that including netinet6/in6_var.h works */ # include #endif # include diff --git a/ipv6.h b/ipv6.h index b94cdf8a..12367ad9 100644 --- a/ipv6.h +++ b/ipv6.h @@ -29,6 +29,7 @@ #define IPV6_H #include +#include #include @@ -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 *); diff --git a/platform-bsd.c b/platform-bsd.c index 925b74ea..f6088f8c 100644 --- a/platform-bsd.c +++ b/platform-bsd.c @@ -53,6 +53,12 @@ # 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) {