if_bridgevar.h 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325
  1. /* $NetBSD: if_bridgevar.h,v 1.4 2003/07/08 07:13:50 itojun Exp $ */
  2. /*
  3. * SPDX-License-Identifier: BSD-4-Clause
  4. *
  5. * Copyright 2001 Wasabi Systems, Inc.
  6. * All rights reserved.
  7. *
  8. * Written by Jason R. Thorpe for Wasabi Systems, Inc.
  9. *
  10. * Redistribution and use in source and binary forms, with or without
  11. * modification, are permitted provided that the following conditions
  12. * are met:
  13. * 1. Redistributions of source code must retain the above copyright
  14. * notice, this list of conditions and the following disclaimer.
  15. * 2. Redistributions in binary form must reproduce the above copyright
  16. * notice, this list of conditions and the following disclaimer in the
  17. * documentation and/or other materials provided with the distribution.
  18. * 3. All advertising materials mentioning features or use of this software
  19. * must display the following acknowledgement:
  20. * This product includes software developed for the NetBSD Project by
  21. * Wasabi Systems, Inc.
  22. * 4. The name of Wasabi Systems, Inc. may not be used to endorse
  23. * or promote products derived from this software without specific prior
  24. * written permission.
  25. *
  26. * THIS SOFTWARE IS PROVIDED BY WASABI SYSTEMS, INC. ``AS IS'' AND
  27. * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
  28. * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  29. * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL WASABI SYSTEMS, INC
  30. * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  31. * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  32. * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  33. * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  34. * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  35. * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  36. * POSSIBILITY OF SUCH DAMAGE.
  37. */
  38. /*
  39. * Copyright (c) 1999, 2000 Jason L. Wright (jason@thought.net)
  40. * All rights reserved.
  41. *
  42. * Redistribution and use in source and binary forms, with or without
  43. * modification, are permitted provided that the following conditions
  44. * are met:
  45. * 1. Redistributions of source code must retain the above copyright
  46. * notice, this list of conditions and the following disclaimer.
  47. * 2. Redistributions in binary form must reproduce the above copyright
  48. * notice, this list of conditions and the following disclaimer in the
  49. * documentation and/or other materials provided with the distribution.
  50. * 3. All advertising materials mentioning features or use of this software
  51. * must display the following acknowledgement:
  52. * This product includes software developed by Jason L. Wright
  53. * 4. The name of the author may not be used to endorse or promote products
  54. * derived from this software without specific prior written permission.
  55. *
  56. * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
  57. * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  58. * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  59. * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
  60. * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  61. * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  62. * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  63. * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
  64. * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
  65. * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  66. * POSSIBILITY OF SUCH DAMAGE.
  67. *
  68. * OpenBSD: if_bridge.h,v 1.14 2001/03/22 03:48:29 jason Exp
  69. */
  70. /*
  71. * Data structure and control definitions for bridge interfaces.
  72. */
  73. #include <sys/types.h>
  74. #include <sys/callout.h>
  75. #include <sys/queue.h>
  76. #include <sys/condvar.h>
  77. #include <net/ethernet.h>
  78. #include <net/if.h>
  79. /*
  80. * Commands used in the SIOCSDRVSPEC ioctl. Note the lookup of the
  81. * bridge interface itself is keyed off the ifdrv structure.
  82. */
  83. #define BRDGADD 0 /* add bridge member (ifbreq) */
  84. #define BRDGDEL 1 /* delete bridge member (ifbreq) */
  85. #define BRDGGIFFLGS 2 /* get member if flags (ifbreq) */
  86. #define BRDGSIFFLGS 3 /* set member if flags (ifbreq) */
  87. #define BRDGSCACHE 4 /* set cache size (ifbrparam) */
  88. #define BRDGGCACHE 5 /* get cache size (ifbrparam) */
  89. #define BRDGGIFS 6 /* get member list (ifbifconf) */
  90. #define BRDGRTS 7 /* get address list (ifbaconf) */
  91. #define BRDGSADDR 8 /* set static address (ifbareq) */
  92. #define BRDGSTO 9 /* set cache timeout (ifbrparam) */
  93. #define BRDGGTO 10 /* get cache timeout (ifbrparam) */
  94. #define BRDGDADDR 11 /* delete address (ifbareq) */
  95. #define BRDGFLUSH 12 /* flush address cache (ifbreq) */
  96. #define BRDGGPRI 13 /* get priority (ifbrparam) */
  97. #define BRDGSPRI 14 /* set priority (ifbrparam) */
  98. #define BRDGGHT 15 /* get hello time (ifbrparam) */
  99. #define BRDGSHT 16 /* set hello time (ifbrparam) */
  100. #define BRDGGFD 17 /* get forward delay (ifbrparam) */
  101. #define BRDGSFD 18 /* set forward delay (ifbrparam) */
  102. #define BRDGGMA 19 /* get max age (ifbrparam) */
  103. #define BRDGSMA 20 /* set max age (ifbrparam) */
  104. #define BRDGSIFPRIO 21 /* set if priority (ifbreq) */
  105. #define BRDGSIFCOST 22 /* set if path cost (ifbreq) */
  106. #define BRDGADDS 23 /* add bridge span member (ifbreq) */
  107. #define BRDGDELS 24 /* delete bridge span member (ifbreq) */
  108. #define BRDGPARAM 25 /* get bridge STP params (ifbropreq) */
  109. #define BRDGGRTE 26 /* get cache drops (ifbrparam) */
  110. #define BRDGGIFSSTP 27 /* get member STP params list
  111. * (ifbpstpconf) */
  112. #define BRDGSPROTO 28 /* set protocol (ifbrparam) */
  113. #define BRDGSTXHC 29 /* set tx hold count (ifbrparam) */
  114. #define BRDGSIFAMAX 30 /* set max interface addrs (ifbreq) */
  115. /*
  116. * Generic bridge control request.
  117. */
  118. struct ifbreq {
  119. char ifbr_ifsname[IFNAMSIZ]; /* member if name */
  120. uint32_t ifbr_ifsflags; /* member if flags */
  121. uint32_t ifbr_stpflags; /* member if STP flags */
  122. uint32_t ifbr_path_cost; /* member if STP cost */
  123. uint8_t ifbr_portno; /* member if port number */
  124. uint8_t ifbr_priority; /* member if STP priority */
  125. uint8_t ifbr_proto; /* member if STP protocol */
  126. uint8_t ifbr_role; /* member if STP role */
  127. uint8_t ifbr_state; /* member if STP state */
  128. uint32_t ifbr_addrcnt; /* member if addr number */
  129. uint32_t ifbr_addrmax; /* member if addr max */
  130. uint32_t ifbr_addrexceeded; /* member if addr violations */
  131. uint8_t pad[32];
  132. };
  133. /* BRDGGIFFLAGS, BRDGSIFFLAGS */
  134. #define IFBIF_LEARNING 0x0001 /* if can learn */
  135. #define IFBIF_DISCOVER 0x0002 /* if sends packets w/ unknown dest. */
  136. #define IFBIF_STP 0x0004 /* if participates in spanning tree */
  137. #define IFBIF_SPAN 0x0008 /* if is a span port */
  138. #define IFBIF_STICKY 0x0010 /* if learned addresses stick */
  139. #define IFBIF_BSTP_EDGE 0x0020 /* member stp edge port */
  140. #define IFBIF_BSTP_AUTOEDGE 0x0040 /* member stp autoedge enabled */
  141. #define IFBIF_BSTP_PTP 0x0080 /* member stp point to point */
  142. #define IFBIF_BSTP_AUTOPTP 0x0100 /* member stp autoptp enabled */
  143. #define IFBIF_BSTP_ADMEDGE 0x0200 /* member stp admin edge enabled */
  144. #define IFBIF_BSTP_ADMCOST 0x0400 /* member stp admin path cost */
  145. #define IFBIF_PRIVATE 0x0800 /* if is a private segment */
  146. #define IFBIFBITS "\020\001LEARNING\002DISCOVER\003STP\004SPAN" \
  147. "\005STICKY\014PRIVATE\006EDGE\007AUTOEDGE\010PTP" \
  148. "\011AUTOPTP"
  149. #define IFBIFMASK ~(IFBIF_BSTP_EDGE|IFBIF_BSTP_AUTOEDGE|IFBIF_BSTP_PTP| \
  150. IFBIF_BSTP_AUTOPTP|IFBIF_BSTP_ADMEDGE| \
  151. IFBIF_BSTP_ADMCOST) /* not saved */
  152. /* BRDGFLUSH */
  153. #define IFBF_FLUSHDYN 0x00 /* flush learned addresses only */
  154. #define IFBF_FLUSHALL 0x01 /* flush all addresses */
  155. /*
  156. * Interface list structure.
  157. */
  158. struct ifbifconf {
  159. uint32_t ifbic_len; /* buffer size */
  160. union {
  161. caddr_t ifbicu_buf;
  162. struct ifbreq *ifbicu_req;
  163. } ifbic_ifbicu;
  164. #define ifbic_buf ifbic_ifbicu.ifbicu_buf
  165. #define ifbic_req ifbic_ifbicu.ifbicu_req
  166. };
  167. /*
  168. * Bridge address request.
  169. */
  170. struct ifbareq {
  171. char ifba_ifsname[IFNAMSIZ]; /* member if name */
  172. unsigned long ifba_expire; /* address expire time */
  173. uint8_t ifba_flags; /* address flags */
  174. uint8_t ifba_dst[ETHER_ADDR_LEN];/* destination address */
  175. uint16_t ifba_vlan; /* vlan id */
  176. };
  177. #define IFBAF_TYPEMASK 0x03 /* address type mask */
  178. #define IFBAF_DYNAMIC 0x00 /* dynamically learned address */
  179. #define IFBAF_STATIC 0x01 /* static address */
  180. #define IFBAF_STICKY 0x02 /* sticky address */
  181. #define IFBAFBITS "\020\1STATIC\2STICKY"
  182. /*
  183. * Address list structure.
  184. */
  185. struct ifbaconf {
  186. uint32_t ifbac_len; /* buffer size */
  187. union {
  188. caddr_t ifbacu_buf;
  189. struct ifbareq *ifbacu_req;
  190. } ifbac_ifbacu;
  191. #define ifbac_buf ifbac_ifbacu.ifbacu_buf
  192. #define ifbac_req ifbac_ifbacu.ifbacu_req
  193. };
  194. /*
  195. * Bridge parameter structure.
  196. */
  197. struct ifbrparam {
  198. union {
  199. uint32_t ifbrpu_int32;
  200. uint16_t ifbrpu_int16;
  201. uint8_t ifbrpu_int8;
  202. } ifbrp_ifbrpu;
  203. };
  204. #define ifbrp_csize ifbrp_ifbrpu.ifbrpu_int32 /* cache size */
  205. #define ifbrp_ctime ifbrp_ifbrpu.ifbrpu_int32 /* cache time (sec) */
  206. #define ifbrp_prio ifbrp_ifbrpu.ifbrpu_int16 /* bridge priority */
  207. #define ifbrp_proto ifbrp_ifbrpu.ifbrpu_int8 /* bridge protocol */
  208. #define ifbrp_txhc ifbrp_ifbrpu.ifbrpu_int8 /* bpdu tx holdcount */
  209. #define ifbrp_hellotime ifbrp_ifbrpu.ifbrpu_int8 /* hello time (sec) */
  210. #define ifbrp_fwddelay ifbrp_ifbrpu.ifbrpu_int8 /* fwd time (sec) */
  211. #define ifbrp_maxage ifbrp_ifbrpu.ifbrpu_int8 /* max age (sec) */
  212. #define ifbrp_cexceeded ifbrp_ifbrpu.ifbrpu_int32 /* # of cache dropped
  213. * adresses */
  214. /*
  215. * Bridge current operational parameters structure.
  216. */
  217. struct ifbropreq {
  218. uint8_t ifbop_holdcount;
  219. uint8_t ifbop_maxage;
  220. uint8_t ifbop_hellotime;
  221. uint8_t ifbop_fwddelay;
  222. uint8_t ifbop_protocol;
  223. uint16_t ifbop_priority;
  224. uint16_t ifbop_root_port;
  225. uint32_t ifbop_root_path_cost;
  226. uint64_t ifbop_bridgeid;
  227. uint64_t ifbop_designated_root;
  228. uint64_t ifbop_designated_bridge;
  229. struct timeval ifbop_last_tc_time;
  230. };
  231. /*
  232. * Bridge member operational STP params structure.
  233. */
  234. struct ifbpstpreq {
  235. uint8_t ifbp_portno; /* bp STP port number */
  236. uint32_t ifbp_fwd_trans; /* bp STP fwd transitions */
  237. uint32_t ifbp_design_cost; /* bp STP designated cost */
  238. uint32_t ifbp_design_port; /* bp STP designated port */
  239. uint64_t ifbp_design_bridge; /* bp STP designated bridge */
  240. uint64_t ifbp_design_root; /* bp STP designated root */
  241. };
  242. /*
  243. * Bridge STP ports list structure.
  244. */
  245. struct ifbpstpconf {
  246. uint32_t ifbpstp_len; /* buffer size */
  247. union {
  248. caddr_t ifbpstpu_buf;
  249. struct ifbpstpreq *ifbpstpu_req;
  250. } ifbpstp_ifbpstpu;
  251. #define ifbpstp_buf ifbpstp_ifbpstpu.ifbpstpu_buf
  252. #define ifbpstp_req ifbpstp_ifbpstpu.ifbpstpu_req
  253. };
  254. #define STP_STATES \
  255. "disabled", \
  256. "listening", \
  257. "learning", \
  258. "forwarding", \
  259. "blocking", \
  260. "discarding"
  261. #define STP_PROTOS \
  262. "stp", \
  263. "-", \
  264. "rstp"
  265. #define STP_ROLES \
  266. "disabled", \
  267. "root", \
  268. "designated", \
  269. "alternate", \
  270. "backup"
  271. #define PV2ID(pv, epri, eaddr) do { \
  272. epri = pv >> 48; \
  273. eaddr[0] = pv >> 40; \
  274. eaddr[1] = pv >> 32; \
  275. eaddr[2] = pv >> 24; \
  276. eaddr[3] = pv >> 16; \
  277. eaddr[4] = pv >> 8; \
  278. eaddr[5] = pv >> 0; \
  279. } while (0)
  280. #ifdef _KERNEL
  281. #define BRIDGE_INPUT(_ifp, _m) do { \
  282. KASSERT((_ifp)->if_bridge_input != NULL, \
  283. ("%s: if_bridge not loaded!", __func__)); \
  284. _m = (*(_ifp)->if_bridge_input)(_ifp, _m); \
  285. if (_m != NULL) { \
  286. _ifp = _m->m_pkthdr.rcvif; \
  287. m->m_flags &= ~M_BRIDGE_INJECT; \
  288. } \
  289. } while (0)
  290. #define BRIDGE_OUTPUT(_ifp, _m, _err) do { \
  291. KASSERT((_ifp)->if_bridge_output != NULL, \
  292. ("%s: if_bridge not loaded!", __func__)); \
  293. _err = (*(_ifp)->if_bridge_output)(_ifp, _m, NULL, NULL); \
  294. } while (0)
  295. extern void (*bridge_dn_p)(struct mbuf *, struct ifnet *);
  296. #endif /* _KERNEL */