4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
22 * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
23 * Use is subject to license terms.
33 #include <sys/types.h>
34 #include <sys/sysmacros.h>
37 #include <sys/socket.h>
38 #include <sys/sockio.h>
40 #include <netinet/in_systm.h>
41 #include <netinet/in.h>
42 #include <netinet/ip.h>
43 #include <netinet/ip_icmp.h>
44 #include <netinet/icmp6.h>
45 #include <netinet/if_ether.h>
46 #include <inet/ipsecesp.h>
47 #include <inet/ipsecah.h>
52 interpret_esp(int flags
, uint8_t *hdr
, int iplen
, int fraglen
)
54 /* LINTED: alignment */
55 esph_t
*esph
= (esph_t
*)hdr
;
57 esph_t storage
; /* In case hdr isn't aligned. */
60 if (fraglen
< sizeof (esph_t
))
61 return (fraglen
); /* incomplete header */
63 if (!IS_P2ALIGNED(hdr
, 4)) {
64 aligned_esph
= &storage
;
65 bcopy(hdr
, aligned_esph
, sizeof (esph_t
));
71 line
= (char *)get_sum_line();
73 * sprintf() is safe because line guarantees us 80 columns,
74 * and SPI and replay certainly won't exceed that.
76 (void) sprintf(line
, "ESP SPI=0x%x Replay=%u",
77 ntohl(aligned_esph
->esph_spi
),
78 ntohl(aligned_esph
->esph_replay
));
82 if (flags
& F_DTAIL
) {
83 show_header("ESP: ", "Encapsulating Security Payload",
87 * sprintf() is safe because get_line guarantees us 80 columns,
88 * and SPI and replay certainly won't exceed that.
90 (void) sprintf(get_line((char *)&esph
->esph_spi
- dlc_header
,
91 4), "SPI = 0x%x", ntohl(aligned_esph
->esph_spi
));
92 (void) sprintf(get_line((char *)&esph
->esph_replay
-
93 dlc_header
, 4), "Replay = %u",
94 ntohl(aligned_esph
->esph_replay
));
95 (void) sprintf(get_line((char *)(esph
+ 1) - dlc_header
,
96 4), " ....ENCRYPTED DATA....");
99 return (sizeof (esph_t
));
103 interpret_ah(int flags
, uint8_t *hdr
, int iplen
, int fraglen
)
105 /* LINTED: alignment */
106 ah_t
*ah
= (ah_t
*)hdr
;
108 ah_t storage
; /* In case hdr isn't aligned. */
110 uint_t ahlen
, auth_data_len
;
111 uint8_t *auth_data
, *data
;
115 if (fraglen
< sizeof (ah_t
))
116 return (fraglen
); /* incomplete header */
118 if (!IS_P2ALIGNED(hdr
, 4)) {
119 aligned_ah
= (ah_t
*)&storage
;
120 bcopy(hdr
, &storage
, sizeof (ah_t
));
126 * "+ 8" is for the "constant" part that's not included in the AH
129 * The AH RFC specifies the length field in "length in 4-byte units,
130 * not counting the first 8 bytes". So if an AH is 24 bytes long,
131 * the length field will contain "4". (4 * 4 + 8 == 24).
133 ahlen
= (aligned_ah
->ah_length
<< 2) + 8;
136 return (fraglen
+ ahlen
); /* incomplete header */
138 auth_data_len
= ahlen
- sizeof (ah_t
);
139 auth_data
= (uint8_t *)(ah
+ 1);
140 data
= auth_data
+ auth_data_len
;
143 line
= (char *)get_sum_line();
144 (void) sprintf(line
, "AH SPI=0x%x Replay=%u",
145 ntohl(aligned_ah
->ah_spi
), ntohl(aligned_ah
->ah_replay
));
146 line
+= strlen(line
);
149 if (flags
& F_DTAIL
) {
150 show_header("AH: ", "Authentication Header", ahlen
);
152 (void) sprintf(get_line((char *)&ah
->ah_nexthdr
- dlc_header
,
153 1), "Next header = %d (%s)", aligned_ah
->ah_nexthdr
,
154 getproto(aligned_ah
->ah_nexthdr
));
155 (void) sprintf(get_line((char *)&ah
->ah_length
- dlc_header
, 1),
156 "AH length = %d (%d bytes)", aligned_ah
->ah_length
, ahlen
);
157 (void) sprintf(get_line((char *)&ah
->ah_reserved
- dlc_header
,
158 2), "<Reserved field = 0x%x>",
159 ntohs(aligned_ah
->ah_reserved
));
160 (void) sprintf(get_line((char *)&ah
->ah_spi
- dlc_header
, 4),
161 "SPI = 0x%x", ntohl(aligned_ah
->ah_spi
));
162 (void) sprintf(get_line((char *)&ah
->ah_replay
- dlc_header
, 4),
163 "Replay = %u", ntohl(aligned_ah
->ah_replay
));
166 * 2 for two hex digits per auth_data byte
167 * plus one byte for trailing null byte.
169 buff
= malloc(auth_data_len
* 2 + 1);
173 for (i
= 0; i
< auth_data_len
; i
++)
174 sprintf(buff
+ i
* 2, "%02x", auth_data
[i
]);
177 (void) sprintf(get_line((char *)auth_data
- dlc_header
,
178 auth_data_len
), "ICV = %s",
179 (buff
== NULL
) ? "<out of memory>" : buff
);
181 /* malloc(3c) says I can call free even if buff == NULL */
187 new_iplen
= iplen
- ahlen
;
188 proto
= aligned_ah
->ah_nexthdr
;
191 * Print IPv6 Extension Headers, or skip them in the summary case.
193 if (proto
== IPPROTO_HOPOPTS
|| proto
== IPPROTO_DSTOPTS
||
194 proto
== IPPROTO_ROUTING
|| proto
== IPPROTO_FRAGMENT
) {
195 (void) print_ipv6_extensions(flags
, &data
, &proto
, &iplen
,
202 /* LINTED: alignment */
203 (void) interpret_ip(flags
, (struct ip
*)data
,
207 (void) interpret_ipv6(flags
, (ip6_t
*)data
,
211 (void) interpret_icmp(flags
,
212 /* LINTED: alignment */
213 (struct icmp
*)data
, new_iplen
, fraglen
);
216 /* LINTED: alignment */
217 (void) interpret_icmpv6(flags
, (icmp6_t
*)data
,
221 (void) interpret_tcp(flags
,
222 (struct tcphdr
*)data
, new_iplen
, fraglen
);
226 (void) interpret_esp(flags
, data
, new_iplen
,
231 (void) interpret_ah(flags
, data
, new_iplen
,
236 (void) interpret_udp(flags
,
237 (struct udphdr
*)data
, new_iplen
, fraglen
);
239 /* default case is to not print anything else */