summarylogtreecommitdiffstats
path: root/openvswitch.patch
blob: 4844bd723d25c683db3b23fccc5768c9ccb72cef (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
diff --git a/src/drivers/drivers.mak b/src/drivers/drivers.mak
index 9434078..7d8786c 100644
--- a/src/drivers/drivers.mak
+++ b/src/drivers/drivers.mak
@@ -145,6 +145,10 @@ DRV_WPA_OBJS += ../src/drivers/driver_wext.o
 NEED_RFKILL=y
 endif
 
+ifdef CONFIG_OPENVSWITCH
+DRV_CFLAGS += -DCONFIG_OPENVSWITCH
+endif
+
 ifdef NEED_NETLINK
 DRV_OBJS += ../src/drivers/netlink.o
 endif
diff --git a/src/drivers/drivers.mk b/src/drivers/drivers.mk
index 8da4c53..4cee638 100644
--- a/src/drivers/drivers.mk
+++ b/src/drivers/drivers.mk
@@ -132,6 +132,10 @@ DRV_WPA_OBJS += src/drivers/driver_wext.c
 NEED_RFKILL=y
 endif
 
+ifdef CONFIG_OPENVSWITCH
+DRV_CFLAGS += -DCONFIG_OPENVSWITCH
+endif
+
 ifdef NEED_NETLINK
 DRV_OBJS += src/drivers/netlink.c
 endif
diff --git a/src/drivers/linux_ioctl.c b/src/drivers/linux_ioctl.c
index 837971d..f666e27 100644
--- a/src/drivers/linux_ioctl.c
+++ b/src/drivers/linux_ioctl.c
@@ -14,6 +14,69 @@
 #include "utils/common.h"
 #include "linux_ioctl.h"
 
+#ifdef CONFIG_OPENVSWITCH
+#include <sys/wait.h>
+#include <sys/stat.h>
+
+#define run_prog(p, ...) ({ \
+	struct stat q; \
+	int rc = -1, status; \
+	if(stat(p, &q) == 0) \
+	{ \
+		pid_t pid = fork(); \
+		if (!pid) \
+			exit(execl(p, p, ##__VA_ARGS__, NULL)); \
+		if (pid < 0) { \
+			rc = -1; \
+		} else { \
+			while ((rc = waitpid(pid, &status, 0)) == -1 && errno == EINTR); \
+			rc = (rc == pid && WIFEXITED(status)) ? WEXITSTATUS(status) : -1; \
+		} \
+	} \
+	rc; \
+})
+
+int ovs_br_get(char *brname, const char *ifname)
+{
+	FILE *f;
+	char cmd[64];
+	char *c;
+	struct stat q;
+
+	if(stat("/usr/bin/ovs-vsctl", &q) != 0)
+		return -1;
+
+	brname[0] = '\0';
+	sprintf(cmd, "/usr/bin/ovs-vsctl iface-to-br %s", ifname);
+	f = popen(cmd, "r");
+	if (!f)
+		return -1;
+	c = fgets(brname, IFNAMSIZ, f);
+	pclose(f);
+	if (c && strlen(brname)) {
+		/* Ignore newline */
+		if ((c = strchr(brname, '\n')))
+			*c = '\0';
+		return 0;
+	}
+	return -1;
+}
+
+int ovs_br_add_if(const char *brname, const char *ifname)
+{
+	if (run_prog("/usr/bin/ovs-vsctl", "add-port", brname, ifname))
+		return -1;
+	return 0;
+}
+
+int ovs_br_del_if(const char *brname, const char *ifname)
+{
+	if (run_prog("/usr/bin/ovs-vsctl", "del-port", brname, ifname))
+		return -1;
+	return 0;
+}
+
+#endif
 
 int linux_set_iface_flags(int sock, const char *ifname, int dev_up)
 {
@@ -118,7 +181,6 @@ int linux_set_ifhwaddr(int sock, const char *ifname, const u8 *addr)
 	return 0;
 }
 
-
 #ifndef SIOCBRADDBR
 #define SIOCBRADDBR 0x89a0
 #endif
@@ -162,6 +224,11 @@ int linux_br_add_if(int sock, const char *brname, const char *ifname)
 	struct ifreq ifr;
 	int ifindex;
 
+#ifdef CONFIG_OPENVSWITCH
+	if (!ovs_br_add_if(brname, ifname))
+		return 0;
+#endif
+
 	ifindex = if_nametoindex(ifname);
 	if (ifindex == 0)
 		return -1;
@@ -184,6 +251,11 @@ int linux_br_del_if(int sock, const char *brname, const char *ifname)
 	struct ifreq ifr;
 	int ifindex;
 
+#ifdef CONFIG_OPENVSWITCH
+	if (!ovs_br_del_if(brname, ifname))
+		return 0;
+#endif
+
 	ifindex = if_nametoindex(ifname);
 	if (ifindex == 0)
 		return -1;
@@ -206,6 +278,11 @@ int linux_br_get(char *brname, const char *ifname)
 	char path[128], brlink[128], *pos;
 	ssize_t res;
 
+#ifdef CONFIG_OPENVSWITCH
+	if (!ovs_br_get(brname, ifname))
+		return 0;
+#endif
+
 	os_snprintf(path, sizeof(path), "/sys/class/net/%s/brport/bridge",
 		    ifname);
 	res = readlink(path, brlink, sizeof(brlink));
@@ -219,3 +296,4 @@ int linux_br_get(char *brname, const char *ifname)
 	os_strlcpy(brname, pos, IFNAMSIZ);
 	return 0;
 }
+