Hello. This is the updated version of the patch above, supporting glob-like wildcards, tilde expansion and environment variable expansion as per wordexp(3).
The syntax is still the same: source /etc/network/interfaces.d/* -- WBR, Andrew
diff -pu ifupdown-0.7~alpha3.orig/ifupdown.nw ifupdown-0.7~alpha3/ifupdown.nw
--- ifupdown-0.7~alpha3.orig/ifupdown.nw 2007-12-21 16:22:19.000000000 +0200
+++ ifupdown-0.7~alpha3/ifupdown.nw 2010-10-02 16:12:20.000000000 +0300
@@ -1233,14 +1233,20 @@ helpful error message. Pretty simple, he
<<exported symbols>>=
interfaces_file *read_interfaces(char *filename);
+interfaces_file *read_interfaces_defn(interfaces_file *defn, char *filename);
@
<<config functions>>=
interfaces_file *read_interfaces(char *filename) {
- <<variables local to read interfaces>>
interfaces_file *defn;
<<allocate defn or [[return NULL]]>>
+ return read_interfaces_defn(defn, filename);
+}
+
+interfaces_file *read_interfaces_defn(interfaces_file *defn, char *filename) {
+ <<variables local to read interfaces>>
+
<<open file or [[return NULL]]>>
while (<<we've gotten a line from the file>>) {
@@ -1562,6 +1568,9 @@ if (rest == NULL) continue; /* blank lin
if (strcmp(firstword, "mapping") == 0) {
<<process [[mapping]] line>>
currently_processing = MAPPING;
+} else if (strcmp(firstword, "source") == 0) {
+ <<process [[source]] line>>
+ currently_processing = NONE;
} else if (strcmp(firstword, "iface") == 0) {
<<process [[iface]] line>>
currently_processing = IFACE;
@@ -1590,6 +1599,37 @@ switch(currently_processing) {
}
@
+\subsubsection{Source Line}
+
+% To source another file, we just call [[read_interfaces_defn]] again.
+
+When processing the [[source]] stanza, we use [[wordexp]] function to expand wildcards
+and environment variables.
+
+<<config headers>>=
+#include <wordexp.h>
+@
+
+We use [[WRDE_NOCMD]] flag, so no command substitution occurs
+because of security concerns. Then we go through the output array and read interfaces
+recursively into already allocated [[defn]].
+
+<<process [[source]] line>>=
+wordexp_t p;
+char ** w;
+int i;
+int fail = wordexp(rest, &p, WRDE_NOCMD);
+if (!fail)
+{
+ w = p.we_wordv;
+ for (i = 0; i < p.we_wordc; i++)
+ {
+ read_interfaces_defn(defn, w[i]);
+ }
+ wordfree(&p);
+}
+@
+
\subsubsection{Mapping Line}
Declaring a new mapping is reasonably copewithable --- we need to process
diff -pu ifupdown-0.7~alpha3.orig/interfaces.5.pre ifupdown-0.7~alpha3/interfaces.5.pre
--- ifupdown-0.7~alpha3.orig/interfaces.5.pre 2007-12-21 15:30:54.000000000 +0200
+++ ifupdown-0.7~alpha3/interfaces.5.pre 2010-10-02 16:20:59.000000000 +0300
@@ -29,14 +29,16 @@ NOT supported, comments must be on a lin
A line may be extended across multiple lines by making the last character
a backslash.
.P
-The file consists of zero or more "iface", "mapping", "auto" and "allow-"
-stanzas. Here is an example.
+The file consists of zero or more "iface", "mapping", "auto", "allow-" and
+"source" stanzas. Here is an example.
.EX
auto lo eth0
allow-hotplug eth1
iface lo inet loopback
+source interfaces.d/machine\-dependent
+
mapping eth0
script /usr/local/sbin/map\-scheme
map HOME eth0\-home
@@ -68,6 +70,14 @@ a command such as "ifup \-\-allow=hotplu
up eth0 or eth1 if it is listed in an "allow-hotplug" line. Note that
"allow-auto" and "auto" are synonyms.
.P
+Lines beginning with "source" are used to include stanzas from other files,
+so configuration can be split into many files. The word "source" is
+followed by the path of file to be sourced. Shell wildcards can be
+used.
+(See
+.BR wordexp (3)
+for details.)
+.P
Stanzas beginning with the word "mapping" are used to determine how a
logical interface name is chosen for a physical interface that is to be
brought up. The first line of a mapping stanza consists of the word
signature.asc
Description: This is a digitally signed message part.

