provide hooks and fallbacks for rdomain support

This commit is contained in:
Damien Miller 2017-10-25 13:10:59 +11:00
parent 3235473bc8
commit 43c29bb7cf
3 changed files with 35 additions and 0 deletions

13
misc.c
View File

@ -184,6 +184,9 @@ set_reuseaddr(int fd)
char * char *
get_rdomain(int fd) get_rdomain(int fd)
{ {
#if defined(HAVE_SYS_GET_RDOMAIN)
return sys_get_rdomain(fd);
#elif defined(__OpenBSD__)
int rtable; int rtable;
char *ret; char *ret;
socklen_t len = sizeof(rtable); socklen_t len = sizeof(rtable);
@ -195,11 +198,17 @@ get_rdomain(int fd)
} }
xasprintf(&ret, "%d", rtable); xasprintf(&ret, "%d", rtable);
return ret; return ret;
#else /* defined(__OpenBSD__) */
return NULL;
#endif
} }
int int
set_rdomain(int fd, const char *name) set_rdomain(int fd, const char *name)
{ {
#if defined(HAVE_SYS_SET_RDOMAIN)
return sys_set_rdomain(fd, name);
#elif defined(__OpenBSD__)
int rtable; int rtable;
const char *errstr; const char *errstr;
@ -219,6 +228,10 @@ set_rdomain(int fd, const char *name)
return -1; return -1;
} }
return 0; return 0;
#else /* defined(__OpenBSD__) */
error("Setting routing domain is not supported on this platform");
return -1;
#endif
} }
/* Characters considered whitespace in strsep calls. */ /* Characters considered whitespace in strsep calls. */

View File

@ -735,6 +735,9 @@ add_one_listen_addr(ServerOptions *options, const char *addr,
static int static int
valid_rdomain(const char *name) valid_rdomain(const char *name)
{ {
#if defined(HAVE_SYS_VALID_RDOMAIN)
return valid_rdomain(name)
#elif defined(__OpenBSD__)
const char *errstr; const char *errstr;
long long num; long long num;
struct rt_tableinfo info; struct rt_tableinfo info;
@ -758,6 +761,10 @@ valid_rdomain(const char *name)
return 0; return 0;
return 1; return 1;
#else /* defined(__OpenBSD__) */
error("Routing domains are not supported on this platform");
return 0;
#endif
} }
/* /*

15
sshd.c
View File

@ -1372,6 +1372,18 @@ check_ip_options(struct ssh *ssh)
static void static void
set_process_rdomain(struct ssh *ssh, const char *name) set_process_rdomain(struct ssh *ssh, const char *name)
{ {
#if defined(HAVE_SYS_SET_PROCESS_RDOMAIN)
if (name == NULL)
return; /* default */
if (strcmp(name, "%D") == 0) {
/* "expands" to routing domain of connection */
if ((name = ssh_packet_rdomain_in(ssh)) == NULL)
return;
}
/* NB. We don't pass 'ssh' to sys_set_process_rdomain() */
return sys_set_process_rdomain(name);
#elif defined(__OpenBSD__)
int rtable, ortable = getrtable(); int rtable, ortable = getrtable();
const char *errstr; const char *errstr;
@ -1391,6 +1403,9 @@ set_process_rdomain(struct ssh *ssh, const char *name)
fatal("Unable to set routing domain %d: %s", fatal("Unable to set routing domain %d: %s",
rtable, strerror(errno)); rtable, strerror(errno));
debug("%s: set routing domain %d (was %d)", __func__, rtable, ortable); debug("%s: set routing domain %d (was %d)", __func__, rtable, ortable);
#else /* defined(__OpenBSD__) */
fatal("Unable to set routing domain: not supported in this platform");
#endif
} }
/* /*