diff --git a/openbsd-compat/port-net.c b/openbsd-compat/port-net.c index d384b1454..f6e32ad49 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 +#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 #include int diff --git a/openbsd-compat/port-net.h b/openbsd-compat/port-net.h index 715e9fb34..8aa4085f4 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