summaryrefslogtreecommitdiff
path: root/usr/src/lib/libdtrace/common/ip.d.in
blob: f1e6332529edb7171eaa975b2ff81e358c47829c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
/*
 * CDDL HEADER START
 *
 * The contents of this file are subject to the terms of the
 * Common Development and Distribution License (the "License").
 * You may not use this file except in compliance with the License.
 *
 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
 * or http://www.opensolaris.org/os/licensing.
 * See the License for the specific language governing permissions
 * and limitations under the License.
 *
 * When distributing Covered Code, include this CDDL HEADER in each
 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
 * If applicable, add the following below this CDDL HEADER, with the
 * fields enclosed by brackets "[]" replaced with your own identifying
 * information: Portions Copyright [yyyy] [name of copyright owner]
 *
 * CDDL HEADER END
 */
/*
 * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
 */

#pragma D depends_on module ip
#pragma D depends_on provider ip

inline int IPH_DF = @IPH_DF@;
#pragma D binding "1.5" IPH_DF
inline int IPH_MF = @IPH_MF@;
#pragma D binding "1.5" IPH_MF

#pragma D binding "1.5" IPPROTO_IP
inline int IPPROTO_IP = @IPPROTO_IP@;
#pragma D binding "1.5" IPPROTO_HOPOPTS
inline int IPPROTO_HOPOPTS = @IPPROTO_HOPOPTS@;
#pragma D binding "1.5" IPPROTO_ICMP
inline int IPPROTO_ICMP = @IPPROTO_ICMP@;
#pragma D binding "1.5" IPPROTO_IGMP
inline int IPPROTO_IGMP = @IPPROTO_IGMP@;
#pragma D binding "1.5" IPPROTO_GGP
inline int IPPROTO_GGP = @IPPROTO_GGP@;
#pragma D binding "1.5" IPPROTO_ENCAP
inline int IPPROTO_ENCAP = @IPPROTO_ENCAP@;
#pragma D binding "1.5" IPPROTO_TCP
inline int IPPROTO_TCP = @IPPROTO_TCP@;
#pragma D binding "1.5" IPPROTO_EGP
inline int IPPROTO_EGP = @IPPROTO_EGP@;
#pragma D binding "1.5" IPPROTO_PUP
inline int IPPROTO_PUP = @IPPROTO_PUP@;
#pragma D binding "1.5" IPPROTO_UDP
inline int IPPROTO_UDP = @IPPROTO_UDP@;
#pragma D binding "1.5" IPPROTO_IDP
inline int IPPROTO_IDP = @IPPROTO_IDP@;
#pragma D binding "1.5" IPPROTO_IPV6
inline int IPPROTO_IPV6 = @IPPROTO_IPV6@;
#pragma D binding "1.5" IPPROTO_ROUTING
inline int IPPROTO_ROUTING = @IPPROTO_ROUTING@;
#pragma D binding "1.5" IPPROTO_FRAGMENT
inline int IPPROTO_FRAGMENT = @IPPROTO_FRAGMENT@;
#pragma D binding "1.5" IPPROTO_RSVP
inline int IPPROTO_RSVP = @IPPROTO_RSVP@;
#pragma D binding "1.5" IPPROTO_ESP
inline int IPPROTO_ESP = @IPPROTO_ESP@;
#pragma D binding "1.5" IPPROTO_AH
inline int IPPROTO_AH = @IPPROTO_AH@;
#pragma D binding "1.5" IPPROTO_ICMPV6
inline int IPPROTO_ICMPV6 = @IPPROTO_ICMPV6@;
#pragma D binding "1.5" IPPROTO_NONE
inline int IPPROTO_NONE = @IPPROTO_NONE@;
#pragma D binding "1.5" IPPROTO_DSTOPTS
inline int IPPROTO_DSTOPTS = @IPPROTO_DSTOPTS@;
#pragma D binding "1.5" IPPROTO_HELLO
inline int IPPROTO_HELLO = @IPPROTO_HELLO@;
#pragma D binding "1.5" IPPROTO_ND
inline int IPPROTO_ND = @IPPROTO_ND@;
#pragma D binding "1.5" IPPROTO_EON
inline int IPPROTO_EON = @IPPROTO_EON@;
#pragma D binding "1.5" IPPROTO_OSPF
inline int IPPROTO_OSPF = @IPPROTO_OSPF@;
#pragma D binding "1.5" IPPROTO_PIM
inline int IPPROTO_PIM = @IPPROTO_PIM@;
#pragma D binding "1.5" IPPROTO_SCTP
inline int IPPROTO_SCTP = @IPPROTO_SCTP@;
#pragma D binding "1.5" IPPROTO_RAW
inline int IPPROTO_RAW = @IPPROTO_RAW@;
#pragma D binding "1.5" IPPROTO_MAX
inline int IPPROTO_MAX = @IPPROTO_MAX@;

