tethering: Fix bridge module loading problem
authorArtem Bityutskiy <artem.bityutskiy@linux.intel.com>
Wed, 5 Sep 2012 14:52:45 +0000 (17:52 +0300)
committerArtem Bityutskiy <artem.bityutskiy@linux.intel.com>
Tue, 18 Sep 2012 06:53:11 +0000 (09:53 +0300)
This is back-port from upstream. Commit ID in upstream is
4fe07dfed4f720136ee142e56a9d43242c8c78dc. Fixes TIVI-166.

Connman tries to check if bridging is supported by the kernel by checking
whether "/proc/sys/net/bridge" is present. If the bridge is a kernel
module which is not already loaded, then tethering cannot be enabled.

Instead of checking for the file we invoke the "get bridge version" socket
ioctl and the kernel will handle module loading issues - if the bridge
module is not loaded, it will first load it, and then check the version.

Change-Id: I5d9e15ca2fcab384c660c8b66ab5f184067545b1

src/tethering.c

index 265408b..5cf3308 100644 (file)
@@ -35,6 +35,7 @@
 #include <string.h>
 #include <fcntl.h>
 #include <linux/if_tun.h>
+#include <linux/if_bridge.h>
 
 #include "connman.h"
 
@@ -46,8 +47,6 @@
 #define DBUS_TYPE_UNIX_FD -1
 #endif
 
-#define BRIDGE_PROC_DIR "/proc/sys/net/bridge"
-
 #define BRIDGE_NAME "tether"
 #define BRIDGE_DNS "8.8.8.8"
 
@@ -79,12 +78,19 @@ struct connman_private_network {
 
 const char *__connman_tethering_get_bridge(void)
 {
-       struct stat st;
+       int sk, err;
+       unsigned long args[3];
 
-       if (stat(BRIDGE_PROC_DIR, &st) < 0) {
-               connman_error("Missing support for 802.1d ethernet bridging");
+       sk = socket(AF_INET, SOCK_STREAM, 0);
+       if (sk < 0)
+               return NULL;
+
+       args[0] = BRCTL_GET_VERSION;
+       args[1] = args[2] = 0;
+       err = ioctl(sk, SIOCGIFBR, &args);
+       close(sk);
+       if (err == -1)
                return NULL;
-       }
 
        return BRIDGE_NAME;
 }