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