aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGlenn L McGrath <bug1@ihug.co.nz>2002-11-10 13:17:08 +0000
committerGlenn L McGrath <bug1@ihug.co.nz>2002-11-10 13:17:08 +0000
commit49a28b3b5ea56468e2f12305e3a37679b397b337 (patch)
treeeea3eca7832910cb500c6637ec3dc1c863144587
parent8ae75013c8ddbbbbd82e539e0463086ffa442b40 (diff)
downloadbusybox-w32-49a28b3b5ea56468e2f12305e3a37679b397b337.tar.gz
busybox-w32-49a28b3b5ea56468e2f12305e3a37679b397b337.tar.bz2
busybox-w32-49a28b3b5ea56468e2f12305e3a37679b397b337.zip
Make mapping support a definable feature, saves 1.6kB
-rw-r--r--networking/config.in1
-rw-r--r--networking/ifupdown.c70
2 files changed, 40 insertions, 31 deletions
diff --git a/networking/config.in b/networking/config.in
index fe714fe0c..7393febae 100644
--- a/networking/config.in
+++ b/networking/config.in
@@ -21,6 +21,7 @@ if [ "$CONFIG_IFUPDOWN" = "y" ]; then
21 bool ' Enable support for IPv4' CONFIG_FEATURE_IFUPDOWN_IPV4 21 bool ' Enable support for IPv4' CONFIG_FEATURE_IFUPDOWN_IPV4
22 bool ' Enable support for IPv6 (requires ip command)' CONFIG_FEATURE_IFUPDOWN_IPV6 22 bool ' Enable support for IPv6 (requires ip command)' CONFIG_FEATURE_IFUPDOWN_IPV6
23 bool ' Enable support for IPX (requires ipx_interface command)' CONFIG_FEATURE_IFUPDOWN_IPX 23 bool ' Enable support for IPX (requires ipx_interface command)' CONFIG_FEATURE_IFUPDOWN_IPX
24 bool ' Mapping support' CONFIG_FEATURE_IFUPDOWN_MAPPING
24fi 25fi
25bool 'ip' CONFIG_IP 26bool 'ip' CONFIG_IP
26if [ "$CONFIG_IP" = "y" ]; then 27if [ "$CONFIG_IP" = "y" ]; then
diff --git a/networking/ifupdown.c b/networking/ifupdown.c
index f56842dc7..392bdf04d 100644
--- a/networking/ifupdown.c
+++ b/networking/ifupdown.c
@@ -57,6 +57,7 @@ typedef struct address_family {
57 method *method; 57 method *method;
58} address_family; 58} address_family;
59 59
60#ifdef CONFIG_FEATURE_IFUPDOWN_MAPPING
60typedef struct mapping_defn { 61typedef struct mapping_defn {
61 struct mapping_defn *next; 62 struct mapping_defn *next;
62 63
@@ -70,6 +71,7 @@ typedef struct mapping_defn {
70 int n_mappings; 71 int n_mappings;
71 char **mapping; 72 char **mapping;
72} mapping_defn; 73} mapping_defn;
74#endif
73 75
74typedef struct variable { 76typedef struct variable {
75 char *name; 77 char *name;
@@ -96,7 +98,9 @@ typedef struct interfaces_file {
96 char **autointerfaces; 98 char **autointerfaces;
97 99
98 interface_defn *ifaces; 100 interface_defn *ifaces;
101#ifdef CONFIG_FEATURE_IFUPDOWN_MAPPING
99 mapping_defn *mappings; 102 mapping_defn *mappings;
103#endif
100} interfaces_file; 104} interfaces_file;
101 105
102#define MAX_OPT_DEPTH 10 106#define MAX_OPT_DEPTH 10
@@ -109,17 +113,6 @@ static int no_act = 0;
109static int verbose = 0; 113static int verbose = 0;
110static char **environ = NULL; 114static char **environ = NULL;
111 115
112static int execable(char *program)
113{
114 struct stat buf;
115 if (0 == stat(program, &buf)) {
116 if (S_ISREG(buf.st_mode) && (S_IXUSR & buf.st_mode)) {
117 return(1);
118 }
119 }
120 return(0);
121}
122
123static void addstr(char **buf, size_t *len, size_t *pos, char *str, size_t str_length) 116static void addstr(char **buf, size_t *len, size_t *pos, char *str, size_t str_length)
124{ 117{
125 if (*pos + str_length >= *len) { 118 if (*pos + str_length >= *len) {
@@ -434,6 +427,17 @@ static int static_down(interface_defn *ifd, execfn *exec)
434 return(1); 427 return(1);
435} 428}
436 429
430static int execable(char *program)
431{
432 struct stat buf;
433 if (0 == stat(program, &buf)) {
434 if (S_ISREG(buf.st_mode) && (S_IXUSR & buf.st_mode)) {
435 return(1);
436 }
437 }
438 return(0);
439}
440
437static int dhcp_up(interface_defn *ifd, execfn *exec) 441static int dhcp_up(interface_defn *ifd, execfn *exec)
438{ 442{
439 if (execable("/sbin/dhclient")) { 443 if (execable("/sbin/dhclient")) {
@@ -679,7 +683,9 @@ static interfaces_file *read_interfaces(char *filename)
679{ 683{
680 interface_defn *currif = NULL; 684 interface_defn *currif = NULL;
681 interfaces_file *defn; 685 interfaces_file *defn;
686#ifdef CONFIG_FEATURE_IFUPDOWN_MAPPING
682 mapping_defn *currmap = NULL; 687 mapping_defn *currmap = NULL;
688#endif
683 FILE *f; 689 FILE *f;
684 char firstword[80]; 690 char firstword[80];
685 char *buf = NULL; 691 char *buf = NULL;
@@ -692,7 +698,9 @@ static interfaces_file *read_interfaces(char *filename)
692 defn = xmalloc(sizeof(interfaces_file)); 698 defn = xmalloc(sizeof(interfaces_file));
693 defn->max_autointerfaces = defn->n_autointerfaces = 0; 699 defn->max_autointerfaces = defn->n_autointerfaces = 0;
694 defn->autointerfaces = NULL; 700 defn->autointerfaces = NULL;
701#ifdef CONFIG_FEATURE_IFUPDOWN_MAPPING
695 defn->mappings = NULL; 702 defn->mappings = NULL;
703#endif
696 defn->ifaces = NULL; 704 defn->ifaces = NULL;
697 f = fopen(filename, "r"); 705 f = fopen(filename, "r");
698 if (f == NULL) { 706 if (f == NULL) {
@@ -707,7 +715,7 @@ static interfaces_file *read_interfaces(char *filename)
707 } 715 }
708 716
709 if (strcmp(firstword, "mapping") == 0) { 717 if (strcmp(firstword, "mapping") == 0) {
710 718#if 0
711 currmap = xmalloc(sizeof(mapping_defn)); 719 currmap = xmalloc(sizeof(mapping_defn));
712 currmap->max_matches = 0; 720 currmap->max_matches = 0;
713 currmap->n_matches = 0; 721 currmap->n_matches = 0;
@@ -734,6 +742,7 @@ static interfaces_file *read_interfaces(char *filename)
734 currmap->next = NULL; 742 currmap->next = NULL;
735 } 743 }
736 currently_processing = MAPPING; 744 currently_processing = MAPPING;
745#endif
737 } else if (strcmp(firstword, "iface") == 0) { 746 } else if (strcmp(firstword, "iface") == 0) {
738 { 747 {
739 char iface_name[80]; 748 char iface_name[80];
@@ -871,6 +880,7 @@ static interfaces_file *read_interfaces(char *filename)
871 currif->n_options++; 880 currif->n_options++;
872 break; 881 break;
873 case MAPPING: 882 case MAPPING:
883#ifdef CONFIG_FEATURE_IFUPDOWN_MAPPING
874 if (strcmp(firstword, "script") == 0) { 884 if (strcmp(firstword, "script") == 0) {
875 if (currmap->script != NULL) { 885 if (currmap->script != NULL) {
876 error_msg("%s:%d: duplicate script in mapping", filename, line); 886 error_msg("%s:%d: duplicate script in mapping", filename, line);
@@ -889,6 +899,7 @@ static interfaces_file *read_interfaces(char *filename)
889 error_msg("%s:%d: misplaced option", filename, line); 899 error_msg("%s:%d: misplaced option", filename, line);
890 return NULL; 900 return NULL;
891 } 901 }
902#endif
892 break; 903 break;
893 case NONE: 904 case NONE:
894 default: 905 default:
@@ -1063,6 +1074,7 @@ static int iface_down(interface_defn *iface)
1063 return (1); 1074 return (1);
1064} 1075}
1065 1076
1077#ifdef CONFIG_FEATURE_IFUPDOWN_MAPPING
1066static int popen2(FILE **in, FILE **out, char *command, ...) 1078static int popen2(FILE **in, FILE **out, char *command, ...)
1067{ 1079{
1068 va_list ap; 1080 va_list ap;
@@ -1144,6 +1156,8 @@ static int run_mapping(char *physical, char *logical, int len, mapping_defn * ma
1144 1156
1145 return 1; 1157 return 1;
1146} 1158}
1159#endif /* CONFIG_FEATURE_IFUPDOWN_MAPPING */
1160
1147 1161
1148static int lookfor_iface(char **ifaces, int n_ifaces, char *iface) 1162static int lookfor_iface(char **ifaces, int n_ifaces, char *iface)
1149{ 1163{
@@ -1173,16 +1187,6 @@ static void add_to_state(char ***ifaces, int *n_ifaces, int *max_ifaces, char *n
1173extern int ifupdown_main(int argc, char **argv) 1187extern int ifupdown_main(int argc, char **argv)
1174{ 1188{
1175 int (*cmds) (interface_defn *) = NULL; 1189 int (*cmds) (interface_defn *) = NULL;
1176 struct option long_opts[] = {
1177 {"help", no_argument, NULL, 'h'},
1178 {"verbose", no_argument, NULL, 'v'},
1179 {"all", no_argument, NULL, 'a'},
1180 {"interfaces", required_argument, NULL, 'i'},
1181 {"no-act", no_argument, NULL, 'n'},
1182 {"no-mappings", no_argument, NULL, 1},
1183 {"force", no_argument, NULL, 2},
1184 {0, 0, 0, 0}
1185 };
1186 interfaces_file *defn; 1190 interfaces_file *defn;
1187 FILE *state_fp = NULL; 1191 FILE *state_fp = NULL;
1188 char **target_iface = NULL; 1192 char **target_iface = NULL;
@@ -1191,7 +1195,9 @@ extern int ifupdown_main(int argc, char **argv)
1191 char *statefile = "/etc/network/ifstate"; 1195 char *statefile = "/etc/network/ifstate";
1192 1196
1193 int do_all = 0; 1197 int do_all = 0;
1198#ifdef CONFIG_FEATURE_IFUPDOWN_MAPPING
1194 int run_mappings = 1; 1199 int run_mappings = 1;
1200#endif
1195 int force = 0; 1201 int force = 0;
1196 int n_target_ifaces = 0; 1202 int n_target_ifaces = 0;
1197 int n_state = 0; 1203 int n_state = 0;
@@ -1206,24 +1212,26 @@ extern int ifupdown_main(int argc, char **argv)
1206 cmds = iface_down; 1212 cmds = iface_down;
1207 } 1213 }
1208 1214
1209 while ((i = getopt_long(argc, argv, "i:hvna", long_opts, NULL)) != EOF) { 1215 while ((i = getopt(argc, argv, "i:hvnamf")) != -1) {
1210 switch (i) { 1216 switch (i) {
1211 case 'i': 1217 case 'i': /* interfaces */
1212 interfaces = xstrdup(optarg); 1218 interfaces = xstrdup(optarg);
1213 break; 1219 break;
1214 case 'v': 1220 case 'v': /* verbose */
1215 verbose = 1; 1221 verbose = 1;
1216 break; 1222 break;
1217 case 'a': 1223 case 'a': /* all */
1218 do_all = 1; 1224 do_all = 1;
1219 break; 1225 break;
1220 case 'n': 1226 case 'n': /* no-act */
1221 no_act = 1; 1227 no_act = 1;
1222 break; 1228 break;
1223 case 1: 1229#ifdef CONFIG_FEATURE_IFUPDOWN_MAPPING
1230 case 'm': /* no-mappings */
1224 run_mappings = 0; 1231 run_mappings = 0;
1225 break; 1232 break;
1226 case 2: 1233#endif
1234 case 'f': /* force */
1227 force = 1; 1235 force = 1;
1228 break; 1236 break;
1229 default: 1237 default:
@@ -1346,7 +1354,7 @@ extern int ifupdown_main(int argc, char **argv)
1346 liface[79] = 0; 1354 liface[79] = 0;
1347 } 1355 }
1348 } 1356 }
1349 1357#ifdef CONFIG_FEATURE_IFUPDOWN_MAPPING
1350 if ((cmds == iface_up) && run_mappings) { 1358 if ((cmds == iface_up) && run_mappings) {
1351 mapping_defn *currmap; 1359 mapping_defn *currmap;
1352 1360
@@ -1363,7 +1371,7 @@ extern int ifupdown_main(int argc, char **argv)
1363 } 1371 }
1364 } 1372 }
1365 } 1373 }
1366 1374#endif
1367 1375
1368 for (currif = defn->ifaces; currif; currif = currif->next) { 1376 for (currif = defn->ifaces; currif; currif = currif->next) {
1369 if (strcmp(liface, currif->iface) == 0) { 1377 if (strcmp(liface, currif->iface) == 0) {