#define EUNDEFVAR 10002
#define EUNBALPER 10000
-#ifdef CONFIG_FEATURE_IFUPDOWN_MAPPING
+#if ENABLE_FEATURE_IFUPDOWN_MAPPING
#define MAX_INTERFACE_LENGTH 10
#endif
-#define debug_noise(fmt, args...)
+#define debug_noise(args...) /*fprintf(stderr, args)*/
/* Forward declaration */
struct interface_defn_t;
#if ENABLE_FEATURE_IFUPDOWN_IPV4 || ENABLE_FEATURE_IFUPDOWN_IPV6
-#ifdef CONFIG_FEATURE_IFUPDOWN_IP
+#if ENABLE_FEATURE_IFUPDOWN_IP
static unsigned count_bits(unsigned a)
{
static char *parse(const char *command, struct interface_defn_t *ifd)
{
- char *result = NULL;
size_t old_pos[MAX_OPT_DEPTH] = { 0 };
int okay[MAX_OPT_DEPTH] = { 1 };
int opt_depth = 1;
+ char *result = xstrdup("");
while (*command) {
switch (*command) {
if (varvalue) {
addstr(&result, varvalue, strlen(varvalue));
} else {
-#ifdef CONFIG_FEATURE_IFUPDOWN_IP
+#if ENABLE_FEATURE_IFUPDOWN_IP
/* Sigh... Add a special case for 'ip' to convert from
* dotted quad to bit count style netmasks. */
- if (strncmp(command, "bnmask", 6)==0) {
+ if (strncmp(command, "bnmask", 6) == 0) {
unsigned res;
varvalue = get_var("netmask", 7, ifd);
if (varvalue && (res = count_netmask_bits(varvalue)) > 0) {
int ret;
out = parse(command, ifd);
- if (!out) {
+ if (!out || !out[0]) {
return 0;
}
ret = (*exec)(out);
}
#endif
-#ifdef CONFIG_FEATURE_IFUPDOWN_IPV6
+#if ENABLE_FEATURE_IFUPDOWN_IPV6
static int loopback_up6(struct interface_defn_t *ifd, execfn *exec)
{
-#ifdef CONFIG_FEATURE_IFUPDOWN_IP
+#if ENABLE_FEATURE_IFUPDOWN_IP
int result;
result = execute("ip addr add ::1 dev %iface%", ifd, exec);
result += execute("ip link set %iface% up", ifd, exec);
static int loopback_down6(struct interface_defn_t *ifd, execfn *exec)
{
-#ifdef CONFIG_FEATURE_IFUPDOWN_IP
+#if ENABLE_FEATURE_IFUPDOWN_IP
return execute("ip link set %iface% down", ifd, exec);
#else
return execute("ifconfig %iface% del ::1", ifd, exec);
static int static_up6(struct interface_defn_t *ifd, execfn *exec)
{
int result;
-#ifdef CONFIG_FEATURE_IFUPDOWN_IP
- result = execute("ip addr add %address%/%netmask% dev %iface% [[label %label%]]", ifd, exec);
- result += execute("ip link set [[mtu %mtu%]] [[address %hwaddress%]] %iface% up", ifd, exec);
- result += execute("[[ ip route add ::/0 via %gateway% ]]", ifd, exec);
+#if ENABLE_FEATURE_IFUPDOWN_IP
+ result = execute("ip addr add %address%/%netmask% dev %iface%[[ label %label%]]", ifd, exec);
+ result += execute("ip link set[[ mtu %mtu%]][[ address %hwaddress%]] %iface% up", ifd, exec);
+ /* Was: "[[ ip ....%gateway% ]]". Removed extra spaces w/o checking */
+ result += execute("[[ip route add ::/0 via %gateway%]]", ifd, exec);
#else
- result = execute("ifconfig %iface% [[media %media%]] [[hw %hwaddress%]] [[mtu %mtu%]] up", ifd, exec);
+ result = execute("ifconfig %iface%[[ media %media%]][[ hw %hwaddress%]][[ mtu %mtu%]] up", ifd, exec);
result += execute("ifconfig %iface% add %address%/%netmask%", ifd, exec);
- result += execute("[[ route -A inet6 add ::/0 gw %gateway% ]]", ifd, exec);
+ result += execute("[[route -A inet6 add ::/0 gw %gateway%]]", ifd, exec);
#endif
return ((result == 3) ? 3 : 0);
}
static int static_down6(struct interface_defn_t *ifd, execfn *exec)
{
-#ifdef CONFIG_FEATURE_IFUPDOWN_IP
+#if ENABLE_FEATURE_IFUPDOWN_IP
return execute("ip link set %iface% down", ifd, exec);
#else
return execute("ifconfig %iface% down", ifd, exec);
#endif
}
-#ifdef CONFIG_FEATURE_IFUPDOWN_IP
+#if ENABLE_FEATURE_IFUPDOWN_IP
static int v4tunnel_up(struct interface_defn_t *ifd, execfn *exec)
{
int result;
result = execute("ip tunnel add %iface% mode sit remote "
- "%endpoint% [[local %local%]] [[ttl %ttl%]]", ifd, exec);
+ "%endpoint%[[ local %local%]][[ ttl %ttl%]]", ifd, exec);
result += execute("ip link set %iface% up", ifd, exec);
result += execute("ip addr add %address%/%netmask% dev %iface%", ifd, exec);
- result += execute("[[ ip route add ::/0 via %gateway% ]]", ifd, exec);
+ result += execute("[[ip route add ::/0 via %gateway%]]", ifd, exec);
return ((result == 4) ? 4 : 0);
}
#endif
static const struct method_t methods6[] = {
-#ifdef CONFIG_FEATURE_IFUPDOWN_IP
+#if ENABLE_FEATURE_IFUPDOWN_IP
{ "v4tunnel", v4tunnel_up, v4tunnel_down, },
#endif
{ "static", static_up6, static_down6, },
sizeof(methods6) / sizeof(struct method_t),
methods6
};
-#endif /* CONFIG_FEATURE_IFUPDOWN_IPV6 */
+#endif /* FEATURE_IFUPDOWN_IPV6 */
-#ifdef CONFIG_FEATURE_IFUPDOWN_IPV4
+#if ENABLE_FEATURE_IFUPDOWN_IPV4
static int loopback_up(struct interface_defn_t *ifd, execfn *exec)
{
-#ifdef CONFIG_FEATURE_IFUPDOWN_IP
+#if ENABLE_FEATURE_IFUPDOWN_IP
int result;
result = execute("ip addr add 127.0.0.1/8 dev %iface%", ifd, exec);
result += execute("ip link set %iface% up", ifd, exec);
static int loopback_down(struct interface_defn_t *ifd, execfn *exec)
{
-#ifdef CONFIG_FEATURE_IFUPDOWN_IP
+#if ENABLE_FEATURE_IFUPDOWN_IP
int result;
result = execute("ip addr flush dev %iface%", ifd, exec);
result += execute("ip link set %iface% down", ifd, exec);
static int static_up(struct interface_defn_t *ifd, execfn *exec)
{
int result;
-#ifdef CONFIG_FEATURE_IFUPDOWN_IP
- result = execute("ip addr add %address%/%bnmask% [[broadcast %broadcast%]] "
- "dev %iface% [[peer %pointopoint%]] [[label %label%]]", ifd, exec);
- result += execute("ip link set [[mtu %mtu%]] [[address %hwaddress%]] %iface% up", ifd, exec);
- result += execute("[[ ip route add default via %gateway% dev %iface% ]]", ifd, exec);
+#if ENABLE_FEATURE_IFUPDOWN_IP
+ result = execute("ip addr add %address%/%bnmask%[[ broadcast %broadcast%]] "
+ "dev %iface%[[ peer %pointopoint%]][[ label %label%]]", ifd, exec);
+ result += execute("ip link set[[ mtu %mtu%]][[ address %hwaddress%]] %iface% up", ifd, exec);
+ result += execute("[[ip route add default via %gateway% dev %iface%]]", ifd, exec);
return ((result == 3) ? 3 : 0);
#else
/* ifconfig said to set iface up before it processes hw %hwaddress%,
* which then of course fails. Thus we run two separate ifconfig */
- result = execute("ifconfig %iface% [[hw %hwaddress%]] [[media %media%]] [[mtu %mtu%]] up",
+ result = execute("ifconfig %iface%[[ hw %hwaddress%]][[ media %media%]][[ mtu %mtu%]] up",
ifd, exec);
- result += execute("ifconfig %iface% %address% netmask %netmask% "
- "[[broadcast %broadcast%]] [[pointopoint %pointopoint%]] ",
+ result += execute("ifconfig %iface% %address% netmask %netmask%"
+ "[[ broadcast %broadcast%]][[ pointopoint %pointopoint%]] ",
ifd, exec);
- result += execute("[[ route add default gw %gateway% %iface% ]]", ifd, exec);
+ result += execute("[[route add default gw %gateway% %iface%]]", ifd, exec);
return ((result == 3) ? 3 : 0);
#endif
}
static int static_down(struct interface_defn_t *ifd, execfn *exec)
{
int result;
-#ifdef CONFIG_FEATURE_IFUPDOWN_IP
+#if ENABLE_FEATURE_IFUPDOWN_IP
result = execute("ip addr flush dev %iface%", ifd, exec);
result += execute("ip link set %iface% down", ifd, exec);
#else
- result = execute("[[ route del default gw %gateway% %iface% ]]", ifd, exec);
+ result = execute("[[route del default gw %gateway% %iface%]]", ifd, exec);
result += execute("ifconfig %iface% down", ifd, exec);
#endif
return ((result == 2) ? 2 : 0);
}
-#ifndef CONFIG_APP_UDHCPC
+#if !ENABLE_APP_UDHCPC
struct dhcp_client_t
{
const char *name;
static const struct dhcp_client_t ext_dhcp_clients[] = {
{ "udhcpc",
- "udhcpc -R -n -p /var/run/udhcpc.%iface%.pid -i %iface% [[-H %hostname%]] [[-c %clientid%]] [[-s %script%]]",
+ "udhcpc -R -n -p /var/run/udhcpc.%iface%.pid -i %iface%[[ -H %hostname%]][[ -c %clientid%]][[ -s %script%]]",
"kill -TERM `cat /var/run/udhcpc.%iface%.pid` 2>/dev/null",
},
{ "pump",
- "pump -i %iface% [[-h %hostname%]] [[-l %leasehours%]]",
+ "pump -i %iface%[[ -h %hostname%]][[ -l %leasehours%]]",
"pump -i %iface% -k",
},
{ "dhclient",
"kill -9 `cat /var/run/dhclient.%iface%.pid` 2>/dev/null",
},
{ "dhcpcd",
- "dhcpcd [[-h %hostname%]] [[-i %vendor%]] [[-I %clientid%]] [[-l %leasetime%]] %iface%",
+ "dhcpcd[[ -h %hostname%]][[ -i %vendor%]][[ -I %clientid%]][[ -l %leasetime%]] %iface%",
"dhcpcd -k %iface%",
},
};
static int dhcp_up(struct interface_defn_t *ifd, execfn *exec)
{
-#ifdef CONFIG_APP_UDHCPC
+#if ENABLE_APP_UDHCPC
return execute("udhcpc -R -n -p /var/run/udhcpc.%iface%.pid "
- "-i %iface% [[-H %hostname%]] [[-c %clientid%]] [[-s %script%]]",
+ "-i %iface%[[ -H %hostname%]][[ -c %clientid%]][[ -s %script%]]",
ifd, exec);
#else
int i, nclients = sizeof(ext_dhcp_clients) / sizeof(ext_dhcp_clients[0]);
static int dhcp_down(struct interface_defn_t *ifd, execfn *exec)
{
-#ifdef CONFIG_APP_UDHCPC
+#if ENABLE_APP_UDHCPC
return execute("kill -TERM "
"`cat /var/run/udhcpc.%iface%.pid` 2>/dev/null", ifd, exec);
#else
static int bootp_up(struct interface_defn_t *ifd, execfn *exec)
{
- return execute("bootpc [[--bootfile %bootfile%]] --dev %iface% "
- "[[--server %server%]] [[--hwaddr %hwaddr%]] "
+ return execute("bootpc[[ --bootfile %bootfile%]] --dev %iface%"
+ "[[ --server %server%]][[ --hwaddr %hwaddr%]] "
"--returniffail --serverbcast", ifd, exec);
}
static int ppp_up(struct interface_defn_t *ifd, execfn *exec)
{
- return execute("pon [[%provider%]]", ifd, exec);
+ return execute("pon[[ %provider%]]", ifd, exec);
}
static int ppp_down(struct interface_defn_t *ifd, execfn *exec)
{
- return execute("poff [[%provider%]]", ifd, exec);
+ return execute("poff[[ %provider%]]", ifd, exec);
}
static int wvdial_up(struct interface_defn_t *ifd, execfn *exec)
{
- return execute("/sbin/start-stop-daemon --start -x /usr/bin/wvdial "
- "-p /var/run/wvdial.%iface% -b -m -- [[ %provider% ]]", ifd, exec);
+ return execute("start-stop-daemon --start -x wvdial "
+ "-p /var/run/wvdial.%iface% -b -m --[[ %provider%]]", ifd, exec);
}
static int wvdial_down(struct interface_defn_t *ifd, execfn *exec)
{
- return execute("/sbin/start-stop-daemon --stop -x /usr/bin/wvdial "
+ return execute("start-stop-daemon --stop -x wvdial "
"-p /var/run/wvdial.%iface% -s 2", ifd, exec);
}
methods
};
-#endif /* ifdef CONFIG_FEATURE_IFUPDOWN_IPV4 */
+#endif /* if ENABLE_FEATURE_IFUPDOWN_IPV4 */
static char *next_word(char **buf)
{
static struct interfaces_file_t *read_interfaces(const char *filename)
{
-#ifdef CONFIG_FEATURE_IFUPDOWN_MAPPING
+#if ENABLE_FEATURE_IFUPDOWN_MAPPING
struct mapping_defn_t *currmap = NULL;
#endif
struct interface_defn_t *currif = NULL;
}
if (strcmp(firstword, "mapping") == 0) {
-#ifdef CONFIG_FEATURE_IFUPDOWN_MAPPING
+#if ENABLE_FEATURE_IFUPDOWN_MAPPING
currmap = xzalloc(sizeof(struct mapping_defn_t));
while ((firstword = next_word(&buf_ptr)) != NULL) {
currently_processing = MAPPING;
} else if (strcmp(firstword, "iface") == 0) {
static const struct address_family_t *const addr_fams[] = {
-#ifdef CONFIG_FEATURE_IFUPDOWN_IPV4
+#if ENABLE_FEATURE_IFUPDOWN_IPV4
&addr_inet,
#endif
-#ifdef CONFIG_FEATURE_IFUPDOWN_IPV6
+#if ENABLE_FEATURE_IFUPDOWN_IPV6
&addr_inet6,
#endif
NULL
currif->n_options++;
break;
case MAPPING:
-#ifdef CONFIG_FEATURE_IFUPDOWN_MAPPING
+#if ENABLE_FEATURE_IFUPDOWN_MAPPING
if (strcmp(firstword, "script") == 0) {
if (currmap->script != NULL) {
bb_error_msg("duplicate script in mapping \"%s\"", buf);
fflush(NULL);
switch (child = fork()) {
- case -1: /* failure */
+ case -1: /* failure */
return 0;
- case 0: /* child */
+ case 0: /* child */
execle(DEFAULT_SHELL, DEFAULT_SHELL, "-c", str, NULL, __myenviron);
exit(127);
}
return 1;
}
-static int check(char *str) {
+static int check(char *str)
+{
return str != NULL;
}
static int iface_up(struct interface_defn_t *iface)
{
- if (!iface->method->up(iface,check)) return -1;
+ if (!iface->method->up(iface, check)) return -1;
set_environ(iface, "start");
if (!execute_all(iface, "pre-up")) return 0;
if (!iface->method->up(iface, doit)) return 0;
return 1;
}
-#ifdef CONFIG_FEATURE_IFUPDOWN_MAPPING
+#if ENABLE_FEATURE_IFUPDOWN_MAPPING
static int popen2(FILE **in, FILE **out, char *command, ...)
{
va_list ap;
return logical;
}
-#endif /* CONFIG_FEATURE_IFUPDOWN_MAPPING */
+#endif /* FEATURE_IFUPDOWN_MAPPING */
static llist_t *find_iface_state(llist_t *state_list, const char *iface)
{
int ifupdown_main(int argc, char **argv)
{
- static const char statefile[] = "/var/run/ifstate";
-
int (*cmds)(struct interface_defn_t *) = NULL;
struct interfaces_file_t *defn;
llist_t *state_list = NULL;
const char *interfaces = "/etc/network/interfaces";
int any_failures = 0;
+ cmds = iface_down;
if (applet_name[2] == 'u') {
/* ifup command */
cmds = iface_up;
- } else {
- /* ifdown command */
- cmds = iface_down;
}
getopt32(argc, argv, OPTION_STR, &interfaces);
if (argc - optind > 0) {
if (DO_ALL) bb_show_usage();
- } else
+ } else {
if (!DO_ALL) bb_show_usage();
+ }
debug_noise("reading %s file:\n", interfaces);
defn = read_interfaces(interfaces);
debug_noise("\ndone reading %s\n\n", interfaces);
if (!defn) {
- exit(EXIT_FAILURE);
+ return EXIT_FAILURE;
}
startup_PATH = getenv("PATH");
}
}
-#ifdef CONFIG_FEATURE_IFUPDOWN_MAPPING
+#if ENABLE_FEATURE_IFUPDOWN_MAPPING
if ((cmds == iface_up) && !NO_MAPPINGS) {
struct mapping_defn_t *currmap;
}
#endif
-
iface_list = defn->ifaces;
while (iface_list) {
currif = (struct interface_defn_t *) iface_list->data;
okay = 1;
currif->iface = iface;
- debug_noise("\nConfiguring interface %s (%s)\n", liface, currif->address_family->name);
+ debug_noise("\nZ Configuring interface %s (%s)\n", liface, currif->address_family->name);
/* Call the cmds function pointer, does either iface_up() or iface_down() */
cmds_ret = cmds(currif);
if (cmds_ret == -1) {
bb_error_msg("don't seem to have all the variables for %s/%s",
liface, currif->address_family->name);
- any_failures += 1;
+ any_failures = 1;
} else if (cmds_ret == 0) {
- any_failures += 1;
+ any_failures = 1;
}
currif->iface = oldiface;
if (!okay && !FORCE) {
bb_error_msg("ignoring unknown interface %s", liface);
- any_failures += 1;
+ any_failures = 1;
} else {
llist_t *iface_state = find_iface_state(state_list, iface);
/* Actually write the new state */
if (!NO_ACT) {
- FILE *state_fp = NULL;
+ FILE *state_fp;
- state_fp = xfopen(statefile, "w");
+ state_fp = xfopen("/var/run/ifstate", "w");
while (state_list) {
if (state_list->data) {
fputs(state_list->data, state_fp);
fclose(state_fp);
}
- if (any_failures)
- return 1;
- return 0;
+ return any_failures;
}