summarylogtreecommitdiffstats
path: root/openvswitch.patch
blob: 09120cfa3d9e3ea9a93a9edd8980d890c5c1134c (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
diff -wbBur hostapd-2.8.q/src/drivers/drivers.mak hostapd-2.8/src/drivers/drivers.mak
--- hostapd-2.8.q/src/drivers/drivers.mak	2019-04-21 10:10:22.000000000 +0300
+++ hostapd-2.8/src/drivers/drivers.mak	2019-04-25 15:05:36.981411804 +0300
@@ -136,6 +136,10 @@
 NEED_RFKILL=y
 endif
 
+ifdef CONFIG_OPENVSWITCH
+DRV_CFLAGS += -DCONFIG_OPENVSWITCH
+endif
+
 ifdef NEED_NETLINK
 DRV_OBJS += ../src/drivers/netlink.o
 endif
diff -wbBur hostapd-2.8.q/src/drivers/drivers.mk hostapd-2.8/src/drivers/drivers.mk
--- hostapd-2.8.q/src/drivers/drivers.mk	2019-04-21 10:10:22.000000000 +0300
+++ hostapd-2.8/src/drivers/drivers.mk	2019-04-25 15:05:36.981411804 +0300
@@ -128,6 +128,10 @@
 NEED_RFKILL=y
 endif
 
+ifdef CONFIG_OPENVSWITCH
+DRV_CFLAGS += -DCONFIG_OPENVSWITCH
+endif
+
 ifdef NEED_NETLINK
 DRV_OBJS += src/drivers/netlink.c
 endif
diff -wbBur hostapd-2.8.q/src/drivers/linux_ioctl.c hostapd-2.8/src/drivers/linux_ioctl.c
--- hostapd-2.8.q/src/drivers/linux_ioctl.c	2019-04-21 10:10:22.000000000 +0300
+++ hostapd-2.8/src/drivers/linux_ioctl.c	2019-04-25 15:05:36.981411804 +0300
@@ -15,6 +15,69 @@
 #include "common/linux_bridge.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)
 {
@@ -152,6 +215,11 @@
 	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;
@@ -177,6 +245,11 @@
 	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;
@@ -199,6 +272,11 @@
 	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));