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