View | Details | Raw Unified | Return to bug 250302 | Differences between
and this patch

Collapse All | Expand All

(-)files/patch-src_wifimgr-gtk.c (+26 lines)
Line 0 Link Here
1
--- src/wifimgr-gtk.c.orig	2020-10-12 00:55:51 UTC
2
+++ src/wifimgr-gtk.c
3
@@ -1175,12 +1175,12 @@ gui_fill_network_table(GtkWidget * x, gpointer * gp) {
4
 	col = 0;
5
 
6
 	if (!nets) {
7
-		nets = build_network_list(wifi_if);
8
+		nets = build_network_list(intf->wifi);
9
 		gui_order_networks();
10
 	}
11
 
12
 	if (wifi_if_status == WIFI_IF_UP)
13
-		associated_net = ifconfig_associated_network(wifi_if);
14
+		associated_net = ifconfig_associated_network(intf->wifi);
15
 	else
16
 		associated_net = NULL;
17
 
18
@@ -1359,7 +1359,7 @@ gui_interface_up_down(GtkWidget * x1, gpointer * x2) {
19
 
20
 	gui_changes = 0;
21
 
22
-	toggle_intf_up_down(wifi_if);
23
+	toggle_intf_up_down(intf->wifi);
24
 
25
 	/* change the main icon */
26
 	icon = (wifi_if_status == WIFI_IF_UP) ? ICON_PATH "/wifimgr.png" : ICON_PATH "/wifimgr-grey.png";
(-)files/patch-src_wifimgr.c (+259 lines)
Line 0 Link Here
1
--- src/wifimgr.c.orig	2018-08-31 19:34:01 UTC
2
+++ src/wifimgr.c
3
@@ -51,7 +51,7 @@
4
 #define gettext(x)	(x)
5
 #endif
6
 
7
-char *			wifi_if;
8
+struct intfs *		intf;
9
 int			wifi_if_status;
10
 struct wifi_net *	nets;
11
 char			conf_ctrl_interface[256];
12
@@ -109,43 +109,79 @@ struct conflist	conf_proto[] = {
13
 };
14
 
15
 /*
16
-** parse /etc/rc.conf to find WiFi interface
17
+** FreeBSD: parse /etc/rc.conf*   to find WiFi and lagg  interfaces
18
+** OpenBSD: parse /etc/hostname.* to find WiFi and trunk interfaces
19
+** NetBSD:  parse /etc/ifconfig.* to find WiFi and agr   interfaces
20
 */
21
-char *
22
-find_wifi_if(char * file) {
23
+struct intfs *
24
+find_intf(char * file) {
25
 	FILE *			fp;
26
 	char			line[1024];
27
 	char *			p;
28
+	char			s[256+10];
29
 	static char		wifi_if[256];
30
+	static char		aggr_if[256];
31
+	static struct intfs	stat_intf;
32
+	struct intfs *		intf=&stat_intf;
33
 
34
 	if ((fp = fopen(file, "r")) == NULL)
35
-		return NULL;
36
+		return intf;
37
 
38
 	while(fgets(line, sizeof(line), fp) != NULL) {
39
 		for (p = line; *p == ' ' || *p == '\t'; p++);
40
 		if (*p == '#')
41
 			continue;
42
-		if (strncmp(p, "ifconfig_", 9) == 0
43
-		    && strstr(p, "=\"")
44
-		    && strstr(p, "WPA")
45
-		) {
46
-			sscanf(p, "ifconfig_%[^=]=", wifi_if);
47
-			fclose(fp);
48
-			return wifi_if;
49
+		if (intf->wifi == NULL) {
50
+			if (strncmp(p, "ifconfig_", 9) == 0
51
+			    && strstr(p, "=\"")
52
+			    && strstr(p, "WPA")) {
53
+				sscanf(p, "ifconfig_%[^=]=", wifi_if);
54
+				intf->wifi = wifi_if;
55
+				rewind(fp); /* within the same rc file, do not assume that     */
56
+				continue;   /* the WiFi interface appears before the aggregate */
57
+			}
58
+			if (strncmp(p, "wpa_supplicant_flags", 20) == 0
59
+			    && strstr(p, "-i")) {
60
+				p = strstr(p, "-i");
61
+				sscanf(p, "-i %[^ \"]", wifi_if);
62
+				intf->wifi = wifi_if;
63
+				rewind(fp); /* Same comment */
64
+				continue;
65
+			}
66
 		}
67
-		if (strncmp(p, "wpa_supplicant_flags", 20) == 0
68
-		    && strstr(p, "-i")
69
-		) {
70
-			p = strstr(p, "-i");
71
-			sscanf(p, "-i %[^ \"]", wifi_if);
72
-			fclose(fp);
73
-			return wifi_if;
74
+		/* now that we have an interface in intf->wifi,    */
75
+		/* search for a aggregate that uses this interface */
76
+		else if (intf->aggr == NULL) {
77
+			sprintf (s, "laggport %s", intf->wifi);
78
+			if (strncmp(p, "ifconfig_", 9) == 0
79
+			    && strstr(p, "=\"")
80
+			    && strstr(p, s)) {
81
+				sscanf(p, "ifconfig_%[^=]=", aggr_if);
82
+				intf->aggr = aggr_if;
83
+				return intf;
84
+			}
85
+			sprintf (s, "trunkport %s", intf->wifi);
86
+			if (strstr(p, s)) {
87
+				if (strstr(file, "hostname.") == NULL)
88
+					return intf;
89
+				sscanf(strstr(file, "hostname."), "hostname.%s", aggr_if);
90
+				intf->aggr = aggr_if;
91
+				return intf;
92
+			}
93
+			sprintf (s, "agrport %s", intf->wifi);
94
+			if (strstr(p, s)) {
95
+				if (strstr(file, "hostname.") == NULL)
96
+					return intf;
97
+				sscanf(strstr(file, "hostname."), "hostname.%s", aggr_if);
98
+				intf->aggr = aggr_if;
99
+				return intf;
100
+			}
101
 		}
102
 	}
103
 
104
 	fclose(fp);
105
 
106
-	return NULL;
107
+	return intf;
108
 }
109
 
110
 /*
111
@@ -220,7 +256,6 @@ read_networks_file(char * file) {
112
 				exit(1);
113
 			}
114
 			memset(new, 0, sizeof(*new));
115
-
116
 			new->wn_enabled = 1;
117
 			new->wn_next = NULL;
118
 		}
119
@@ -775,7 +810,7 @@ restart_intf() {
120
 	/* there must be a config file for wpa_supplicant(8) to start */
121
 	check_networks_file(NETWORKS_FILE);
122
 
123
-	fprintf(sucmd, "restart_netif %s\n", wifi_if);
124
+	fprintf(sucmd, "restart_netif %s %s\n", intf->wifi, intf->aggr);
125
 	fgets(resp, sizeof(resp), sucmd);
126
 	chop(resp);
127
 	if (strcmp(resp, "OK") != 0) {
128
@@ -783,13 +818,13 @@ restart_intf() {
129
 		char *		err;
130
 
131
 		err = index(resp, ' ') + 1;
132
-		sprintf(buf, gettext("Cannot reset interface <b>%s</b> - %s."), wifi_if, err);
133
+		sprintf(buf, gettext("Cannot reset interface <b>%s</b> - %s."), intf->wifi, err);
134
 		gui_message(buf, MSG_ERROR);
135
 		exit(1);
136
 	}
137
 
138
 	/* loop up to 10 seconds for interface to re-associate */
139
-	while (!ifconfig_associated_network(wifi_if) && count++ < 20)
140
+	while (!ifconfig_associated_network(intf->wifi) && count++ < 20)
141
 		usleep(500000);
142
 
143
 	return 1;
144
@@ -799,7 +834,7 @@ restart_intf() {
145
 ** scan for currently available networks
146
 */
147
 void
148
-ifconfig_network_scan(char * intf) {
149
+ifconfig_network_scan(char * wifi_if) {
150
 	char			line[2048];	/* yes, some lines are longer than 1024 bytes! */
151
 	char			cmd[256];
152
 	FILE *			fp;
153
@@ -817,7 +852,7 @@ ifconfig_network_scan(char * intf) {
154
 	if (wifi_if_status != WIFI_IF_UP)
155
 		return;
156
 
157
-	sprintf(cmd, "%s -v %s list scan | %s 's/^ /-/'", PATH_IFCONFIG, intf, PATH_SED);
158
+	sprintf(cmd, "%s -v %s list scan | %s 's/^ /-/'", PATH_IFCONFIG, wifi_if, PATH_SED);
159
 
160
 	if ((fp = popen(cmd, "r")) == NULL) {
161
 		char		buf[256];
162
@@ -912,14 +947,14 @@ ifconfig_network_scan(char * intf) {
163
 ** run ifconfig to find interface UP/DOWN status
164
 */
165
 int
166
-ifconfig_intf_status(char * intf) {
167
+ifconfig_intf_status(char * wifi_if) {
168
 	char			cmd[256];
169
 	FILE *			fp;
170
 	char			line[1024];
171
 	int			status;
172
 
173
 	/* run ifconfig command */
174
-	sprintf(cmd, "%s %s", PATH_IFCONFIG, intf);
175
+	sprintf(cmd, "%s %s", PATH_IFCONFIG, wifi_if);
176
 	if ((fp = popen(cmd, "r")) == NULL) {
177
 		char		buf[256];
178
 		sprintf(buf, gettext("Cannot exec %s."), PATH_IFCONFIG);
179
@@ -946,7 +981,7 @@ ifconfig_intf_status(char * intf) {
180
 **	return SSID if network is specified with SSID/any_bssid
181
 */
182
 char *
183
-ifconfig_associated_network(char * intf) {
184
+ifconfig_associated_network(char * wifi_if) {
185
 	char			cmd[256];
186
 	FILE *			fp;
187
 	char			line[1024];
188
@@ -958,7 +993,7 @@ ifconfig_associated_network(char * intf) {
189
 	struct wifi_net *	net;
190
 
191
 	/* run ifconfig command */
192
-	sprintf(cmd, "%s %s", PATH_IFCONFIG, intf);
193
+	sprintf(cmd, "%s %s", PATH_IFCONFIG, wifi_if);
194
 	if ((fp = popen(cmd, "r")) == NULL) {
195
 		char		buf[256];
196
 		sprintf(buf, gettext("Cannot exec %s."), PATH_IFCONFIG);
197
@@ -1008,7 +1043,7 @@ ifconfig_associated_network(char * intf) {
198
 ** toggle interface up or down
199
 */
200
 int
201
-toggle_intf_up_down(char * intf) {
202
+toggle_intf_up_down(char * wifi_if) {
203
 	char			resp[256];
204
 	int			count = 0;
205
 
206
@@ -1017,7 +1052,7 @@ toggle_intf_up_down(char * intf) {
207
 		check_networks_file(NETWORKS_FILE);
208
 
209
 	/* execute su command enable/disable interface */
210
-	fprintf(sucmd, "%s_netif %s\n", (wifi_if_status == WIFI_IF_DOWN) ? "start" : "stop", wifi_if);
211
+	fprintf(sucmd, "%s_netif %s\n", (wifi_if_status == WIFI_IF_DOWN) ? "start" : "stop", intf->wifi);
212
 	fgets(resp, sizeof(resp), sucmd);
213
 	chop(resp);
214
 	if (strcmp(resp, "OK") != 0) {
215
@@ -1033,10 +1068,10 @@ toggle_intf_up_down(char * intf) {
216
 
217
 	if (wifi_if_status == WIFI_IF_DOWN)
218
 		/* loop up to 10 seconds for interface to re-associate */
219
-		while (!ifconfig_associated_network(wifi_if) && count++ < 20)
220
+		while (!ifconfig_associated_network(intf->wifi) && count++ < 20)
221
 			usleep(500000);
222
 
223
-	wifi_if_status = ifconfig_intf_status(intf);
224
+	wifi_if_status = ifconfig_intf_status(wifi_if);
225
 
226
 	return wifi_if_status;
227
 }
228
@@ -1259,9 +1294,19 @@ main(int argc, char ** argv) {
229
 	/* open channel to setuid backend */
230
 	wifimgrsu_init();
231
 
232
-	/* find WiFi interface */
233
-	if ((wifi_if = find_wifi_if(RC_CONF_LOCAL_FILE)) == NULL &&
234
-	    (wifi_if = find_wifi_if(RC_CONF_FILE)) == NULL) {
235
+	/* find the first WiFi interface, then the first aggregate that uses that interface
236
+	**
237
+	** Do not assume that the WiFi interface and the aggregate
238
+	** that uses it are configured in the same configuration file,
239
+	** and give precedence to /etc/rc.conf.local over /etc/rc.conf
240
+	** for both WiFi configuration and link aggregation.
241
+	**
242
+	** The logic would be much simpler on OpenBSD/NetBSD since
243
+	** one usually use one configuration file per interface.
244
+	*/
245
+	if ((intf = find_intf(RC_CONF_LOCAL_FILE))->aggr == NULL
246
+	 && (intf = find_intf(RC_CONF_FILE))->aggr == NULL
247
+	 && (intf = find_intf(RC_CONF_LOCAL_FILE))->wifi == NULL) {
248
 		char		buf[256];
249
 		sprintf(buf, gettext("No WiFi interface is configured in <b>%s</b>."), RC_CONF_FILE);
250
 		gui_message(buf, MSG_ERROR);
251
@@ -1269,7 +1314,7 @@ main(int argc, char ** argv) {
252
 	}
253
 
254
 	/* find interface status */
255
-	wifi_if_status = ifconfig_intf_status(wifi_if);
256
+	wifi_if_status = ifconfig_intf_status(intf->wifi);
257
 
258
 	/* load rc config */
259
 	cache_load_config();
(-)files/patch-src_wifimgr.h (+23 lines)
Line 0 Link Here
1
--- src/wifimgr.h.orig	2020-08-23 08:35:32 UTC
2
+++ src/wifimgr.h
3
@@ -131,6 +131,11 @@ struct conflist {
4
 	int			cl_value;
5
 };
6
 
7
+struct intfs {
8
+	char *			wifi;
9
+	char *			aggr;
10
+};
11
+
12
 extern struct conflist		conf_auth_alg[];
13
 extern struct conflist		conf_eap[];
14
 extern struct conflist		conf_group[];
15
@@ -138,7 +143,7 @@ extern struct conflist		conf_key_mgmt[];
16
 extern struct conflist		conf_pairwise[];
17
 extern struct conflist		conf_proto[];
18
 extern struct wifi_net *	nets;
19
-extern char *			wifi_if;
20
+extern struct intfs *		intf;
21
 extern int			wifi_if_status;
22
 #define WIFI_IF_DOWN		0
23
 #define WIFI_IF_UP		1

Return to bug 250302