aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--networking/ifupdown.c19
1 files changed, 13 insertions, 6 deletions
diff --git a/networking/ifupdown.c b/networking/ifupdown.c
index 818048284..0f0857cb4 100644
--- a/networking/ifupdown.c
+++ b/networking/ifupdown.c
@@ -743,7 +743,7 @@ static const struct method_t *get_method(const struct address_family_t *af, char
743 return NULL; 743 return NULL;
744} 744}
745 745
746static struct interfaces_file_t *read_interfaces(const char *filename) 746static struct interfaces_file_t *read_interfaces(const char *filename, struct interfaces_file_t *defn)
747{ 747{
748 /* Let's try to be compatible. 748 /* Let's try to be compatible.
749 * 749 *
@@ -758,19 +758,25 @@ static struct interfaces_file_t *read_interfaces(const char *filename)
758 * be ignored. Blank lines are ignored. Lines may be indented freely. 758 * be ignored. Blank lines are ignored. Lines may be indented freely.
759 * A "\" character at the very end of the line indicates the next line 759 * A "\" character at the very end of the line indicates the next line
760 * should be treated as a continuation of the current one. 760 * should be treated as a continuation of the current one.
761 *
762 * Lines beginning with "source" are used to include stanzas from
763 * other files, so configuration can be split into many files.
764 * The word "source" is followed by the path of file to be sourced.
761 */ 765 */
762#if ENABLE_FEATURE_IFUPDOWN_MAPPING 766#if ENABLE_FEATURE_IFUPDOWN_MAPPING
763 struct mapping_defn_t *currmap = NULL; 767 struct mapping_defn_t *currmap = NULL;
764#endif 768#endif
765 struct interface_defn_t *currif = NULL; 769 struct interface_defn_t *currif = NULL;
766 struct interfaces_file_t *defn;
767 FILE *f; 770 FILE *f;
768 char *buf; 771 char *buf;
769 char *first_word; 772 char *first_word;
770 char *rest_of_line; 773 char *rest_of_line;
771 enum { NONE, IFACE, MAPPING } currently_processing = NONE; 774 enum { NONE, IFACE, MAPPING } currently_processing = NONE;
772 775
773 defn = xzalloc(sizeof(*defn)); 776 if (!defn)
777 defn = xzalloc(sizeof(*defn));
778
779 debug_noise("reading %s file:\n", filename);
774 f = xfopen_for_read(filename); 780 f = xfopen_for_read(filename);
775 781
776 while ((buf = xmalloc_fgetline(f)) != NULL) { 782 while ((buf = xmalloc_fgetline(f)) != NULL) {
@@ -881,6 +887,8 @@ static struct interfaces_file_t *read_interfaces(const char *filename)
881 debug_noise("\nauto %s\n", first_word); 887 debug_noise("\nauto %s\n", first_word);
882 } 888 }
883 currently_processing = NONE; 889 currently_processing = NONE;
890 } else if (strcmp(first_word, "source") == 0) {
891 read_interfaces(next_word(&rest_of_line), defn);
884 } else { 892 } else {
885 switch (currently_processing) { 893 switch (currently_processing) {
886 case IFACE: 894 case IFACE:
@@ -934,6 +942,7 @@ static struct interfaces_file_t *read_interfaces(const char *filename)
934 bb_error_msg_and_die("%s: I/O error", filename); 942 bb_error_msg_and_die("%s: I/O error", filename);
935 } 943 }
936 fclose(f); 944 fclose(f);
945 debug_noise("\ndone reading %s\n\n", filename);
937 946
938 return defn; 947 return defn;
939} 948}
@@ -1199,9 +1208,7 @@ int ifupdown_main(int argc UNUSED_PARAM, char **argv)
1199 if (!DO_ALL) bb_show_usage(); 1208 if (!DO_ALL) bb_show_usage();
1200 } 1209 }
1201 1210
1202 debug_noise("reading %s file:\n", interfaces); 1211 defn = read_interfaces(interfaces, NULL);
1203 defn = read_interfaces(interfaces);
1204 debug_noise("\ndone reading %s\n\n", interfaces);
1205 1212
1206 /* Create a list of interfaces to work on */ 1213 /* Create a list of interfaces to work on */
1207 if (DO_ALL) { 1214 if (DO_ALL) {