if_trunk.h 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230
  1. /* $OpenBSD: if_trunk.h,v 1.23 2015/05/26 11:39:07 mpi Exp $ */
  2. /*
  3. * Copyright (c) 2005, 2006, 2007 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_TRUNK_H
  18. #define _NET_TRUNK_H
  19. /*
  20. * Global definitions
  21. */
  22. #define TRUNK_MAX_PORTS 32 /* logically */
  23. #define TRUNK_MAX_NAMESIZE 32 /* name of a protocol */
  24. #define TRUNK_MAX_STACKING 4 /* maximum number of stacked trunks */
  25. /* Port flags */
  26. #define TRUNK_PORT_SLAVE 0x00000000 /* normal enslaved port */
  27. #define TRUNK_PORT_MASTER 0x00000001 /* primary port */
  28. #define TRUNK_PORT_STACK 0x00000002 /* stacked trunk port */
  29. #define TRUNK_PORT_ACTIVE 0x00000004 /* port is active */
  30. #define TRUNK_PORT_COLLECTING 0x00000008 /* port is receiving frames */
  31. #define TRUNK_PORT_DISTRIBUTING 0x00000010 /* port is sending frames */
  32. #define TRUNK_PORT_DISABLED 0x00000020 /* port is disabled */
  33. #define TRUNK_PORT_GLOBAL 0x80000000 /* IOCTL: global flag */
  34. #define TRUNK_PORT_BITS "\20\01MASTER\02STACK\03ACTIVE" \
  35. "\04COLLECTING\05DISTRIBUTING\06DISABLED"
  36. /* Supported trunk PROTOs */
  37. enum trunk_proto {
  38. TRUNK_PROTO_NONE = 0, /* no trunk protocol defined */
  39. TRUNK_PROTO_ROUNDROBIN = 1, /* simple round robin */
  40. TRUNK_PROTO_FAILOVER = 2, /* active failover */
  41. TRUNK_PROTO_LOADBALANCE = 3, /* loadbalance */
  42. TRUNK_PROTO_BROADCAST = 4, /* broadcast */
  43. TRUNK_PROTO_LACP = 5, /* 802.3ad LACP */
  44. TRUNK_PROTO_MAX = 6
  45. };
  46. struct trunk_protos {
  47. const char *tpr_name;
  48. enum trunk_proto tpr_proto;
  49. };
  50. #define TRUNK_PROTO_DEFAULT TRUNK_PROTO_ROUNDROBIN
  51. #define TRUNK_PROTOS { \
  52. { "roundrobin", TRUNK_PROTO_ROUNDROBIN }, \
  53. { "failover", TRUNK_PROTO_FAILOVER }, \
  54. { "lacp", TRUNK_PROTO_LACP }, \
  55. { "loadbalance", TRUNK_PROTO_LOADBALANCE }, \
  56. { "broadcast", TRUNK_PROTO_BROADCAST }, \
  57. { "none", TRUNK_PROTO_NONE }, \
  58. { "default", TRUNK_PROTO_DEFAULT } \
  59. }
  60. /*
  61. * Trunk ioctls.
  62. */
  63. /*
  64. * LACP current operational parameters structure.
  65. */
  66. struct lacp_opreq {
  67. u_int16_t actor_prio;
  68. u_int8_t actor_mac[ETHER_ADDR_LEN];
  69. u_int16_t actor_key;
  70. u_int16_t actor_portprio;
  71. u_int16_t actor_portno;
  72. u_int8_t actor_state;
  73. u_int16_t partner_prio;
  74. u_int8_t partner_mac[ETHER_ADDR_LEN];
  75. u_int16_t partner_key;
  76. u_int16_t partner_portprio;
  77. u_int16_t partner_portno;
  78. u_int8_t partner_state;
  79. };
  80. /* Trunk port settings */
  81. struct trunk_reqport {
  82. char rp_ifname[IFNAMSIZ]; /* name of the trunk */
  83. char rp_portname[IFNAMSIZ]; /* name of the port */
  84. u_int32_t rp_prio; /* port priority */
  85. u_int32_t rp_flags; /* port flags */
  86. union {
  87. struct lacp_opreq rpsc_lacp;
  88. } rp_psc;
  89. #define rp_lacpreq rp_psc.rpsc_lacp
  90. };
  91. #define SIOCGTRUNKPORT _IOWR('i', 140, struct trunk_reqport)
  92. #define SIOCSTRUNKPORT _IOW('i', 141, struct trunk_reqport)
  93. #define SIOCSTRUNKDELPORT _IOW('i', 142, struct trunk_reqport)
  94. /* Trunk, ports and options */
  95. struct trunk_reqall {
  96. char ra_ifname[IFNAMSIZ]; /* name of the trunk */
  97. u_int ra_proto; /* trunk protocol */
  98. size_t ra_size; /* size of buffer */
  99. struct trunk_reqport *ra_port; /* allocated buffer */
  100. int ra_ports; /* total port count */
  101. union {
  102. struct lacp_opreq rpsc_lacp;
  103. } ra_psc;
  104. #define ra_lacpreq ra_psc.rpsc_lacp
  105. };
  106. #define SIOCGTRUNK _IOWR('i', 143, struct trunk_reqall)
  107. #define SIOCSTRUNK _IOW('i', 144, struct trunk_reqall)
  108. #ifdef _KERNEL
  109. /*
  110. * Internal kernel part
  111. */
  112. struct trunk_softc;
  113. struct trunk_port {
  114. struct ifnet *tp_if; /* physical interface */
  115. struct trunk_softc *tp_trunk; /* parent trunk */
  116. u_int8_t tp_lladdr[ETHER_ADDR_LEN];
  117. caddr_t tp_psc; /* protocol data */
  118. u_char tp_iftype; /* interface type */
  119. u_int32_t tp_prio; /* port priority */
  120. u_int32_t tp_flags; /* port flags */
  121. void *lh_cookie; /* if state hook */
  122. void *dh_cookie; /* if detach hook */
  123. struct ifih tp_ifih; /* input handler */
  124. /* Redirected callbacks */
  125. void (*tp_watchdog)(struct ifnet *);
  126. int (*tp_ioctl)(struct ifnet *, u_long, caddr_t);
  127. int (*tp_output)(struct ifnet *, struct mbuf *, struct sockaddr *,
  128. struct rtentry *);
  129. SLIST_ENTRY(trunk_port) tp_entries;
  130. };
  131. #define tp_ifname tp_if->if_xname /* interface name */
  132. #define tp_ifflags tp_if->if_flags /* interface flags */
  133. #define tp_link_state tp_if->if_link_state /* link state */
  134. #define tp_capabilities tp_if->if_capabilities /* capabilities */
  135. #define TRUNK_PORTACTIVE(_tp) ( \
  136. LINK_STATE_IS_UP((_tp)->tp_link_state) && \
  137. (_tp)->tp_ifflags & IFF_UP)
  138. struct trunk_mc {
  139. union {
  140. struct ether_multi *mcu_enm;
  141. } mc_u;
  142. struct sockaddr_storage mc_addr;
  143. SLIST_ENTRY(trunk_mc) mc_entries;
  144. };
  145. #define mc_enm mc_u.mcu_enm
  146. struct trunk_ifreq {
  147. union {
  148. struct ifreq ifreq;
  149. struct {
  150. char ifr_name[IFNAMSIZ];
  151. struct sockaddr_storage ifr_ss;
  152. } ifreq_storage;
  153. } ifreq;
  154. };
  155. struct trunk_softc {
  156. struct arpcom tr_ac; /* virtual interface */
  157. int tr_unit; /* trunk unit */
  158. enum trunk_proto tr_proto; /* trunk protocol */
  159. u_int tr_count; /* number of ports */
  160. struct trunk_port *tr_primary; /* primary port */
  161. struct ifmedia tr_media; /* media config */
  162. caddr_t tr_psc; /* protocol data */
  163. SLIST_HEAD(__tplhd, trunk_port) tr_ports; /* list of interfaces */
  164. SLIST_ENTRY(trunk_softc) tr_entries;
  165. SLIST_HEAD(__mclhd, trunk_mc) tr_mc_head; /* multicast addresses */
  166. /* Trunk protocol callbacks */
  167. int (*tr_detach)(struct trunk_softc *);
  168. int (*tr_start)(struct trunk_softc *, struct mbuf *);
  169. int (*tr_watchdog)(struct trunk_softc *);
  170. int (*tr_input)(struct trunk_softc *, struct trunk_port *,
  171. struct mbuf *);
  172. int (*tr_port_create)(struct trunk_port *);
  173. void (*tr_port_destroy)(struct trunk_port *);
  174. void (*tr_linkstate)(struct trunk_port *);
  175. void (*tr_init)(struct trunk_softc *);
  176. void (*tr_stop)(struct trunk_softc *);
  177. void (*tr_req)(struct trunk_softc *, caddr_t);
  178. void (*tr_portreq)(struct trunk_port *, caddr_t);
  179. };
  180. #define tr_ifflags tr_ac.ac_if.if_flags /* flags */
  181. #define tr_ifname tr_ac.ac_if.if_xname /* name */
  182. #define tr_capabilities tr_ac.ac_if.if_capabilities /* capabilities */
  183. #define tr_ifindex tr_ac.ac_if.if_index /* int index */
  184. #define tr_lladdr tr_ac.ac_enaddr /* lladdr */
  185. #define IFCAP_TRUNK_MASK 0xffff0000 /* private capabilities */
  186. #define IFCAP_TRUNK_FULLDUPLEX 0x00010000 /* full duplex with >1 ports */
  187. /* Private data used by the loadbalancing protocol */
  188. struct trunk_lb {
  189. SIPHASH_KEY lb_key;
  190. struct trunk_port *lb_ports[TRUNK_MAX_PORTS];
  191. };
  192. int trunk_enqueue(struct ifnet *, struct mbuf *);
  193. u_int32_t trunk_hashmbuf(struct mbuf *, SIPHASH_KEY *);
  194. #endif /* _KERNEL */
  195. #endif /* _NET_TRUNK_H */