]>
The Tcpdump Group git mirrors - tcpdump/blob - print-rt6.c
2 * Copyright (c) 1988, 1989, 1990, 1991, 1993, 1994
3 * The Regents of the University of California. All rights reserved.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that: (1) source code distributions
7 * retain the above copyright notice and this paragraph in its entirety, (2)
8 * distributions including binary code include the above copyright notice and
9 * this paragraph in its entirety in the documentation or other materials
10 * provided with the distribution, and (3) all advertising materials mentioning
11 * features or use of this software display the following acknowledgement:
12 * ``This product includes software developed by the University of California,
13 * Lawrence Berkeley Laboratory and its contributors.'' Neither the name of
14 * the University nor the names of its contributors may be used to endorse
15 * or promote products derived from this software without specific prior
17 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
18 * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
19 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
22 /* \summary: IPv6 routing header printer */
28 #include "netdissect-stdinc.h"
30 #include "netdissect.h"
31 #include "addrtoname.h"
37 srh_tlv_print(netdissect_options
*ndo
, const u_char
*p
, u_int bytes_left
)
39 u_int tlv_type
, tlv_len
;
40 while (bytes_left
!= 0) {
41 tlv_type
= GET_U_1(p
);
42 ND_ICHECKMSG_U("remaining length", bytes_left
, <, 1);
47 if (tlv_type
== IPV6_SRH_TLV_PAD1
) {
48 ND_PRINT(", TLV-type=Pad1(%u)", tlv_type
);
53 ND_ICHECKMSG_U("remaining length", bytes_left
, <, 1);
58 case IPV6_SRH_TLV_PADN
:
59 ND_PRINT(", TLV-type=PadN(%u)", tlv_type
);
60 ND_PRINT(", TLV-len=%u", tlv_len
);
61 ND_ICHECKMSG_U("PadN length", tlv_len
, >, 5); /* RFC 8754 */
62 ND_ICHECKMSG_U("remaining length", bytes_left
, <, tlv_len
);
64 bytes_left
-= tlv_len
;
66 case IPV6_SRH_TLV_HMAC
:
67 ND_PRINT(", TLV-type=HMAC(%u)", tlv_type
);
68 ND_PRINT(", TLV-len=%u", tlv_len
);
69 ND_ICHECKMSG_U("remaining length", bytes_left
, <, 6);
73 reserved
= GET_BE_U_2(p
);
76 ND_PRINT(", D=%u", reserved
>> 15);
77 key_id
= GET_BE_U_4(p
);
80 ND_PRINT(", HMAC-key-ID=0x%02x", key_id
);
83 ND_PRINT(", HMAC=0x");
84 for (u_int i
= 0; i
< tlv_len
; i
++) {
85 hmac_byte
= GET_U_1(p
);
86 ND_ICHECKMSG_U("remaining length", bytes_left
, <, 1);
90 ND_PRINT("%02x", hmac_byte
);
93 default: /* Unknown type */
95 ND_PRINT(", TLV-len=%u", tlv_len
);
97 ND_PRINT(", TLV-value=0x");
98 ND_ICHECKMSG_U("remaining length", bytes_left
, <, tlv_len
);
100 for (u_int i
= 0; i
< tlv_len
; i
++) {
101 tlv_byte
= GET_U_1(p
);
105 ND_PRINT("%02x", tlv_byte
);
118 rt6_print(netdissect_options
*ndo
, const u_char
*bp
, const u_char
*bp2 _U_
)
120 const struct ip6_rthdr
*dp
;
121 const struct ip6_rthdr0
*dp0
;
122 const struct ip6_srh
*srh
;
123 u_int i
, len
, type
, seg_list_len
, last_entry
;
127 ndo
->ndo_protocol
= "rt6";
129 nd_print_protocol_caps(ndo
);
130 dp
= (const struct ip6_rthdr
*)bp
;
132 len
= GET_U_1(dp
->ip6r_len
);
133 ND_PRINT(" (len=%u", len
); /*)*/
134 type
= GET_U_1(dp
->ip6r_type
);
135 ND_PRINT(", type=%u", type
);
136 if (type
== IPV6_RTHDR_TYPE_0
)
137 ND_PRINT(" [Deprecated]");
138 ND_PRINT(", segleft=%u", GET_U_1(dp
->ip6r_segleft
));
141 case IPV6_RTHDR_TYPE_0
:
142 case IPV6_RTHDR_TYPE_2
: /* Mobile IPv6 ID-20 */
143 dp0
= (const struct ip6_rthdr0
*)dp
;
145 if (GET_BE_U_4(dp0
->ip6r0_reserved
) || ndo
->ndo_vflag
) {
146 ND_PRINT(", rsv=0x%0x",
147 GET_BE_U_4(dp0
->ip6r0_reserved
));
151 ND_PRINT(" (invalid length %u)", len
);
155 p
= (const u_char
*) dp0
->ip6r0_addr
;
156 for (i
= 0; i
< len
; i
++) {
157 ND_PRINT(", [%u]%s", i
, GET_IP6ADDR_STRING(p
));
162 return((GET_U_1(dp0
->ip6r0_len
) + 1) << 3);
164 case IPV6_RTHDR_TYPE_4
:
165 srh
= (const struct ip6_srh
*)dp
;
166 last_entry
= GET_U_1(srh
->srh_last_ent
);
167 ND_PRINT(", last-entry=%u", last_entry
);
169 if (GET_U_1(srh
->srh_flags
) || ndo
->ndo_vflag
) {
170 ND_PRINT(", flags=0x%0x",
171 GET_U_1(srh
->srh_flags
));
174 ND_PRINT(", tag=%x", GET_BE_U_2(srh
->srh_tag
));
175 p
= (const u_char
*) srh
->srh_segments
;
176 for (i
= 0; i
< last_entry
+ 1; i
++) {
177 ND_PRINT(", [%u]%s", i
, GET_IP6ADDR_STRING(p
));
180 seg_list_len
= (last_entry
+ 1) * 2;
181 if (seg_list_len
< len
) {
184 bytes_left
= (len
- seg_list_len
) * 8;
185 err
= srh_tlv_print(ndo
, p
, bytes_left
);
192 return((GET_U_1(srh
->srh_len
) + 1) << 3);
195 ND_PRINT(" (unknown type)");
200 nd_print_invalid(ndo
);