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 (GET_U_1(bp + i) == IP6OPT_PAD1)
55 optlen = GET_U_1(bp + i + 1) + 2;
62 switch (GET_U_1(bp + i)) {
67 if (len - i < IP6OPT_MINLEN) {
68 ND_PRINT(", padn: trunc");
74 if (len - i < IP6OPT_MINLEN) {
75 ND_PRINT(", sopt_type %u: trunc)", GET_U_1(bp + i));
78 ND_PRINT(", sopt_type 0x%02x: len=%u", GET_U_1(bp + i),
90 ip6_opt_process(netdissect_options *ndo, const u_char *bp, int len,
91 int *found_jumbop, uint32_t *payload_len)
96 uint32_t jumbolen = 0;
100 for (i = 0; i < len; i += optlen) {
101 if (GET_U_1(bp + i) == IP6OPT_PAD1)
105 optlen = GET_U_1(bp + i + 1) + 2;
109 if (i + optlen > len)
112 switch (GET_U_1(bp + i)) {
118 if (len - i < IP6OPT_MINLEN) {
119 ND_PRINT("(padn: trunc)");
125 case IP6OPT_ROUTER_ALERT:
126 if (len - i < IP6OPT_RTALERT_LEN) {
127 ND_PRINT("(rtalert: trunc)");
130 if (GET_U_1(bp + i + 1) != IP6OPT_RTALERT_LEN - 2) {
131 ND_PRINT("(rtalert: invalid len %u)", GET_U_1(bp + i + 1));
135 ND_PRINT("(rtalert: 0x%04x) ", GET_BE_U_2(bp + i + 2));
138 if (len - i < IP6OPT_JUMBO_LEN) {
139 ND_PRINT("(jumbo: trunc)");
142 if (GET_U_1(bp + i + 1) != IP6OPT_JUMBO_LEN - 2) {
143 ND_PRINT("(jumbo: invalid len %u)", GET_U_1(bp + i + 1));
146 jumbolen = GET_BE_U_4(bp + i + 2);
148 /* More than one Jumbo Payload option */
150 ND_PRINT("(jumbo: %u - already seen) ", jumbolen);
153 if (payload_len == NULL) {
154 /* Not a hop-by-hop option - not valid */
156 ND_PRINT("(jumbo: %u - not a hop-by-hop option) ", jumbolen);
157 } else if (*payload_len != 0) {
158 /* Payload length was non-zero - not valid */
160 ND_PRINT("(jumbo: %u - payload len != 0) ", jumbolen);
163 * This is a hop-by-hop option, and Payload length
164 * was zero in the IPv6 header.
166 if (jumbolen < 65536) {
169 ND_PRINT("(jumbo: %u - < 65536) ", jumbolen);
171 /* OK, this is valid */
173 *payload_len = jumbolen;
175 ND_PRINT("(jumbo: %u) ", jumbolen);
180 case IP6OPT_HOME_ADDRESS:
181 if (len - i < IP6OPT_HOMEADDR_MINLEN) {
182 ND_PRINT("(homeaddr: trunc)");
185 if (GET_U_1(bp + i + 1) < IP6OPT_HOMEADDR_MINLEN - 2) {
186 ND_PRINT("(homeaddr: invalid len %u)", GET_U_1(bp + i + 1));
189 if (ndo->ndo_vflag) {
190 ND_PRINT("(homeaddr: %s", GET_IP6ADDR_STRING(bp + i + 2));
191 if (GET_U_1(bp + i + 1) > IP6OPT_HOMEADDR_MINLEN - 2) {
192 if (ip6_sopt_print(ndo, bp + i + IP6OPT_HOMEADDR_MINLEN,
193 (optlen - IP6OPT_HOMEADDR_MINLEN)) == -1)
200 if (len - i < IP6OPT_MINLEN) {
201 ND_PRINT("(type %u: trunc)", GET_U_1(bp + i));
205 ND_PRINT("(opt_type 0x%02x: len=%u)", GET_U_1(bp + i),
206 GET_U_1(bp + i + 1));
219 hbhopt_process(netdissect_options *ndo, const u_char *bp, int *found_jumbo,
222 const struct ip6_hbh *dp = (const struct ip6_hbh *)bp;
225 ndo->ndo_protocol = "hbhopt";
226 hbhlen = (GET_U_1(dp->ip6h_len) + 1) << 3;
227 ND_TCHECK_LEN(dp, hbhlen);
229 if (ip6_opt_process(ndo, (const u_char *)dp + sizeof(*dp),
230 hbhlen - sizeof(*dp), found_jumbo, jumbolen) == -1)
240 dstopt_process(netdissect_options *ndo, const u_char *bp)
242 const struct ip6_dest *dp = (const struct ip6_dest *)bp;
245 ndo->ndo_protocol = "dstopt";
246 dstoptlen = (GET_U_1(dp->ip6d_len) + 1) << 3;
247 ND_TCHECK_LEN(dp, dstoptlen);
249 if (ndo->ndo_vflag) {
251 * The Jumbo Payload option is a hop-by-hop option; we don't
252 * honor Jumbo Payload destination options, reporting them
255 if (ip6_opt_process(ndo, (const u_char *)dp + sizeof(*dp),
256 dstoptlen - sizeof(*dp), NULL, NULL) == -1)