2 * Copyright (C) 1998 WIDE Project.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * 3. Neither the name of the project nor the names of its contributors
14 * may be used to endorse or promote products derived from this software
15 * without specific prior written permission.
17 * THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND
18 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 * ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE
21 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30 /* \summary: IPv6 header option printer */
36 #include <netdissect-stdinc.h>
38 #include "netdissect.h"
39 #include "addrtoname.h"
45 ip6_sopt_print(netdissect_options *ndo, const u_char *bp, int len)
50 for (i = 0; i < len; i += optlen) {
51 if (bp[i] == IP6OPT_PAD1)
55 optlen = bp[i + 1] + 2;
64 ND_PRINT((ndo, ", pad1"));
67 if (len - i < IP6OPT_MINLEN) {
68 ND_PRINT((ndo, ", padn: trunc"));
71 ND_PRINT((ndo, ", padn"));
74 if (len - i < IP6OPT_MINLEN) {
75 ND_PRINT((ndo, ", sopt_type %d: trunc)", bp[i]));
78 ND_PRINT((ndo, ", sopt_type 0x%02x: len=%d", bp[i], bp[i + 1]));
85 ND_PRINT((ndo, "[trunc] "));
89 ip6_opt_print(netdissect_options *ndo, const u_char *bp, int len)
96 for (i = 0; i < len; i += optlen) {
97 if (bp[i] == IP6OPT_PAD1)
101 optlen = bp[i + 1] + 2;
105 if (i + optlen > len)
110 ND_PRINT((ndo, "(pad1)"));
113 if (len - i < IP6OPT_MINLEN) {
114 ND_PRINT((ndo, "(padn: trunc)"));
117 ND_PRINT((ndo, "(padn)"));
119 case IP6OPT_ROUTER_ALERT:
120 if (len - i < IP6OPT_RTALERT_LEN) {
121 ND_PRINT((ndo, "(rtalert: trunc)"));
124 if (bp[i + 1] != IP6OPT_RTALERT_LEN - 2) {
125 ND_PRINT((ndo, "(rtalert: invalid len %d)", bp[i + 1]));
128 ND_PRINT((ndo, "(rtalert: 0x%04x) ", EXTRACT_16BITS(&bp[i + 2])));
131 if (len - i < IP6OPT_JUMBO_LEN) {
132 ND_PRINT((ndo, "(jumbo: trunc)"));
135 if (bp[i + 1] != IP6OPT_JUMBO_LEN - 2) {
136 ND_PRINT((ndo, "(jumbo: invalid len %d)", bp[i + 1]));
139 ND_PRINT((ndo, "(jumbo: %u) ", EXTRACT_32BITS(&bp[i + 2])));
141 case IP6OPT_HOME_ADDRESS:
142 if (len - i < IP6OPT_HOMEADDR_MINLEN) {
143 ND_PRINT((ndo, "(homeaddr: trunc)"));
146 if (bp[i + 1] < IP6OPT_HOMEADDR_MINLEN - 2) {
147 ND_PRINT((ndo, "(homeaddr: invalid len %d)", bp[i + 1]));
150 ND_PRINT((ndo, "(homeaddr: %s", ip6addr_string(ndo, &bp[i + 2])));
151 if (bp[i + 1] > IP6OPT_HOMEADDR_MINLEN - 2) {
152 ip6_sopt_print(ndo, &bp[i + IP6OPT_HOMEADDR_MINLEN],
153 (optlen - IP6OPT_HOMEADDR_MINLEN));
155 ND_PRINT((ndo, ")"));
158 if (len - i < IP6OPT_MINLEN) {
159 ND_PRINT((ndo, "(type %d: trunc)", bp[i]));
162 ND_PRINT((ndo, "(opt_type 0x%02x: len=%d)", bp[i], bp[i + 1]));
166 ND_PRINT((ndo, " "));
170 ND_PRINT((ndo, "[trunc] "));
174 hbhopt_print(netdissect_options *ndo, register const u_char *bp)
176 const struct ip6_hbh *dp = (const struct ip6_hbh *)bp;
179 ND_TCHECK(dp->ip6h_len);
180 hbhlen = (int)((dp->ip6h_len + 1) << 3);
181 ND_TCHECK2(*dp, hbhlen);
182 ND_PRINT((ndo, "HBH "));
184 ip6_opt_print(ndo, (const u_char *)dp + sizeof(*dp), hbhlen - sizeof(*dp));
189 ND_PRINT((ndo, "[|HBH]"));
194 dstopt_print(netdissect_options *ndo, register const u_char *bp)
196 const struct ip6_dest *dp = (const struct ip6_dest *)bp;
199 ND_TCHECK(dp->ip6d_len);
200 dstoptlen = (int)((dp->ip6d_len + 1) << 3);
201 ND_TCHECK2(*dp, dstoptlen);
202 ND_PRINT((ndo, "DSTOPT "));
203 if (ndo->ndo_vflag) {
204 ip6_opt_print(ndo, (const u_char *)dp + sizeof(*dp),
205 dstoptlen - sizeof(*dp));
211 ND_PRINT((ndo, "[|DSTOPT]"));