From: Joan Lledó <[email protected]>
* Consider the `__GNU__` macro in conditional blocks all over the code.
* Define RTM_NEWADDR and RTM_DELADDR
* They are only used internally by dhcpcd so they can have any value.
* Declare getprogname()
---
compat/rbtree.h | 2 +-
src/bpf.c | 13 +++++++++----
src/dhcpcd.c | 2 +-
src/dhcpcd.h | 2 +-
src/duid.c | 2 +-
src/if.h | 4 +++-
src/ipv6.c | 2 +-
src/ipv6.h | 6 +++---
src/logerr.c | 7 +++++++
src/route.c | 6 +++---
src/script.c | 4 +++-
11 files changed, 33 insertions(+), 17 deletions(-)
diff --git a/compat/rbtree.h b/compat/rbtree.h
index 656da22a..8e7ecbad 100644
--- a/compat/rbtree.h
+++ b/compat/rbtree.h
@@ -46,7 +46,7 @@
#else
#include "queue.h"
#endif
-#if !defined(__linux__) && !defined(__QNX__) && !defined(__sun)
+#if !defined(__linux__) && !defined(__QNX__) && !defined(__sun) &&
!defined(__GNU__)
#include <sys/endian.h>
#else
#include "endian.h"
diff --git a/src/bpf.c b/src/bpf.c
index 08b8fa68..1721471e 100644
--- a/src/bpf.c
+++ b/src/bpf.c
@@ -39,6 +39,8 @@
/* Special BPF snowflake. */
#include <linux/filter.h>
#define bpf_insn sock_filter
+#elif defined(__GNU__)
+#include <pcap/bpf.h>
#else
#include <net/bpf.h>
#endif
@@ -139,9 +141,10 @@ bpf_frame_bcast(const struct interface *ifp, const void
*frame)
}
}
-#ifndef __linux__
+#if !defined(__linux__) && !defined(__GNU__)
/* Linux is a special snowflake for opening, attaching and reading BPF.
- * See if-linux.c for the Linux specific BPF functions. */
+ * See if-linux.c for the Linux specific BPF functions.
+ * For the Hurd, we just use the libpcap backend, see if-pcap.c. */
const char *bpf_name = "Berkley Packet Filter";
@@ -312,8 +315,8 @@ bpf_wattach(int fd, void *filter, unsigned int filter_len)
#endif
#endif
-#ifndef __sun
-/* SunOS is special too - sending via BPF goes nowhere. */
+#if !defined(__sun) && !defined(__GNU__)
+/* SunOS and the Hurd are special too - sending via BPF goes nowhere. */
ssize_t
bpf_send(const struct bpf *bpf, uint16_t protocol,
const void *data, size_t len)
@@ -341,6 +344,7 @@ bpf_send(const struct bpf *bpf, uint16_t protocol,
}
#endif
+#ifndef __GNU__
void
bpf_close(struct bpf *bpf)
{
@@ -349,6 +353,7 @@ bpf_close(struct bpf *bpf)
free(bpf->bpf_buffer);
free(bpf);
}
+#endif
#ifdef ARP
#define BPF_CMP_HWADDR_LEN ((((HWADDR_LEN / 4) + 2) * 2) + 1)
diff --git a/src/dhcpcd.c b/src/dhcpcd.c
index 1037469c..2a7f309a 100644
--- a/src/dhcpcd.c
+++ b/src/dhcpcd.c
@@ -2487,7 +2487,7 @@ start_manager:
os_init();
-#if defined(BSD) && defined(INET6)
+#if defined(BSD) && !defined(__GNU__) && defined(INET6)
/* Disable the kernel RTADV sysctl as early as possible. */
if (ctx.options & DHCPCD_IPV6 && ctx.options & DHCPCD_IPV6RS)
if_disable_rtadv();
diff --git a/src/dhcpcd.h b/src/dhcpcd.h
index 2c5df6d1..0c2c3cce 100644
--- a/src/dhcpcd.h
+++ b/src/dhcpcd.h
@@ -187,7 +187,7 @@ struct dhcpcd_ctx {
char *randomstate; /* original state */
/* For filtering RTM_MISS messages per router */
-#ifdef BSD
+#if defined(BSD) && !defined(__GNU__)
uint8_t *rt_missfilter;
size_t rt_missfilterlen;
size_t rt_missfiltersize;
diff --git a/src/duid.c b/src/duid.c
index 13c339c9..b87d1847 100644
--- a/src/duid.c
+++ b/src/duid.c
@@ -32,7 +32,7 @@
#include <sys/param.h>
#include <sys/socket.h>
#include <sys/types.h>
-#ifdef BSD
+#if defined(BSD) && !defined(__GNU__)
# include <sys/sysctl.h>
#endif
diff --git a/src/if.h b/src/if.h
index 8d1aeccf..e5ac9be1 100644
--- a/src/if.h
+++ b/src/if.h
@@ -32,7 +32,7 @@
#include <net/if.h>
#include <net/route.h> /* for RTM_ADD et all */
#include <netinet/in.h>
-#ifdef BSD
+#if defined(BSD) && !defined(__GNU__)
#include <netinet/in_var.h> /* for IN_IFF_TENTATIVE et all */
#endif
@@ -228,6 +228,8 @@ int if_setmac(struct interface *ifp, void *, uint8_t);
#define RTM_DELETE 0x2 /* Delete Route */
#define RTM_CHANGE 0x3 /* Change Metrics or flags */
#define RTM_GET 0x4 /* Report Metrics */
+#define RTM_NEWADDR 0x5 /* Add address */
+#define RTM_DELADDR 0x6 /* Remove address */
#endif
/* Define SOCK_CLOEXEC and SOCK_NONBLOCK for systems that lack it.
diff --git a/src/ipv6.c b/src/ipv6.c
index 81249a6a..d4a4b778 100644
--- a/src/ipv6.c
+++ b/src/ipv6.c
@@ -45,7 +45,7 @@
#include "compat/bitops.h"
#endif
-#ifdef BSD
+#if defined(BSD) && !defined(__GNU__)
/* Purely for the ND6_IFF_AUTO_LINKLOCAL #define which is solely used
* to generate our CAN_ADD_LLADDR #define. */
# include <netinet6/in6_var.h>
diff --git a/src/ipv6.h b/src/ipv6.h
index fd9f4f23..9ce0a739 100644
--- a/src/ipv6.h
+++ b/src/ipv6.h
@@ -36,11 +36,11 @@
#include "if.h"
#ifndef __linux__
-# if !defined(__QNX__) && !defined(__sun)
+# if !defined(__QNX__) && !defined(__sun) && !defined(__GNU__)
# include <sys/endian.h>
# endif
# include <net/if.h>
-# ifndef __sun
+# if !defined(__sun) && !defined(__GNU__)
# include <netinet6/in6_var.h>
# endif
#endif
@@ -113,7 +113,7 @@
#define IN6_IFF_TEMPORARY IN6_IFF_PRIVACY
#endif
-#ifdef __sun
+#if defined(__sun) || defined(__GNU__)
/* Solaris lacks these defines.
* While it supports DaD, to seems to only expose IFF_DUPLICATE
* so we have no way of knowing if it's tentative or not.
diff --git a/src/logerr.c b/src/logerr.c
index 7e8038bd..33f258de 100644
--- a/src/logerr.c
+++ b/src/logerr.c
@@ -103,6 +103,13 @@ getprogname(void)
}
#endif
+#if defined(__GNU__)
+static const char *
+getprogname(void) {
+ return program_invocation_short_name;
+}
+#endif
+
#ifndef SMALL
/* Write the time, syslog style. month day time - */
static int
diff --git a/src/route.c b/src/route.c
index a31c4f73..0c123267 100644
--- a/src/route.c
+++ b/src/route.c
@@ -781,7 +781,7 @@ rt_build(struct dhcpcd_ctx *ctx, int af)
goto getfail;
#endif
-#ifdef BSD
+#if defined(BSD) && !defined(__GNU__)
/* Rewind the miss filter */
ctx->rt_missfilterlen = 0;
#endif
@@ -792,7 +792,7 @@ rt_build(struct dhcpcd_ctx *ctx, int af)
continue;
} else if (!(ctx->options & DHCPCD_CONFIGURE))
continue;
-#ifdef BSD
+#if defined(BSD) && !defined(__GNU__)
if (rt_is_default(rt) &&
if_missfilter(rt->rt_ifp, &rt->rt_gateway) == -1)
logerr("if_missfilter");
@@ -815,7 +815,7 @@ rt_build(struct dhcpcd_ctx *ctx, int af)
}
}
-#ifdef BSD
+#if defined(BSD) && !defined(__GNU__)
if (if_missfilter_apply(ctx) == -1 && errno != ENOTSUP)
logerr("if_missfilter_apply");
#endif
diff --git a/src/script.c b/src/script.c
index aceef7ba..09c1d01f 100644
--- a/src/script.c
+++ b/src/script.c
@@ -605,10 +605,11 @@ send_interface(struct fd_list *fd, const struct interface
*ifp, int af)
const struct dhcp6_state *d6;
#endif
-#ifndef AF_LINK
+#if !defined(AF_LINK) && defined(AF_PACKET)
#define AF_LINK AF_PACKET
#endif
+#ifdef AF_LINK
if (af == AF_UNSPEC || af == AF_LINK) {
const char *reason;
@@ -629,6 +630,7 @@ send_interface(struct fd_list *fd, const struct interface
*ifp, int af)
} else
retval++;
}
+#endif
#ifdef INET
if (af == AF_UNSPEC || af == AF_INET) {
--
2.50.1