/*
 * pktinfo is where packet ID info can be made available for deeper
 * analysis if packet IDs become supported by the kernel in the future.
 * The pkt_addr member is currently always NULL.
 */
typedef struct pktinfo {
	uintptr_t pkt_addr;
} pktinfo_t;

/*
 * csinfo is where connection state info is made available.
 */
typedef struct csinfo {
	uintptr_t cs_addr;
	uint64_t cs_cid;
	pid_t cs_pid;
	zoneid_t cs_zoneid;
} csinfo_t;

/*
 * ipinfo contains common IP info for both IPv4 and IPv6.
 */
typedef struct ipinfo {
	uint8_t ip_ver;			/* IP version (4, 6) */
	uint32_t ip_plength;		/* payload length */
	string ip_saddr;		/* source address */
	string ip_daddr;		/* destination address */
} ipinfo_t;

/*
 * ifinfo contains network interface info.
 */
typedef struct ifinfo {
	string if_name;			/* interface name */
	int8_t if_local;		/* is delivered locally */
	netstackid_t if_ipstack;	/* ipstack ID */
	uintptr_t if_addr;		/* pointer to raw ill_t */
} ifinfo_t;

/*
 * ipv4info is a translated version of the IPv4 header (with raw pointer).
 * These values are NULL if the packet is not IPv4.
 */
typedef struct ipv4info {
	uint8_t ipv4_ver;		/* IP version (4) */
	uint8_t ipv4_ihl;		/* header length, bytes */
	uint8_t ipv4_tos;		/* type of service field */
	uint16_t ipv4_length;		/* length (header + payload) */
	uint16_t ipv4_ident;		/* identification */
	uint8_t ipv4_flags;		/* IP flags */
	uint16_t ipv4_offset;		/* fragment offset */
	uint8_t ipv4_ttl;		/* time to live */
	uint8_t ipv4_protocol;		/* next level protocol */
	string ipv4_protostr;		/* next level protocol, as a string */
	uint16_t ipv4_checksum;		/* header checksum */
	ipaddr_t ipv4_src;		/* source address */
	ipaddr_t ipv4_dst;		/* destination address */
	string ipv4_saddr;		/* source address, string */
	string ipv4_daddr;		/* destination address, string */
	ipha_t *ipv4_hdr;		/* pointer to raw header */
} ipv4info_t;

/*
 * ipv6info is a translated version of the IPv6 header (with raw pointer).
 * These values are NULL if the packet is not IPv6.
 */
typedef struct ipv6info {
	uint8_t ipv6_ver;		/* IP version (6) */
	uint8_t ipv6_tclass;		/* traffic class */
	uint32_t ipv6_flow;		/* flow label */
	uint16_t ipv6_plen;		/* payload length */
	uint8_t ipv6_nexthdr;		/* next header protocol */
	string ipv6_nextstr;		/* next header protocol, as a string */
	uint8_t ipv6_hlim;		/* hop limit */
	in6_addr_t *ipv6_src;		/* source address */
	in6_addr_t *ipv6_dst;		/* destination address */
	string ipv6_saddr;		/* source address, string */
	string ipv6_daddr;		/* destination address, string */
	ip6_t *ipv6_hdr;		/* pointer to raw header */
} ipv6info_t;

/*
 * void_ip_t is a void pointer to either an IPv4 or IPv6 header.  It has
 * its own type name so that a translator can be determined.
 */
typedef uintptr_t void_ip_t;

/*
 * __dtrace_ipsr_ill_t is used by the translator to take an ill_t plus an
 * additional arg6 from the ip:::send and ip:::recieve probes, and translate
 * them to an ifinfo_t.
 */
typedef ill_t __dtrace_ipsr_ill_t;

