~cyphermox/+junk/nm-mms-support

« back to all changes in this revision

Viewing changes to debian/patches/nm-source-stanza.patch

  • Committer: Mathieu Trudel-Lapierre
  • Date: 2014-01-23 20:22:18 UTC
  • Revision ID: mathieu-tl@ubuntu.com-20140123202218-s3hp66wjtxvh7o8q
ifupdown plugin: Support ifupdown's source stanza. (LP: #1271567)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
Let the NM's ifupdown plugin honor ifupdown's source stanza.
 
2
 
 
3
Upstream bug: https://bugzilla.gnome.org/show_bug.cgi?id=707276
 
4
Upstream patches:
 
5
http://cgit.freedesktop.org/NetworkManager/NetworkManager/commit/?id=48ed1abca77195ed9b36645593733da143e3be3f
 
6
http://cgit.freedesktop.org/NetworkManager/NetworkManager/commit/?id=4e09b87d5404580ec5a75234fe48d4c6137c4e40
 
7
 
 
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
 
12
@@ -25,6 +25,8 @@
 
13
 #include <stdio.h>
 
14
 #include <stdlib.h>
 
15
 #include <string.h>
 
16
+#include <wordexp.h>
 
17
+#include <libgen.h>
 
18
 #include "nm-utils.h"
 
19
 
 
20
 if_block* first;
 
21
@@ -96,21 +98,33 @@
 
22
        return(dst);
 
23
 }
 
24
 
 
25
-void ifparser_init (const char *eni_file, int quiet)
 
26
+static void _ifparser_source (const char *path, const char *en_dir, int quiet);
 
27
+
 
28
+static void
 
29
+_recursive_ifparser (const char *eni_file, int quiet)
 
30
 {
 
31
-       FILE *inp = fopen (eni_file, "r");
 
32
+       FILE *inp;
 
33
        char line[255];
 
34
        int skip_to_block = 1;
 
35
        int skip_long_line = 0;
 
36
        int offs = 0;
 
37
 
 
38
+       // Check if interfaces file exists and open it
 
39
+       if (!g_file_test (eni_file, G_FILE_TEST_EXISTS)) {
 
40
+               if (!quiet)
 
41
+                       g_warning ("Warning: interfaces file %s doesn't exist\n", eni_file);
 
42
+               return;
 
43
+       }
 
44
+       inp = fopen (eni_file, "r");
 
45
        if (inp == NULL) {
 
46
                if (!quiet)
 
47
                        g_warning ("Error: Can't open %s\n", eni_file);
 
48
                return;
 
49
        }
 
50
+       if (!quiet)
 
51
+               g_message ("      interface-parser: parsing file %s\n", eni_file);
 
52
+
 
53
 
 
54
-       first = last = NULL;
 
55
        while (!feof(inp))
 
56
        {
 
57
                char *token[128];       // 255 chars can only be split into 127 tokens
 
58
@@ -175,8 +189,9 @@
 
59
                        continue;
 
60
                }
 
61
 
 
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.
 
67
 
 
68
                // iface stanza takes at least 3 parameters
 
69
                if (strcmp(token[0], "iface") == 0) {
 
70
@@ -211,17 +226,71 @@
 
71
                                add_block(token[0], token[i]);
 
72
                        skip_to_block = 0;
 
73
                }
 
74
+               // source stanza takes one or more filepaths as parameters
 
75
+               else if (strcmp(token[0], "source") == 0) {
 
76
+                       int i;
 
77
+                       char *en_dir;
 
78
+
 
79
+                       skip_to_block = 0;
 
80
+
 
81
+                       if (toknum == 1) {
 
82
+                               if (!quiet)
 
83
+                                       g_warning ("Error: Invalid source line without parameters\n");
 
84
+                               continue;
 
85
+                       }
 
86
+
 
87
+                       en_dir = g_path_get_dirname (eni_file);
 
88
+                       for (i = 1; i < toknum; ++i)
 
89
+                               _ifparser_source (token[i], en_dir, quiet);
 
90
+                       g_free (en_dir);
 
91
+               }
 
92
                else {
 
93
                        if (skip_to_block) {
 
94
                                if (!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));
 
98
                                }
 
99
                        } else
 
100
                                add_data(token[0], join_values_with_spaces(value, token + 1));
 
101
                }
 
102
        }
 
103
        fclose(inp);
 
104
+
 
105
+       if (!quiet)
 
106
+               g_message ("      interface-parser: finished parsing file %s\n", eni_file);
 
107
+}
 
108
+
 
109
+static void
 
110
+_ifparser_source (const char *path, const char *en_dir, int quiet)
 
111
+{
 
112
+       char *abs_path;
 
113
+       wordexp_t we;
 
114
+       uint i;
 
115
+
 
116
+       if (g_path_is_absolute (path))
 
117
+               abs_path = g_strdup (path);
 
118
+       else
 
119
+               abs_path = g_build_filename (en_dir, path, NULL);
 
120
+
 
121
+       if (!quiet)
 
122
+               g_message ("      interface-parser: source line includes interfaces file(s) %s\n", abs_path);
 
123
+
 
124
+       /* ifupdown uses WRDE_NOCMD for wordexp. */
 
125
+       if (wordexp (abs_path, &we, WRDE_NOCMD)) {
 
126
+               if (!quiet)
 
127
+                       g_warning ("Error: word expansion for %s failed\n", abs_path);
 
128
+       } else {
 
129
+               for (i = 0; i < we.we_wordc; i++)
 
130
+                       _recursive_ifparser (we.we_wordv[i], quiet);
 
131
+               wordfree (&we);
 
132
+       }
 
133
+       g_free (abs_path);
 
134
+}
 
135
+
 
136
+void ifparser_init (const char *eni_file, int quiet)
 
137
+{
 
138
+       first = last = NULL;
 
139
+       _recursive_ifparser (eni_file, quiet);
 
140
 }
 
141
 
 
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
 
147
@@ -903,6 +903,32 @@
 
148
        g_object_unref (connection);
 
149
 }
 
150
 
 
151
+static void
 
152
+test20_source_stanza (const char *path)
 
153
+{
 
154
+       Expected *e;
 
155
+       ExpectedBlock *b;
 
156
+
 
157
+       e = expected_new ();
 
158
+
 
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"));
 
164
+
 
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"));
 
170
+
 
171
+       init_ifparser_with_file (path, "test20-source-stanza");
 
172
+       compare_expected_to_ifparser (e);
 
173
+
 
174
+       ifparser_destroy ();
 
175
+       expected_free (e);
 
176
+}
 
177
 
 
178
 #if GLIB_CHECK_VERSION(2,25,12)
 
179
 typedef GTestFixtureFunc TCFunc;
 
180
@@ -947,6 +973,7 @@
 
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));
 
185
 
 
186
        return g_test_run ();
 
187
 }
 
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
 
192
@@ -0,0 +1 @@
 
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
 
198
@@ -0,0 +1,2 @@
 
199
+auto eth0
 
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
 
205
@@ -0,0 +1,2 @@
 
206
+auto eth1
 
207
+iface eth1 inet dhcp