Implement networkEnableIpForwarding() using BSD style sysctl. --- configure.ac | 7 ++++--- src/network/bridge_driver.c | 13 +++++++++++++ 2 files changed, 17 insertions(+), 3 deletions(-)
diff --git a/configure.ac b/configure.ac index d3219ce..cc2213d 100644 --- a/configure.ac +++ b/configure.ac @@ -207,7 +207,8 @@ dnl Availability of various common functions (non-fatal if missing), dnl and various less common threadsafe functions AC_CHECK_FUNCS_ONCE([cfmakeraw geteuid getgid getgrnam_r getmntent_r \ 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 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). 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/un.h sys/syscall.h netinet/tcp.h ifaddrs.h libtasn1.h \ - sys/ucred.h sys/mount.h]) + sys/un.h sys/syscall.h sys/sysctl.h netinet/tcp.h ifaddrs.h \ + libtasn1.h sys/ucred.h sys/mount.h]) dnl Check whether endian provides handy macros. AC_CHECK_DECLS([htole64], [], [], [[#include <endian.h>]]) diff --git a/src/network/bridge_driver.c b/src/network/bridge_driver.c index dd30244..80a5bc0 100644 --- a/src/network/bridge_driver.c +++ b/src/network/bridge_driver.c @@ -41,6 +41,9 @@ #include <sys/wait.h> #include <sys/ioctl.h> #include <net/if.h> +#if HAVE_SYS_SYSCTL_H +# include <sys/sysctl.h> +#endif #include "virerror.h" #include "datatypes.h" @@ -1537,10 +1540,20 @@ static int networkEnableIpForwarding(bool enableIPv4, bool enableIPv6) { 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) ret = virFileWriteStr("/proc/sys/net/ipv4/ip_forward", "1\n", 0); if (enableIPv6 && ret == 0) ret = virFileWriteStr("/proc/sys/net/ipv6/conf/all/forwarding", "1\n", 0); +#endif return ret; } -- 1.8.2.3 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list