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()
---
src/bpf.c | 13 +++++++++----
src/dhcpcd.c | 2 +-
src/dhcpcd.h | 2 +-
src/duid.c | 2 +-
src/eloop.c | 2 +-
src/if.h | 4 +++-
src/ipv6.c | 2 +-
src/ipv6.h | 6 +++---
src/logerr.c | 7 +++++++
src/queue.h | 2 +-
src/route.c | 6 +++---
src/script.c | 4 +++-
12 files changed, 34 insertions(+), 18 deletions(-)
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 149c2a3d..3a911b96 100644
--- a/src/dhcpcd.c
+++ b/src/dhcpcd.c
@@ -2574,7 +2574,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 5f7fed00..fe16d8c0 100644
--- a/src/dhcpcd.h
+++ b/src/dhcpcd.h
@@ -181,7 +181,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/eloop.c b/src/eloop.c
index 52dd206a..5dd813e0 100644
--- a/src/eloop.c
+++ b/src/eloop.c
@@ -36,7 +36,7 @@
* On Linux use epoll(7)
* Everywhere else use ppoll(2)
*/
-#ifdef BSD
+#if defined(BSD) && !defined(__GNU__)
#include <sys/event.h>
#define USE_KQUEUE
#if defined(__NetBSD__)
diff --git a/src/if.h b/src/if.h
index 8d1aeccf..d78996ca 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 0xc /* Add address */
+#define RTM_DELADDR 0xd /* 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 e04493d3..4cf3fb3a 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/queue.h b/src/queue.h
index d83fc62c..8182d75a 100644
--- a/src/queue.h
+++ b/src/queue.h
@@ -5,7 +5,7 @@
#if (defined(__unix__) || defined(unix)) && !defined(USG)
#include <sys/param.h>
#endif
-#ifdef BSD
+#if defined(BSD) && !defined(__GNU__)
#include <sys/queue.h>
/* Dragonfly BSD needs this :( */
#if !defined(TAILQ_FOREACH_SAFE) && defined(TAILQ_FOREACH_MUTABLE)
diff --git a/src/route.c b/src/route.c
index 4f5eee6d..f3fe09c3 100644
--- a/src/route.c
+++ b/src/route.c
@@ -793,7 +793,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
@@ -804,7 +804,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");
@@ -827,7 +827,7 @@ rt_build(struct dhcpcd_ctx *ctx, int af)
}
}
-#ifdef BSD
+#if defined(BSD) && !defined(__GNU__)
if (!(ctx->options & DHCPCD_EXITING) &&
if_missfilter_apply(ctx) == -1 && errno != ENOTSUP)
logerr("if_missfilter_apply");
diff --git a/src/script.c b/src/script.c
index 128a7a91..76d9ab38 100644
--- a/src/script.c
+++ b/src/script.c
@@ -606,10 +606,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;
@@ -630,6 +631,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