ifenslave.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623
  1. /* Mode: C;
  2. *
  3. * Mini ifenslave implementation for busybox
  4. * Copyright (C) 2005 by Marc Leeman <marc.leeman@barco.com>
  5. *
  6. * ifenslave.c: Configure network interfaces for parallel routing.
  7. *
  8. * This program controls the Linux implementation of running multiple
  9. * network interfaces in parallel.
  10. *
  11. * Author: Donald Becker <becker@cesdis.gsfc.nasa.gov>
  12. * Copyright 1994-1996 Donald Becker
  13. *
  14. * This program is free software; you can redistribute it
  15. * and/or modify it under the terms of the GNU General Public
  16. * License as published by the Free Software Foundation.
  17. *
  18. * The author may be reached as becker@CESDIS.gsfc.nasa.gov, or C/O
  19. * Center of Excellence in Space Data and Information Sciences
  20. * Code 930.5, Goddard Space Flight Center, Greenbelt MD 20771
  21. *
  22. * Changes :
  23. * - 2000/10/02 Willy Tarreau <willy at meta-x.org> :
  24. * - few fixes. Master's MAC address is now correctly taken from
  25. * the first device when not previously set ;
  26. * - detach support : call BOND_RELEASE to detach an enslaved interface.
  27. * - give a mini-howto from command-line help : # ifenslave -h
  28. *
  29. * - 2001/02/16 Chad N. Tindel <ctindel at ieee dot org> :
  30. * - Master is now brought down before setting the MAC address. In
  31. * the 2.4 kernel you can't change the MAC address while the device is
  32. * up because you get EBUSY.
  33. *
  34. * - 2001/09/13 Takao Indoh <indou dot takao at jp dot fujitsu dot com>
  35. * - Added the ability to change the active interface on a mode 1 bond
  36. * at runtime.
  37. *
  38. * - 2001/10/23 Chad N. Tindel <ctindel at ieee dot org> :
  39. * - No longer set the MAC address of the master. The bond device will
  40. * take care of this itself
  41. * - Try the SIOC*** versions of the bonding ioctls before using the
  42. * old versions
  43. * - 2002/02/18 Erik Habbinga <erik_habbinga @ hp dot com> :
  44. * - ifr2.ifr_flags was not initialized in the hwaddr_notset case,
  45. * SIOCGIFFLAGS now called before hwaddr_notset test
  46. *
  47. * - 2002/10/31 Tony Cureington <tony.cureington * hp_com> :
  48. * - If the master does not have a hardware address when the first slave
  49. * is enslaved, the master is assigned the hardware address of that
  50. * slave - there is a comment in bonding.c stating "ifenslave takes
  51. * care of this now." This corrects the problem of slaves having
  52. * different hardware addresses in active-backup mode when
  53. * multiple interfaces are specified on a single ifenslave command
  54. * (ifenslave bond0 eth0 eth1).
  55. *
  56. * - 2003/03/18 - Tsippy Mendelson <tsippy.mendelson at intel dot com> and
  57. * Shmulik Hen <shmulik.hen at intel dot com>
  58. * - Moved setting the slave's mac address and opening it, from
  59. * the application to the driver. This enables support of modes
  60. * that need to use the unique mac address of each slave.
  61. * The driver also takes care of closing the slave and restoring its
  62. * original mac address upon release.
  63. * In addition, block possibility of enslaving before the master is up.
  64. * This prevents putting the system in an undefined state.
  65. *
  66. * - 2003/05/01 - Amir Noam <amir.noam at intel dot com>
  67. * - Added ABI version control to restore compatibility between
  68. * new/old ifenslave and new/old bonding.
  69. * - Prevent adding an adapter that is already a slave.
  70. * Fixes the problem of stalling the transmission and leaving
  71. * the slave in a down state.
  72. *
  73. * - 2003/05/01 - Shmulik Hen <shmulik.hen at intel dot com>
  74. * - Prevent enslaving if the bond device is down.
  75. * Fixes the problem of leaving the system in unstable state and
  76. * halting when trying to remove the module.
  77. * - Close socket on all abnormal exists.
  78. * - Add versioning scheme that follows that of the bonding driver.
  79. * current version is 1.0.0 as a base line.
  80. *
  81. * - 2003/05/22 - Jay Vosburgh <fubar at us dot ibm dot com>
  82. * - ifenslave -c was broken; it's now fixed
  83. * - Fixed problem with routes vanishing from master during enslave
  84. * processing.
  85. *
  86. * - 2003/05/27 - Amir Noam <amir.noam at intel dot com>
  87. * - Fix backward compatibility issues:
  88. * For drivers not using ABI versions, slave was set down while
  89. * it should be left up before enslaving.
  90. * Also, master was not set down and the default set_mac_address()
  91. * would fail and generate an error message in the system log.
  92. * - For opt_c: slave should not be set to the master's setting
  93. * while it is running. It was already set during enslave. To
  94. * simplify things, it is now handeled separately.
  95. *
  96. * - 2003/12/01 - Shmulik Hen <shmulik.hen at intel dot com>
  97. * - Code cleanup and style changes
  98. * set version to 1.1.0
  99. */
  100. //config:config IFENSLAVE
  101. //config: bool "ifenslave (13 kb)"
  102. //config: default y
  103. //config: help
  104. //config: Userspace application to bind several interfaces
  105. //config: to a logical interface (use with kernel bonding driver).
  106. //applet:IF_IFENSLAVE(APPLET_NOEXEC(ifenslave, ifenslave, BB_DIR_SBIN, BB_SUID_DROP, ifenslave))
  107. //kbuild:lib-$(CONFIG_IFENSLAVE) += ifenslave.o interface.o
  108. //usage:#define ifenslave_trivial_usage
  109. //usage: "[-cdf] MASTER_IFACE SLAVE_IFACE..."
  110. //usage:#define ifenslave_full_usage "\n\n"
  111. //usage: "Configure network interfaces for parallel routing\n"
  112. //usage: "\n -c Change active slave"
  113. //usage: "\n -d Remove slave interface from bonding device"
  114. //usage: "\n -f Force, even if interface is not Ethernet"
  115. /* //usage: "\n -r Create a receive-only slave" */
  116. //usage:
  117. //usage:#define ifenslave_example_usage
  118. //usage: "To create a bond device, simply follow these three steps:\n"
  119. //usage: "- ensure that the required drivers are properly loaded:\n"
  120. //usage: " # modprobe bonding ; modprobe <3c59x|eepro100|pcnet32|tulip|...>\n"
  121. //usage: "- assign an IP address to the bond device:\n"
  122. //usage: " # ifconfig bond0 <addr> netmask <mask> broadcast <bcast>\n"
  123. //usage: "- attach all the interfaces you need to the bond device:\n"
  124. //usage: " # ifenslave bond0 eth0 eth1 eth2\n"
  125. //usage: " If bond0 didn't have a MAC address, it will take eth0's. Then, all\n"
  126. //usage: " interfaces attached AFTER this assignment will get the same MAC addr.\n\n"
  127. //usage: " To detach a dead interface without setting the bond device down:\n"
  128. //usage: " # ifenslave -d bond0 eth1\n\n"
  129. //usage: " To set the bond device down and automatically release all the slaves:\n"
  130. //usage: " # ifconfig bond0 down\n\n"
  131. //usage: " To change active slave:\n"
  132. //usage: " # ifenslave -c bond0 eth0\n"
  133. #include "libbb.h"
  134. /* #include <net/if.h> - no. linux/if_bonding.h pulls in linux/if.h */
  135. #include <linux/if.h>
  136. //#include <net/if_arp.h> - not needed?
  137. #include <linux/if_bonding.h>
  138. #include <linux/sockios.h>
  139. #include "fix_u32.h" /* hack, so we may include kernel's ethtool.h */
  140. #include <linux/ethtool.h>
  141. #ifndef BOND_ABI_VERSION
  142. # define BOND_ABI_VERSION 2
  143. #endif
  144. #ifndef IFNAMSIZ
  145. # define IFNAMSIZ 16
  146. #endif
  147. struct dev_data {
  148. struct ifreq mtu, flags, hwaddr;
  149. };
  150. enum { skfd = 3 }; /* AF_INET socket for ioctl() calls. */
  151. struct globals {
  152. unsigned abi_ver; /* userland - kernel ABI version */
  153. smallint hwaddr_set; /* Master's hwaddr is set */
  154. struct dev_data master;
  155. struct dev_data slave;
  156. };
  157. #define G (*ptr_to_globals)
  158. #define abi_ver (G.abi_ver )
  159. #define hwaddr_set (G.hwaddr_set)
  160. #define master (G.master )
  161. #define slave (G.slave )
  162. #define INIT_G() do { \
  163. SET_PTR_TO_GLOBALS(xzalloc(sizeof(G))); \
  164. } while (0)
  165. /* NOINLINEs are placed where it results in smaller code (gcc 4.3.1) */
  166. static int ioctl_on_skfd(unsigned request, struct ifreq *ifr)
  167. {
  168. return ioctl(skfd, request, ifr);
  169. }
  170. static int set_ifrname_and_do_ioctl(unsigned request, struct ifreq *ifr, const char *ifname)
  171. {
  172. strncpy_IFNAMSIZ(ifr->ifr_name, ifname);
  173. return ioctl_on_skfd(request, ifr);
  174. }
  175. static int get_if_settings(char *ifname, struct dev_data *dd)
  176. {
  177. int res;
  178. res = set_ifrname_and_do_ioctl(SIOCGIFMTU, &dd->mtu, ifname);
  179. res |= set_ifrname_and_do_ioctl(SIOCGIFFLAGS, &dd->flags, ifname);
  180. res |= set_ifrname_and_do_ioctl(SIOCGIFHWADDR, &dd->hwaddr, ifname);
  181. return res;
  182. }
  183. static int get_slave_flags(char *slave_ifname)
  184. {
  185. return set_ifrname_and_do_ioctl(SIOCGIFFLAGS, &slave.flags, slave_ifname);
  186. }
  187. static int set_hwaddr(char *ifname, struct sockaddr *hwaddr)
  188. {
  189. struct ifreq ifr;
  190. memcpy(&(ifr.ifr_hwaddr), hwaddr, sizeof(*hwaddr));
  191. return set_ifrname_and_do_ioctl(SIOCSIFHWADDR, &ifr, ifname);
  192. }
  193. static int set_mtu(char *ifname, int mtu)
  194. {
  195. struct ifreq ifr;
  196. ifr.ifr_mtu = mtu;
  197. return set_ifrname_and_do_ioctl(SIOCSIFMTU, &ifr, ifname);
  198. }
  199. static int set_if_flags(char *ifname, int flags)
  200. {
  201. struct ifreq ifr;
  202. ifr.ifr_flags = flags;
  203. return set_ifrname_and_do_ioctl(SIOCSIFFLAGS, &ifr, ifname);
  204. }
  205. static int set_if_up(char *ifname, int flags)
  206. {
  207. int res = set_if_flags(ifname, flags | IFF_UP);
  208. if (res)
  209. bb_perror_msg("%s: can't up", ifname);
  210. return res;
  211. }
  212. static int set_if_down(char *ifname, int flags)
  213. {
  214. int res = set_if_flags(ifname, flags & ~IFF_UP);
  215. if (res)
  216. bb_perror_msg("%s: can't down", ifname);
  217. return res;
  218. }
  219. static int clear_if_addr(char *ifname)
  220. {
  221. struct ifreq ifr;
  222. ifr.ifr_addr.sa_family = AF_INET;
  223. memset(ifr.ifr_addr.sa_data, 0, sizeof(ifr.ifr_addr.sa_data));
  224. return set_ifrname_and_do_ioctl(SIOCSIFADDR, &ifr, ifname);
  225. }
  226. static int set_if_addr(char *master_ifname, char *slave_ifname)
  227. {
  228. #if (SIOCGIFADDR | SIOCSIFADDR \
  229. | SIOCGIFDSTADDR | SIOCSIFDSTADDR \
  230. | SIOCGIFBRDADDR | SIOCSIFBRDADDR \
  231. | SIOCGIFNETMASK | SIOCSIFNETMASK) <= 0xffff
  232. #define INT uint16_t
  233. #else
  234. #define INT int
  235. #endif
  236. static const struct {
  237. INT g_ioctl;
  238. INT s_ioctl;
  239. } ifra[] = {
  240. { SIOCGIFADDR, SIOCSIFADDR },
  241. { SIOCGIFDSTADDR, SIOCSIFDSTADDR },
  242. { SIOCGIFBRDADDR, SIOCSIFBRDADDR },
  243. { SIOCGIFNETMASK, SIOCSIFNETMASK },
  244. };
  245. struct ifreq ifr;
  246. int res;
  247. unsigned i;
  248. for (i = 0; i < ARRAY_SIZE(ifra); i++) {
  249. res = set_ifrname_and_do_ioctl(ifra[i].g_ioctl, &ifr, master_ifname);
  250. if (res < 0) {
  251. ifr.ifr_addr.sa_family = AF_INET;
  252. memset(ifr.ifr_addr.sa_data, 0,
  253. sizeof(ifr.ifr_addr.sa_data));
  254. }
  255. res = set_ifrname_and_do_ioctl(ifra[i].s_ioctl, &ifr, slave_ifname);
  256. if (res < 0)
  257. return res;
  258. }
  259. return 0;
  260. }
  261. static void change_active(char *master_ifname, char *slave_ifname)
  262. {
  263. struct ifreq ifr;
  264. if (!(slave.flags.ifr_flags & IFF_SLAVE)) {
  265. bb_error_msg_and_die("%s is not a slave", slave_ifname);
  266. }
  267. strncpy_IFNAMSIZ(ifr.ifr_slave, slave_ifname);
  268. if (set_ifrname_and_do_ioctl(SIOCBONDCHANGEACTIVE, &ifr, master_ifname)
  269. && ioctl_on_skfd(BOND_CHANGE_ACTIVE_OLD, &ifr)
  270. ) {
  271. bb_perror_msg_and_die(
  272. "master %s, slave %s: can't "
  273. "change active",
  274. master_ifname, slave_ifname);
  275. }
  276. }
  277. static NOINLINE int enslave(char *master_ifname, char *slave_ifname)
  278. {
  279. struct ifreq ifr;
  280. int res;
  281. if (slave.flags.ifr_flags & IFF_SLAVE) {
  282. bb_error_msg(
  283. "%s is already a slave",
  284. slave_ifname);
  285. return 1;
  286. }
  287. res = set_if_down(slave_ifname, slave.flags.ifr_flags);
  288. if (res)
  289. return res;
  290. if (abi_ver < 2) {
  291. /* Older bonding versions would panic if the slave has no IP
  292. * address, so get the IP setting from the master.
  293. */
  294. res = set_if_addr(master_ifname, slave_ifname);
  295. if (res) {
  296. bb_perror_msg("%s: can't set address", slave_ifname);
  297. return res;
  298. }
  299. } else {
  300. res = clear_if_addr(slave_ifname);
  301. if (res) {
  302. bb_perror_msg("%s: can't clear address", slave_ifname);
  303. return res;
  304. }
  305. }
  306. if (master.mtu.ifr_mtu != slave.mtu.ifr_mtu) {
  307. res = set_mtu(slave_ifname, master.mtu.ifr_mtu);
  308. if (res) {
  309. bb_perror_msg("%s: can't set MTU", slave_ifname);
  310. return res;
  311. }
  312. }
  313. if (hwaddr_set) {
  314. /* Master already has an hwaddr
  315. * so set it's hwaddr to the slave
  316. */
  317. if (abi_ver < 1) {
  318. /* The driver is using an old ABI, so
  319. * the application sets the slave's
  320. * hwaddr
  321. */
  322. if (set_hwaddr(slave_ifname, &(master.hwaddr.ifr_hwaddr))) {
  323. bb_perror_msg("%s: can't set hw address",
  324. slave_ifname);
  325. goto undo_mtu;
  326. }
  327. /* For old ABI the application needs to bring the
  328. * slave back up
  329. */
  330. if (set_if_up(slave_ifname, slave.flags.ifr_flags))
  331. goto undo_slave_mac;
  332. }
  333. /* The driver is using a new ABI,
  334. * so the driver takes care of setting
  335. * the slave's hwaddr and bringing
  336. * it up again
  337. */
  338. } else {
  339. /* No hwaddr for master yet, so
  340. * set the slave's hwaddr to it
  341. */
  342. if (abi_ver < 1) {
  343. /* For old ABI, the master needs to be
  344. * down before setting it's hwaddr
  345. */
  346. if (set_if_down(master_ifname, master.flags.ifr_flags))
  347. goto undo_mtu;
  348. }
  349. if (set_hwaddr(master_ifname, &(slave.hwaddr.ifr_hwaddr))) {
  350. bb_error_msg("%s: can't set hw address",
  351. master_ifname);
  352. goto undo_mtu;
  353. }
  354. if (abi_ver < 1) {
  355. /* For old ABI, bring the master
  356. * back up
  357. */
  358. if (set_if_up(master_ifname, master.flags.ifr_flags))
  359. goto undo_master_mac;
  360. }
  361. hwaddr_set = 1;
  362. }
  363. /* Do the real thing */
  364. strncpy_IFNAMSIZ(ifr.ifr_slave, slave_ifname);
  365. if (set_ifrname_and_do_ioctl(SIOCBONDENSLAVE, &ifr, master_ifname)
  366. && ioctl_on_skfd(BOND_ENSLAVE_OLD, &ifr)
  367. ) {
  368. goto undo_master_mac;
  369. }
  370. return 0;
  371. /* rollback (best effort) */
  372. undo_master_mac:
  373. set_hwaddr(master_ifname, &(master.hwaddr.ifr_hwaddr));
  374. hwaddr_set = 0;
  375. goto undo_mtu;
  376. undo_slave_mac:
  377. set_hwaddr(slave_ifname, &(slave.hwaddr.ifr_hwaddr));
  378. undo_mtu:
  379. set_mtu(slave_ifname, slave.mtu.ifr_mtu);
  380. return 1;
  381. }
  382. static int release(char *master_ifname, char *slave_ifname)
  383. {
  384. struct ifreq ifr;
  385. int res = 0;
  386. if (!(slave.flags.ifr_flags & IFF_SLAVE)) {
  387. bb_error_msg("%s is not a slave", slave_ifname);
  388. return 1;
  389. }
  390. strncpy_IFNAMSIZ(ifr.ifr_slave, slave_ifname);
  391. if (set_ifrname_and_do_ioctl(SIOCBONDRELEASE, &ifr, master_ifname) < 0
  392. && ioctl_on_skfd(BOND_RELEASE_OLD, &ifr) < 0
  393. ) {
  394. return 1;
  395. }
  396. if (abi_ver < 1) {
  397. /* The driver is using an old ABI, so we'll set the interface
  398. * down to avoid any conflicts due to same MAC/IP
  399. */
  400. res = set_if_down(slave_ifname, slave.flags.ifr_flags);
  401. }
  402. /* set to default mtu */
  403. set_mtu(slave_ifname, 1500);
  404. return res;
  405. }
  406. static NOINLINE void get_drv_info(char *master_ifname)
  407. {
  408. struct ifreq ifr;
  409. struct ethtool_drvinfo info;
  410. memset(&ifr, 0, sizeof(ifr));
  411. ifr.ifr_data = (caddr_t)&info;
  412. info.cmd = ETHTOOL_GDRVINFO;
  413. /* both fields are 32 bytes long (long enough) */
  414. strcpy(info.driver, "ifenslave");
  415. strcpy(info.fw_version, utoa(BOND_ABI_VERSION));
  416. if (set_ifrname_and_do_ioctl(SIOCETHTOOL, &ifr, master_ifname) < 0) {
  417. if (errno == EOPNOTSUPP)
  418. return;
  419. bb_perror_msg_and_die("%s: SIOCETHTOOL error", master_ifname);
  420. }
  421. abi_ver = bb_strtou(info.fw_version, NULL, 0);
  422. if (errno)
  423. bb_error_msg_and_die("%s: SIOCETHTOOL error", master_ifname);
  424. }
  425. int ifenslave_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
  426. int ifenslave_main(int argc UNUSED_PARAM, char **argv)
  427. {
  428. char *master_ifname, *slave_ifname;
  429. int rv;
  430. int res;
  431. unsigned opt;
  432. enum {
  433. OPT_c = (1 << 0),
  434. OPT_d = (1 << 1),
  435. OPT_f = (1 << 2),
  436. };
  437. INIT_G();
  438. opt = getopt32long(argv, "cdfa",
  439. "change-active\0" No_argument "c"
  440. "detach\0" No_argument "d"
  441. "force\0" No_argument "f"
  442. /* "all-interfaces\0" No_argument "a" */
  443. );
  444. argv += optind;
  445. if (opt & (opt-1)) /* Only one option can be given */
  446. bb_show_usage();
  447. master_ifname = *argv++;
  448. /* No interface names - show all interfaces. */
  449. if (!master_ifname) {
  450. display_interfaces(NULL);
  451. return EXIT_SUCCESS;
  452. }
  453. /* Open a basic socket */
  454. xmove_fd(xsocket(AF_INET, SOCK_DGRAM, 0), skfd);
  455. /* Exchange abi version with bonding module */
  456. get_drv_info(master_ifname);
  457. slave_ifname = *argv++;
  458. if (!slave_ifname) {
  459. if (opt & (OPT_d|OPT_c)) {
  460. /* --change or --detach, and no slaves given -
  461. * show all interfaces. */
  462. display_interfaces(slave_ifname /* == NULL */);
  463. return 2; /* why 2? */
  464. }
  465. /* A single arg means show the
  466. * configuration for this interface
  467. */
  468. display_interfaces(master_ifname);
  469. return EXIT_SUCCESS;
  470. }
  471. if (get_if_settings(master_ifname, &master)) {
  472. /* Probably a good reason not to go on */
  473. bb_perror_msg_and_die("%s: can't get settings", master_ifname);
  474. }
  475. /* Check if master is indeed a master;
  476. * if not then fail any operation
  477. */
  478. if (!(master.flags.ifr_flags & IFF_MASTER))
  479. bb_error_msg_and_die("%s is not a master", master_ifname);
  480. /* Check if master is up; if not then fail any operation */
  481. if (!(master.flags.ifr_flags & IFF_UP))
  482. bb_error_msg_and_die("%s is not up", master_ifname);
  483. #ifdef WHY_BOTHER
  484. /* Neither -c[hange] nor -d[etach] -> it's "enslave" then;
  485. * and -f[orce] is not there too. Check that it's ethernet. */
  486. if (!(opt & (OPT_d|OPT_c|OPT_f))) {
  487. /* The family '1' is ARPHRD_ETHER for ethernet. */
  488. if (master.hwaddr.ifr_hwaddr.sa_family != 1) {
  489. bb_error_msg_and_die(
  490. "%s is not ethernet-like (-f overrides)",
  491. master_ifname);
  492. }
  493. }
  494. #endif
  495. /* Accepts only one slave */
  496. if (opt & OPT_c) {
  497. /* Change active slave */
  498. if (get_slave_flags(slave_ifname)) {
  499. bb_perror_msg_and_die(
  500. "%s: can't get flags", slave_ifname);
  501. }
  502. change_active(master_ifname, slave_ifname);
  503. return EXIT_SUCCESS;
  504. }
  505. /* Accepts multiple slaves */
  506. res = 0;
  507. do {
  508. if (opt & OPT_d) {
  509. /* Detach a slave interface from the master */
  510. rv = get_slave_flags(slave_ifname);
  511. if (rv) {
  512. /* Can't work with this slave, */
  513. /* remember the error and skip it */
  514. bb_perror_msg(
  515. "skipping %s: can't get %s",
  516. slave_ifname, "flags");
  517. res = rv;
  518. continue;
  519. }
  520. rv = release(master_ifname, slave_ifname);
  521. if (rv) {
  522. bb_perror_msg("can't release %s from %s",
  523. slave_ifname, master_ifname);
  524. res = rv;
  525. }
  526. } else {
  527. /* Attach a slave interface to the master */
  528. rv = get_if_settings(slave_ifname, &slave);
  529. if (rv) {
  530. /* Can't work with this slave, */
  531. /* remember the error and skip it */
  532. bb_perror_msg(
  533. "skipping %s: can't get %s",
  534. slave_ifname, "settings");
  535. res = rv;
  536. continue;
  537. }
  538. rv = enslave(master_ifname, slave_ifname);
  539. if (rv) {
  540. bb_perror_msg("can't enslave %s to %s",
  541. slave_ifname, master_ifname);
  542. res = rv;
  543. }
  544. }
  545. } while ((slave_ifname = *argv++) != NULL);
  546. if (ENABLE_FEATURE_CLEAN_UP) {
  547. close(skfd);
  548. }
  549. return res;
  550. }