xref: /openbsd/usr.sbin/ospfd/ospf.h (revision 62d04914)
1 /*	$OpenBSD: ospf.h,v 1.20 2011/03/25 08:52:21 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_E		0x02
85 #define OSPF_OPTION_MC		0x04
86 #define OSPF_OPTION_NP		0x08
87 #define OSPF_OPTION_EA		0x10
88 #define OSPF_OPTION_DC		0x20
89 
90 /* OSPF packet types */
91 #define PACKET_TYPE_HELLO	1
92 #define PACKET_TYPE_DD		2
93 #define PACKET_TYPE_LS_REQUEST	3
94 #define PACKET_TYPE_LS_UPDATE	4
95 #define PACKET_TYPE_LS_ACK	5
96 
97 /* OSPF auth types */
98 #define	AUTH_TYPE_NONE		0
99 #define AUTH_TYPE_SIMPLE	1
100 #define	AUTH_TYPE_CRYPT		2
101 
102 #define MIN_AUTHTYPE		0
103 #define MAX_AUTHTYPE		2
104 
105 /* LSA */
106 #define LS_REFRESH_TIME		1800
107 #define MIN_LS_INTERVAL		5
108 #define MIN_LS_ARRIVAL		1
109 #define DEFAULT_AGE		0
110 #define MAX_AGE			3600
111 #define CHECK_AGE		300
112 #define MAX_AGE_DIFF		900
113 #define LS_INFINITY		0xffffff
114 #define RESV_SEQ_NUM		0x80000000	/* reserved and "unused" */
115 #define INIT_SEQ_NUM		0x80000001
116 #define MAX_SEQ_NUM		0x7fffffff
117 
118 /* OSPF header */
119 struct crypt {
120 	u_int16_t		dummy;
121 	u_int8_t		keyid;
122 	u_int8_t		len;
123 	u_int32_t		seq_num;
124 };
125 
126 struct ospf_hdr {
127 	u_int8_t		version;
128 	u_int8_t		type;
129 	u_int16_t		len;
130 	u_int32_t		rtr_id;
131 	u_int32_t		area_id;
132 	u_int16_t		chksum;
133 	u_int16_t		auth_type;
134 	union {
135 		char		simple[MAX_SIMPLE_AUTH_LEN];
136 		struct crypt	crypt;
137 	} auth_key;
138 };
139 
140 /* Hello header (type 1) */
141 struct hello_hdr {
142 	u_int32_t		mask;
143 	u_int16_t		hello_interval;
144 	u_int8_t		opts;
145 	u_int8_t		rtr_priority;
146 	u_int32_t		rtr_dead_interval;
147 	u_int32_t		d_rtr;
148 	u_int32_t		bd_rtr;
149 };
150 
151 /* Database Description header (type 2) */
152 struct db_dscrp_hdr {
153 	u_int16_t		iface_mtu;
154 	u_int8_t		opts;
155 	u_int8_t		bits;
156 	u_int32_t		dd_seq_num;
157 };
158 
159 #define OSPF_DBD_MS		0x01
160 #define OSPF_DBD_M		0x02
161 #define OSPF_DBD_I		0x04
162 
163 /*  Link State Request header (type 3) */
164 struct ls_req_hdr {
165 	u_int32_t		type;
166 	u_int32_t		ls_id;
167 	u_int32_t		adv_rtr;
168 };
169 
170 /* Link State Update header (type 4) */
171 struct ls_upd_hdr {
172 	u_int32_t		num_lsa;
173 };
174 
175 #define	LSA_TYPE_ROUTER		1
176 #define LSA_TYPE_NETWORK	2
177 #define LSA_TYPE_SUM_NETWORK	3
178 #define LSA_TYPE_SUM_ROUTER	4
179 #define	LSA_TYPE_EXTERNAL	5
180 
181 #define LINK_TYPE_POINTTOPOINT	1
182 #define LINK_TYPE_TRANSIT_NET	2
183 #define LINK_TYPE_STUB_NET	3
184 #define LINK_TYPE_VIRTUAL	4
185 
186 /* LSA headers */
187 #define LSA_METRIC_MASK		0x00ffffff	/* only for sum & as-ext */
188 #define LSA_ASEXT_E_FLAG	0x80000000
189 
190 #define OSPF_RTR_B		0x01
191 #define OSPF_RTR_E		0x02
192 #define OSPF_RTR_V		0x04
193 
194 struct lsa_rtr {
195 	u_int8_t		flags;
196 	u_int8_t		dummy;
197 	u_int16_t		nlinks;
198 };
199 
200 struct lsa_rtr_link {
201 	u_int32_t		id;
202 	u_int32_t		data;
203 	u_int8_t		type;
204 	u_int8_t		num_tos;
205 	u_int16_t		metric;
206 };
207 
208 struct lsa_net {
209 	u_int32_t		mask;
210 	u_int32_t		att_rtr[1];
211 };
212 
213 struct lsa_net_link {
214 	u_int32_t		att_rtr;
215 };
216 
217 struct lsa_sum {
218 	u_int32_t		mask;
219 	u_int32_t		metric;		/* only lower 24 bit */
220 };
221 
222 struct lsa_asext {
223 	u_int32_t		mask;
224 	u_int32_t		metric;		/* lower 24 bit plus E bit */
225 	u_int32_t		fw_addr;
226 	u_int32_t		ext_tag;
227 };
228 
229 struct lsa_hdr {
230 	u_int16_t		age;
231 	u_int8_t		opts;
232 	u_int8_t		type;
233 	u_int32_t		ls_id;
234 	u_int32_t		adv_rtr;
235 	u_int32_t		seq_num;
236 	u_int16_t		ls_chksum;
237 	u_int16_t		len;
238 };
239 
240 #define LS_CKSUM_OFFSET	offsetof(struct lsa_hdr, ls_chksum)
241 
242 struct lsa {
243 	struct lsa_hdr		hdr;
244 	union {
245 		struct lsa_rtr		rtr;
246 		struct lsa_net		net;
247 		struct lsa_sum		sum;
248 		struct lsa_asext	asext;
249 	}			data;
250 };
251 
252 #endif /* !_OSPF_H_ */
253