Gentoo Archives: gentoo-commits

From: "Mu Qiao (qiaomuf)" <qiaomuf@g.o>
To: gentoo-commits@l.g.o
Subject: [gentoo-commits] gentoo-x86 commit in net-misc/networkmanager/files: networkmanager-0.8.2-shared-connection.patch
Date: Mon, 24 Jan 2011 07:31:59
Message-Id: 20110124073149.294E920057@flycatcher.gentoo.org
1 qiaomuf 11/01/24 07:31:49
2
3 Added: networkmanager-0.8.2-shared-connection.patch
4 Log:
5 Revision bump wrt bug #350476
6
7 (Portage version: 2.1.9.25/cvs/Linux x86_64)
8
9 Revision Changes Path
10 1.1 net-misc/networkmanager/files/networkmanager-0.8.2-shared-connection.patch
11
12 file : http://sources.gentoo.org/viewvc.cgi/gentoo-x86/net-misc/networkmanager/files/networkmanager-0.8.2-shared-connection.patch?rev=1.1&view=markup
13 plain: http://sources.gentoo.org/viewvc.cgi/gentoo-x86/net-misc/networkmanager/files/networkmanager-0.8.2-shared-connection.patch?rev=1.1&content-type=text/plain
14
15 Index: networkmanager-0.8.2-shared-connection.patch
16 ===================================================================
17 From 5a67c7a5ad341fa84091287eb6452458c7ee24b0 Mon Sep 17 00:00:00 2001
18 From: Mu Qiao <qiaomuf@g.o>
19 Date: Wed, 5 Jan 2011 13:30:08 +0800
20 Subject: [PATCH] Support shared and link-local method for ipv4
21 Signed-off-by: Mu Qiao <qiaomuf@g.o>
22 fix flush_to_file, return TRUE when nothing changed
23 ssid do not lose quotes anymore
24 do not delete old connection when ssid is not changed
25
26 Signed-off-by: Mu Qiao <qiaomuf@g.o>
27 ---
28 system-settings/plugins/ifnet/connection_parser.c | 92 ++++++++++++++------
29 system-settings/plugins/ifnet/net_parser.c | 55 +++++++-----
30 system-settings/plugins/ifnet/net_parser.h | 4 +-
31 system-settings/plugins/ifnet/net_utils.c | 4 +
32 .../plugins/ifnet/nm-ifnet-connection.c | 8 +-
33 system-settings/plugins/ifnet/wpa_parser.c | 21 +++--
34 6 files changed, 123 insertions(+), 61 deletions(-)
35
36 diff --git a/system-settings/plugins/ifnet/connection_parser.c b/system-settings/plugins/ifnet/connection_parser.c
37 index f9fae51..539f33c 100644
38 --- a/system-settings/plugins/ifnet/connection_parser.c
39 +++ b/system-settings/plugins/ifnet/connection_parser.c
40 @@ -557,7 +557,7 @@ make_ip4_setting (NMConnection * connection, gchar * conn_name, GError ** error)
41
42 NMSettingIP4Config *ip4_setting =
43 NM_SETTING_IP4_CONFIG (nm_setting_ip4_config_new ());
44 - gchar *value;
45 + gchar *value, *method = NULL;
46 gboolean is_static_block = is_static_ip4 (conn_name);
47 ip_block *iblock = NULL;
48
49 @@ -569,12 +569,42 @@ make_ip4_setting (NMConnection * connection, gchar * conn_name, GError ** error)
50 && strstr (value, "nogateway") ? TRUE : FALSE, NULL);
51
52 if (!is_static_block) {
53 - g_object_set (ip4_setting,
54 - NM_SETTING_IP4_CONFIG_METHOD,
55 - NM_SETTING_IP4_CONFIG_METHOD_AUTO,
56 - NM_SETTING_IP4_CONFIG_NEVER_DEFAULT, FALSE, NULL);
57 - PLUGIN_PRINT (IFNET_PLUGIN_NAME, "Using DHCP for %s",
58 - conn_name);
59 + method = ifnet_get_data (conn_name, "config");
60 + if (!method){
61 + g_set_error (error, ifnet_plugin_error_quark (), 0,
62 + "Unknown config for %s", conn_name);
63 + g_object_unref (ip4_setting);
64 + return;
65 + }
66 + if (!strcmp (method, "dhcp"))
67 + g_object_set (ip4_setting,
68 + NM_SETTING_IP4_CONFIG_METHOD,
69 + NM_SETTING_IP4_CONFIG_METHOD_AUTO,
70 + NM_SETTING_IP4_CONFIG_NEVER_DEFAULT, FALSE, NULL);
71 + else if (!strcmp (method, "autoip")){
72 + g_object_set (ip4_setting,
73 + NM_SETTING_IP4_CONFIG_METHOD,
74 + NM_SETTING_IP4_CONFIG_METHOD_LINK_LOCAL,
75 + NM_SETTING_IP4_CONFIG_NEVER_DEFAULT, FALSE, NULL);
76 + nm_connection_add_setting (connection, NM_SETTING (ip4_setting));
77 + return;
78 + }
79 + else if (!strcmp (method, "shared")){
80 + g_object_set (ip4_setting,
81 + NM_SETTING_IP4_CONFIG_METHOD,
82 + NM_SETTING_IP4_CONFIG_METHOD_SHARED,
83 + NM_SETTING_IP4_CONFIG_NEVER_DEFAULT, FALSE, NULL);
84 + nm_connection_add_setting (connection, NM_SETTING (ip4_setting));
85 + return;
86 + }
87 + else {
88 + g_set_error (error, ifnet_plugin_error_quark (), 0,
89 + "Unknown config for %s", conn_name);
90 + g_object_unref (ip4_setting);
91 + return;
92 + }
93 + PLUGIN_PRINT (IFNET_PLUGIN_NAME, "Using %s method for %s",
94 + method, conn_name);
95 } else {
96 iblock = convert_ip4_config_block (conn_name);
97 if (!iblock) {
98 @@ -625,7 +655,7 @@ make_ip4_setting (NMConnection * connection, gchar * conn_name, GError ** error)
99 }
100
101 /* add dhcp hostname and client id */
102 - if (!is_static_block) {
103 + if (method && !strcmp (method, "dhcp")) {
104 gchar *dhcp_hostname, *client_id;
105
106 get_dhcp_hostname_and_client_id (&dhcp_hostname, &client_id);
107 @@ -712,7 +742,6 @@ make_ip4_setting (NMConnection * connection, gchar * conn_name, GError ** error)
108 iblock = iblock->next;
109 destroy_ip_block (current_iblock);
110 }
111 -
112 /* Finally add setting to connection */
113 nm_connection_add_setting (connection, NM_SETTING (ip4_setting));
114 }
115 @@ -1243,10 +1272,10 @@ parse_wpa_psk (gchar * psk, GError ** error)
116 * the passphrase contains spaces.
117 */
118
119 - p = psk;
120 - if (p[0] == '"' && psk[strlen (psk) - 1] == '"')
121 + p = g_strdup (psk);
122 + if (p[0] == '"' && p[strlen (p) - 1] == '"')
123 quoted = TRUE;
124 - if (!quoted && (strlen (psk) == 64)) {
125 + if (!quoted && (strlen (p) == 64)) {
126 /* Verify the hex PSK; 64 digits */
127 if (!is_hex (p)) {
128 g_set_error (error, ifnet_plugin_error_quark (),
129 @@ -1254,7 +1283,7 @@ parse_wpa_psk (gchar * psk, GError ** error)
130 "Invalid WPA_PSK (contains non-hexadecimal characters)");
131 goto out;
132 }
133 - hashed = g_strdup (psk);
134 + hashed = g_strdup (p);
135 } else {
136 strip_string (p, '"');
137
138 @@ -1276,6 +1305,7 @@ parse_wpa_psk (gchar * psk, GError ** error)
139 }
140
141 out:
142 + g_free (p);
143 return hashed;
144 }
145
146 @@ -2085,7 +2115,8 @@ write_wireless_security_setting (NMConnection * connection,
147 } else if (!strcmp (key_mgmt, "wpa-eap")) {
148 wpa_set_data (conn_name, "key_mgmt", "WPA-EAP");
149 wpa = TRUE;
150 - }
151 + } else
152 + PLUGIN_WARN (IFNET_PLUGIN_NAME, "Unknown key_mgmt: %s", key_mgmt);
153
154 if (auth_alg) {
155 if (!strcmp (auth_alg, "shared"))
156 @@ -2180,8 +2211,11 @@ write_wireless_security_setting (NMConnection * connection,
157 g_string_append (quoted, psk);
158 g_string_append_c (quoted, '"');
159 }
160 - wpa_set_data (conn_name, "psk",
161 - quoted ? quoted->str : (gchar *) psk);
162 + if (psk)
163 + wpa_set_data (conn_name, "psk",
164 + quoted ? quoted->str : (gchar *) psk);
165 + else
166 + PLUGIN_WARN (IFNET_PLUGIN_NAME, "Use WPA, but no psk received from NM");
167 if (quoted)
168 g_string_free (quoted, TRUE);
169 } else
170 @@ -2190,15 +2224,19 @@ write_wireless_security_setting (NMConnection * connection,
171 return TRUE;
172 }
173
174 -/* remove old ssid and add new one*/
175 +/* Only remove old config when ssid is changed.
176 + * See bug #350476.
177 + * */
178 static void
179 update_wireless_ssid (NMConnection * connection, gchar * conn_name,
180 gchar * ssid, gboolean hex)
181 {
182 - ifnet_delete_network (conn_name);
183 - ifnet_add_connection (ssid, "wireless");
184 + if (strcmp (conn_name, ssid)){
185 + ifnet_delete_network (conn_name);
186 + wpa_delete_security (conn_name);
187 + }
188
189 - wpa_delete_security (conn_name);
190 + ifnet_add_network (ssid, "wireless");
191 wpa_add_security (ssid);
192 }
193
194 @@ -2443,8 +2481,12 @@ write_ip4_setting (NMConnection * connection, gchar * conn_name,
195 }
196 ifnet_set_data (conn_name, "config", ips->str);
197 g_string_free (ips, TRUE);
198 - } else
199 - ifnet_set_data (conn_name, "config", "dhcp");
200 + } else if (!strcmp (value, NM_SETTING_IP4_CONFIG_METHOD_SHARED))
201 + ifnet_set_data (conn_name, "config", "shared");
202 + else if (!strcmp (value, NM_SETTING_IP4_CONFIG_METHOD_LINK_LOCAL))
203 + ifnet_set_data (conn_name, "config", "autoip");
204 + else
205 + ifnet_set_data (conn_name, "config", "dhcp");
206
207 /* DNS Servers */
208 ifnet_set_data (conn_name, "dns_servers", NULL);
209 @@ -2858,7 +2900,7 @@ get_wired_name ()
210 for (; i < 256; i++) {
211 gchar *conn_name = g_strdup_printf ("eth%d", i);
212
213 - if (!ifnet_has_connection (conn_name)) {
214 + if (!ifnet_has_network (conn_name)) {
215 return conn_name;
216 } else
217 g_free (conn_name);
218 @@ -2875,7 +2917,7 @@ get_ppp_name ()
219 for (; i < 256; i++) {
220 gchar *conn_name = g_strdup_printf ("ppp%d", i);
221
222 - if (!ifnet_has_connection (conn_name)) {
223 + if (!ifnet_has_network (conn_name)) {
224 return conn_name;
225 } else
226 g_free (conn_name);
227 @@ -2982,7 +3024,7 @@ ifnet_add_new_connection (NMConnection * connection,
228 goto out;
229 }
230
231 - if (ifnet_add_connection (new_name, new_type))
232 + if (ifnet_add_network (new_name, new_type))
233 success =
234 ifnet_update_parsers_by_connection (connection, new_name,
235 NULL, config_file,
236 diff --git a/system-settings/plugins/ifnet/net_parser.c b/system-settings/plugins/ifnet/net_parser.c
237 index b4a381d..de2db8a 100644
238 --- a/system-settings/plugins/ifnet/net_parser.c
239 +++ b/system-settings/plugins/ifnet/net_parser.c
240 @@ -37,6 +37,9 @@ static GList *functions_list;
241 /* Used to decide whether to write changes to file*/
242 static gboolean net_parser_data_changed = FALSE;
243
244 +static void
245 +destroy_connection_config (GHashTable * conn);
246 +
247 static GHashTable *
248 add_new_connection_config (const gchar * type, const gchar * name)
249 {
250 @@ -58,8 +61,10 @@ add_new_connection_config (const gchar * type, const gchar * name)
251 }
252
253 gboolean
254 -ifnet_add_connection (gchar * name, gchar * type)
255 +ifnet_add_network (gchar * name, gchar * type)
256 {
257 + if (ifnet_has_network (name))
258 + return TRUE;
259 if (add_new_connection_config (type, name)) {
260 PLUGIN_PRINT (IFNET_PLUGIN_NAME, "Adding network for %s", name);
261 net_parser_data_changed = TRUE;
262 @@ -69,11 +74,27 @@ ifnet_add_connection (gchar * name, gchar * type)
263 }
264
265 gboolean
266 -ifnet_has_connection (gchar * conn_name)
267 +ifnet_has_network (gchar * conn_name)
268 {
269 return g_hash_table_lookup (conn_table, conn_name) != NULL;
270 }
271
272 +gboolean
273 +ifnet_delete_network (gchar * conn_name)
274 +{
275 + GHashTable *network = NULL;
276 +
277 + g_return_val_if_fail (conn_table != NULL && conn_name != NULL, FALSE);
278 + PLUGIN_PRINT (IFNET_PLUGIN_NAME, "Deleting network for %s", conn_name);
279 + network = g_hash_table_lookup (conn_table, conn_name);
280 + if (!network)
281 + return FALSE;
282 + g_hash_table_remove (conn_table, conn_name);
283 + destroy_connection_config (network);
284 + net_parser_data_changed = TRUE;
285 + return TRUE;
286 +}
287 +
288 static GHashTable *
289 get_connection_config (gchar * name)
290 {
291 @@ -377,21 +398,27 @@ ifnet_set_data (gchar * conn_name, gchar * key, gchar * value)
292 {
293 gpointer orin_key = NULL, orin_value = NULL;
294 GHashTable *conn = g_hash_table_lookup (conn_table, conn_name);
295 + gchar *new_value = NULL;
296
297 if (!conn) {
298 PLUGIN_WARN (IFNET_PLUGIN_NAME,
299 "%s does not exsit!", conn_name);
300 return;
301 }
302 + if (value){
303 + new_value = g_strdup (value);
304 + strip_string (new_value, '"');
305 + }
306 /* Remove existing key value pair */
307 if (g_hash_table_lookup_extended (conn, key, &orin_key, &orin_value)) {
308 + if (new_value && !strcmp (orin_value, new_value))
309 + return;
310 g_hash_table_remove (conn, orin_key);
311 g_free (orin_key);
312 g_free (orin_value);
313 }
314 - if (value)
315 - g_hash_table_insert (conn, g_strdup (key),
316 - strip_string (g_strdup (value), '"'));
317 + if (new_value)
318 + g_hash_table_insert (conn, g_strdup (key), new_value);
319 net_parser_data_changed = TRUE;
320 }
321
322 @@ -467,7 +494,7 @@ ifnet_flush_to_file (gchar * config_file)
323 gboolean result = FALSE;
324
325 if (!net_parser_data_changed)
326 - return FALSE;
327 + return TRUE;
328 if (!conn_table || !global_settings_table)
329 return FALSE;
330
331 @@ -583,22 +610,6 @@ ifnet_flush_to_file (gchar * config_file)
332 return result;
333 }
334
335 -gboolean
336 -ifnet_delete_network (gchar * conn_name)
337 -{
338 - GHashTable *network = NULL;
339 -
340 - g_return_val_if_fail (conn_table != NULL && conn_name != NULL, FALSE);
341 - PLUGIN_PRINT (IFNET_PLUGIN_NAME, "Deleting network for %s", conn_name);
342 - network = g_hash_table_lookup (conn_table, conn_name);
343 - if (!network)
344 - return FALSE;
345 - g_hash_table_remove (conn_table, conn_name);
346 - destroy_connection_config (network);
347 - net_parser_data_changed = TRUE;
348 - return TRUE;
349 -}
350 -
351 void
352 ifnet_destroy (void)
353 {
354 diff --git a/system-settings/plugins/ifnet/net_parser.h b/system-settings/plugins/ifnet/net_parser.h
355 index 73a44c8..b71a01f 100644
356 --- a/system-settings/plugins/ifnet/net_parser.h
357 +++ b/system-settings/plugins/ifnet/net_parser.h
358 @@ -36,11 +36,11 @@ GList *ifnet_get_connection_names (void);
359 gchar *ifnet_get_data (gchar * conn_name, const gchar * key);
360 gchar *ifnet_get_global_data (const gchar * key);
361 gchar *ifnet_get_global_setting (gchar * group, gchar * key);
362 -gboolean ifnet_has_connection (gchar * conn_name);
363 +gboolean ifnet_has_network (gchar * conn_name);
364
365 /* Writer functions */
366 gboolean ifnet_flush_to_file (gchar * config_file);
367 void ifnet_set_data (gchar * conn_name, gchar * key, gchar * value);
368 -gboolean ifnet_add_connection (gchar * name, gchar * type);
369 +gboolean ifnet_add_network (gchar * name, gchar * type);
370 gboolean ifnet_delete_network (gchar * conn_name);
371 #endif
372 diff --git a/system-settings/plugins/ifnet/net_utils.c b/system-settings/plugins/ifnet/net_utils.c
373 index 2dc253c..7e52f10 100644
374 --- a/system-settings/plugins/ifnet/net_utils.c
375 +++ b/system-settings/plugins/ifnet/net_utils.c
376 @@ -278,6 +278,10 @@ is_static_ip4 (gchar * conn_name)
377
378 if (!data)
379 return FALSE;
380 + if (!strcmp (data, "shared"))
381 + return FALSE;
382 + if (!strcmp (data, "autoip"))
383 + return FALSE;
384 dhcp6 = strstr (data, "dhcp6");
385 if (dhcp6) {
386 gchar *dhcp4;
387 diff --git a/system-settings/plugins/ifnet/nm-ifnet-connection.c b/system-settings/plugins/ifnet/nm-ifnet-connection.c
388 index e47495c..ebe2581 100644
389 --- a/system-settings/plugins/ifnet/nm-ifnet-connection.c
390 +++ b/system-settings/plugins/ifnet/nm-ifnet-connection.c
391 @@ -71,12 +71,14 @@ nm_ifnet_connection_new (gchar * conn_name)
392 {
393 NMConnection *tmp;
394 GObject *object;
395 - GError **error = NULL;
396 + GError *error = NULL;
397
398 g_return_val_if_fail (conn_name != NULL, NULL);
399 - tmp = ifnet_update_connection_from_config_block (conn_name, error);
400 - if (!tmp)
401 + tmp = ifnet_update_connection_from_config_block (conn_name, &error);
402 + if (!tmp){
403 + g_error_free (error);
404 return NULL;
405 + }
406 object = (GObject *) g_object_new (NM_TYPE_IFNET_CONNECTION,
407 NM_IFNET_CONNECTION_CONN_NAME,
408 conn_name, NULL);
409 diff --git a/system-settings/plugins/ifnet/wpa_parser.c b/system-settings/plugins/ifnet/wpa_parser.c
410 index 5e94108..42c52c3 100644
411 --- a/system-settings/plugins/ifnet/wpa_parser.c
412 +++ b/system-settings/plugins/ifnet/wpa_parser.c
413 @@ -366,7 +366,7 @@ wpa_flush_to_file (gchar * config_file)
414 gboolean result = FALSE;
415
416 if (!wpa_parser_data_changed)
417 - return FALSE;
418 + return TRUE;
419 if (!wsec_table || !wsec_global_table)
420 return FALSE;
421
422 @@ -450,26 +450,29 @@ wpa_set_data (gchar * ssid, gchar * key, gchar * value)
423 {
424 gpointer orig_key = NULL, orig_value = NULL;
425 GHashTable *security = g_hash_table_lookup (wsec_table, ssid);
426 + gchar *new_value = NULL;
427
428 g_return_if_fail (security != NULL);
429
430 + if (value){
431 + new_value = g_strdup(value);
432 + if (strcmp (key, "ssid") != 0 && strcmp (key, "psk") != 0
433 + && !g_str_has_prefix (key, "wep_key"))
434 + strip_string (new_value, '"');
435 + }
436 /* Remove old key value pairs */
437 if (g_hash_table_lookup_extended
438 (security, key, &orig_key, &orig_value)) {
439 + if (new_value && !strcmp(orig_value, new_value))
440 + return;
441 g_hash_table_remove (security, orig_key);
442 g_free (orig_key);
443 g_free (orig_value);
444 }
445
446 /* Add new key value */
447 - if (value) {
448 - gchar *new_value = g_strdup (value);
449 -
450 - if (strcmp (key, "ssid") != 0 && strcmp (key, "psk") != 0
451 - && !g_str_has_prefix (key, "wep_key"))
452 - strip_string (new_value, '"');
453 + if (new_value)
454 g_hash_table_insert (security, g_strdup (key), new_value);
455 - }
456 wpa_parser_data_changed = TRUE;
457 }
458
459 @@ -483,7 +486,7 @@ gboolean
460 wpa_add_security (gchar * ssid)
461 {
462 if (wpa_has_security (ssid))
463 - return FALSE;
464 + return TRUE;
465 else {
466 GHashTable *security =
467 g_hash_table_new (g_str_hash, g_str_equal);
468 --
469 1.7.3.4