]> The Tcpdump Group git mirrors - tcpdump/blob - ospf.h
OSPF: add support for segment routing extensions and hostname extensions
[tcpdump] / ospf.h
1 /*
2 * Copyright (c) 1991, 1993, 1994, 1995, 1996, 1997
3 * The Regents of the University of California. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that: (1) source code distributions
7 * retain the above copyright notice and this paragraph in its entirety, (2)
8 * distributions including binary code include the above copyright notice and
9 * this paragraph in its entirety in the documentation or other materials
10 * provided with the distribution, and (3) all advertising materials mentioning
11 * features or use of this software display the following acknowledgement:
12 * ``This product includes software developed by the University of California,
13 * Lawrence Berkeley Laboratory and its contributors.'' Neither the name of
14 * the University nor the names of its contributors may be used to endorse
15 * or promote products derived from this software without specific prior
16 * written permission.
17 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
18 * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
19 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
20 *
21 * OSPF support contributed by Jeffrey Honig (jch@mitchell.cit.cornell.edu)
22 */
23 #define OSPF_TYPE_HELLO 1 /* Hello */
24 #define OSPF_TYPE_DD 2 /* Database Description */
25 #define OSPF_TYPE_LS_REQ 3 /* Link State Request */
26 #define OSPF_TYPE_LS_UPDATE 4 /* Link State Update */
27 #define OSPF_TYPE_LS_ACK 5 /* Link State Ack */
28
29 /* Options field
30 *
31 * +------------------------------------+
32 * | DN | O | DC | L | N/P | MC | E | T |
33 * +------------------------------------+
34 *
35 */
36
37 #define OSPF_OPTION_MT 0x01 /* MT bit: multi-topology */
38 #define OSPF_OPTION_E 0x02 /* E bit: External routes advertised */
39 #define OSPF_OPTION_MC 0x04 /* MC bit: Multicast capable */
40 #define OSPF_OPTION_NP 0x08 /* N/P bit: NSSA capable */
41 #define OSPF_OPTION_L 0x10 /* L bit: Packet contains LLS data block */
42 #define OSPF_OPTION_DC 0x20 /* DC bit: Demand circuit capable */
43 #define OSPF_OPTION_O 0x40 /* O bit: Opaque LSA capable */
44 #define OSPF_OPTION_DN 0x80 /* DN bit: Up/Down Bit capable - draft-ietf-ospf-2547-dnbit-04 */
45
46 /* ospf_authtype */
47 #define OSPF_AUTH_NONE 0 /* No auth-data */
48 #define OSPF_AUTH_SIMPLE 1 /* Simple password */
49 #define OSPF_AUTH_SIMPLE_LEN 8 /* max length of simple authentication */
50 #define OSPF_AUTH_MD5 2 /* MD5 authentication */
51 #define OSPF_AUTH_MD5_LEN 16 /* length of MD5 authentication */
52
53 /* db_flags */
54 #define OSPF_DB_INIT 0x04
55 #define OSPF_DB_MORE 0x02
56 #define OSPF_DB_MASTER 0x01
57 #define OSPF_DB_RESYNC 0x08 /* RFC4811 */
58
59 /* ls_type */
60 #define LS_TYPE_ROUTER 1 /* router link */
61 #define LS_TYPE_NETWORK 2 /* network link */
62 #define LS_TYPE_SUM_IP 3 /* summary link */
63 #define LS_TYPE_SUM_ABR 4 /* summary area link */
64 #define LS_TYPE_ASE 5 /* ASE */
65 #define LS_TYPE_GROUP 6 /* Group membership (multicast */
66 /* extensions 23 July 1991) */
67 #define LS_TYPE_NSSA 7 /* rfc3101 - Not so Stubby Areas */
68 #define LS_TYPE_OPAQUE_LL 9 /* rfc2370 - Opaque Link Local */
69 #define LS_TYPE_OPAQUE_AL 10 /* rfc2370 - Opaque Link Local */
70 #define LS_TYPE_OPAQUE_DW 11 /* rfc2370 - Opaque Domain Wide */
71
72 #define LS_OPAQUE_TYPE_TE 1 /* rfc3630 */
73 #define LS_OPAQUE_TYPE_GRACE 3 /* rfc3623 */
74 #define LS_OPAQUE_TYPE_RI 4 /* draft-ietf-ospf-cap-03 */
75 #define LS_OPAQUE_TYPE_EP 7 /* rfc7684 */
76
77 #define LS_OPAQUE_TE_TLV_ROUTER 1 /* rfc3630 */
78 #define LS_OPAQUE_TE_TLV_LINK 2 /* rfc3630 */
79
80 #define LS_OPAQUE_TE_LINK_SUBTLV_LINK_TYPE 1 /* rfc3630 */
81 #define LS_OPAQUE_TE_LINK_SUBTLV_LINK_ID 2 /* rfc3630 */
82 #define LS_OPAQUE_TE_LINK_SUBTLV_LOCAL_IP 3 /* rfc3630 */
83 #define LS_OPAQUE_TE_LINK_SUBTLV_REMOTE_IP 4 /* rfc3630 */
84 #define LS_OPAQUE_TE_LINK_SUBTLV_TE_METRIC 5 /* rfc3630 */
85 #define LS_OPAQUE_TE_LINK_SUBTLV_MAX_BW 6 /* rfc3630 */
86 #define LS_OPAQUE_TE_LINK_SUBTLV_MAX_RES_BW 7 /* rfc3630 */
87 #define LS_OPAQUE_TE_LINK_SUBTLV_UNRES_BW 8 /* rfc3630 */
88 #define LS_OPAQUE_TE_LINK_SUBTLV_ADMIN_GROUP 9 /* rfc3630 */
89 #define LS_OPAQUE_TE_LINK_SUBTLV_LINK_LOCAL_REMOTE_ID 11 /* rfc4203 */
90 #define LS_OPAQUE_TE_LINK_SUBTLV_LINK_PROTECTION_TYPE 14 /* rfc4203 */
91 #define LS_OPAQUE_TE_LINK_SUBTLV_INTF_SW_CAP_DESCR 15 /* rfc4203 */
92 #define LS_OPAQUE_TE_LINK_SUBTLV_SHARED_RISK_GROUP 16 /* rfc4203 */
93 #define LS_OPAQUE_TE_LINK_SUBTLV_BW_CONSTRAINTS 17 /* rfc4124 */
94
95 #define LS_OPAQUE_TE_LINK_SUBTLV_LINK_TYPE_PTP 1 /* rfc3630 */
96 #define LS_OPAQUE_TE_LINK_SUBTLV_LINK_TYPE_MA 2 /* rfc3630 */
97
98 #define LS_OPAQUE_RI_SUBTLV_SID_LABEL 1 /* rfc8665 */
99
100 #define LS_OPAQUE_EP_EXTD_PREFIX_TLV 1 /* rfc7684 */
101 #define LS_OPAQUE_EP_EXTD_PREFIX_RANGE_TLV 2 /* rfc8665 */
102 #define LS_OPAQUE_EP_SUBTLV_PREFIX_SID 2 /* rfc8665 */
103
104 #define LS_OPAQUE_GRACE_TLV_PERIOD 1 /* rfc3623 */
105 #define LS_OPAQUE_GRACE_TLV_REASON 2 /* rfc3623 */
106 #define LS_OPAQUE_GRACE_TLV_INT_ADDRESS 3 /* rfc3623 */
107
108 #define LS_OPAQUE_GRACE_TLV_REASON_UNKNOWN 0 /* rfc3623 */
109 #define LS_OPAQUE_GRACE_TLV_REASON_SW_RESTART 1 /* rfc3623 */
110 #define LS_OPAQUE_GRACE_TLV_REASON_SW_UPGRADE 2 /* rfc3623 */
111 #define LS_OPAQUE_GRACE_TLV_REASON_CP_SWITCH 3 /* rfc3623 */
112
113 #define LS_OPAQUE_RI_TLV_CAP 1 /* draft-ietf-ospf-cap-03 */
114 #define LS_OPAQUE_RI_TLV_HOSTNAME 7 /* rfc5642 */
115 #define LS_OPAQUE_RI_TLV_SID_LABEL_RANGE 9 /* rfc8665 */
116
117 /* rla_link.link_type */
118 #define RLA_TYPE_ROUTER 1 /* point-to-point to another router */
119 #define RLA_TYPE_TRANSIT 2 /* connection to transit network */
120 #define RLA_TYPE_STUB 3 /* connection to stub network */
121 #define RLA_TYPE_VIRTUAL 4 /* virtual link */
122
123 /* rla_flags */
124 #define RLA_FLAG_B 0x01
125 #define RLA_FLAG_E 0x02
126 #define RLA_FLAG_V 0x04
127 #define RLA_FLAG_W 0x08
128 #define RLA_FLAG_NT 0x10 /* RFC3101 Appendix B */
129 #define RLA_FLAG_H 0x80
130
131 /* sla_tosmetric breakdown */
132 #define SLA_MASK_TOS 0x7f000000
133 #define SLA_MASK_METRIC 0x00ffffff
134 #define SLA_SHIFT_TOS 24
135
136 /* asla_tosmetric breakdown */
137 #define ASLA_FLAG_EXTERNAL 0x80000000
138 #define ASLA_MASK_TOS 0x7f000000
139 #define ASLA_SHIFT_TOS 24
140 #define ASLA_MASK_METRIC 0x00ffffff
141
142 /* multicast vertex type */
143 #define MCLA_VERTEX_ROUTER 1
144 #define MCLA_VERTEX_NETWORK 2
145
146 /* Link-Local-Signaling */
147 #define OSPF_LLS_HDRLEN 4U /* RFC5613 Section 2.2 */
148
149 #define OSPF_LLS_EO 1 /* RFC4811, RFC4812 */
150 #define OSPF_LLS_MD5 2 /* RFC4813 */
151
152 #define OSPF_LLS_EO_LR 0x00000001 /* RFC4811 */
153 #define OSPF_LLS_EO_RS 0x00000002 /* RFC4812 */
154
155 /*
156 * TOS metric struct (will be 0 or more in router links update)
157 */
158 struct tos_metric {
159 nd_uint8_t tos_type;
160 nd_uint8_t reserved;
161 nd_uint16_t tos_metric;
162 };
163 struct tos_link {
164 nd_uint8_t link_type;
165 nd_uint8_t link_tos_count;
166 nd_uint16_t tos_metric;
167 };
168 union un_tos {
169 struct tos_link link;
170 struct tos_metric metrics;
171 };
172
173 /* link state advertisement header */
174 struct lsa_hdr {
175 nd_uint16_t ls_age;
176 nd_uint8_t ls_options;
177 nd_uint8_t ls_type;
178 union {
179 nd_ipv4 lsa_id;
180 struct { /* opaque LSAs change the LSA-ID field */
181 nd_uint8_t opaque_type;
182 nd_uint24_t opaque_id;
183 } opaque_field;
184 } un_lsa_id;
185 nd_ipv4 ls_router;
186 nd_uint32_t ls_seq;
187 nd_uint16_t ls_chksum;
188 nd_uint16_t ls_length;
189 };
190
191 /* link state advertisement */
192 struct lsa {
193 struct lsa_hdr ls_hdr;
194
195 /* Link state types */
196 union {
197 /* Router links advertisements */
198 struct {
199 nd_uint8_t rla_flags;
200 nd_byte rla_zero;
201 nd_uint16_t rla_count;
202 struct rlalink {
203 nd_ipv4 link_id;
204 nd_ipv4 link_data;
205 union un_tos un_tos;
206 } rla_link[1]; /* may repeat */
207 } un_rla;
208
209 /* Network links advertisements */
210 struct {
211 nd_ipv4 nla_mask;
212 nd_ipv4 nla_router[1]; /* may repeat */
213 } un_nla;
214
215 /* Summary links advertisements */
216 struct {
217 nd_ipv4 sla_mask;
218 nd_uint32_t sla_tosmetric[1]; /* may repeat */
219 } un_sla;
220
221 /* AS external links advertisements */
222 struct {
223 nd_ipv4 asla_mask;
224 struct aslametric {
225 nd_uint32_t asla_tosmetric;
226 nd_ipv4 asla_forward;
227 nd_ipv4 asla_tag;
228 } asla_metric[1]; /* may repeat */
229 } un_asla;
230
231 /* Multicast group membership */
232 struct mcla {
233 nd_uint32_t mcla_vtype;
234 nd_ipv4 mcla_vid;
235 } un_mcla[1];
236
237 /* Opaque TE LSA */
238 struct {
239 nd_uint16_t type;
240 nd_uint16_t length;
241 nd_byte data[1]; /* may repeat */
242 } un_te_lsa_tlv[1]; /* may repeat */
243
244 /* Opaque Grace LSA */
245 struct {
246 nd_uint16_t type;
247 nd_uint16_t length;
248 nd_byte data[1]; /* may repeat */
249 } un_grace_tlv[1]; /* may repeat */
250
251 /* Opaque Router information LSA */
252 struct {
253 nd_uint16_t type;
254 nd_uint16_t length;
255 nd_byte data[1]; /* may repeat */
256 } un_ri_tlv[1]; /* may repeat */
257
258 /* Extended Prefix LSA */
259 struct {
260 nd_uint16_t type;
261 nd_uint16_t length;
262 nd_byte data[1]; /* may repeat */
263 } un_ep_tlv[1]; /* may repeat */
264
265 /* Unknown LSA */
266 struct unknown {
267 nd_byte data[1]; /* may repeat */
268 } un_unknown[1];
269
270 } lsa_un;
271 };
272
273 #define OSPF_AUTH_SIZE 8
274
275 /*
276 * the main header
277 */
278 struct ospfhdr {
279 nd_uint8_t ospf_version;
280 nd_uint8_t ospf_type;
281 nd_uint16_t ospf_len;
282 nd_ipv4 ospf_routerid;
283 nd_ipv4 ospf_areaid;
284 nd_uint16_t ospf_chksum;
285 nd_uint16_t ospf_authtype;
286 nd_byte ospf_authdata[OSPF_AUTH_SIZE];
287 union {
288
289 /* Hello packet */
290 struct {
291 nd_ipv4 hello_mask;
292 nd_uint16_t hello_helloint;
293 nd_uint8_t hello_options;
294 nd_uint8_t hello_priority;
295 nd_uint32_t hello_deadint;
296 nd_ipv4 hello_dr;
297 nd_ipv4 hello_bdr;
298 nd_ipv4 hello_neighbor[1]; /* may repeat */
299 } un_hello;
300
301 /* Database Description packet */
302 struct {
303 nd_uint16_t db_ifmtu;
304 nd_uint8_t db_options;
305 nd_uint8_t db_flags;
306 nd_uint32_t db_seq;
307 struct lsa_hdr db_lshdr[1]; /* may repeat */
308 } un_db;
309
310 /* Link State Request */
311 struct lsr {
312 nd_uint32_t ls_type;
313 union {
314 nd_ipv4 ls_stateid;
315 struct { /* opaque LSAs change the LSA-ID field */
316 nd_uint8_t opaque_type;
317 nd_uint24_t opaque_id;
318 } opaque_field;
319 } un_ls_stateid;
320 nd_ipv4 ls_router;
321 } un_lsr[1]; /* may repeat */
322
323 /* Link State Update */
324 struct {
325 nd_uint32_t lsu_count;
326 struct lsa lsu_lsa[1]; /* may repeat */
327 } un_lsu;
328
329 /* Link State Acknowledgement */
330 struct {
331 struct lsa_hdr lsa_lshdr[1]; /* may repeat */
332 } un_lsa ;
333 } ospf_un ;
334 };
335
336 #define ospf_hello ospf_un.un_hello
337 #define ospf_db ospf_un.un_db
338 #define ospf_lsr ospf_un.un_lsr
339 #define ospf_lsu ospf_un.un_lsu
340 #define ospf_lsa ospf_un.un_lsa