if_lagg.h 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301
  1. /* $OpenBSD: if_trunk.h,v 1.11 2007/01/31 06:20:19 reyk Exp $ */
  2. /*
  3. * Copyright (c) 2005, 2006 Reyk Floeter <reyk@openbsd.org>
  4. *
  5. * Permission to use, copy, modify, and distribute this software for any
  6. * purpose with or without fee is hereby granted, provided that the above
  7. * copyright notice and this permission notice appear in all copies.
  8. *
  9. * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
  10. * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
  11. * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
  12. * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  13. * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
  14. * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
  15. * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  16. */
  17. #ifndef _NET_LAGG_H
  18. #define _NET_LAGG_H
  19. /*
  20. * Global definitions
  21. */
  22. #define LAGG_MAX_PORTS 32 /* logically */
  23. #define LAGG_MAX_NAMESIZE 32 /* name of a protocol */
  24. #define LAGG_MAX_STACKING 4 /* maximum number of stacked laggs */
  25. /* Lagg flags */
  26. #define LAGG_F_HASHL2 0x00000001 /* hash layer 2 */
  27. #define LAGG_F_HASHL3 0x00000002 /* hash layer 3 */
  28. #define LAGG_F_HASHL4 0x00000004 /* hash layer 4 */
  29. #define LAGG_F_HASHMASK 0x00000007
  30. /* Port flags */
  31. #define LAGG_PORT_SLAVE 0x00000000 /* normal enslaved port */
  32. #define LAGG_PORT_MASTER 0x00000001 /* primary port */
  33. #define LAGG_PORT_STACK 0x00000002 /* stacked lagg port */
  34. #define LAGG_PORT_ACTIVE 0x00000004 /* port is active */
  35. #define LAGG_PORT_COLLECTING 0x00000008 /* port is receiving frames */
  36. #define LAGG_PORT_DISTRIBUTING 0x00000010 /* port is sending frames */
  37. #define LAGG_PORT_BITS "\20\01MASTER\02STACK\03ACTIVE\04COLLECTING" \
  38. "\05DISTRIBUTING"
  39. /* Supported lagg PROTOs */
  40. typedef enum {
  41. LAGG_PROTO_NONE = 0, /* no lagg protocol defined */
  42. LAGG_PROTO_ROUNDROBIN, /* simple round robin */
  43. LAGG_PROTO_FAILOVER, /* active failover */
  44. LAGG_PROTO_LOADBALANCE, /* loadbalance */
  45. LAGG_PROTO_LACP, /* 802.3ad lacp */
  46. LAGG_PROTO_BROADCAST, /* broadcast */
  47. LAGG_PROTO_MAX,
  48. } lagg_proto;
  49. struct lagg_protos {
  50. const char *lpr_name;
  51. lagg_proto lpr_proto;
  52. };
  53. #define LAGG_PROTO_DEFAULT LAGG_PROTO_FAILOVER
  54. #define LAGG_PROTOS { \
  55. { "failover", LAGG_PROTO_FAILOVER }, \
  56. { "lacp", LAGG_PROTO_LACP }, \
  57. { "loadbalance", LAGG_PROTO_LOADBALANCE }, \
  58. { "roundrobin", LAGG_PROTO_ROUNDROBIN }, \
  59. { "broadcast", LAGG_PROTO_BROADCAST }, \
  60. { "none", LAGG_PROTO_NONE }, \
  61. { "default", LAGG_PROTO_DEFAULT } \
  62. }
  63. /* Supported lagg TYPEs */
  64. typedef enum {
  65. LAGG_TYPE_ETHERNET = 0, /* ethernet (default) */
  66. LAGG_TYPE_INFINIBAND, /* infiniband */
  67. LAGG_TYPE_MAX,
  68. } lagg_type;
  69. struct lagg_types {
  70. const char *lt_name;
  71. lagg_type lt_value;
  72. };
  73. #define LAGG_TYPE_DEFAULT LAGG_TYPE_ETHERNET
  74. #define LAGG_TYPES { \
  75. { "ethernet", LAGG_TYPE_ETHERNET }, \
  76. { "infiniband", LAGG_TYPE_INFINIBAND }, \
  77. }
  78. /*
  79. * lagg create clone params
  80. */
  81. struct iflaggparam {
  82. uint8_t lagg_type; /* see LAGG_TYPE_XXX */
  83. uint8_t reserved_8[3];
  84. uint32_t reserved_32[3];
  85. };
  86. /*
  87. * lagg ioctls.
  88. */
  89. /*
  90. * LACP current operational parameters structure.
  91. */
  92. struct lacp_opreq {
  93. uint16_t actor_prio;
  94. uint8_t actor_mac[ETHER_ADDR_LEN];
  95. uint16_t actor_key;
  96. uint16_t actor_portprio;
  97. uint16_t actor_portno;
  98. uint8_t actor_state;
  99. uint16_t partner_prio;
  100. uint8_t partner_mac[ETHER_ADDR_LEN];
  101. uint16_t partner_key;
  102. uint16_t partner_portprio;
  103. uint16_t partner_portno;
  104. uint8_t partner_state;
  105. };
  106. /* lagg port settings */
  107. struct lagg_reqport {
  108. char rp_ifname[IFNAMSIZ]; /* name of the lagg */
  109. char rp_portname[IFNAMSIZ]; /* name of the port */
  110. u_int32_t rp_prio; /* port priority */
  111. u_int32_t rp_flags; /* port flags */
  112. union {
  113. struct lacp_opreq rpsc_lacp;
  114. } rp_psc;
  115. #define rp_lacpreq rp_psc.rpsc_lacp
  116. };
  117. #define SIOCGLAGGPORT _IOWR('i', 140, struct lagg_reqport)
  118. #define SIOCSLAGGPORT _IOW('i', 141, struct lagg_reqport)
  119. #define SIOCSLAGGDELPORT _IOW('i', 142, struct lagg_reqport)
  120. /* lagg, ports and options */
  121. struct lagg_reqall {
  122. char ra_ifname[IFNAMSIZ]; /* name of the lagg */
  123. u_int ra_proto; /* lagg protocol */
  124. size_t ra_size; /* size of buffer */
  125. struct lagg_reqport *ra_port; /* allocated buffer */
  126. int ra_ports; /* total port count */
  127. union {
  128. struct lacp_opreq rpsc_lacp;
  129. } ra_psc;
  130. #define ra_lacpreq ra_psc.rpsc_lacp
  131. };
  132. #define SIOCGLAGG _IOWR('i', 143, struct lagg_reqall)
  133. #define SIOCSLAGG _IOW('i', 144, struct lagg_reqall)
  134. struct lagg_reqflags {
  135. char rf_ifname[IFNAMSIZ]; /* name of the lagg */
  136. uint32_t rf_flags; /* lagg protocol */
  137. };
  138. #define SIOCGLAGGFLAGS _IOWR('i', 145, struct lagg_reqflags)
  139. #define SIOCSLAGGHASH _IOW('i', 146, struct lagg_reqflags)
  140. struct lagg_reqopts {
  141. char ro_ifname[IFNAMSIZ]; /* name of the lagg */
  142. int ro_opts; /* Option bitmap */
  143. #define LAGG_OPT_NONE 0x00
  144. #define LAGG_OPT_USE_FLOWID 0x01 /* enable use of flowid */
  145. /* Pseudo flags which are used in ro_opts but not stored into sc_opts. */
  146. #define LAGG_OPT_FLOWIDSHIFT 0x02 /* set flowid shift */
  147. #define LAGG_OPT_USE_NUMA 0x04 /* enable use of numa */
  148. #define LAGG_OPT_FLOWIDSHIFT_MASK 0x1f /* flowid is uint32_t */
  149. #define LAGG_OPT_LACP_STRICT 0x10 /* LACP strict mode */
  150. #define LAGG_OPT_LACP_TXTEST 0x20 /* LACP debug: txtest */
  151. #define LAGG_OPT_LACP_RXTEST 0x40 /* LACP debug: rxtest */
  152. #define LAGG_OPT_LACP_FAST_TIMO 0x80 /* LACP fast timeout */
  153. #define LAGG_OPT_RR_LIMIT 0x100 /* RR stride */
  154. u_int ro_count; /* number of ports */
  155. u_int ro_active; /* active port count */
  156. u_int ro_flapping; /* number of flapping */
  157. int ro_flowid_shift; /* shift the flowid */
  158. uint32_t ro_bkt; /* stride for RR */
  159. };
  160. #define SIOCGLAGGOPTS _IOWR('i', 152, struct lagg_reqopts)
  161. #define SIOCSLAGGOPTS _IOW('i', 153, struct lagg_reqopts)
  162. #define LAGG_OPT_BITS "\020\001USE_FLOWID\003USE_NUMA" \
  163. "\005LACP_STRICT\006LACP_TXTEST" \
  164. "\007LACP_RXTEST\010LACP_FAST_TIMO"
  165. #ifdef _KERNEL
  166. /*
  167. * Internal kernel part
  168. */
  169. #define LAGG_PORTACTIVE(_tp) ( \
  170. ((_tp)->lp_ifp->if_link_state == LINK_STATE_UP) && \
  171. ((_tp)->lp_ifp->if_flags & IFF_UP) \
  172. )
  173. struct lagg_ifreq {
  174. union {
  175. struct ifreq ifreq;
  176. struct {
  177. char ifr_name[IFNAMSIZ];
  178. struct sockaddr_storage ifr_ss;
  179. } ifreq_storage;
  180. } ifreq;
  181. };
  182. #define sc_ifflags sc_ifp->if_flags /* flags */
  183. #define sc_ifname sc_ifp->if_xname /* name */
  184. /* Private data used by the loadbalancing protocol */
  185. struct lagg_lb {
  186. u_int32_t lb_key;
  187. struct lagg_port *lb_ports[LAGG_MAX_PORTS];
  188. };
  189. struct lagg_mc {
  190. struct sockaddr_dl mc_addr;
  191. struct ifmultiaddr *mc_ifma;
  192. SLIST_ENTRY(lagg_mc) mc_entries;
  193. };
  194. struct lagg_counters {
  195. uint64_t val[IFCOUNTERS];
  196. };
  197. struct lagg_softc {
  198. struct ifnet *sc_ifp; /* virtual interface */
  199. struct mtx sc_mtx; /* watchdog mutex */
  200. struct sx sc_sx;
  201. int sc_proto; /* lagg protocol */
  202. u_int sc_count; /* number of ports */
  203. u_int sc_active; /* active port count */
  204. u_int sc_flapping; /* number of flapping
  205. * events */
  206. struct lagg_port *sc_primary; /* primary port */
  207. struct ifmedia sc_media; /* media config */
  208. void *sc_psc; /* protocol data */
  209. uint32_t sc_seq; /* sequence counter */
  210. uint32_t sc_stride; /* stride for RR */
  211. uint32_t sc_flags;
  212. int sc_destroying; /* destroying lagg */
  213. CK_SLIST_HEAD(__tplhd, lagg_port) sc_ports; /* list of interfaces */
  214. SLIST_ENTRY(lagg_softc) sc_entries;
  215. eventhandler_tag vlan_attach;
  216. eventhandler_tag vlan_detach;
  217. struct callout sc_callout;
  218. u_int sc_opts;
  219. int flowid_shift; /* shift the flowid */
  220. struct lagg_counters detached_counters; /* detached ports sum */
  221. struct callout sc_watchdog; /* watchdog timer */
  222. #define LAGG_ADDR_LEN \
  223. MAX(INFINIBAND_ADDR_LEN, ETHER_ADDR_LEN)
  224. uint8_t sc_bcast_addr[LAGG_ADDR_LEN];
  225. };
  226. struct lagg_port {
  227. struct ifnet *lp_ifp; /* physical interface */
  228. struct lagg_softc *lp_softc; /* parent lagg */
  229. uint8_t lp_lladdr[LAGG_ADDR_LEN];
  230. u_char lp_iftype; /* interface type */
  231. uint32_t lp_prio; /* port priority */
  232. uint32_t lp_flags; /* port flags */
  233. int lp_ifflags; /* saved ifp flags */
  234. int lp_ifcapenable; /* saved ifp capenable */
  235. int lp_ifcapenable2;/* saved ifp capenable2 */
  236. void *lh_cookie; /* if state hook */
  237. void *lp_psc; /* protocol data */
  238. int lp_detaching; /* ifnet is detaching */
  239. SLIST_HEAD(__mclhd, lagg_mc) lp_mc_head; /* multicast addresses */
  240. /* Redirected callbacks */
  241. int (*lp_ioctl)(struct ifnet *, u_long, caddr_t);
  242. int (*lp_output)(struct ifnet *, struct mbuf *,
  243. const struct sockaddr *, struct route *);
  244. struct lagg_counters port_counters; /* ifp counters copy */
  245. CK_SLIST_ENTRY(lagg_port) lp_entries;
  246. struct epoch_context lp_epoch_ctx;
  247. };
  248. extern struct mbuf *(*lagg_input_ethernet_p)(struct ifnet *, struct mbuf *);
  249. extern struct mbuf *(*lagg_input_infiniband_p)(struct ifnet *, struct mbuf *);
  250. extern void (*lagg_linkstate_p)(struct ifnet *, int );
  251. int lagg_enqueue(struct ifnet *, struct mbuf *);
  252. SYSCTL_DECL(_net_link_lagg);
  253. #endif /* _KERNEL */
  254. #endif /* _NET_LAGG_H */