summaryrefslogtreecommitdiff
path: root/src/bridge.c
diff options
context:
space:
mode:
authorDaniel Wagner <daniel.wagner@bmw-carit.de>2012-02-01 18:54:48 +0100
committerSamuel Ortiz <sameo@linux.intel.com>2012-02-13 11:33:17 +0100
commite785a37c5a20e198c4841acd937b2533fed96f62 (patch)
tree5cb728d990a0ff01cbe6ba3059ec7229461e3bb7 /src/bridge.c
parent1c3c3eaff479583550749e720a64ebcaaff2e38c (diff)
downloadconnman-e785a37c5a20e198c4841acd937b2533fed96f62.tar.gz
connman-e785a37c5a20e198c4841acd937b2533fed96f62.tar.bz2
connman-e785a37c5a20e198c4841acd937b2533fed96f62.zip
bridge: Move bridge code into a seperate file
The bridge handling code will reused by session.c.
Diffstat (limited to 'src/bridge.c')
-rw-r--r--src/bridge.c139
1 files changed, 139 insertions, 0 deletions
diff --git a/src/bridge.c b/src/bridge.c
new file mode 100644
index 00000000..da1622fa
--- /dev/null
+++ b/src/bridge.c
@@ -0,0 +1,139 @@
+/*
+ *
+ * Connection Manager
+ *
+ * Copyright (C) 2007-2012 Intel Corporation. All rights reserved.
+ * Copyright (C) 2012 BMW Car IT GmbH. All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ *
+ */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <errno.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <unistd.h>
+#include <stdio.h>
+#include <sys/ioctl.h>
+#include <net/if.h>
+#include <linux/sockios.h>
+#include <string.h>
+#include <fcntl.h>
+#include <linux/if_tun.h>
+
+#include "connman.h"
+
+static int set_forward_delay(const char *name, unsigned int delay)
+{
+ FILE *f;
+ char *forward_delay_path;
+
+ forward_delay_path =
+ g_strdup_printf("/sys/class/net/%s/bridge/forward_delay", name);
+
+ if (forward_delay_path == NULL)
+ return -ENOMEM;
+
+ f = fopen(forward_delay_path, "r+");
+
+ g_free(forward_delay_path);
+
+ if (f == NULL)
+ return -errno;
+
+ fprintf(f, "%d", delay);
+
+ fclose(f);
+
+ return 0;
+}
+
+int __connman_bridge_create(const char *name)
+{
+ int sk, err;
+
+ DBG("name %s", name);
+
+ sk = socket(AF_INET, SOCK_STREAM | SOCK_CLOEXEC, 0);
+ if (sk < 0)
+ return -EOPNOTSUPP;
+
+ if (ioctl(sk, SIOCBRADDBR, name) == -1) {
+ err = -errno;
+ if (err != -EEXIST)
+ return -EOPNOTSUPP;
+ }
+
+ err = set_forward_delay(name, 0);
+
+ if (err < 0)
+ ioctl(sk, SIOCBRDELBR, name);
+
+ close(sk);
+
+ return err;
+}
+
+int __connman_bridge_remove(const char *name)
+{
+ int sk, err;
+
+ DBG("name %s", name);
+
+ sk = socket(AF_INET, SOCK_STREAM | SOCK_CLOEXEC, 0);
+ if (sk < 0)
+ return -EOPNOTSUPP;
+
+ err = ioctl(sk, SIOCBRDELBR, name);
+
+ close(sk);
+
+ if (err < 0)
+ return -EOPNOTSUPP;
+
+ return 0;
+}
+
+int __connman_bridge_enable(const char *name, const char *broadcast,
+ const char *gateway)
+{
+ int err, index;
+
+ index = connman_inet_ifindex(name);
+ if (index < 0)
+ return index;
+
+ err = __connman_inet_modify_address(RTM_NEWADDR,
+ NLM_F_REPLACE | NLM_F_ACK, index, AF_INET,
+ gateway, NULL, 24, broadcast);
+ if (err < 0)
+ return err;
+
+ return connman_inet_ifup(index);
+}
+
+int __connman_bridge_disable(const char *name)
+{
+ int index;
+
+ index = connman_inet_ifindex(name);
+ if (index < 0)
+ return index;
+
+ return connman_inet_ifdown(index);
+}