[openssh-commits] [openssh] 01/01: implement get/set_rdomain() for Linux
git+noreply at mindrot.org
git+noreply at mindrot.org
Wed Oct 25 13:48:35 AEDT 2017
This is an automated email from the git hooks/post-receive script.
djm pushed a commit to branch master
in repository openssh.
commit ce1cca39d7935dd394080ce2df62f5ce5b51f485
Author: Damien Miller <djm at mindrot.org>
Date: Wed Oct 25 13:47:59 2017 +1100
implement get/set_rdomain() for Linux
Not enabled, pending implementation of valid_rdomain() and autoconf glue
---
openbsd-compat/port-net.c | 40 ++++++++++++++++++++++++++++++++++++++--
openbsd-compat/port-net.h | 7 +++++--
2 files changed, 43 insertions(+), 4 deletions(-)
diff --git a/openbsd-compat/port-net.c b/openbsd-compat/port-net.c
index d384b145..f6e32ad4 100644
--- a/openbsd-compat/port-net.c
+++ b/openbsd-compat/port-net.c
@@ -41,7 +41,44 @@
* including tun/tap forwarding and routing domains.
*/
-#if defined(SYS_RDOMAIN_XXX)
+#if defined(SYS_RDOMAIN_LINUX) || defined(SSH_TUN_LINUX)
+#include <linux/if.h>
+#endif
+
+#if defined(SYS_RDOMAIN_LINUX)
+char *
+sys_get_rdomain(int fd)
+{
+ char dev[IFNAMSIZ + 1];
+ socklen_t len = sizeof(dev) - 1;
+
+ if (getsockopt(fd, SOL_SOCKET, SO_BINDTODEVICE, dev, &len) == -1) {
+ error("%s: cannot determine VRF for fd=%d : %s",
+ __func__, fd, strerror(errno));
+ return NULL;
+ }
+ dev[len] = '\0';
+ return strdup(dev);
+}
+
+int
+sys_set_rdomain(int fd, const char *name)
+{
+ if (setsockopt(fd, SOL_SOCKET, SO_BINDTODEVICE,
+ name, strlen(name)) == -1) {
+ error("%s: setsockopt(%d, SO_BINDTODEVICE, %s): %s",
+ __func__, fd, name, strerror(errno));
+ return -1;
+ }
+ return 0;
+}
+
+int
+valid_rdomain(const char *name)
+{
+ return 0;
+}
+#elif defined(SYS_RDOMAIN_XXX)
/* XXX examples */
char *
sys_get_rdomain(int fd)
@@ -84,7 +121,6 @@ sys_set_process_rdomain(const char *name)
*/
#if defined(SSH_TUN_LINUX)
-#include <linux/if.h>
#include <linux/if_tun.h>
int
diff --git a/openbsd-compat/port-net.h b/openbsd-compat/port-net.h
index 715e9fb3..8aa4085f 100644
--- a/openbsd-compat/port-net.h
+++ b/openbsd-compat/port-net.h
@@ -31,14 +31,17 @@ int sys_tun_infilter(struct ssh *, struct Channel *, char *, int);
u_char *sys_tun_outfilter(struct ssh *, struct Channel *, u_char **, size_t *);
#endif
-#if defined(SYS_RDOMAIN_XXX)
+#if defined(SYS_RDOMAIN_LINUX)
# define HAVE_SYS_GET_RDOMAIN
# define HAVE_SYS_SET_RDOMAIN
-# define HAVE_SYS_SET_PROCESS_RDOMAIN
# define HAVE_SYS_VALID_RDOMAIN
char *sys_get_rdomain(int fd);
int sys_set_rdomain(int fd, const char *name);
int valid_rdomain(const char *name);
+#endif
+
+#if defined(SYS_RDOMAIN_XXX)
+# define HAVE_SYS_SET_PROCESS_RDOMAIN
void sys_set_process_rdomain(const char *name);
#endif
--
To stop receiving notification emails like this one, please contact
djm at mindrot.org.
More information about the openssh-commits
mailing list