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