xref: /openbsd/usr.sbin/ospf6d/ospf6.h (revision fc61954a)
1 /*	$OpenBSD: ospf6.h,v 1.21 2013/03/25 14:29:35 markus 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 #include <stddef.h>
26 
27 /* misc */
28 #define OSPF6_VERSION		3
29 #define IPPROTO_OSPF		89
30 #define AllSPFRouters		"ff02::5"
31 #define AllDRouters		"ff02::6"
32 
33 #define PACKET_HDR		100 /* XXX used to calculate the IP payload */
34 
35 #define DEFAULT_METRIC		10
36 #define DEFAULT_REDIST_METRIC	100
37 #define MIN_METRIC		1
38 #define MAX_METRIC		65535	/* sum & as-ext lsa use 24bit metrics */
39 
40 #define DEFAULT_PRIORITY	1
41 #define MIN_PRIORITY		0
42 #define MAX_PRIORITY		255
43 
44 #define DEFAULT_HELLO_INTERVAL	10
45 #define MIN_HELLO_INTERVAL	1
46 #define MAX_HELLO_INTERVAL	65535
47 
48 #define DEFAULT_RTR_DEAD_TIME	40
49 #define MIN_RTR_DEAD_TIME	2
50 #define MAX_RTR_DEAD_TIME	65535
51 
52 #define DEFAULT_RXMT_INTERVAL	5
53 #define MIN_RXMT_INTERVAL	5
54 #define MAX_RXMT_INTERVAL	3600
55 
56 #define DEFAULT_TRANSMIT_DELAY	1
57 #define MIN_TRANSMIT_DELAY	1
58 #define MAX_TRANSMIT_DELAY	3600
59 
60 #define DEFAULT_ADJ_TMOUT	120
61 
62 #define DEFAULT_NBR_TMOUT	86400	/* 24 hours */
63 
64 #define DEFAULT_SPF_DELAY	1
65 #define MIN_SPF_DELAY		1
66 #define MAX_SPF_DELAY		10
67 
68 #define DEFAULT_SPF_HOLDTIME	5
69 #define MIN_SPF_HOLDTIME	1
70 #define MAX_SPF_HOLDTIME	5
71 
72 #define MIN_MD_ID		0
73 #define MAX_MD_ID		255
74 
75 #define DEFAULT_INSTANCE_ID	0
76 #define MIN_INSTANCE_ID	0
77 #define MAX_INSTANCE_ID	0
78 
79 /* OSPF compatibility flags */
80 #define OSPF_OPTION_V6		0x01
81 #define OSPF_OPTION_E		0x02
82 #define OSPF_OPTION_x		0x04	/* ignored, should be 0 */
83 #define OSPF_OPTION_N		0x08
84 #define OSPF_OPTION_R		0x10
85 #define OSPF_OPTION_DC		0x20
86 
87 /* OSPF packet types */
88 #define PACKET_TYPE_HELLO	1
89 #define PACKET_TYPE_DD		2
90 #define PACKET_TYPE_LS_REQUEST	3
91 #define PACKET_TYPE_LS_UPDATE	4
92 #define PACKET_TYPE_LS_ACK	5
93 
94 /* LSA */
95 #define LS_REFRESH_TIME		1800
96 #define MIN_LS_INTERVAL		5
97 #define MIN_LS_ARRIVAL		1
98 #define DEFAULT_AGE		0
99 #define MAX_AGE			3600
100 #define CHECK_AGE		300
101 #define MAX_AGE_DIFF		900
102 #define LS_INFINITY		0xffffff
103 #define RESV_SEQ_NUM		0x80000000U	/* reserved and "unused" */
104 #define INIT_SEQ_NUM		0x80000001U
105 #define MAX_SEQ_NUM		0x7fffffffU
106 
107 /* OSPF header */
108 struct ospf_hdr {
109 	u_int8_t		version;
110 	u_int8_t		type;
111 	u_int16_t		len;
112 	u_int32_t		rtr_id;
113 	u_int32_t		area_id;
114 	u_int16_t		chksum;
115 	u_int8_t		instance;
116 	u_int8_t		zero;		/* must be zero */
117 };
118 
119 /* Hello header (type 1) */
120 struct hello_hdr {
121 	u_int32_t		iface_id;
122 	u_int32_t		opts;	/* 8bit rtr_priority + 24bits options */
123 	u_int16_t		hello_interval;
124 	u_int16_t		rtr_dead_interval;
125 	u_int32_t		d_rtr;
126 	u_int32_t		bd_rtr;
127 };
128 
129 /* Database Description header (type 2) */
130 struct db_dscrp_hdr {
131 	u_int32_t		opts;
132 	u_int16_t		iface_mtu;
133 	u_int8_t		zero;		/* must be zero */
134 	u_int8_t		bits;
135 	u_int32_t		dd_seq_num;
136 };
137 
138 #define OSPF_DBD_MS		0x01
139 #define OSPF_DBD_M		0x02
140 #define OSPF_DBD_I		0x04
141 
142 /*  Link State Request header (type 3) */
143 struct ls_req_hdr {
144 	u_int16_t		zero;
145 	u_int16_t		type;
146 	u_int32_t		ls_id;
147 	u_int32_t		adv_rtr;
148 };
149 
150 /* Link State Update header (type 4) */
151 struct ls_upd_hdr {
152 	u_int32_t		num_lsa;
153 };
154 
155 #define LSA_TYPE_LINK		0x0008
156 #define	LSA_TYPE_ROUTER		0x2001
157 #define LSA_TYPE_NETWORK	0x2002
158 #define LSA_TYPE_INTER_A_PREFIX	0x2003
159 #define LSA_TYPE_INTER_A_ROUTER	0x2004
160 #define LSA_TYPE_INTRA_A_PREFIX	0x2009
161 #define	LSA_TYPE_EXTERNAL	0x4005
162 
163 #define LSA_TYPE_FLAG_U		0x8000
164 #define LSA_TYPE_FLAG_S2	0x4000
165 #define LSA_TYPE_FLAG_S1	0x2000
166 #define LSA_TYPE_SCOPE_MASK	0x6000
167 
168 #define LSA_IS_SCOPE_LLOCAL(x)	\
169     (((x) & LSA_TYPE_SCOPE_MASK) == 0)
170 #define LSA_IS_SCOPE_AREA(x)	\
171     (((x) & LSA_TYPE_SCOPE_MASK) == LSA_TYPE_FLAG_S1)
172 #define LSA_IS_SCOPE_AS(x)	\
173     (((x) & LSA_TYPE_SCOPE_MASK) == LSA_TYPE_FLAG_S2)
174 
175 #define LINK_TYPE_POINTTOPOINT	1
176 #define LINK_TYPE_TRANSIT_NET	2
177 #define LINK_TYPE_RESERVED	3
178 #define LINK_TYPE_VIRTUAL	4
179 
180 /* for some reason they thought 24bit types are fun, make them less a hazard */
181 #define LSA_24_MASK 0xffffff
182 #define LSA_24_GETHI(x)		\
183 	((x) >> 24)
184 #define LSA_24_GETLO(x)		\
185 	((x) & LSA_24_MASK)
186 #define LSA_24_SETHI(x, y)	\
187 	((x) = ((x) & LSA_24_MASK) | (((y) & 0xff) << 24))
188 #define LSA_24_SETLO(x, y)	\
189 	((x) = ((y) & LSA_24_MASK) | ((x) & ~LSA_24_MASK))
190 
191 /* LSA headers */
192 #define LSA_METRIC_MASK		0x00ffffff	/* only for sum & as-ext */
193 #define LSA_ASEXT_E_FLAG	0x04000000
194 #define LSA_ASEXT_F_FLAG	0x02000000
195 #define LSA_ASEXT_T_FLAG	0x01000000
196 
197 #define OSPF_RTR_B		0x01
198 #define OSPF_RTR_E		0x02
199 #define OSPF_RTR_V		0x04
200 #define OSPF_RTR_x		0x08	/* ignored, should be 0 */
201 #define OSPF_RTR_Nt		0x10
202 
203 #define OSPF_PREFIX_NU		0x01
204 #define OSPF_PREFIX_LA		0x02
205 #define OSPF_PREFIX_x		0x04	/* ignored, should be 0 */
206 #define OSPF_PREFIX_P		0x08
207 #define OSPF_PREFIX_DN		0x10
208 
209 /* return encoded IPv6 prefix size in bytes depending on the prefixlen */
210 #define LSA_PREFIXSIZE(x)	(((x) + 31)/32 * 4)
211 
212 struct lsa_prefix {
213 	u_int8_t		prefixlen;
214 	u_int8_t		options;
215 	u_int16_t		metric;	/* Ref. LS type in AS-Ext-LSA */
216 	/* + an IPv6 prefix encoded in (prefixlen + 31)/32 words */
217 };
218 
219 struct lsa_rtr {
220 	u_int32_t		opts;	/* 8bit flags + 24bits options */
221 };
222 
223 struct lsa_rtr_link {
224 	u_int8_t		type;
225 	u_int8_t		dummy;
226 	u_int16_t		metric;
227 	u_int32_t		iface_id;
228 	u_int32_t		nbr_iface_id;
229 	u_int32_t		nbr_rtr_id;
230 };
231 
232 struct lsa_net {
233 	u_int32_t		opts;	/* 24bits options */
234 };
235 
236 struct lsa_net_link {
237 	u_int32_t		att_rtr;
238 };
239 
240 struct lsa_prefix_sum {
241 	u_int32_t		metric;		/* only lower 24 bit */
242 	/* + one prefix */
243 };
244 
245 struct lsa_rtr_sum {
246 	u_int32_t		opts;		/* lower 24bit options */
247 	u_int32_t		metric;		/* only lower 24 bit */
248 	u_int32_t		dest_rtr_id;
249 };
250 
251 struct lsa_asext {
252 	u_int32_t		metric;		/* lower 24 bit plus EFT bits */
253 	struct lsa_prefix	prefix;
254 	/* + if F bit is set, an optional forwarding address (128bit) */
255 	/* + if T bit is set, an optional external route tag (32bit) */
256 	/* + if referenced LS type (i.e. prefix.metric) is non-zero, an
257 	 *   optional referenced LS ID (32bit) -- not used by OSPF itself */
258 };
259 
260 struct lsa_link {
261 	u_int32_t		opts;		/* rtr pri & 24bit options */
262 	struct in6_addr		lladdr;
263 	u_int32_t		numprefix;
264 	/* + numprefix * lsa_prefix */
265 };
266 
267 struct lsa_intra_prefix {
268 	u_int16_t		numprefix;
269 	u_int16_t		ref_type;
270 	u_int32_t		ref_ls_id;
271 	u_int32_t		ref_adv_rtr;
272 	/* + numprefix * lsa_prefix */
273 };
274 
275 struct lsa_hdr {
276 	u_int16_t		age;
277 	u_int16_t		type;
278 	u_int32_t		ls_id;
279 	u_int32_t		adv_rtr;
280 	u_int32_t		seq_num;
281 	u_int16_t		ls_chksum;
282 	u_int16_t		len;
283 };
284 
285 #define LS_CKSUM_OFFSET	offsetof(struct lsa_hdr, ls_chksum)
286 
287 struct lsa {
288 	struct lsa_hdr		hdr;
289 	union {
290 		struct lsa_rtr		rtr;
291 		struct lsa_net		net;
292 		struct lsa_prefix_sum	pref_sum;
293 		struct lsa_rtr_sum	rtr_sum;
294 		struct lsa_asext	asext;
295 		struct lsa_link		link;
296 		struct lsa_intra_prefix pref_intra;
297 	}			data;
298 };
299 
300 #endif /* !_OSPF_H_ */
301