xref: /openbsd-src/usr.sbin/ospf6d/ospf6.h (revision 850e275390052b330d93020bf619a739a3c277ac)
1 /*	$OpenBSD: ospf6.h,v 1.8 2007/11/27 11:29:34 claudio Exp $ */
2 
3 /*
4  * Copyright (c) 2004, 2005, 2007 Esben Norby <norby@openbsd.org>
5  *
6  * Permission to use, copy, modify, and distribute this software for any
7  * purpose with or without fee is hereby granted, provided that the above
8  * copyright notice and this permission notice appear in all copies.
9  *
10  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17  */
18 
19 /* OSPF protocol definitions */
20 
21 #ifndef _OSPF_H_
22 #define _OSPF_H_
23 
24 #include <netinet/in.h>
25 
26 /* misc */
27 #define OSPF6_VERSION		3
28 #define IPPROTO_OSPF		89
29 #define AllSPFRouters		"ff02::5"
30 #define AllDRouters		"ff02::6"
31 
32 #define PACKET_HDR		100 /* XXX used to calculate the IP payload */
33 
34 #define DEFAULT_METRIC		10
35 #define DEFAULT_REDIST_METRIC	100
36 #define MIN_METRIC		1
37 #define MAX_METRIC		65535	/* sum & as-ext lsa use 24bit metrics */
38 
39 #define DEFAULT_PRIORITY	1
40 #define MIN_PRIORITY		0
41 #define MAX_PRIORITY		255
42 
43 #define DEFAULT_HELLO_INTERVAL	10
44 #define MIN_HELLO_INTERVAL	1
45 #define MAX_HELLO_INTERVAL	65535
46 
47 #define DEFAULT_RTR_DEAD_TIME	40
48 #define MIN_RTR_DEAD_TIME	2
49 #define MAX_RTR_DEAD_TIME	65535
50 
51 #define DEFAULT_RXMT_INTERVAL	5
52 #define MIN_RXMT_INTERVAL	5
53 #define MAX_RXMT_INTERVAL	3600
54 
55 #define DEFAULT_TRANSMIT_DELAY	1
56 #define MIN_TRANSMIT_DELAY	1
57 #define MAX_TRANSMIT_DELAY	3600
58 
59 #define DEFAULT_ADJ_TMOUT	60
60 
61 #define DEFAULT_NBR_TMOUT	86400	/* 24 hours */
62 
63 #define DEFAULT_SPF_DELAY	1
64 #define MIN_SPF_DELAY		1
65 #define MAX_SPF_DELAY		10
66 
67 #define DEFAULT_SPF_HOLDTIME	5
68 #define MIN_SPF_HOLDTIME	1
69 #define MAX_SPF_HOLDTIME	5
70 
71 #define MIN_MD_ID		0
72 #define MAX_MD_ID		255
73 
74 #define DEFAULT_INSTANCE_ID	0
75 #define MIN_INSTANCE_ID	0
76 #define MAX_INSTANCE_ID	0
77 
78 /* OSPF compatibility flags */
79 #define OSPF_OPTION_V6		0x01
80 #define OSPF_OPTION_E		0x02
81 #define OSPF_OPTION_MC		0x04
82 #define OSPF_OPTION_N		0x08
83 #define OSPF_OPTION_R		0x10
84 #define OSPF_OPTION_DC		0x20
85 
86 /* OSPF packet types */
87 #define PACKET_TYPE_HELLO	1
88 #define PACKET_TYPE_DD		2
89 #define PACKET_TYPE_LS_REQUEST	3
90 #define PACKET_TYPE_LS_UPDATE	4
91 #define PACKET_TYPE_LS_ACK	5
92 
93 /* LSA */
94 #define LS_REFRESH_TIME		1800
95 #define MIN_LS_INTERVAL		5
96 #define MIN_LS_ARRIVAL		1
97 #define DEFAULT_AGE		0
98 #define MAX_AGE			3600
99 #define CHECK_AGE		300
100 #define MAX_AGE_DIFF		900
101 #define LS_INFINITY		0xffffff
102 #define RESV_SEQ_NUM		0x80000000	/* reserved and "unused" */
103 #define INIT_SEQ_NUM		0x80000001
104 #define MAX_SEQ_NUM		0x7fffffff
105 
106 /* OSPF header */
107 struct ospf_hdr {
108 	u_int8_t		version;
109 	u_int8_t		type;
110 	u_int16_t		len;
111 	u_int32_t		rtr_id;
112 	u_int32_t		area_id;
113 	u_int16_t		chksum;
114 	u_int8_t		instance;
115 	u_int8_t		zero;		/* must be zero */
116 };
117 
118 /* Hello header (type 1) */
119 struct hello_hdr {
120 	u_int32_t		iface_id;
121 	u_int8_t		rtr_priority;
122 	u_int8_t		opts1;
123 	u_int8_t		opts2;
124 	u_int8_t		opts3;
125 	u_int16_t		hello_interval;
126 	u_int16_t		rtr_dead_interval;
127 	u_int32_t		d_rtr;
128 	u_int32_t		bd_rtr;
129 };
130 
131 /* Database Description header (type 2) */
132 struct db_dscrp_hdr {
133 	u_int32_t		opts;
134 	u_int16_t		iface_mtu;
135 	u_int8_t		zero;		/* must be zero */
136 	u_int8_t		bits;
137 	u_int32_t		dd_seq_num;
138 };
139 
140 #define OSPF_DBD_MS		0x01
141 #define OSPF_DBD_M		0x02
142 #define OSPF_DBD_I		0x04
143 
144 /*  Link State Request header (type 3) */
145 struct ls_req_hdr {
146 	u_int16_t		zero;
147 	u_int16_t		type;
148 	u_int32_t		ls_id;
149 	u_int32_t		adv_rtr;
150 };
151 
152 /* Link State Update header (type 4) */
153 struct ls_upd_hdr {
154 	u_int32_t		num_lsa;
155 };
156 
157 #define LSA_TYPE_LINK		0x0008
158 #define	LSA_TYPE_ROUTER		0x2001
159 #define LSA_TYPE_NETWORK	0x2002
160 #define LSA_TYPE_INTER_A_PREFIX	0x2003
161 #define LSA_TYPE_INTER_A_ROUTER	0x2004
162 #define LSA_TYPE_INTRA_A_PREFIX	0x2009
163 #define	LSA_TYPE_EXTERNAL	0x4005
164 
165 #define LSA_TYPE_FLAG_U		0x8000
166 #define LSA_TYPE_FLAG_S2	0x4000
167 #define LSA_TYPE_FLAG_S1	0x2000
168 #define LSA_TYPE_SCOPE_MASK	0x6000
169 
170 #define LSA_IS_SCOPE_LLOCAL(x)	\
171     (((x) & LSA_TYPE_SCOPE_MASK) == 0)
172 #define LSA_IS_SCOPE_AREA(x)	\
173     (((x) & LSA_TYPE_SCOPE_MASK) == LSA_TYPE_FLAG_S1)
174 #define LSA_IS_SCOPE_AS(x)	\
175     (((x) & LSA_TYPE_SCOPE_MASK) == LSA_TYPE_FLAG_S2)
176 
177 #define LINK_TYPE_POINTTOPOINT	1
178 #define LINK_TYPE_TRANSIT_NET	2
179 #define LINK_TYPE_RESERVED	3
180 #define LINK_TYPE_VIRTUAL	4
181 
182 /* LSA headers */
183 #define LSA_METRIC_MASK		0x00ffffff	/* only for sum & as-ext */
184 #define LSA_ASEXT_E_FLAG	0x80000000
185 
186 #define OSPF_RTR_B		0x01
187 #define OSPF_RTR_E		0x02
188 #define OSPF_RTR_V		0x04
189 #define OSPF_RTR_W		0x08
190 
191 struct lsa_prefix {
192 	struct in6_addr		prefix;
193 	u_int16_t		metric;
194 	u_int8_t		prefixlen;
195 	u_int8_t		options;
196 };
197 
198 struct lsa_rtr {
199 	u_int32_t		opts;	/* 8bit flags + 24bits options */
200 };
201 
202 struct lsa_rtr_link {
203 	u_int8_t		type;
204 	u_int8_t		dummy;
205 	u_int16_t		metric;
206 	u_int32_t		iface_id;
207 	u_int32_t		nbr_iface_id;
208 	u_int32_t		nbr_rtr_id;
209 };
210 
211 struct lsa_net {
212 	u_int32_t		mask;
213 	u_int32_t		att_rtr[1];
214 };
215 
216 struct lsa_net_link {
217 	u_int32_t		att_rtr;
218 };
219 
220 struct lsa_prefix_sum {
221 	u_int32_t		metric;		/* only lower 24 bit */
222 	/* + one prefix */
223 };
224 
225 struct lsa_rtr_sum {
226 	u_int32_t		options;	/* lower 24bit options */
227 	u_int32_t		metric;		/* only lower 24 bit */
228 	u_int32_t		dest_rtr_id;
229 };
230 
231 struct lsa_asext {
232 	u_int32_t		mask;
233 	u_int32_t		metric;		/* lower 24 bit plus E bit */
234 	u_int32_t		fw_addr;
235 	u_int32_t		ext_tag;
236 };
237 
238 struct lsa_link {
239 	u_int32_t		options;	/* rtr pri & 24bit options */
240 	struct in6_addr		lladdr;
241 	u_int32_t		numprefix;
242 	/* + numprefix prefix */
243 };
244 
245 struct lsa_intra_prefix {
246 	u_int16_t		numprefix;
247 	u_int16_t		ref_type;
248 	u_int32_t		ref_lsid;
249 	u_int32_t		ref_adv_rtr;
250 	/* + numprefix prefix */
251 };
252 
253 struct lsa_hdr {
254 	u_int16_t		age;
255 	u_int16_t		type;
256 	u_int32_t		ls_id;
257 	u_int32_t		adv_rtr;
258 	u_int32_t		seq_num;
259 	u_int16_t		ls_chksum;
260 	u_int16_t		len;
261 };
262 
263 #define LS_CKSUM_OFFSET	((u_int16_t)(&((struct lsa_hdr *)0)->ls_chksum))
264 
265 struct lsa {
266 	struct lsa_hdr		hdr;
267 	union {
268 		struct lsa_rtr		rtr;
269 		struct lsa_net		net;
270 		struct lsa_prefix_sum	pref_sum;
271 		struct lsa_rtr_sum	rtr_sum;
272 		struct lsa_asext	asext;
273 		struct lsa_link		link;
274 		struct lsa_intra_prefix pref_intra;
275 	}			data;
276 };
277 
278 #endif /* !_OSPF_H_ */
279