/*
 * __dtrace_tcp_void_ip_t is used by the translator to take either the
 * non-NULL void_ip_t * passed in or, if it is NULL, uses arg3 (tcp_t *)
 * from the tcp:::send and tcp:::recieve probes to translate to an ipinfo_t.
 * When no headers are available in the TCP fusion case for tcp:::send
 * and tcp:::receive case, this allows us to present the consumer with header
 * data based on the tcp_t * content in order to hide the implementation
 * details of TCP fusion.
 */
typedef void * __dtrace_tcp_void_ip_t;

#pragma D binding "1.5" translator
translator pktinfo_t < mblk_t *M > {
	pkt_addr = NULL;
};

#pragma D binding "1.5" translator
translator csinfo_t < conn_t *C > {
	cs_addr = NULL;
};

#pragma D binding "1.6.3" translator
translator csinfo_t < ip_xmit_attr_t *C > {
	cs_addr = (uintptr_t)C;
	cs_cid = C ? C->ixa_conn_id : NULL;
	cs_pid = C ? C->ixa_cpid : -1;
	cs_zoneid = C ?
	    (C->ixa_ipst == NULL || C->ixa_ipst->ips_netstack == NULL ||
	    C->ixa_ipst->ips_netstack->netstack_stackid ==
	    @GLOBAL_NETSTACKID@ ||
	    C->ixa_cred == NULL ||
	    C->ixa_cred->cr_zone == NULL ||
	    C->ixa_cred->cr_uid == -1 ?
	    C->ixa_zoneid : C->ixa_cred->cr_zone->zone_id) : -1;
};

#pragma D binding "1.5" translator
translator ipinfo_t < ipha_t *I > {
	ip_ver = I->ipha_version_and_hdr_length >> 4;
	ip_plength = ntohs(I->ipha_length) -
	    ((I->ipha_version_and_hdr_length & 0xf) << 2);
	ip_saddr = inet_ntoa(&I->ipha_src);
	ip_daddr = inet_ntoa(&I->ipha_dst);
};

#pragma D binding "1.5" translator
translator ipinfo_t < ip6_t *I > {
	ip_ver = *(uint8_t *)I >> 4;
	ip_plength = ntohs(I->ip6_ctlun.ip6_un1.ip6_un1_plen);
	ip_saddr = inet_ntoa6(&I->ip6_src);
	ip_daddr = inet_ntoa6(&I->ip6_dst);
};

#pragma D binding "1.5" translator
translator ipinfo_t < void_ip_t *I > {
	ip_ver = I != NULL ? *(uint8_t *)I >> 4 : 0;
	ip_plength = I != NULL ? (*(uint8_t *)I >> 4 == 4 ?
	    ntohs(((ipha_t *)I)->ipha_length) -
	    ((((ipha_t *)I)->ipha_version_and_hdr_length & 0xf) << 2) :
	    *(uint8_t *)I >> 4 == 6 ?
	    ntohs(((ip6_t *)I)->ip6_ctlun.ip6_un1.ip6_un1_plen) : 0) : 0;
	ip_saddr = I != NULL ? (*(uint8_t *)I >> 4 == 4 ?
	    inet_ntoa(&((ipha_t *)I)->ipha_src) : *(uint8_t *)I >> 4 == 6 ?
	    inet_ntoa6(&((ip6_t *)I)->ip6_src) : "<unknown>") : "<unknown>";
	ip_daddr = I != NULL ? (*(uint8_t *)I >> 4 == 4 ?
	    inet_ntoa(&((ipha_t *)I)->ipha_dst) : *(uint8_t *)I >> 4 == 6 ?
	    inet_ntoa6(&((ip6_t *)I)->ip6_dst) : "<unknown>") : "<unknown>";
};

#pragma D binding "1.5" translator
translator ifinfo_t < __dtrace_ipsr_ill_t *I > {
	if_name = I != NULL ? stringof(I->ill_name) : "<null>";
	if_ipstack = I != NULL ? I->ill_ipst->ips_netstack->netstack_stackid
	    : 0;
	if_local = arg6;		/* probe dependent */
	if_addr = (uintptr_t)I;
};

/*
 * Translate to an ipinfo_t * from either the non-NULL void_ip_t * passed in,
 * or use arg3 (tcp_t *) to fabricate ip header info.
 */
