xref: /illumos-gate/usr/src/uts/common/net/trill.h (revision b210e77709da8e42dfe621e10ccf4be504206058)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License (the "License").
6  * You may not use this file except in compliance with the License.
7  *
8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9  * or http://www.opensolaris.org/os/licensing.
10  * See the License for the specific language governing permissions
11  * and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL HEADER in each
14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15  * If applicable, add the following below this CDDL HEADER, with the
16  * fields enclosed by brackets "[]" replaced with your own identifying
17  * information: Portions Copyright [yyyy] [name of copyright owner]
18  *
19  * CDDL HEADER END
20  */
21 
22 /*
23  * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  */
26 
27 #ifndef _NET_TRILL_H
28 #define	_NET_TRILL_H
29 
30 #include <sys/types.h>
31 #include <sys/param.h>
32 #include <sys/ethernet.h>
33 
34 #ifdef __cplusplus
35 extern "C" {
36 #endif
37 
38 /* Various well-known Ethernet addresses used by TRILL */
39 #define	ALL_RBRIDGES		{ 0x01, 0x80, 0xC2, 0x00, 0x02, 0x00 }
40 #define	ALL_ISIS_RBRIDGES	{ 0x01, 0x80, 0xC2, 0x00, 0x02, 0x01 }
41 #define	ALL_ESADI_RBRIDGES	{ 0x01, 0x80, 0xC2, 0x00, 0x02, 0x02 }
42 
43 #define	TRILL_PROTOCOL_VERS 0	/* th_version */
44 #define	TRILL_DEFAULT_HOPS 21	/* th_hopcount */
45 
46 /* Nickname range */
47 #define	RBRIDGE_NICKNAME_MIN		0x0000
48 #define	RBRIDGE_NICKNAME_MAX		0xFFFF
49 
50 /* Define well-known nicknames */
51 #define	RBRIDGE_NICKNAME_NONE		RBRIDGE_NICKNAME_MIN
52 #define	RBRIDGE_NICKNAME_MINRES		0xFFC0
53 #define	RBRIDGE_NICKNAME_MAXRES		(RBRIDGE_NICKNAME_MAX - 1)
54 #define	RBRIDGE_NICKNAME_UNUSED		RBRIDGE_NICKNAME_MAX
55 
56 #define	MIN_RBRIDGE_RANDOM_NICKNAME	(RBRIDGE_NICKNAME_NONE + 1)
57 #define	MAX_RBRIDGE_RANDOM_NICKNAME	(RBRIDGE_NICKNAME_MINRES - 1)
58 
59 /* AF_TRILL IOCTL codes */
60 #define	TRILL_BASE	(0x54524c00)	/* base (TRL in hex) */
61 #define	TRILL_SETNICK	(TRILL_BASE + 0)    /* trill_node_t */
62 #define	TRILL_GETNICK	(TRILL_BASE + 1)    /* uint16_t */
63 #define	TRILL_ADDNICK	(TRILL_BASE + 2)    /* trill_node_t */
64 #define	TRILL_DELNICK	(TRILL_BASE + 3)    /* uint16_t */
65 #define	TRILL_DELALL	(TRILL_BASE + 4)    /* void */
66 #define	TRILL_HWADDR	(TRILL_BASE + 5)    /* uint8_t[ETHERADDRL] */
67 #define	TRILL_TREEROOT	(TRILL_BASE + 6)    /* uint16_t */
68 #define	TRILL_NEWBRIDGE	(TRILL_BASE + 7)    /* char[MAXLINKNAMELEN] */
69 #define	TRILL_VLANFWDER	(TRILL_BASE + 8)    /* uint8_t[TRILL_VLANS_ARRSIZE] */
70 #define	TRILL_DESIGVLAN (TRILL_BASE + 9)    /* uint16_t */
71 #define	TRILL_LISTNICK	(TRILL_BASE + 10)   /* trill_listnick_t */
72 #define	TRILL_GETBRIDGE	(TRILL_BASE + 11)   /* char[MAXLINKNAMELEN] */
73 #define	TRILL_PORTFLUSH	(TRILL_BASE + 12)   /* uint16_t */
74 #define	TRILL_NICKFLUSH	(TRILL_BASE + 13)   /* uint16_t */
75 #define	TRILL_GETMTU	(TRILL_BASE + 14)   /* uint_t * */
76 
77 typedef struct trill_header {
78 #ifdef	_BIT_FIELDS_HTOL
79 	uint8_t th_version : 2;
80 	uint8_t th_reserved : 2;
81 	uint8_t th_multidest : 1;
82 	uint8_t th_optslen_hi : 3;
83 #else
84 	uint8_t th_optslen_hi : 3;
85 	uint8_t th_multidest : 1;
86 	uint8_t th_reserved : 2;
87 	uint8_t th_version : 2;
88 #endif
89 
90 #ifdef	_BIT_FIELDS_HTOL
91 	uint8_t th_optslen_lo : 2;
92 	uint8_t th_hopcount : 6;
93 #else
94 	uint8_t th_hopcount : 6;
95 	uint8_t th_optslen_lo : 2;
96 #endif
97 	uint16_t th_egressnick;
98 	uint16_t th_ingressnick;
99 } trill_header_t;
100 
101 #define	TRILL_HDR_ALIGN		(sizeof (uint16_t))
102 
103 #define	SET_TRILL_OPTS_LEN(hdr_p, val) \
104 	do { \
105 		(hdr_p)->th_optslen_lo = (val)&0x03;	\
106 		(hdr_p)->th_optslen_hi = (val)>>2;	\
107 		_NOTE(CONSTANTCONDITION)		\
108 	} while (0)
109 
110 #define	GET_TRILL_OPTS_LEN(hdr_p) \
111 	((hdr_p)->th_optslen_lo|((hdr_p)->th_optslen_hi<<2))
112 
113 /* RBridge nick and tree information (*variable* size) */
114 typedef struct trill_nickinfo_s {
115 	/* Nickname of the RBridge */
116 	uint16_t	tni_nick;
117 	/* Next-hop SNPA address to reach this RBridge */
118 	ether_addr_t	tni_adjsnpa;
119 	/* Link on our system to use to reach next-hop */
120 	datalink_id_t	tni_linkid;
121 	/* Num of *our* adjacencies on a tree rooted at this RBridge */
122 	uint16_t	tni_adjcount;
123 	/* Num of distribution tree root nicks chosen by this RBridge */
124 	uint16_t	tni_dtrootcount;
125 	/*
126 	 * Variable size bytes to store adjacency nicks, distribution
127 	 * tree roots and VLAN filter lists. Adjacency nicks and
128 	 * distribution tree roots are 16-bit fields.
129 	 *
130 	 * Number of VLAN filter lists is equal to tni_adjcount as
131 	 * the VLAN filter list is one per adjacency in each DT.
132 	 * VLAN filter list is a 512 byte bitmap with the set of VLANs
133 	 * that are reachable downstream via the adjacency.
134 	 */
135 } trill_nickinfo_t;
136 
137 typedef struct trill_listnick_s {
138 	uint16_t	tln_nick;
139 	ether_addr_t	tln_nexthop;
140 	datalink_id_t	tln_linkid;
141 	boolean_t	tln_ours;
142 } trill_listnick_t;
143 
144 /* Access the adjacency nick list at the end of trill_nickinfo_t */
145 #define	TNI_ADJNICKSPTR(v) ((uint16_t *)((trill_nickinfo_t *)(v)+1))
146 #define	TNI_ADJNICK(v, n) (TNI_ADJNICKSPTR(v)[(n)])
147 
148 /* Access the DT root nick list in trill_nickinfo_t after adjacency nicks */
149 #define	TNI_DTROOTNICKSPTR(v) (TNI_ADJNICKSPTR(v)+(v)->tni_adjcount)
150 #define	TNI_DTROOTNICK(v, n) (TNI_DTROOTNICKSPTR(v)[(n)])
151 
152 /* Access the VLAN filter list in trill_nickinfo_t after DT Roots */
153 #define	TNI_VLANFILTERSPTR(v) (TNI_DTROOTNICKSPTR(v)+(v)->tni_dtrootcount)
154 #define	TNI_VLANFILTERMAP(v, n) \
155 	(((uint8_t *)(TNI_VLANFILTERSPTR(v)))+((n)*((1<<12)/NBBY)))
156 
157 #define	TNI_TOTALSIZE(v) (sizeof (trill_nickinfo_t) + \
158 	(sizeof (uint16_t) * (v)->tni_adjcount) + \
159 	(sizeof (uint16_t) * (v)->tni_dtrootcount) + \
160 	(((1<<12)/NBBY) * (v)->tni_adjcount))
161 
162 /*
163  * This is a special value used in the sockaddr_dl "selector" field to denote
164  * that the packet represents a Bridging PDU.  The core STP instance is not
165  * defined on a VLAN, so this overload is safe.  All other selector values are
166  * used for TRILL IS-IS PDUs to indicate VLAN ID.
167  */
168 #define	TRILL_TCI_BPDU	0xFFFF
169 
170 #ifdef __cplusplus
171 }
172 #endif
173 
174 #endif /* _NET_TRILL_H */
175