trunklacp.h 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296
  1. /* $OpenBSD: trunklacp.h,v 1.9 2015/05/11 08:41:43 mpi Exp $ */
  2. /* $NetBSD: ieee8023ad_impl.h,v 1.2 2005/12/10 23:21:39 elad Exp $ */
  3. /*
  4. * Copyright (c)2005 YAMAMOTO Takashi,
  5. * All rights reserved.
  6. *
  7. * Redistribution and use in source and binary forms, with or without
  8. * modification, are permitted provided that the following conditions
  9. * are met:
  10. * 1. Redistributions of source code must retain the above copyright
  11. * notice, this list of conditions and the following disclaimer.
  12. * 2. Redistributions in binary form must reproduce the above copyright
  13. * notice, this list of conditions and the following disclaimer in the
  14. * documentation and/or other materials provided with the distribution.
  15. *
  16. * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
  17. * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  18. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  19. * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
  20. * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  21. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  22. * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  23. * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  24. * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  25. * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  26. * SUCH DAMAGE.
  27. *
  28. * $FreeBSD: src/sys/net/ieee8023ad_lacp.h,v 1.11 2008/03/17 01:26:44 thompsa Exp $
  29. */
  30. #ifndef _NET_TRUNKLACP_H_
  31. #define _NET_TRUNKLACP_H_
  32. /*
  33. * IEEE802.3 slow protocols (on-wire) definitions.
  34. * XXX should be elsewhere.
  35. */
  36. #define SLOWPROTOCOLS_SUBTYPE_LACP 1
  37. #define SLOWPROTOCOLS_SUBTYPE_MARKER 2
  38. struct slowprothdr {
  39. u_int8_t sph_subtype;
  40. u_int8_t sph_version;
  41. } __packed;
  42. /* TLV on-wire structure. */
  43. struct tlvhdr {
  44. u_int8_t tlv_type;
  45. u_int8_t tlv_length;
  46. /* u_int8_t tlv_value[]; */
  47. } __packed;
  48. /* ... and our implementation. */
  49. #define TLV_SET(tlv, type, length) \
  50. do { \
  51. (tlv)->tlv_type = (type); \
  52. (tlv)->tlv_length = sizeof(*tlv) + (length); \
  53. } while (/*CONSTCOND*/0)
  54. struct tlv_template {
  55. u_int8_t tmpl_type;
  56. u_int8_t tmpl_length;
  57. };
  58. struct lacp_systemid {
  59. u_int16_t lsi_prio;
  60. u_int8_t lsi_mac[6];
  61. } __packed;
  62. struct lacp_portid {
  63. u_int16_t lpi_prio;
  64. u_int16_t lpi_portno;
  65. } __packed;
  66. struct lacp_peerinfo {
  67. struct lacp_systemid lip_systemid;
  68. u_int16_t lip_key;
  69. struct lacp_portid lip_portid;
  70. u_int8_t lip_state;
  71. u_int8_t lip_resv[3];
  72. } __packed;
  73. struct lacp_collectorinfo {
  74. u_int16_t lci_maxdelay;
  75. u_int8_t lci_resv[12];
  76. } __packed;
  77. struct lacpdu {
  78. struct ether_header ldu_eh;
  79. struct slowprothdr ldu_sph;
  80. struct tlvhdr ldu_tlv_actor;
  81. struct lacp_peerinfo ldu_actor;
  82. struct tlvhdr ldu_tlv_partner;
  83. struct lacp_peerinfo ldu_partner;
  84. struct tlvhdr ldu_tlv_collector;
  85. struct lacp_collectorinfo ldu_collector;
  86. struct tlvhdr ldu_tlv_term;
  87. u_int8_t ldu_resv[50];
  88. } __packed;
  89. /*
  90. * IEEE802.3ad marker protocol (on-wire) definitions.
  91. */
  92. struct lacp_markerinfo {
  93. u_int16_t mi_rq_port;
  94. u_int8_t mi_rq_system[ETHER_ADDR_LEN];
  95. u_int32_t mi_rq_xid;
  96. u_int8_t mi_pad[2];
  97. } __packed;
  98. #ifdef _KERNEL
  99. /*
  100. * IEEE802.3ad LACP implementation details.
  101. */
  102. #define LACP_TIMER_CURRENT_WHILE 0
  103. #define LACP_TIMER_PERIODIC 1
  104. #define LACP_TIMER_WAIT_WHILE 2
  105. #define LACP_NTIMER 3
  106. #define LACP_TIMER_ARM(port, timer, val) \
  107. (port)->lp_timer[(timer)] = (val)
  108. #define LACP_TIMER_DISARM(port, timer) \
  109. (port)->lp_timer[(timer)] = 0
  110. #define LACP_TIMER_ISARMED(port, timer) \
  111. ((port)->lp_timer[(timer)] > 0)
  112. /*
  113. * IEEE802.3ad LACP protocol definitions.
  114. */
  115. #define LACP_STATE_ACTIVITY (1<<0)
  116. #define LACP_STATE_TIMEOUT (1<<1)
  117. #define LACP_STATE_AGGREGATION (1<<2)
  118. #define LACP_STATE_SYNC (1<<3)
  119. #define LACP_STATE_COLLECTING (1<<4)
  120. #define LACP_STATE_DISTRIBUTING (1<<5)
  121. #define LACP_STATE_DEFAULTED (1<<6)
  122. #define LACP_STATE_EXPIRED (1<<7)
  123. #define LACP_PORT_NTT 0x00000001
  124. #define LACP_PORT_MARK 0x00000002
  125. #define LACP_STATE_BITS \
  126. "\020" \
  127. "\001ACTIVITY" \
  128. "\002TIMEOUT" \
  129. "\003AGGREGATION" \
  130. "\004SYNC" \
  131. "\005COLLECTING" \
  132. "\006DISTRIBUTING" \
  133. "\007DEFAULTED" \
  134. "\010EXPIRED"
  135. struct markerdu {
  136. struct ether_header mdu_eh;
  137. struct slowprothdr mdu_sph;
  138. struct tlvhdr mdu_tlv;
  139. struct lacp_markerinfo mdu_info;
  140. struct tlvhdr mdu_tlv_term;
  141. u_int8_t mdu_resv[90];
  142. } __packed;
  143. #define MARKER_TYPE_INFO 0x01
  144. #define MARKER_TYPE_RESPONSE 0x02
  145. enum lacp_selected {
  146. LACP_UNSELECTED,
  147. LACP_STANDBY, /* not used in this implementation */
  148. LACP_SELECTED,
  149. };
  150. enum lacp_mux_state {
  151. LACP_MUX_DETACHED,
  152. LACP_MUX_WAITING,
  153. LACP_MUX_ATTACHED,
  154. LACP_MUX_COLLECTING,
  155. LACP_MUX_DISTRIBUTING,
  156. };
  157. #define LACP_MAX_PORTS 32
  158. struct lacp_portmap {
  159. int pm_count;
  160. struct lacp_port *pm_map[LACP_MAX_PORTS];
  161. };
  162. struct lacp_port {
  163. TAILQ_ENTRY(lacp_port) lp_dist_q;
  164. LIST_ENTRY(lacp_port) lp_next;
  165. struct lacp_softc *lp_lsc;
  166. struct trunk_port *lp_trunk;
  167. struct ifnet *lp_ifp;
  168. struct lacp_peerinfo lp_partner;
  169. struct lacp_peerinfo lp_actor;
  170. struct lacp_markerinfo lp_marker;
  171. #define lp_state lp_actor.lip_state
  172. #define lp_key lp_actor.lip_key
  173. #define lp_systemid lp_actor.lip_systemid
  174. struct timeval lp_last_lacpdu;
  175. int lp_lacpdu_sent;
  176. enum lacp_mux_state lp_mux_state;
  177. enum lacp_selected lp_selected;
  178. int lp_flags;
  179. u_int lp_media; /* XXX redundant */
  180. int lp_timer[LACP_NTIMER];
  181. struct ifmultiaddr *lp_ifma;
  182. struct lacp_aggregator *lp_aggregator;
  183. };
  184. struct lacp_aggregator {
  185. TAILQ_ENTRY(lacp_aggregator) la_q;
  186. int la_refcnt; /* num of ports which selected us */
  187. int la_nports; /* num of distributing ports */
  188. TAILQ_HEAD(, lacp_port) la_ports; /* distributing ports */
  189. struct lacp_peerinfo la_partner;
  190. struct lacp_peerinfo la_actor;
  191. int la_pending; /* number of ports in wait_while */
  192. };
  193. struct lacp_softc {
  194. struct trunk_softc *lsc_softc;
  195. struct lacp_aggregator *lsc_active_aggregator;
  196. TAILQ_HEAD(, lacp_aggregator) lsc_aggregators;
  197. int lsc_suppress_distributing;
  198. struct timeout lsc_transit_callout;
  199. struct timeout lsc_callout;
  200. LIST_HEAD(, lacp_port) lsc_ports;
  201. struct lacp_portmap lsc_pmap[2];
  202. volatile u_int lsc_activemap;
  203. SIPHASH_KEY lsc_hashkey;
  204. };
  205. #define LACP_TYPE_ACTORINFO 1
  206. #define LACP_TYPE_PARTNERINFO 2
  207. #define LACP_TYPE_COLLECTORINFO 3
  208. /* timeout values (in sec) */
  209. #define LACP_FAST_PERIODIC_TIME (1)
  210. #define LACP_SLOW_PERIODIC_TIME (30)
  211. #define LACP_SHORT_TIMEOUT_TIME (3 * LACP_FAST_PERIODIC_TIME)
  212. #define LACP_LONG_TIMEOUT_TIME (3 * LACP_SLOW_PERIODIC_TIME)
  213. #define LACP_CHURN_DETECTION_TIME (60)
  214. #define LACP_AGGREGATE_WAIT_TIME (2)
  215. #define LACP_TRANSIT_DELAY 3000 /* in msec */
  216. #define LACP_STATE_EQ(s1, s2, mask) \
  217. ((((s1) ^ (s2)) & (mask)) == 0)
  218. #define LACP_SYS_PRI(peer) (peer).lip_systemid.lsi_prio
  219. #define LACP_PORT(_lp) ((struct lacp_port *)(_lp)->tp_psc)
  220. #define LACP_SOFTC(_sc) ((struct lacp_softc *)(_sc)->tr_psc)
  221. #define LACP_LOCK_INIT(_lsc) mtx_init(&(_lsc)->lsc_mtx, \
  222. "lacp mtx", NULL, MTX_DEF)
  223. #define LACP_LOCK_DESTROY(_lsc) mtx_destroy(&(_lsc)->lsc_mtx)
  224. #define LACP_LOCK(_lsc) mtx_lock(&(_lsc)->lsc_mtx)
  225. #define LACP_UNLOCK(_lsc) mtx_unlock(&(_lsc)->lsc_mtx)
  226. #define LACP_LOCK_ASSERT(_lsc) mtx_assert(&(_lsc)->lsc_mtx, MA_OWNED)
  227. int lacp_input(struct trunk_port *, struct mbuf *);
  228. struct trunk_port *lacp_select_tx_port(struct trunk_softc *, struct mbuf *);
  229. int lacp_attach(struct trunk_softc *);
  230. int lacp_detach(struct trunk_softc *);
  231. void lacp_init(struct trunk_softc *);
  232. void lacp_stop(struct trunk_softc *);
  233. int lacp_port_create(struct trunk_port *);
  234. void lacp_port_destroy(struct trunk_port *);
  235. void lacp_linkstate(struct trunk_port *);
  236. void lacp_req(struct trunk_softc *, caddr_t);
  237. void lacp_portreq(struct trunk_port *, caddr_t);
  238. u_int lacp_port_status(struct trunk_port *);
  239. /* following constants don't include terminating NUL */
  240. #define LACP_MACSTR_MAX (2*6 + 5)
  241. #define LACP_SYSTEMPRIOSTR_MAX (4)
  242. #define LACP_SYSTEMIDSTR_MAX (LACP_SYSTEMPRIOSTR_MAX + 1 + LACP_MACSTR_MAX)
  243. #define LACP_PORTPRIOSTR_MAX (4)
  244. #define LACP_PORTNOSTR_MAX (4)
  245. #define LACP_PORTIDSTR_MAX (LACP_PORTPRIOSTR_MAX + 1 + LACP_PORTNOSTR_MAX)
  246. #define LACP_KEYSTR_MAX (4)
  247. #define LACP_PARTNERSTR_MAX \
  248. (1 + LACP_SYSTEMIDSTR_MAX + 1 + LACP_KEYSTR_MAX + 1 \
  249. + LACP_PORTIDSTR_MAX + 1)
  250. #define LACP_LAGIDSTR_MAX \
  251. (1 + LACP_PARTNERSTR_MAX + 1 + LACP_PARTNERSTR_MAX + 1)
  252. #define LACP_STATESTR_MAX (255) /* XXX */
  253. #endif /* _KERNEL */
  254. #endif /* _NET_TRUNKLACP_H_ */