#pragma D binding "1.6.3" translator
translator ipinfo_t < __dtrace_tcp_void_ip_t *I > {
	ip_ver = I != NULL ? *(uint8_t *)I >> 4 :
	    arg3 != NULL ? ((tcp_t *)arg3)->tcp_connp->conn_ipversion : 0;
	ip_plength =
	    I != NULL && *(uint8_t *)I >> 4 == 4 ?
	    ntohs(((ipha_t *)I)->ipha_length) -
	    ((((ipha_t *)I)->ipha_version_and_hdr_length & 0xf) << 2) :
	    I != NULL && *(uint8_t *)I >> 4 == 6 ?
	    ntohs(((ip6_t *)I)->ip6_ctlun.ip6_un1.ip6_un1_plen) :
	    I != NULL ? 0 :
	    arg3 != NULL && probename == "send" ?
	    ((tcp_t *)arg3)->tcp_last_sent_len + @TCP_MIN_HEADER_LENGTH@ :
	    arg3 != NULL && probename == "receive" ?
	    ((tcp_t *)arg3)->tcp_last_recv_len + @TCP_MIN_HEADER_LENGTH@ :
	    0;
	ip_saddr =
	    I != NULL && *(uint8_t *)I >> 4 == 4 ?
	    inet_ntoa(&((ipha_t *)I)->ipha_src) :
	    I != NULL && *(uint8_t *)I >> 4 == 6 ?
	    inet_ntoa6(&((ip6_t *)I)->ip6_src) :
	    I != NULL ? "<unknown>" :
	    arg3 != NULL && probename == "send" ?
	    inet_ntoa6(&((tcp_t *)arg3)->tcp_connp->connua_v6addr.connua_laddr):
	    arg3 != NULL && probename == "receive" ?
	    inet_ntoa6(&((tcp_t *)arg3)->tcp_connp->connua_v6addr.connua_faddr):
	    "<unknown>";
	ip_daddr =
	    I != NULL && *(uint8_t *)I >> 4 == 4 ?
	    inet_ntoa(&((ipha_t *)I)->ipha_dst) :
	    I != NULL && *(uint8_t *)I >> 4 == 6 ?
	    inet_ntoa6(&((ip6_t *)I)->ip6_dst) :
	    I != NULL ? "<unknown>" :
	    arg3 != NULL && probename == "send" ?
	    inet_ntoa6(&((tcp_t *)arg3)->tcp_connp->connua_v6addr.connua_faddr):
	    arg3 != NULL && probename == "receive" ?
	    inet_ntoa6(&((tcp_t *)arg3)->tcp_connp->connua_v6addr.connua_laddr):
	    "<unknown>";
};

#pragma D binding "1.5" translator
translator ipv4info_t < ipha_t *I > {
	ipv4_ver = I != NULL ? I->ipha_version_and_hdr_length >> 4 : 0;
	ipv4_ihl = I != NULL ? (I->ipha_version_and_hdr_length & 0xf) << 2 : 0;
	ipv4_tos = I != NULL ? I->ipha_type_of_service : 0;
	ipv4_length = I != NULL ? ntohs(I->ipha_length) : 0;
	ipv4_ident = I != NULL ? ntohs(I->ipha_ident) : 0;
	ipv4_flags = I != NULL ? ntohs(I->ipha_fragment_offset_and_flags) >>
	    12 : 0;
	ipv4_offset = I != NULL ? ntohs(I->ipha_fragment_offset_and_flags) &
	    0x0fff : 0;
	ipv4_ttl = I != NULL ? I->ipha_ttl : 0;
	ipv4_protocol = I != NULL ? I->ipha_protocol : 0;
	ipv4_protostr = I == NULL ? "<null>" :
	    I->ipha_protocol == IPPROTO_TCP     ? "TCP"    :
	    I->ipha_protocol == IPPROTO_UDP     ? "UDP"    :
	    I->ipha_protocol == IPPROTO_IP      ? "IP"     :
	    I->ipha_protocol == IPPROTO_ICMP    ? "ICMP"   :
	    I->ipha_protocol == IPPROTO_IGMP    ? "IGMP"   :
	    I->ipha_protocol == IPPROTO_EGP     ? "EGP"    :
	    I->ipha_protocol == IPPROTO_IPV6    ? "IPv6"   :
	    I->ipha_protocol == IPPROTO_ROUTING ? "ROUTE"  :
	    I->ipha_protocol == IPPROTO_ESP     ? "ESP"    :
	    I->ipha_protocol == IPPROTO_AH      ? "AH"     :
	    I->ipha_protocol == IPPROTO_ICMPV6  ? "ICMPv6" :
	    I->ipha_protocol == IPPROTO_OSPF    ? "OSPF"   :
	    I->ipha_protocol == IPPROTO_SCTP    ? "SCTP"   :
	    I->ipha_protocol == IPPROTO_RAW     ? "RAW"    :
	    lltostr((uint64_t)I->ipha_protocol);
	ipv4_checksum = I != NULL ? ntohs(I->ipha_hdr_checksum) : 0;
	ipv4_src = I != NULL ? I->ipha_src : 0;
	ipv4_dst = I != NULL ? I->ipha_dst : 0;
	ipv4_saddr = I != NULL ? inet_ntoa(&I->ipha_src) : "<null>";
	ipv4_daddr = I != NULL ? inet_ntoa(&I->ipha_dst) : "<null>";
	ipv4_hdr = I;
};

