implement get/set_rdomain() for Linux

Not enabled, pending implementation of valid_rdomain() and autoconf glue
This commit is contained in:
Damien Miller 2017-10-25 13:47:59 +11:00
parent 6eee79f9b8
commit ce1cca39d7
2 changed files with 43 additions and 4 deletions

View File

@ -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

View File

@ -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