14291Sbrendan/* 24291Sbrendan * CDDL HEADER START 34291Sbrendan * 44291Sbrendan * The contents of this file are subject to the terms of the 54291Sbrendan * Common Development and Distribution License (the "License"). 64291Sbrendan * You may not use this file except in compliance with the License. 74291Sbrendan * 84291Sbrendan * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 94291Sbrendan * or http://www.opensolaris.org/os/licensing. 104291Sbrendan * See the License for the specific language governing permissions 114291Sbrendan * and limitations under the License. 124291Sbrendan * 134291Sbrendan * When distributing Covered Code, include this CDDL HEADER in each 144291Sbrendan * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 154291Sbrendan * If applicable, add the following below this CDDL HEADER, with the 164291Sbrendan * fields enclosed by brackets "[]" replaced with your own identifying 174291Sbrendan * information: Portions Copyright [yyyy] [name of copyright owner] 184291Sbrendan * 194291Sbrendan * CDDL HEADER END 204291Sbrendan */ 214291Sbrendan/* 22*11237SJonathan.Haslam@Sun.COM * Copyright 2009 Sun Microsystems, Inc. All rights reserved. 234291Sbrendan * Use is subject to license terms. 244291Sbrendan */ 254291Sbrendan 266878Sbrendan#pragma D depends_on module ip 276878Sbrendan#pragma D depends_on provider ip 286878Sbrendan 296878Sbrendaninline int IPH_DF = @IPH_DF@; 30*11237SJonathan.Haslam@Sun.COM#pragma D binding "1.5" IPH_DF 316878Sbrendaninline int IPH_MF = @IPH_MF@; 32*11237SJonathan.Haslam@Sun.COM#pragma D binding "1.5" IPH_MF 336878Sbrendan 34*11237SJonathan.Haslam@Sun.COM#pragma D binding "1.5" IPPROTO_IP 356878Sbrendaninline int IPPROTO_IP = @IPPROTO_IP@; 36*11237SJonathan.Haslam@Sun.COM#pragma D binding "1.5" IPPROTO_HOPOPTS 376878Sbrendaninline int IPPROTO_HOPOPTS = @IPPROTO_HOPOPTS@; 38*11237SJonathan.Haslam@Sun.COM#pragma D binding "1.5" IPPROTO_ICMP 396878Sbrendaninline int IPPROTO_ICMP = @IPPROTO_ICMP@; 40*11237SJonathan.Haslam@Sun.COM#pragma D binding "1.5" IPPROTO_IGMP 416878Sbrendaninline int IPPROTO_IGMP = @IPPROTO_IGMP@; 42*11237SJonathan.Haslam@Sun.COM#pragma D binding "1.5" IPPROTO_GGP 436878Sbrendaninline int IPPROTO_GGP = @IPPROTO_GGP@; 44*11237SJonathan.Haslam@Sun.COM#pragma D binding "1.5" IPPROTO_ENCAP 456878Sbrendaninline int IPPROTO_ENCAP = @IPPROTO_ENCAP@; 46*11237SJonathan.Haslam@Sun.COM#pragma D binding "1.5" IPPROTO_TCP 476878Sbrendaninline int IPPROTO_TCP = @IPPROTO_TCP@; 48*11237SJonathan.Haslam@Sun.COM#pragma D binding "1.5" IPPROTO_EGP 496878Sbrendaninline int IPPROTO_EGP = @IPPROTO_EGP@; 50*11237SJonathan.Haslam@Sun.COM#pragma D binding "1.5" IPPROTO_PUP 516878Sbrendaninline int IPPROTO_PUP = @IPPROTO_PUP@; 52*11237SJonathan.Haslam@Sun.COM#pragma D binding "1.5" IPPROTO_UDP 536878Sbrendaninline int IPPROTO_UDP = @IPPROTO_UDP@; 54*11237SJonathan.Haslam@Sun.COM#pragma D binding "1.5" IPPROTO_IDP 556878Sbrendaninline int IPPROTO_IDP = @IPPROTO_IDP@; 56*11237SJonathan.Haslam@Sun.COM#pragma D binding "1.5" IPPROTO_IPV6 576878Sbrendaninline int IPPROTO_IPV6 = @IPPROTO_IPV6@; 58*11237SJonathan.Haslam@Sun.COM#pragma D binding "1.5" IPPROTO_ROUTING 596878Sbrendaninline int IPPROTO_ROUTING = @IPPROTO_ROUTING@; 60*11237SJonathan.Haslam@Sun.COM#pragma D binding "1.5" IPPROTO_FRAGMENT 616878Sbrendaninline int IPPROTO_FRAGMENT = @IPPROTO_FRAGMENT@; 62*11237SJonathan.Haslam@Sun.COM#pragma D binding "1.5" IPPROTO_RSVP 636878Sbrendaninline int IPPROTO_RSVP = @IPPROTO_RSVP@; 64*11237SJonathan.Haslam@Sun.COM#pragma D binding "1.5" IPPROTO_ESP 656878Sbrendaninline int IPPROTO_ESP = @IPPROTO_ESP@; 66*11237SJonathan.Haslam@Sun.COM#pragma D binding "1.5" IPPROTO_AH 676878Sbrendaninline int IPPROTO_AH = @IPPROTO_AH@; 68*11237SJonathan.Haslam@Sun.COM#pragma D binding "1.5" IPPROTO_ICMPV6 696878Sbrendaninline int IPPROTO_ICMPV6 = @IPPROTO_ICMPV6@; 70*11237SJonathan.Haslam@Sun.COM#pragma D binding "1.5" IPPROTO_NONE 716878Sbrendaninline int IPPROTO_NONE = @IPPROTO_NONE@; 72*11237SJonathan.Haslam@Sun.COM#pragma D binding "1.5" IPPROTO_DSTOPTS 736878Sbrendaninline int IPPROTO_DSTOPTS = @IPPROTO_DSTOPTS@; 74*11237SJonathan.Haslam@Sun.COM#pragma D binding "1.5" IPPROTO_HELLO 756878Sbrendaninline int IPPROTO_HELLO = @IPPROTO_HELLO@; 76*11237SJonathan.Haslam@Sun.COM#pragma D binding "1.5" IPPROTO_ND 776878Sbrendaninline int IPPROTO_ND = @IPPROTO_ND@; 78*11237SJonathan.Haslam@Sun.COM#pragma D binding "1.5" IPPROTO_EON 796878Sbrendaninline int IPPROTO_EON = @IPPROTO_EON@; 80*11237SJonathan.Haslam@Sun.COM#pragma D binding "1.5" IPPROTO_OSPF 816878Sbrendaninline int IPPROTO_OSPF = @IPPROTO_OSPF@; 82*11237SJonathan.Haslam@Sun.COM#pragma D binding "1.5" IPPROTO_PIM 836878Sbrendaninline int IPPROTO_PIM = @IPPROTO_PIM@; 84*11237SJonathan.Haslam@Sun.COM#pragma D binding "1.5" IPPROTO_SCTP 856878Sbrendaninline int IPPROTO_SCTP = @IPPROTO_SCTP@; 86*11237SJonathan.Haslam@Sun.COM#pragma D binding "1.5" IPPROTO_RAW 876878Sbrendaninline int IPPROTO_RAW = @IPPROTO_RAW@; 88*11237SJonathan.Haslam@Sun.COM#pragma D binding "1.5" IPPROTO_MAX 896878Sbrendaninline int IPPROTO_MAX = @IPPROTO_MAX@; 906878Sbrendan 916878Sbrendan/* 926878Sbrendan * pktinfo is where packet ID info can be made available for deeper 936878Sbrendan * analysis if packet IDs become supported by the kernel in the future. 946878Sbrendan * The pkt_addr member is currently always NULL. 956878Sbrendan */ 966878Sbrendantypedef struct pktinfo { 976878Sbrendan uintptr_t pkt_addr; 986878Sbrendan} pktinfo_t; 996878Sbrendan 1006878Sbrendan/* 1016878Sbrendan * csinfo is where connection state info can be made available if 1026878Sbrendan * connection IDs become supported by the kernel in the future. 1036878Sbrendan * The cs_addr member is currently always NULL. 1046878Sbrendan */ 1056878Sbrendantypedef struct csinfo { 1066878Sbrendan uintptr_t cs_addr; 1076878Sbrendan} csinfo_t; 1086878Sbrendan 1096878Sbrendan/* 1106878Sbrendan * ipinfo contains common IP info for both IPv4 and IPv6. 1116878Sbrendan */ 1126878Sbrendantypedef struct ipinfo { 1136878Sbrendan uint8_t ip_ver; /* IP version (4, 6) */ 1146878Sbrendan uint32_t ip_plength; /* payload length */ 1156878Sbrendan string ip_saddr; /* source address */ 1166878Sbrendan string ip_daddr; /* destination address */ 1176878Sbrendan} ipinfo_t; 1186878Sbrendan 1196878Sbrendan/* 1206878Sbrendan * ifinfo contains network interface info. 1216878Sbrendan */ 1226878Sbrendantypedef struct ifinfo { 1236878Sbrendan string if_name; /* interface name */ 1246878Sbrendan int8_t if_local; /* is delivered locally */ 1256878Sbrendan netstackid_t if_ipstack; /* ipstack ID */ 1266878Sbrendan uintptr_t if_addr; /* pointer to raw ill_t */ 1276878Sbrendan} ifinfo_t; 1286878Sbrendan 1296878Sbrendan/* 1306878Sbrendan * ipv4info is a translated version of the IPv4 header (with raw pointer). 1316878Sbrendan * These values are NULL if the packet is not IPv4. 1326878Sbrendan */ 1336878Sbrendantypedef struct ipv4info { 1346878Sbrendan uint8_t ipv4_ver; /* IP version (4) */ 1356878Sbrendan uint8_t ipv4_ihl; /* header length, bytes */ 1366878Sbrendan uint8_t ipv4_tos; /* type of service field */ 1376878Sbrendan uint16_t ipv4_length; /* length (header + payload) */ 1386878Sbrendan uint16_t ipv4_ident; /* identification */ 1396878Sbrendan uint8_t ipv4_flags; /* IP flags */ 1406878Sbrendan uint16_t ipv4_offset; /* fragment offset */ 1416878Sbrendan uint8_t ipv4_ttl; /* time to live */ 1426878Sbrendan uint8_t ipv4_protocol; /* next level protocol */ 1436878Sbrendan string ipv4_protostr; /* next level protocol, as a string */ 1446878Sbrendan uint16_t ipv4_checksum; /* header checksum */ 1456878Sbrendan ipaddr_t ipv4_src; /* source address */ 1466878Sbrendan ipaddr_t ipv4_dst; /* destination address */ 1476878Sbrendan string ipv4_saddr; /* source address, string */ 1486878Sbrendan string ipv4_daddr; /* destination address, string */ 1496878Sbrendan ipha_t *ipv4_hdr; /* pointer to raw header */ 1506878Sbrendan} ipv4info_t; 1516878Sbrendan 1526878Sbrendan/* 1536878Sbrendan * ipv6info is a translated version of the IPv6 header (with raw pointer). 1546878Sbrendan * These values are NULL if the packet is not IPv6. 1556878Sbrendan */ 1566878Sbrendantypedef struct ipv6info { 1576878Sbrendan uint8_t ipv6_ver; /* IP version (6) */ 1586878Sbrendan uint8_t ipv6_tclass; /* traffic class */ 1596878Sbrendan uint32_t ipv6_flow; /* flow label */ 1606878Sbrendan uint16_t ipv6_plen; /* payload length */ 1616878Sbrendan uint8_t ipv6_nexthdr; /* next header protocol */ 1626878Sbrendan string ipv6_nextstr; /* next header protocol, as a string */ 1636878Sbrendan uint8_t ipv6_hlim; /* hop limit */ 1646878Sbrendan in6_addr_t *ipv6_src; /* source address */ 1656878Sbrendan in6_addr_t *ipv6_dst; /* destination address */ 1666878Sbrendan string ipv6_saddr; /* source address, string */ 1676878Sbrendan string ipv6_daddr; /* destination address, string */ 1686878Sbrendan ip6_t *ipv6_hdr; /* pointer to raw header */ 1696878Sbrendan} ipv6info_t; 1706878Sbrendan 1716878Sbrendan/* 1726878Sbrendan * void_ip_t is a void pointer to either an IPv4 or IPv6 header. It has 1736878Sbrendan * its own type name so that a translator can be determined. 1746878Sbrendan */ 1756878Sbrendantypedef uintptr_t void_ip_t; 1766878Sbrendan 1776878Sbrendan/* 1786878Sbrendan * __dtrace_ipsr_ill_t is used by the translator to take an ill_t plus an 1796878Sbrendan * additional arg6 from the ip:::send and ip:::recieve probes, and translate 1806878Sbrendan * them to an ifinfo_t. 1816878Sbrendan */ 1826878Sbrendantypedef ill_t __dtrace_ipsr_ill_t; 1836878Sbrendan 184*11237SJonathan.Haslam@Sun.COM#pragma D binding "1.5" translator 1856878Sbrendantranslator pktinfo_t < mblk_t *M > { 1866878Sbrendan pkt_addr = NULL; 1876878Sbrendan}; 1886878Sbrendan 189*11237SJonathan.Haslam@Sun.COM#pragma D binding "1.5" translator 1906878Sbrendantranslator csinfo_t < conn_t *C > { 1916878Sbrendan cs_addr = NULL; 1926878Sbrendan}; 1936878Sbrendan 194*11237SJonathan.Haslam@Sun.COM#pragma D binding "1.5" translator 1956878Sbrendantranslator ipinfo_t < ipha_t *I > { 1966878Sbrendan ip_ver = I->ipha_version_and_hdr_length >> 4; 1976878Sbrendan ip_plength = ntohs(I->ipha_length) - 1986878Sbrendan ((I->ipha_version_and_hdr_length & 0xf) << 2); 1996878Sbrendan ip_saddr = inet_ntoa(&I->ipha_src); 2006878Sbrendan ip_daddr = inet_ntoa(&I->ipha_dst); 2016878Sbrendan}; 2026878Sbrendan 203*11237SJonathan.Haslam@Sun.COM#pragma D binding "1.5" translator 2046878Sbrendantranslator ipinfo_t < ip6_t *I > { 2056878Sbrendan ip_ver = *(uint8_t *)I >> 4; 2066878Sbrendan ip_plength = ntohs(I->ip6_ctlun.ip6_un1.ip6_un1_plen); 2076878Sbrendan ip_saddr = inet_ntoa6(&I->ip6_src); 2086878Sbrendan ip_daddr = inet_ntoa6(&I->ip6_dst); 2096878Sbrendan}; 2106878Sbrendan 211*11237SJonathan.Haslam@Sun.COM#pragma D binding "1.5" translator 2126878Sbrendantranslator ipinfo_t < void_ip_t *I > { 2136878Sbrendan ip_ver = I != NULL ? *(uint8_t *)I >> 4 : 0; 2146878Sbrendan ip_plength = I != NULL ? (*(uint8_t *)I >> 4 == 4 ? 2156878Sbrendan ntohs(((ipha_t *)I)->ipha_length) - 2166878Sbrendan ((((ipha_t *)I)->ipha_version_and_hdr_length & 0xf) << 2) : 2176878Sbrendan *(uint8_t *)I >> 4 == 6 ? 2186878Sbrendan ntohs(((ip6_t *)I)->ip6_ctlun.ip6_un1.ip6_un1_plen) : 0) : 0; 2196878Sbrendan ip_saddr = I != NULL ? (*(uint8_t *)I >> 4 == 4 ? 2206878Sbrendan inet_ntoa(&((ipha_t *)I)->ipha_src) : *(uint8_t *)I >> 4 == 6 ? 2216878Sbrendan inet_ntoa6(&((ip6_t *)I)->ip6_src) : "<unknown>") : "<unknown>"; 2226878Sbrendan ip_daddr = I != NULL ? (*(uint8_t *)I >> 4 == 4 ? 2236878Sbrendan inet_ntoa(&((ipha_t *)I)->ipha_dst) : *(uint8_t *)I >> 4 == 6 ? 2246878Sbrendan inet_ntoa6(&((ip6_t *)I)->ip6_dst) : "<unknown>") : "<unknown>"; 2256878Sbrendan}; 2266878Sbrendan 227*11237SJonathan.Haslam@Sun.COM#pragma D binding "1.5" translator 2286878Sbrendantranslator ifinfo_t < __dtrace_ipsr_ill_t *I > { 2296878Sbrendan if_name = I != NULL ? stringof(I->ill_name) : "<null>"; 2306878Sbrendan if_ipstack = I != NULL ? I->ill_ipst->ips_netstack->netstack_stackid 2316878Sbrendan : 0; 2326878Sbrendan if_local = arg6; /* probe dependent */ 2336878Sbrendan if_addr = (uintptr_t)I; 2346878Sbrendan}; 2356878Sbrendan 236*11237SJonathan.Haslam@Sun.COM#pragma D binding "1.5" translator 2376878Sbrendantranslator ipv4info_t < ipha_t *I > { 2386878Sbrendan ipv4_ver = I != NULL ? I->ipha_version_and_hdr_length >> 4 : 0; 2396878Sbrendan ipv4_ihl = I != NULL ? (I->ipha_version_and_hdr_length & 0xf) << 2 : 0; 2406878Sbrendan ipv4_tos = I != NULL ? I->ipha_type_of_service : 0; 2416878Sbrendan ipv4_length = I != NULL ? ntohs(I->ipha_length) : 0; 2426878Sbrendan ipv4_ident = I != NULL ? ntohs(I->ipha_ident) : 0; 2436878Sbrendan ipv4_flags = I != NULL ? ntohs(I->ipha_fragment_offset_and_flags) >> 2446878Sbrendan 12 : 0; 2456878Sbrendan ipv4_offset = I != NULL ? ntohs(I->ipha_fragment_offset_and_flags) & 2466878Sbrendan 0x0fff : 0; 2476878Sbrendan ipv4_ttl = I != NULL ? I->ipha_ttl : 0; 2486878Sbrendan ipv4_protocol = I != NULL ? I->ipha_protocol : 0; 2496878Sbrendan ipv4_protostr = I == NULL ? "<null>" : 2506878Sbrendan I->ipha_protocol == IPPROTO_TCP ? "TCP" : 2516878Sbrendan I->ipha_protocol == IPPROTO_UDP ? "UDP" : 2526878Sbrendan I->ipha_protocol == IPPROTO_IP ? "IP" : 2536878Sbrendan I->ipha_protocol == IPPROTO_ICMP ? "ICMP" : 2546878Sbrendan I->ipha_protocol == IPPROTO_IGMP ? "IGMP" : 2556878Sbrendan I->ipha_protocol == IPPROTO_EGP ? "EGP" : 2566878Sbrendan I->ipha_protocol == IPPROTO_IPV6 ? "IPv6" : 2576878Sbrendan I->ipha_protocol == IPPROTO_ROUTING ? "ROUTE" : 2586878Sbrendan I->ipha_protocol == IPPROTO_ESP ? "ESP" : 2596878Sbrendan I->ipha_protocol == IPPROTO_AH ? "AH" : 2606878Sbrendan I->ipha_protocol == IPPROTO_ICMPV6 ? "ICMPv6" : 2616878Sbrendan I->ipha_protocol == IPPROTO_OSPF ? "OSPF" : 2626878Sbrendan I->ipha_protocol == IPPROTO_SCTP ? "SCTP" : 2636878Sbrendan I->ipha_protocol == IPPROTO_RAW ? "RAW" : 2646878Sbrendan lltostr((uint64_t)I->ipha_protocol); 2656878Sbrendan ipv4_checksum = I != NULL ? ntohs(I->ipha_hdr_checksum) : 0; 2666878Sbrendan ipv4_src = I != NULL ? I->ipha_src : 0; 2676878Sbrendan ipv4_dst = I != NULL ? I->ipha_dst : 0; 2686878Sbrendan ipv4_saddr = I != NULL ? inet_ntoa(&I->ipha_src) : "<null>"; 2696878Sbrendan ipv4_daddr = I != NULL ? inet_ntoa(&I->ipha_dst) : "<null>"; 2706878Sbrendan ipv4_hdr = I; 2716878Sbrendan}; 2726878Sbrendan 273*11237SJonathan.Haslam@Sun.COM#pragma D binding "1.5" translator 2746878Sbrendantranslator ipv6info_t < ip6_t *I > { 2756878Sbrendan ipv6_ver = I != NULL ? I->ip6_ctlun.ip6_un2_vfc >> 4 : 0; 2766878Sbrendan ipv6_tclass = I != NULL ? ((I->ip6_ctlun.ip6_un1.ip6_un1_flow && 2776878Sbrendan 0x0fffffff) >> 20) : 0; 2786878Sbrendan ipv6_flow = I != NULL ? I->ip6_ctlun.ip6_un1.ip6_un1_flow && 2796878Sbrendan 0x000fffff : 0; 2806878Sbrendan ipv6_plen = I != NULL ? ntohs(I->ip6_ctlun.ip6_un1.ip6_un1_plen) : 0; 2816878Sbrendan ipv6_nexthdr = I != NULL ? I->ip6_ctlun.ip6_un1.ip6_un1_nxt : 0; 2826878Sbrendan ipv6_nextstr = I == NULL ? "<null>" : 2836878Sbrendan I->ip6_ctlun.ip6_un1.ip6_un1_nxt == IPPROTO_TCP ? "TCP" : 2846878Sbrendan I->ip6_ctlun.ip6_un1.ip6_un1_nxt == IPPROTO_UDP ? "UDP" : 2856878Sbrendan I->ip6_ctlun.ip6_un1.ip6_un1_nxt == IPPROTO_IP ? "IP" : 2866878Sbrendan I->ip6_ctlun.ip6_un1.ip6_un1_nxt == IPPROTO_ICMP ? "ICMP" : 2876878Sbrendan I->ip6_ctlun.ip6_un1.ip6_un1_nxt == IPPROTO_IGMP ? "IGMP" : 2886878Sbrendan I->ip6_ctlun.ip6_un1.ip6_un1_nxt == IPPROTO_EGP ? "EGP" : 2896878Sbrendan I->ip6_ctlun.ip6_un1.ip6_un1_nxt == IPPROTO_IPV6 ? "IPv6" : 2906878Sbrendan I->ip6_ctlun.ip6_un1.ip6_un1_nxt == IPPROTO_ROUTING ? "ROUTE" : 2916878Sbrendan I->ip6_ctlun.ip6_un1.ip6_un1_nxt == IPPROTO_ESP ? "ESP" : 2926878Sbrendan I->ip6_ctlun.ip6_un1.ip6_un1_nxt == IPPROTO_AH ? "AH" : 2936878Sbrendan I->ip6_ctlun.ip6_un1.ip6_un1_nxt == IPPROTO_ICMPV6 ? "ICMPv6" : 2946878Sbrendan I->ip6_ctlun.ip6_un1.ip6_un1_nxt == IPPROTO_OSPF ? "OSPF" : 2956878Sbrendan I->ip6_ctlun.ip6_un1.ip6_un1_nxt == IPPROTO_SCTP ? "SCTP" : 2966878Sbrendan I->ip6_ctlun.ip6_un1.ip6_un1_nxt == IPPROTO_RAW ? "RAW" : 2976878Sbrendan lltostr((uint64_t)I->ip6_ctlun.ip6_un1.ip6_un1_nxt); 2986878Sbrendan ipv6_hlim = I != NULL ? I->ip6_ctlun.ip6_un1.ip6_un1_hlim : 0; 2996878Sbrendan ipv6_src = I != NULL ? &I->ip6_src : 0; 3006878Sbrendan ipv6_dst = I != NULL ? &I->ip6_dst : 0; 3016878Sbrendan ipv6_saddr = I != NULL ? inet_ntoa6(&I->ip6_src) : "<null>"; 3026878Sbrendan ipv6_daddr = I != NULL ? inet_ntoa6(&I->ip6_dst) : "<null>"; 3036878Sbrendan ipv6_hdr = I; 3046878Sbrendan}; 305