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/* 224291Sbrendan * Copyright 2007 Sun Microsystems, Inc. All rights reserved. 234291Sbrendan * Use is subject to license terms. 244291Sbrendan */ 254291Sbrendan 264291Sbrendan#pragma ident "%Z%%M% %I% %E% SMI" 274291Sbrendan 28*6878Sbrendan#pragma D depends_on module ip 29*6878Sbrendan#pragma D depends_on provider ip 30*6878Sbrendan 31*6878Sbrendaninline int IPH_DF = @IPH_DF@; 32*6878Sbrendan#pragma D binding "1.0" IPH_DF 33*6878Sbrendaninline int IPH_MF = @IPH_MF@; 34*6878Sbrendan#pragma D binding "1.0" IPH_MF 35*6878Sbrendan 36*6878Sbrendan#pragma D binding "1.0" IPPROTO_IP 37*6878Sbrendaninline int IPPROTO_IP = @IPPROTO_IP@; 38*6878Sbrendan#pragma D binding "1.0" IPPROTO_HOPOPTS 39*6878Sbrendaninline int IPPROTO_HOPOPTS = @IPPROTO_HOPOPTS@; 40*6878Sbrendan#pragma D binding "1.0" IPPROTO_ICMP 41*6878Sbrendaninline int IPPROTO_ICMP = @IPPROTO_ICMP@; 42*6878Sbrendan#pragma D binding "1.0" IPPROTO_IGMP 43*6878Sbrendaninline int IPPROTO_IGMP = @IPPROTO_IGMP@; 44*6878Sbrendan#pragma D binding "1.0" IPPROTO_GGP 45*6878Sbrendaninline int IPPROTO_GGP = @IPPROTO_GGP@; 46*6878Sbrendan#pragma D binding "1.0" IPPROTO_ENCAP 47*6878Sbrendaninline int IPPROTO_ENCAP = @IPPROTO_ENCAP@; 48*6878Sbrendan#pragma D binding "1.0" IPPROTO_TCP 49*6878Sbrendaninline int IPPROTO_TCP = @IPPROTO_TCP@; 50*6878Sbrendan#pragma D binding "1.0" IPPROTO_EGP 51*6878Sbrendaninline int IPPROTO_EGP = @IPPROTO_EGP@; 52*6878Sbrendan#pragma D binding "1.0" IPPROTO_PUP 53*6878Sbrendaninline int IPPROTO_PUP = @IPPROTO_PUP@; 54*6878Sbrendan#pragma D binding "1.0" IPPROTO_UDP 55*6878Sbrendaninline int IPPROTO_UDP = @IPPROTO_UDP@; 56*6878Sbrendan#pragma D binding "1.0" IPPROTO_IDP 57*6878Sbrendaninline int IPPROTO_IDP = @IPPROTO_IDP@; 58*6878Sbrendan#pragma D binding "1.0" IPPROTO_IPV6 59*6878Sbrendaninline int IPPROTO_IPV6 = @IPPROTO_IPV6@; 60*6878Sbrendan#pragma D binding "1.0" IPPROTO_ROUTING 61*6878Sbrendaninline int IPPROTO_ROUTING = @IPPROTO_ROUTING@; 62*6878Sbrendan#pragma D binding "1.0" IPPROTO_FRAGMENT 63*6878Sbrendaninline int IPPROTO_FRAGMENT = @IPPROTO_FRAGMENT@; 64*6878Sbrendan#pragma D binding "1.0" IPPROTO_RSVP 65*6878Sbrendaninline int IPPROTO_RSVP = @IPPROTO_RSVP@; 66*6878Sbrendan#pragma D binding "1.0" IPPROTO_ESP 67*6878Sbrendaninline int IPPROTO_ESP = @IPPROTO_ESP@; 68*6878Sbrendan#pragma D binding "1.0" IPPROTO_AH 69*6878Sbrendaninline int IPPROTO_AH = @IPPROTO_AH@; 70*6878Sbrendan#pragma D binding "1.0" IPPROTO_ICMPV6 71*6878Sbrendaninline int IPPROTO_ICMPV6 = @IPPROTO_ICMPV6@; 72*6878Sbrendan#pragma D binding "1.0" IPPROTO_NONE 73*6878Sbrendaninline int IPPROTO_NONE = @IPPROTO_NONE@; 74*6878Sbrendan#pragma D binding "1.0" IPPROTO_DSTOPTS 75*6878Sbrendaninline int IPPROTO_DSTOPTS = @IPPROTO_DSTOPTS@; 76*6878Sbrendan#pragma D binding "1.0" IPPROTO_HELLO 77*6878Sbrendaninline int IPPROTO_HELLO = @IPPROTO_HELLO@; 78*6878Sbrendan#pragma D binding "1.0" IPPROTO_ND 79*6878Sbrendaninline int IPPROTO_ND = @IPPROTO_ND@; 80*6878Sbrendan#pragma D binding "1.0" IPPROTO_EON 81*6878Sbrendaninline int IPPROTO_EON = @IPPROTO_EON@; 82*6878Sbrendan#pragma D binding "1.0" IPPROTO_OSPF 83*6878Sbrendaninline int IPPROTO_OSPF = @IPPROTO_OSPF@; 84*6878Sbrendan#pragma D binding "1.0" IPPROTO_PIM 85*6878Sbrendaninline int IPPROTO_PIM = @IPPROTO_PIM@; 86*6878Sbrendan#pragma D binding "1.0" IPPROTO_SCTP 87*6878Sbrendaninline int IPPROTO_SCTP = @IPPROTO_SCTP@; 88*6878Sbrendan#pragma D binding "1.0" IPPROTO_RAW 89*6878Sbrendaninline int IPPROTO_RAW = @IPPROTO_RAW@; 90*6878Sbrendan#pragma D binding "1.0" IPPROTO_MAX 91*6878Sbrendaninline int IPPROTO_MAX = @IPPROTO_MAX@; 92*6878Sbrendan 93*6878Sbrendan/* 94*6878Sbrendan * pktinfo is where packet ID info can be made available for deeper 95*6878Sbrendan * analysis if packet IDs become supported by the kernel in the future. 96*6878Sbrendan * The pkt_addr member is currently always NULL. 97*6878Sbrendan */ 98*6878Sbrendantypedef struct pktinfo { 99*6878Sbrendan uintptr_t pkt_addr; 100*6878Sbrendan} pktinfo_t; 101*6878Sbrendan 102*6878Sbrendan/* 103*6878Sbrendan * csinfo is where connection state info can be made available if 104*6878Sbrendan * connection IDs become supported by the kernel in the future. 105*6878Sbrendan * The cs_addr member is currently always NULL. 106*6878Sbrendan */ 107*6878Sbrendantypedef struct csinfo { 108*6878Sbrendan uintptr_t cs_addr; 109*6878Sbrendan} csinfo_t; 110*6878Sbrendan 111*6878Sbrendan/* 112*6878Sbrendan * ipinfo contains common IP info for both IPv4 and IPv6. 113*6878Sbrendan */ 114*6878Sbrendantypedef struct ipinfo { 115*6878Sbrendan uint8_t ip_ver; /* IP version (4, 6) */ 116*6878Sbrendan uint32_t ip_plength; /* payload length */ 117*6878Sbrendan string ip_saddr; /* source address */ 118*6878Sbrendan string ip_daddr; /* destination address */ 119*6878Sbrendan} ipinfo_t; 120*6878Sbrendan 121*6878Sbrendan/* 122*6878Sbrendan * ifinfo contains network interface info. 123*6878Sbrendan */ 124*6878Sbrendantypedef struct ifinfo { 125*6878Sbrendan string if_name; /* interface name */ 126*6878Sbrendan int8_t if_local; /* is delivered locally */ 127*6878Sbrendan netstackid_t if_ipstack; /* ipstack ID */ 128*6878Sbrendan uintptr_t if_addr; /* pointer to raw ill_t */ 129*6878Sbrendan} ifinfo_t; 130*6878Sbrendan 131*6878Sbrendan/* 132*6878Sbrendan * ipv4info is a translated version of the IPv4 header (with raw pointer). 133*6878Sbrendan * These values are NULL if the packet is not IPv4. 134*6878Sbrendan */ 135*6878Sbrendantypedef struct ipv4info { 136*6878Sbrendan uint8_t ipv4_ver; /* IP version (4) */ 137*6878Sbrendan uint8_t ipv4_ihl; /* header length, bytes */ 138*6878Sbrendan uint8_t ipv4_tos; /* type of service field */ 139*6878Sbrendan uint16_t ipv4_length; /* length (header + payload) */ 140*6878Sbrendan uint16_t ipv4_ident; /* identification */ 141*6878Sbrendan uint8_t ipv4_flags; /* IP flags */ 142*6878Sbrendan uint16_t ipv4_offset; /* fragment offset */ 143*6878Sbrendan uint8_t ipv4_ttl; /* time to live */ 144*6878Sbrendan uint8_t ipv4_protocol; /* next level protocol */ 145*6878Sbrendan string ipv4_protostr; /* next level protocol, as a string */ 146*6878Sbrendan uint16_t ipv4_checksum; /* header checksum */ 147*6878Sbrendan ipaddr_t ipv4_src; /* source address */ 148*6878Sbrendan ipaddr_t ipv4_dst; /* destination address */ 149*6878Sbrendan string ipv4_saddr; /* source address, string */ 150*6878Sbrendan string ipv4_daddr; /* destination address, string */ 151*6878Sbrendan ipha_t *ipv4_hdr; /* pointer to raw header */ 152*6878Sbrendan} ipv4info_t; 153*6878Sbrendan 154*6878Sbrendan/* 155*6878Sbrendan * ipv6info is a translated version of the IPv6 header (with raw pointer). 156*6878Sbrendan * These values are NULL if the packet is not IPv6. 157*6878Sbrendan */ 158*6878Sbrendantypedef struct ipv6info { 159*6878Sbrendan uint8_t ipv6_ver; /* IP version (6) */ 160*6878Sbrendan uint8_t ipv6_tclass; /* traffic class */ 161*6878Sbrendan uint32_t ipv6_flow; /* flow label */ 162*6878Sbrendan uint16_t ipv6_plen; /* payload length */ 163*6878Sbrendan uint8_t ipv6_nexthdr; /* next header protocol */ 164*6878Sbrendan string ipv6_nextstr; /* next header protocol, as a string */ 165*6878Sbrendan uint8_t ipv6_hlim; /* hop limit */ 166*6878Sbrendan in6_addr_t *ipv6_src; /* source address */ 167*6878Sbrendan in6_addr_t *ipv6_dst; /* destination address */ 168*6878Sbrendan string ipv6_saddr; /* source address, string */ 169*6878Sbrendan string ipv6_daddr; /* destination address, string */ 170*6878Sbrendan ip6_t *ipv6_hdr; /* pointer to raw header */ 171*6878Sbrendan} ipv6info_t; 172*6878Sbrendan 173*6878Sbrendan/* 174*6878Sbrendan * void_ip_t is a void pointer to either an IPv4 or IPv6 header. It has 175*6878Sbrendan * its own type name so that a translator can be determined. 176*6878Sbrendan */ 177*6878Sbrendantypedef uintptr_t void_ip_t; 178*6878Sbrendan 179*6878Sbrendan/* 180*6878Sbrendan * __dtrace_ipsr_ill_t is used by the translator to take an ill_t plus an 181*6878Sbrendan * additional arg6 from the ip:::send and ip:::recieve probes, and translate 182*6878Sbrendan * them to an ifinfo_t. 183*6878Sbrendan */ 184*6878Sbrendantypedef ill_t __dtrace_ipsr_ill_t; 185*6878Sbrendan 186*6878Sbrendan#pragma D binding "1.0" translator 187*6878Sbrendantranslator pktinfo_t < mblk_t *M > { 188*6878Sbrendan pkt_addr = NULL; 189*6878Sbrendan}; 190*6878Sbrendan 191*6878Sbrendan#pragma D binding "1.0" translator 192*6878Sbrendantranslator csinfo_t < conn_t *C > { 193*6878Sbrendan cs_addr = NULL; 194*6878Sbrendan}; 195*6878Sbrendan 196*6878Sbrendan#pragma D binding "1.0" translator 197*6878Sbrendantranslator ipinfo_t < ipha_t *I > { 198*6878Sbrendan ip_ver = I->ipha_version_and_hdr_length >> 4; 199*6878Sbrendan ip_plength = ntohs(I->ipha_length) - 200*6878Sbrendan ((I->ipha_version_and_hdr_length & 0xf) << 2); 201*6878Sbrendan ip_saddr = inet_ntoa(&I->ipha_src); 202*6878Sbrendan ip_daddr = inet_ntoa(&I->ipha_dst); 203*6878Sbrendan}; 204*6878Sbrendan 205*6878Sbrendan#pragma D binding "1.0" translator 206*6878Sbrendantranslator ipinfo_t < ip6_t *I > { 207*6878Sbrendan ip_ver = *(uint8_t *)I >> 4; 208*6878Sbrendan ip_plength = ntohs(I->ip6_ctlun.ip6_un1.ip6_un1_plen); 209*6878Sbrendan ip_saddr = inet_ntoa6(&I->ip6_src); 210*6878Sbrendan ip_daddr = inet_ntoa6(&I->ip6_dst); 211*6878Sbrendan}; 212*6878Sbrendan 213*6878Sbrendan#pragma D binding "1.0" translator 214*6878Sbrendantranslator ipinfo_t < void_ip_t *I > { 215*6878Sbrendan ip_ver = I != NULL ? *(uint8_t *)I >> 4 : 0; 216*6878Sbrendan ip_plength = I != NULL ? (*(uint8_t *)I >> 4 == 4 ? 217*6878Sbrendan ntohs(((ipha_t *)I)->ipha_length) - 218*6878Sbrendan ((((ipha_t *)I)->ipha_version_and_hdr_length & 0xf) << 2) : 219*6878Sbrendan *(uint8_t *)I >> 4 == 6 ? 220*6878Sbrendan ntohs(((ip6_t *)I)->ip6_ctlun.ip6_un1.ip6_un1_plen) : 0) : 0; 221*6878Sbrendan ip_saddr = I != NULL ? (*(uint8_t *)I >> 4 == 4 ? 222*6878Sbrendan inet_ntoa(&((ipha_t *)I)->ipha_src) : *(uint8_t *)I >> 4 == 6 ? 223*6878Sbrendan inet_ntoa6(&((ip6_t *)I)->ip6_src) : "<unknown>") : "<unknown>"; 224*6878Sbrendan ip_daddr = I != NULL ? (*(uint8_t *)I >> 4 == 4 ? 225*6878Sbrendan inet_ntoa(&((ipha_t *)I)->ipha_dst) : *(uint8_t *)I >> 4 == 6 ? 226*6878Sbrendan inet_ntoa6(&((ip6_t *)I)->ip6_dst) : "<unknown>") : "<unknown>"; 227*6878Sbrendan}; 228*6878Sbrendan 229*6878Sbrendan#pragma D binding "1.0" translator 230*6878Sbrendantranslator ifinfo_t < __dtrace_ipsr_ill_t *I > { 231*6878Sbrendan if_name = I != NULL ? stringof(I->ill_name) : "<null>"; 232*6878Sbrendan if_ipstack = I != NULL ? I->ill_ipst->ips_netstack->netstack_stackid 233*6878Sbrendan : 0; 234*6878Sbrendan if_local = arg6; /* probe dependent */ 235*6878Sbrendan if_addr = (uintptr_t)I; 236*6878Sbrendan}; 237*6878Sbrendan 238*6878Sbrendan#pragma D binding "1.0" translator 239*6878Sbrendantranslator ipv4info_t < ipha_t *I > { 240*6878Sbrendan ipv4_ver = I != NULL ? I->ipha_version_and_hdr_length >> 4 : 0; 241*6878Sbrendan ipv4_ihl = I != NULL ? (I->ipha_version_and_hdr_length & 0xf) << 2 : 0; 242*6878Sbrendan ipv4_tos = I != NULL ? I->ipha_type_of_service : 0; 243*6878Sbrendan ipv4_length = I != NULL ? ntohs(I->ipha_length) : 0; 244*6878Sbrendan ipv4_ident = I != NULL ? ntohs(I->ipha_ident) : 0; 245*6878Sbrendan ipv4_flags = I != NULL ? ntohs(I->ipha_fragment_offset_and_flags) >> 246*6878Sbrendan 12 : 0; 247*6878Sbrendan ipv4_offset = I != NULL ? ntohs(I->ipha_fragment_offset_and_flags) & 248*6878Sbrendan 0x0fff : 0; 249*6878Sbrendan ipv4_ttl = I != NULL ? I->ipha_ttl : 0; 250*6878Sbrendan ipv4_protocol = I != NULL ? I->ipha_protocol : 0; 251*6878Sbrendan ipv4_protostr = I == NULL ? "<null>" : 252*6878Sbrendan I->ipha_protocol == IPPROTO_TCP ? "TCP" : 253*6878Sbrendan I->ipha_protocol == IPPROTO_UDP ? "UDP" : 254*6878Sbrendan I->ipha_protocol == IPPROTO_IP ? "IP" : 255*6878Sbrendan I->ipha_protocol == IPPROTO_ICMP ? "ICMP" : 256*6878Sbrendan I->ipha_protocol == IPPROTO_IGMP ? "IGMP" : 257*6878Sbrendan I->ipha_protocol == IPPROTO_EGP ? "EGP" : 258*6878Sbrendan I->ipha_protocol == IPPROTO_IPV6 ? "IPv6" : 259*6878Sbrendan I->ipha_protocol == IPPROTO_ROUTING ? "ROUTE" : 260*6878Sbrendan I->ipha_protocol == IPPROTO_ESP ? "ESP" : 261*6878Sbrendan I->ipha_protocol == IPPROTO_AH ? "AH" : 262*6878Sbrendan I->ipha_protocol == IPPROTO_ICMPV6 ? "ICMPv6" : 263*6878Sbrendan I->ipha_protocol == IPPROTO_OSPF ? "OSPF" : 264*6878Sbrendan I->ipha_protocol == IPPROTO_SCTP ? "SCTP" : 265*6878Sbrendan I->ipha_protocol == IPPROTO_RAW ? "RAW" : 266*6878Sbrendan lltostr((uint64_t)I->ipha_protocol); 267*6878Sbrendan ipv4_checksum = I != NULL ? ntohs(I->ipha_hdr_checksum) : 0; 268*6878Sbrendan ipv4_src = I != NULL ? I->ipha_src : 0; 269*6878Sbrendan ipv4_dst = I != NULL ? I->ipha_dst : 0; 270*6878Sbrendan ipv4_saddr = I != NULL ? inet_ntoa(&I->ipha_src) : "<null>"; 271*6878Sbrendan ipv4_daddr = I != NULL ? inet_ntoa(&I->ipha_dst) : "<null>"; 272*6878Sbrendan ipv4_hdr = I; 273*6878Sbrendan}; 274*6878Sbrendan 275*6878Sbrendan#pragma D binding "1.0" translator 276*6878Sbrendantranslator ipv6info_t < ip6_t *I > { 277*6878Sbrendan ipv6_ver = I != NULL ? I->ip6_ctlun.ip6_un2_vfc >> 4 : 0; 278*6878Sbrendan ipv6_tclass = I != NULL ? ((I->ip6_ctlun.ip6_un1.ip6_un1_flow && 279*6878Sbrendan 0x0fffffff) >> 20) : 0; 280*6878Sbrendan ipv6_flow = I != NULL ? I->ip6_ctlun.ip6_un1.ip6_un1_flow && 281*6878Sbrendan 0x000fffff : 0; 282*6878Sbrendan ipv6_plen = I != NULL ? ntohs(I->ip6_ctlun.ip6_un1.ip6_un1_plen) : 0; 283*6878Sbrendan ipv6_nexthdr = I != NULL ? I->ip6_ctlun.ip6_un1.ip6_un1_nxt : 0; 284*6878Sbrendan ipv6_nextstr = I == NULL ? "<null>" : 285*6878Sbrendan I->ip6_ctlun.ip6_un1.ip6_un1_nxt == IPPROTO_TCP ? "TCP" : 286*6878Sbrendan I->ip6_ctlun.ip6_un1.ip6_un1_nxt == IPPROTO_UDP ? "UDP" : 287*6878Sbrendan I->ip6_ctlun.ip6_un1.ip6_un1_nxt == IPPROTO_IP ? "IP" : 288*6878Sbrendan I->ip6_ctlun.ip6_un1.ip6_un1_nxt == IPPROTO_ICMP ? "ICMP" : 289*6878Sbrendan I->ip6_ctlun.ip6_un1.ip6_un1_nxt == IPPROTO_IGMP ? "IGMP" : 290*6878Sbrendan I->ip6_ctlun.ip6_un1.ip6_un1_nxt == IPPROTO_EGP ? "EGP" : 291*6878Sbrendan I->ip6_ctlun.ip6_un1.ip6_un1_nxt == IPPROTO_IPV6 ? "IPv6" : 292*6878Sbrendan I->ip6_ctlun.ip6_un1.ip6_un1_nxt == IPPROTO_ROUTING ? "ROUTE" : 293*6878Sbrendan I->ip6_ctlun.ip6_un1.ip6_un1_nxt == IPPROTO_ESP ? "ESP" : 294*6878Sbrendan I->ip6_ctlun.ip6_un1.ip6_un1_nxt == IPPROTO_AH ? "AH" : 295*6878Sbrendan I->ip6_ctlun.ip6_un1.ip6_un1_nxt == IPPROTO_ICMPV6 ? "ICMPv6" : 296*6878Sbrendan I->ip6_ctlun.ip6_un1.ip6_un1_nxt == IPPROTO_OSPF ? "OSPF" : 297*6878Sbrendan I->ip6_ctlun.ip6_un1.ip6_un1_nxt == IPPROTO_SCTP ? "SCTP" : 298*6878Sbrendan I->ip6_ctlun.ip6_un1.ip6_un1_nxt == IPPROTO_RAW ? "RAW" : 299*6878Sbrendan lltostr((uint64_t)I->ip6_ctlun.ip6_un1.ip6_un1_nxt); 300*6878Sbrendan ipv6_hlim = I != NULL ? I->ip6_ctlun.ip6_un1.ip6_un1_hlim : 0; 301*6878Sbrendan ipv6_src = I != NULL ? &I->ip6_src : 0; 302*6878Sbrendan ipv6_dst = I != NULL ? &I->ip6_dst : 0; 303*6878Sbrendan ipv6_saddr = I != NULL ? inet_ntoa6(&I->ip6_src) : "<null>"; 304*6878Sbrendan ipv6_daddr = I != NULL ? inet_ntoa6(&I->ip6_dst) : "<null>"; 305*6878Sbrendan ipv6_hdr = I; 306*6878Sbrendan}; 307