]> xenbits.xensource.com Git - libvirt.git/commitdiff
bridge driver: implement networkEnableIpForwarding for BSD
authorRoman Bogorodskiy <bogorodskiy@gmail.com>
Sun, 11 Aug 2013 14:30:56 +0000 (18:30 +0400)
committerEric Blake <eblake@redhat.com>
Wed, 21 Aug 2013 22:28:19 +0000 (16:28 -0600)
Implement networkEnableIpForwarding() using BSD style sysctl.

configure.ac
src/network/bridge_driver.c

index afa9cd39ea23647b8d5ce89a6ebe44dd1a2b15cd..c52f212438596909db66d8d9d54afcf482d75942 100644 (file)
@@ -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>]])
 
index 00f2befcaff96efd1e737f4295efba674f74c570..62ae0b7eb02218ad95c10545e139152ce92d7c2a 100644 (file)
@@ -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"
@@ -1545,10 +1548,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;
 }