xref: /openbsd/usr.sbin/ospfd/ospf.h (revision 097ed198)
1 /*	$OpenBSD: ospf.h,v 1.21 2011/05/09 12:24:41 claudio Exp $ */
2 
3 /*
4  * Copyright (c) 2004, 2005 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 OSPF_VERSION		2
29 #define IPPROTO_OSPF		89
30 #define AllSPFRouters		"224.0.0.5"
31 #define AllDRouters		"224.0.0.6"
32 
33 #define DEFAULT_METRIC		10
34 #define DEFAULT_REDIST_METRIC	100
35 #define MIN_METRIC		1
36 #define MAX_METRIC		65535	/* sum & as-ext lsa use 24bit metrics */
37 
38 #define DEFAULT_PRIORITY	1
39 #define MIN_PRIORITY		0
40 #define MAX_PRIORITY		255
41 
42 #define DEFAULT_HELLO_INTERVAL	10
43 #define MIN_HELLO_INTERVAL	1
44 #define MAX_HELLO_INTERVAL	65535
45 
46 /* msec */
47 #define DEFAULT_FAST_INTERVAL	333
48 #define MIN_FAST_INTERVAL	50
49 #define MAX_FAST_INTERVAL	333
50 
51 #define DEFAULT_RTR_DEAD_TIME	40
52 #define FAST_RTR_DEAD_TIME	1
53 #define MIN_RTR_DEAD_TIME	2
54 #define MAX_RTR_DEAD_TIME	2147483647
55 
56 #define DEFAULT_RXMT_INTERVAL	5
57 #define MIN_RXMT_INTERVAL	5
58 #define MAX_RXMT_INTERVAL	3600
59 
60 #define DEFAULT_TRANSMIT_DELAY	1
61 #define MIN_TRANSMIT_DELAY	1
62 #define MAX_TRANSMIT_DELAY	3600
63 
64 #define DEFAULT_ADJ_TMOUT	60
65 
66 #define DEFAULT_NBR_TMOUT	86400	/* 24 hours */
67 
68 /* msec */
69 #define DEFAULT_SPF_DELAY	1000
70 #define MIN_SPF_DELAY		10
71 #define MAX_SPF_DELAY		10000
72 
73 /* msec */
74 #define DEFAULT_SPF_HOLDTIME	5000
75 #define MIN_SPF_HOLDTIME	10
76 #define MAX_SPF_HOLDTIME	5000
77 
78 #define MIN_MD_ID		0
79 #define MAX_MD_ID		255
80 
81 #define MAX_SIMPLE_AUTH_LEN	8
82 
83 /* OSPF compatibility flags */
84 #define OSPF_OPTION_MT		0x01
85 #define OSPF_OPTION_E		0x02
86 #define OSPF_OPTION_MC		0x04
87 #define OSPF_OPTION_NP		0x08
88 #define OSPF_OPTION_EA		0x10
89 #define OSPF_OPTION_DC		0x20
90 #define OSPF_OPTION_O		0x40	/* only on DD options */
91 #define OSPF_OPTION_DN		0x80	/* only on LSA options */
92 
93 /* OSPF packet types */
94 #define PACKET_TYPE_HELLO	1
95 #define PACKET_TYPE_DD		2
96 #define PACKET_TYPE_LS_REQUEST	3
97 #define PACKET_TYPE_LS_UPDATE	4
98 #define PACKET_TYPE_LS_ACK	5
99 
100 /* OSPF auth types */
101 #define	AUTH_TYPE_NONE		0
102 #define AUTH_TYPE_SIMPLE	1
103 #define	AUTH_TYPE_CRYPT		2
104 
105 #define MIN_AUTHTYPE		0
106 #define MAX_AUTHTYPE		2
107 
108 /* LSA */
109 #define LS_REFRESH_TIME		1800
110 #define MIN_LS_INTERVAL		5
111 #define MIN_LS_ARRIVAL		1
112 #define DEFAULT_AGE		0
113 #define MAX_AGE			3600
114 #define CHECK_AGE		300
115 #define MAX_AGE_DIFF		900
116 #define LS_INFINITY		0xffffff
117 #define RESV_SEQ_NUM		0x80000000	/* reserved and "unused" */
118 #define INIT_SEQ_NUM		0x80000001
119 #define MAX_SEQ_NUM		0x7fffffff
120 
121 /* OSPF header */
122 struct crypt {
123 	u_int16_t		dummy;
124 	u_int8_t		keyid;
125 	u_int8_t		len;
126 	u_int32_t		seq_num;
127 };
128 
129 struct ospf_hdr {
130 	u_int8_t		version;
131 	u_int8_t		type;
132 	u_int16_t		len;
133 	u_int32_t		rtr_id;
134 	u_int32_t		area_id;
135 	u_int16_t		chksum;
136 	u_int16_t		auth_type;
137 	union {
138 		char		simple[MAX_SIMPLE_AUTH_LEN];
139 		struct crypt	crypt;
140 	} auth_key;
141 };
142 
143 /* Hello header (type 1) */
144 struct hello_hdr {
145 	u_int32_t		mask;
146 	u_int16_t		hello_interval;
147 	u_int8_t		opts;
148 	u_int8_t		rtr_priority;
149 	u_int32_t		rtr_dead_interval;
150 	u_int32_t		d_rtr;
151 	u_int32_t		bd_rtr;
152 };
153 
154 /* Database Description header (type 2) */
155 struct db_dscrp_hdr {
156 	u_int16_t		iface_mtu;
157 	u_int8_t		opts;
158 	u_int8_t		bits;
159 	u_int32_t		dd_seq_num;
160 };
161 
162 #define OSPF_DBD_MS		0x01
163 #define OSPF_DBD_M		0x02
164 #define OSPF_DBD_I		0x04
165 
166 /*  Link State Request header (type 3) */
167 struct ls_req_hdr {
168 	u_int32_t		type;
169 	u_int32_t		ls_id;
170 	u_int32_t		adv_rtr;
171 };
172 
173 /* Link State Update header (type 4) */
174 struct ls_upd_hdr {
175 	u_int32_t		num_lsa;
176 };
177 
178 #define	LSA_TYPE_ROUTER		1
179 #define LSA_TYPE_NETWORK	2
180 #define LSA_TYPE_SUM_NETWORK	3
181 #define LSA_TYPE_SUM_ROUTER	4
182 #define	LSA_TYPE_EXTERNAL	5
183 #define	LSA_TYPE_LINK_OPAQ	9
184 #define	LSA_TYPE_AREA_OPAQ	10
185 #define	LSA_TYPE_AS_OPAQ	11
186 
187 #define LINK_TYPE_POINTTOPOINT	1
188 #define LINK_TYPE_TRANSIT_NET	2
189 #define LINK_TYPE_STUB_NET	3
190 #define LINK_TYPE_VIRTUAL	4
191 
192 /* LSA headers */
193 #define LSA_METRIC_MASK		0x00ffffff	/* only for sum & as-ext */
194 #define LSA_ASEXT_E_FLAG	0x80000000
195 
196 /* for some reason they thought 24bit types are fun, make them less a hazard */
197 #define LSA_24_MASK 0xffffff
198 #define LSA_24_GETHI(x)		\
199 	((x) >> 24)
200 #define LSA_24_GETLO(x)		\
201 	((x) & LSA_24_MASK)
202 #define LSA_24_SETHI(x, y)	\
203 	((x) = ((x) & LSA_24_MASK) | (((y) & 0xff) << 24))
204 #define LSA_24_SETLO(x, y)	\
205 	((x) = ((y) & LSA_24_MASK) | ((x) & ~LSA_24_MASK))
206 
207 
208 #define OSPF_RTR_B		0x01
209 #define OSPF_RTR_E		0x02
210 #define OSPF_RTR_V		0x04
211 
212 struct lsa_rtr {
213 	u_int8_t		flags;
214 	u_int8_t		dummy;
215 	u_int16_t		nlinks;
216 };
217 
218 struct lsa_rtr_link {
219 	u_int32_t		id;
220 	u_int32_t		data;
221 	u_int8_t		type;
222 	u_int8_t		num_tos;
223 	u_int16_t		metric;
224 };
225 
226 struct lsa_net {
227 	u_int32_t		mask;
228 	u_int32_t		att_rtr[1];
229 };
230 
231 struct lsa_net_link {
232 	u_int32_t		att_rtr;
233 };
234 
235 struct lsa_sum {
236 	u_int32_t		mask;
237 	u_int32_t		metric;		/* only lower 24 bit */
238 };
239 
240 struct lsa_asext {
241 	u_int32_t		mask;
242 	u_int32_t		metric;		/* lower 24 bit plus E bit */
243 	u_int32_t		fw_addr;
244 	u_int32_t		ext_tag;
245 };
246 
247 struct lsa_hdr {
248 	u_int16_t		age;
249 	u_int8_t		opts;
250 	u_int8_t		type;
251 	u_int32_t		ls_id;
252 	u_int32_t		adv_rtr;
253 	u_int32_t		seq_num;
254 	u_int16_t		ls_chksum;
255 	u_int16_t		len;
256 };
257 
258 #define LS_CKSUM_OFFSET	offsetof(struct lsa_hdr, ls_chksum)
259 
260 struct lsa {
261 	struct lsa_hdr		hdr;
262 	union {
263 		struct lsa_rtr		rtr;
264 		struct lsa_net		net;
265 		struct lsa_sum		sum;
266 		struct lsa_asext	asext;
267 	}			data;
268 };
269 
270 #endif /* !_OSPF_H_ */
271