aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--networking/ifupdown.c42
1 files changed, 15 insertions, 27 deletions
diff --git a/networking/ifupdown.c b/networking/ifupdown.c
index abc6b5813..5946323d0 100644
--- a/networking/ifupdown.c
+++ b/networking/ifupdown.c
@@ -87,7 +87,6 @@ struct mapping_defn_t {
87 87
88 char *script; 88 char *script;
89 89
90 int max_mappings;
91 int n_mappings; 90 int n_mappings;
92 char **mapping; 91 char **mapping;
93}; 92};
@@ -102,7 +101,6 @@ struct interface_defn_t {
102 const struct method_t *method; 101 const struct method_t *method;
103 102
104 char *iface; 103 char *iface;
105 int max_options;
106 int n_options; 104 int n_options;
107 struct variable_t *option; 105 struct variable_t *option;
108}; 106};
@@ -138,6 +136,16 @@ struct globals {
138#define INIT_G() do { } while (0) 136#define INIT_G() do { } while (0)
139 137
140 138
139static const char keywords_up_down[] ALIGN1 =
140 "up\0"
141 "down\0"
142 "pre-up\0"
143 "pre-down\0"
144 "post-up\0"
145 "post-down\0"
146;
147
148
141#if ENABLE_FEATURE_IFUPDOWN_IPV4 || ENABLE_FEATURE_IFUPDOWN_IPV6 149#if ENABLE_FEATURE_IFUPDOWN_IPV4 || ENABLE_FEATURE_IFUPDOWN_IPV6
142 150
143static void addstr(char **bufp, const char *str, size_t str_length) 151static void addstr(char **bufp, const char *str, size_t str_length)
@@ -803,7 +811,6 @@ static struct interfaces_file_t *read_interfaces(const char *filename)
803 currmap->match = xrealloc_vector(currmap->match, 4, currmap->n_matches); 811 currmap->match = xrealloc_vector(currmap->match, 4, currmap->n_matches);
804 currmap->match[currmap->n_matches++] = xstrdup(first_word); 812 currmap->match[currmap->n_matches++] = xstrdup(first_word);
805 } 813 }
806 /*currmap->max_mappings = 0; - done by xzalloc */
807 /*currmap->n_mappings = 0;*/ 814 /*currmap->n_mappings = 0;*/
808 /*currmap->mapping = NULL;*/ 815 /*currmap->mapping = NULL;*/
809 /*currmap->script = NULL;*/ 816 /*currmap->script = NULL;*/
@@ -888,25 +895,16 @@ static struct interfaces_file_t *read_interfaces(const char *filename)
888 if (rest_of_line[0] == '\0') 895 if (rest_of_line[0] == '\0')
889 bb_error_msg_and_die("option with empty value \"%s\"", buf); 896 bb_error_msg_and_die("option with empty value \"%s\"", buf);
890 897
891 if (strcmp(first_word, "up") != 0 898 /* If not one of "up", "down",... words... */
892 && strcmp(first_word, "down") != 0 899 if (index_in_strings(keywords_up_down, first_word) < 0) {
893 && strcmp(first_word, "pre-up") != 0
894 && strcmp(first_word, "pre-down") != 0
895 && strcmp(first_word, "post-up") != 0
896 && strcmp(first_word, "post-down") != 0
897 ) {
898 int i; 900 int i;
899 for (i = 0; i < currif->n_options; i++) { 901 for (i = 0; i < currif->n_options; i++) {
900 if (strcmp(currif->option[i].name, first_word) == 0) 902 if (strcmp(currif->option[i].name, first_word) == 0)
901 bb_error_msg_and_die("duplicate option \"%s\"", buf); 903 bb_error_msg_and_die("duplicate option \"%s\"", buf);
902 } 904 }
903 } 905 }
904 if (currif->n_options >= currif->max_options) {
905 currif->max_options += 10;
906 currif->option = xrealloc(currif->option,
907 sizeof(*currif->option) * currif->max_options);
908 }
909 debug_noise("\t%s=%s\n", first_word, rest_of_line); 906 debug_noise("\t%s=%s\n", first_word, rest_of_line);
907 currif->option = xrealloc_vector(currif->option, 4, currif->n_options);
910 currif->option[currif->n_options].name = xstrdup(first_word); 908 currif->option[currif->n_options].name = xstrdup(first_word);
911 currif->option[currif->n_options].value = xstrdup(rest_of_line); 909 currif->option[currif->n_options].value = xstrdup(rest_of_line);
912 currif->n_options++; 910 currif->n_options++;
@@ -918,11 +916,7 @@ static struct interfaces_file_t *read_interfaces(const char *filename)
918 bb_error_msg_and_die("duplicate script in mapping \"%s\"", buf); 916 bb_error_msg_and_die("duplicate script in mapping \"%s\"", buf);
919 currmap->script = xstrdup(next_word(&rest_of_line)); 917 currmap->script = xstrdup(next_word(&rest_of_line));
920 } else if (strcmp(first_word, "map") == 0) { 918 } else if (strcmp(first_word, "map") == 0) {
921 if (currmap->n_mappings >= currmap->max_mappings) { 919 currmap->mapping = xrealloc_vector(currmap->mapping, 2, currmap->n_mappings);
922 currmap->max_mappings = currmap->max_mappings * 2 + 1;
923 currmap->mapping = xrealloc(currmap->mapping,
924 sizeof(char *) * currmap->max_mappings);
925 }
926 currmap->mapping[currmap->n_mappings] = xstrdup(next_word(&rest_of_line)); 920 currmap->mapping[currmap->n_mappings] = xstrdup(next_word(&rest_of_line));
927 currmap->n_mappings++; 921 currmap->n_mappings++;
928 } else { 922 } else {
@@ -986,13 +980,7 @@ static void set_environ(struct interface_defn_t *iface, const char *mode)
986 pp = G.my_environ; 980 pp = G.my_environ;
987 981
988 for (i = 0; i < iface->n_options; i++) { 982 for (i = 0; i < iface->n_options; i++) {
989 if (strcmp(iface->option[i].name, "up") == 0 983 if (index_in_strings(keywords_up_down, iface->option[i].name) >= 0) {
990 || strcmp(iface->option[i].name, "down") == 0
991 || strcmp(iface->option[i].name, "pre-up") == 0
992 || strcmp(iface->option[i].name, "pre-down") == 0
993 || strcmp(iface->option[i].name, "post-up") == 0
994 || strcmp(iface->option[i].name, "post-down") == 0
995 ) {
996 continue; 984 continue;
997 } 985 }
998 *pp++ = setlocalenv("IF_%s=%s", iface->option[i].name, iface->option[i].value); 986 *pp++ = setlocalenv("IF_%s=%s", iface->option[i].name, iface->option[i].value);