* set version to 1.1.0
*/
+//usage:#define ifenslave_trivial_usage
+//usage: "[-cdf] MASTER_IFACE SLAVE_IFACE..."
+//usage:#define ifenslave_full_usage "\n\n"
+//usage: "Configure network interfaces for parallel routing\n"
+//usage: "\n -c,--change-active Change active slave"
+//usage: "\n -d,--detach Remove slave interface from bonding device"
+//usage: "\n -f,--force Force, even if interface is not Ethernet"
+/* //usage: "\n -r,--receive-slave Create a receive-only slave" */
+//usage:
+//usage:#define ifenslave_example_usage
+//usage: "To create a bond device, simply follow these three steps:\n"
+//usage: "- ensure that the required drivers are properly loaded:\n"
+//usage: " # modprobe bonding ; modprobe <3c59x|eepro100|pcnet32|tulip|...>\n"
+//usage: "- assign an IP address to the bond device:\n"
+//usage: " # ifconfig bond0 <addr> netmask <mask> broadcast <bcast>\n"
+//usage: "- attach all the interfaces you need to the bond device:\n"
+//usage: " # ifenslave bond0 eth0 eth1 eth2\n"
+//usage: " If bond0 didn't have a MAC address, it will take eth0's. Then, all\n"
+//usage: " interfaces attached AFTER this assignment will get the same MAC addr.\n\n"
+//usage: " To detach a dead interface without setting the bond device down:\n"
+//usage: " # ifenslave -d bond0 eth1\n\n"
+//usage: " To set the bond device down and automatically release all the slaves:\n"
+//usage: " # ifconfig bond0 down\n\n"
+//usage: " To change active slave:\n"
+//usage: " # ifenslave -c bond0 eth0\n"
+
#include "libbb.h"
-#include <net/if_arp.h>
+/* #include <net/if.h> - no. linux/if_bonding.h pulls in linux/if.h */
+#include <linux/if.h>
+//#include <net/if_arp.h> - not needed?
#include <linux/if_bonding.h>
#include <linux/sockios.h>
-
-typedef unsigned long long u64; /* hack, so we may include kernel's ethtool.h */
-typedef uint32_t u32; /* ditto */
-typedef uint16_t u16; /* ditto */
-typedef uint8_t u8; /* ditto */
+#include "fix_u32.h" /* hack, so we may include kernel's ethtool.h */
#include <linux/ethtool.h>
+#ifndef BOND_ABI_VERSION
+# define BOND_ABI_VERSION 2
+#endif
+#ifndef IFNAMSIZ
+# define IFNAMSIZ 16
+#endif
struct dev_data {
/* NOINLINEs are placed where it results in smaller code (gcc 4.3.1) */
-static void strncpy_IFNAMSIZ(char *dst, const char *src)
-{
- strncpy(dst, src, IFNAMSIZ);
-}
-
static int ioctl_on_skfd(unsigned request, struct ifreq *ifr)
{
return ioctl(skfd, request, ifr);
if (res < 0) {
ifr.ifr_addr.sa_family = AF_INET;
memset(ifr.ifr_addr.sa_data, 0,
- sizeof(ifr.ifr_addr.sa_data));
+ sizeof(ifr.ifr_addr.sa_data));
}
res = set_ifrname_and_do_ioctl(ifra[i].s_ioctl, &ifr, slave_ifname);
}
int ifenslave_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
-int ifenslave_main(int argc ATTRIBUTE_UNUSED, char **argv)
+int ifenslave_main(int argc UNUSED_PARAM, char **argv)
{
char *master_ifname, *slave_ifname;
int rv;
OPT_d = (1 << 1),
OPT_f = (1 << 2),
};
-#if ENABLE_GETOPT_LONG
+#if ENABLE_LONG_OPTS
static const char ifenslave_longopts[] ALIGN1 =
"change-active\0" No_argument "c"
"detach\0" No_argument "d"
#ifdef WHY_BOTHER
/* Neither -c[hange] nor -d[etach] -> it's "enslave" then;
* and -f[orce] is not there too. Check that it's ethernet. */
- if (!(opt & (OPT_d|OPT_c|OPT_f)) {
+ if (!(opt & (OPT_d|OPT_c|OPT_f))) {
/* The family '1' is ARPHRD_ETHER for ethernet. */
if (master.hwaddr.ifr_hwaddr.sa_family != 1) {
bb_error_msg_and_die(