#pragma D binding "1.5" translator
translator ipv6info_t < ip6_t *I > {
	ipv6_ver = I != NULL ? I->ip6_ctlun.ip6_un2_vfc >> 4 : 0;
	ipv6_tclass = I != NULL ? ((I->ip6_ctlun.ip6_un1.ip6_un1_flow &&
	    0x0fffffff) >> 20) : 0;
	ipv6_flow = I != NULL ? I->ip6_ctlun.ip6_un1.ip6_un1_flow &&
	    0x000fffff : 0;
	ipv6_plen = I != NULL ? ntohs(I->ip6_ctlun.ip6_un1.ip6_un1_plen) : 0;
	ipv6_nexthdr = I != NULL ? I->ip6_ctlun.ip6_un1.ip6_un1_nxt : 0;
	ipv6_nextstr = I == NULL ? "<null>" :
	    I->ip6_ctlun.ip6_un1.ip6_un1_nxt == IPPROTO_TCP     ? "TCP"    :
	    I->ip6_ctlun.ip6_un1.ip6_un1_nxt == IPPROTO_UDP     ? "UDP"    :
	    I->ip6_ctlun.ip6_un1.ip6_un1_nxt == IPPROTO_IP      ? "IP"     :
	    I->ip6_ctlun.ip6_un1.ip6_un1_nxt == IPPROTO_ICMP    ? "ICMP"   :
	    I->ip6_ctlun.ip6_un1.ip6_un1_nxt == IPPROTO_IGMP    ? "IGMP"   :
	    I->ip6_ctlun.ip6_un1.ip6_un1_nxt == IPPROTO_EGP     ? "EGP"    :
	    I->ip6_ctlun.ip6_un1.ip6_un1_nxt == IPPROTO_IPV6    ? "IPv6"   :
	    I->ip6_ctlun.ip6_un1.ip6_un1_nxt == IPPROTO_ROUTING ? "ROUTE"  :
	    I->ip6_ctlun.ip6_un1.ip6_un1_nxt == IPPROTO_ESP     ? "ESP"    :
	    I->ip6_ctlun.ip6_un1.ip6_un1_nxt == IPPROTO_AH      ? "AH"     :
	    I->ip6_ctlun.ip6_un1.ip6_un1_nxt == IPPROTO_ICMPV6  ? "ICMPv6" :
	    I->ip6_ctlun.ip6_un1.ip6_un1_nxt == IPPROTO_OSPF    ? "OSPF"   :
	    I->ip6_ctlun.ip6_un1.ip6_un1_nxt == IPPROTO_SCTP    ? "SCTP"   :
	    I->ip6_ctlun.ip6_un1.ip6_un1_nxt == IPPROTO_RAW     ? "RAW"    :
	    lltostr((uint64_t)I->ip6_ctlun.ip6_un1.ip6_un1_nxt);
	ipv6_hlim = I != NULL ? I->ip6_ctlun.ip6_un1.ip6_un1_hlim : 0;
	ipv6_src = I != NULL ? &I->ip6_src : 0;
	ipv6_dst = I != NULL ? &I->ip6_dst : 0;
	ipv6_saddr = I != NULL ? inet_ntoa6(&I->ip6_src) : "<null>";
	ipv6_daddr = I != NULL ? inet_ntoa6(&I->ip6_dst) : "<null>";
	ipv6_hdr = I;
};