xref: /illumos-gate/usr/src/cmd/cmd-inet/usr.sbin/snoop/snoop_ospf.h (revision 2a8bcb4efb45d99ac41c94a75c396b362c414f7f)
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, Version 1.0 only
6  * (the "License").  You may not use this file except in compliance
7  * with the License.
8  *
9  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10  * or http://www.opensolaris.org/os/licensing.
11  * See the License for the specific language governing permissions
12  * and limitations under the License.
13  *
14  * When distributing Covered Code, include this CDDL HEADER in each
15  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16  * If applicable, add the following below this CDDL HEADER, with the
17  * fields enclosed by brackets "[]" replaced with your own identifying
18  * information: Portions Copyright [yyyy] [name of copyright owner]
19  *
20  * CDDL HEADER END
21  */
22 /*
23  * Copyright 2004 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  */
26 
27 #ifndef _OSPF_H
28 #define	_OSPF_H
29 
30 /*
31  * Definitions for parsing OSPF packets (RFC 2328 and RFC 2740)
32  */
33 
34 #ifdef __cplusplus
35 extern "C" {
36 #endif
37 
38 #define	OSPF_TYPE_UMD	0	/* UMD's special monitoring packets */
39 #define	OSPF_TYPE_HELLO	1	/* Hello */
40 #define	OSPF_TYPE_DB	2	/* Database Description */
41 #define	OSPF_TYPE_LSR	3	/* Link State Request */
42 #define	OSPF_TYPE_LSU	4	/* Link State Update */
43 #define	OSPF_TYPE_LSA	5	/* Link State Ack */
44 #define	OSPF_TYPE_MAX	6
45 
46 extern char *ospf_types[];
47 struct bits {
48 	uint32_t bit;
49 	const char *str;
50 };
51 char *ospf_print_bits(const struct bits *, uchar_t);
52 char *ospf_print_lsa_age(long);
53 
54 /* Options *_options	*/
55 #define	OSPF_OPTION_T	0x01	/* RFC 2328 T bit: TOS support	*/
56 #define	OSPF_OPTION_E	0x02	/* E bit: External routes advertised	*/
57 #define	OSPF_OPTION_MC	0x04	/* MC bit: Multicast capable */
58 #define	OSPF_OPTION_N	0x08	/* N bit: For type-7 LSA */
59 #define	OSPF_OPTION_R	0x10	/* R bit: Router bit */
60 #define	OSPF_OPTION_DC	0x20	/* DC bit: Demand circuits */
61 
62 #define	OSPF_OPTION_V6	0x01	/* RFC 2740 V6 bit */
63 
64 /* ospf_authtype	*/
65 #define	OSPF_AUTH_NONE		0	/* No auth-data */
66 #define	OSPF_AUTH_SIMPLE	1	/* Simple password */
67 #define	OSPF_AUTH_MD5		2	/* MD5 authentication */
68 #define	OSPF_AUTH_MD5_LEN	16	/* length of MD5 authentication */
69 
70 #define	OSPF_AUTH_TYPE_MAX	3
71 
72 /* db_flags	*/
73 #define	OSPF_DB_INIT		0x04	/* "I"  */
74 #define	OSPF_DB_MORE		0x02 	/* "M"  */
75 #define	OSPF_DB_MASTER		0x01	/* "MS" */
76 
77 
78 /* ls_type	*/
79 #define	LS_TYPE_ROUTER		1   /* router link */
80 #define	LS_TYPE_NETWORK		2   /* network link */
81 #define	LS_TYPE_SUM_IP		3   /* summary link */
82 #define	LS_TYPE_SUM_ABR		4   /* summary area link */
83 #define	LS_TYPE_ASE		5   /* ASE  */
84 #define	LS_TYPE_GROUP		6   /* Group membership (multicast */
85 				    /* extensions 23 July 1991) */
86 #define	LS_TYPE_TYPE7		7   /* Type 7 LSA */
87 #define	LS_TYPE_LINK		8   /* Link LSA */
88 #define	LS_TYPE_INTRA_AP	9   /* Intra-Area-Prefix */
89 #define	LS_TYPE_MAX		10
90 #define	LS_TYPE_MASK		0x1fff
91 
92 #define	LS_TYPE_INTER_AP	3   /* RFC 2740 Inter-Area-Prefix */
93 #define	LS_TYPE_INTER_AR	4   /* RFC 2740 Inter-Area-Router */
94 
95 #define	LS6_SCOPE_LINKLOCAL	0x0000
96 #define	LS6_SCOPE_AREA		0x2000
97 #define	LS6_SCOPE_AS		0x4000
98 #define	LS6_SCOPE_MASK		0x6000
99 
100 /* rla_link.link_type	*/
101 #define	RLA_TYPE_ROUTER		1   /* point-to-point to another router	*/
102 #define	RLA_TYPE_TRANSIT	2   /* connection to transit network	*/
103 #define	RLA_TYPE_STUB		3   /* connection to stub network	*/
104 #define	RLA_TYPE_VIRTUAL	4   /* virtual link			*/
105 
106 /* rla_flags	*/
107 #define	RLA_FLAG_B	0x01
108 #define	RLA_FLAG_E	0x02
109 #define	RLA_FLAG_V	0x04
110 #define	RLA_FLAG_W	0x08
111 
112 
113 /* sla_tosmetric breakdown	*/
114 #define	SLA_MASK_TOS		0x7f000000
115 #define	SLA_MASK_METRIC		0x00ffffff
116 #define	SLA_SHIFT_TOS		24
117 
118 /* asla_tosmetric breakdown	*/
119 #define	ASLA_FLAG_EXTERNAL	0x80000000
120 #define	ASLA_MASK_TOS		0x7f000000
121 #define	ASLA_SHIFT_TOS		24
122 #define	ASLA_MASK_METRIC	0x00ffffff
123 
124 /* multicast vertex type 	*/
125 #define	MCLA_VERTEX_ROUTER	1
126 #define	MCLA_VERTEX_NETWORK	2
127 
128 /* link state advertisement header */
129 struct lsa_hdr {
130 	ushort_t ls_age;
131 	uchar_t ls_options;
132 	uchar_t ls_type;
133 	struct in_addr ls_stateid;
134 	struct in_addr ls_router;
135 	uint32_t ls_seq;
136 	ushort_t ls_chksum;
137 	ushort_t ls_length;
138 };
139 
140 /* link state advertisement */
141 struct lsa {
142 	struct lsa_hdr ls_hdr;
143 
144 	/* Link state types */
145 	union {
146 		/* Router links advertisements */
147 		struct {
148 			uchar_t rla_flags;
149 			uchar_t rla_zero[1];
150 			ushort_t rla_count;
151 			struct rlalink {
152 				struct in_addr link_id;
153 				struct in_addr link_data;
154 				uchar_t link_type;
155 				uchar_t link_toscount;
156 				ushort_t link_tos0metric;
157 			} rla_link[1];		/* may repeat	*/
158 		} un_rla;
159 
160 		/* Network links advertisements */
161 		struct {
162 			struct in_addr nla_mask;
163 			struct in_addr nla_router[1];	/* may repeat	*/
164 		} un_nla;
165 
166 		/* Summary links advertisements */
167 		struct {
168 			struct in_addr sla_mask;
169 			uint32_t sla_tosmetric[1];	/* may repeat	*/
170 		} un_sla;
171 
172 		/* AS external links advertisements */
173 		struct {
174 			struct in_addr asla_mask;
175 			struct aslametric {
176 				uint32_t asla_tosmetric;
177 				struct in_addr asla_forward;
178 				struct in_addr asla_tag;
179 			} asla_metric[1];		/* may repeat	*/
180 		} un_asla;
181 
182 		/* Multicast group membership */
183 		struct mcla {
184 			uint32_t mcla_vtype;
185 			struct in_addr mcla_vid;
186 		} un_mcla[1];
187 	} lsa_un;
188 };
189 
190 /*
191  * TOS metric struct (will be 0 or more in router links update)
192  */
193 struct tos_metric {
194 	uchar_t tos_type;
195 	uchar_t tos_zero;
196 	ushort_t tos_metric;
197 };
198 
199 /*
200  * OSPF minimum header sizes
201  */
202 #define	OSPF_AUTH_SIZE			8
203 #define	OSPF_MIN_HEADER_SIZE		24
204 #define	OSPF6_MIN_HEADER_SIZE		16
205 #define	OSPF_MIN_HELLO_HEADER_SIZE	20
206 #define	OSPF_MIN_DB_HEADER_SIZE		8
207 #define	OSPF6_MIN_DB_HEADER_SIZE	12
208 #define	OSPF_MIN_LSR_HEADER_SIZE	12
209 #define	OSPF_MIN_LSU_HEADER_SIZE	4
210 
211 /*
212  * ospf packet header
213  */
214 struct ospfhdr {
215 	uchar_t ospf_version;
216 	uchar_t ospf_type;
217 	ushort_t ospf_len;
218 	struct in_addr ospf_routerid;
219 	struct in_addr ospf_areaid;
220 	ushort_t ospf_chksum;
221 	ushort_t ospf_authtype;
222 	uchar_t ospf_authdata[OSPF_AUTH_SIZE];
223 	union {
224 
225 		/* Hello packet */
226 		struct {
227 			struct in_addr hello_mask;
228 			ushort_t hello_helloint;
229 			uchar_t hello_options;
230 			uchar_t hello_priority;
231 			uint32_t hello_deadint;
232 			struct in_addr hello_dr;
233 			struct in_addr hello_bdr;
234 			struct in_addr hello_neighbor[1]; /* may repeat	*/
235 		} un_hello;
236 
237 		/* Database Description packet */
238 		struct {
239 			uchar_t db_zero[2];
240 			uchar_t db_options;
241 			uchar_t db_flags;
242 			uint32_t db_seq;
243 			struct lsa_hdr db_lshdr[1];	/* may repeat */
244 		} un_db;
245 
246 		/* Link State Request */
247 		struct lsr {
248 			uint32_t ls_type;
249 			struct in_addr ls_stateid;
250 			struct in_addr ls_router;
251 		} un_lsr[1];				/* may repeat */
252 
253 		/* Link State Update */
254 		struct {
255 			uint32_t lsu_count;
256 			struct lsa lsu_lsa[1]; 		/* may repeat */
257 		} un_lsu;
258 
259 		/* Link State Acknowledgement */
260 		struct {
261 			struct lsa_hdr lsa_lshdr[1]; 	/* may repeat */
262 		} un_lsa;
263 	} ospf_un;
264 };
265 
266 #define	ospf_hello	ospf_un.un_hello
267 #define	ospf_db		ospf_un.un_db
268 #define	ospf_lsr	ospf_un.un_lsr
269 #define	ospf_lsu	ospf_un.un_lsu
270 #define	ospf_lsa	ospf_un.un_lsa
271 
272 
273 
274 #ifdef __cplusplus
275 }
276 #endif
277 
278 #endif /* _OSPF_H */
279