summaryrefslogtreecommitdiff
path: root/sysdep/linux
diff options
context:
space:
mode:
authorAlexander Zubkov <green@qrator.net>2022-01-08 18:31:56 +0100
committerOndrej Zajicek (work) <santiago@crfreenet.org>2022-01-08 19:02:31 +0100
commit87a02489f3880689a4e2ad72b0b981649dad2154 (patch)
treeb5e486015ab7907bf165ae20851290258e72114d /sysdep/linux
parentbcb25084d31fdb90fcf1666f10e73fe0f863afc0 (diff)
IO: Support nonlocal bind in socket interface
Add option to socket interface for nonlocal binding, i.e. binding to an IP address that is not present on interfaces. This behaviour is enabled when SKF_FREEBIND socket flag is set. For Linux systems, it is implemented by IP_FREEBIND socket flag. Minor changes done by commiter.
Diffstat (limited to 'sysdep/linux')
-rw-r--r--sysdep/linux/sysio.h19
1 files changed, 19 insertions, 0 deletions
diff --git a/sysdep/linux/sysio.h b/sysdep/linux/sysio.h
index e21ff487..f13eda7c 100644
--- a/sysdep/linux/sysio.h
+++ b/sysdep/linux/sysio.h
@@ -10,6 +10,10 @@
#define IPV6_MINHOPCOUNT 73
#endif
+#ifndef IPV6_FREEBIND
+#define IPV6_FREEBIND 78
+#endif
+
#ifndef TCP_MD5SIG_EXT
#define TCP_MD5SIG_EXT 32
#endif
@@ -266,3 +270,18 @@ sk_set_priority(sock *s, int prio)
return 0;
}
+static inline int
+sk_set_freebind(sock *s)
+{
+ int y = 1;
+
+ if (sk_is_ipv4(s))
+ if (setsockopt(s->fd, SOL_IP, IP_FREEBIND, &y, sizeof(y)) < 0)
+ ERR("IP_FREEBIND");
+
+ if (sk_is_ipv6(s))
+ if (setsockopt(s->fd, SOL_IPV6, IPV6_FREEBIND, &y, sizeof(y)) < 0)
+ ERR("IPV6_FREEBIND");
+
+ return 0;
+}