summaryrefslogtreecommitdiff
path: root/community/netcf/netcf-0.1.7.patch
blob: d4a4d31b73063d1b18f31947509d309b0b20e29f (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
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
diff -ur netcf-0.1.7.ori//data/xml/initscripts-get.xsl netcf-0.1.7/data/xml/initscripts-get.xsl
--- netcf-0.1.7.ori//data/xml/initscripts-get.xsl	2009-10-04 08:18:41.000000000 +0200
+++ netcf-0.1.7/data/xml/initscripts-get.xsl	2010-12-08 14:54:28.891813397 +0100
@@ -47,9 +47,12 @@
   <xsl:template name="vlan-interface-common">
     <xsl:variable name="iface" select="concat(vlan/interface/@name, '.', vlan/@tag)"/>
 
-    <xsl:attribute name="path">/files/etc/sysconfig/network-scripts/ifcfg-<xsl:value-of select="$iface"/></xsl:attribute>
-    <node label="DEVICE" value="{$iface}"/>
-    <node label="VLAN" value="yes"/>
+    <xsl:attribute name="path">/files/etc/network.d/ifcfg-<xsl:value-of select="$iface"/></xsl:attribute>
+    <node label="INTERFACE" value="{$iface}"/>
+    <node label="PHYS_INTERFACE" value="{vlan/interface/@name}"/>
+    <node label="VLAN" value="{vlan/@tag}"/>
+    <node label="CONNECTION" value="ethernet-iproute-vlan"/>
+    <node label="FLAG" value="false"/>
   </xsl:template>
 
   <xsl:template name='bare-vlan-interface'>
@@ -68,6 +71,7 @@
       <xsl:call-template name="startmode"/>
       <xsl:call-template name="mtu"/>
       <node label="TYPE" value="Bridge"/>
+      <node label="CONNECTION" value="bridge"/>
       <xsl:call-template name="interface-addressing"/>
       <xsl:if test="bridge/@stp">
         <node label="STP" value="{bridge/@stp}"/>
@@ -75,7 +79,11 @@
       <xsl:if test="bridge/@delay">
         <node label="DELAY" value="{bridge/@delay}"/>
       </xsl:if>
+      <node label="DHCP_TIMEOUT" value="0"/>
+    <!--
+    We don't have to define interfaces separately
     </tree>
+    
     <xsl:for-each select='bridge/interface'>
       <tree>
         <xsl:if test="@type = 'ethernet'">
@@ -87,12 +95,29 @@
         <xsl:if test="@type = 'bond'">
           <xsl:call-template name="bare-bond-interface"/>
         </xsl:if>
+
+        BRIDGE_INTERFACES= is defined with all interfaces
         <node label="BRIDGE" value="{../../@name}"/>
+
+        <xsl:variable name="bridgeifaces" select="concat($bridgeifaces, '.', @name)"/>
       </tree>
       <xsl:if test="@type = 'bond'">
         <xsl:call-template name="bond-slaves"/>
       </xsl:if>
     </xsl:for-each>
+    -->
+    <!-- <xsl:if test="count(ip) > 1"> -->
+    <node label="BRIDGE_INTERFACES">
+    <xsl:attribute name="value">
+      <xsl:text></xsl:text>
+      <xsl:for-each select="bridge/interface">
+        <xsl:value-of select="@name"/><xsl:value-of select="string(' ')"/>
+      </xsl:for-each>
+      <xsl:text></xsl:text>
+    </xsl:attribute>
+    </node>
+    <!-- </xsl:if> -->
+    </tree>
   </xsl:template>
 
   <!--
@@ -138,8 +163,8 @@
        Named templates, following the Relax NG syntax
   -->
   <xsl:template name="name-attr">
-    <xsl:attribute name="path">/files/etc/sysconfig/network-scripts/ifcfg-<xsl:value-of select="@name"/></xsl:attribute>
-    <node label="DEVICE" value="{@name}"/>
+    <xsl:attribute name="path">/files/etc/network.d/ifcfg-<xsl:value-of select="@name"/></xsl:attribute>
+    <node label="INTERFACE" value="{@name}"/>
   </xsl:template>
 
   <xsl:template name="mtu">
@@ -153,6 +178,7 @@
     <xsl:if test="mac">
       <node label="HWADDR" value="{mac/@address}"/>
     </xsl:if>
+    <node label="CONNECTION" value="{@type}"/>
     <xsl:call-template name="startmode"/>
     <xsl:call-template name="mtu"/>
   </xsl:template>
@@ -184,14 +210,14 @@
   <xsl:template name="protocol-ipv4">
     <xsl:choose>
       <xsl:when test="dhcp">
-        <node label="BOOTPROTO" value="dhcp"/>
+        <node label="IP" value="dhcp"/>
         <xsl:if test="dhcp/@peerdns">
           <node label="PEERDNS" value="{dhcp/@peerdns}"/>
         </xsl:if>
       </xsl:when>
       <xsl:when test="ip">
-        <node label="BOOTPROTO" value="none"/>
-        <node label="IPADDR" value="{ip/@address}"/>
+        <node label="IP" value="static"/>
+        <node label="ADDR" value="{ip/@address}"/>
         <xsl:if test="ip/@prefix">
           <node label="NETMASK" value="{ipcalc:netmask(ip/@prefix)}"/>
         </xsl:if>
diff -ur netcf-0.1.7.ori//data/xml/initscripts-put.xsl netcf-0.1.7/data/xml/initscripts-put.xsl
--- netcf-0.1.7.ori//data/xml/initscripts-put.xsl	2009-10-04 08:18:41.000000000 +0200
+++ netcf-0.1.7/data/xml/initscripts-put.xsl	2010-11-26 10:44:46.133757628 +0100
@@ -47,7 +47,7 @@
   </xsl:template>
 
   <xsl:template name="bare-vlan-interface">
-    <xsl:variable name="name" select="node[@label = 'DEVICE']/@value"/>
+    <xsl:variable name="name" select="node[@label = 'INTERFACE']/@value"/>
     <interface type="vlan">
       <xsl:call-template name="name-attr"/>
       <xsl:call-template name="vlan-device"/>
@@ -55,7 +55,7 @@
   </xsl:template>
 
   <xsl:template name="vlan-device">
-    <xsl:variable name="name" select="node[@label = 'DEVICE']/@value"/>
+    <xsl:variable name="name" select="node[@label = 'INTERFACE']/@value"/>
     <xsl:variable name="device" select="substring-before($name, '.')"/>
     <xsl:variable name="tag" select="substring-after($name, '.')"/>
     <vlan tag="{$tag}">
@@ -70,7 +70,7 @@
                 match="tree[node[@label = 'TYPE' and @value = 'Bridge']]">
     <interface type="bridge">
       <!-- the bridge node itself -->
-      <xsl:variable name="iface" select="node[@label= 'DEVICE']/@value"/>
+      <xsl:variable name="iface" select="node[@label= 'INTERFACE']/@value"/>
       <xsl:call-template name="name-attr"/>
       <xsl:call-template name="startmode"/>
       <xsl:call-template name="mtu"/>
@@ -101,17 +101,17 @@
       Bond
   -->
   <xsl:template name="bond-element">
-    <xsl:variable name="iface" select="node[@label= 'DEVICE']/@value"/>
+    <xsl:variable name="iface" select="node[@label= 'INTERFACE']/@value"/>
     <bond>
       <xsl:variable name="opts" select="node[@label = 'BONDING_OPTS']/@value"/>
       <xsl:call-template name="bonding-opts">
         <xsl:with-param name="opts" select="$opts"/>
       </xsl:call-template>
       <xsl:variable name="primary" select="bond:option($opts, 'primary')"/>
-      <xsl:for-each select="/descendant-or-self::*[node[@label = 'MASTER' and @value = $iface]][node[@label = 'DEVICE' and @value = $primary]]">
+      <xsl:for-each select="/descendant-or-self::*[node[@label = 'MASTER' and @value = $iface]][node[@label = 'INTERFACE' and @value = $primary]]">
         <xsl:call-template name='bare-ethernet-interface'/>
       </xsl:for-each>
-      <xsl:for-each select="/descendant-or-self::*[node[@label = 'MASTER' and @value = $iface]][node[@label = 'DEVICE' and @value != $primary]]">
+      <xsl:for-each select="/descendant-or-self::*[node[@label = 'MASTER' and @value = $iface]][node[@label = 'INTERFACE' and @value != $primary]]">
         <xsl:call-template name='bare-ethernet-interface'/>
       </xsl:for-each>
     </bond>
@@ -125,7 +125,7 @@
   </xsl:template>
 
   <xsl:template name="bond-interface"
-                match="tree[node[@label = 'DEVICE'][@value = //tree/node[@label = 'MASTER']/@value]][count(node[@label = 'BRIDGE']) = 0]">
+                match="tree[node[@label = 'INTERFACE'][@value = //tree/node[@label = 'MASTER']/@value]][count(node[@label = 'BRIDGE']) = 0]">
     <interface type="bond">
       <xsl:call-template name="name-attr"/>
       <xsl:call-template name="startmode"/>
@@ -154,7 +154,7 @@
 
   <xsl:template name="name-attr">
     <xsl:attribute name="name">
-      <xsl:value-of select="node[@label= 'DEVICE']/@value"/>
+      <xsl:value-of select="node[@label= 'INTERFACE']/@value"/>
     </xsl:attribute>
   </xsl:template>
 
@@ -173,7 +173,7 @@
     <xsl:variable name="uses_dhcp"
                   select="node[@label = 'BOOTPROTO']/@value = 'dhcp'"/>
     <xsl:variable name="uses_static"
-                  select="count(node[@label = 'IPADDR']) > 0"/>
+                  select="count(node[@label = 'ADDR']) > 0"/>
     <xsl:variable name="uses_ipv4" select="$uses_dhcp or $uses_static"/>
     <xsl:if test="$uses_ipv4">
     <protocol family="ipv4">
@@ -186,7 +186,7 @@
           </dhcp>
         </xsl:when>
         <xsl:when test="$uses_static">
-          <ip address="{node[@label = 'IPADDR']/@value}">
+          <ip address="{node[@label = 'ADDR']/@value}">
             <xsl:choose>
               <xsl:when test="node[@label = 'PREFIX']">
                 <xsl:attribute name="prefix"><xsl:value-of select="node[@label = 'PREFIX']/@value"/></xsl:attribute>
diff -ur netcf-0.1.7.ori//src/drv_initscripts.c netcf-0.1.7/src/drv_initscripts.c
--- netcf-0.1.7.ori//src/drv_initscripts.c	2010-09-23 14:13:13.000000000 +0200
+++ netcf-0.1.7/src/drv_initscripts.c	2010-12-08 13:57:02.027361706 +0100
@@ -49,17 +49,20 @@
 #include <libexslt/exslt.h>
 
 static const char *const network_scripts_path =
-    "/files/etc/sysconfig/network-scripts";
+    //"/files/etc/sysconfig/network-scripts";
+    "/files/etc/network.d/*";
 
 static const char *const ifcfg_path =
-    "/files/etc/sysconfig/network-scripts/*";
+    //"/files/etc/sysconfig/network-scripts/*";
+    "/files/etc/network.d/*";
 
 /* Augeas should only load the files we are interested in */
 static const struct augeas_pv augeas_xfm_common_pv[] = {
     /* Ifcfg files */
     { "/augeas/load/Ifcfg/lens", "Sysconfig.lns" },
     { "/augeas/load/Ifcfg/incl",
-      "/etc/sysconfig/network-scripts/ifcfg-*" },
+      "/etc/network.d/ifcfg-*" },
+      //"/etc/sysconfig/network-scripts/ifcfg-*" },
     { "/augeas/load/Ifcfg/excl[1]", "*~" },
     { "/augeas/load/Ifcfg/excl[2]", "*.bak" },
     { "/augeas/load/Ifcfg/excl[3]", "*.orig" },
@@ -107,10 +110,10 @@
     int nmatches;
 
     nmatches = aug_fmt_match(ncf, NULL,
-                             "%s[ DEVICE = '%s'"
+                             "%s[ INTERFACE = '%s'"
                              "    or BRIDGE = '%s'"
                              "    or MASTER = '%s'"
-                             "    or MASTER = ../*[BRIDGE = '%s']/DEVICE ]/DEVICE",
+                             "    or MASTER = ../*[BRIDGE = '%s']/INTERFACE ]/INTERFACE",
                              ifcfg_path, name, name, name, name);
     return nmatches > 0;
 }
