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