1
Let the NM's ifupdown plugin honor ifupdown's source stanza.
3
Upstream bug: https://bugzilla.gnome.org/show_bug.cgi?id=707276
5
http://cgit.freedesktop.org/NetworkManager/NetworkManager/commit/?id=48ed1abca77195ed9b36645593733da143e3be3f
6
http://cgit.freedesktop.org/NetworkManager/NetworkManager/commit/?id=4e09b87d5404580ec5a75234fe48d4c6137c4e40
8
Index: network-manager-0.9.8.4/src/settings/plugins/ifupdown/interface_parser.c
9
===================================================================
10
--- network-manager-0.9.8.4.orig/src/settings/plugins/ifupdown/interface_parser.c 2014-01-23 10:55:18.150494764 +0000
11
+++ network-manager-0.9.8.4/src/settings/plugins/ifupdown/interface_parser.c 2014-01-23 10:55:18.146494765 +0000
25
-void ifparser_init (const char *eni_file, int quiet)
26
+static void _ifparser_source (const char *path, const char *en_dir, int quiet);
29
+_recursive_ifparser (const char *eni_file, int quiet)
31
- FILE *inp = fopen (eni_file, "r");
34
int skip_to_block = 1;
35
int skip_long_line = 0;
38
+ // Check if interfaces file exists and open it
39
+ if (!g_file_test (eni_file, G_FILE_TEST_EXISTS)) {
41
+ g_warning ("Warning: interfaces file %s doesn't exist\n", eni_file);
44
+ inp = fopen (eni_file, "r");
47
g_warning ("Error: Can't open %s\n", eni_file);
51
+ g_message (" interface-parser: parsing file %s\n", eni_file);
54
- first = last = NULL;
57
char *token[128]; // 255 chars can only be split into 127 tokens
62
- // There are four different stanzas:
63
- // iface, mapping, auto and allow-*. Create a block for each of them.
64
+ // There are five different stanzas:
65
+ // iface, mapping, auto, allow-* and source.
66
+ // Create a block for each of them except source.
68
// iface stanza takes at least 3 parameters
69
if (strcmp(token[0], "iface") == 0) {
71
add_block(token[0], token[i]);
74
+ // source stanza takes one or more filepaths as parameters
75
+ else if (strcmp(token[0], "source") == 0) {
83
+ g_warning ("Error: Invalid source line without parameters\n");
87
+ en_dir = g_path_get_dirname (eni_file);
88
+ for (i = 1; i < toknum; ++i)
89
+ _ifparser_source (token[i], en_dir, quiet);
95
g_message ("Error: ignoring out-of-block data '%s'\n",
96
- join_values_with_spaces(value, token));
97
+ join_values_with_spaces(value, token));
100
add_data(token[0], join_values_with_spaces(value, token + 1));
106
+ g_message (" interface-parser: finished parsing file %s\n", eni_file);
110
+_ifparser_source (const char *path, const char *en_dir, int quiet)
116
+ if (g_path_is_absolute (path))
117
+ abs_path = g_strdup (path);
119
+ abs_path = g_build_filename (en_dir, path, NULL);
122
+ g_message (" interface-parser: source line includes interfaces file(s) %s\n", abs_path);
124
+ /* ifupdown uses WRDE_NOCMD for wordexp. */
125
+ if (wordexp (abs_path, &we, WRDE_NOCMD)) {
127
+ g_warning ("Error: word expansion for %s failed\n", abs_path);
129
+ for (i = 0; i < we.we_wordc; i++)
130
+ _recursive_ifparser (we.we_wordv[i], quiet);
136
+void ifparser_init (const char *eni_file, int quiet)
138
+ first = last = NULL;
139
+ _recursive_ifparser (eni_file, quiet);
142
void _destroy_data(if_data *ifd)
143
Index: network-manager-0.9.8.4/src/settings/plugins/ifupdown/tests/test-ifupdown.c
144
===================================================================
145
--- network-manager-0.9.8.4.orig/src/settings/plugins/ifupdown/tests/test-ifupdown.c 2014-01-23 10:55:18.150494764 +0000
146
+++ network-manager-0.9.8.4/src/settings/plugins/ifupdown/tests/test-ifupdown.c 2014-01-23 10:55:18.146494765 +0000
148
g_object_unref (connection);
152
+test20_source_stanza (const char *path)
157
+ e = expected_new ();
159
+ b = expected_block_new ("auto", "eth0");
160
+ expected_add_block (e, b);
161
+ b = expected_block_new ("iface", "eth0");
162
+ expected_add_block (e, b);
163
+ expected_block_add_key (b, expected_key_new ("inet", "dhcp"));
165
+ b = expected_block_new ("auto", "eth1");
166
+ expected_add_block (e, b);
167
+ b = expected_block_new ("iface", "eth1");
168
+ expected_add_block (e, b);
169
+ expected_block_add_key (b, expected_key_new ("inet", "dhcp"));
171
+ init_ifparser_with_file (path, "test20-source-stanza");
172
+ compare_expected_to_ifparser (e);
174
+ ifparser_destroy ();
178
#if GLIB_CHECK_VERSION(2,25,12)
179
typedef GTestFixtureFunc TCFunc;
181
g_test_suite_add (suite, TESTCASE (test17_read_static_ipv4, TEST_ENI_DIR));
182
g_test_suite_add (suite, TESTCASE (test18_read_static_ipv6, TEST_ENI_DIR));
183
g_test_suite_add (suite, TESTCASE (test19_read_static_ipv4_plen, TEST_ENI_DIR));
184
+ g_test_suite_add (suite, TESTCASE (test20_source_stanza, TEST_ENI_DIR));
186
return g_test_run ();
188
Index: network-manager-0.9.8.4/src/settings/plugins/ifupdown/tests/test20-source-stanza
189
===================================================================
190
--- /dev/null 1970-01-01 00:00:00.000000000 +0000
191
+++ network-manager-0.9.8.4/src/settings/plugins/ifupdown/tests/test20-source-stanza 2014-01-23 10:55:18.146494765 +0000
193
+source test20-source-stanza.eth*
194
Index: network-manager-0.9.8.4/src/settings/plugins/ifupdown/tests/test20-source-stanza.eth0
195
===================================================================
196
--- /dev/null 1970-01-01 00:00:00.000000000 +0000
197
+++ network-manager-0.9.8.4/src/settings/plugins/ifupdown/tests/test20-source-stanza.eth0 2014-01-23 10:55:18.146494765 +0000
200
+iface eth0 inet dhcp
201
Index: network-manager-0.9.8.4/src/settings/plugins/ifupdown/tests/test20-source-stanza.eth1
202
===================================================================
203
--- /dev/null 1970-01-01 00:00:00.000000000 +0000
204
+++ network-manager-0.9.8.4/src/settings/plugins/ifupdown/tests/test20-source-stanza.eth1 2014-01-23 10:55:18.146494765 +0000
207
+iface eth1 inet dhcp