1303 files changed, 32187 insertions, 57138 deletions
diff --git a/networking/ifplugd.c b/networking/ifplugd.c index b578f4c..4f8a274 100644 --- a/networking/ifplugd.c +++ b/networking/ifplugd.c @@ -6,6 +6,16 @@ * * Licensed under GPLv2 or later, see file LICENSE in this source tree. */ +//config:config IFPLUGD +//config: bool "ifplugd" +//config: default y +//config: select PLATFORM_LINUX +//config: help +//config: Network interface plug detection daemon. + +//applet:IF_IFPLUGD(APPLET(ifplugd, BB_DIR_USR_SBIN, BB_SUID_DROP)) + +//kbuild:lib-$(CONFIG_IFPLUGD) += ifplugd.o //usage:#define ifplugd_trivial_usage //usage: "[OPTIONS]" @@ -38,7 +48,17 @@ #include <linux/mii.h> #include <linux/ethtool.h> #ifdef HAVE_NET_ETHERNET_H -# include <net/ethernet.h> +/* musl breakage: + * In file included from /usr/include/net/ethernet.h:10, + * from networking/ifplugd.c:41: + * /usr/include/netinet/if_ether.h:96: error: redefinition of 'struct ethhdr' + * + * Build succeeds without it on musl. Commented it out. + * If on your system you need it, consider removing <linux/ethtool.h> + * and copy-pasting its definitions here (<linux/ethtool.h> is what pulls in + * conflicting definition of struct ethhdr on musl). + */ +/* # include <net/ethernet.h> */ #endif #include <linux/netlink.h> #include <linux/rtnetlink.h> @@ -48,6 +68,10 @@ #define __user #include <linux/wireless.h> +#ifndef ETH_ALEN +# define ETH_ALEN 6 +#endif + /* From initial port to busybox, removed most of the redundancy by converting implementation of a polymorphic interface to the strict @@ -93,9 +117,9 @@ enum { #endif }; #if ENABLE_FEATURE_PIDFILE -# define OPTION_STR "+ansfFi:r:It:u:d:m:pqlx:Mk" +# define OPTION_STR "+ansfFi:r:It:+u:+d:+m:pqlx:Mk" #else -# define OPTION_STR "+ansfFi:r:It:u:d:m:pqlx:M" +# define OPTION_STR "+ansfFi:r:It:+u:+d:+m:pqlx:M" #endif enum { // interface status @@ -289,8 +313,6 @@ static const struct { { "IFF_RUNNING" , &detect_link_iff }, }; - - static const char *strstatus(int status) { if (status == IFSTATUS_ERR) @@ -346,8 +368,12 @@ static void up_iface(void) ifrequest.ifr_flags |= IFF_UP; /* Let user know we mess up with interface */ bb_error_msg("upping interface"); - if (network_ioctl(SIOCSIFFLAGS, &ifrequest, "setting interface flags") < 0) - xfunc_die(); + if (network_ioctl(SIOCSIFFLAGS, &ifrequest, "setting interface flags") < 0) { + if (errno != ENODEV) + xfunc_die(); + G.iface_exists = 0; + return; + } } #if 0 /* why do we mess with IP addr? It's not our business */ @@ -548,7 +574,6 @@ int ifplugd_main(int argc UNUSED_PARAM, char **argv) INIT_G(); - opt_complementary = "t+:u+:d+"; opts = getopt32(argv, OPTION_STR, &G.iface, &G.script_name, &G.poll_time, &G.delay_up, &G.delay_down, &G.api_mode, &G.extra_arg); @@ -652,7 +677,6 @@ int ifplugd_main(int argc UNUSED_PARAM, char **argv) delay_time = 0; while (1) { int iface_status_old; - int iface_exists_old; switch (bb_got_signal) { case SIGINT: @@ -678,12 +702,12 @@ int ifplugd_main(int argc UNUSED_PARAM, char **argv) goto exiting; } - iface_status_old = iface_status; - iface_exists_old = G.iface_exists; - if ((opts & FLAG_MONITOR) && (netlink_pollfd[0].revents & POLLIN) ) { + int iface_exists_old; + + iface_exists_old = G.iface_exists; G.iface_exists = check_existence_through_netlink(); if (G.iface_exists < 0) /* error */ goto exiting; @@ -696,6 +720,7 @@ int ifplugd_main(int argc UNUSED_PARAM, char **argv) } /* note: if !G.iface_exists, returns DOWN */ + iface_status_old = iface_status; iface_status = detect_link(); if (iface_status == IFSTATUS_ERR) { if (!(opts & FLAG_MONITOR)) @@ -709,7 +734,7 @@ int ifplugd_main(int argc UNUSED_PARAM, char **argv) if (delay_time) { /* link restored its old status before - * we run script. don't run the script: */ + * we ran script. don't run the script: */ delay_time = 0; } else { delay_time = monotonic_sec(); @@ -717,15 +742,19 @@ int ifplugd_main(int argc UNUSED_PARAM, char **argv) delay_time += G.delay_up; if (iface_status == IFSTATUS_DOWN) delay_time += G.delay_down; - if (delay_time == 0) - delay_time++; +#if 0 /* if you are back in 1970... */ + if (delay_time == 0) { + sleep(1); + delay_time = 1; + } +#endif } } if (delay_time && (int)(monotonic_sec() - delay_time) >= 0) { - delay_time = 0; if (run_script(iface_status_str) != 0) goto exiting; + delay_time = 0; } } /* while (1) */ |