summaryrefslogtreecommitdiff
path: root/sysdep/bsd/sysio.h
diff options
context:
space:
mode:
authorMaria Matejka <mq@ucw.cz>2023-01-22 13:19:22 +0100
committerMaria Matejka <mq@ucw.cz>2023-01-22 13:19:22 +0100
commit521fec2fdc391ee468fd3f58f994609483e6a6eb (patch)
treecf78b05da718c8003332e25b0217f3769f964aaf /sysdep/bsd/sysio.h
parent21c4c8eafb7125375b2e562cc0e7e9d52bbb1aaf (diff)
parent2b7643e1f8ecb0bd4cf9af4183b4fd53b655d19c (diff)
Merge commit '2b7643e1f8ecb0bd4cf9af4183b4fd53b655d19c' into thread-next
Diffstat (limited to 'sysdep/bsd/sysio.h')
-rw-r--r--sysdep/bsd/sysio.h34
1 files changed, 33 insertions, 1 deletions
diff --git a/sysdep/bsd/sysio.h b/sysdep/bsd/sysio.h
index f1887fb4..b6b42b1e 100644
--- a/sysdep/bsd/sysio.h
+++ b/sysdep/bsd/sysio.h
@@ -15,8 +15,23 @@
#ifdef __FreeBSD__
/* Should be defined in sysdep/cf/bsd.h, but it is flavor-specific */
#define CONFIG_DONTROUTE_UNICAST
+
+#if __FreeBSD_version >= 1201000
+#define CONFIG_USE_IP_MREQN
+#endif
+
#endif
+
+#ifdef __OpenBSD__
+
+#if OpenBSD >= 202105
+#define CONFIG_USE_IP_MREQN
+#endif
+
+#endif
+
+
#ifdef __NetBSD__
#ifndef IP_RECVTTL
@@ -29,6 +44,7 @@
#endif
+
#ifdef __DragonFly__
#define TCP_MD5SIG TCP_SIGNATURE_ENABLE
#endif
@@ -45,13 +61,21 @@
#define INIT_MREQ4(maddr,ifa) \
{ .imr_multiaddr = ipa_to_in4(maddr), .imr_interface = ip4_to_in4(ifa->sysdep) }
+#define INIT_MREQN4(maddr,ifa) \
+ { .imr_multiaddr = ipa_to_in4(maddr), .imr_ifindex = ifa->index }
+
static inline int
sk_setup_multicast4(sock *s)
{
- struct in_addr ifa = ip4_to_in4(s->iface->sysdep);
u8 ttl = s->ttl;
u8 n = 0;
+#ifdef CONFIG_USE_IP_MREQN
+ struct ip_mreqn ifa = { .imr_ifindex = s->iface->index };
+#else
+ struct in_addr ifa = ip4_to_in4(s->iface->sysdep);
+#endif
+
/* This defines where should we send _outgoing_ multicasts */
if (setsockopt(s->fd, IPPROTO_IP, IP_MULTICAST_IF, &ifa, sizeof(ifa)) < 0)
ERR("IP_MULTICAST_IF");
@@ -68,7 +92,11 @@ sk_setup_multicast4(sock *s)
static inline int
sk_join_group4(sock *s, ip_addr maddr)
{
+#ifdef CONFIG_USE_IP_MREQN
+ struct ip_mreqn mr = INIT_MREQN4(maddr, s->iface);
+#else
struct ip_mreq mr = INIT_MREQ4(maddr, s->iface);
+#endif
if (setsockopt(s->fd, IPPROTO_IP, IP_ADD_MEMBERSHIP, &mr, sizeof(mr)) < 0)
ERR("IP_ADD_MEMBERSHIP");
@@ -79,7 +107,11 @@ sk_join_group4(sock *s, ip_addr maddr)
static inline int
sk_leave_group4(sock *s, ip_addr maddr)
{
+#ifdef CONFIG_USE_IP_MREQN
+ struct ip_mreqn mr = INIT_MREQN4(maddr, s->iface);
+#else
struct ip_mreq mr = INIT_MREQ4(maddr, s->iface);
+#endif
if (setsockopt(s->fd, IPPROTO_IP, IP_DROP_MEMBERSHIP, &mr, sizeof(mr)) < 0)
ERR("IP_ADD_MEMBERSHIP");