@@ -173,7 +176,7 @@
     aug = get_augeas(ncf);
     ERR_BAIL(ncf);
 
-    ndevs = aug_fmt_match(ncf, &devs, "%s[DEVICE = '%s']",
+    ndevs = aug_fmt_match(ncf, &devs, "%s[INTERFACE = '%s']",
                           ifcfg_path, name);
     ERR_COND_BAIL(ndevs < 0, ncf, EOTHER);
 
@@ -296,7 +299,8 @@
     int result = 0, ndevs;
     char **devs = NULL;
 
-    ndevs = aug_fmt_match(ncf, &devs, "%s/DEVICE", ifcfg_path);
+    ndevs = aug_fmt_match(ncf, &devs, "%s/INTERFACE", ifcfg_path);
+    printf("%i\n", ndevs);
     ERR_COND_BAIL(ndevs < 0, ncf, EOTHER);
 
     result = uniq_ifcfg_paths(ncf, ndevs, devs, intf);
@@ -453,11 +457,11 @@
 
 int drv_list_interfaces(struct netcf *ncf, int maxnames, char **names,
         unsigned int flags) {
-    return list_interface_ids(ncf, maxnames, names, flags, "DEVICE");
+    return list_interface_ids(ncf, maxnames, names, flags, "INTERFACE");
 }
 
 int drv_num_of_interfaces(struct netcf *ncf, unsigned int flags) {
-    return list_interface_ids(ncf, 0, NULL, flags, "DEVICE");
+    return list_interface_ids(ncf, 0, NULL, flags, "INTERFACE");
 }
 
 struct netcf_if *drv_lookup_by_name(struct netcf *ncf, const char *name) {
@@ -599,8 +603,8 @@
 
     ncf = nif->ncf;
     ndevs = aug_fmt_match(ncf, &devs,
-              "%s[ DEVICE = '%s' or BRIDGE = '%s' or MASTER = '%s'"
-              "    or MASTER = ../*[BRIDGE = '%s']/DEVICE ]/DEVICE",
+              "%s[ INTERFACE = '%s' or BRIDGE = '%s' or MASTER = '%s'"
+              "    or MASTER = ../*[BRIDGE = '%s']/INTERFACE ]/INTERFACE",
               ifcfg_path, nif->name, nif->name, nif->name, nif->name);
     ERR_BAIL(ncf);
 
@@ -745,7 +749,7 @@
     int nmatches = 0;
 
     nmatches = aug_fmt_match(ncf, NULL,
-                             "%s[ DEVICE = '%s' and TYPE = 'Bridge']",
+                             "%s[ INTERFACE = '%s' and TYPE = 'Bridge']",
                              ifcfg_path, name);
     return nmatches > 0;
 }
@@ -758,7 +762,7 @@
     ERR_BAIL(ncf);
 
     nslaves = aug_fmt_match(ncf, slaves,
-                            "%s[ BRIDGE = '%s' ]/DEVICE", ifcfg_path, name);
+                            "%s[ BRIDGE = '%s' ]/INTERFACE", ifcfg_path, name);
     ERR_BAIL(ncf);
     for (int i=0; i < nslaves; i++) {
         char *p = (*slaves)[i];
@@ -790,8 +794,8 @@
     /* The last or clause catches slaves of a bond that are enslaved to
      * a bridge NAME */
     r = xasprintf(&path,
-          "%s[ DEVICE = '%s' or BRIDGE = '%s' or MASTER = '%s' "
-          "    or MASTER = ../*[BRIDGE = '%s']/DEVICE ]",
+          "%s[ INTERFACE = '%s' or BRIDGE = '%s' or MASTER = '%s' "
+          "    or MASTER = ../*[BRIDGE = '%s']/INTERFACE ]",
                   ifcfg_path, name, name, name, name);
     ERR_NOMEM(r < 0, ncf);
 
@@ -967,7 +971,7 @@
     for (int i = 0; i < nmatches; i++) {
         if (!has_ifcfg_file(ncf, matches[i]))
             continue;
-        r = xasprintf(&ifcfg, "%s[DEVICE = '%s']", ifcfg_path, matches[i]);
+        r = xasprintf(&ifcfg, "%s[INTERFACE = '%s']", ifcfg_path, matches[i]);
         ERR_NOMEM(r < 0, ncf);
 
         if (! is_slave(ncf, ifcfg))
@@ -1023,7 +1027,10 @@
  */
 
 int drv_if_up(struct netcf_if *nif) {
-    static const char *const ifup = "ifup";
+    //static const char *const ifup = "ifup";
+    static const char *const ifup = "netcfg";
+    static const char *const ifprefix = "ifcfg-";
+    char ifname[strlen(nif->name) + sizeof(ifprefix)];
     struct netcf *ncf = nif->ncf;
     char **slaves = NULL;
     int nslaves = 0;
@@ -1035,11 +1042,24 @@
         ERR_BAIL(ncf);
 
         for (int i=0; i < nslaves; i++) {
-            run1(ncf, ifup, slaves[i]);
+            //run1(ncf, ifup, slaves[i]);
+            const char *const argv[] = {
+                ifup, "-u", slaves[i], NULL
+            };
+
+            run_program(ncf, argv);
             ERR_BAIL(ncf);
         }
     }
-    run1(ncf, ifup, nif->name);
+    //run1(ncf, ifup, nif->name);
+    /* Interfaces name have to be equal to script under /etc/network.d */
+    strcpy(ifname, ifprefix);
+    strcat(ifname, nif->name);
+    const char *const argv[] = {
+                ifup, "-u", ifname, NULL
+            };
+
+    run_program(ncf, argv);
     ERR_BAIL(ncf);
     result = 0;
  error:
@@ -1048,13 +1068,23 @@
 }
 
 int drv_if_down(struct netcf_if *nif) {
-    static const char *const ifdown = "ifdown";
+    //static const char *const ifdown = "ifdown";
+    static const char *const ifdown = "netcfg";
+    static const char *const ifprefix = "ifcfg-";
+    char ifname[strlen(nif->name) + sizeof(ifprefix)];
     struct netcf *ncf = nif->ncf;
     char **slaves = NULL;
     int nslaves = 0;
     int result = -1;
 
-    run1(ncf, ifdown, nif->name);
+    //run1(ncf, ifdown, nif->name);
+    strcpy(ifname, ifprefix);
+    strcat(ifname, nif->name);
+    const char *const argv[] = {
+        ifdown, "-d", ifname, NULL
+    };
+
+    run_program(ncf, argv);
     ERR_BAIL(ncf);
     if (is_bridge(ncf, nif->name)) {
         /* Bring up bridge slaves after the bridge */
@@ -1062,7 +1092,12 @@
         ERR_BAIL(ncf);
 
         for (int i=0; i < nslaves; i++) {
-            run1(ncf, ifdown, slaves[i]);
+            //run1(ncf, ifdown, slaves[i]);
+            const char *const argvs[] = {
+                ifdown, "-d", slaves[i], NULL
+            };
+
+            run_program(ncf, argvs);
             ERR_BAIL(ncf);
         }
     }
diff -ur netcf-0.1.7.ori//tests/interface/bridge.xml~ netcf-0.1.7/tests/interface/bridge.xml~
--- netcf-0.1.7.ori//tests/interface/bridge.xml~	2009-10-13 19:14:53.000000000 +0200
+++ netcf-0.1.7/tests/interface/bridge.xml~	2009-10-14 05:09:05.000000000 +0200
@@ -2,10 +2,12 @@
   <start mode="onboot"/>
   <mtu size="1500"/>
   <protocol family="ipv4">
-    <ip address="192.168.80.5" prefix="24"/>
+    <dhcp/>
   </protocol>
   <bridge stp="off" delay="0.01">
     <interface type="ethernet" name="eth0">
+      <mac address="ab:bb:cc:dd:ee:ff"/>
     </interface>
+    <interface type="ethernet" name="eth1"/>
   </bridge>
 </interface>
diff -ur netcf-0.1.7.ori//tests/interface/vlan.xml~ netcf-0.1.7/tests/interface/vlan.xml~
--- netcf-0.1.7.ori//tests/interface/vlan.xml~	2010-07-30 06:02:39.000000000 +0200
+++ netcf-0.1.7/tests/interface/vlan.xml~	2010-09-07 18:26:22.000000000 +0200
@@ -1,9 +1,9 @@
-<interface type="vlan" name="eth1.42">
+<interface type="vlan" name="eth0.42">
   <start mode="onboot"/>
   <protocol family="ipv4">
     <dhcp peerdns="no"/>
   </protocol>
   <vlan tag="42">
-    <interface name="eth1"/>
+    <interface name="eth0"/>
   </vlan>
 </interface>