print-ospf6.c revision 1.1.1.5 1 1.1 christos /*
2 1.1 christos * Copyright (c) 1992, 1993, 1994, 1995, 1996, 1997
3 1.1 christos * The Regents of the University of California. All rights reserved.
4 1.1 christos *
5 1.1 christos * Redistribution and use in source and binary forms, with or without
6 1.1 christos * modification, are permitted provided that: (1) source code distributions
7 1.1 christos * retain the above copyright notice and this paragraph in its entirety, (2)
8 1.1 christos * distributions including binary code include the above copyright notice and
9 1.1 christos * this paragraph in its entirety in the documentation or other materials
10 1.1 christos * provided with the distribution, and (3) all advertising materials mentioning
11 1.1 christos * features or use of this software display the following acknowledgement:
12 1.1 christos * ``This product includes software developed by the University of California,
13 1.1 christos * Lawrence Berkeley Laboratory and its contributors.'' Neither the name of
14 1.1 christos * the University nor the names of its contributors may be used to endorse
15 1.1 christos * or promote products derived from this software without specific prior
16 1.1 christos * written permission.
17 1.1 christos * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
18 1.1 christos * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
19 1.1 christos * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
20 1.1 christos *
21 1.1 christos * OSPF support contributed by Jeffrey Honig (jch (at) mitchell.cit.cornell.edu)
22 1.1 christos */
23 1.1 christos
24 1.1 christos #ifdef HAVE_CONFIG_H
25 1.1 christos #include "config.h"
26 1.1 christos #endif
27 1.1 christos
28 1.1.1.5 christos #include <netdissect-stdinc.h>
29 1.1 christos
30 1.1 christos #include <string.h>
31 1.1 christos
32 1.1.1.5 christos #include "netdissect.h"
33 1.1 christos #include "addrtoname.h"
34 1.1 christos #include "extract.h"
35 1.1 christos
36 1.1 christos #include "ospf.h"
37 1.1.1.4 christos
38 1.1.1.4 christos #define OSPF_TYPE_HELLO 1 /* Hello */
39 1.1.1.4 christos #define OSPF_TYPE_DD 2 /* Database Description */
40 1.1.1.4 christos #define OSPF_TYPE_LS_REQ 3 /* Link State Request */
41 1.1.1.4 christos #define OSPF_TYPE_LS_UPDATE 4 /* Link State Update */
42 1.1.1.4 christos #define OSPF_TYPE_LS_ACK 5 /* Link State Ack */
43 1.1.1.4 christos
44 1.1.1.4 christos /* Options *_options */
45 1.1.1.4 christos #define OSPF6_OPTION_V6 0x01 /* V6 bit: A bit for peeping tom */
46 1.1.1.4 christos #define OSPF6_OPTION_E 0x02 /* E bit: External routes advertised */
47 1.1.1.4 christos #define OSPF6_OPTION_MC 0x04 /* MC bit: Multicast capable */
48 1.1.1.4 christos #define OSPF6_OPTION_N 0x08 /* N bit: For type-7 LSA */
49 1.1.1.4 christos #define OSPF6_OPTION_R 0x10 /* R bit: Router bit */
50 1.1.1.4 christos #define OSPF6_OPTION_DC 0x20 /* DC bit: Demand circuits */
51 1.1.1.4 christos /* The field is actually 24-bit (RFC5340 Section A.2). */
52 1.1.1.4 christos #define OSPF6_OPTION_AF 0x0100 /* AF bit: Multiple address families */
53 1.1.1.4 christos #define OSPF6_OPTION_L 0x0200 /* L bit: Link-local signaling (LLS) */
54 1.1.1.4 christos #define OSPF6_OPTION_AT 0x0400 /* AT bit: Authentication trailer */
55 1.1.1.4 christos
56 1.1.1.4 christos
57 1.1.1.4 christos /* db_flags */
58 1.1.1.4 christos #define OSPF6_DB_INIT 0x04 /* */
59 1.1.1.4 christos #define OSPF6_DB_MORE 0x02
60 1.1.1.4 christos #define OSPF6_DB_MASTER 0x01
61 1.1.1.4 christos #define OSPF6_DB_M6 0x10 /* IPv6 MTU */
62 1.1.1.4 christos
63 1.1.1.4 christos /* ls_type */
64 1.1.1.4 christos #define LS_TYPE_ROUTER 1 /* router link */
65 1.1.1.4 christos #define LS_TYPE_NETWORK 2 /* network link */
66 1.1.1.4 christos #define LS_TYPE_INTER_AP 3 /* Inter-Area-Prefix */
67 1.1.1.4 christos #define LS_TYPE_INTER_AR 4 /* Inter-Area-Router */
68 1.1.1.4 christos #define LS_TYPE_ASE 5 /* ASE */
69 1.1.1.4 christos #define LS_TYPE_GROUP 6 /* Group membership */
70 1.1.1.4 christos #define LS_TYPE_NSSA 7 /* NSSA */
71 1.1.1.4 christos #define LS_TYPE_LINK 8 /* Link LSA */
72 1.1.1.4 christos #define LS_TYPE_INTRA_AP 9 /* Intra-Area-Prefix */
73 1.1.1.4 christos #define LS_TYPE_INTRA_ATE 10 /* Intra-Area-TE */
74 1.1.1.4 christos #define LS_TYPE_GRACE 11 /* Grace LSA */
75 1.1.1.4 christos #define LS_TYPE_RI 12 /* Router information */
76 1.1.1.4 christos #define LS_TYPE_INTER_ASTE 13 /* Inter-AS-TE */
77 1.1.1.4 christos #define LS_TYPE_L1VPN 14 /* L1VPN */
78 1.1.1.4 christos #define LS_TYPE_MASK 0x1fff
79 1.1.1.4 christos
80 1.1.1.4 christos #define LS_SCOPE_LINKLOCAL 0x0000
81 1.1.1.4 christos #define LS_SCOPE_AREA 0x2000
82 1.1.1.4 christos #define LS_SCOPE_AS 0x4000
83 1.1.1.4 christos #define LS_SCOPE_MASK 0x6000
84 1.1.1.4 christos #define LS_SCOPE_U 0x8000
85 1.1.1.4 christos
86 1.1.1.4 christos /* rla_link.link_type */
87 1.1.1.4 christos #define RLA_TYPE_ROUTER 1 /* point-to-point to another router */
88 1.1.1.4 christos #define RLA_TYPE_TRANSIT 2 /* connection to transit network */
89 1.1.1.4 christos #define RLA_TYPE_VIRTUAL 4 /* virtual link */
90 1.1.1.4 christos
91 1.1.1.4 christos /* rla_flags */
92 1.1.1.4 christos #define RLA_FLAG_B 0x01
93 1.1.1.4 christos #define RLA_FLAG_E 0x02
94 1.1.1.4 christos #define RLA_FLAG_V 0x04
95 1.1.1.4 christos #define RLA_FLAG_W 0x08
96 1.1.1.4 christos #define RLA_FLAG_N 0x10
97 1.1.1.4 christos
98 1.1.1.4 christos /* lsa_prefix options */
99 1.1.1.4 christos #define LSA_PREFIX_OPT_NU 0x01
100 1.1.1.4 christos #define LSA_PREFIX_OPT_LA 0x02
101 1.1.1.4 christos #define LSA_PREFIX_OPT_MC 0x04
102 1.1.1.4 christos #define LSA_PREFIX_OPT_P 0x08
103 1.1.1.4 christos #define LSA_PREFIX_OPT_DN 0x10
104 1.1.1.4 christos
105 1.1.1.4 christos /* sla_tosmetric breakdown */
106 1.1.1.4 christos #define SLA_MASK_TOS 0x7f000000
107 1.1.1.4 christos #define SLA_MASK_METRIC 0x00ffffff
108 1.1.1.4 christos #define SLA_SHIFT_TOS 24
109 1.1.1.4 christos
110 1.1.1.4 christos /* asla_metric */
111 1.1.1.4 christos #define ASLA_FLAG_FWDADDR 0x02000000
112 1.1.1.4 christos #define ASLA_FLAG_ROUTETAG 0x01000000
113 1.1.1.4 christos #define ASLA_MASK_METRIC 0x00ffffff
114 1.1.1.4 christos
115 1.1.1.4 christos /* RFC6506 Section 4.1 */
116 1.1.1.4 christos #define OSPF6_AT_HDRLEN 16U
117 1.1.1.4 christos #define OSPF6_AUTH_TYPE_HMAC 0x0001
118 1.1.1.4 christos
119 1.1.1.4 christos typedef uint32_t rtrid_t;
120 1.1.1.4 christos
121 1.1.1.4 christos /* link state advertisement header */
122 1.1.1.4 christos struct lsa6_hdr {
123 1.1.1.4 christos uint16_t ls_age;
124 1.1.1.4 christos uint16_t ls_type;
125 1.1.1.4 christos rtrid_t ls_stateid;
126 1.1.1.4 christos rtrid_t ls_router;
127 1.1.1.4 christos uint32_t ls_seq;
128 1.1.1.4 christos uint16_t ls_chksum;
129 1.1.1.4 christos uint16_t ls_length;
130 1.1.1.4 christos };
131 1.1.1.4 christos
132 1.1.1.4 christos /* Length of an IPv6 address, in bytes. */
133 1.1.1.4 christos #define IPV6_ADDR_LEN_BYTES (128/8)
134 1.1.1.4 christos
135 1.1.1.4 christos struct lsa6_prefix {
136 1.1.1.4 christos uint8_t lsa_p_len;
137 1.1.1.4 christos uint8_t lsa_p_opt;
138 1.1.1.4 christos uint16_t lsa_p_metric;
139 1.1.1.4 christos uint8_t lsa_p_prefix[IPV6_ADDR_LEN_BYTES]; /* maximum length */
140 1.1.1.4 christos };
141 1.1.1.4 christos
142 1.1.1.4 christos /* link state advertisement */
143 1.1.1.4 christos struct lsa6 {
144 1.1.1.4 christos struct lsa6_hdr ls_hdr;
145 1.1.1.4 christos
146 1.1.1.4 christos /* Link state types */
147 1.1.1.4 christos union {
148 1.1.1.4 christos /* Router links advertisements */
149 1.1.1.4 christos struct {
150 1.1.1.4 christos union {
151 1.1.1.4 christos uint8_t flg;
152 1.1.1.4 christos uint32_t opt;
153 1.1.1.4 christos } rla_flgandopt;
154 1.1.1.4 christos #define rla_flags rla_flgandopt.flg
155 1.1.1.4 christos #define rla_options rla_flgandopt.opt
156 1.1.1.4 christos struct rlalink6 {
157 1.1.1.4 christos uint8_t link_type;
158 1.1.1.4 christos uint8_t link_zero[1];
159 1.1.1.4 christos uint16_t link_metric;
160 1.1.1.4 christos uint32_t link_ifid;
161 1.1.1.4 christos uint32_t link_nifid;
162 1.1.1.4 christos rtrid_t link_nrtid;
163 1.1.1.4 christos } rla_link[1]; /* may repeat */
164 1.1.1.4 christos } un_rla;
165 1.1.1.4 christos
166 1.1.1.4 christos /* Network links advertisements */
167 1.1.1.4 christos struct {
168 1.1.1.4 christos uint32_t nla_options;
169 1.1.1.4 christos rtrid_t nla_router[1]; /* may repeat */
170 1.1.1.4 christos } un_nla;
171 1.1.1.4 christos
172 1.1.1.4 christos /* Inter Area Prefix LSA */
173 1.1.1.4 christos struct {
174 1.1.1.4 christos uint32_t inter_ap_metric;
175 1.1.1.4 christos struct lsa6_prefix inter_ap_prefix[1];
176 1.1.1.4 christos } un_inter_ap;
177 1.1.1.4 christos
178 1.1.1.4 christos /* AS external links advertisements */
179 1.1.1.4 christos struct {
180 1.1.1.4 christos uint32_t asla_metric;
181 1.1.1.4 christos struct lsa6_prefix asla_prefix[1];
182 1.1.1.4 christos /* some optional fields follow */
183 1.1.1.4 christos } un_asla;
184 1.1.1.4 christos
185 1.1.1.4 christos #if 0
186 1.1.1.4 christos /* Summary links advertisements */
187 1.1.1.4 christos struct {
188 1.1.1.4 christos struct in_addr sla_mask;
189 1.1.1.4 christos uint32_t sla_tosmetric[1]; /* may repeat */
190 1.1.1.4 christos } un_sla;
191 1.1.1.4 christos
192 1.1.1.4 christos /* Multicast group membership */
193 1.1.1.4 christos struct mcla {
194 1.1.1.4 christos uint32_t mcla_vtype;
195 1.1.1.4 christos struct in_addr mcla_vid;
196 1.1.1.4 christos } un_mcla[1];
197 1.1.1.4 christos #endif
198 1.1.1.4 christos
199 1.1.1.4 christos /* Type 7 LSA */
200 1.1.1.4 christos
201 1.1.1.4 christos /* Link LSA */
202 1.1.1.4 christos struct llsa {
203 1.1.1.4 christos union {
204 1.1.1.4 christos uint8_t pri;
205 1.1.1.4 christos uint32_t opt;
206 1.1.1.4 christos } llsa_priandopt;
207 1.1.1.4 christos #define llsa_priority llsa_priandopt.pri
208 1.1.1.4 christos #define llsa_options llsa_priandopt.opt
209 1.1.1.4 christos struct in6_addr llsa_lladdr;
210 1.1.1.4 christos uint32_t llsa_nprefix;
211 1.1.1.4 christos struct lsa6_prefix llsa_prefix[1];
212 1.1.1.4 christos } un_llsa;
213 1.1.1.4 christos
214 1.1.1.4 christos /* Intra-Area-Prefix */
215 1.1.1.4 christos struct {
216 1.1.1.4 christos uint16_t intra_ap_nprefix;
217 1.1.1.4 christos uint16_t intra_ap_lstype;
218 1.1.1.4 christos rtrid_t intra_ap_lsid;
219 1.1.1.4 christos rtrid_t intra_ap_rtid;
220 1.1.1.4 christos struct lsa6_prefix intra_ap_prefix[1];
221 1.1.1.4 christos } un_intra_ap;
222 1.1.1.4 christos } lsa_un;
223 1.1.1.4 christos };
224 1.1.1.4 christos
225 1.1.1.4 christos /*
226 1.1.1.4 christos * the main header
227 1.1.1.4 christos */
228 1.1.1.4 christos struct ospf6hdr {
229 1.1.1.4 christos uint8_t ospf6_version;
230 1.1.1.4 christos uint8_t ospf6_type;
231 1.1.1.4 christos uint16_t ospf6_len;
232 1.1.1.4 christos rtrid_t ospf6_routerid;
233 1.1.1.4 christos rtrid_t ospf6_areaid;
234 1.1.1.4 christos uint16_t ospf6_chksum;
235 1.1.1.4 christos uint8_t ospf6_instanceid;
236 1.1.1.4 christos uint8_t ospf6_rsvd;
237 1.1.1.4 christos };
238 1.1.1.4 christos
239 1.1.1.4 christos /*
240 1.1.1.4 christos * The OSPF6 header length is 16 bytes, regardless of how your compiler
241 1.1.1.4 christos * might choose to pad the above structure.
242 1.1.1.4 christos */
243 1.1.1.4 christos #define OSPF6HDR_LEN 16
244 1.1.1.4 christos
245 1.1.1.4 christos /* Hello packet */
246 1.1.1.4 christos struct hello6 {
247 1.1.1.4 christos uint32_t hello_ifid;
248 1.1.1.4 christos union {
249 1.1.1.4 christos uint8_t pri;
250 1.1.1.4 christos uint32_t opt;
251 1.1.1.4 christos } hello_priandopt;
252 1.1.1.4 christos #define hello_priority hello_priandopt.pri
253 1.1.1.4 christos #define hello_options hello_priandopt.opt
254 1.1.1.4 christos uint16_t hello_helloint;
255 1.1.1.4 christos uint16_t hello_deadint;
256 1.1.1.4 christos rtrid_t hello_dr;
257 1.1.1.4 christos rtrid_t hello_bdr;
258 1.1.1.4 christos rtrid_t hello_neighbor[1]; /* may repeat */
259 1.1.1.4 christos };
260 1.1.1.4 christos
261 1.1.1.4 christos /* Database Description packet */
262 1.1.1.4 christos struct dd6 {
263 1.1.1.4 christos uint32_t db_options;
264 1.1.1.4 christos uint16_t db_mtu;
265 1.1.1.4 christos uint8_t db_mbz;
266 1.1.1.4 christos uint8_t db_flags;
267 1.1.1.4 christos uint32_t db_seq;
268 1.1.1.4 christos struct lsa6_hdr db_lshdr[1]; /* may repeat */
269 1.1.1.4 christos };
270 1.1.1.4 christos
271 1.1.1.4 christos /* Link State Request */
272 1.1.1.4 christos struct lsr6 {
273 1.1.1.4 christos uint16_t ls_mbz;
274 1.1.1.4 christos uint16_t ls_type;
275 1.1.1.4 christos rtrid_t ls_stateid;
276 1.1.1.4 christos rtrid_t ls_router;
277 1.1.1.4 christos };
278 1.1.1.4 christos
279 1.1.1.4 christos /* Link State Update */
280 1.1.1.4 christos struct lsu6 {
281 1.1.1.4 christos uint32_t lsu_count;
282 1.1.1.4 christos struct lsa6 lsu_lsa[1]; /* may repeat */
283 1.1.1.4 christos };
284 1.1.1.4 christos
285 1.1.1.4 christos static const char tstr[] = " [|ospf3]";
286 1.1 christos
287 1.1 christos static const struct tok ospf6_option_values[] = {
288 1.1 christos { OSPF6_OPTION_V6, "V6" },
289 1.1 christos { OSPF6_OPTION_E, "External" },
290 1.1.1.4 christos { OSPF6_OPTION_MC, "Deprecated" },
291 1.1 christos { OSPF6_OPTION_N, "NSSA" },
292 1.1 christos { OSPF6_OPTION_R, "Router" },
293 1.1 christos { OSPF6_OPTION_DC, "Demand Circuit" },
294 1.1.1.4 christos { OSPF6_OPTION_AF, "AFs Support" },
295 1.1.1.4 christos { OSPF6_OPTION_L, "LLS" },
296 1.1.1.4 christos { OSPF6_OPTION_AT, "Authentication Trailer" },
297 1.1 christos { 0, NULL }
298 1.1 christos };
299 1.1 christos
300 1.1 christos static const struct tok ospf6_rla_flag_values[] = {
301 1.1 christos { RLA_FLAG_B, "ABR" },
302 1.1 christos { RLA_FLAG_E, "External" },
303 1.1 christos { RLA_FLAG_V, "Virtual-Link Endpoint" },
304 1.1 christos { RLA_FLAG_W, "Wildcard Receiver" },
305 1.1 christos { RLA_FLAG_N, "NSSA Translator" },
306 1.1 christos { 0, NULL }
307 1.1 christos };
308 1.1 christos
309 1.1 christos static const struct tok ospf6_asla_flag_values[] = {
310 1.1 christos { ASLA_FLAG_EXTERNAL, "External Type 2" },
311 1.1.1.4 christos { ASLA_FLAG_FWDADDR, "Forwarding" },
312 1.1 christos { ASLA_FLAG_ROUTETAG, "Tag" },
313 1.1 christos { 0, NULL }
314 1.1 christos };
315 1.1 christos
316 1.1.1.3 christos static const struct tok ospf6_type_values[] = {
317 1.1 christos { OSPF_TYPE_HELLO, "Hello" },
318 1.1 christos { OSPF_TYPE_DD, "Database Description" },
319 1.1 christos { OSPF_TYPE_LS_REQ, "LS-Request" },
320 1.1 christos { OSPF_TYPE_LS_UPDATE, "LS-Update" },
321 1.1 christos { OSPF_TYPE_LS_ACK, "LS-Ack" },
322 1.1 christos { 0, NULL }
323 1.1 christos };
324 1.1 christos
325 1.1.1.3 christos static const struct tok ospf6_lsa_values[] = {
326 1.1 christos { LS_TYPE_ROUTER, "Router" },
327 1.1 christos { LS_TYPE_NETWORK, "Network" },
328 1.1 christos { LS_TYPE_INTER_AP, "Inter-Area Prefix" },
329 1.1 christos { LS_TYPE_INTER_AR, "Inter-Area Router" },
330 1.1 christos { LS_TYPE_ASE, "External" },
331 1.1.1.4 christos { LS_TYPE_GROUP, "Deprecated" },
332 1.1 christos { LS_TYPE_NSSA, "NSSA" },
333 1.1 christos { LS_TYPE_LINK, "Link" },
334 1.1 christos { LS_TYPE_INTRA_AP, "Intra-Area Prefix" },
335 1.1 christos { LS_TYPE_INTRA_ATE, "Intra-Area TE" },
336 1.1 christos { LS_TYPE_GRACE, "Grace" },
337 1.1.1.4 christos { LS_TYPE_RI, "Router Information" },
338 1.1.1.4 christos { LS_TYPE_INTER_ASTE, "Inter-AS-TE" },
339 1.1.1.4 christos { LS_TYPE_L1VPN, "Layer 1 VPN" },
340 1.1 christos { 0, NULL }
341 1.1 christos };
342 1.1 christos
343 1.1.1.3 christos static const struct tok ospf6_ls_scope_values[] = {
344 1.1 christos { LS_SCOPE_LINKLOCAL, "Link Local" },
345 1.1 christos { LS_SCOPE_AREA, "Area Local" },
346 1.1 christos { LS_SCOPE_AS, "Domain Wide" },
347 1.1 christos { 0, NULL }
348 1.1 christos };
349 1.1 christos
350 1.1.1.3 christos static const struct tok ospf6_dd_flag_values[] = {
351 1.1 christos { OSPF6_DB_INIT, "Init" },
352 1.1 christos { OSPF6_DB_MORE, "More" },
353 1.1 christos { OSPF6_DB_MASTER, "Master" },
354 1.1.1.4 christos { OSPF6_DB_M6, "IPv6 MTU" },
355 1.1 christos { 0, NULL }
356 1.1 christos };
357 1.1 christos
358 1.1.1.3 christos static const struct tok ospf6_lsa_prefix_option_values[] = {
359 1.1 christos { LSA_PREFIX_OPT_NU, "No Unicast" },
360 1.1 christos { LSA_PREFIX_OPT_LA, "Local address" },
361 1.1.1.4 christos { LSA_PREFIX_OPT_MC, "Deprecated" },
362 1.1 christos { LSA_PREFIX_OPT_P, "Propagate" },
363 1.1 christos { LSA_PREFIX_OPT_DN, "Down" },
364 1.1 christos { 0, NULL }
365 1.1 christos };
366 1.1 christos
367 1.1.1.4 christos static const struct tok ospf6_auth_type_str[] = {
368 1.1.1.4 christos { OSPF6_AUTH_TYPE_HMAC, "HMAC" },
369 1.1.1.4 christos { 0, NULL }
370 1.1.1.4 christos };
371 1.1 christos
372 1.1 christos static void
373 1.1.1.4 christos ospf6_print_ls_type(netdissect_options *ndo,
374 1.1.1.4 christos register u_int ls_type, register const rtrid_t *ls_stateid)
375 1.1 christos {
376 1.1.1.4 christos ND_PRINT((ndo, "\n\t %s LSA (%d), %s Scope%s, LSA-ID %s",
377 1.1 christos tok2str(ospf6_lsa_values, "Unknown", ls_type & LS_TYPE_MASK),
378 1.1 christos ls_type & LS_TYPE_MASK,
379 1.1 christos tok2str(ospf6_ls_scope_values, "Unknown", ls_type & LS_SCOPE_MASK),
380 1.1 christos ls_type &0x8000 ? ", transitive" : "", /* U-bit */
381 1.1.1.4 christos ipaddr_string(ndo, ls_stateid)));
382 1.1 christos }
383 1.1 christos
384 1.1 christos static int
385 1.1.1.4 christos ospf6_print_lshdr(netdissect_options *ndo,
386 1.1.1.4 christos register const struct lsa6_hdr *lshp, const u_char *dataend)
387 1.1 christos {
388 1.1.1.5 christos if ((const u_char *)(lshp + 1) > dataend)
389 1.1.1.4 christos goto trunc;
390 1.1.1.4 christos ND_TCHECK(lshp->ls_type);
391 1.1.1.4 christos ND_TCHECK(lshp->ls_seq);
392 1.1 christos
393 1.1.1.4 christos ND_PRINT((ndo, "\n\t Advertising Router %s, seq 0x%08x, age %us, length %u",
394 1.1.1.4 christos ipaddr_string(ndo, &lshp->ls_router),
395 1.1 christos EXTRACT_32BITS(&lshp->ls_seq),
396 1.1 christos EXTRACT_16BITS(&lshp->ls_age),
397 1.1.1.4 christos EXTRACT_16BITS(&lshp->ls_length)-(u_int)sizeof(struct lsa6_hdr)));
398 1.1 christos
399 1.1.1.4 christos ospf6_print_ls_type(ndo, EXTRACT_16BITS(&lshp->ls_type), &lshp->ls_stateid);
400 1.1 christos
401 1.1 christos return (0);
402 1.1 christos trunc:
403 1.1 christos return (1);
404 1.1 christos }
405 1.1 christos
406 1.1 christos static int
407 1.1.1.4 christos ospf6_print_lsaprefix(netdissect_options *ndo,
408 1.1.1.4 christos const uint8_t *tptr, u_int lsa_length)
409 1.1 christos {
410 1.1.1.5 christos const struct lsa6_prefix *lsapp = (const struct lsa6_prefix *)tptr;
411 1.1 christos u_int wordlen;
412 1.1 christos struct in6_addr prefix;
413 1.1 christos
414 1.1.1.4 christos if (lsa_length < sizeof (*lsapp) - IPV6_ADDR_LEN_BYTES)
415 1.1.1.2 christos goto trunc;
416 1.1.1.4 christos lsa_length -= sizeof (*lsapp) - IPV6_ADDR_LEN_BYTES;
417 1.1.1.4 christos ND_TCHECK2(*lsapp, sizeof (*lsapp) - IPV6_ADDR_LEN_BYTES);
418 1.1 christos wordlen = (lsapp->lsa_p_len + 31) / 32;
419 1.1 christos if (wordlen * 4 > sizeof(struct in6_addr)) {
420 1.1.1.4 christos ND_PRINT((ndo, " bogus prefixlen /%d", lsapp->lsa_p_len));
421 1.1 christos goto trunc;
422 1.1 christos }
423 1.1.1.2 christos if (lsa_length < wordlen * 4)
424 1.1.1.2 christos goto trunc;
425 1.1.1.2 christos lsa_length -= wordlen * 4;
426 1.1.1.4 christos ND_TCHECK2(lsapp->lsa_p_prefix, wordlen * 4);
427 1.1 christos memset(&prefix, 0, sizeof(prefix));
428 1.1 christos memcpy(&prefix, lsapp->lsa_p_prefix, wordlen * 4);
429 1.1.1.4 christos ND_PRINT((ndo, "\n\t\t%s/%d", ip6addr_string(ndo, &prefix),
430 1.1.1.4 christos lsapp->lsa_p_len));
431 1.1 christos if (lsapp->lsa_p_opt) {
432 1.1.1.4 christos ND_PRINT((ndo, ", Options [%s]",
433 1.1 christos bittok2str(ospf6_lsa_prefix_option_values,
434 1.1.1.4 christos "none", lsapp->lsa_p_opt)));
435 1.1 christos }
436 1.1.1.4 christos ND_PRINT((ndo, ", metric %u", EXTRACT_16BITS(&lsapp->lsa_p_metric)));
437 1.1.1.4 christos return sizeof(*lsapp) - IPV6_ADDR_LEN_BYTES + wordlen * 4;
438 1.1 christos
439 1.1 christos trunc:
440 1.1 christos return -1;
441 1.1 christos }
442 1.1 christos
443 1.1 christos
444 1.1 christos /*
445 1.1 christos * Print a single link state advertisement. If truncated return 1, else 0.
446 1.1 christos */
447 1.1 christos static int
448 1.1.1.4 christos ospf6_print_lsa(netdissect_options *ndo,
449 1.1.1.4 christos register const struct lsa6 *lsap, const u_char *dataend)
450 1.1 christos {
451 1.1 christos register const struct rlalink6 *rlp;
452 1.1 christos #if 0
453 1.1 christos register const struct tos_metric *tosp;
454 1.1 christos #endif
455 1.1 christos register const rtrid_t *ap;
456 1.1 christos #if 0
457 1.1 christos register const struct aslametric *almp;
458 1.1 christos register const struct mcla *mcp;
459 1.1 christos #endif
460 1.1 christos register const struct llsa *llsap;
461 1.1 christos register const struct lsa6_prefix *lsapp;
462 1.1 christos #if 0
463 1.1.1.4 christos register const uint32_t *lp;
464 1.1 christos #endif
465 1.1 christos register u_int prefixes;
466 1.1.1.2 christos register int bytelen;
467 1.1.1.2 christos register u_int length, lsa_length;
468 1.1.1.4 christos uint32_t flags32;
469 1.1.1.4 christos const uint8_t *tptr;
470 1.1 christos
471 1.1.1.4 christos if (ospf6_print_lshdr(ndo, &lsap->ls_hdr, dataend))
472 1.1 christos return (1);
473 1.1.1.4 christos ND_TCHECK(lsap->ls_hdr.ls_length);
474 1.1 christos length = EXTRACT_16BITS(&lsap->ls_hdr.ls_length);
475 1.1.1.2 christos
476 1.1.1.2 christos /*
477 1.1.1.2 christos * The LSA length includes the length of the header;
478 1.1.1.2 christos * it must have a value that's at least that length.
479 1.1.1.2 christos * If it does, find the length of what follows the
480 1.1.1.2 christos * header.
481 1.1.1.2 christos */
482 1.1.1.5 christos if (length < sizeof(struct lsa6_hdr) || (const u_char *)lsap + length > dataend)
483 1.1.1.2 christos return (1);
484 1.1 christos lsa_length = length - sizeof(struct lsa6_hdr);
485 1.1.1.5 christos tptr = (const uint8_t *)lsap+sizeof(struct lsa6_hdr);
486 1.1 christos
487 1.1 christos switch (EXTRACT_16BITS(&lsap->ls_hdr.ls_type)) {
488 1.1 christos case LS_TYPE_ROUTER | LS_SCOPE_AREA:
489 1.1.1.2 christos if (lsa_length < sizeof (lsap->lsa_un.un_rla.rla_options))
490 1.1.1.2 christos return (1);
491 1.1.1.2 christos lsa_length -= sizeof (lsap->lsa_un.un_rla.rla_options);
492 1.1.1.4 christos ND_TCHECK(lsap->lsa_un.un_rla.rla_options);
493 1.1.1.4 christos ND_PRINT((ndo, "\n\t Options [%s]",
494 1.1.1.4 christos bittok2str(ospf6_option_values, "none",
495 1.1.1.4 christos EXTRACT_32BITS(&lsap->lsa_un.un_rla.rla_options))));
496 1.1.1.4 christos ND_PRINT((ndo, ", RLA-Flags [%s]",
497 1.1.1.4 christos bittok2str(ospf6_rla_flag_values, "none",
498 1.1.1.4 christos lsap->lsa_un.un_rla.rla_flags)));
499 1.1 christos
500 1.1 christos rlp = lsap->lsa_un.un_rla.rla_link;
501 1.1.1.2 christos while (lsa_length != 0) {
502 1.1.1.2 christos if (lsa_length < sizeof (*rlp))
503 1.1.1.2 christos return (1);
504 1.1.1.2 christos lsa_length -= sizeof (*rlp);
505 1.1.1.4 christos ND_TCHECK(*rlp);
506 1.1 christos switch (rlp->link_type) {
507 1.1 christos
508 1.1 christos case RLA_TYPE_VIRTUAL:
509 1.1.1.4 christos ND_PRINT((ndo, "\n\t Virtual Link: Neighbor Router-ID %s"
510 1.1 christos "\n\t Neighbor Interface-ID %s, Interface %s",
511 1.1.1.4 christos ipaddr_string(ndo, &rlp->link_nrtid),
512 1.1.1.4 christos ipaddr_string(ndo, &rlp->link_nifid),
513 1.1.1.4 christos ipaddr_string(ndo, &rlp->link_ifid)));
514 1.1 christos break;
515 1.1 christos
516 1.1 christos case RLA_TYPE_ROUTER:
517 1.1.1.4 christos ND_PRINT((ndo, "\n\t Neighbor Router-ID %s"
518 1.1 christos "\n\t Neighbor Interface-ID %s, Interface %s",
519 1.1.1.4 christos ipaddr_string(ndo, &rlp->link_nrtid),
520 1.1.1.4 christos ipaddr_string(ndo, &rlp->link_nifid),
521 1.1.1.4 christos ipaddr_string(ndo, &rlp->link_ifid)));
522 1.1 christos break;
523 1.1 christos
524 1.1 christos case RLA_TYPE_TRANSIT:
525 1.1.1.4 christos ND_PRINT((ndo, "\n\t Neighbor Network-ID %s"
526 1.1 christos "\n\t Neighbor Interface-ID %s, Interface %s",
527 1.1.1.4 christos ipaddr_string(ndo, &rlp->link_nrtid),
528 1.1.1.4 christos ipaddr_string(ndo, &rlp->link_nifid),
529 1.1.1.4 christos ipaddr_string(ndo, &rlp->link_ifid)));
530 1.1 christos break;
531 1.1 christos
532 1.1 christos default:
533 1.1.1.4 christos ND_PRINT((ndo, "\n\t Unknown Router Links Type 0x%02x",
534 1.1.1.4 christos rlp->link_type));
535 1.1 christos return (0);
536 1.1 christos }
537 1.1.1.4 christos ND_PRINT((ndo, ", metric %d", EXTRACT_16BITS(&rlp->link_metric)));
538 1.1 christos rlp++;
539 1.1 christos }
540 1.1 christos break;
541 1.1 christos
542 1.1 christos case LS_TYPE_NETWORK | LS_SCOPE_AREA:
543 1.1.1.2 christos if (lsa_length < sizeof (lsap->lsa_un.un_nla.nla_options))
544 1.1.1.2 christos return (1);
545 1.1.1.2 christos lsa_length -= sizeof (lsap->lsa_un.un_nla.nla_options);
546 1.1.1.4 christos ND_TCHECK(lsap->lsa_un.un_nla.nla_options);
547 1.1.1.4 christos ND_PRINT((ndo, "\n\t Options [%s]",
548 1.1.1.4 christos bittok2str(ospf6_option_values, "none",
549 1.1.1.4 christos EXTRACT_32BITS(&lsap->lsa_un.un_nla.nla_options))));
550 1.1.1.2 christos
551 1.1.1.4 christos ND_PRINT((ndo, "\n\t Connected Routers:"));
552 1.1 christos ap = lsap->lsa_un.un_nla.nla_router;
553 1.1.1.2 christos while (lsa_length != 0) {
554 1.1.1.2 christos if (lsa_length < sizeof (*ap))
555 1.1.1.2 christos return (1);
556 1.1.1.2 christos lsa_length -= sizeof (*ap);
557 1.1.1.4 christos ND_TCHECK(*ap);
558 1.1.1.4 christos ND_PRINT((ndo, "\n\t\t%s", ipaddr_string(ndo, ap)));
559 1.1 christos ++ap;
560 1.1 christos }
561 1.1 christos break;
562 1.1 christos
563 1.1 christos case LS_TYPE_INTER_AP | LS_SCOPE_AREA:
564 1.1.1.2 christos if (lsa_length < sizeof (lsap->lsa_un.un_inter_ap.inter_ap_metric))
565 1.1.1.2 christos return (1);
566 1.1.1.2 christos lsa_length -= sizeof (lsap->lsa_un.un_inter_ap.inter_ap_metric);
567 1.1.1.4 christos ND_TCHECK(lsap->lsa_un.un_inter_ap.inter_ap_metric);
568 1.1.1.4 christos ND_PRINT((ndo, ", metric %u",
569 1.1.1.4 christos EXTRACT_32BITS(&lsap->lsa_un.un_inter_ap.inter_ap_metric) & SLA_MASK_METRIC));
570 1.1.1.2 christos
571 1.1.1.5 christos tptr = (const uint8_t *)lsap->lsa_un.un_inter_ap.inter_ap_prefix;
572 1.1.1.2 christos while (lsa_length != 0) {
573 1.1.1.4 christos bytelen = ospf6_print_lsaprefix(ndo, tptr, lsa_length);
574 1.1.1.2 christos if (bytelen < 0)
575 1.1 christos goto trunc;
576 1.1.1.2 christos lsa_length -= bytelen;
577 1.1.1.2 christos tptr += bytelen;
578 1.1 christos }
579 1.1 christos break;
580 1.1.1.2 christos
581 1.1.1.2 christos case LS_TYPE_ASE | LS_SCOPE_AS:
582 1.1.1.2 christos if (lsa_length < sizeof (lsap->lsa_un.un_asla.asla_metric))
583 1.1.1.2 christos return (1);
584 1.1.1.2 christos lsa_length -= sizeof (lsap->lsa_un.un_asla.asla_metric);
585 1.1.1.4 christos ND_TCHECK(lsap->lsa_un.un_asla.asla_metric);
586 1.1 christos flags32 = EXTRACT_32BITS(&lsap->lsa_un.un_asla.asla_metric);
587 1.1.1.4 christos ND_PRINT((ndo, "\n\t Flags [%s]",
588 1.1.1.4 christos bittok2str(ospf6_asla_flag_values, "none", flags32)));
589 1.1.1.4 christos ND_PRINT((ndo, " metric %u",
590 1.1 christos EXTRACT_32BITS(&lsap->lsa_un.un_asla.asla_metric) &
591 1.1.1.4 christos ASLA_MASK_METRIC));
592 1.1.1.2 christos
593 1.1.1.5 christos tptr = (const uint8_t *)lsap->lsa_un.un_asla.asla_prefix;
594 1.1.1.5 christos lsapp = (const struct lsa6_prefix *)tptr;
595 1.1.1.4 christos bytelen = ospf6_print_lsaprefix(ndo, tptr, lsa_length);
596 1.1 christos if (bytelen < 0)
597 1.1 christos goto trunc;
598 1.1.1.2 christos lsa_length -= bytelen;
599 1.1.1.2 christos tptr += bytelen;
600 1.1 christos
601 1.1.1.2 christos if ((flags32 & ASLA_FLAG_FWDADDR) != 0) {
602 1.1.1.5 christos const struct in6_addr *fwdaddr6;
603 1.1 christos
604 1.1.1.5 christos fwdaddr6 = (const struct in6_addr *)tptr;
605 1.1.1.2 christos if (lsa_length < sizeof (*fwdaddr6))
606 1.1.1.2 christos return (1);
607 1.1.1.2 christos lsa_length -= sizeof (*fwdaddr6);
608 1.1.1.4 christos ND_TCHECK(*fwdaddr6);
609 1.1.1.4 christos ND_PRINT((ndo, " forward %s",
610 1.1.1.4 christos ip6addr_string(ndo, fwdaddr6)));
611 1.1.1.2 christos tptr += sizeof(*fwdaddr6);
612 1.1.1.2 christos }
613 1.1 christos
614 1.1.1.2 christos if ((flags32 & ASLA_FLAG_ROUTETAG) != 0) {
615 1.1.1.4 christos if (lsa_length < sizeof (uint32_t))
616 1.1.1.2 christos return (1);
617 1.1.1.4 christos lsa_length -= sizeof (uint32_t);
618 1.1.1.5 christos ND_TCHECK(*(const uint32_t *)tptr);
619 1.1.1.4 christos ND_PRINT((ndo, " tag %s",
620 1.1.1.5 christos ipaddr_string(ndo, (const uint32_t *)tptr)));
621 1.1.1.4 christos tptr += sizeof(uint32_t);
622 1.1.1.2 christos }
623 1.1 christos
624 1.1.1.2 christos if (lsapp->lsa_p_metric) {
625 1.1.1.4 christos if (lsa_length < sizeof (uint32_t))
626 1.1.1.2 christos return (1);
627 1.1.1.4 christos lsa_length -= sizeof (uint32_t);
628 1.1.1.5 christos ND_TCHECK(*(const uint32_t *)tptr);
629 1.1.1.4 christos ND_PRINT((ndo, " RefLSID: %s",
630 1.1.1.5 christos ipaddr_string(ndo, (const uint32_t *)tptr)));
631 1.1.1.4 christos tptr += sizeof(uint32_t);
632 1.1 christos }
633 1.1 christos break;
634 1.1 christos
635 1.1 christos case LS_TYPE_LINK:
636 1.1 christos /* Link LSA */
637 1.1 christos llsap = &lsap->lsa_un.un_llsa;
638 1.1.1.2 christos if (lsa_length < sizeof (llsap->llsa_priandopt))
639 1.1.1.2 christos return (1);
640 1.1.1.2 christos lsa_length -= sizeof (llsap->llsa_priandopt);
641 1.1.1.4 christos ND_TCHECK(llsap->llsa_priandopt);
642 1.1.1.4 christos ND_PRINT((ndo, "\n\t Options [%s]",
643 1.1.1.4 christos bittok2str(ospf6_option_values, "none",
644 1.1.1.4 christos EXTRACT_32BITS(&llsap->llsa_options))));
645 1.1.1.2 christos
646 1.1.1.2 christos if (lsa_length < sizeof (llsap->llsa_lladdr) + sizeof (llsap->llsa_nprefix))
647 1.1.1.2 christos return (1);
648 1.1.1.2 christos lsa_length -= sizeof (llsap->llsa_lladdr) + sizeof (llsap->llsa_nprefix);
649 1.1 christos prefixes = EXTRACT_32BITS(&llsap->llsa_nprefix);
650 1.1.1.4 christos ND_PRINT((ndo, "\n\t Priority %d, Link-local address %s, Prefixes %d:",
651 1.1 christos llsap->llsa_priority,
652 1.1.1.4 christos ip6addr_string(ndo, &llsap->llsa_lladdr),
653 1.1.1.4 christos prefixes));
654 1.1 christos
655 1.1.1.5 christos tptr = (const uint8_t *)llsap->llsa_prefix;
656 1.1.1.2 christos while (prefixes > 0) {
657 1.1.1.4 christos bytelen = ospf6_print_lsaprefix(ndo, tptr, lsa_length);
658 1.1.1.2 christos if (bytelen < 0)
659 1.1.1.2 christos goto trunc;
660 1.1.1.2 christos prefixes--;
661 1.1.1.2 christos lsa_length -= bytelen;
662 1.1.1.2 christos tptr += bytelen;
663 1.1.1.2 christos }
664 1.1 christos break;
665 1.1 christos
666 1.1 christos case LS_TYPE_INTRA_AP | LS_SCOPE_AREA:
667 1.1 christos /* Intra-Area-Prefix LSA */
668 1.1.1.2 christos if (lsa_length < sizeof (lsap->lsa_un.un_intra_ap.intra_ap_rtid))
669 1.1.1.2 christos return (1);
670 1.1.1.2 christos lsa_length -= sizeof (lsap->lsa_un.un_intra_ap.intra_ap_rtid);
671 1.1.1.4 christos ND_TCHECK(lsap->lsa_un.un_intra_ap.intra_ap_rtid);
672 1.1.1.4 christos ospf6_print_ls_type(ndo,
673 1.1 christos EXTRACT_16BITS(&lsap->lsa_un.un_intra_ap.intra_ap_lstype),
674 1.1 christos &lsap->lsa_un.un_intra_ap.intra_ap_lsid);
675 1.1.1.2 christos
676 1.1.1.2 christos if (lsa_length < sizeof (lsap->lsa_un.un_intra_ap.intra_ap_nprefix))
677 1.1.1.2 christos return (1);
678 1.1.1.2 christos lsa_length -= sizeof (lsap->lsa_un.un_intra_ap.intra_ap_nprefix);
679 1.1.1.4 christos ND_TCHECK(lsap->lsa_un.un_intra_ap.intra_ap_nprefix);
680 1.1 christos prefixes = EXTRACT_16BITS(&lsap->lsa_un.un_intra_ap.intra_ap_nprefix);
681 1.1.1.4 christos ND_PRINT((ndo, "\n\t Prefixes %d:", prefixes));
682 1.1 christos
683 1.1.1.5 christos tptr = (const uint8_t *)lsap->lsa_un.un_intra_ap.intra_ap_prefix;
684 1.1.1.2 christos while (prefixes > 0) {
685 1.1.1.4 christos bytelen = ospf6_print_lsaprefix(ndo, tptr, lsa_length);
686 1.1.1.2 christos if (bytelen < 0)
687 1.1.1.2 christos goto trunc;
688 1.1.1.2 christos prefixes--;
689 1.1.1.2 christos lsa_length -= bytelen;
690 1.1.1.2 christos tptr += bytelen;
691 1.1.1.2 christos }
692 1.1 christos break;
693 1.1 christos
694 1.1 christos case LS_TYPE_GRACE | LS_SCOPE_LINKLOCAL:
695 1.1.1.4 christos if (ospf_print_grace_lsa(ndo, tptr, lsa_length) == -1) {
696 1.1 christos return 1;
697 1.1 christos }
698 1.1.1.2 christos break;
699 1.1 christos
700 1.1 christos case LS_TYPE_INTRA_ATE | LS_SCOPE_LINKLOCAL:
701 1.1.1.4 christos if (ospf_print_te_lsa(ndo, tptr, lsa_length) == -1) {
702 1.1.1.2 christos return 1;
703 1.1.1.2 christos }
704 1.1.1.2 christos break;
705 1.1 christos
706 1.1 christos default:
707 1.1.1.4 christos if(!print_unknown_data(ndo,tptr,
708 1.1.1.2 christos "\n\t ",
709 1.1.1.2 christos lsa_length)) {
710 1.1.1.2 christos return (1);
711 1.1.1.2 christos }
712 1.1.1.2 christos break;
713 1.1 christos }
714 1.1 christos
715 1.1 christos return (0);
716 1.1 christos trunc:
717 1.1 christos return (1);
718 1.1 christos }
719 1.1 christos
720 1.1 christos static int
721 1.1.1.4 christos ospf6_decode_v3(netdissect_options *ndo,
722 1.1.1.4 christos register const struct ospf6hdr *op,
723 1.1.1.4 christos register const u_char *dataend)
724 1.1 christos {
725 1.1 christos register const rtrid_t *ap;
726 1.1 christos register const struct lsr6 *lsrp;
727 1.1 christos register const struct lsa6_hdr *lshp;
728 1.1 christos register const struct lsa6 *lsap;
729 1.1 christos register int i;
730 1.1 christos
731 1.1 christos switch (op->ospf6_type) {
732 1.1 christos
733 1.1.1.4 christos case OSPF_TYPE_HELLO: {
734 1.1.1.5 christos register const struct hello6 *hellop = (const struct hello6 *)((const uint8_t *)op + OSPF6HDR_LEN);
735 1.1.1.4 christos
736 1.1.1.4 christos ND_PRINT((ndo, "\n\tOptions [%s]",
737 1.1.1.4 christos bittok2str(ospf6_option_values, "none",
738 1.1.1.4 christos EXTRACT_32BITS(&hellop->hello_options))));
739 1.1.1.4 christos
740 1.1.1.4 christos ND_TCHECK(hellop->hello_deadint);
741 1.1.1.4 christos ND_PRINT((ndo, "\n\t Hello Timer %us, Dead Timer %us, Interface-ID %s, Priority %u",
742 1.1.1.4 christos EXTRACT_16BITS(&hellop->hello_helloint),
743 1.1.1.4 christos EXTRACT_16BITS(&hellop->hello_deadint),
744 1.1.1.4 christos ipaddr_string(ndo, &hellop->hello_ifid),
745 1.1.1.4 christos hellop->hello_priority));
746 1.1.1.4 christos
747 1.1.1.4 christos ND_TCHECK(hellop->hello_dr);
748 1.1.1.4 christos if (EXTRACT_32BITS(&hellop->hello_dr) != 0)
749 1.1.1.4 christos ND_PRINT((ndo, "\n\t Designated Router %s",
750 1.1.1.4 christos ipaddr_string(ndo, &hellop->hello_dr)));
751 1.1.1.4 christos ND_TCHECK(hellop->hello_bdr);
752 1.1.1.4 christos if (EXTRACT_32BITS(&hellop->hello_bdr) != 0)
753 1.1.1.4 christos ND_PRINT((ndo, ", Backup Designated Router %s",
754 1.1.1.4 christos ipaddr_string(ndo, &hellop->hello_bdr)));
755 1.1.1.4 christos if (ndo->ndo_vflag > 1) {
756 1.1.1.4 christos ND_PRINT((ndo, "\n\t Neighbor List:"));
757 1.1.1.4 christos ap = hellop->hello_neighbor;
758 1.1.1.5 christos while ((const u_char *)ap < dataend) {
759 1.1.1.4 christos ND_TCHECK(*ap);
760 1.1.1.4 christos ND_PRINT((ndo, "\n\t %s", ipaddr_string(ndo, ap)));
761 1.1 christos ++ap;
762 1.1 christos }
763 1.1 christos }
764 1.1 christos break; /* HELLO */
765 1.1.1.4 christos }
766 1.1 christos
767 1.1.1.4 christos case OSPF_TYPE_DD: {
768 1.1.1.5 christos register const struct dd6 *ddp = (const struct dd6 *)((const uint8_t *)op + OSPF6HDR_LEN);
769 1.1.1.4 christos
770 1.1.1.4 christos ND_TCHECK(ddp->db_options);
771 1.1.1.4 christos ND_PRINT((ndo, "\n\tOptions [%s]",
772 1.1.1.4 christos bittok2str(ospf6_option_values, "none",
773 1.1.1.4 christos EXTRACT_32BITS(&ddp->db_options))));
774 1.1.1.4 christos ND_TCHECK(ddp->db_flags);
775 1.1.1.4 christos ND_PRINT((ndo, ", DD Flags [%s]",
776 1.1.1.4 christos bittok2str(ospf6_dd_flag_values,"none",ddp->db_flags)));
777 1.1.1.4 christos
778 1.1.1.4 christos ND_TCHECK(ddp->db_seq);
779 1.1.1.4 christos ND_PRINT((ndo, ", MTU %u, DD-Sequence 0x%08x",
780 1.1.1.4 christos EXTRACT_16BITS(&ddp->db_mtu),
781 1.1.1.4 christos EXTRACT_32BITS(&ddp->db_seq)));
782 1.1.1.4 christos if (ndo->ndo_vflag > 1) {
783 1.1.1.4 christos /* Print all the LS adv's */
784 1.1.1.4 christos lshp = ddp->db_lshdr;
785 1.1.1.5 christos while ((const u_char *)lshp < dataend) {
786 1.1.1.4 christos if (ospf6_print_lshdr(ndo, lshp++, dataend))
787 1.1.1.4 christos goto trunc;
788 1.1.1.4 christos }
789 1.1.1.4 christos }
790 1.1 christos break;
791 1.1.1.4 christos }
792 1.1 christos
793 1.1 christos case OSPF_TYPE_LS_REQ:
794 1.1.1.4 christos if (ndo->ndo_vflag > 1) {
795 1.1.1.5 christos lsrp = (const struct lsr6 *)((const uint8_t *)op + OSPF6HDR_LEN);
796 1.1.1.5 christos while ((const u_char *)lsrp < dataend) {
797 1.1.1.4 christos ND_TCHECK(*lsrp);
798 1.1.1.4 christos ND_PRINT((ndo, "\n\t Advertising Router %s",
799 1.1.1.4 christos ipaddr_string(ndo, &lsrp->ls_router)));
800 1.1.1.4 christos ospf6_print_ls_type(ndo, EXTRACT_16BITS(&lsrp->ls_type),
801 1.1 christos &lsrp->ls_stateid);
802 1.1 christos ++lsrp;
803 1.1 christos }
804 1.1 christos }
805 1.1 christos break;
806 1.1 christos
807 1.1 christos case OSPF_TYPE_LS_UPDATE:
808 1.1.1.4 christos if (ndo->ndo_vflag > 1) {
809 1.1.1.5 christos register const struct lsu6 *lsup = (const struct lsu6 *)((const uint8_t *)op + OSPF6HDR_LEN);
810 1.1.1.4 christos
811 1.1.1.4 christos ND_TCHECK(lsup->lsu_count);
812 1.1.1.4 christos i = EXTRACT_32BITS(&lsup->lsu_count);
813 1.1.1.4 christos lsap = lsup->lsu_lsa;
814 1.1.1.5 christos while ((const u_char *)lsap < dataend && i--) {
815 1.1.1.4 christos if (ospf6_print_lsa(ndo, lsap, dataend))
816 1.1 christos goto trunc;
817 1.1.1.5 christos lsap = (const struct lsa6 *)((const u_char *)lsap +
818 1.1 christos EXTRACT_16BITS(&lsap->ls_hdr.ls_length));
819 1.1 christos }
820 1.1 christos }
821 1.1 christos break;
822 1.1 christos
823 1.1 christos case OSPF_TYPE_LS_ACK:
824 1.1.1.4 christos if (ndo->ndo_vflag > 1) {
825 1.1.1.5 christos lshp = (const struct lsa6_hdr *)((const uint8_t *)op + OSPF6HDR_LEN);
826 1.1.1.5 christos while ((const u_char *)lshp < dataend) {
827 1.1.1.4 christos if (ospf6_print_lshdr(ndo, lshp++, dataend))
828 1.1.1.4 christos goto trunc;
829 1.1 christos }
830 1.1 christos }
831 1.1 christos break;
832 1.1 christos
833 1.1 christos default:
834 1.1 christos break;
835 1.1 christos }
836 1.1 christos return (0);
837 1.1 christos trunc:
838 1.1 christos return (1);
839 1.1 christos }
840 1.1 christos
841 1.1.1.4 christos /* RFC5613 Section 2.2 (w/o the TLVs) */
842 1.1.1.4 christos static int
843 1.1.1.4 christos ospf6_print_lls(netdissect_options *ndo,
844 1.1.1.4 christos const u_char *cp, const u_int len)
845 1.1.1.4 christos {
846 1.1.1.4 christos uint16_t llsdatalen;
847 1.1.1.4 christos
848 1.1.1.4 christos if (len == 0)
849 1.1.1.4 christos return 0;
850 1.1.1.4 christos if (len < OSPF_LLS_HDRLEN)
851 1.1.1.4 christos goto trunc;
852 1.1.1.4 christos /* Checksum */
853 1.1.1.4 christos ND_TCHECK2(*cp, 2);
854 1.1.1.4 christos ND_PRINT((ndo, "\n\tLLS Checksum 0x%04x", EXTRACT_16BITS(cp)));
855 1.1.1.4 christos cp += 2;
856 1.1.1.4 christos /* LLS Data Length */
857 1.1.1.4 christos ND_TCHECK2(*cp, 2);
858 1.1.1.4 christos llsdatalen = EXTRACT_16BITS(cp);
859 1.1.1.4 christos ND_PRINT((ndo, ", Data Length %u", llsdatalen));
860 1.1.1.4 christos if (llsdatalen < OSPF_LLS_HDRLEN || llsdatalen > len)
861 1.1.1.4 christos goto trunc;
862 1.1.1.4 christos cp += 2;
863 1.1.1.4 christos /* LLS TLVs */
864 1.1.1.4 christos ND_TCHECK2(*cp, llsdatalen - OSPF_LLS_HDRLEN);
865 1.1.1.4 christos /* FIXME: code in print-ospf.c can be reused to decode the TLVs */
866 1.1.1.4 christos
867 1.1.1.4 christos return llsdatalen;
868 1.1.1.4 christos trunc:
869 1.1.1.4 christos return -1;
870 1.1.1.4 christos }
871 1.1.1.4 christos
872 1.1.1.4 christos /* RFC6506 Section 4.1 */
873 1.1.1.4 christos static int
874 1.1.1.4 christos ospf6_decode_at(netdissect_options *ndo,
875 1.1.1.4 christos const u_char *cp, const u_int len)
876 1.1.1.4 christos {
877 1.1.1.4 christos uint16_t authdatalen;
878 1.1.1.4 christos
879 1.1.1.4 christos if (len == 0)
880 1.1.1.4 christos return 0;
881 1.1.1.4 christos if (len < OSPF6_AT_HDRLEN)
882 1.1.1.4 christos goto trunc;
883 1.1.1.4 christos /* Authentication Type */
884 1.1.1.4 christos ND_TCHECK2(*cp, 2);
885 1.1.1.4 christos ND_PRINT((ndo, "\n\tAuthentication Type %s", tok2str(ospf6_auth_type_str, "unknown (0x%04x)", EXTRACT_16BITS(cp))));
886 1.1.1.4 christos cp += 2;
887 1.1.1.4 christos /* Auth Data Len */
888 1.1.1.4 christos ND_TCHECK2(*cp, 2);
889 1.1.1.4 christos authdatalen = EXTRACT_16BITS(cp);
890 1.1.1.4 christos ND_PRINT((ndo, ", Length %u", authdatalen));
891 1.1.1.4 christos if (authdatalen < OSPF6_AT_HDRLEN || authdatalen > len)
892 1.1.1.4 christos goto trunc;
893 1.1.1.4 christos cp += 2;
894 1.1.1.4 christos /* Reserved */
895 1.1.1.4 christos ND_TCHECK2(*cp, 2);
896 1.1.1.4 christos cp += 2;
897 1.1.1.4 christos /* Security Association ID */
898 1.1.1.4 christos ND_TCHECK2(*cp, 2);
899 1.1.1.4 christos ND_PRINT((ndo, ", SAID %u", EXTRACT_16BITS(cp)));
900 1.1.1.4 christos cp += 2;
901 1.1.1.4 christos /* Cryptographic Sequence Number (High-Order 32 Bits) */
902 1.1.1.4 christos ND_TCHECK2(*cp, 4);
903 1.1.1.4 christos ND_PRINT((ndo, ", CSN 0x%08x", EXTRACT_32BITS(cp)));
904 1.1.1.4 christos cp += 4;
905 1.1.1.4 christos /* Cryptographic Sequence Number (Low-Order 32 Bits) */
906 1.1.1.4 christos ND_TCHECK2(*cp, 4);
907 1.1.1.4 christos ND_PRINT((ndo, ":%08x", EXTRACT_32BITS(cp)));
908 1.1.1.4 christos cp += 4;
909 1.1.1.4 christos /* Authentication Data */
910 1.1.1.4 christos ND_TCHECK2(*cp, authdatalen - OSPF6_AT_HDRLEN);
911 1.1.1.4 christos if (ndo->ndo_vflag > 1)
912 1.1.1.4 christos print_unknown_data(ndo,cp, "\n\tAuthentication Data ", authdatalen - OSPF6_AT_HDRLEN);
913 1.1.1.4 christos return 0;
914 1.1.1.4 christos
915 1.1.1.4 christos trunc:
916 1.1.1.4 christos return 1;
917 1.1.1.4 christos }
918 1.1.1.4 christos
919 1.1.1.4 christos /* The trailing data may include LLS and/or AT data (in this specific order).
920 1.1.1.4 christos * LLS data may be present only in Hello and DBDesc packets with the L-bit set.
921 1.1.1.4 christos * AT data may be present in Hello and DBDesc packets with the AT-bit set or in
922 1.1.1.4 christos * any other packet type, thus decode the AT data regardless of the AT-bit.
923 1.1.1.4 christos */
924 1.1.1.4 christos static int
925 1.1.1.4 christos ospf6_decode_v3_trailer(netdissect_options *ndo,
926 1.1.1.4 christos const struct ospf6hdr *op, const u_char *cp, const unsigned len)
927 1.1.1.4 christos {
928 1.1.1.4 christos int llslen = 0;
929 1.1.1.4 christos int lls_hello = 0;
930 1.1.1.4 christos int lls_dd = 0;
931 1.1.1.4 christos
932 1.1.1.4 christos if (op->ospf6_type == OSPF_TYPE_HELLO) {
933 1.1.1.5 christos const struct hello6 *hellop = (const struct hello6 *)((const uint8_t *)op + OSPF6HDR_LEN);
934 1.1.1.4 christos if (EXTRACT_32BITS(&hellop->hello_options) & OSPF6_OPTION_L)
935 1.1.1.4 christos lls_hello = 1;
936 1.1.1.4 christos } else if (op->ospf6_type == OSPF_TYPE_DD) {
937 1.1.1.5 christos const struct dd6 *ddp = (const struct dd6 *)((const uint8_t *)op + OSPF6HDR_LEN);
938 1.1.1.4 christos if (EXTRACT_32BITS(&ddp->db_options) & OSPF6_OPTION_L)
939 1.1.1.4 christos lls_dd = 1;
940 1.1.1.4 christos }
941 1.1.1.4 christos if ((lls_hello || lls_dd) && (llslen = ospf6_print_lls(ndo, cp, len)) < 0)
942 1.1.1.4 christos goto trunc;
943 1.1.1.4 christos return ospf6_decode_at(ndo, cp + llslen, len - llslen);
944 1.1.1.4 christos
945 1.1.1.4 christos trunc:
946 1.1.1.4 christos return 1;
947 1.1.1.4 christos }
948 1.1.1.4 christos
949 1.1 christos void
950 1.1.1.4 christos ospf6_print(netdissect_options *ndo,
951 1.1.1.4 christos register const u_char *bp, register u_int length)
952 1.1 christos {
953 1.1 christos register const struct ospf6hdr *op;
954 1.1 christos register const u_char *dataend;
955 1.1 christos register const char *cp;
956 1.1.1.4 christos uint16_t datalen;
957 1.1 christos
958 1.1.1.5 christos op = (const struct ospf6hdr *)bp;
959 1.1 christos
960 1.1 christos /* If the type is valid translate it, or just print the type */
961 1.1 christos /* value. If it's not valid, say so and return */
962 1.1.1.4 christos ND_TCHECK(op->ospf6_type);
963 1.1.1.4 christos cp = tok2str(ospf6_type_values, "unknown packet type (%u)", op->ospf6_type);
964 1.1.1.4 christos ND_PRINT((ndo, "OSPFv%u, %s, length %d", op->ospf6_version, cp, length));
965 1.1 christos if (*cp == 'u') {
966 1.1 christos return;
967 1.1.1.4 christos }
968 1.1 christos
969 1.1.1.4 christos if(!ndo->ndo_vflag) { /* non verbose - so lets bail out here */
970 1.1.1.4 christos return;
971 1.1.1.4 christos }
972 1.1 christos
973 1.1.1.4 christos /* OSPFv3 data always comes first and optional trailing data may follow. */
974 1.1.1.4 christos ND_TCHECK(op->ospf6_len);
975 1.1.1.4 christos datalen = EXTRACT_16BITS(&op->ospf6_len);
976 1.1.1.4 christos if (datalen > length) {
977 1.1.1.4 christos ND_PRINT((ndo, " [len %d]", datalen));
978 1.1 christos return;
979 1.1 christos }
980 1.1.1.4 christos dataend = bp + datalen;
981 1.1.1.4 christos
982 1.1.1.4 christos ND_TCHECK(op->ospf6_routerid);
983 1.1.1.4 christos ND_PRINT((ndo, "\n\tRouter-ID %s", ipaddr_string(ndo, &op->ospf6_routerid)));
984 1.1 christos
985 1.1.1.4 christos ND_TCHECK(op->ospf6_areaid);
986 1.1.1.4 christos if (EXTRACT_32BITS(&op->ospf6_areaid) != 0)
987 1.1.1.4 christos ND_PRINT((ndo, ", Area %s", ipaddr_string(ndo, &op->ospf6_areaid)));
988 1.1 christos else
989 1.1.1.4 christos ND_PRINT((ndo, ", Backbone Area"));
990 1.1.1.4 christos ND_TCHECK(op->ospf6_instanceid);
991 1.1 christos if (op->ospf6_instanceid)
992 1.1.1.4 christos ND_PRINT((ndo, ", Instance %u", op->ospf6_instanceid));
993 1.1 christos
994 1.1 christos /* Do rest according to version. */
995 1.1 christos switch (op->ospf6_version) {
996 1.1 christos
997 1.1 christos case 3:
998 1.1 christos /* ospf version 3 */
999 1.1.1.4 christos if (ospf6_decode_v3(ndo, op, dataend) ||
1000 1.1.1.4 christos ospf6_decode_v3_trailer(ndo, op, dataend, length - datalen))
1001 1.1 christos goto trunc;
1002 1.1 christos break;
1003 1.1 christos } /* end switch on version */
1004 1.1 christos
1005 1.1 christos return;
1006 1.1 christos trunc:
1007 1.1.1.4 christos ND_PRINT((ndo, "%s", tstr));
1008 1.1 christos }
1009