aboutsummaryrefslogtreecommitdiff
path: root/networking/ifupdown.c
diff options
context:
space:
mode:
Diffstat (limited to 'networking/ifupdown.c')
-rw-r--r--networking/ifupdown.c40
1 files changed, 17 insertions, 23 deletions
diff --git a/networking/ifupdown.c b/networking/ifupdown.c
index 382033038..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,23 +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, "post-down") != 0
895 ) {
896 int i; 900 int i;
897 for (i = 0; i < currif->n_options; i++) { 901 for (i = 0; i < currif->n_options; i++) {
898 if (strcmp(currif->option[i].name, first_word) == 0) 902 if (strcmp(currif->option[i].name, first_word) == 0)
899 bb_error_msg_and_die("duplicate option \"%s\"", buf); 903 bb_error_msg_and_die("duplicate option \"%s\"", buf);
900 } 904 }
901 } 905 }
902 if (currif->n_options >= currif->max_options) {
903 currif->max_options += 10;
904 currif->option = xrealloc(currif->option,
905 sizeof(*currif->option) * currif->max_options);
906 }
907 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);
908 currif->option[currif->n_options].name = xstrdup(first_word); 908 currif->option[currif->n_options].name = xstrdup(first_word);
909 currif->option[currif->n_options].value = xstrdup(rest_of_line); 909 currif->option[currif->n_options].value = xstrdup(rest_of_line);
910 currif->n_options++; 910 currif->n_options++;
@@ -916,11 +916,7 @@ static struct interfaces_file_t *read_interfaces(const char *filename)
916 bb_error_msg_and_die("duplicate script in mapping \"%s\"", buf); 916 bb_error_msg_and_die("duplicate script in mapping \"%s\"", buf);
917 currmap->script = xstrdup(next_word(&rest_of_line)); 917 currmap->script = xstrdup(next_word(&rest_of_line));
918 } else if (strcmp(first_word, "map") == 0) { 918 } else if (strcmp(first_word, "map") == 0) {
919 if (currmap->n_mappings >= currmap->max_mappings) { 919 currmap->mapping = xrealloc_vector(currmap->mapping, 2, currmap->n_mappings);
920 currmap->max_mappings = currmap->max_mappings * 2 + 1;
921 currmap->mapping = xrealloc(currmap->mapping,
922 sizeof(char *) * currmap->max_mappings);
923 }
924 currmap->mapping[currmap->n_mappings] = xstrdup(next_word(&rest_of_line)); 920 currmap->mapping[currmap->n_mappings] = xstrdup(next_word(&rest_of_line));
925 currmap->n_mappings++; 921 currmap->n_mappings++;
926 } else { 922 } else {
@@ -984,11 +980,7 @@ static void set_environ(struct interface_defn_t *iface, const char *mode)
984 pp = G.my_environ; 980 pp = G.my_environ;
985 981
986 for (i = 0; i < iface->n_options; i++) { 982 for (i = 0; i < iface->n_options; i++) {
987 if (strcmp(iface->option[i].name, "up") == 0 983 if (index_in_strings(keywords_up_down, iface->option[i].name) >= 0) {
988 || strcmp(iface->option[i].name, "down") == 0
989 || strcmp(iface->option[i].name, "pre-up") == 0
990 || strcmp(iface->option[i].name, "post-down") == 0
991 ) {
992 continue; 984 continue;
993 } 985 }
994 *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);
@@ -1056,6 +1048,7 @@ static int iface_up(struct interface_defn_t *iface)
1056 if (!execute_all(iface, "pre-up")) return 0; 1048 if (!execute_all(iface, "pre-up")) return 0;
1057 if (!iface->method->up(iface, doit)) return 0; 1049 if (!iface->method->up(iface, doit)) return 0;
1058 if (!execute_all(iface, "up")) return 0; 1050 if (!execute_all(iface, "up")) return 0;
1051 if (!execute_all(iface, "post-up")) return 0;
1059 return 1; 1052 return 1;
1060} 1053}
1061 1054
@@ -1063,6 +1056,7 @@ static int iface_down(struct interface_defn_t *iface)
1063{ 1056{
1064 if (!iface->method->down(iface,check)) return -1; 1057 if (!iface->method->down(iface,check)) return -1;
1065 set_environ(iface, "stop"); 1058 set_environ(iface, "stop");
1059 if (!execute_all(iface, "pre-down")) return 0;
1066 if (!execute_all(iface, "down")) return 0; 1060 if (!execute_all(iface, "down")) return 0;
1067 if (!iface->method->down(iface, doit)) return 0; 1061 if (!iface->method->down(iface, doit)) return 0;
1068 if (!execute_all(iface, "post-down")) return 0; 1062 if (!execute_all(iface, "post-down")) return 0;