blob: a4e90c8cfdcc19b14e3ca7215f043ac81fe4503a [file] [log] [blame]
The Android Open Source Project2949f582009-03-03 19:30:46 -08001/*
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 */
The Android Open Source Project2949f582009-03-03 19:30:46 -080023#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 * +------------------------------------+
JP Abgrall53f17a92014-02-12 14:02:41 -080032 * | DN | O | DC | L | N/P | MC | E | T |
The Android Open Source Project2949f582009-03-03 19:30:46 -080033 * +------------------------------------+
34 *
35 */
Elliott Hughes892a68b2015-10-19 14:43:53 -070036
Elliott Hughes820eced2021-08-20 18:00:50 -070037#define OSPF_OPTION_MT 0x01 /* MT bit: multi-topology */
38#define OSPF_OPTION_E 0x02 /* E bit: External routes advertised */
The Android Open Source Project2949f582009-03-03 19:30:46 -080039#define OSPF_OPTION_MC 0x04 /* MC bit: Multicast capable */
40#define OSPF_OPTION_NP 0x08 /* N/P bit: NSSA capable */
JP Abgrall53f17a92014-02-12 14:02:41 -080041#define OSPF_OPTION_L 0x10 /* L bit: Packet contains LLS data block */
The Android Open Source Project2949f582009-03-03 19:30:46 -080042#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 */
JP Abgrall53f17a92014-02-12 14:02:41 -080054#define OSPF_DB_INIT 0x04
The Android Open Source Project2949f582009-03-03 19:30:46 -080055#define OSPF_DB_MORE 0x02
JP Abgrall53f17a92014-02-12 14:02:41 -080056#define OSPF_DB_MASTER 0x01
57#define OSPF_DB_RESYNC 0x08 /* RFC4811 */
The Android Open Source Project2949f582009-03-03 19:30:46 -080058
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
76#define LS_OPAQUE_TE_TLV_ROUTER 1 /* rfc3630 */
77#define LS_OPAQUE_TE_TLV_LINK 2 /* rfc3630 */
78
79#define LS_OPAQUE_TE_LINK_SUBTLV_LINK_TYPE 1 /* rfc3630 */
80#define LS_OPAQUE_TE_LINK_SUBTLV_LINK_ID 2 /* rfc3630 */
81#define LS_OPAQUE_TE_LINK_SUBTLV_LOCAL_IP 3 /* rfc3630 */
82#define LS_OPAQUE_TE_LINK_SUBTLV_REMOTE_IP 4 /* rfc3630 */
83#define LS_OPAQUE_TE_LINK_SUBTLV_TE_METRIC 5 /* rfc3630 */
84#define LS_OPAQUE_TE_LINK_SUBTLV_MAX_BW 6 /* rfc3630 */
85#define LS_OPAQUE_TE_LINK_SUBTLV_MAX_RES_BW 7 /* rfc3630 */
86#define LS_OPAQUE_TE_LINK_SUBTLV_UNRES_BW 8 /* rfc3630 */
87#define LS_OPAQUE_TE_LINK_SUBTLV_ADMIN_GROUP 9 /* rfc3630 */
JP Abgrall53f17a92014-02-12 14:02:41 -080088#define LS_OPAQUE_TE_LINK_SUBTLV_LINK_LOCAL_REMOTE_ID 11 /* rfc4203 */
89#define LS_OPAQUE_TE_LINK_SUBTLV_LINK_PROTECTION_TYPE 14 /* rfc4203 */
90#define LS_OPAQUE_TE_LINK_SUBTLV_INTF_SW_CAP_DESCR 15 /* rfc4203 */
91#define LS_OPAQUE_TE_LINK_SUBTLV_SHARED_RISK_GROUP 16 /* rfc4203 */
The Android Open Source Project2949f582009-03-03 19:30:46 -080092#define LS_OPAQUE_TE_LINK_SUBTLV_BW_CONSTRAINTS 17 /* rfc4124 */
93
94#define LS_OPAQUE_TE_LINK_SUBTLV_LINK_TYPE_PTP 1 /* rfc3630 */
95#define LS_OPAQUE_TE_LINK_SUBTLV_LINK_TYPE_MA 2 /* rfc3630 */
96
97#define LS_OPAQUE_GRACE_TLV_PERIOD 1 /* rfc3623 */
98#define LS_OPAQUE_GRACE_TLV_REASON 2 /* rfc3623 */
99#define LS_OPAQUE_GRACE_TLV_INT_ADDRESS 3 /* rfc3623 */
100
101#define LS_OPAQUE_GRACE_TLV_REASON_UNKNOWN 0 /* rfc3623 */
102#define LS_OPAQUE_GRACE_TLV_REASON_SW_RESTART 1 /* rfc3623 */
103#define LS_OPAQUE_GRACE_TLV_REASON_SW_UPGRADE 2 /* rfc3623 */
104#define LS_OPAQUE_GRACE_TLV_REASON_CP_SWITCH 3 /* rfc3623 */
105
106#define LS_OPAQUE_RI_TLV_CAP 1 /* draft-ietf-ospf-cap-03 */
107
The Android Open Source Project2949f582009-03-03 19:30:46 -0800108
109/* rla_link.link_type */
110#define RLA_TYPE_ROUTER 1 /* point-to-point to another router */
111#define RLA_TYPE_TRANSIT 2 /* connection to transit network */
112#define RLA_TYPE_STUB 3 /* connection to stub network */
113#define RLA_TYPE_VIRTUAL 4 /* virtual link */
114
115/* rla_flags */
116#define RLA_FLAG_B 0x01
117#define RLA_FLAG_E 0x02
118#define RLA_FLAG_W1 0x04
119#define RLA_FLAG_W2 0x08
120
121/* sla_tosmetric breakdown */
122#define SLA_MASK_TOS 0x7f000000
123#define SLA_MASK_METRIC 0x00ffffff
124#define SLA_SHIFT_TOS 24
125
126/* asla_tosmetric breakdown */
127#define ASLA_FLAG_EXTERNAL 0x80000000
128#define ASLA_MASK_TOS 0x7f000000
129#define ASLA_SHIFT_TOS 24
130#define ASLA_MASK_METRIC 0x00ffffff
131
132/* multicast vertex type */
133#define MCLA_VERTEX_ROUTER 1
134#define MCLA_VERTEX_NETWORK 2
135
JP Abgrall53f17a92014-02-12 14:02:41 -0800136/* Link-Local-Signaling */
Elliott Hughes892a68b2015-10-19 14:43:53 -0700137#define OSPF_LLS_HDRLEN 4U /* RFC5613 Section 2.2 */
138
JP Abgrall53f17a92014-02-12 14:02:41 -0800139#define OSPF_LLS_EO 1 /* RFC4811, RFC4812 */
140#define OSPF_LLS_MD5 2 /* RFC4813 */
141
142#define OSPF_LLS_EO_LR 0x00000001 /* RFC4811 */
143#define OSPF_LLS_EO_RS 0x00000002 /* RFC4812 */
144
145/*
146 * TOS metric struct (will be 0 or more in router links update)
147 */
148struct tos_metric {
Elliott Hughes820eced2021-08-20 18:00:50 -0700149 nd_uint8_t tos_type;
150 nd_uint8_t reserved;
151 nd_uint16_t tos_metric;
JP Abgrall53f17a92014-02-12 14:02:41 -0800152};
153struct tos_link {
Elliott Hughes820eced2021-08-20 18:00:50 -0700154 nd_uint8_t link_type;
155 nd_uint8_t link_tos_count;
156 nd_uint16_t tos_metric;
JP Abgrall53f17a92014-02-12 14:02:41 -0800157};
158union un_tos {
159 struct tos_link link;
160 struct tos_metric metrics;
161};
162
The Android Open Source Project2949f582009-03-03 19:30:46 -0800163/* link state advertisement header */
164struct lsa_hdr {
Elliott Hughes820eced2021-08-20 18:00:50 -0700165 nd_uint16_t ls_age;
166 nd_uint8_t ls_options;
167 nd_uint8_t ls_type;
The Android Open Source Project2949f582009-03-03 19:30:46 -0800168 union {
Elliott Hughes820eced2021-08-20 18:00:50 -0700169 nd_ipv4 lsa_id;
The Android Open Source Project2949f582009-03-03 19:30:46 -0800170 struct { /* opaque LSAs change the LSA-ID field */
Elliott Hughes820eced2021-08-20 18:00:50 -0700171 nd_uint8_t opaque_type;
172 nd_uint24_t opaque_id;
The Android Open Source Project2949f582009-03-03 19:30:46 -0800173 } opaque_field;
174 } un_lsa_id;
Elliott Hughes820eced2021-08-20 18:00:50 -0700175 nd_ipv4 ls_router;
176 nd_uint32_t ls_seq;
177 nd_uint16_t ls_chksum;
178 nd_uint16_t ls_length;
The Android Open Source Project2949f582009-03-03 19:30:46 -0800179};
180
181/* link state advertisement */
182struct lsa {
183 struct lsa_hdr ls_hdr;
184
185 /* Link state types */
186 union {
187 /* Router links advertisements */
188 struct {
Elliott Hughes820eced2021-08-20 18:00:50 -0700189 nd_uint8_t rla_flags;
190 nd_byte rla_zero;
191 nd_uint16_t rla_count;
The Android Open Source Project2949f582009-03-03 19:30:46 -0800192 struct rlalink {
Elliott Hughes820eced2021-08-20 18:00:50 -0700193 nd_ipv4 link_id;
194 nd_ipv4 link_data;
JP Abgrall53f17a92014-02-12 14:02:41 -0800195 union un_tos un_tos;
The Android Open Source Project2949f582009-03-03 19:30:46 -0800196 } rla_link[1]; /* may repeat */
197 } un_rla;
198
199 /* Network links advertisements */
200 struct {
Elliott Hughes820eced2021-08-20 18:00:50 -0700201 nd_ipv4 nla_mask;
202 nd_ipv4 nla_router[1]; /* may repeat */
The Android Open Source Project2949f582009-03-03 19:30:46 -0800203 } un_nla;
204
205 /* Summary links advertisements */
206 struct {
Elliott Hughes820eced2021-08-20 18:00:50 -0700207 nd_ipv4 sla_mask;
208 nd_uint32_t sla_tosmetric[1]; /* may repeat */
The Android Open Source Project2949f582009-03-03 19:30:46 -0800209 } un_sla;
210
211 /* AS external links advertisements */
212 struct {
Elliott Hughes820eced2021-08-20 18:00:50 -0700213 nd_ipv4 asla_mask;
The Android Open Source Project2949f582009-03-03 19:30:46 -0800214 struct aslametric {
Elliott Hughes820eced2021-08-20 18:00:50 -0700215 nd_uint32_t asla_tosmetric;
216 nd_ipv4 asla_forward;
217 nd_ipv4 asla_tag;
The Android Open Source Project2949f582009-03-03 19:30:46 -0800218 } asla_metric[1]; /* may repeat */
219 } un_asla;
220
221 /* Multicast group membership */
222 struct mcla {
Elliott Hughes820eced2021-08-20 18:00:50 -0700223 nd_uint32_t mcla_vtype;
224 nd_ipv4 mcla_vid;
The Android Open Source Project2949f582009-03-03 19:30:46 -0800225 } un_mcla[1];
226
227 /* Opaque TE LSA */
228 struct {
Elliott Hughes820eced2021-08-20 18:00:50 -0700229 nd_uint16_t type;
230 nd_uint16_t length;
231 nd_byte data[1]; /* may repeat */
232 } un_te_lsa_tlv[1]; /* may repeat */
The Android Open Source Project2949f582009-03-03 19:30:46 -0800233
234 /* Opaque Grace LSA */
235 struct {
Elliott Hughes820eced2021-08-20 18:00:50 -0700236 nd_uint16_t type;
237 nd_uint16_t length;
238 nd_byte data[1]; /* may repeat */
239 } un_grace_tlv[1]; /* may repeat */
The Android Open Source Project2949f582009-03-03 19:30:46 -0800240
241 /* Opaque Router information LSA */
242 struct {
Elliott Hughes820eced2021-08-20 18:00:50 -0700243 nd_uint16_t type;
244 nd_uint16_t length;
245 nd_byte data[1]; /* may repeat */
246 } un_ri_tlv[1]; /* may repeat */
The Android Open Source Project2949f582009-03-03 19:30:46 -0800247
248 /* Unknown LSA */
249 struct unknown {
Elliott Hughes820eced2021-08-20 18:00:50 -0700250 nd_byte data[1]; /* may repeat */
The Android Open Source Project2949f582009-03-03 19:30:46 -0800251 } un_unknown[1];
252
253 } lsa_un;
254};
255
The Android Open Source Project2949f582009-03-03 19:30:46 -0800256#define OSPF_AUTH_SIZE 8
257
258/*
259 * the main header
260 */
261struct ospfhdr {
Elliott Hughes820eced2021-08-20 18:00:50 -0700262 nd_uint8_t ospf_version;
263 nd_uint8_t ospf_type;
264 nd_uint16_t ospf_len;
265 nd_ipv4 ospf_routerid;
266 nd_ipv4 ospf_areaid;
267 nd_uint16_t ospf_chksum;
268 nd_uint16_t ospf_authtype;
269 nd_byte ospf_authdata[OSPF_AUTH_SIZE];
The Android Open Source Project2949f582009-03-03 19:30:46 -0800270 union {
271
272 /* Hello packet */
273 struct {
Elliott Hughes820eced2021-08-20 18:00:50 -0700274 nd_ipv4 hello_mask;
275 nd_uint16_t hello_helloint;
276 nd_uint8_t hello_options;
277 nd_uint8_t hello_priority;
278 nd_uint32_t hello_deadint;
279 nd_ipv4 hello_dr;
280 nd_ipv4 hello_bdr;
281 nd_ipv4 hello_neighbor[1]; /* may repeat */
The Android Open Source Project2949f582009-03-03 19:30:46 -0800282 } un_hello;
283
284 /* Database Description packet */
285 struct {
Elliott Hughes820eced2021-08-20 18:00:50 -0700286 nd_uint16_t db_ifmtu;
287 nd_uint8_t db_options;
288 nd_uint8_t db_flags;
289 nd_uint32_t db_seq;
The Android Open Source Project2949f582009-03-03 19:30:46 -0800290 struct lsa_hdr db_lshdr[1]; /* may repeat */
291 } un_db;
292
293 /* Link State Request */
294 struct lsr {
Elliott Hughes820eced2021-08-20 18:00:50 -0700295 nd_uint32_t ls_type;
The Android Open Source Project2949f582009-03-03 19:30:46 -0800296 union {
Elliott Hughes820eced2021-08-20 18:00:50 -0700297 nd_ipv4 ls_stateid;
The Android Open Source Project2949f582009-03-03 19:30:46 -0800298 struct { /* opaque LSAs change the LSA-ID field */
Elliott Hughes820eced2021-08-20 18:00:50 -0700299 nd_uint8_t opaque_type;
300 nd_uint24_t opaque_id;
The Android Open Source Project2949f582009-03-03 19:30:46 -0800301 } opaque_field;
302 } un_ls_stateid;
Elliott Hughes820eced2021-08-20 18:00:50 -0700303 nd_ipv4 ls_router;
The Android Open Source Project2949f582009-03-03 19:30:46 -0800304 } un_lsr[1]; /* may repeat */
305
306 /* Link State Update */
307 struct {
Elliott Hughes820eced2021-08-20 18:00:50 -0700308 nd_uint32_t lsu_count;
309 struct lsa lsu_lsa[1]; /* may repeat */
The Android Open Source Project2949f582009-03-03 19:30:46 -0800310 } un_lsu;
311
312 /* Link State Acknowledgement */
313 struct {
314 struct lsa_hdr lsa_lshdr[1]; /* may repeat */
315 } un_lsa ;
316 } ospf_un ;
317};
318
319#define ospf_hello ospf_un.un_hello
320#define ospf_db ospf_un.un_db
321#define ospf_lsr ospf_un.un_lsr
322#define ospf_lsu ospf_un.un_lsu
323#define ospf_lsa ospf_un.un_lsa