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