bonding.h 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376
  1. /*
  2. * Bond several ethernet interfaces into a Cisco, running 'Etherchannel'.
  3. *
  4. * Portions are (c) Copyright 1995 Simon "Guru Aleph-Null" Janes
  5. * NCM: Network and Communications Management, Inc.
  6. *
  7. * BUT, I'm the one who modified it for ethernet, so:
  8. * (c) Copyright 1999, Thomas Davis, tadavis@lbl.gov
  9. *
  10. * This software may be used and distributed according to the terms
  11. * of the GNU Public License, incorporated herein by reference.
  12. *
  13. */
  14. #ifndef _LINUX_BONDING_H
  15. #define _LINUX_BONDING_H
  16. #include <linux/timer.h>
  17. #include <linux/proc_fs.h>
  18. #include <linux/if_bonding.h>
  19. #include <linux/kobject.h>
  20. #include <linux/in6.h>
  21. #include "bond_3ad.h"
  22. #include "bond_alb.h"
  23. #define DRV_VERSION "3.5.0"
  24. #define DRV_RELDATE "November 4, 2008"
  25. #define DRV_NAME "bonding"
  26. #define DRV_DESCRIPTION "Ethernet Channel Bonding Driver"
  27. #define BOND_MAX_ARP_TARGETS 16
  28. extern struct list_head bond_dev_list;
  29. #ifdef BONDING_DEBUG
  30. #define dprintk(fmt, args...) \
  31. printk(KERN_DEBUG \
  32. DRV_NAME ": %s() %d: " fmt, __func__, __LINE__ , ## args )
  33. #else
  34. #define dprintk(fmt, args...)
  35. #endif /* BONDING_DEBUG */
  36. #define IS_UP(dev) \
  37. ((((dev)->flags & IFF_UP) == IFF_UP) && \
  38. netif_running(dev) && \
  39. netif_carrier_ok(dev))
  40. /*
  41. * Checks whether bond is ready for transmit.
  42. *
  43. * Caller must hold bond->lock
  44. */
  45. #define BOND_IS_OK(bond) \
  46. (((bond)->dev->flags & IFF_UP) && \
  47. netif_running((bond)->dev) && \
  48. ((bond)->slave_cnt > 0))
  49. /*
  50. * Checks whether slave is ready for transmit.
  51. */
  52. #define SLAVE_IS_OK(slave) \
  53. (((slave)->dev->flags & IFF_UP) && \
  54. netif_running((slave)->dev) && \
  55. ((slave)->link == BOND_LINK_UP) && \
  56. ((slave)->state == BOND_STATE_ACTIVE))
  57. #define USES_PRIMARY(mode) \
  58. (((mode) == BOND_MODE_ACTIVEBACKUP) || \
  59. ((mode) == BOND_MODE_TLB) || \
  60. ((mode) == BOND_MODE_ALB))
  61. /*
  62. * Less bad way to call ioctl from within the kernel; this needs to be
  63. * done some other way to get the call out of interrupt context.
  64. * Needs "ioctl" variable to be supplied by calling context.
  65. */
  66. #define IOCTL(dev, arg, cmd) ({ \
  67. int res = 0; \
  68. mm_segment_t fs = get_fs(); \
  69. set_fs(get_ds()); \
  70. res = ioctl(dev, arg, cmd); \
  71. set_fs(fs); \
  72. res; })
  73. /**
  74. * bond_for_each_slave_from - iterate the slaves list from a starting point
  75. * @bond: the bond holding this list.
  76. * @pos: current slave.
  77. * @cnt: counter for max number of moves
  78. * @start: starting point.
  79. *
  80. * Caller must hold bond->lock
  81. */
  82. #define bond_for_each_slave_from(bond, pos, cnt, start) \
  83. for (cnt = 0, pos = start; \
  84. cnt < (bond)->slave_cnt; \
  85. cnt++, pos = (pos)->next)
  86. /**
  87. * bond_for_each_slave_from_to - iterate the slaves list from start point to stop point
  88. * @bond: the bond holding this list.
  89. * @pos: current slave.
  90. * @cnt: counter for number max of moves
  91. * @start: start point.
  92. * @stop: stop point.
  93. *
  94. * Caller must hold bond->lock
  95. */
  96. #define bond_for_each_slave_from_to(bond, pos, cnt, start, stop) \
  97. for (cnt = 0, pos = start; \
  98. ((cnt < (bond)->slave_cnt) && (pos != (stop)->next)); \
  99. cnt++, pos = (pos)->next)
  100. /**
  101. * bond_for_each_slave - iterate the slaves list from head
  102. * @bond: the bond holding this list.
  103. * @pos: current slave.
  104. * @cnt: counter for max number of moves
  105. *
  106. * Caller must hold bond->lock
  107. */
  108. #define bond_for_each_slave(bond, pos, cnt) \
  109. bond_for_each_slave_from(bond, pos, cnt, (bond)->first_slave)
  110. struct bond_params {
  111. int mode;
  112. int xmit_policy;
  113. int miimon;
  114. int num_grat_arp;
  115. int num_unsol_na;
  116. int arp_interval;
  117. int arp_validate;
  118. int use_carrier;
  119. int fail_over_mac;
  120. int updelay;
  121. int downdelay;
  122. int lacp_fast;
  123. int ad_select;
  124. char primary[IFNAMSIZ];
  125. __be32 arp_targets[BOND_MAX_ARP_TARGETS];
  126. };
  127. struct bond_parm_tbl {
  128. char *modename;
  129. int mode;
  130. };
  131. #define BOND_MAX_MODENAME_LEN 20
  132. struct vlan_entry {
  133. struct list_head vlan_list;
  134. __be32 vlan_ip;
  135. unsigned short vlan_id;
  136. #if defined(CONFIG_IPV6) || defined(CONFIG_IPV6_MODULE)
  137. struct in6_addr vlan_ipv6;
  138. #endif
  139. };
  140. struct slave {
  141. struct net_device *dev; /* first - useful for panic debug */
  142. struct slave *next;
  143. struct slave *prev;
  144. int delay;
  145. unsigned long jiffies;
  146. unsigned long last_arp_rx;
  147. s8 link; /* one of BOND_LINK_XXXX */
  148. s8 new_link;
  149. s8 state; /* one of BOND_STATE_XXXX */
  150. u32 original_flags;
  151. u32 original_mtu;
  152. u32 link_failure_count;
  153. u16 speed;
  154. u8 duplex;
  155. u8 perm_hwaddr[ETH_ALEN];
  156. struct ad_slave_info ad_info; /* HUGE - better to dynamically alloc */
  157. struct tlb_slave_info tlb_info;
  158. };
  159. /*
  160. * Link pseudo-state only used internally by monitors
  161. */
  162. #define BOND_LINK_NOCHANGE -1
  163. /*
  164. * Here are the locking policies for the two bonding locks:
  165. *
  166. * 1) Get bond->lock when reading/writing slave list.
  167. * 2) Get bond->curr_slave_lock when reading/writing bond->curr_active_slave.
  168. * (It is unnecessary when the write-lock is put with bond->lock.)
  169. * 3) When we lock with bond->curr_slave_lock, we must lock with bond->lock
  170. * beforehand.
  171. */
  172. struct bonding {
  173. struct net_device *dev; /* first - useful for panic debug */
  174. struct slave *first_slave;
  175. struct slave *curr_active_slave;
  176. struct slave *current_arp_slave;
  177. struct slave *primary_slave;
  178. s32 slave_cnt; /* never change this value outside the attach/detach wrappers */
  179. rwlock_t lock;
  180. rwlock_t curr_slave_lock;
  181. s8 kill_timers;
  182. s8 send_grat_arp;
  183. s8 send_unsol_na;
  184. s8 setup_by_slave;
  185. struct net_device_stats stats;
  186. #ifdef CONFIG_PROC_FS
  187. struct proc_dir_entry *proc_entry;
  188. char proc_file_name[IFNAMSIZ];
  189. #endif /* CONFIG_PROC_FS */
  190. struct list_head bond_list;
  191. struct dev_mc_list *mc_list;
  192. int (*xmit_hash_policy)(struct sk_buff *, struct net_device *, int);
  193. __be32 master_ip;
  194. u16 flags;
  195. u16 rr_tx_counter;
  196. struct ad_bond_info ad_info;
  197. struct alb_bond_info alb_info;
  198. struct bond_params params;
  199. struct list_head vlan_list;
  200. struct vlan_group *vlgrp;
  201. struct packet_type arp_mon_pt;
  202. struct workqueue_struct *wq;
  203. struct delayed_work mii_work;
  204. struct delayed_work arp_work;
  205. struct delayed_work alb_work;
  206. struct delayed_work ad_work;
  207. #if defined(CONFIG_IPV6) || defined(CONFIG_IPV6_MODULE)
  208. struct in6_addr master_ipv6;
  209. #endif
  210. };
  211. /**
  212. * Returns NULL if the net_device does not belong to any of the bond's slaves
  213. *
  214. * Caller must hold bond lock for read
  215. */
  216. static inline struct slave *bond_get_slave_by_dev(struct bonding *bond, struct net_device *slave_dev)
  217. {
  218. struct slave *slave = NULL;
  219. int i;
  220. bond_for_each_slave(bond, slave, i) {
  221. if (slave->dev == slave_dev) {
  222. break;
  223. }
  224. }
  225. return slave;
  226. }
  227. static inline struct bonding *bond_get_bond_by_slave(struct slave *slave)
  228. {
  229. if (!slave || !slave->dev->master) {
  230. return NULL;
  231. }
  232. return (struct bonding *)netdev_priv(slave->dev->master);
  233. }
  234. #define BOND_FOM_NONE 0
  235. #define BOND_FOM_ACTIVE 1
  236. #define BOND_FOM_FOLLOW 2
  237. #define BOND_ARP_VALIDATE_NONE 0
  238. #define BOND_ARP_VALIDATE_ACTIVE (1 << BOND_STATE_ACTIVE)
  239. #define BOND_ARP_VALIDATE_BACKUP (1 << BOND_STATE_BACKUP)
  240. #define BOND_ARP_VALIDATE_ALL (BOND_ARP_VALIDATE_ACTIVE | \
  241. BOND_ARP_VALIDATE_BACKUP)
  242. static inline int slave_do_arp_validate(struct bonding *bond,
  243. struct slave *slave)
  244. {
  245. return bond->params.arp_validate & (1 << slave->state);
  246. }
  247. static inline unsigned long slave_last_rx(struct bonding *bond,
  248. struct slave *slave)
  249. {
  250. if (slave_do_arp_validate(bond, slave))
  251. return slave->last_arp_rx;
  252. return slave->dev->last_rx;
  253. }
  254. static inline void bond_set_slave_inactive_flags(struct slave *slave)
  255. {
  256. struct bonding *bond = netdev_priv(slave->dev->master);
  257. if (bond->params.mode != BOND_MODE_TLB &&
  258. bond->params.mode != BOND_MODE_ALB)
  259. slave->state = BOND_STATE_BACKUP;
  260. slave->dev->priv_flags |= IFF_SLAVE_INACTIVE;
  261. if (slave_do_arp_validate(bond, slave))
  262. slave->dev->priv_flags |= IFF_SLAVE_NEEDARP;
  263. }
  264. static inline void bond_set_slave_active_flags(struct slave *slave)
  265. {
  266. slave->state = BOND_STATE_ACTIVE;
  267. slave->dev->priv_flags &= ~(IFF_SLAVE_INACTIVE | IFF_SLAVE_NEEDARP);
  268. }
  269. static inline void bond_set_master_3ad_flags(struct bonding *bond)
  270. {
  271. bond->dev->priv_flags |= IFF_MASTER_8023AD;
  272. }
  273. static inline void bond_unset_master_3ad_flags(struct bonding *bond)
  274. {
  275. bond->dev->priv_flags &= ~IFF_MASTER_8023AD;
  276. }
  277. static inline void bond_set_master_alb_flags(struct bonding *bond)
  278. {
  279. bond->dev->priv_flags |= IFF_MASTER_ALB;
  280. }
  281. static inline void bond_unset_master_alb_flags(struct bonding *bond)
  282. {
  283. bond->dev->priv_flags &= ~IFF_MASTER_ALB;
  284. }
  285. struct vlan_entry *bond_next_vlan(struct bonding *bond, struct vlan_entry *curr);
  286. int bond_dev_queue_xmit(struct bonding *bond, struct sk_buff *skb, struct net_device *slave_dev);
  287. int bond_create(char *name, struct bond_params *params);
  288. void bond_destroy(struct bonding *bond);
  289. int bond_release_and_destroy(struct net_device *bond_dev, struct net_device *slave_dev);
  290. int bond_create_sysfs(void);
  291. void bond_destroy_sysfs(void);
  292. void bond_destroy_sysfs_entry(struct bonding *bond);
  293. int bond_create_sysfs_entry(struct bonding *bond);
  294. int bond_create_slave_symlinks(struct net_device *master, struct net_device *slave);
  295. void bond_destroy_slave_symlinks(struct net_device *master, struct net_device *slave);
  296. int bond_enslave(struct net_device *bond_dev, struct net_device *slave_dev);
  297. int bond_release(struct net_device *bond_dev, struct net_device *slave_dev);
  298. void bond_mii_monitor(struct work_struct *);
  299. void bond_loadbalance_arp_mon(struct work_struct *);
  300. void bond_activebackup_arp_mon(struct work_struct *);
  301. void bond_set_mode_ops(struct bonding *bond, int mode);
  302. int bond_parse_parm(const char *mode_arg, struct bond_parm_tbl *tbl);
  303. void bond_select_active_slave(struct bonding *bond);
  304. void bond_change_active_slave(struct bonding *bond, struct slave *new_active);
  305. void bond_register_arp(struct bonding *);
  306. void bond_unregister_arp(struct bonding *);
  307. /* exported from bond_main.c */
  308. extern struct list_head bond_dev_list;
  309. extern struct bond_parm_tbl bond_lacp_tbl[];
  310. extern struct bond_parm_tbl bond_mode_tbl[];
  311. extern struct bond_parm_tbl xmit_hashtype_tbl[];
  312. extern struct bond_parm_tbl arp_validate_tbl[];
  313. extern struct bond_parm_tbl fail_over_mac_tbl[];
  314. #if defined(CONFIG_IPV6) || defined(CONFIG_IPV6_MODULE)
  315. void bond_send_unsolicited_na(struct bonding *bond);
  316. void bond_register_ipv6_notifier(void);
  317. void bond_unregister_ipv6_notifier(void);
  318. #else
  319. static inline void bond_send_unsolicited_na(struct bonding *bond)
  320. {
  321. return;
  322. }
  323. static inline void bond_register_ipv6_notifier(void)
  324. {
  325. return;
  326. }
  327. static inline void bond_unregister_ipv6_notifier(void)
  328. {
  329. return;
  330. }
  331. #endif
  332. #endif /* _LINUX_BONDING_H */