xref: /openbsd/usr.sbin/ospfd/ospf.h (revision 204df0f8)
1 /*	$OpenBSD: ospf.h,v 1.1 2005/01/28 14:05:40 claudio Exp $ */
2 
3 /*
4  * Copyright (c) 2004, 2005 Esben Norby <esben.norby@ericsson.com>
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 <stdbool.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 PACKET_HDR		100 /* XXX used to calculate the IP payload */
34 
35 #define DEFAULT_METRIC		1
36 #define MIN_METRIC		1
37 #define MAX_METRIC		65535
38 
39 #define DEFAULT_PRIORITY	0 /* XXX force to 0 for now */
40 #define MIN_PRIORITY		0
41 #define MAX_PRIORITY		255
42 
43 #define DEFAULT_HELLO_INTERVAL	10
44 #define MIN_HELLO_INTERVAL	1
45 #define MAX_HELLO_INTERVAL	65535
46 
47 #define DEFAULT_RTR_DEAD_TIME	40
48 #define MIN_RTR_DEAD_TIME	2
49 #define MAX_RTR_DEAD_TIME	2147483647
50 
51 #define DEFAULT_RXMT_INTERVAL	5
52 #define MIN_RXMT_INTERVAL	5
53 #define MAX_RXMT_INTERVAL	3600
54 
55 #define DEFAULT_TRANSIT_DELAY	1
56 #define MIN_TRANSIT_DELAY	1
57 #define MAX_TRANSIT_DELAY	3600
58 
59 #define DEFAULT_ADJ_TMOUT	60	/* XXX sane value? */
60 
61 /* OSPF compatibility flags */
62 #define OSPF_OPTION_E		0x02
63 #define OSPF_OPTION_MC		0x04
64 #define OSPF_OPTION_NP		0x08
65 #define OSPF_OPTION_EA		0x10
66 #define OSPF_OPTION_DC		0x20
67 
68 /* OSPF packet types */
69 #define PACKET_TYPE_HELLO	1
70 #define PACKET_TYPE_DD		2
71 #define PACKET_TYPE_LS_REQUEST	3
72 #define PACKET_TYPE_LS_UPDATE	4
73 #define PACKET_TYPE_LS_ACK	5
74 
75 /* OSPF auth types */
76 #define	AUTH_TYPE_NONE		0
77 #define AUTH_TYPE_SIMPLE	1
78 #define	AUTH_TYPE_CRYPT		2
79 
80 #define MIN_AUTHTYPE		0
81 #define MAX_AUTHTYPE		2
82 
83 /* LSA */
84 #define LS_REFRESH_TIME		1800
85 #define MIN_LS_INTERVAL		5
86 #define MIN_LS_ARRIVAL		1
87 #define DEFAULT_AGE		0
88 #define MAX_AGE			3600
89 #define CHECK_AGE		300
90 #define MAX_AGE_DIFF		900
91 #define LS_INFINITY		0xffffff
92 #define INIT_SEQ_NUM		0x80000001
93 #define MAX_SEQ_NUM		0x7fffffff
94 
95 /* OSPF header */
96 struct ospf_hdr {
97 	u_int8_t		version;
98 	u_int8_t		type;
99 	u_int16_t		len;
100 	u_int32_t		rtr_id;
101 	u_int32_t		area_id;
102 	u_int16_t		chksum;
103 	u_int16_t		auth_type;
104 	union {
105 		char		simple[8];
106 		u_int64_t	crypt;
107 	} auth_key;
108 };
109 
110 /* Hello header (type 1) */
111 struct hello_hdr {
112 	u_int32_t		mask;
113 	u_int16_t		hello_interval;
114 	u_int8_t		opts;
115 	u_int8_t		rtr_priority;
116 	u_int32_t		rtr_dead_interval;
117 	u_int32_t		d_rtr;
118 	u_int32_t		bd_rtr;
119 };
120 
121 /* Database Description header (type 2) */
122 struct db_dscrp_hdr {
123 	u_int16_t		iface_mtu;
124 	u_int8_t		opts;
125 	u_int8_t		bits;
126 	u_int32_t		dd_seq_num;
127 };
128 
129 #define OSPF_DBD_MS		0x01
130 #define OSPF_DBD_M		0x02
131 #define OSPF_DBD_I		0x04
132 
133 /*  Link State Request header (type 3) */
134 struct ls_req_hdr {
135 	u_int32_t		type;
136 	u_int32_t		ls_id;
137 	u_int32_t		adv_rtr;
138 };
139 
140 /* Link State Update header (type 4) */
141 struct ls_upd_hdr {
142 	u_int32_t		num_lsa;
143 };
144 
145 #define	LSA_TYPE_ROUTER		1
146 #define LSA_TYPE_NETWORK	2
147 #define LSA_TYPE_SUM_NETWORK	3
148 #define LSA_TYPE_SUM_ROUTER	4
149 #define	LSA_TYPE_EXTERNAL	5
150 
151 #define LINK_TYPE_POINTTOPOINT	1
152 #define LINK_TYPE_TRANSIT_NET	2
153 #define LINK_TYPE_STUB_NET	3
154 #define LINK_TYPE_VIRTUAL	4
155 
156 /* LSA headers */
157 struct lsa_rtr {
158 	u_int8_t		flags;
159 	u_int8_t		dummy;
160 	u_int16_t		nlinks;
161 };
162 
163 struct lsa_rtr_link {
164 	u_int32_t		id;
165 	u_int32_t		data;
166 	u_int8_t		type;
167 	u_int8_t		num_tos;
168 	u_int16_t		metric;
169 };
170 
171 struct lsa_net {
172 	u_int32_t		mask;
173 	u_int32_t		att_rtr[1];
174 };
175 
176 struct lsa_sum {
177 	u_int32_t		mask;
178 	u_int32_t		metric;		/* only lower 24 bit */
179 };
180 
181 struct lsa_hdr {
182 	u_int16_t		age;
183 	u_int8_t		opts;
184 	u_int8_t		type;
185 	u_int32_t		ls_id;
186 	u_int32_t		adv_rtr;
187 	int32_t			seq_num;
188 	u_int16_t		ls_chksum;
189 	u_int16_t		len;
190 };
191 
192 #define LS_CKSUM_OFFSET	((u_int16_t)(&((struct lsa_hdr *)0)->ls_chksum))
193 
194 struct lsa {
195 	struct lsa_hdr		hdr;
196 	union {
197 		struct lsa_rtr	rtr;
198 		struct lsa_net  net;
199 		struct lsa_sum	sum;
200 	}			data;
201 };
202 
203 #endif /* !_OSPF_H_ */
204