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