xref: /openbsd/usr.sbin/ospfd/ospf.h (revision 11d8e949)
1 /*	$OpenBSD: ospf.h,v 1.13 2005/12/04 20:56:46 norby 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 
26 /* misc */
27 #define OSPF_VERSION		2
28 #define IPPROTO_OSPF		89
29 #define AllSPFRouters		"224.0.0.5"
30 #define AllDRouters		"224.0.0.6"
31 
32 #define PACKET_HDR		100 /* XXX used to calculate the IP payload */
33 
34 #define DEFAULT_METRIC		10
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 #define DEFAULT_RTR_DEAD_TIME	40
47 #define MIN_RTR_DEAD_TIME	2
48 #define MAX_RTR_DEAD_TIME	2147483647
49 
50 #define DEFAULT_RXMT_INTERVAL	5
51 #define MIN_RXMT_INTERVAL	5
52 #define MAX_RXMT_INTERVAL	3600
53 
54 #define DEFAULT_TRANSMIT_DELAY	1
55 #define MIN_TRANSMIT_DELAY	1
56 #define MAX_TRANSMIT_DELAY	3600
57 
58 #define DEFAULT_ADJ_TMOUT	600	/* XXX sane value? */
59 
60 #define DEFAULT_NBR_TMOUT	86400	/* 24 hours */
61 
62 #define DEFAULT_SPF_DELAY	1
63 #define MIN_SPF_DELAY		1
64 #define MAX_SPF_DELAY		10
65 
66 #define DEFAULT_SPF_HOLDTIME	5
67 #define MIN_SPF_HOLDTIME	1
68 #define MAX_SPF_HOLDTIME	5
69 
70 #define MIN_MD_ID		0
71 #define MAX_MD_ID		255
72 
73 #define MAX_SIMPLE_AUTH_LEN	8
74 
75 /* OSPF compatibility flags */
76 #define OSPF_OPTION_E		0x02
77 #define OSPF_OPTION_MC		0x04
78 #define OSPF_OPTION_NP		0x08
79 #define OSPF_OPTION_EA		0x10
80 #define OSPF_OPTION_DC		0x20
81 
82 /* OSPF packet types */
83 #define PACKET_TYPE_HELLO	1
84 #define PACKET_TYPE_DD		2
85 #define PACKET_TYPE_LS_REQUEST	3
86 #define PACKET_TYPE_LS_UPDATE	4
87 #define PACKET_TYPE_LS_ACK	5
88 
89 /* OSPF auth types */
90 #define	AUTH_TYPE_NONE		0
91 #define AUTH_TYPE_SIMPLE	1
92 #define	AUTH_TYPE_CRYPT		2
93 
94 #define MIN_AUTHTYPE		0
95 #define MAX_AUTHTYPE		2
96 
97 /* LSA */
98 #define LS_REFRESH_TIME		1800
99 #define MIN_LS_INTERVAL		5
100 #define MIN_LS_ARRIVAL		1
101 #define DEFAULT_AGE		0
102 #define MAX_AGE			3600
103 #define CHECK_AGE		300
104 #define MAX_AGE_DIFF		900
105 #define LS_INFINITY		0xffffff
106 #define RESV_SEQ_NUM		0x80000000	/* reserved and "unused" */
107 #define INIT_SEQ_NUM		0x80000001
108 #define MAX_SEQ_NUM		0x7fffffff
109 
110 /* OSPF header */
111 struct crypt {
112 	u_int16_t		dummy;
113 	u_int8_t		keyid;
114 	u_int8_t		len;
115 	u_int32_t		seq_num;
116 };
117 
118 struct ospf_hdr {
119 	u_int8_t		version;
120 	u_int8_t		type;
121 	u_int16_t		len;
122 	u_int32_t		rtr_id;
123 	u_int32_t		area_id;
124 	u_int16_t		chksum;
125 	u_int16_t		auth_type;
126 	union {
127 		char		simple[MAX_SIMPLE_AUTH_LEN];
128 		struct crypt	crypt;
129 	} auth_key;
130 };
131 
132 /* Hello header (type 1) */
133 struct hello_hdr {
134 	u_int32_t		mask;
135 	u_int16_t		hello_interval;
136 	u_int8_t		opts;
137 	u_int8_t		rtr_priority;
138 	u_int32_t		rtr_dead_interval;
139 	u_int32_t		d_rtr;
140 	u_int32_t		bd_rtr;
141 };
142 
143 /* Database Description header (type 2) */
144 struct db_dscrp_hdr {
145 	u_int16_t		iface_mtu;
146 	u_int8_t		opts;
147 	u_int8_t		bits;
148 	u_int32_t		dd_seq_num;
149 };
150 
151 #define OSPF_DBD_MS		0x01
152 #define OSPF_DBD_M		0x02
153 #define OSPF_DBD_I		0x04
154 
155 /*  Link State Request header (type 3) */
156 struct ls_req_hdr {
157 	u_int32_t		type;
158 	u_int32_t		ls_id;
159 	u_int32_t		adv_rtr;
160 };
161 
162 /* Link State Update header (type 4) */
163 struct ls_upd_hdr {
164 	u_int32_t		num_lsa;
165 };
166 
167 #define	LSA_TYPE_ROUTER		1
168 #define LSA_TYPE_NETWORK	2
169 #define LSA_TYPE_SUM_NETWORK	3
170 #define LSA_TYPE_SUM_ROUTER	4
171 #define	LSA_TYPE_EXTERNAL	5
172 
173 #define LINK_TYPE_POINTTOPOINT	1
174 #define LINK_TYPE_TRANSIT_NET	2
175 #define LINK_TYPE_STUB_NET	3
176 #define LINK_TYPE_VIRTUAL	4
177 
178 /* LSA headers */
179 #define LSA_METRIC_MASK		0x00ffffff	/* only for sum & as-ext */
180 #define LSA_ASEXT_E_FLAG	0x80000000
181 
182 #define OSPF_RTR_B		0x01
183 #define OSPF_RTR_E		0x02
184 #define OSPF_RTR_V		0x04
185 
186 struct lsa_rtr {
187 	u_int8_t		flags;
188 	u_int8_t		dummy;
189 	u_int16_t		nlinks;
190 };
191 
192 struct lsa_rtr_link {
193 	u_int32_t		id;
194 	u_int32_t		data;
195 	u_int8_t		type;
196 	u_int8_t		num_tos;
197 	u_int16_t		metric;
198 };
199 
200 struct lsa_net {
201 	u_int32_t		mask;
202 	u_int32_t		att_rtr[1];
203 };
204 
205 struct lsa_net_link {
206 	u_int32_t		att_rtr;
207 };
208 
209 struct lsa_sum {
210 	u_int32_t		mask;
211 	u_int32_t		metric;		/* only lower 24 bit */
212 };
213 
214 struct lsa_asext {
215 	u_int32_t		mask;
216 	u_int32_t		metric;		/* lower 24 bit plus E bit */
217 	u_int32_t		fw_addr;
218 	u_int32_t		ext_tag;
219 };
220 
221 struct lsa_hdr {
222 	u_int16_t		age;
223 	u_int8_t		opts;
224 	u_int8_t		type;
225 	u_int32_t		ls_id;
226 	u_int32_t		adv_rtr;
227 	u_int32_t		seq_num;
228 	u_int16_t		ls_chksum;
229 	u_int16_t		len;
230 };
231 
232 #define LS_CKSUM_OFFSET	((u_int16_t)(&((struct lsa_hdr *)0)->ls_chksum))
233 
234 struct lsa {
235 	struct lsa_hdr		hdr;
236 	union {
237 		struct lsa_rtr		rtr;
238 		struct lsa_net		net;
239 		struct lsa_sum		sum;
240 		struct lsa_asext	asext;
241 	}			data;
242 };
243 
244 #endif /* !_OSPF_H_ */
245