5 * Copyright (C) 2007-2012 Intel Corporation. All rights reserved.
6 * Copyright (C) 2012 BMW Car IT GmbH. All rights reserved.
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License version 2 as
10 * published by the Free Software Foundation.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
28 #include <sys/types.h>
32 #include <sys/ioctl.h>
34 #include <linux/sockios.h>
37 #include <linux/if_tun.h>
41 static int set_forward_delay(const char *name, unsigned int delay)
44 char *forward_delay_path;
47 g_strdup_printf("/sys/class/net/%s/bridge/forward_delay", name);
49 if (forward_delay_path == NULL)
52 f = fopen(forward_delay_path, "r+");
54 g_free(forward_delay_path);
59 fprintf(f, "%d", delay);
66 int __connman_bridge_create(const char *name)
72 sk = socket(AF_INET, SOCK_STREAM | SOCK_CLOEXEC, 0);
76 if (ioctl(sk, SIOCBRADDBR, name) == -1) {
82 err = set_forward_delay(name, 0);
85 ioctl(sk, SIOCBRDELBR, name);
92 int __connman_bridge_remove(const char *name)
98 sk = socket(AF_INET, SOCK_STREAM | SOCK_CLOEXEC, 0);
102 err = ioctl(sk, SIOCBRDELBR, name);
112 int __connman_bridge_enable(const char *name, const char *gateway,
113 const char *broadcast)
117 index = connman_inet_ifindex(name);
121 err = __connman_inet_modify_address(RTM_NEWADDR,
122 NLM_F_REPLACE | NLM_F_ACK, index, AF_INET,
123 gateway, NULL, 24, broadcast);
127 return connman_inet_ifup(index);
130 int __connman_bridge_disable(const char *name)
134 index = connman_inet_ifindex(name);
138 return connman_inet_ifdown(index);