17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate * CDDL HEADER START
37c478bd9Sstevel@tonic-gate *
47c478bd9Sstevel@tonic-gate * The contents of this file are subject to the terms of the
545916cd2Sjpk * Common Development and Distribution License (the "License").
645916cd2Sjpk * You may not use this file except in compliance with the License.
77c478bd9Sstevel@tonic-gate *
87c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
97c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing.
107c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions
117c478bd9Sstevel@tonic-gate * and limitations under the License.
127c478bd9Sstevel@tonic-gate *
137c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each
147c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
157c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the
167c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying
177c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner]
187c478bd9Sstevel@tonic-gate *
197c478bd9Sstevel@tonic-gate * CDDL HEADER END
207c478bd9Sstevel@tonic-gate */
217c478bd9Sstevel@tonic-gate /*
222b24ab6bSSebastien Roy * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
237c478bd9Sstevel@tonic-gate * Use is subject to license terms.
24*7d897698SMilan Jurik * Copyright 2012 Milan Jurik. All rights reserved.
257c478bd9Sstevel@tonic-gate */
267c478bd9Sstevel@tonic-gate
277c478bd9Sstevel@tonic-gate #include <stdio.h>
287c478bd9Sstevel@tonic-gate #include <string.h>
297c478bd9Sstevel@tonic-gate #include <fcntl.h>
307c478bd9Sstevel@tonic-gate #include <string.h>
317c478bd9Sstevel@tonic-gate #include <sys/types.h>
327c478bd9Sstevel@tonic-gate #include <sys/time.h>
337c478bd9Sstevel@tonic-gate
347c478bd9Sstevel@tonic-gate #include <sys/stropts.h>
357c478bd9Sstevel@tonic-gate #include <sys/socket.h>
367c478bd9Sstevel@tonic-gate #include <net/if.h>
377c478bd9Sstevel@tonic-gate #include <netinet/in_systm.h>
387c478bd9Sstevel@tonic-gate #include <netinet/in.h>
397c478bd9Sstevel@tonic-gate #include <netinet/ip.h>
407c478bd9Sstevel@tonic-gate #include <netinet/ip6.h>
417c478bd9Sstevel@tonic-gate #include <netinet/ip_icmp.h>
427c478bd9Sstevel@tonic-gate #include <netinet/icmp6.h>
437c478bd9Sstevel@tonic-gate #include <netinet/if_ether.h>
4445916cd2Sjpk #include <inet/ip.h>
457c478bd9Sstevel@tonic-gate #include <inet/ip6.h>
467c478bd9Sstevel@tonic-gate #include <arpa/inet.h>
477c478bd9Sstevel@tonic-gate #include <netdb.h>
4845916cd2Sjpk #include <tsol/label.h>
4945916cd2Sjpk #include <sys/tsol/tndb.h>
5045916cd2Sjpk #include <sys/tsol/label_macro.h>
5145916cd2Sjpk
527c478bd9Sstevel@tonic-gate #include "snoop.h"
537c478bd9Sstevel@tonic-gate
547c478bd9Sstevel@tonic-gate
557c478bd9Sstevel@tonic-gate /*
567c478bd9Sstevel@tonic-gate * IPv6 extension header masks. These are used by the print_ipv6_extensions()
577c478bd9Sstevel@tonic-gate * function to return information to the caller about which extension headers
587c478bd9Sstevel@tonic-gate * were processed. This can be useful if the caller wants to know if the
597c478bd9Sstevel@tonic-gate * packet is an IPv6 fragment, for example.
607c478bd9Sstevel@tonic-gate */
617c478bd9Sstevel@tonic-gate #define SNOOP_HOPOPTS 0x01U
627c478bd9Sstevel@tonic-gate #define SNOOP_ROUTING 0x02U
637c478bd9Sstevel@tonic-gate #define SNOOP_DSTOPTS 0x04U
647c478bd9Sstevel@tonic-gate #define SNOOP_FRAGMENT 0x08U
657c478bd9Sstevel@tonic-gate #define SNOOP_AH 0x10U
667c478bd9Sstevel@tonic-gate #define SNOOP_ESP 0x20U
677c478bd9Sstevel@tonic-gate #define SNOOP_IPV6 0x40U
687c478bd9Sstevel@tonic-gate
6945916cd2Sjpk static void prt_routing_hdr(int, const struct ip6_rthdr *);
7045916cd2Sjpk static void prt_fragment_hdr(int, const struct ip6_frag *);
7145916cd2Sjpk static void prt_hbh_options(int, const struct ip6_hbh *);
7245916cd2Sjpk static void prt_dest_options(int, const struct ip6_dest *);
7345916cd2Sjpk static void print_route(const uchar_t *);
7445916cd2Sjpk static void print_ipoptions(const uchar_t *, int);
7545916cd2Sjpk static void print_ripso(const uchar_t *);
7645916cd2Sjpk static void print_cipso(const uchar_t *);
777c478bd9Sstevel@tonic-gate
787c478bd9Sstevel@tonic-gate /* Keep track of how many nested IP headers we have. */
797c478bd9Sstevel@tonic-gate unsigned int encap_levels;
807c478bd9Sstevel@tonic-gate unsigned int total_encap_levels = 1;
817c478bd9Sstevel@tonic-gate
827c478bd9Sstevel@tonic-gate int
interpret_ip(int flags,const struct ip * ip,int fraglen)8345916cd2Sjpk interpret_ip(int flags, const struct ip *ip, int fraglen)
847c478bd9Sstevel@tonic-gate {
8545916cd2Sjpk uchar_t *data;
867c478bd9Sstevel@tonic-gate char buff[24];
877c478bd9Sstevel@tonic-gate boolean_t isfrag = B_FALSE;
887c478bd9Sstevel@tonic-gate boolean_t morefrag;
897c478bd9Sstevel@tonic-gate uint16_t fragoffset;
907c478bd9Sstevel@tonic-gate int hdrlen;
917c478bd9Sstevel@tonic-gate uint16_t iplen, uitmp;
927c478bd9Sstevel@tonic-gate
937c478bd9Sstevel@tonic-gate if (ip->ip_v == IPV6_VERSION) {
947c478bd9Sstevel@tonic-gate iplen = interpret_ipv6(flags, (ip6_t *)ip, fraglen);
957c478bd9Sstevel@tonic-gate return (iplen);
967c478bd9Sstevel@tonic-gate }
977c478bd9Sstevel@tonic-gate
987c478bd9Sstevel@tonic-gate if (encap_levels == 0)
997c478bd9Sstevel@tonic-gate total_encap_levels = 0;
1007c478bd9Sstevel@tonic-gate encap_levels++;
1017c478bd9Sstevel@tonic-gate total_encap_levels++;
1027c478bd9Sstevel@tonic-gate
1037c478bd9Sstevel@tonic-gate hdrlen = ip->ip_hl * 4;
10445916cd2Sjpk data = ((uchar_t *)ip) + hdrlen;
1057c478bd9Sstevel@tonic-gate iplen = ntohs(ip->ip_len) - hdrlen;
1067c478bd9Sstevel@tonic-gate fraglen -= hdrlen;
1077c478bd9Sstevel@tonic-gate if (fraglen > iplen)
1087c478bd9Sstevel@tonic-gate fraglen = iplen;
1097c478bd9Sstevel@tonic-gate if (fraglen < 0) {
1107c478bd9Sstevel@tonic-gate (void) snprintf(get_sum_line(), MAXLINE,
1117c478bd9Sstevel@tonic-gate "IP truncated: header missing %d bytes", -fraglen);
1127c478bd9Sstevel@tonic-gate encap_levels--;
1137c478bd9Sstevel@tonic-gate return (fraglen + iplen);
1147c478bd9Sstevel@tonic-gate }
1157c478bd9Sstevel@tonic-gate /*
1167c478bd9Sstevel@tonic-gate * We flag this as a fragment if the more fragments bit is set, or
1177c478bd9Sstevel@tonic-gate * if the fragment offset is non-zero.
1187c478bd9Sstevel@tonic-gate */
1197c478bd9Sstevel@tonic-gate morefrag = (ntohs(ip->ip_off) & IP_MF) == 0 ? B_FALSE : B_TRUE;
1207c478bd9Sstevel@tonic-gate fragoffset = (ntohs(ip->ip_off) & 0x1FFF) * 8;
1217c478bd9Sstevel@tonic-gate if (morefrag || fragoffset != 0)
1227c478bd9Sstevel@tonic-gate isfrag = B_TRUE;
1237c478bd9Sstevel@tonic-gate
1242b24ab6bSSebastien Roy src_name = addrtoname(AF_INET, &ip->ip_src);
1252b24ab6bSSebastien Roy dst_name = addrtoname(AF_INET, &ip->ip_dst);
1267c478bd9Sstevel@tonic-gate
1277c478bd9Sstevel@tonic-gate if (flags & F_SUM) {
1287c478bd9Sstevel@tonic-gate if (isfrag) {
1297c478bd9Sstevel@tonic-gate (void) snprintf(get_sum_line(), MAXLINE,
1307c478bd9Sstevel@tonic-gate "%s IP fragment ID=%d Offset=%-4d MF=%d TOS=0x%x "
1317c478bd9Sstevel@tonic-gate "TTL=%d",
1327c478bd9Sstevel@tonic-gate getproto(ip->ip_p),
1337c478bd9Sstevel@tonic-gate ntohs(ip->ip_id),
1347c478bd9Sstevel@tonic-gate fragoffset,
1357c478bd9Sstevel@tonic-gate morefrag,
1367c478bd9Sstevel@tonic-gate ip->ip_tos,
1377c478bd9Sstevel@tonic-gate ip->ip_ttl);
1387c478bd9Sstevel@tonic-gate } else {
1397c478bd9Sstevel@tonic-gate (void) strlcpy(buff, inet_ntoa(ip->ip_dst),
1407c478bd9Sstevel@tonic-gate sizeof (buff));
1417c478bd9Sstevel@tonic-gate uitmp = ntohs(ip->ip_len);
1427c478bd9Sstevel@tonic-gate (void) snprintf(get_sum_line(), MAXLINE,
1437c478bd9Sstevel@tonic-gate "IP D=%s S=%s LEN=%u%s, ID=%d, TOS=0x%x, TTL=%d",
1447c478bd9Sstevel@tonic-gate buff,
1457c478bd9Sstevel@tonic-gate inet_ntoa(ip->ip_src),
1467c478bd9Sstevel@tonic-gate uitmp,
1477c478bd9Sstevel@tonic-gate iplen > fraglen ? "?" : "",
1487c478bd9Sstevel@tonic-gate ntohs(ip->ip_id),
1497c478bd9Sstevel@tonic-gate ip->ip_tos,
1507c478bd9Sstevel@tonic-gate ip->ip_ttl);
1517c478bd9Sstevel@tonic-gate }
1527c478bd9Sstevel@tonic-gate }
1537c478bd9Sstevel@tonic-gate
1547c478bd9Sstevel@tonic-gate if (flags & F_DTAIL) {
1557c478bd9Sstevel@tonic-gate show_header("IP: ", "IP Header", iplen);
1567c478bd9Sstevel@tonic-gate show_space();
15745916cd2Sjpk (void) snprintf(get_line(0, 0), get_line_remain(),
15845916cd2Sjpk "Version = %d", ip->ip_v);
15945916cd2Sjpk (void) snprintf(get_line(0, 0), get_line_remain(),
16045916cd2Sjpk "Header length = %d bytes", hdrlen);
16145916cd2Sjpk (void) snprintf(get_line(0, 0), get_line_remain(),
16245916cd2Sjpk "Type of service = 0x%02x", ip->ip_tos);
16345916cd2Sjpk (void) snprintf(get_line(0, 0), get_line_remain(),
16445916cd2Sjpk " xxx. .... = %d (precedence)",
1657c478bd9Sstevel@tonic-gate ip->ip_tos >> 5);
16645916cd2Sjpk (void) snprintf(get_line(0, 0), get_line_remain(),
16745916cd2Sjpk " %s", getflag(ip->ip_tos, IPTOS_LOWDELAY,
1687c478bd9Sstevel@tonic-gate "low delay", "normal delay"));
16945916cd2Sjpk (void) snprintf(get_line(0, 0), get_line_remain(), " %s",
1707c478bd9Sstevel@tonic-gate getflag(ip->ip_tos, IPTOS_THROUGHPUT,
1717c478bd9Sstevel@tonic-gate "high throughput", "normal throughput"));
17245916cd2Sjpk (void) snprintf(get_line(0, 0), get_line_remain(), " %s",
1737c478bd9Sstevel@tonic-gate getflag(ip->ip_tos, IPTOS_RELIABILITY,
1747c478bd9Sstevel@tonic-gate "high reliability", "normal reliability"));
17545916cd2Sjpk (void) snprintf(get_line(0, 0), get_line_remain(), " %s",
1767c478bd9Sstevel@tonic-gate getflag(ip->ip_tos, IPTOS_ECT,
1777c478bd9Sstevel@tonic-gate "ECN capable transport", "not ECN capable transport"));
17845916cd2Sjpk (void) snprintf(get_line(0, 0), get_line_remain(), " %s",
1797c478bd9Sstevel@tonic-gate getflag(ip->ip_tos, IPTOS_CE,
1807c478bd9Sstevel@tonic-gate "ECN congestion experienced",
1817c478bd9Sstevel@tonic-gate "no ECN congestion experienced"));
1827c478bd9Sstevel@tonic-gate /* warning: ip_len is signed in netinet/ip.h */
1837c478bd9Sstevel@tonic-gate uitmp = ntohs(ip->ip_len);
18445916cd2Sjpk (void) snprintf(get_line(0, 0), get_line_remain(),
18545916cd2Sjpk "Total length = %u bytes%s", uitmp,
1867c478bd9Sstevel@tonic-gate iplen > fraglen ? " -- truncated" : "");
18745916cd2Sjpk (void) snprintf(get_line(0, 0), get_line_remain(),
18845916cd2Sjpk "Identification = %d", ntohs(ip->ip_id));
1897c478bd9Sstevel@tonic-gate /* warning: ip_off is signed in netinet/ip.h */
1907c478bd9Sstevel@tonic-gate uitmp = ntohs(ip->ip_off);
19145916cd2Sjpk (void) snprintf(get_line(0, 0), get_line_remain(),
19245916cd2Sjpk "Flags = 0x%x", uitmp >> 12);
19345916cd2Sjpk (void) snprintf(get_line(0, 0), get_line_remain(), " %s",
1947c478bd9Sstevel@tonic-gate getflag(uitmp >> 8, IP_DF >> 8,
1957c478bd9Sstevel@tonic-gate "do not fragment", "may fragment"));
19645916cd2Sjpk (void) snprintf(get_line(0, 0), get_line_remain(), " %s",
1977c478bd9Sstevel@tonic-gate getflag(uitmp >> 8, IP_MF >> 8,
1987c478bd9Sstevel@tonic-gate "more fragments", "last fragment"));
19945916cd2Sjpk (void) snprintf(get_line(0, 0), get_line_remain(),
20045916cd2Sjpk "Fragment offset = %u bytes",
2017c478bd9Sstevel@tonic-gate fragoffset);
20245916cd2Sjpk (void) snprintf(get_line(0, 0), get_line_remain(),
20345916cd2Sjpk "Time to live = %d seconds/hops",
2047c478bd9Sstevel@tonic-gate ip->ip_ttl);
20545916cd2Sjpk (void) snprintf(get_line(0, 0), get_line_remain(),
20645916cd2Sjpk "Protocol = %d (%s)", ip->ip_p,
2077c478bd9Sstevel@tonic-gate getproto(ip->ip_p));
2087c478bd9Sstevel@tonic-gate /*
2097c478bd9Sstevel@tonic-gate * XXX need to compute checksum and print whether it's correct
2107c478bd9Sstevel@tonic-gate */
21145916cd2Sjpk (void) snprintf(get_line(0, 0), get_line_remain(),
21245916cd2Sjpk "Header checksum = %04x",
2137c478bd9Sstevel@tonic-gate ntohs(ip->ip_sum));
21445916cd2Sjpk (void) snprintf(get_line(0, 0), get_line_remain(),
21545916cd2Sjpk "Source address = %s, %s",
2167c478bd9Sstevel@tonic-gate inet_ntoa(ip->ip_src), addrtoname(AF_INET, &ip->ip_src));
21745916cd2Sjpk (void) snprintf(get_line(0, 0), get_line_remain(),
21845916cd2Sjpk "Destination address = %s, %s",
2197c478bd9Sstevel@tonic-gate inet_ntoa(ip->ip_dst), addrtoname(AF_INET, &ip->ip_dst));
2207c478bd9Sstevel@tonic-gate
2217c478bd9Sstevel@tonic-gate /* Print IP options - if any */
2227c478bd9Sstevel@tonic-gate
22345916cd2Sjpk print_ipoptions((const uchar_t *)(ip + 1),
22445916cd2Sjpk hdrlen - sizeof (struct ip));
2257c478bd9Sstevel@tonic-gate show_space();
2267c478bd9Sstevel@tonic-gate }
2277c478bd9Sstevel@tonic-gate
2287c478bd9Sstevel@tonic-gate /*
2297c478bd9Sstevel@tonic-gate * If we are in detail mode, and this is not the first fragment of
2307c478bd9Sstevel@tonic-gate * a fragmented packet, print out a little line stating this.
2317c478bd9Sstevel@tonic-gate * Otherwise, go to the next protocol layer only if this is not a
2327c478bd9Sstevel@tonic-gate * fragment, or we are in detail mode and this is the first fragment
2337c478bd9Sstevel@tonic-gate * of a fragmented packet.
2347c478bd9Sstevel@tonic-gate */
2357c478bd9Sstevel@tonic-gate if (flags & F_DTAIL && fragoffset != 0) {
23645916cd2Sjpk (void) snprintf(get_detail_line(0, 0), MAXLINE,
2377c478bd9Sstevel@tonic-gate "%s: [%d byte(s) of data, continuation of IP ident=%d]",
2387c478bd9Sstevel@tonic-gate getproto(ip->ip_p),
2397c478bd9Sstevel@tonic-gate iplen,
2407c478bd9Sstevel@tonic-gate ntohs(ip->ip_id));
2417c478bd9Sstevel@tonic-gate } else if (!isfrag || (flags & F_DTAIL) && isfrag && fragoffset == 0) {
2427c478bd9Sstevel@tonic-gate /* go to the next protocol layer */
2437c478bd9Sstevel@tonic-gate
2447c478bd9Sstevel@tonic-gate if (fraglen > 0) {
2457c478bd9Sstevel@tonic-gate switch (ip->ip_p) {
2467c478bd9Sstevel@tonic-gate case IPPROTO_IP:
2477c478bd9Sstevel@tonic-gate break;
2487c478bd9Sstevel@tonic-gate case IPPROTO_ENCAP:
24945916cd2Sjpk (void) interpret_ip(flags,
25045916cd2Sjpk /* LINTED: alignment */
25145916cd2Sjpk (const struct ip *)data, fraglen);
2527c478bd9Sstevel@tonic-gate break;
2537c478bd9Sstevel@tonic-gate case IPPROTO_ICMP:
25445916cd2Sjpk (void) interpret_icmp(flags,
25545916cd2Sjpk /* LINTED: alignment */
25645916cd2Sjpk (struct icmp *)data, iplen, fraglen);
2577c478bd9Sstevel@tonic-gate break;
2587c478bd9Sstevel@tonic-gate case IPPROTO_IGMP:
2597c478bd9Sstevel@tonic-gate interpret_igmp(flags, data, iplen, fraglen);
2607c478bd9Sstevel@tonic-gate break;
2617c478bd9Sstevel@tonic-gate case IPPROTO_GGP:
2627c478bd9Sstevel@tonic-gate break;
2637c478bd9Sstevel@tonic-gate case IPPROTO_TCP:
26445916cd2Sjpk (void) interpret_tcp(flags,
26545916cd2Sjpk (struct tcphdr *)data, iplen, fraglen);
2667c478bd9Sstevel@tonic-gate break;
2677c478bd9Sstevel@tonic-gate
2687c478bd9Sstevel@tonic-gate case IPPROTO_ESP:
26945916cd2Sjpk (void) interpret_esp(flags, data, iplen,
27045916cd2Sjpk fraglen);
2717c478bd9Sstevel@tonic-gate break;
2727c478bd9Sstevel@tonic-gate case IPPROTO_AH:
27345916cd2Sjpk (void) interpret_ah(flags, data, iplen,
27445916cd2Sjpk fraglen);
2757c478bd9Sstevel@tonic-gate break;
2767c478bd9Sstevel@tonic-gate
2777c478bd9Sstevel@tonic-gate case IPPROTO_OSPF:
2787c478bd9Sstevel@tonic-gate interpret_ospf(flags, data, iplen, fraglen);
2797c478bd9Sstevel@tonic-gate break;
2807c478bd9Sstevel@tonic-gate
2817c478bd9Sstevel@tonic-gate case IPPROTO_EGP:
2827c478bd9Sstevel@tonic-gate case IPPROTO_PUP:
2837c478bd9Sstevel@tonic-gate break;
2847c478bd9Sstevel@tonic-gate case IPPROTO_UDP:
28545916cd2Sjpk (void) interpret_udp(flags,
28645916cd2Sjpk (struct udphdr *)data, iplen, fraglen);
2877c478bd9Sstevel@tonic-gate break;
2887c478bd9Sstevel@tonic-gate
2897c478bd9Sstevel@tonic-gate case IPPROTO_IDP:
2907c478bd9Sstevel@tonic-gate case IPPROTO_HELLO:
2917c478bd9Sstevel@tonic-gate case IPPROTO_ND:
2927c478bd9Sstevel@tonic-gate case IPPROTO_RAW:
2937c478bd9Sstevel@tonic-gate break;
2947c478bd9Sstevel@tonic-gate case IPPROTO_IPV6: /* IPV6 encap */
29545916cd2Sjpk /* LINTED: alignment */
2967c478bd9Sstevel@tonic-gate (void) interpret_ipv6(flags, (ip6_t *)data,
2977c478bd9Sstevel@tonic-gate iplen);
2987c478bd9Sstevel@tonic-gate break;
2997c478bd9Sstevel@tonic-gate case IPPROTO_SCTP:
30045916cd2Sjpk (void) interpret_sctp(flags,
30145916cd2Sjpk (struct sctp_hdr *)data, iplen, fraglen);
3027c478bd9Sstevel@tonic-gate break;
3037c478bd9Sstevel@tonic-gate }
3047c478bd9Sstevel@tonic-gate }
3057c478bd9Sstevel@tonic-gate }
3067c478bd9Sstevel@tonic-gate
3077c478bd9Sstevel@tonic-gate encap_levels--;
3087c478bd9Sstevel@tonic-gate return (iplen);
3097c478bd9Sstevel@tonic-gate }
3107c478bd9Sstevel@tonic-gate
3117c478bd9Sstevel@tonic-gate int
interpret_ipv6(int flags,const ip6_t * ip6h,int fraglen)31245916cd2Sjpk interpret_ipv6(int flags, const ip6_t *ip6h, int fraglen)
3137c478bd9Sstevel@tonic-gate {
3147c478bd9Sstevel@tonic-gate uint8_t *data;
3157c478bd9Sstevel@tonic-gate int hdrlen, iplen;
3167c478bd9Sstevel@tonic-gate int version, flow, class;
3177c478bd9Sstevel@tonic-gate uchar_t proto;
3187c478bd9Sstevel@tonic-gate boolean_t isfrag = B_FALSE;
3197c478bd9Sstevel@tonic-gate uint8_t extmask;
3207c478bd9Sstevel@tonic-gate /*
3217c478bd9Sstevel@tonic-gate * The print_srcname and print_dstname strings are the hostname
3227c478bd9Sstevel@tonic-gate * parts of the verbose IPv6 header output, including the comma
3237c478bd9Sstevel@tonic-gate * and the space after the litteral address strings.
3247c478bd9Sstevel@tonic-gate */
3257c478bd9Sstevel@tonic-gate char print_srcname[MAXHOSTNAMELEN + 2];
3267c478bd9Sstevel@tonic-gate char print_dstname[MAXHOSTNAMELEN + 2];
3277c478bd9Sstevel@tonic-gate char src_addrstr[INET6_ADDRSTRLEN];
3287c478bd9Sstevel@tonic-gate char dst_addrstr[INET6_ADDRSTRLEN];
3297c478bd9Sstevel@tonic-gate
3307c478bd9Sstevel@tonic-gate iplen = ntohs(ip6h->ip6_plen);
3317c478bd9Sstevel@tonic-gate hdrlen = IPV6_HDR_LEN;
3327c478bd9Sstevel@tonic-gate fraglen -= hdrlen;
3337c478bd9Sstevel@tonic-gate if (fraglen < 0)
3347c478bd9Sstevel@tonic-gate return (fraglen + hdrlen);
3357c478bd9Sstevel@tonic-gate data = ((uint8_t *)ip6h) + hdrlen;
3367c478bd9Sstevel@tonic-gate
3377c478bd9Sstevel@tonic-gate proto = ip6h->ip6_nxt;
3387c478bd9Sstevel@tonic-gate
3397c478bd9Sstevel@tonic-gate src_name = addrtoname(AF_INET6, &ip6h->ip6_src);
3407c478bd9Sstevel@tonic-gate dst_name = addrtoname(AF_INET6, &ip6h->ip6_dst);
3417c478bd9Sstevel@tonic-gate
3427c478bd9Sstevel@tonic-gate /*
3437c478bd9Sstevel@tonic-gate * Use endian-aware masks to extract traffic class and
3447c478bd9Sstevel@tonic-gate * flowinfo. Also, flowinfo is now 20 bits and class 8
3457c478bd9Sstevel@tonic-gate * rather than 24 and 4.
3467c478bd9Sstevel@tonic-gate */
3477c478bd9Sstevel@tonic-gate class = ntohl((ip6h->ip6_vcf & IPV6_FLOWINFO_TCLASS) >> 20);
3487c478bd9Sstevel@tonic-gate flow = ntohl(ip6h->ip6_vcf & IPV6_FLOWINFO_FLOWLABEL);
3497c478bd9Sstevel@tonic-gate
3507c478bd9Sstevel@tonic-gate /*
3517c478bd9Sstevel@tonic-gate * NOTE: the F_SUM and F_DTAIL flags are mutually exclusive,
3527c478bd9Sstevel@tonic-gate * so the code within the first part of the following if statement
3537c478bd9Sstevel@tonic-gate * will not affect the detailed printing of the packet.
3547c478bd9Sstevel@tonic-gate */
3557c478bd9Sstevel@tonic-gate if (flags & F_SUM) {
35645916cd2Sjpk (void) snprintf(get_sum_line(), MAXLINE,
35745916cd2Sjpk "IPv6 S=%s D=%s LEN=%d HOPS=%d CLASS=0x%x FLOW=0x%x",
3587c478bd9Sstevel@tonic-gate src_name, dst_name, iplen, ip6h->ip6_hops, class, flow);
3597c478bd9Sstevel@tonic-gate } else if (flags & F_DTAIL) {
3607c478bd9Sstevel@tonic-gate
3617c478bd9Sstevel@tonic-gate (void) inet_ntop(AF_INET6, &ip6h->ip6_src, src_addrstr,
3627c478bd9Sstevel@tonic-gate INET6_ADDRSTRLEN);
3637c478bd9Sstevel@tonic-gate (void) inet_ntop(AF_INET6, &ip6h->ip6_dst, dst_addrstr,
3647c478bd9Sstevel@tonic-gate INET6_ADDRSTRLEN);
3657c478bd9Sstevel@tonic-gate
3667c478bd9Sstevel@tonic-gate version = ntohl(ip6h->ip6_vcf) >> 28;
3677c478bd9Sstevel@tonic-gate
3682b24ab6bSSebastien Roy if (strcmp(src_name, src_addrstr) == 0) {
3697c478bd9Sstevel@tonic-gate print_srcname[0] = '\0';
3702b24ab6bSSebastien Roy } else {
3717c478bd9Sstevel@tonic-gate snprintf(print_srcname, sizeof (print_srcname),
3722b24ab6bSSebastien Roy ", %s", src_name);
3732b24ab6bSSebastien Roy }
3747c478bd9Sstevel@tonic-gate
3752b24ab6bSSebastien Roy if (strcmp(dst_name, dst_addrstr) == 0) {
3767c478bd9Sstevel@tonic-gate print_dstname[0] = '\0';
3772b24ab6bSSebastien Roy } else {
3787c478bd9Sstevel@tonic-gate snprintf(print_dstname, sizeof (print_dstname),
3792b24ab6bSSebastien Roy ", %s", dst_name);
3802b24ab6bSSebastien Roy }
3817c478bd9Sstevel@tonic-gate
3827c478bd9Sstevel@tonic-gate show_header("IPv6: ", "IPv6 Header", iplen);
3837c478bd9Sstevel@tonic-gate show_space();
3847c478bd9Sstevel@tonic-gate
38545916cd2Sjpk (void) snprintf(get_line(0, 0), get_line_remain(),
3867c478bd9Sstevel@tonic-gate "Version = %d", version);
38745916cd2Sjpk (void) snprintf(get_line(0, 0), get_line_remain(),
3887c478bd9Sstevel@tonic-gate "Traffic Class = %d", class);
38945916cd2Sjpk (void) snprintf(get_line(0, 0), get_line_remain(),
3907c478bd9Sstevel@tonic-gate "Flow label = 0x%x", flow);
39145916cd2Sjpk (void) snprintf(get_line(0, 0), get_line_remain(),
39245916cd2Sjpk "Payload length = %d", iplen);
39345916cd2Sjpk (void) snprintf(get_line(0, 0), get_line_remain(),
39445916cd2Sjpk "Next Header = %d (%s)", proto,
3957c478bd9Sstevel@tonic-gate getproto(proto));
39645916cd2Sjpk (void) snprintf(get_line(0, 0), get_line_remain(),
39745916cd2Sjpk "Hop Limit = %d", ip6h->ip6_hops);
39845916cd2Sjpk (void) snprintf(get_line(0, 0), get_line_remain(),
3997c478bd9Sstevel@tonic-gate "Source address = %s%s", src_addrstr, print_srcname);
40045916cd2Sjpk (void) snprintf(get_line(0, 0), get_line_remain(),
4017c478bd9Sstevel@tonic-gate "Destination address = %s%s", dst_addrstr, print_dstname);
4027c478bd9Sstevel@tonic-gate
4037c478bd9Sstevel@tonic-gate show_space();
4047c478bd9Sstevel@tonic-gate }
4057c478bd9Sstevel@tonic-gate
4067c478bd9Sstevel@tonic-gate /*
4077c478bd9Sstevel@tonic-gate * Print IPv6 Extension Headers, or skip them in the summary case.
4087c478bd9Sstevel@tonic-gate * Set isfrag to true if one of the extension headers encounterred
4097c478bd9Sstevel@tonic-gate * was a fragment header.
4107c478bd9Sstevel@tonic-gate */
4117c478bd9Sstevel@tonic-gate if (proto == IPPROTO_HOPOPTS || proto == IPPROTO_DSTOPTS ||
4127c478bd9Sstevel@tonic-gate proto == IPPROTO_ROUTING || proto == IPPROTO_FRAGMENT) {
4137c478bd9Sstevel@tonic-gate extmask = print_ipv6_extensions(flags, &data, &proto, &iplen,
4147c478bd9Sstevel@tonic-gate &fraglen);
4157c478bd9Sstevel@tonic-gate if ((extmask & SNOOP_FRAGMENT) != 0) {
4167c478bd9Sstevel@tonic-gate isfrag = B_TRUE;
4177c478bd9Sstevel@tonic-gate }
4187c478bd9Sstevel@tonic-gate }
4197c478bd9Sstevel@tonic-gate
4207c478bd9Sstevel@tonic-gate /*
4217c478bd9Sstevel@tonic-gate * We only want to print upper layer information if this is not
4227c478bd9Sstevel@tonic-gate * a fragment, or if we're printing in detail. Note that the
4237c478bd9Sstevel@tonic-gate * proto variable will be set to IPPROTO_NONE if this is a fragment
4247c478bd9Sstevel@tonic-gate * with a non-zero fragment offset.
4257c478bd9Sstevel@tonic-gate */
4267c478bd9Sstevel@tonic-gate if (!isfrag || flags & F_DTAIL) {
4277c478bd9Sstevel@tonic-gate /* go to the next protocol layer */
4287c478bd9Sstevel@tonic-gate
4297c478bd9Sstevel@tonic-gate switch (proto) {
4307c478bd9Sstevel@tonic-gate case IPPROTO_IP:
4317c478bd9Sstevel@tonic-gate break;
4327c478bd9Sstevel@tonic-gate case IPPROTO_ENCAP:
43345916cd2Sjpk /* LINTED: alignment */
43445916cd2Sjpk (void) interpret_ip(flags, (const struct ip *)data,
43545916cd2Sjpk fraglen);
4367c478bd9Sstevel@tonic-gate break;
4377c478bd9Sstevel@tonic-gate case IPPROTO_ICMPV6:
43845916cd2Sjpk /* LINTED: alignment */
43945916cd2Sjpk (void) interpret_icmpv6(flags, (icmp6_t *)data, iplen,
4407c478bd9Sstevel@tonic-gate fraglen);
4417c478bd9Sstevel@tonic-gate break;
4427c478bd9Sstevel@tonic-gate case IPPROTO_IGMP:
4437c478bd9Sstevel@tonic-gate interpret_igmp(flags, data, iplen, fraglen);
4447c478bd9Sstevel@tonic-gate break;
4457c478bd9Sstevel@tonic-gate case IPPROTO_GGP:
4467c478bd9Sstevel@tonic-gate break;
4477c478bd9Sstevel@tonic-gate case IPPROTO_TCP:
44845916cd2Sjpk (void) interpret_tcp(flags, (struct tcphdr *)data,
44945916cd2Sjpk iplen, fraglen);
4507c478bd9Sstevel@tonic-gate break;
4517c478bd9Sstevel@tonic-gate case IPPROTO_ESP:
45245916cd2Sjpk (void) interpret_esp(flags, data, iplen, fraglen);
4537c478bd9Sstevel@tonic-gate break;
4547c478bd9Sstevel@tonic-gate case IPPROTO_AH:
45545916cd2Sjpk (void) interpret_ah(flags, data, iplen, fraglen);
4567c478bd9Sstevel@tonic-gate break;
4577c478bd9Sstevel@tonic-gate case IPPROTO_EGP:
4587c478bd9Sstevel@tonic-gate case IPPROTO_PUP:
4597c478bd9Sstevel@tonic-gate break;
4607c478bd9Sstevel@tonic-gate case IPPROTO_UDP:
46145916cd2Sjpk (void) interpret_udp(flags, (struct udphdr *)data,
46245916cd2Sjpk iplen, fraglen);
4637c478bd9Sstevel@tonic-gate break;
4647c478bd9Sstevel@tonic-gate case IPPROTO_IDP:
4657c478bd9Sstevel@tonic-gate case IPPROTO_HELLO:
4667c478bd9Sstevel@tonic-gate case IPPROTO_ND:
4677c478bd9Sstevel@tonic-gate case IPPROTO_RAW:
4687c478bd9Sstevel@tonic-gate break;
4697c478bd9Sstevel@tonic-gate case IPPROTO_IPV6:
47045916cd2Sjpk /* LINTED: alignment */
47145916cd2Sjpk (void) interpret_ipv6(flags, (const ip6_t *)data,
47245916cd2Sjpk iplen);
4737c478bd9Sstevel@tonic-gate break;
4747c478bd9Sstevel@tonic-gate case IPPROTO_SCTP:
47545916cd2Sjpk (void) interpret_sctp(flags, (struct sctp_hdr *)data,
47645916cd2Sjpk iplen, fraglen);
4777c478bd9Sstevel@tonic-gate break;
4787c478bd9Sstevel@tonic-gate case IPPROTO_OSPF:
4797c478bd9Sstevel@tonic-gate interpret_ospf6(flags, data, iplen, fraglen);
4807c478bd9Sstevel@tonic-gate break;
4817c478bd9Sstevel@tonic-gate }
4827c478bd9Sstevel@tonic-gate }
4837c478bd9Sstevel@tonic-gate
4847c478bd9Sstevel@tonic-gate return (iplen);
4857c478bd9Sstevel@tonic-gate }
4867c478bd9Sstevel@tonic-gate
4877c478bd9Sstevel@tonic-gate /*
4887c478bd9Sstevel@tonic-gate * ip_ext: data including the extension header.
4897c478bd9Sstevel@tonic-gate * iplen: length of the data remaining in the packet.
4907c478bd9Sstevel@tonic-gate * Returns a mask of IPv6 extension headers it processed.
4917c478bd9Sstevel@tonic-gate */
4927c478bd9Sstevel@tonic-gate uint8_t
print_ipv6_extensions(int flags,uint8_t ** hdr,uint8_t * next,int * iplen,int * fraglen)4937c478bd9Sstevel@tonic-gate print_ipv6_extensions(int flags, uint8_t **hdr, uint8_t *next, int *iplen,
4947c478bd9Sstevel@tonic-gate int *fraglen)
4957c478bd9Sstevel@tonic-gate {
4967c478bd9Sstevel@tonic-gate uint8_t *data_ptr;
4977c478bd9Sstevel@tonic-gate uchar_t proto = *next;
4987c478bd9Sstevel@tonic-gate boolean_t is_extension_header;
4997c478bd9Sstevel@tonic-gate struct ip6_hbh *ipv6ext_hbh;
5007c478bd9Sstevel@tonic-gate struct ip6_dest *ipv6ext_dest;
5017c478bd9Sstevel@tonic-gate struct ip6_rthdr *ipv6ext_rthdr;
5027c478bd9Sstevel@tonic-gate struct ip6_frag *ipv6ext_frag;
5037c478bd9Sstevel@tonic-gate uint32_t exthdrlen;
5047c478bd9Sstevel@tonic-gate uint8_t extmask = 0;
5057c478bd9Sstevel@tonic-gate
5067c478bd9Sstevel@tonic-gate if ((hdr == NULL) || (*hdr == NULL) || (next == NULL) || (iplen == 0))
5077c478bd9Sstevel@tonic-gate return (0);
5087c478bd9Sstevel@tonic-gate
5097c478bd9Sstevel@tonic-gate data_ptr = *hdr;
5107c478bd9Sstevel@tonic-gate is_extension_header = B_TRUE;
5117c478bd9Sstevel@tonic-gate while (is_extension_header) {
5127c478bd9Sstevel@tonic-gate
5137c478bd9Sstevel@tonic-gate /*
5147c478bd9Sstevel@tonic-gate * There must be at least enough data left to read the
5157c478bd9Sstevel@tonic-gate * next header and header length fields from the next
5167c478bd9Sstevel@tonic-gate * header.
5177c478bd9Sstevel@tonic-gate */
5187c478bd9Sstevel@tonic-gate if (*fraglen < 2) {
5197c478bd9Sstevel@tonic-gate return (extmask);
5207c478bd9Sstevel@tonic-gate }
5217c478bd9Sstevel@tonic-gate
5227c478bd9Sstevel@tonic-gate switch (proto) {
5237c478bd9Sstevel@tonic-gate case IPPROTO_HOPOPTS:
5247c478bd9Sstevel@tonic-gate ipv6ext_hbh = (struct ip6_hbh *)data_ptr;
5257c478bd9Sstevel@tonic-gate exthdrlen = 8 + ipv6ext_hbh->ip6h_len * 8;
5267c478bd9Sstevel@tonic-gate if (*fraglen <= exthdrlen) {
5277c478bd9Sstevel@tonic-gate return (extmask);
5287c478bd9Sstevel@tonic-gate }
5297c478bd9Sstevel@tonic-gate prt_hbh_options(flags, ipv6ext_hbh);
5307c478bd9Sstevel@tonic-gate extmask |= SNOOP_HOPOPTS;
5317c478bd9Sstevel@tonic-gate proto = ipv6ext_hbh->ip6h_nxt;
5327c478bd9Sstevel@tonic-gate break;
5337c478bd9Sstevel@tonic-gate case IPPROTO_DSTOPTS:
5347c478bd9Sstevel@tonic-gate ipv6ext_dest = (struct ip6_dest *)data_ptr;
5357c478bd9Sstevel@tonic-gate exthdrlen = 8 + ipv6ext_dest->ip6d_len * 8;
5367c478bd9Sstevel@tonic-gate if (*fraglen <= exthdrlen) {
5377c478bd9Sstevel@tonic-gate return (extmask);
5387c478bd9Sstevel@tonic-gate }
5397c478bd9Sstevel@tonic-gate prt_dest_options(flags, ipv6ext_dest);
5407c478bd9Sstevel@tonic-gate extmask |= SNOOP_DSTOPTS;
5417c478bd9Sstevel@tonic-gate proto = ipv6ext_dest->ip6d_nxt;
5427c478bd9Sstevel@tonic-gate break;
5437c478bd9Sstevel@tonic-gate case IPPROTO_ROUTING:
5447c478bd9Sstevel@tonic-gate ipv6ext_rthdr = (struct ip6_rthdr *)data_ptr;
5457c478bd9Sstevel@tonic-gate exthdrlen = 8 + ipv6ext_rthdr->ip6r_len * 8;
5467c478bd9Sstevel@tonic-gate if (*fraglen <= exthdrlen) {
5477c478bd9Sstevel@tonic-gate return (extmask);
5487c478bd9Sstevel@tonic-gate }
5497c478bd9Sstevel@tonic-gate prt_routing_hdr(flags, ipv6ext_rthdr);
5507c478bd9Sstevel@tonic-gate extmask |= SNOOP_ROUTING;
5517c478bd9Sstevel@tonic-gate proto = ipv6ext_rthdr->ip6r_nxt;
5527c478bd9Sstevel@tonic-gate break;
5537c478bd9Sstevel@tonic-gate case IPPROTO_FRAGMENT:
55445916cd2Sjpk /* LINTED: alignment */
5557c478bd9Sstevel@tonic-gate ipv6ext_frag = (struct ip6_frag *)data_ptr;
5567c478bd9Sstevel@tonic-gate exthdrlen = sizeof (struct ip6_frag);
5577c478bd9Sstevel@tonic-gate if (*fraglen <= exthdrlen) {
5587c478bd9Sstevel@tonic-gate return (extmask);
5597c478bd9Sstevel@tonic-gate }
5607c478bd9Sstevel@tonic-gate prt_fragment_hdr(flags, ipv6ext_frag);
5617c478bd9Sstevel@tonic-gate extmask |= SNOOP_FRAGMENT;
5627c478bd9Sstevel@tonic-gate /*
5637c478bd9Sstevel@tonic-gate * If this is not the first fragment, forget about
5647c478bd9Sstevel@tonic-gate * the rest of the packet, snoop decoding is
5657c478bd9Sstevel@tonic-gate * stateless.
5667c478bd9Sstevel@tonic-gate */
5677c478bd9Sstevel@tonic-gate if ((ipv6ext_frag->ip6f_offlg & IP6F_OFF_MASK) != 0)
5687c478bd9Sstevel@tonic-gate proto = IPPROTO_NONE;
5697c478bd9Sstevel@tonic-gate else
5707c478bd9Sstevel@tonic-gate proto = ipv6ext_frag->ip6f_nxt;
5717c478bd9Sstevel@tonic-gate break;
5727c478bd9Sstevel@tonic-gate default:
5737c478bd9Sstevel@tonic-gate is_extension_header = B_FALSE;
5747c478bd9Sstevel@tonic-gate break;
5757c478bd9Sstevel@tonic-gate }
5767c478bd9Sstevel@tonic-gate
5777c478bd9Sstevel@tonic-gate if (is_extension_header) {
5787c478bd9Sstevel@tonic-gate *iplen -= exthdrlen;
5797c478bd9Sstevel@tonic-gate *fraglen -= exthdrlen;
5807c478bd9Sstevel@tonic-gate data_ptr += exthdrlen;
5817c478bd9Sstevel@tonic-gate }
5827c478bd9Sstevel@tonic-gate }
5837c478bd9Sstevel@tonic-gate
5847c478bd9Sstevel@tonic-gate *next = proto;
5857c478bd9Sstevel@tonic-gate *hdr = data_ptr;
5867c478bd9Sstevel@tonic-gate return (extmask);
5877c478bd9Sstevel@tonic-gate }
5887c478bd9Sstevel@tonic-gate
5897c478bd9Sstevel@tonic-gate static void
print_ipoptions(const uchar_t * opt,int optlen)59045916cd2Sjpk print_ipoptions(const uchar_t *opt, int optlen)
5917c478bd9Sstevel@tonic-gate {
5927c478bd9Sstevel@tonic-gate int len;
59345916cd2Sjpk int remain;
5947c478bd9Sstevel@tonic-gate char *line;
59545916cd2Sjpk const char *truncstr;
5967c478bd9Sstevel@tonic-gate
5977c478bd9Sstevel@tonic-gate if (optlen <= 0) {
59845916cd2Sjpk (void) snprintf(get_line(0, 0), get_line_remain(),
5997c478bd9Sstevel@tonic-gate "No options");
6007c478bd9Sstevel@tonic-gate return;
6017c478bd9Sstevel@tonic-gate }
6027c478bd9Sstevel@tonic-gate
60345916cd2Sjpk (void) snprintf(get_line(0, 0), get_line_remain(),
6047c478bd9Sstevel@tonic-gate "Options: (%d bytes)", optlen);
6057c478bd9Sstevel@tonic-gate
6067c478bd9Sstevel@tonic-gate while (optlen > 0) {
60745916cd2Sjpk line = get_line(0, 0);
60845916cd2Sjpk remain = get_line_remain();
6097c478bd9Sstevel@tonic-gate len = opt[1];
61045916cd2Sjpk truncstr = len > optlen ? "?" : "";
6117c478bd9Sstevel@tonic-gate switch (opt[0]) {
6127c478bd9Sstevel@tonic-gate case IPOPT_EOL:
61345916cd2Sjpk (void) strlcpy(line, " - End of option list", remain);
6147c478bd9Sstevel@tonic-gate return;
6157c478bd9Sstevel@tonic-gate case IPOPT_NOP:
61645916cd2Sjpk (void) strlcpy(line, " - No op", remain);
6177c478bd9Sstevel@tonic-gate len = 1;
6187c478bd9Sstevel@tonic-gate break;
6197c478bd9Sstevel@tonic-gate case IPOPT_RR:
62045916cd2Sjpk (void) snprintf(line, remain,
62145916cd2Sjpk " - Record route (%d bytes%s)", len, truncstr);
6227c478bd9Sstevel@tonic-gate print_route(opt);
6237c478bd9Sstevel@tonic-gate break;
6247c478bd9Sstevel@tonic-gate case IPOPT_TS:
62545916cd2Sjpk (void) snprintf(line, remain,
62645916cd2Sjpk " - Time stamp (%d bytes%s)", len, truncstr);
6277c478bd9Sstevel@tonic-gate break;
6287c478bd9Sstevel@tonic-gate case IPOPT_SECURITY:
62945916cd2Sjpk (void) snprintf(line, remain, " - RIPSO (%d bytes%s)",
63045916cd2Sjpk len, truncstr);
63145916cd2Sjpk print_ripso(opt);
63245916cd2Sjpk break;
63345916cd2Sjpk case IPOPT_COMSEC:
63445916cd2Sjpk (void) snprintf(line, remain, " - CIPSO (%d bytes%s)",
63545916cd2Sjpk len, truncstr);
63645916cd2Sjpk print_cipso(opt);
6377c478bd9Sstevel@tonic-gate break;
6387c478bd9Sstevel@tonic-gate case IPOPT_LSRR:
63945916cd2Sjpk (void) snprintf(line, remain,
64045916cd2Sjpk " - Loose source route (%d bytes%s)", len,
64145916cd2Sjpk truncstr);
6427c478bd9Sstevel@tonic-gate print_route(opt);
6437c478bd9Sstevel@tonic-gate break;
6447c478bd9Sstevel@tonic-gate case IPOPT_SATID:
64545916cd2Sjpk (void) snprintf(line, remain,
64645916cd2Sjpk " - SATNET Stream id (%d bytes%s)",
64745916cd2Sjpk len, truncstr);
6487c478bd9Sstevel@tonic-gate break;
6497c478bd9Sstevel@tonic-gate case IPOPT_SSRR:
65045916cd2Sjpk (void) snprintf(line, remain,
65145916cd2Sjpk " - Strict source route, (%d bytes%s)", len,
65245916cd2Sjpk truncstr);
6537c478bd9Sstevel@tonic-gate print_route(opt);
6547c478bd9Sstevel@tonic-gate break;
6557c478bd9Sstevel@tonic-gate default:
65645916cd2Sjpk (void) snprintf(line, remain,
65745916cd2Sjpk " - Option %d (unknown - %d bytes%s) %s",
65845916cd2Sjpk opt[0], len, truncstr,
65945916cd2Sjpk tohex((char *)&opt[2], len - 2));
6607c478bd9Sstevel@tonic-gate break;
6617c478bd9Sstevel@tonic-gate }
6627c478bd9Sstevel@tonic-gate if (len <= 0) {
66345916cd2Sjpk (void) snprintf(line, remain,
66445916cd2Sjpk " - Incomplete option len %d", len);
6657c478bd9Sstevel@tonic-gate break;
6667c478bd9Sstevel@tonic-gate }
6677c478bd9Sstevel@tonic-gate opt += len;
6687c478bd9Sstevel@tonic-gate optlen -= len;
6697c478bd9Sstevel@tonic-gate }
6707c478bd9Sstevel@tonic-gate }
6717c478bd9Sstevel@tonic-gate
6727c478bd9Sstevel@tonic-gate static void
print_route(const uchar_t * opt)67345916cd2Sjpk print_route(const uchar_t *opt)
6747c478bd9Sstevel@tonic-gate {
67545916cd2Sjpk int len, pointer, remain;
6767c478bd9Sstevel@tonic-gate struct in_addr addr;
6777c478bd9Sstevel@tonic-gate char *line;
6787c478bd9Sstevel@tonic-gate
6797c478bd9Sstevel@tonic-gate len = opt[1];
6807c478bd9Sstevel@tonic-gate pointer = opt[2];
6817c478bd9Sstevel@tonic-gate
68245916cd2Sjpk (void) snprintf(get_line(0, 0), get_line_remain(),
6837c478bd9Sstevel@tonic-gate " Pointer = %d", pointer);
6847c478bd9Sstevel@tonic-gate
6857c478bd9Sstevel@tonic-gate pointer -= IPOPT_MINOFF;
6867c478bd9Sstevel@tonic-gate opt += (IPOPT_OFFSET + 1);
6877c478bd9Sstevel@tonic-gate len -= (IPOPT_OFFSET + 1);
6887c478bd9Sstevel@tonic-gate
6897c478bd9Sstevel@tonic-gate while (len > 0) {
69045916cd2Sjpk line = get_line(0, 0);
69145916cd2Sjpk remain = get_line_remain();
6927c478bd9Sstevel@tonic-gate memcpy((char *)&addr, opt, sizeof (addr));
6937c478bd9Sstevel@tonic-gate if (addr.s_addr == INADDR_ANY)
69445916cd2Sjpk (void) strlcpy(line, " -", remain);
6957c478bd9Sstevel@tonic-gate else
69645916cd2Sjpk (void) snprintf(line, remain, " %s",
6977c478bd9Sstevel@tonic-gate addrtoname(AF_INET, &addr));
6987c478bd9Sstevel@tonic-gate if (pointer == 0)
69945916cd2Sjpk (void) strlcat(line, " <-- (current)", remain);
7007c478bd9Sstevel@tonic-gate
7017c478bd9Sstevel@tonic-gate opt += sizeof (addr);
7027c478bd9Sstevel@tonic-gate len -= sizeof (addr);
7037c478bd9Sstevel@tonic-gate pointer -= sizeof (addr);
7047c478bd9Sstevel@tonic-gate }
7057c478bd9Sstevel@tonic-gate }
7067c478bd9Sstevel@tonic-gate
7077c478bd9Sstevel@tonic-gate char *
getproto(int p)70845916cd2Sjpk getproto(int p)
7097c478bd9Sstevel@tonic-gate {
7107c478bd9Sstevel@tonic-gate switch (p) {
7117c478bd9Sstevel@tonic-gate case IPPROTO_HOPOPTS: return ("IPv6-HopOpts");
7127c478bd9Sstevel@tonic-gate case IPPROTO_IPV6: return ("IPv6");
7137c478bd9Sstevel@tonic-gate case IPPROTO_ROUTING: return ("IPv6-Route");
7147c478bd9Sstevel@tonic-gate case IPPROTO_FRAGMENT: return ("IPv6-Frag");
7157c478bd9Sstevel@tonic-gate case IPPROTO_RSVP: return ("RSVP");
7167c478bd9Sstevel@tonic-gate case IPPROTO_ENCAP: return ("IP-in-IP");
7177c478bd9Sstevel@tonic-gate case IPPROTO_AH: return ("AH");
7187c478bd9Sstevel@tonic-gate case IPPROTO_ESP: return ("ESP");
7197c478bd9Sstevel@tonic-gate case IPPROTO_ICMP: return ("ICMP");
7207c478bd9Sstevel@tonic-gate case IPPROTO_ICMPV6: return ("ICMPv6");
7217c478bd9Sstevel@tonic-gate case IPPROTO_DSTOPTS: return ("IPv6-DstOpts");
7227c478bd9Sstevel@tonic-gate case IPPROTO_IGMP: return ("IGMP");
7237c478bd9Sstevel@tonic-gate case IPPROTO_GGP: return ("GGP");
7247c478bd9Sstevel@tonic-gate case IPPROTO_TCP: return ("TCP");
7257c478bd9Sstevel@tonic-gate case IPPROTO_EGP: return ("EGP");
7267c478bd9Sstevel@tonic-gate case IPPROTO_PUP: return ("PUP");
7277c478bd9Sstevel@tonic-gate case IPPROTO_UDP: return ("UDP");
7287c478bd9Sstevel@tonic-gate case IPPROTO_IDP: return ("IDP");
7297c478bd9Sstevel@tonic-gate case IPPROTO_HELLO: return ("HELLO");
7307c478bd9Sstevel@tonic-gate case IPPROTO_ND: return ("ND");
7317c478bd9Sstevel@tonic-gate case IPPROTO_EON: return ("EON");
7327c478bd9Sstevel@tonic-gate case IPPROTO_RAW: return ("RAW");
7337c478bd9Sstevel@tonic-gate case IPPROTO_OSPF: return ("OSPF");
7347c478bd9Sstevel@tonic-gate default: return ("");
7357c478bd9Sstevel@tonic-gate }
7367c478bd9Sstevel@tonic-gate }
7377c478bd9Sstevel@tonic-gate
7387c478bd9Sstevel@tonic-gate static void
prt_routing_hdr(int flags,const struct ip6_rthdr * ipv6ext_rthdr)73945916cd2Sjpk prt_routing_hdr(int flags, const struct ip6_rthdr *ipv6ext_rthdr)
7407c478bd9Sstevel@tonic-gate {
7417c478bd9Sstevel@tonic-gate uint8_t nxt_hdr;
7427c478bd9Sstevel@tonic-gate uint8_t type;
7437c478bd9Sstevel@tonic-gate uint32_t len;
7447c478bd9Sstevel@tonic-gate uint8_t segleft;
7457c478bd9Sstevel@tonic-gate uint32_t numaddrs;
7467c478bd9Sstevel@tonic-gate int i;
7477c478bd9Sstevel@tonic-gate struct ip6_rthdr0 *ipv6ext_rthdr0;
7487c478bd9Sstevel@tonic-gate struct in6_addr *addrs;
7497c478bd9Sstevel@tonic-gate char addr[INET6_ADDRSTRLEN];
7507c478bd9Sstevel@tonic-gate
7517c478bd9Sstevel@tonic-gate /* in summary mode, we don't do anything. */
7527c478bd9Sstevel@tonic-gate if (flags & F_SUM) {
7537c478bd9Sstevel@tonic-gate return;
7547c478bd9Sstevel@tonic-gate }
7557c478bd9Sstevel@tonic-gate
7567c478bd9Sstevel@tonic-gate nxt_hdr = ipv6ext_rthdr->ip6r_nxt;
7577c478bd9Sstevel@tonic-gate type = ipv6ext_rthdr->ip6r_type;
7587c478bd9Sstevel@tonic-gate len = 8 * (ipv6ext_rthdr->ip6r_len + 1);
7597c478bd9Sstevel@tonic-gate segleft = ipv6ext_rthdr->ip6r_segleft;
7607c478bd9Sstevel@tonic-gate
7617c478bd9Sstevel@tonic-gate show_header("IPv6-Route: ", "IPv6 Routing Header", 0);
7627c478bd9Sstevel@tonic-gate show_space();
7637c478bd9Sstevel@tonic-gate
76445916cd2Sjpk (void) snprintf(get_line(0, 0), get_line_remain(),
7657c478bd9Sstevel@tonic-gate "Next header = %d (%s)", nxt_hdr, getproto(nxt_hdr));
76645916cd2Sjpk (void) snprintf(get_line(0, 0), get_line_remain(),
7677c478bd9Sstevel@tonic-gate "Header length = %d", len);
76845916cd2Sjpk (void) snprintf(get_line(0, 0), get_line_remain(),
7697c478bd9Sstevel@tonic-gate "Routing type = %d", type);
77045916cd2Sjpk (void) snprintf(get_line(0, 0), get_line_remain(),
7717c478bd9Sstevel@tonic-gate "Segments left = %d", segleft);
7727c478bd9Sstevel@tonic-gate
7737c478bd9Sstevel@tonic-gate if (type == IPV6_RTHDR_TYPE_0) {
7747c478bd9Sstevel@tonic-gate /*
7757c478bd9Sstevel@tonic-gate * XXX This loop will print all addresses in the routing header,
7767c478bd9Sstevel@tonic-gate * XXX not just the segments left.
7777c478bd9Sstevel@tonic-gate * XXX (The header length field is twice the number of
7787c478bd9Sstevel@tonic-gate * XXX addresses)
7797c478bd9Sstevel@tonic-gate * XXX At some future time, we may want to change this
7807c478bd9Sstevel@tonic-gate * XXX to differentiate between the hops yet to do
7817c478bd9Sstevel@tonic-gate * XXX and the hops already taken.
7827c478bd9Sstevel@tonic-gate */
78345916cd2Sjpk /* LINTED: alignment */
7847c478bd9Sstevel@tonic-gate ipv6ext_rthdr0 = (struct ip6_rthdr0 *)ipv6ext_rthdr;
7857c478bd9Sstevel@tonic-gate numaddrs = ipv6ext_rthdr0->ip6r0_len / 2;
7867c478bd9Sstevel@tonic-gate addrs = (struct in6_addr *)(ipv6ext_rthdr0 + 1);
7877c478bd9Sstevel@tonic-gate for (i = 0; i < numaddrs; i++) {
7887c478bd9Sstevel@tonic-gate (void) inet_ntop(AF_INET6, &addrs[i], addr,
7897c478bd9Sstevel@tonic-gate INET6_ADDRSTRLEN);
79045916cd2Sjpk (void) snprintf(get_line(0, 0), get_line_remain(),
7917c478bd9Sstevel@tonic-gate "address[%d]=%s", i, addr);
7927c478bd9Sstevel@tonic-gate }
7937c478bd9Sstevel@tonic-gate }
7947c478bd9Sstevel@tonic-gate
7957c478bd9Sstevel@tonic-gate show_space();
7967c478bd9Sstevel@tonic-gate }
7977c478bd9Sstevel@tonic-gate
7987c478bd9Sstevel@tonic-gate static void
prt_fragment_hdr(int flags,const struct ip6_frag * ipv6ext_frag)79945916cd2Sjpk prt_fragment_hdr(int flags, const struct ip6_frag *ipv6ext_frag)
8007c478bd9Sstevel@tonic-gate {
8017c478bd9Sstevel@tonic-gate boolean_t morefrag;
8027c478bd9Sstevel@tonic-gate uint16_t fragoffset;
8037c478bd9Sstevel@tonic-gate uint8_t nxt_hdr;
8047c478bd9Sstevel@tonic-gate uint32_t fragident;
8057c478bd9Sstevel@tonic-gate
8067c478bd9Sstevel@tonic-gate /* extract the various fields from the fragment header */
8077c478bd9Sstevel@tonic-gate nxt_hdr = ipv6ext_frag->ip6f_nxt;
8087c478bd9Sstevel@tonic-gate morefrag = (ipv6ext_frag->ip6f_offlg & IP6F_MORE_FRAG) == 0
8097c478bd9Sstevel@tonic-gate ? B_FALSE : B_TRUE;
8107c478bd9Sstevel@tonic-gate fragoffset = ntohs(ipv6ext_frag->ip6f_offlg & IP6F_OFF_MASK);
8117c478bd9Sstevel@tonic-gate fragident = ntohl(ipv6ext_frag->ip6f_ident);
8127c478bd9Sstevel@tonic-gate
8137c478bd9Sstevel@tonic-gate if (flags & F_SUM) {
81445916cd2Sjpk (void) snprintf(get_sum_line(), MAXLINE,
8155086f56fSPaul Wernau "IPv6 fragment ID=%u Offset=%-4d MF=%d",
8167c478bd9Sstevel@tonic-gate fragident,
8177c478bd9Sstevel@tonic-gate fragoffset,
8187c478bd9Sstevel@tonic-gate morefrag);
8197c478bd9Sstevel@tonic-gate } else { /* F_DTAIL */
8207c478bd9Sstevel@tonic-gate show_header("IPv6-Frag: ", "IPv6 Fragment Header", 0);
8217c478bd9Sstevel@tonic-gate show_space();
8227c478bd9Sstevel@tonic-gate
82345916cd2Sjpk (void) snprintf(get_line(0, 0), get_line_remain(),
8247c478bd9Sstevel@tonic-gate "Next Header = %d (%s)", nxt_hdr, getproto(nxt_hdr));
82545916cd2Sjpk (void) snprintf(get_line(0, 0), get_line_remain(),
8267c478bd9Sstevel@tonic-gate "Fragment Offset = %d", fragoffset);
82745916cd2Sjpk (void) snprintf(get_line(0, 0), get_line_remain(),
8287c478bd9Sstevel@tonic-gate "More Fragments Flag = %s", morefrag ? "true" : "false");
82945916cd2Sjpk (void) snprintf(get_line(0, 0), get_line_remain(),
8305086f56fSPaul Wernau "Identification = %u", fragident);
8317c478bd9Sstevel@tonic-gate
8327c478bd9Sstevel@tonic-gate show_space();
8337c478bd9Sstevel@tonic-gate }
8347c478bd9Sstevel@tonic-gate }
8357c478bd9Sstevel@tonic-gate
8367c478bd9Sstevel@tonic-gate static void
print_ip6opt_ls(const uchar_t * data,unsigned int op_len)83745916cd2Sjpk print_ip6opt_ls(const uchar_t *data, unsigned int op_len)
8387c478bd9Sstevel@tonic-gate {
83945916cd2Sjpk uint32_t doi;
84045916cd2Sjpk uint8_t sotype, solen;
84145916cd2Sjpk uint16_t value, value2;
84245916cd2Sjpk char *cp;
84345916cd2Sjpk int remlen;
84445916cd2Sjpk boolean_t printed;
84545916cd2Sjpk
84645916cd2Sjpk (void) snprintf(get_line(0, 0), get_line_remain(),
84745916cd2Sjpk "Labeled Security Option len = %u bytes%s", op_len,
84845916cd2Sjpk op_len < sizeof (uint32_t) || (op_len & 1) != 0 ? "?" : "");
84945916cd2Sjpk if (op_len < sizeof (uint32_t))
85045916cd2Sjpk return;
85145916cd2Sjpk GETINT32(doi, data);
85245916cd2Sjpk (void) snprintf(get_line(0, 0), get_line_remain(),
85345916cd2Sjpk " DOI = %d (%s)", doi, doi == IP6LS_DOI_V4 ? "IPv4" : "???");
85445916cd2Sjpk op_len -= sizeof (uint32_t);
85545916cd2Sjpk while (op_len > 0) {
85645916cd2Sjpk GETINT8(sotype, data);
85745916cd2Sjpk if (op_len < 2) {
85845916cd2Sjpk (void) snprintf(get_line(0, 0), get_line_remain(),
85945916cd2Sjpk " truncated %u suboption (no len)", sotype);
86045916cd2Sjpk break;
86145916cd2Sjpk }
86245916cd2Sjpk GETINT8(solen, data);
86345916cd2Sjpk if (solen < 2 || solen > op_len) {
86445916cd2Sjpk (void) snprintf(get_line(0, 0), get_line_remain(),
86545916cd2Sjpk " bad %u suboption (len 2 <= %u <= %u)",
86645916cd2Sjpk sotype, solen, op_len);
86745916cd2Sjpk if (solen < 2)
86845916cd2Sjpk solen = 2;
86945916cd2Sjpk if (solen > op_len)
87045916cd2Sjpk solen = op_len;
87145916cd2Sjpk }
87245916cd2Sjpk op_len -= solen;
87345916cd2Sjpk solen -= 2;
87445916cd2Sjpk cp = get_line(0, 0);
87545916cd2Sjpk remlen = get_line_remain();
87645916cd2Sjpk (void) strlcpy(cp, " ", remlen);
87745916cd2Sjpk cp += 4;
87845916cd2Sjpk remlen -= 4;
87945916cd2Sjpk printed = B_TRUE;
88045916cd2Sjpk switch (sotype) {
88145916cd2Sjpk case IP6LS_TT_LEVEL:
88245916cd2Sjpk if (solen != 2) {
88345916cd2Sjpk printed = B_FALSE;
88445916cd2Sjpk break;
88545916cd2Sjpk }
88645916cd2Sjpk GETINT16(value, data);
88745916cd2Sjpk (void) snprintf(cp, remlen, "Level %u", value);
88845916cd2Sjpk solen = 0;
88945916cd2Sjpk break;
89045916cd2Sjpk case IP6LS_TT_VECTOR:
89145916cd2Sjpk (void) strlcpy(cp, "Bit-Vector: ", remlen);
89245916cd2Sjpk remlen -= strlen(cp);
89345916cd2Sjpk cp += strlen(cp);
89445916cd2Sjpk while (solen > 1) {
89545916cd2Sjpk GETINT16(value, data);
89645916cd2Sjpk solen -= 2;
89745916cd2Sjpk (void) snprintf(cp, remlen, "%04x", value);
89845916cd2Sjpk remlen -= strlen(cp);
89945916cd2Sjpk cp += strlen(cp);
90045916cd2Sjpk }
90145916cd2Sjpk break;
90245916cd2Sjpk case IP6LS_TT_ENUM:
90345916cd2Sjpk (void) strlcpy(cp, "Enumeration:", remlen);
90445916cd2Sjpk remlen -= strlen(cp);
90545916cd2Sjpk cp += strlen(cp);
90645916cd2Sjpk while (solen > 1) {
90745916cd2Sjpk GETINT16(value, data);
90845916cd2Sjpk solen -= 2;
90945916cd2Sjpk (void) snprintf(cp, remlen, " %u", value);
91045916cd2Sjpk remlen -= strlen(cp);
91145916cd2Sjpk cp += strlen(cp);
91245916cd2Sjpk }
91345916cd2Sjpk break;
91445916cd2Sjpk case IP6LS_TT_RANGES:
91545916cd2Sjpk (void) strlcpy(cp, "Ranges:", remlen);
91645916cd2Sjpk remlen -= strlen(cp);
91745916cd2Sjpk cp += strlen(cp);
91845916cd2Sjpk while (solen > 3) {
91945916cd2Sjpk GETINT16(value, data);
92045916cd2Sjpk GETINT16(value2, data);
92145916cd2Sjpk solen -= 4;
92245916cd2Sjpk (void) snprintf(cp, remlen, " %u-%u", value,
92345916cd2Sjpk value2);
92445916cd2Sjpk remlen -= strlen(cp);
92545916cd2Sjpk cp += strlen(cp);
92645916cd2Sjpk }
92745916cd2Sjpk break;
92845916cd2Sjpk case IP6LS_TT_V4:
92945916cd2Sjpk (void) strlcpy(cp, "IPv4 Option", remlen);
93045916cd2Sjpk print_ipoptions(data, solen);
93145916cd2Sjpk solen = 0;
93245916cd2Sjpk break;
93345916cd2Sjpk case IP6LS_TT_DEST:
93445916cd2Sjpk (void) snprintf(cp, remlen,
93545916cd2Sjpk "Destination-Only Data length %u", solen);
93645916cd2Sjpk solen = 0;
93745916cd2Sjpk break;
93845916cd2Sjpk default:
93945916cd2Sjpk (void) snprintf(cp, remlen,
94045916cd2Sjpk " unknown %u suboption (len %u)", sotype, solen);
94145916cd2Sjpk solen = 0;
94245916cd2Sjpk break;
94345916cd2Sjpk }
94445916cd2Sjpk if (solen != 0) {
94545916cd2Sjpk if (printed) {
94645916cd2Sjpk cp = get_line(0, 0);
94745916cd2Sjpk remlen = get_line_remain();
94845916cd2Sjpk }
94945916cd2Sjpk (void) snprintf(cp, remlen,
95045916cd2Sjpk " malformed %u suboption (remaining %u)",
95145916cd2Sjpk sotype, solen);
95245916cd2Sjpk data += solen;
95345916cd2Sjpk }
95445916cd2Sjpk }
95545916cd2Sjpk }
95645916cd2Sjpk
95745916cd2Sjpk static void
prt_hbh_options(int flags,const struct ip6_hbh * ipv6ext_hbh)95845916cd2Sjpk prt_hbh_options(int flags, const struct ip6_hbh *ipv6ext_hbh)
95945916cd2Sjpk {
96045916cd2Sjpk const uint8_t *data, *ndata;
96145916cd2Sjpk uint32_t len;
9627c478bd9Sstevel@tonic-gate uint8_t op_type;
9637c478bd9Sstevel@tonic-gate uint8_t op_len;
9647c478bd9Sstevel@tonic-gate uint8_t nxt_hdr;
9657c478bd9Sstevel@tonic-gate
9667c478bd9Sstevel@tonic-gate /* in summary mode, we don't do anything. */
9677c478bd9Sstevel@tonic-gate if (flags & F_SUM) {
9687c478bd9Sstevel@tonic-gate return;
9697c478bd9Sstevel@tonic-gate }
9707c478bd9Sstevel@tonic-gate
9717c478bd9Sstevel@tonic-gate show_header("IPv6-HopOpts: ", "IPv6 Hop-by-Hop Options Header", 0);
9727c478bd9Sstevel@tonic-gate show_space();
9737c478bd9Sstevel@tonic-gate
9747c478bd9Sstevel@tonic-gate /*
9757c478bd9Sstevel@tonic-gate * Store the lengh of this ext hdr in bytes. The caller has
9767c478bd9Sstevel@tonic-gate * ensured that there is at least len bytes of data left.
9777c478bd9Sstevel@tonic-gate */
9787c478bd9Sstevel@tonic-gate len = ipv6ext_hbh->ip6h_len * 8 + 8;
9797c478bd9Sstevel@tonic-gate
98045916cd2Sjpk ndata = (const uint8_t *)ipv6ext_hbh + 2;
9817c478bd9Sstevel@tonic-gate len -= 2;
9827c478bd9Sstevel@tonic-gate
9837c478bd9Sstevel@tonic-gate nxt_hdr = ipv6ext_hbh->ip6h_nxt;
98445916cd2Sjpk (void) snprintf(get_line(0, 0), get_line_remain(),
9857c478bd9Sstevel@tonic-gate "Next Header = %u (%s)", nxt_hdr, getproto(nxt_hdr));
9867c478bd9Sstevel@tonic-gate
9877c478bd9Sstevel@tonic-gate while (len > 0) {
98845916cd2Sjpk data = ndata;
9897c478bd9Sstevel@tonic-gate GETINT8(op_type, data);
99045916cd2Sjpk /* This is the only one-octet IPv6 option */
99145916cd2Sjpk if (op_type == IP6OPT_PAD1) {
99245916cd2Sjpk (void) snprintf(get_line(0, 0), get_line_remain(),
9937c478bd9Sstevel@tonic-gate "pad1 option ");
9947c478bd9Sstevel@tonic-gate len--;
99545916cd2Sjpk ndata = data;
99645916cd2Sjpk continue;
99745916cd2Sjpk }
99845916cd2Sjpk GETINT8(op_len, data);
99945916cd2Sjpk if (len < 2 || op_len + 2 > len) {
100045916cd2Sjpk (void) snprintf(get_line(0, 0), get_line_remain(),
100145916cd2Sjpk "Error: option %u truncated (%u + 2 > %u)",
100245916cd2Sjpk op_type, op_len, len);
100345916cd2Sjpk op_len = len - 2;
100445916cd2Sjpk /*
100545916cd2Sjpk * Continue processing the malformed option so that we
100645916cd2Sjpk * can display as much as possible.
100745916cd2Sjpk */
100845916cd2Sjpk }
100945916cd2Sjpk
101045916cd2Sjpk /* advance pointers to the next option */
101145916cd2Sjpk len -= op_len + 2;
101245916cd2Sjpk ndata = data + op_len;
101345916cd2Sjpk
101445916cd2Sjpk /* process this option */
101545916cd2Sjpk switch (op_type) {
10167c478bd9Sstevel@tonic-gate case IP6OPT_PADN:
101745916cd2Sjpk (void) snprintf(get_line(0, 0), get_line_remain(),
10187c478bd9Sstevel@tonic-gate "padN option len = %u", op_len);
10197c478bd9Sstevel@tonic-gate break;
10207c478bd9Sstevel@tonic-gate case IP6OPT_JUMBO: {
10217c478bd9Sstevel@tonic-gate uint32_t payload_len;
10227c478bd9Sstevel@tonic-gate
102345916cd2Sjpk (void) snprintf(get_line(0, 0), get_line_remain(),
102445916cd2Sjpk "Jumbo Payload Option len = %u bytes%s", op_len,
102545916cd2Sjpk op_len == sizeof (uint32_t) ? "" : "?");
10267c478bd9Sstevel@tonic-gate if (op_len == sizeof (uint32_t)) {
10277c478bd9Sstevel@tonic-gate GETINT32(payload_len, data);
102845916cd2Sjpk (void) snprintf(get_line(0, 0),
102945916cd2Sjpk get_line_remain(),
10307c478bd9Sstevel@tonic-gate "Jumbo Payload Length = %u bytes",
10317c478bd9Sstevel@tonic-gate payload_len);
10327c478bd9Sstevel@tonic-gate }
10337c478bd9Sstevel@tonic-gate break;
10347c478bd9Sstevel@tonic-gate }
10357c478bd9Sstevel@tonic-gate case IP6OPT_ROUTER_ALERT: {
10367c478bd9Sstevel@tonic-gate uint16_t value;
10377c478bd9Sstevel@tonic-gate const char *label[] = {"MLD", "RSVP", "AN"};
10387c478bd9Sstevel@tonic-gate
103945916cd2Sjpk (void) snprintf(get_line(0, 0), get_line_remain(),
104045916cd2Sjpk "Router Alert Option len = %u bytes%s", op_len,
104145916cd2Sjpk op_len == sizeof (uint16_t) ? "" : "?");
10427c478bd9Sstevel@tonic-gate if (op_len == sizeof (uint16_t)) {
10437c478bd9Sstevel@tonic-gate GETINT16(value, data);
104445916cd2Sjpk (void) snprintf(get_line(0, 0),
104545916cd2Sjpk get_line_remain(),
10467c478bd9Sstevel@tonic-gate "Alert Type = %d (%s)", value,
10477c478bd9Sstevel@tonic-gate value < sizeof (label) / sizeof (label[0]) ?
10487c478bd9Sstevel@tonic-gate label[value] : "???");
10497c478bd9Sstevel@tonic-gate }
10507c478bd9Sstevel@tonic-gate break;
10517c478bd9Sstevel@tonic-gate }
105245916cd2Sjpk case IP6OPT_LS:
105345916cd2Sjpk print_ip6opt_ls(data, op_len);
105445916cd2Sjpk break;
10557c478bd9Sstevel@tonic-gate default:
105645916cd2Sjpk (void) snprintf(get_line(0, 0), get_line_remain(),
10577c478bd9Sstevel@tonic-gate "Option type = %u, len = %u", op_type, op_len);
10587c478bd9Sstevel@tonic-gate break;
10597c478bd9Sstevel@tonic-gate }
10607c478bd9Sstevel@tonic-gate }
10617c478bd9Sstevel@tonic-gate
10627c478bd9Sstevel@tonic-gate show_space();
10637c478bd9Sstevel@tonic-gate }
10647c478bd9Sstevel@tonic-gate
10657c478bd9Sstevel@tonic-gate static void
prt_dest_options(int flags,const struct ip6_dest * ipv6ext_dest)106645916cd2Sjpk prt_dest_options(int flags, const struct ip6_dest *ipv6ext_dest)
10677c478bd9Sstevel@tonic-gate {
106845916cd2Sjpk const uint8_t *data, *ndata;
106945916cd2Sjpk uint32_t len;
10707c478bd9Sstevel@tonic-gate uint8_t op_type;
10717c478bd9Sstevel@tonic-gate uint32_t op_len;
10727c478bd9Sstevel@tonic-gate uint8_t nxt_hdr;
10737c478bd9Sstevel@tonic-gate uint8_t value;
10747c478bd9Sstevel@tonic-gate
10757c478bd9Sstevel@tonic-gate /* in summary mode, we don't do anything. */
10767c478bd9Sstevel@tonic-gate if (flags & F_SUM) {
10777c478bd9Sstevel@tonic-gate return;
10787c478bd9Sstevel@tonic-gate }
10797c478bd9Sstevel@tonic-gate
10807c478bd9Sstevel@tonic-gate show_header("IPv6-DstOpts: ", "IPv6 Destination Options Header", 0);
10817c478bd9Sstevel@tonic-gate show_space();
10827c478bd9Sstevel@tonic-gate
10837c478bd9Sstevel@tonic-gate /*
10847c478bd9Sstevel@tonic-gate * Store the length of this ext hdr in bytes. The caller has
10857c478bd9Sstevel@tonic-gate * ensured that there is at least len bytes of data left.
10867c478bd9Sstevel@tonic-gate */
10877c478bd9Sstevel@tonic-gate len = ipv6ext_dest->ip6d_len * 8 + 8;
10887c478bd9Sstevel@tonic-gate
108945916cd2Sjpk ndata = (const uint8_t *)ipv6ext_dest + 2; /* skip hdr/len */
10907c478bd9Sstevel@tonic-gate len -= 2;
10917c478bd9Sstevel@tonic-gate
10927c478bd9Sstevel@tonic-gate nxt_hdr = ipv6ext_dest->ip6d_nxt;
109345916cd2Sjpk (void) snprintf(get_line(0, 0), get_line_remain(),
10947c478bd9Sstevel@tonic-gate "Next Header = %u (%s)", nxt_hdr, getproto(nxt_hdr));
10957c478bd9Sstevel@tonic-gate
10967c478bd9Sstevel@tonic-gate while (len > 0) {
109745916cd2Sjpk data = ndata;
10987c478bd9Sstevel@tonic-gate GETINT8(op_type, data);
109945916cd2Sjpk if (op_type == IP6OPT_PAD1) {
110045916cd2Sjpk (void) snprintf(get_line(0, 0), get_line_remain(),
11017c478bd9Sstevel@tonic-gate "pad1 option ");
11027c478bd9Sstevel@tonic-gate len--;
110345916cd2Sjpk ndata = data;
110445916cd2Sjpk continue;
110545916cd2Sjpk }
110645916cd2Sjpk GETINT8(op_len, data);
110745916cd2Sjpk if (len < 2 || op_len + 2 > len) {
110845916cd2Sjpk (void) snprintf(get_line(0, 0), get_line_remain(),
110945916cd2Sjpk "Error: option %u truncated (%u + 2 > %u)",
111045916cd2Sjpk op_type, op_len, len);
111145916cd2Sjpk op_len = len - 2;
111245916cd2Sjpk /*
111345916cd2Sjpk * Continue processing the malformed option so that we
111445916cd2Sjpk * can display as much as possible.
111545916cd2Sjpk */
111645916cd2Sjpk }
111745916cd2Sjpk
111845916cd2Sjpk /* advance pointers to the next option */
111945916cd2Sjpk len -= op_len + 2;
112045916cd2Sjpk ndata = data + op_len;
112145916cd2Sjpk
112245916cd2Sjpk /* process this option */
112345916cd2Sjpk switch (op_type) {
11247c478bd9Sstevel@tonic-gate case IP6OPT_PADN:
112545916cd2Sjpk (void) snprintf(get_line(0, 0), get_line_remain(),
11267c478bd9Sstevel@tonic-gate "padN option len = %u", op_len);
11277c478bd9Sstevel@tonic-gate break;
11287c478bd9Sstevel@tonic-gate case IP6OPT_TUNNEL_LIMIT:
11297c478bd9Sstevel@tonic-gate GETINT8(value, data);
113045916cd2Sjpk (void) snprintf(get_line(0, 0), get_line_remain(),
11317c478bd9Sstevel@tonic-gate "tunnel encapsulation limit len = %d, value = %d",
11327c478bd9Sstevel@tonic-gate op_len, value);
113345916cd2Sjpk break;
113445916cd2Sjpk case IP6OPT_LS:
113545916cd2Sjpk print_ip6opt_ls(data, op_len);
11367c478bd9Sstevel@tonic-gate break;
11377c478bd9Sstevel@tonic-gate default:
113845916cd2Sjpk (void) snprintf(get_line(0, 0), get_line_remain(),
11397c478bd9Sstevel@tonic-gate "Option type = %u, len = %u", op_type, op_len);
114045916cd2Sjpk break;
114145916cd2Sjpk }
114245916cd2Sjpk }
114345916cd2Sjpk
114445916cd2Sjpk show_space();
114545916cd2Sjpk }
114645916cd2Sjpk
114745916cd2Sjpk #define ALABEL_MAXLEN 256
114845916cd2Sjpk
114945916cd2Sjpk static char ascii_label[ALABEL_MAXLEN];
115045916cd2Sjpk static char *plabel = ascii_label;
115145916cd2Sjpk
115245916cd2Sjpk struct snoop_pair {
115345916cd2Sjpk int val;
115445916cd2Sjpk const char *name;
115545916cd2Sjpk };
115645916cd2Sjpk
115745916cd2Sjpk static struct snoop_pair ripso_class_tbl[] = {
115845916cd2Sjpk TSOL_CL_TOP_SECRET, "TOP SECRET",
115945916cd2Sjpk TSOL_CL_SECRET, "SECRET",
116045916cd2Sjpk TSOL_CL_CONFIDENTIAL, "CONFIDENTIAL",
116145916cd2Sjpk TSOL_CL_UNCLASSIFIED, "UNCLASSIFIED",
116245916cd2Sjpk -1, NULL
116345916cd2Sjpk };
116445916cd2Sjpk
116545916cd2Sjpk static struct snoop_pair ripso_prot_tbl[] = {
116645916cd2Sjpk TSOL_PA_GENSER, "GENSER",
116745916cd2Sjpk TSOL_PA_SIOP_ESI, "SIOP-ESI",
116845916cd2Sjpk TSOL_PA_SCI, "SCI",
116945916cd2Sjpk TSOL_PA_NSA, "NSA",
117045916cd2Sjpk TSOL_PA_DOE, "DOE",
117145916cd2Sjpk 0x04, "UNASSIGNED",
117245916cd2Sjpk 0x02, "UNASSIGNED",
117345916cd2Sjpk -1, NULL
117445916cd2Sjpk };
117545916cd2Sjpk
117645916cd2Sjpk static struct snoop_pair *
get_pair_byval(struct snoop_pair pairlist[],int val)117745916cd2Sjpk get_pair_byval(struct snoop_pair pairlist[], int val)
117845916cd2Sjpk {
117945916cd2Sjpk int i;
118045916cd2Sjpk
118145916cd2Sjpk for (i = 0; pairlist[i].name != NULL; i++)
118245916cd2Sjpk if (pairlist[i].val == val)
118345916cd2Sjpk return (&pairlist[i]);
118445916cd2Sjpk return (NULL);
118545916cd2Sjpk }
118645916cd2Sjpk
118745916cd2Sjpk static void
print_ripso(const uchar_t * opt)118845916cd2Sjpk print_ripso(const uchar_t *opt)
118945916cd2Sjpk {
119045916cd2Sjpk struct snoop_pair *ripso_class;
119145916cd2Sjpk int i, index, prot_len;
119245916cd2Sjpk boolean_t first_prot;
119345916cd2Sjpk char line[100], *ptr;
119445916cd2Sjpk
119545916cd2Sjpk prot_len = opt[1] - 3;
119645916cd2Sjpk if (prot_len < 0)
119745916cd2Sjpk return;
119845916cd2Sjpk
119945916cd2Sjpk show_header("RIPSO: ", "Revised IP Security Option", 0);
120045916cd2Sjpk show_space();
120145916cd2Sjpk
120245916cd2Sjpk (void) snprintf(get_line(0, 0), get_line_remain(),
120345916cd2Sjpk "Type = Basic Security Option (%d), Length = %d", opt[0], opt[1]);
120445916cd2Sjpk
120545916cd2Sjpk /*
120645916cd2Sjpk * Display Classification Level
120745916cd2Sjpk */
120845916cd2Sjpk ripso_class = get_pair_byval(ripso_class_tbl, (int)opt[2]);
1209*7d897698SMilan Jurik if (ripso_class == NULL)
121045916cd2Sjpk (void) snprintf(get_line(0, 0), get_line_remain(),
121145916cd2Sjpk "Classification = Unknown (0x%02x)", opt[2]);
121245916cd2Sjpk else
121345916cd2Sjpk (void) snprintf(get_line(0, 0), get_line_remain(),
121445916cd2Sjpk "Classification = %s (0x%02x)",
121545916cd2Sjpk ripso_class->name, ripso_class->val);
121645916cd2Sjpk
121745916cd2Sjpk /*
121845916cd2Sjpk * Display Protection Authority Flags
121945916cd2Sjpk */
122045916cd2Sjpk (void) snprintf(line, sizeof (line), "Protection Authority = ");
122145916cd2Sjpk ptr = line;
122245916cd2Sjpk first_prot = B_TRUE;
122345916cd2Sjpk for (i = 0; i < prot_len; i++) {
122445916cd2Sjpk index = 0;
122545916cd2Sjpk while (ripso_prot_tbl[index].name != NULL) {
122645916cd2Sjpk if (opt[3 + i] & ripso_prot_tbl[index].val) {
122745916cd2Sjpk ptr = strchr(ptr, 0);
122845916cd2Sjpk if (!first_prot) {
122945916cd2Sjpk (void) strlcpy(ptr, ", ",
123045916cd2Sjpk sizeof (line) - (ptr - line));
123145916cd2Sjpk ptr = strchr(ptr, 0);
123245916cd2Sjpk }
123345916cd2Sjpk (void) snprintf(ptr,
123445916cd2Sjpk sizeof (line) - (ptr - line),
123545916cd2Sjpk "%s (0x%02x)",
123645916cd2Sjpk ripso_prot_tbl[index].name,
123745916cd2Sjpk ripso_prot_tbl[index].val);
123845916cd2Sjpk }
123945916cd2Sjpk index++;
12407c478bd9Sstevel@tonic-gate }
124145916cd2Sjpk if ((opt[3 + i] & 1) == 0)
12427c478bd9Sstevel@tonic-gate break;
124345916cd2Sjpk }
124445916cd2Sjpk if (!first_prot)
124545916cd2Sjpk (void) snprintf(get_line(0, 0), get_line_remain(), "%s", line);
124645916cd2Sjpk else
124745916cd2Sjpk (void) snprintf(get_line(0, 0), get_line_remain(), "%sNone",
124845916cd2Sjpk line);
124945916cd2Sjpk }
125045916cd2Sjpk
125145916cd2Sjpk #define CIPSO_GENERIC_ARRAY_LEN 200
125245916cd2Sjpk
125345916cd2Sjpk /*
125445916cd2Sjpk * Return 1 if CIPSO SL and Categories are all 1's; 0 otherwise.
125545916cd2Sjpk *
125645916cd2Sjpk * Note: opt starts with "Tag Type":
125745916cd2Sjpk *
125845916cd2Sjpk * |tag_type(1)|tag_length(1)|align(1)|sl(1)|categories(variable)|
125945916cd2Sjpk *
126045916cd2Sjpk */
126145916cd2Sjpk static boolean_t
cipso_high(const uchar_t * opt)126245916cd2Sjpk cipso_high(const uchar_t *opt)
126345916cd2Sjpk {
126445916cd2Sjpk int i;
126545916cd2Sjpk
126645916cd2Sjpk if (((int)opt[1] + 6) < IP_MAX_OPT_LENGTH)
126745916cd2Sjpk return (B_FALSE);
126845916cd2Sjpk for (i = 0; i < ((int)opt[1] - 3); i++)
126945916cd2Sjpk if (opt[3 + i] != 0xff)
127045916cd2Sjpk return (B_FALSE);
127145916cd2Sjpk return (B_TRUE);
127245916cd2Sjpk }
127345916cd2Sjpk
127445916cd2Sjpk /*
127545916cd2Sjpk * Converts CIPSO label to SL.
127645916cd2Sjpk *
127745916cd2Sjpk * Note: opt starts with "Tag Type":
127845916cd2Sjpk *
127945916cd2Sjpk * |tag_type(1)|tag_length(1)|align(1)|sl(1)|categories(variable)|
128045916cd2Sjpk *
128145916cd2Sjpk */
128245916cd2Sjpk static void
cipso2sl(const uchar_t * opt,bslabel_t * sl,int * high)128345916cd2Sjpk cipso2sl(const uchar_t *opt, bslabel_t *sl, int *high)
128445916cd2Sjpk {
128545916cd2Sjpk int i, taglen;
128645916cd2Sjpk uchar_t *q = (uchar_t *)&((_bslabel_impl_t *)sl)->compartments;
128745916cd2Sjpk
128845916cd2Sjpk *high = 0;
128945916cd2Sjpk taglen = opt[1];
129045916cd2Sjpk memset((caddr_t)sl, 0, sizeof (bslabel_t));
129145916cd2Sjpk
129245916cd2Sjpk if (cipso_high(opt)) {
129345916cd2Sjpk BSLHIGH(sl);
129445916cd2Sjpk *high = 1;
129545916cd2Sjpk } else {
129645916cd2Sjpk LCLASS_SET((_bslabel_impl_t *)sl, opt[3]);
129745916cd2Sjpk for (i = 0; i < taglen - TSOL_TT1_MIN_LENGTH; i++)
129845916cd2Sjpk q[i] = opt[TSOL_TT1_MIN_LENGTH + i];
129945916cd2Sjpk }
130045916cd2Sjpk SETBLTYPE(sl, SUN_SL_ID);
130145916cd2Sjpk }
130245916cd2Sjpk
130345916cd2Sjpk static int
interpret_cipso_tagtype1(const uchar_t * opt)130445916cd2Sjpk interpret_cipso_tagtype1(const uchar_t *opt)
130545916cd2Sjpk {
130645916cd2Sjpk int i, taglen, ishigh;
130745916cd2Sjpk bslabel_t sl;
130845916cd2Sjpk char line[CIPSO_GENERIC_ARRAY_LEN], *ptr;
130945916cd2Sjpk
131045916cd2Sjpk taglen = opt[1];
131145916cd2Sjpk if (taglen < TSOL_TT1_MIN_LENGTH ||
131245916cd2Sjpk taglen > TSOL_TT1_MAX_LENGTH)
131345916cd2Sjpk return (taglen);
131445916cd2Sjpk
131545916cd2Sjpk (void) snprintf(get_line(0, 0), get_line_remain(),
131645916cd2Sjpk "Tag Type = %d, Tag Length = %d", opt[0], opt[1]);
131745916cd2Sjpk (void) snprintf(get_line(0, 0), get_line_remain(),
131845916cd2Sjpk "Sensitivity Level = 0x%02x", opt[3]);
131945916cd2Sjpk ptr = line;
132045916cd2Sjpk for (i = 0; i < taglen - TSOL_TT1_MIN_LENGTH; i++) {
132145916cd2Sjpk (void) snprintf(ptr, sizeof (line) - (ptr - line), "%02x",
132245916cd2Sjpk opt[TSOL_TT1_MIN_LENGTH + i]);
132345916cd2Sjpk ptr = strchr(ptr, 0);
132445916cd2Sjpk }
132545916cd2Sjpk if (i != 0) {
132645916cd2Sjpk (void) snprintf(get_line(0, 0), get_line_remain(),
132745916cd2Sjpk "Categories = ");
132845916cd2Sjpk (void) snprintf(get_line(0, 0), get_line_remain(), "\t%s",
132945916cd2Sjpk line);
133045916cd2Sjpk } else {
133145916cd2Sjpk (void) snprintf(get_line(0, 0), get_line_remain(),
133245916cd2Sjpk "Categories = None");
133345916cd2Sjpk }
133445916cd2Sjpk cipso2sl(opt, &sl, &ishigh);
1335b9dac67bSrica if (is_system_labeled()) {
133645916cd2Sjpk if (bsltos(&sl, &plabel, ALABEL_MAXLEN,
133745916cd2Sjpk LONG_CLASSIFICATION|LONG_WORDS|VIEW_INTERNAL) < 0) {
133845916cd2Sjpk (void) snprintf(get_line(0, 0), get_line_remain(),
133945916cd2Sjpk "The Sensitivity Level and Categories can't be "
134045916cd2Sjpk "mapped to a valid SL");
134145916cd2Sjpk } else {
134245916cd2Sjpk (void) snprintf(get_line(0, 0), get_line_remain(),
134345916cd2Sjpk "The Sensitivity Level and Categories are mapped "
134445916cd2Sjpk "to the SL:");
134545916cd2Sjpk (void) snprintf(get_line(0, 0), get_line_remain(),
134645916cd2Sjpk "\t%s", ascii_label);
134745916cd2Sjpk }
134845916cd2Sjpk }
134945916cd2Sjpk return (taglen);
135045916cd2Sjpk }
135145916cd2Sjpk
135245916cd2Sjpk /*
135345916cd2Sjpk * The following struct definition #define's are copied from TS1.x. They are
135445916cd2Sjpk * not used here (except TTYPE_3_MAX_TOKENS), but included as a reference for
135545916cd2Sjpk * the tag type 3 packet format.
135645916cd2Sjpk */
135745916cd2Sjpk #define TTYPE_3_MAX_TOKENS 7
135845916cd2Sjpk
135945916cd2Sjpk /*
136045916cd2Sjpk * Display CIPSO tag type 3 which is defined by MAXSIX.
136145916cd2Sjpk */
136245916cd2Sjpk static int
interpret_cipso_tagtype3(const uchar_t * opt)136345916cd2Sjpk interpret_cipso_tagtype3(const uchar_t *opt)
136445916cd2Sjpk {
136545916cd2Sjpk uchar_t tagtype;
136645916cd2Sjpk int index, numtokens, taglen;
136745916cd2Sjpk uint16_t mask;
136845916cd2Sjpk uint32_t token;
136945916cd2Sjpk static const char *name[] = {
137045916cd2Sjpk "SL",
137145916cd2Sjpk "NCAV",
137245916cd2Sjpk "INTEG",
137345916cd2Sjpk "SID",
137445916cd2Sjpk "undefined",
137545916cd2Sjpk "undefined",
137645916cd2Sjpk "IL",
137745916cd2Sjpk "PRIVS",
137845916cd2Sjpk "LUID",
137945916cd2Sjpk "PID",
138045916cd2Sjpk "IDS",
138145916cd2Sjpk "ACL"
138245916cd2Sjpk };
138345916cd2Sjpk
138445916cd2Sjpk tagtype = *opt++;
138545916cd2Sjpk (void) memcpy(&mask, opt + 3, sizeof (mask));
138645916cd2Sjpk (void) snprintf(get_line(0, 0), get_line_remain(),
138745916cd2Sjpk "Tag Type = %d (MAXSIX)", tagtype);
138845916cd2Sjpk (void) snprintf(get_line(0, 0), get_line_remain(),
138945916cd2Sjpk "Generation = 0x%02x%02x%02x, Mask = 0x%04x", opt[0], opt[1],
139045916cd2Sjpk opt[2], mask);
139145916cd2Sjpk opt += 3 + sizeof (mask);
139245916cd2Sjpk
139345916cd2Sjpk /*
139445916cd2Sjpk * Display tokens
139545916cd2Sjpk */
139645916cd2Sjpk numtokens = 0;
139745916cd2Sjpk index = 0;
139845916cd2Sjpk while (mask != 0 && numtokens < TTYPE_3_MAX_TOKENS) {
139945916cd2Sjpk if (mask & 0x0001) {
140045916cd2Sjpk (void) memcpy(&token, opt, sizeof (token));
140145916cd2Sjpk opt += sizeof (token);
140245916cd2Sjpk (void) snprintf(get_line(0, 0), get_line_remain(),
140345916cd2Sjpk "Attribute = %s, Token = 0x%08x",
140445916cd2Sjpk index < sizeof (name) / sizeof (*name) ?
140545916cd2Sjpk name[index] : "unknown", token);
140645916cd2Sjpk numtokens++;
14077c478bd9Sstevel@tonic-gate }
140845916cd2Sjpk mask = mask >> 1;
140945916cd2Sjpk index++;
141045916cd2Sjpk }
141145916cd2Sjpk
141245916cd2Sjpk taglen = 6 + numtokens * 4;
141345916cd2Sjpk return (taglen);
141445916cd2Sjpk }
141545916cd2Sjpk
141645916cd2Sjpk static void
print_cipso(const uchar_t * opt)141745916cd2Sjpk print_cipso(const uchar_t *opt)
141845916cd2Sjpk {
141945916cd2Sjpk int optlen, taglen, tagnum;
142045916cd2Sjpk uint32_t doi;
142145916cd2Sjpk char line[CIPSO_GENERIC_ARRAY_LEN];
142245916cd2Sjpk char *oldnest;
142345916cd2Sjpk
142445916cd2Sjpk optlen = opt[1];
142545916cd2Sjpk if (optlen < TSOL_CIPSO_MIN_LENGTH || optlen > TSOL_CIPSO_MAX_LENGTH)
142645916cd2Sjpk return;
142745916cd2Sjpk
142845916cd2Sjpk oldnest = prot_nest_prefix;
142945916cd2Sjpk prot_nest_prefix = prot_prefix;
143045916cd2Sjpk show_header("CIPSO: ", "Common IP Security Option", 0);
143145916cd2Sjpk show_space();
143245916cd2Sjpk
143345916cd2Sjpk /*
143445916cd2Sjpk * Display CIPSO Header
143545916cd2Sjpk */
143645916cd2Sjpk (void) snprintf(get_line(0, 0), get_line_remain(),
143745916cd2Sjpk "Type = CIPSO (%d), Length = %d", opt[0], opt[1]);
143845916cd2Sjpk (void) memcpy(&doi, opt + 2, sizeof (doi));
143945916cd2Sjpk (void) snprintf(get_line(0, 0), get_line_remain(),
144045916cd2Sjpk "Domain of Interpretation = %u", (unsigned)ntohl(doi));
144145916cd2Sjpk
144245916cd2Sjpk if (opt[1] == TSOL_CIPSO_MIN_LENGTH) { /* no tags */
144345916cd2Sjpk show_space();
144445916cd2Sjpk prot_prefix = prot_nest_prefix;
144545916cd2Sjpk prot_nest_prefix = oldnest;
144645916cd2Sjpk return;
14477c478bd9Sstevel@tonic-gate }
144845916cd2Sjpk optlen -= TSOL_CIPSO_MIN_LENGTH;
144945916cd2Sjpk opt += TSOL_CIPSO_MIN_LENGTH;
14507c478bd9Sstevel@tonic-gate
145145916cd2Sjpk /*
145245916cd2Sjpk * Display Each Tag
145345916cd2Sjpk */
145445916cd2Sjpk tagnum = 1;
145545916cd2Sjpk while (optlen >= TSOL_TT1_MIN_LENGTH) {
145645916cd2Sjpk (void) snprintf(line, sizeof (line), "Tag# %d", tagnum);
145745916cd2Sjpk show_header("CIPSO: ", line, 0);
145845916cd2Sjpk /*
145945916cd2Sjpk * We handle tag type 1 and 3 only. Note, tag type 3
146045916cd2Sjpk * is MAXSIX defined.
146145916cd2Sjpk */
146245916cd2Sjpk switch (opt[0]) {
146345916cd2Sjpk case 1:
146445916cd2Sjpk taglen = interpret_cipso_tagtype1(opt);
146545916cd2Sjpk break;
146645916cd2Sjpk case 3:
146745916cd2Sjpk taglen = interpret_cipso_tagtype3(opt);
146845916cd2Sjpk break;
146945916cd2Sjpk default:
147045916cd2Sjpk (void) snprintf(get_line(0, 0), get_line_remain(),
147145916cd2Sjpk "Unknown Tag Type %d", opt[0]);
147245916cd2Sjpk show_space();
147345916cd2Sjpk prot_prefix = prot_nest_prefix;
147445916cd2Sjpk prot_nest_prefix = oldnest;
147545916cd2Sjpk return;
147645916cd2Sjpk }
147745916cd2Sjpk
147845916cd2Sjpk /*
147945916cd2Sjpk * Move to the next tag
148045916cd2Sjpk */
148145916cd2Sjpk if (taglen <= 0)
148245916cd2Sjpk break;
148345916cd2Sjpk optlen -= taglen;
148445916cd2Sjpk opt += taglen;
148545916cd2Sjpk tagnum++;
148645916cd2Sjpk }
14877c478bd9Sstevel@tonic-gate show_space();
148845916cd2Sjpk prot_prefix = prot_nest_prefix;
148945916cd2Sjpk prot_nest_prefix = oldnest;
14907c478bd9Sstevel@tonic-gate }
1491