bridge driver: implement networkEnableIpForwarding for BSD

Implement networkEnableIpForwarding() using BSD style sysctl.
This commit is contained in:
Roman Bogorodskiy 2013-08-11 18:30:56 +04:00 committed by Eric Blake
parent 3f0d2ee95b
commit f083ff82ed
2 changed files with 17 additions and 3 deletions

View File

@ -207,7 +207,8 @@ dnl Availability of various common functions (non-fatal if missing),
dnl and various less common threadsafe functions dnl and various less common threadsafe functions
AC_CHECK_FUNCS_ONCE([cfmakeraw geteuid getgid getgrnam_r getmntent_r \ AC_CHECK_FUNCS_ONCE([cfmakeraw geteuid getgid getgrnam_r getmntent_r \
getpwuid_r getuid kill mmap newlocale posix_fallocate posix_memalign \ getpwuid_r getuid kill mmap newlocale posix_fallocate posix_memalign \
prlimit regexec sched_getaffinity setgroups setns setrlimit symlink]) prlimit regexec sched_getaffinity setgroups setns setrlimit symlink \
sysctlbyname])
dnl Availability of pthread functions (if missing, win32 threading is dnl Availability of pthread functions (if missing, win32 threading is
dnl assumed). Because of $LIB_PTHREAD, we cannot use AC_CHECK_FUNCS_ONCE. dnl assumed). Because of $LIB_PTHREAD, we cannot use AC_CHECK_FUNCS_ONCE.
@ -220,8 +221,8 @@ LIBS=$old_libs
dnl Availability of various common headers (non-fatal if missing). dnl Availability of various common headers (non-fatal if missing).
AC_CHECK_HEADERS([pwd.h paths.h regex.h sys/un.h \ AC_CHECK_HEADERS([pwd.h paths.h regex.h sys/un.h \
sys/poll.h syslog.h mntent.h net/ethernet.h linux/magic.h \ sys/poll.h syslog.h mntent.h net/ethernet.h linux/magic.h \
sys/un.h sys/syscall.h netinet/tcp.h ifaddrs.h libtasn1.h \ sys/un.h sys/syscall.h sys/sysctl.h netinet/tcp.h ifaddrs.h \
sys/ucred.h sys/mount.h]) libtasn1.h sys/ucred.h sys/mount.h])
dnl Check whether endian provides handy macros. dnl Check whether endian provides handy macros.
AC_CHECK_DECLS([htole64], [], [], [[#include <endian.h>]]) AC_CHECK_DECLS([htole64], [], [], [[#include <endian.h>]])

View File

@ -41,6 +41,9 @@
#include <sys/wait.h> #include <sys/wait.h>
#include <sys/ioctl.h> #include <sys/ioctl.h>
#include <net/if.h> #include <net/if.h>
#if HAVE_SYS_SYSCTL_H
# include <sys/sysctl.h>
#endif
#include "virerror.h" #include "virerror.h"
#include "datatypes.h" #include "datatypes.h"
@ -1545,10 +1548,20 @@ static int
networkEnableIpForwarding(bool enableIPv4, bool enableIPv6) networkEnableIpForwarding(bool enableIPv4, bool enableIPv6)
{ {
int ret = 0; int ret = 0;
#ifdef HAVE_SYSCTLBYNAME
int enabled = 1;
if (enableIPv4)
ret = sysctlbyname("net.inet.ip.forwarding", NULL, 0,
&enabled, sizeof(enabled));
if (enableIPv6 && ret == 0)
ret = sysctlbyname("net.inet6.ip6.forwarding", NULL, 0,
&enabled, sizeof(enabled));
#else
if (enableIPv4) if (enableIPv4)
ret = virFileWriteStr("/proc/sys/net/ipv4/ip_forward", "1\n", 0); ret = virFileWriteStr("/proc/sys/net/ipv4/ip_forward", "1\n", 0);
if (enableIPv6 && ret == 0) if (enableIPv6 && ret == 0)
ret = virFileWriteStr("/proc/sys/net/ipv6/conf/all/forwarding", "1\n", 0); ret = virFileWriteStr("/proc/sys/net/ipv6/conf/all/forwarding", "1\n", 0);
#endif
return ret; return ret;
} }