1*05b00f60SXin Li /*
2*05b00f60SXin Li * Copyright (c) 1988, 1989, 1990, 1991, 1992, 1993, 1994
3*05b00f60SXin Li * The Regents of the University of California. All rights reserved.
4*05b00f60SXin Li *
5*05b00f60SXin Li * Redistribution and use in source and binary forms, with or without
6*05b00f60SXin Li * modification, are permitted provided that: (1) source code distributions
7*05b00f60SXin Li * retain the above copyright notice and this paragraph in its entirety, (2)
8*05b00f60SXin Li * distributions including binary code include the above copyright notice and
9*05b00f60SXin Li * this paragraph in its entirety in the documentation or other materials
10*05b00f60SXin Li * provided with the distribution, and (3) all advertising materials mentioning
11*05b00f60SXin Li * features or use of this software display the following acknowledgement:
12*05b00f60SXin Li * ``This product includes software developed by the University of California,
13*05b00f60SXin Li * Lawrence Berkeley Laboratory and its contributors.'' Neither the name of
14*05b00f60SXin Li * the University nor the names of its contributors may be used to endorse
15*05b00f60SXin Li * or promote products derived from this software without specific prior
16*05b00f60SXin Li * written permission.
17*05b00f60SXin Li * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
18*05b00f60SXin Li * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
19*05b00f60SXin Li * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
20*05b00f60SXin Li */
21*05b00f60SXin Li
22*05b00f60SXin Li /* \summary: IPv6 printer */
23*05b00f60SXin Li
24*05b00f60SXin Li #ifdef HAVE_CONFIG_H
25*05b00f60SXin Li #include <config.h>
26*05b00f60SXin Li #endif
27*05b00f60SXin Li
28*05b00f60SXin Li #include "netdissect-stdinc.h"
29*05b00f60SXin Li
30*05b00f60SXin Li #include <string.h>
31*05b00f60SXin Li
32*05b00f60SXin Li #include "netdissect.h"
33*05b00f60SXin Li #include "addrtoname.h"
34*05b00f60SXin Li #include "extract.h"
35*05b00f60SXin Li
36*05b00f60SXin Li #include "ip6.h"
37*05b00f60SXin Li #include "ipproto.h"
38*05b00f60SXin Li
39*05b00f60SXin Li /*
40*05b00f60SXin Li * If routing headers are presend and valid, set dst to the final destination.
41*05b00f60SXin Li * Otherwise, set it to the IPv6 destination.
42*05b00f60SXin Li *
43*05b00f60SXin Li * This is used for UDP and TCP pseudo-header in the checksum
44*05b00f60SXin Li * calculation.
45*05b00f60SXin Li */
46*05b00f60SXin Li static void
ip6_finddst(netdissect_options * ndo,nd_ipv6 * dst,const struct ip6_hdr * ip6)47*05b00f60SXin Li ip6_finddst(netdissect_options *ndo, nd_ipv6 *dst,
48*05b00f60SXin Li const struct ip6_hdr *ip6)
49*05b00f60SXin Li {
50*05b00f60SXin Li const u_char *cp;
51*05b00f60SXin Li u_int advance;
52*05b00f60SXin Li u_int nh;
53*05b00f60SXin Li const void *dst_addr;
54*05b00f60SXin Li const struct ip6_rthdr *dp;
55*05b00f60SXin Li const struct ip6_rthdr0 *dp0;
56*05b00f60SXin Li const struct ip6_srh *srh;
57*05b00f60SXin Li const u_char *p;
58*05b00f60SXin Li int i, len;
59*05b00f60SXin Li
60*05b00f60SXin Li cp = (const u_char *)ip6;
61*05b00f60SXin Li advance = sizeof(struct ip6_hdr);
62*05b00f60SXin Li nh = GET_U_1(ip6->ip6_nxt);
63*05b00f60SXin Li dst_addr = (const void *)ip6->ip6_dst;
64*05b00f60SXin Li
65*05b00f60SXin Li while (cp < ndo->ndo_snapend) {
66*05b00f60SXin Li cp += advance;
67*05b00f60SXin Li
68*05b00f60SXin Li switch (nh) {
69*05b00f60SXin Li
70*05b00f60SXin Li case IPPROTO_HOPOPTS:
71*05b00f60SXin Li case IPPROTO_DSTOPTS:
72*05b00f60SXin Li case IPPROTO_MOBILITY_OLD:
73*05b00f60SXin Li case IPPROTO_MOBILITY:
74*05b00f60SXin Li /*
75*05b00f60SXin Li * These have a header length byte, following
76*05b00f60SXin Li * the next header byte, giving the length of
77*05b00f60SXin Li * the header, in units of 8 octets, excluding
78*05b00f60SXin Li * the first 8 octets.
79*05b00f60SXin Li */
80*05b00f60SXin Li advance = (GET_U_1(cp + 1) + 1) << 3;
81*05b00f60SXin Li nh = GET_U_1(cp);
82*05b00f60SXin Li break;
83*05b00f60SXin Li
84*05b00f60SXin Li case IPPROTO_FRAGMENT:
85*05b00f60SXin Li /*
86*05b00f60SXin Li * The byte following the next header byte is
87*05b00f60SXin Li * marked as reserved, and the header is always
88*05b00f60SXin Li * the same size.
89*05b00f60SXin Li */
90*05b00f60SXin Li advance = sizeof(struct ip6_frag);
91*05b00f60SXin Li nh = GET_U_1(cp);
92*05b00f60SXin Li break;
93*05b00f60SXin Li
94*05b00f60SXin Li case IPPROTO_ROUTING:
95*05b00f60SXin Li /*
96*05b00f60SXin Li * OK, we found it.
97*05b00f60SXin Li */
98*05b00f60SXin Li dp = (const struct ip6_rthdr *)cp;
99*05b00f60SXin Li ND_TCHECK_SIZE(dp);
100*05b00f60SXin Li len = GET_U_1(dp->ip6r_len);
101*05b00f60SXin Li switch (GET_U_1(dp->ip6r_type)) {
102*05b00f60SXin Li
103*05b00f60SXin Li case IPV6_RTHDR_TYPE_0:
104*05b00f60SXin Li case IPV6_RTHDR_TYPE_2: /* Mobile IPv6 ID-20 */
105*05b00f60SXin Li dp0 = (const struct ip6_rthdr0 *)dp;
106*05b00f60SXin Li if (len % 2 == 1)
107*05b00f60SXin Li goto trunc;
108*05b00f60SXin Li len >>= 1;
109*05b00f60SXin Li p = (const u_char *) dp0->ip6r0_addr;
110*05b00f60SXin Li for (i = 0; i < len; i++) {
111*05b00f60SXin Li ND_TCHECK_16(p);
112*05b00f60SXin Li dst_addr = (const void *)p;
113*05b00f60SXin Li p += 16;
114*05b00f60SXin Li }
115*05b00f60SXin Li break;
116*05b00f60SXin Li case IPV6_RTHDR_TYPE_4:
117*05b00f60SXin Li /* IPv6 Segment Routing Header (SRH) */
118*05b00f60SXin Li srh = (const struct ip6_srh *)dp;
119*05b00f60SXin Li if (len % 2 == 1)
120*05b00f60SXin Li goto trunc;
121*05b00f60SXin Li p = (const u_char *) srh->srh_segments;
122*05b00f60SXin Li /*
123*05b00f60SXin Li * The list of segments are encoded in the reverse order.
124*05b00f60SXin Li * Accordingly, the final DA is encoded in srh_segments[0]
125*05b00f60SXin Li */
126*05b00f60SXin Li ND_TCHECK_16(p);
127*05b00f60SXin Li dst_addr = (const void *)p;
128*05b00f60SXin Li break;
129*05b00f60SXin Li
130*05b00f60SXin Li default:
131*05b00f60SXin Li break;
132*05b00f60SXin Li }
133*05b00f60SXin Li
134*05b00f60SXin Li /*
135*05b00f60SXin Li * Only one routing header to a customer.
136*05b00f60SXin Li */
137*05b00f60SXin Li goto done;
138*05b00f60SXin Li
139*05b00f60SXin Li case IPPROTO_AH:
140*05b00f60SXin Li case IPPROTO_ESP:
141*05b00f60SXin Li case IPPROTO_IPCOMP:
142*05b00f60SXin Li default:
143*05b00f60SXin Li /*
144*05b00f60SXin Li * AH and ESP are, in the RFCs that describe them,
145*05b00f60SXin Li * described as being "viewed as an end-to-end
146*05b00f60SXin Li * payload" "in the IPv6 context, so that they
147*05b00f60SXin Li * "should appear after hop-by-hop, routing, and
148*05b00f60SXin Li * fragmentation extension headers". We assume
149*05b00f60SXin Li * that's the case, and stop as soon as we see
150*05b00f60SXin Li * one. (We can't handle an ESP header in
151*05b00f60SXin Li * the general case anyway, as its length depends
152*05b00f60SXin Li * on the encryption algorithm.)
153*05b00f60SXin Li *
154*05b00f60SXin Li * IPComp is also "viewed as an end-to-end
155*05b00f60SXin Li * payload" "in the IPv6 context".
156*05b00f60SXin Li *
157*05b00f60SXin Li * All other protocols are assumed to be the final
158*05b00f60SXin Li * protocol.
159*05b00f60SXin Li */
160*05b00f60SXin Li goto done;
161*05b00f60SXin Li }
162*05b00f60SXin Li }
163*05b00f60SXin Li
164*05b00f60SXin Li done:
165*05b00f60SXin Li trunc:
166*05b00f60SXin Li GET_CPY_BYTES(dst, dst_addr, sizeof(nd_ipv6));
167*05b00f60SXin Li }
168*05b00f60SXin Li
169*05b00f60SXin Li /*
170*05b00f60SXin Li * Compute a V6-style checksum by building a pseudoheader.
171*05b00f60SXin Li */
172*05b00f60SXin Li uint16_t
nextproto6_cksum(netdissect_options * ndo,const struct ip6_hdr * ip6,const uint8_t * data,u_int len,u_int covlen,uint8_t next_proto)173*05b00f60SXin Li nextproto6_cksum(netdissect_options *ndo,
174*05b00f60SXin Li const struct ip6_hdr *ip6, const uint8_t *data,
175*05b00f60SXin Li u_int len, u_int covlen, uint8_t next_proto)
176*05b00f60SXin Li {
177*05b00f60SXin Li struct {
178*05b00f60SXin Li nd_ipv6 ph_src;
179*05b00f60SXin Li nd_ipv6 ph_dst;
180*05b00f60SXin Li uint32_t ph_len;
181*05b00f60SXin Li uint8_t ph_zero[3];
182*05b00f60SXin Li uint8_t ph_nxt;
183*05b00f60SXin Li } ph;
184*05b00f60SXin Li struct cksum_vec vec[2];
185*05b00f60SXin Li u_int nh;
186*05b00f60SXin Li
187*05b00f60SXin Li /* pseudo-header */
188*05b00f60SXin Li memset(&ph, 0, sizeof(ph));
189*05b00f60SXin Li GET_CPY_BYTES(&ph.ph_src, ip6->ip6_src, sizeof(nd_ipv6));
190*05b00f60SXin Li nh = GET_U_1(ip6->ip6_nxt);
191*05b00f60SXin Li switch (nh) {
192*05b00f60SXin Li
193*05b00f60SXin Li case IPPROTO_HOPOPTS:
194*05b00f60SXin Li case IPPROTO_DSTOPTS:
195*05b00f60SXin Li case IPPROTO_MOBILITY_OLD:
196*05b00f60SXin Li case IPPROTO_MOBILITY:
197*05b00f60SXin Li case IPPROTO_FRAGMENT:
198*05b00f60SXin Li case IPPROTO_ROUTING:
199*05b00f60SXin Li /*
200*05b00f60SXin Li * The next header is either a routing header or a header
201*05b00f60SXin Li * after which there might be a routing header, so scan
202*05b00f60SXin Li * for a routing header.
203*05b00f60SXin Li */
204*05b00f60SXin Li ip6_finddst(ndo, &ph.ph_dst, ip6);
205*05b00f60SXin Li break;
206*05b00f60SXin Li
207*05b00f60SXin Li default:
208*05b00f60SXin Li GET_CPY_BYTES(&ph.ph_dst, ip6->ip6_dst, sizeof(nd_ipv6));
209*05b00f60SXin Li break;
210*05b00f60SXin Li }
211*05b00f60SXin Li ph.ph_len = htonl(len);
212*05b00f60SXin Li ph.ph_nxt = next_proto;
213*05b00f60SXin Li
214*05b00f60SXin Li vec[0].ptr = (const uint8_t *)(void *)&ph;
215*05b00f60SXin Li vec[0].len = sizeof(ph);
216*05b00f60SXin Li vec[1].ptr = data;
217*05b00f60SXin Li vec[1].len = covlen;
218*05b00f60SXin Li
219*05b00f60SXin Li return in_cksum(vec, 2);
220*05b00f60SXin Li }
221*05b00f60SXin Li
222*05b00f60SXin Li /*
223*05b00f60SXin Li * print an IP6 datagram.
224*05b00f60SXin Li */
225*05b00f60SXin Li void
ip6_print(netdissect_options * ndo,const u_char * bp,u_int length)226*05b00f60SXin Li ip6_print(netdissect_options *ndo, const u_char *bp, u_int length)
227*05b00f60SXin Li {
228*05b00f60SXin Li const struct ip6_hdr *ip6;
229*05b00f60SXin Li int advance;
230*05b00f60SXin Li u_int len;
231*05b00f60SXin Li u_int total_advance;
232*05b00f60SXin Li const u_char *cp;
233*05b00f60SXin Li uint32_t payload_len;
234*05b00f60SXin Li uint8_t ph, nh;
235*05b00f60SXin Li int fragmented = 0;
236*05b00f60SXin Li u_int flow;
237*05b00f60SXin Li int found_extension_header;
238*05b00f60SXin Li int found_jumbo;
239*05b00f60SXin Li int found_hbh;
240*05b00f60SXin Li
241*05b00f60SXin Li ndo->ndo_protocol = "ip6";
242*05b00f60SXin Li ip6 = (const struct ip6_hdr *)bp;
243*05b00f60SXin Li
244*05b00f60SXin Li ND_TCHECK_SIZE(ip6);
245*05b00f60SXin Li if (length < sizeof (struct ip6_hdr)) {
246*05b00f60SXin Li ND_PRINT("truncated-ip6 %u", length);
247*05b00f60SXin Li return;
248*05b00f60SXin Li }
249*05b00f60SXin Li
250*05b00f60SXin Li if (!ndo->ndo_eflag)
251*05b00f60SXin Li ND_PRINT("IP6 ");
252*05b00f60SXin Li
253*05b00f60SXin Li if (IP6_VERSION(ip6) != 6) {
254*05b00f60SXin Li ND_PRINT("version error: %u != 6", IP6_VERSION(ip6));
255*05b00f60SXin Li return;
256*05b00f60SXin Li }
257*05b00f60SXin Li
258*05b00f60SXin Li payload_len = GET_BE_U_2(ip6->ip6_plen);
259*05b00f60SXin Li /*
260*05b00f60SXin Li * RFC 1883 says:
261*05b00f60SXin Li *
262*05b00f60SXin Li * The Payload Length field in the IPv6 header must be set to zero
263*05b00f60SXin Li * in every packet that carries the Jumbo Payload option. If a
264*05b00f60SXin Li * packet is received with a valid Jumbo Payload option present and
265*05b00f60SXin Li * a non-zero IPv6 Payload Length field, an ICMP Parameter Problem
266*05b00f60SXin Li * message, Code 0, should be sent to the packet's source, pointing
267*05b00f60SXin Li * to the Option Type field of the Jumbo Payload option.
268*05b00f60SXin Li *
269*05b00f60SXin Li * Later versions of the IPv6 spec don't discuss the Jumbo Payload
270*05b00f60SXin Li * option.
271*05b00f60SXin Li *
272*05b00f60SXin Li * If the payload length is 0, we temporarily just set the total
273*05b00f60SXin Li * length to the remaining data in the packet (which, for Ethernet,
274*05b00f60SXin Li * could include frame padding, but if it's a Jumbo Payload frame,
275*05b00f60SXin Li * it shouldn't even be sendable over Ethernet, so we don't worry
276*05b00f60SXin Li * about that), so we can process the extension headers in order
277*05b00f60SXin Li * to *find* a Jumbo Payload hop-by-hop option and, when we've
278*05b00f60SXin Li * processed all the extension headers, check whether we found
279*05b00f60SXin Li * a Jumbo Payload option, and fail if we haven't.
280*05b00f60SXin Li */
281*05b00f60SXin Li if (payload_len != 0) {
282*05b00f60SXin Li len = payload_len + sizeof(struct ip6_hdr);
283*05b00f60SXin Li if (length < len)
284*05b00f60SXin Li ND_PRINT("truncated-ip6 - %u bytes missing!",
285*05b00f60SXin Li len - length);
286*05b00f60SXin Li } else
287*05b00f60SXin Li len = length + sizeof(struct ip6_hdr);
288*05b00f60SXin Li
289*05b00f60SXin Li ph = 255;
290*05b00f60SXin Li nh = GET_U_1(ip6->ip6_nxt);
291*05b00f60SXin Li if (ndo->ndo_vflag) {
292*05b00f60SXin Li flow = GET_BE_U_4(ip6->ip6_flow);
293*05b00f60SXin Li ND_PRINT("(");
294*05b00f60SXin Li /* RFC 2460 */
295*05b00f60SXin Li if (flow & 0x0ff00000)
296*05b00f60SXin Li ND_PRINT("class 0x%02x, ", (flow & 0x0ff00000) >> 20);
297*05b00f60SXin Li if (flow & 0x000fffff)
298*05b00f60SXin Li ND_PRINT("flowlabel 0x%05x, ", flow & 0x000fffff);
299*05b00f60SXin Li
300*05b00f60SXin Li ND_PRINT("hlim %u, next-header %s (%u) payload length: %u) ",
301*05b00f60SXin Li GET_U_1(ip6->ip6_hlim),
302*05b00f60SXin Li tok2str(ipproto_values,"unknown",nh),
303*05b00f60SXin Li nh,
304*05b00f60SXin Li payload_len);
305*05b00f60SXin Li }
306*05b00f60SXin Li
307*05b00f60SXin Li /*
308*05b00f60SXin Li * Cut off the snapshot length to the end of the IP payload.
309*05b00f60SXin Li */
310*05b00f60SXin Li if (!nd_push_snaplen(ndo, bp, len)) {
311*05b00f60SXin Li (*ndo->ndo_error)(ndo, S_ERR_ND_MEM_ALLOC,
312*05b00f60SXin Li "%s: can't push snaplen on buffer stack", __func__);
313*05b00f60SXin Li }
314*05b00f60SXin Li
315*05b00f60SXin Li cp = (const u_char *)ip6;
316*05b00f60SXin Li advance = sizeof(struct ip6_hdr);
317*05b00f60SXin Li total_advance = 0;
318*05b00f60SXin Li /* Process extension headers */
319*05b00f60SXin Li found_extension_header = 0;
320*05b00f60SXin Li found_jumbo = 0;
321*05b00f60SXin Li found_hbh = 0;
322*05b00f60SXin Li while (cp < ndo->ndo_snapend && advance > 0) {
323*05b00f60SXin Li if (len < (u_int)advance)
324*05b00f60SXin Li goto trunc;
325*05b00f60SXin Li cp += advance;
326*05b00f60SXin Li len -= advance;
327*05b00f60SXin Li total_advance += advance;
328*05b00f60SXin Li
329*05b00f60SXin Li if (cp == (const u_char *)(ip6 + 1) &&
330*05b00f60SXin Li nh != IPPROTO_TCP && nh != IPPROTO_UDP &&
331*05b00f60SXin Li nh != IPPROTO_DCCP && nh != IPPROTO_SCTP) {
332*05b00f60SXin Li ND_PRINT("%s > %s: ", GET_IP6ADDR_STRING(ip6->ip6_src),
333*05b00f60SXin Li GET_IP6ADDR_STRING(ip6->ip6_dst));
334*05b00f60SXin Li }
335*05b00f60SXin Li
336*05b00f60SXin Li switch (nh) {
337*05b00f60SXin Li
338*05b00f60SXin Li case IPPROTO_HOPOPTS:
339*05b00f60SXin Li /*
340*05b00f60SXin Li * The Hop-by-Hop Options header, when present,
341*05b00f60SXin Li * must immediately follow the IPv6 header (RFC 8200)
342*05b00f60SXin Li */
343*05b00f60SXin Li if (found_hbh == 1) {
344*05b00f60SXin Li ND_PRINT("[The Hop-by-Hop Options header was already found]");
345*05b00f60SXin Li nd_print_invalid(ndo);
346*05b00f60SXin Li return;
347*05b00f60SXin Li }
348*05b00f60SXin Li if (ph != 255) {
349*05b00f60SXin Li ND_PRINT("[The Hop-by-Hop Options header don't follow the IPv6 header]");
350*05b00f60SXin Li nd_print_invalid(ndo);
351*05b00f60SXin Li return;
352*05b00f60SXin Li }
353*05b00f60SXin Li advance = hbhopt_process(ndo, cp, &found_jumbo, &payload_len);
354*05b00f60SXin Li if (payload_len == 0 && found_jumbo == 0) {
355*05b00f60SXin Li ND_PRINT("[No valid Jumbo Payload Hop-by-Hop option found]");
356*05b00f60SXin Li nd_print_invalid(ndo);
357*05b00f60SXin Li return;
358*05b00f60SXin Li }
359*05b00f60SXin Li if (advance < 0) {
360*05b00f60SXin Li nd_pop_packet_info(ndo);
361*05b00f60SXin Li return;
362*05b00f60SXin Li }
363*05b00f60SXin Li found_extension_header = 1;
364*05b00f60SXin Li found_hbh = 1;
365*05b00f60SXin Li nh = GET_U_1(cp);
366*05b00f60SXin Li break;
367*05b00f60SXin Li
368*05b00f60SXin Li case IPPROTO_DSTOPTS:
369*05b00f60SXin Li advance = dstopt_process(ndo, cp);
370*05b00f60SXin Li if (advance < 0) {
371*05b00f60SXin Li nd_pop_packet_info(ndo);
372*05b00f60SXin Li return;
373*05b00f60SXin Li }
374*05b00f60SXin Li found_extension_header = 1;
375*05b00f60SXin Li nh = GET_U_1(cp);
376*05b00f60SXin Li break;
377*05b00f60SXin Li
378*05b00f60SXin Li case IPPROTO_FRAGMENT:
379*05b00f60SXin Li advance = frag6_print(ndo, cp, (const u_char *)ip6);
380*05b00f60SXin Li if (advance < 0 || ndo->ndo_snapend <= cp + advance) {
381*05b00f60SXin Li nd_pop_packet_info(ndo);
382*05b00f60SXin Li return;
383*05b00f60SXin Li }
384*05b00f60SXin Li found_extension_header = 1;
385*05b00f60SXin Li nh = GET_U_1(cp);
386*05b00f60SXin Li fragmented = 1;
387*05b00f60SXin Li break;
388*05b00f60SXin Li
389*05b00f60SXin Li case IPPROTO_MOBILITY_OLD:
390*05b00f60SXin Li case IPPROTO_MOBILITY:
391*05b00f60SXin Li /*
392*05b00f60SXin Li * XXX - we don't use "advance"; RFC 3775 says that
393*05b00f60SXin Li * the next header field in a mobility header
394*05b00f60SXin Li * should be IPPROTO_NONE, but speaks of
395*05b00f60SXin Li * the possibility of a future extension in
396*05b00f60SXin Li * which payload can be piggybacked atop a
397*05b00f60SXin Li * mobility header.
398*05b00f60SXin Li */
399*05b00f60SXin Li advance = mobility_print(ndo, cp, (const u_char *)ip6);
400*05b00f60SXin Li if (advance < 0) {
401*05b00f60SXin Li nd_pop_packet_info(ndo);
402*05b00f60SXin Li return;
403*05b00f60SXin Li }
404*05b00f60SXin Li found_extension_header = 1;
405*05b00f60SXin Li nh = GET_U_1(cp);
406*05b00f60SXin Li nd_pop_packet_info(ndo);
407*05b00f60SXin Li return;
408*05b00f60SXin Li
409*05b00f60SXin Li case IPPROTO_ROUTING:
410*05b00f60SXin Li ND_TCHECK_1(cp);
411*05b00f60SXin Li advance = rt6_print(ndo, cp, (const u_char *)ip6);
412*05b00f60SXin Li if (advance < 0) {
413*05b00f60SXin Li nd_pop_packet_info(ndo);
414*05b00f60SXin Li return;
415*05b00f60SXin Li }
416*05b00f60SXin Li found_extension_header = 1;
417*05b00f60SXin Li nh = GET_U_1(cp);
418*05b00f60SXin Li break;
419*05b00f60SXin Li
420*05b00f60SXin Li default:
421*05b00f60SXin Li /*
422*05b00f60SXin Li * Not an extension header; hand off to the
423*05b00f60SXin Li * IP protocol demuxer.
424*05b00f60SXin Li */
425*05b00f60SXin Li if (found_jumbo) {
426*05b00f60SXin Li /*
427*05b00f60SXin Li * We saw a Jumbo Payload option.
428*05b00f60SXin Li * Set the length to the payload length
429*05b00f60SXin Li * plus the IPv6 header length, and
430*05b00f60SXin Li * change the snapshot length accordingly.
431*05b00f60SXin Li *
432*05b00f60SXin Li * But make sure it's not shorter than
433*05b00f60SXin Li * the total number of bytes we've
434*05b00f60SXin Li * processed so far.
435*05b00f60SXin Li */
436*05b00f60SXin Li len = payload_len + sizeof(struct ip6_hdr);
437*05b00f60SXin Li if (len < total_advance)
438*05b00f60SXin Li goto trunc;
439*05b00f60SXin Li if (length < len)
440*05b00f60SXin Li ND_PRINT("truncated-ip6 - %u bytes missing!",
441*05b00f60SXin Li len - length);
442*05b00f60SXin Li nd_change_snaplen(ndo, bp, len);
443*05b00f60SXin Li
444*05b00f60SXin Li /*
445*05b00f60SXin Li * Now subtract the length of the IPv6
446*05b00f60SXin Li * header plus extension headers to get
447*05b00f60SXin Li * the payload length.
448*05b00f60SXin Li */
449*05b00f60SXin Li len -= total_advance;
450*05b00f60SXin Li } else {
451*05b00f60SXin Li /*
452*05b00f60SXin Li * We didn't see a Jumbo Payload option;
453*05b00f60SXin Li * was the payload length zero?
454*05b00f60SXin Li */
455*05b00f60SXin Li if (payload_len == 0) {
456*05b00f60SXin Li /*
457*05b00f60SXin Li * Yes. If we found an extension
458*05b00f60SXin Li * header, treat that as a truncated
459*05b00f60SXin Li * packet header, as there was
460*05b00f60SXin Li * no payload to contain an
461*05b00f60SXin Li * extension header.
462*05b00f60SXin Li */
463*05b00f60SXin Li if (found_extension_header)
464*05b00f60SXin Li goto trunc;
465*05b00f60SXin Li
466*05b00f60SXin Li /*
467*05b00f60SXin Li * OK, we didn't see any extension
468*05b00f60SXin Li * header, but that means we have
469*05b00f60SXin Li * no payload, so set the length
470*05b00f60SXin Li * to the IPv6 header length,
471*05b00f60SXin Li * and change the snapshot length
472*05b00f60SXin Li * accordingly.
473*05b00f60SXin Li */
474*05b00f60SXin Li len = sizeof(struct ip6_hdr);
475*05b00f60SXin Li nd_change_snaplen(ndo, bp, len);
476*05b00f60SXin Li
477*05b00f60SXin Li /*
478*05b00f60SXin Li * Now subtract the length of
479*05b00f60SXin Li * the IPv6 header plus extension
480*05b00f60SXin Li * headers (there weren't any, so
481*05b00f60SXin Li * that's just the IPv6 header
482*05b00f60SXin Li * length) to get the payload length.
483*05b00f60SXin Li */
484*05b00f60SXin Li len -= total_advance;
485*05b00f60SXin Li }
486*05b00f60SXin Li }
487*05b00f60SXin Li ip_demux_print(ndo, cp, len, 6, fragmented,
488*05b00f60SXin Li GET_U_1(ip6->ip6_hlim), nh, bp);
489*05b00f60SXin Li nd_pop_packet_info(ndo);
490*05b00f60SXin Li return;
491*05b00f60SXin Li }
492*05b00f60SXin Li ph = nh;
493*05b00f60SXin Li
494*05b00f60SXin Li /* ndo_protocol reassignment after xxx_print() calls */
495*05b00f60SXin Li ndo->ndo_protocol = "ip6";
496*05b00f60SXin Li }
497*05b00f60SXin Li
498*05b00f60SXin Li nd_pop_packet_info(ndo);
499*05b00f60SXin Li return;
500*05b00f60SXin Li trunc:
501*05b00f60SXin Li nd_print_trunc(ndo);
502*05b00f60SXin Li }
503