bond_options.h 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  1. /* SPDX-License-Identifier: GPL-2.0-or-later */
  2. /*
  3. * drivers/net/bond/bond_options.h - bonding options
  4. * Copyright (c) 2013 Nikolay Aleksandrov <[email protected]>
  5. */
  6. #ifndef _NET_BOND_OPTIONS_H
  7. #define _NET_BOND_OPTIONS_H
  8. #include <linux/bits.h>
  9. #include <linux/limits.h>
  10. #include <linux/types.h>
  11. #include <linux/string.h>
  12. struct netlink_ext_ack;
  13. struct nlattr;
  14. #define BOND_OPT_MAX_NAMELEN 32
  15. #define BOND_OPT_VALID(opt) ((opt) < BOND_OPT_LAST)
  16. #define BOND_MODE_ALL_EX(x) (~(x))
  17. /* Option flags:
  18. * BOND_OPTFLAG_NOSLAVES - check if the bond device is empty before setting
  19. * BOND_OPTFLAG_IFDOWN - check if the bond device is down before setting
  20. * BOND_OPTFLAG_RAWVAL - the option parses the value itself
  21. */
  22. enum {
  23. BOND_OPTFLAG_NOSLAVES = BIT(0),
  24. BOND_OPTFLAG_IFDOWN = BIT(1),
  25. BOND_OPTFLAG_RAWVAL = BIT(2)
  26. };
  27. /* Value type flags:
  28. * BOND_VALFLAG_DEFAULT - mark the value as default
  29. * BOND_VALFLAG_(MIN|MAX) - mark the value as min/max
  30. */
  31. enum {
  32. BOND_VALFLAG_DEFAULT = BIT(0),
  33. BOND_VALFLAG_MIN = BIT(1),
  34. BOND_VALFLAG_MAX = BIT(2)
  35. };
  36. /* Option IDs, their bit positions correspond to their IDs */
  37. enum {
  38. BOND_OPT_MODE,
  39. BOND_OPT_PACKETS_PER_SLAVE,
  40. BOND_OPT_XMIT_HASH,
  41. BOND_OPT_ARP_VALIDATE,
  42. BOND_OPT_ARP_ALL_TARGETS,
  43. BOND_OPT_FAIL_OVER_MAC,
  44. BOND_OPT_ARP_INTERVAL,
  45. BOND_OPT_ARP_TARGETS,
  46. BOND_OPT_DOWNDELAY,
  47. BOND_OPT_UPDELAY,
  48. BOND_OPT_LACP_RATE,
  49. BOND_OPT_MINLINKS,
  50. BOND_OPT_AD_SELECT,
  51. BOND_OPT_NUM_PEER_NOTIF,
  52. BOND_OPT_MIIMON,
  53. BOND_OPT_PRIMARY,
  54. BOND_OPT_PRIMARY_RESELECT,
  55. BOND_OPT_USE_CARRIER,
  56. BOND_OPT_ACTIVE_SLAVE,
  57. BOND_OPT_QUEUE_ID,
  58. BOND_OPT_ALL_SLAVES_ACTIVE,
  59. BOND_OPT_RESEND_IGMP,
  60. BOND_OPT_LP_INTERVAL,
  61. BOND_OPT_SLAVES,
  62. BOND_OPT_TLB_DYNAMIC_LB,
  63. BOND_OPT_AD_ACTOR_SYS_PRIO,
  64. BOND_OPT_AD_ACTOR_SYSTEM,
  65. BOND_OPT_AD_USER_PORT_KEY,
  66. BOND_OPT_NUM_PEER_NOTIF_ALIAS,
  67. BOND_OPT_PEER_NOTIF_DELAY,
  68. BOND_OPT_LACP_ACTIVE,
  69. BOND_OPT_MISSED_MAX,
  70. BOND_OPT_NS_TARGETS,
  71. BOND_OPT_PRIO,
  72. BOND_OPT_LAST
  73. };
  74. /* This structure is used for storing option values and for passing option
  75. * values when changing an option. The logic when used as an arg is as follows:
  76. * - if value != ULLONG_MAX -> parse value
  77. * - if string != NULL -> parse string
  78. * - if the opt is RAW data and length less than maxlen,
  79. * copy the data to extra storage
  80. */
  81. #define BOND_OPT_EXTRA_MAXLEN 16
  82. struct bond_opt_value {
  83. char *string;
  84. u64 value;
  85. u32 flags;
  86. union {
  87. char extra[BOND_OPT_EXTRA_MAXLEN];
  88. struct net_device *slave_dev;
  89. };
  90. };
  91. struct bonding;
  92. struct bond_option {
  93. int id;
  94. const char *name;
  95. const char *desc;
  96. u32 flags;
  97. /* unsuppmodes is used to denote modes in which the option isn't
  98. * supported.
  99. */
  100. unsigned long unsuppmodes;
  101. /* supported values which this option can have, can be a subset of
  102. * BOND_OPTVAL_RANGE's value range
  103. */
  104. const struct bond_opt_value *values;
  105. int (*set)(struct bonding *bond, const struct bond_opt_value *val);
  106. };
  107. int __bond_opt_set(struct bonding *bond, unsigned int option,
  108. struct bond_opt_value *val,
  109. struct nlattr *bad_attr, struct netlink_ext_ack *extack);
  110. int __bond_opt_set_notify(struct bonding *bond, unsigned int option,
  111. struct bond_opt_value *val);
  112. int bond_opt_tryset_rtnl(struct bonding *bond, unsigned int option, char *buf);
  113. const struct bond_opt_value *bond_opt_parse(const struct bond_option *opt,
  114. struct bond_opt_value *val);
  115. const struct bond_option *bond_opt_get(unsigned int option);
  116. const struct bond_option *bond_opt_get_by_name(const char *name);
  117. const struct bond_opt_value *bond_opt_get_val(unsigned int option, u64 val);
  118. /* This helper is used to initialize a bond_opt_value structure for parameter
  119. * passing. There should be either a valid string or value, but not both.
  120. * When value is ULLONG_MAX then string will be used.
  121. */
  122. static inline void __bond_opt_init(struct bond_opt_value *optval,
  123. char *string, u64 value,
  124. void *extra, size_t extra_len)
  125. {
  126. memset(optval, 0, sizeof(*optval));
  127. optval->value = ULLONG_MAX;
  128. if (value != ULLONG_MAX)
  129. optval->value = value;
  130. else if (string)
  131. optval->string = string;
  132. if (extra && extra_len <= BOND_OPT_EXTRA_MAXLEN)
  133. memcpy(optval->extra, extra, extra_len);
  134. }
  135. #define bond_opt_initval(optval, value) __bond_opt_init(optval, NULL, value, NULL, 0)
  136. #define bond_opt_initstr(optval, str) __bond_opt_init(optval, str, ULLONG_MAX, NULL, 0)
  137. #define bond_opt_initextra(optval, extra, extra_len) \
  138. __bond_opt_init(optval, NULL, ULLONG_MAX, extra, extra_len)
  139. #define bond_opt_slave_initval(optval, slave_dev, value) \
  140. __bond_opt_init(optval, NULL, value, slave_dev, sizeof(struct net_device *))
  141. void bond_option_arp_ip_targets_clear(struct bonding *bond);
  142. #if IS_ENABLED(CONFIG_IPV6)
  143. void bond_option_ns_ip6_targets_clear(struct bonding *bond);
  144. #endif
  145. #endif /* _NET_BOND_OPTIONS_H */