bond_options.c 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. /*
  2. * drivers/net/bond/bond_options.c - bonding options
  3. * Copyright (c) 2013 Jiri Pirko <jiri@resnulli.us>
  4. *
  5. * This program is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation; either version 2 of the License, or
  8. * (at your option) any later version.
  9. */
  10. #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
  11. #include <linux/errno.h>
  12. #include <linux/if.h>
  13. #include "bonding.h"
  14. static bool bond_mode_is_valid(int mode)
  15. {
  16. int i;
  17. for (i = 0; bond_mode_tbl[i].modename; i++);
  18. return mode >= 0 && mode < i;
  19. }
  20. int bond_option_mode_set(struct bonding *bond, int mode)
  21. {
  22. if (!bond_mode_is_valid(mode)) {
  23. pr_err("invalid mode value %d.\n", mode);
  24. return -EINVAL;
  25. }
  26. if (bond->dev->flags & IFF_UP) {
  27. pr_err("%s: unable to update mode because interface is up.\n",
  28. bond->dev->name);
  29. return -EPERM;
  30. }
  31. if (bond_has_slaves(bond)) {
  32. pr_err("%s: unable to update mode because bond has slaves.\n",
  33. bond->dev->name);
  34. return -EPERM;
  35. }
  36. if (BOND_MODE_IS_LB(mode) && bond->params.arp_interval) {
  37. pr_err("%s: %s mode is incompatible with arp monitoring.\n",
  38. bond->dev->name, bond_mode_tbl[mode].modename);
  39. return -EINVAL;
  40. }
  41. /* don't cache arp_validate between modes */
  42. bond->params.arp_validate = BOND_ARP_VALIDATE_NONE;
  43. bond->params.mode = mode;
  44. return 0;
  45. }