xref: /openbsd-src/usr.sbin/ospf6d/ospf6.h (revision dd3b9a80516716eb7d3616a923f2076c1f1589de)
1*dd3b9a80Ssthen /*	$OpenBSD: ospf6.h,v 1.22 2023/06/21 09:47:03 sthen Exp $ */
2a1a4e97bSnorby 
3a1a4e97bSnorby /*
4a1a4e97bSnorby  * Copyright (c) 2004, 2005, 2007 Esben Norby <norby@openbsd.org>
5a1a4e97bSnorby  *
6a1a4e97bSnorby  * Permission to use, copy, modify, and distribute this software for any
7a1a4e97bSnorby  * purpose with or without fee is hereby granted, provided that the above
8a1a4e97bSnorby  * copyright notice and this permission notice appear in all copies.
9a1a4e97bSnorby  *
10a1a4e97bSnorby  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11a1a4e97bSnorby  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12a1a4e97bSnorby  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13a1a4e97bSnorby  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14a1a4e97bSnorby  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15a1a4e97bSnorby  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16a1a4e97bSnorby  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17a1a4e97bSnorby  */
18a1a4e97bSnorby 
19a1a4e97bSnorby /* OSPF protocol definitions */
20a1a4e97bSnorby 
21a1a4e97bSnorby #ifndef _OSPF_H_
22a1a4e97bSnorby #define _OSPF_H_
23a1a4e97bSnorby 
24a1a4e97bSnorby #include <netinet/in.h>
25a6417e4fSclaudio #include <stddef.h>
26a1a4e97bSnorby 
27a1a4e97bSnorby /* misc */
28a1a4e97bSnorby #define OSPF6_VERSION		3
29a1a4e97bSnorby #define IPPROTO_OSPF		89
30a1a4e97bSnorby #define AllSPFRouters		"ff02::5"
31a1a4e97bSnorby #define AllDRouters		"ff02::6"
32a1a4e97bSnorby 
33a1a4e97bSnorby #define PACKET_HDR		100 /* XXX used to calculate the IP payload */
34a1a4e97bSnorby 
35a1a4e97bSnorby #define DEFAULT_METRIC		10
36a1a4e97bSnorby #define DEFAULT_REDIST_METRIC	100
37a1a4e97bSnorby #define MIN_METRIC		1
38a1a4e97bSnorby #define MAX_METRIC		65535	/* sum & as-ext lsa use 24bit metrics */
39a1a4e97bSnorby 
40a1a4e97bSnorby #define DEFAULT_PRIORITY	1
41a1a4e97bSnorby #define MIN_PRIORITY		0
42a1a4e97bSnorby #define MAX_PRIORITY		255
43a1a4e97bSnorby 
44a1a4e97bSnorby #define DEFAULT_HELLO_INTERVAL	10
45a1a4e97bSnorby #define MIN_HELLO_INTERVAL	1
46a1a4e97bSnorby #define MAX_HELLO_INTERVAL	65535
47a1a4e97bSnorby 
48a1a4e97bSnorby #define DEFAULT_RTR_DEAD_TIME	40
49a1a4e97bSnorby #define MIN_RTR_DEAD_TIME	2
50b7ab0734Sclaudio #define MAX_RTR_DEAD_TIME	65535
51a1a4e97bSnorby 
52a1a4e97bSnorby #define DEFAULT_RXMT_INTERVAL	5
53a1a4e97bSnorby #define MIN_RXMT_INTERVAL	5
54a1a4e97bSnorby #define MAX_RXMT_INTERVAL	3600
55a1a4e97bSnorby 
56a1a4e97bSnorby #define DEFAULT_TRANSMIT_DELAY	1
57a1a4e97bSnorby #define MIN_TRANSMIT_DELAY	1
58a1a4e97bSnorby #define MAX_TRANSMIT_DELAY	3600
59a1a4e97bSnorby 
60c1df15f7Smarkus #define DEFAULT_ADJ_TMOUT	120
61a1a4e97bSnorby 
62a1a4e97bSnorby #define DEFAULT_NBR_TMOUT	86400	/* 24 hours */
63a1a4e97bSnorby 
64a1a4e97bSnorby #define DEFAULT_SPF_DELAY	1
65a1a4e97bSnorby #define MIN_SPF_DELAY		1
66a1a4e97bSnorby #define MAX_SPF_DELAY		10
67a1a4e97bSnorby 
68a1a4e97bSnorby #define DEFAULT_SPF_HOLDTIME	5
69a1a4e97bSnorby #define MIN_SPF_HOLDTIME	1
70a1a4e97bSnorby #define MAX_SPF_HOLDTIME	5
71a1a4e97bSnorby 
72*dd3b9a80Ssthen /* msec */
73*dd3b9a80Ssthen #define KR_RELOAD_TIMER		250
74*dd3b9a80Ssthen #define KR_RELOAD_HOLD_TIMER	5000
75*dd3b9a80Ssthen 
76a1a4e97bSnorby #define MIN_MD_ID		0
77a1a4e97bSnorby #define MAX_MD_ID		255
78a1a4e97bSnorby 
79a1a4e97bSnorby #define DEFAULT_INSTANCE_ID	0
80a1a4e97bSnorby #define MIN_INSTANCE_ID	0
81a1a4e97bSnorby #define MAX_INSTANCE_ID	0
82a1a4e97bSnorby 
83a1a4e97bSnorby /* OSPF compatibility flags */
84a1a4e97bSnorby #define OSPF_OPTION_V6		0x01
85a1a4e97bSnorby #define OSPF_OPTION_E		0x02
86ee8bc187Sclaudio #define OSPF_OPTION_x		0x04	/* ignored, should be 0 */
87a1a4e97bSnorby #define OSPF_OPTION_N		0x08
88a1a4e97bSnorby #define OSPF_OPTION_R		0x10
89a1a4e97bSnorby #define OSPF_OPTION_DC		0x20
90a1a4e97bSnorby 
91a1a4e97bSnorby /* OSPF packet types */
92a1a4e97bSnorby #define PACKET_TYPE_HELLO	1
93a1a4e97bSnorby #define PACKET_TYPE_DD		2
94a1a4e97bSnorby #define PACKET_TYPE_LS_REQUEST	3
95a1a4e97bSnorby #define PACKET_TYPE_LS_UPDATE	4
96a1a4e97bSnorby #define PACKET_TYPE_LS_ACK	5
97a1a4e97bSnorby 
98a1a4e97bSnorby /* LSA */
99a1a4e97bSnorby #define LS_REFRESH_TIME		1800
100a1a4e97bSnorby #define MIN_LS_INTERVAL		5
101a1a4e97bSnorby #define MIN_LS_ARRIVAL		1
102a1a4e97bSnorby #define DEFAULT_AGE		0
103a1a4e97bSnorby #define MAX_AGE			3600
104a1a4e97bSnorby #define CHECK_AGE		300
105a1a4e97bSnorby #define MAX_AGE_DIFF		900
106a1a4e97bSnorby #define LS_INFINITY		0xffffff
107643e3850Sclaudio #define RESV_SEQ_NUM		0x80000000U	/* reserved and "unused" */
108643e3850Sclaudio #define INIT_SEQ_NUM		0x80000001U
109643e3850Sclaudio #define MAX_SEQ_NUM		0x7fffffffU
110a1a4e97bSnorby 
111a1a4e97bSnorby /* OSPF header */
112a1a4e97bSnorby struct ospf_hdr {
113a1a4e97bSnorby 	u_int8_t		version;
114a1a4e97bSnorby 	u_int8_t		type;
115a1a4e97bSnorby 	u_int16_t		len;
116a1a4e97bSnorby 	u_int32_t		rtr_id;
117a1a4e97bSnorby 	u_int32_t		area_id;
118a1a4e97bSnorby 	u_int16_t		chksum;
119a1a4e97bSnorby 	u_int8_t		instance;
120a1a4e97bSnorby 	u_int8_t		zero;		/* must be zero */
121a1a4e97bSnorby };
122a1a4e97bSnorby 
123a1a4e97bSnorby /* Hello header (type 1) */
124a1a4e97bSnorby struct hello_hdr {
125a1a4e97bSnorby 	u_int32_t		iface_id;
1262773be1bSclaudio 	u_int32_t		opts;	/* 8bit rtr_priority + 24bits options */
127a1a4e97bSnorby 	u_int16_t		hello_interval;
128a1a4e97bSnorby 	u_int16_t		rtr_dead_interval;
129a1a4e97bSnorby 	u_int32_t		d_rtr;
130a1a4e97bSnorby 	u_int32_t		bd_rtr;
131a1a4e97bSnorby };
132a1a4e97bSnorby 
133a1a4e97bSnorby /* Database Description header (type 2) */
134a1a4e97bSnorby struct db_dscrp_hdr {
135a1a4e97bSnorby 	u_int32_t		opts;
136a1a4e97bSnorby 	u_int16_t		iface_mtu;
137a1a4e97bSnorby 	u_int8_t		zero;		/* must be zero */
138a1a4e97bSnorby 	u_int8_t		bits;
139a1a4e97bSnorby 	u_int32_t		dd_seq_num;
140a1a4e97bSnorby };
141a1a4e97bSnorby 
142a1a4e97bSnorby #define OSPF_DBD_MS		0x01
143a1a4e97bSnorby #define OSPF_DBD_M		0x02
144a1a4e97bSnorby #define OSPF_DBD_I		0x04
145a1a4e97bSnorby 
146a1a4e97bSnorby /*  Link State Request header (type 3) */
147a1a4e97bSnorby struct ls_req_hdr {
148a1a4e97bSnorby 	u_int16_t		zero;
149a1a4e97bSnorby 	u_int16_t		type;
150a1a4e97bSnorby 	u_int32_t		ls_id;
151a1a4e97bSnorby 	u_int32_t		adv_rtr;
152a1a4e97bSnorby };
153a1a4e97bSnorby 
154a1a4e97bSnorby /* Link State Update header (type 4) */
155a1a4e97bSnorby struct ls_upd_hdr {
156a1a4e97bSnorby 	u_int32_t		num_lsa;
157a1a4e97bSnorby };
158a1a4e97bSnorby 
15919f3adaeSnorby #define LSA_TYPE_LINK		0x0008
16019f3adaeSnorby #define	LSA_TYPE_ROUTER		0x2001
16119f3adaeSnorby #define LSA_TYPE_NETWORK	0x2002
16219f3adaeSnorby #define LSA_TYPE_INTER_A_PREFIX	0x2003
16319f3adaeSnorby #define LSA_TYPE_INTER_A_ROUTER	0x2004
16419f3adaeSnorby #define LSA_TYPE_INTRA_A_PREFIX	0x2009
16519f3adaeSnorby #define	LSA_TYPE_EXTERNAL	0x4005
166a1a4e97bSnorby 
1674139c605Sclaudio #define LSA_TYPE_FLAG_U		0x8000
1684139c605Sclaudio #define LSA_TYPE_FLAG_S2	0x4000
1694139c605Sclaudio #define LSA_TYPE_FLAG_S1	0x2000
1704139c605Sclaudio #define LSA_TYPE_SCOPE_MASK	0x6000
1714139c605Sclaudio 
1724139c605Sclaudio #define LSA_IS_SCOPE_LLOCAL(x)	\
1734139c605Sclaudio     (((x) & LSA_TYPE_SCOPE_MASK) == 0)
1744139c605Sclaudio #define LSA_IS_SCOPE_AREA(x)	\
1754139c605Sclaudio     (((x) & LSA_TYPE_SCOPE_MASK) == LSA_TYPE_FLAG_S1)
1764139c605Sclaudio #define LSA_IS_SCOPE_AS(x)	\
1774139c605Sclaudio     (((x) & LSA_TYPE_SCOPE_MASK) == LSA_TYPE_FLAG_S2)
1784139c605Sclaudio 
179a1a4e97bSnorby #define LINK_TYPE_POINTTOPOINT	1
180a1a4e97bSnorby #define LINK_TYPE_TRANSIT_NET	2
18165002a60Sclaudio #define LINK_TYPE_RESERVED	3
182a1a4e97bSnorby #define LINK_TYPE_VIRTUAL	4
183a1a4e97bSnorby 
184ee8bc187Sclaudio /* for some reason they thought 24bit types are fun, make them less a hazard */
185ee8bc187Sclaudio #define LSA_24_MASK 0xffffff
186ee8bc187Sclaudio #define LSA_24_GETHI(x)		\
187ee8bc187Sclaudio 	((x) >> 24)
188ee8bc187Sclaudio #define LSA_24_GETLO(x)		\
189ee8bc187Sclaudio 	((x) & LSA_24_MASK)
190ee8bc187Sclaudio #define LSA_24_SETHI(x, y)	\
191ee8bc187Sclaudio 	((x) = ((x) & LSA_24_MASK) | (((y) & 0xff) << 24))
192ee8bc187Sclaudio #define LSA_24_SETLO(x, y)	\
193ee8bc187Sclaudio 	((x) = ((y) & LSA_24_MASK) | ((x) & ~LSA_24_MASK))
194ee8bc187Sclaudio 
195a1a4e97bSnorby /* LSA headers */
196a1a4e97bSnorby #define LSA_METRIC_MASK		0x00ffffff	/* only for sum & as-ext */
19776383d36Sclaudio #define LSA_ASEXT_E_FLAG	0x04000000
19876383d36Sclaudio #define LSA_ASEXT_F_FLAG	0x02000000
19976383d36Sclaudio #define LSA_ASEXT_T_FLAG	0x01000000
200a1a4e97bSnorby 
201a1a4e97bSnorby #define OSPF_RTR_B		0x01
202a1a4e97bSnorby #define OSPF_RTR_E		0x02
203a1a4e97bSnorby #define OSPF_RTR_V		0x04
204ee8bc187Sclaudio #define OSPF_RTR_x		0x08	/* ignored, should be 0 */
205ee8bc187Sclaudio #define OSPF_RTR_Nt		0x10
206a1a4e97bSnorby 
207d913b22eSclaudio #define OSPF_PREFIX_NU		0x01
208d913b22eSclaudio #define OSPF_PREFIX_LA		0x02
209d913b22eSclaudio #define OSPF_PREFIX_x		0x04	/* ignored, should be 0 */
210d913b22eSclaudio #define OSPF_PREFIX_P		0x08
211d913b22eSclaudio #define OSPF_PREFIX_DN		0x10
212d913b22eSclaudio 
21340bb6991Sclaudio /* return encoded IPv6 prefix size in bytes depending on the prefixlen */
21440bb6991Sclaudio #define LSA_PREFIXSIZE(x)	(((x) + 31)/32 * 4)
21540bb6991Sclaudio 
2164139c605Sclaudio struct lsa_prefix {
2174139c605Sclaudio 	u_int8_t		prefixlen;
2184139c605Sclaudio 	u_int8_t		options;
21976383d36Sclaudio 	u_int16_t		metric;	/* Ref. LS type in AS-Ext-LSA */
22040bb6991Sclaudio 	/* + an IPv6 prefix encoded in (prefixlen + 31)/32 words */
2214139c605Sclaudio };
2224139c605Sclaudio 
223a1a4e97bSnorby struct lsa_rtr {
2240545ccbfSclaudio 	u_int32_t		opts;	/* 8bit flags + 24bits options */
225a1a4e97bSnorby };
226a1a4e97bSnorby 
227a1a4e97bSnorby struct lsa_rtr_link {
228a1a4e97bSnorby 	u_int8_t		type;
22925e30039Snorby 	u_int8_t		dummy;
230a1a4e97bSnorby 	u_int16_t		metric;
23125e30039Snorby 	u_int32_t		iface_id;
23225e30039Snorby 	u_int32_t		nbr_iface_id;
23325e30039Snorby 	u_int32_t		nbr_rtr_id;
234a1a4e97bSnorby };
235a1a4e97bSnorby 
236a1a4e97bSnorby struct lsa_net {
23767b3ede7Sclaudio 	u_int32_t		opts;	/* 24bits options */
238a1a4e97bSnorby };
239a1a4e97bSnorby 
240a1a4e97bSnorby struct lsa_net_link {
241a1a4e97bSnorby 	u_int32_t		att_rtr;
242a1a4e97bSnorby };
243a1a4e97bSnorby 
2444139c605Sclaudio struct lsa_prefix_sum {
245a1a4e97bSnorby 	u_int32_t		metric;		/* only lower 24 bit */
2464139c605Sclaudio 	/* + one prefix */
2474139c605Sclaudio };
2484139c605Sclaudio 
2494139c605Sclaudio struct lsa_rtr_sum {
250d913b22eSclaudio 	u_int32_t		opts;		/* lower 24bit options */
2514139c605Sclaudio 	u_int32_t		metric;		/* only lower 24 bit */
2524139c605Sclaudio 	u_int32_t		dest_rtr_id;
253a1a4e97bSnorby };
254a1a4e97bSnorby 
255a1a4e97bSnorby struct lsa_asext {
25676383d36Sclaudio 	u_int32_t		metric;		/* lower 24 bit plus EFT bits */
25776383d36Sclaudio 	struct lsa_prefix	prefix;
25876383d36Sclaudio 	/* + if F bit is set, an optional forwarding address (128bit) */
25976383d36Sclaudio 	/* + if T bit is set, an optional external route tag (32bit) */
26076383d36Sclaudio 	/* + if referenced LS type (i.e. prefix.metric) is non-zero, an
26176383d36Sclaudio 	 *   optional referenced LS ID (32bit) -- not used by OSPF itself */
262a1a4e97bSnorby };
263a1a4e97bSnorby 
2644139c605Sclaudio struct lsa_link {
265d913b22eSclaudio 	u_int32_t		opts;		/* rtr pri & 24bit options */
2664139c605Sclaudio 	struct in6_addr		lladdr;
2674139c605Sclaudio 	u_int32_t		numprefix;
268d913b22eSclaudio 	/* + numprefix * lsa_prefix */
2694139c605Sclaudio };
2704139c605Sclaudio 
2714139c605Sclaudio struct lsa_intra_prefix {
2724139c605Sclaudio 	u_int16_t		numprefix;
2734139c605Sclaudio 	u_int16_t		ref_type;
27433de12bdSstsp 	u_int32_t		ref_ls_id;
2754139c605Sclaudio 	u_int32_t		ref_adv_rtr;
276d913b22eSclaudio 	/* + numprefix * lsa_prefix */
2774139c605Sclaudio };
2784139c605Sclaudio 
279a1a4e97bSnorby struct lsa_hdr {
280a1a4e97bSnorby 	u_int16_t		age;
281a1a4e97bSnorby 	u_int16_t		type;
282a1a4e97bSnorby 	u_int32_t		ls_id;
283a1a4e97bSnorby 	u_int32_t		adv_rtr;
284a1a4e97bSnorby 	u_int32_t		seq_num;
285a1a4e97bSnorby 	u_int16_t		ls_chksum;
286a1a4e97bSnorby 	u_int16_t		len;
287a1a4e97bSnorby };
288a1a4e97bSnorby 
289a6417e4fSclaudio #define LS_CKSUM_OFFSET	offsetof(struct lsa_hdr, ls_chksum)
290a1a4e97bSnorby 
291a1a4e97bSnorby struct lsa {
292a1a4e97bSnorby 	struct lsa_hdr		hdr;
293a1a4e97bSnorby 	union {
294a1a4e97bSnorby 		struct lsa_rtr		rtr;
295a1a4e97bSnorby 		struct lsa_net		net;
2964139c605Sclaudio 		struct lsa_prefix_sum	pref_sum;
2974139c605Sclaudio 		struct lsa_rtr_sum	rtr_sum;
298a1a4e97bSnorby 		struct lsa_asext	asext;
2994139c605Sclaudio 		struct lsa_link		link;
3004139c605Sclaudio 		struct lsa_intra_prefix pref_intra;
301a1a4e97bSnorby 	}			data;
302a1a4e97bSnorby };
303a1a4e97bSnorby 
304a1a4e97bSnorby #endif /* !_OSPF_H_ */
305