xref: /illumos-gate/usr/src/lib/libdtrace/common/ip.d.in (revision a18dc42fc967d11feba9b8be61c6727dc6c56b48)
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 2007 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
31inline int IPH_DF = @IPH_DF@;
32#pragma D binding "1.0" IPH_DF
33inline int IPH_MF = @IPH_MF@;
34#pragma D binding "1.0" IPH_MF
35
36#pragma D binding "1.0" IPPROTO_IP
37inline int IPPROTO_IP = @IPPROTO_IP@;
38#pragma D binding "1.0" IPPROTO_HOPOPTS
39inline int IPPROTO_HOPOPTS = @IPPROTO_HOPOPTS@;
40#pragma D binding "1.0" IPPROTO_ICMP
41inline int IPPROTO_ICMP = @IPPROTO_ICMP@;
42#pragma D binding "1.0" IPPROTO_IGMP
43inline int IPPROTO_IGMP = @IPPROTO_IGMP@;
44#pragma D binding "1.0" IPPROTO_GGP
45inline int IPPROTO_GGP = @IPPROTO_GGP@;
46#pragma D binding "1.0" IPPROTO_ENCAP
47inline int IPPROTO_ENCAP = @IPPROTO_ENCAP@;
48#pragma D binding "1.0" IPPROTO_TCP
49inline int IPPROTO_TCP = @IPPROTO_TCP@;
50#pragma D binding "1.0" IPPROTO_EGP
51inline int IPPROTO_EGP = @IPPROTO_EGP@;
52#pragma D binding "1.0" IPPROTO_PUP
53inline int IPPROTO_PUP = @IPPROTO_PUP@;
54#pragma D binding "1.0" IPPROTO_UDP
55inline int IPPROTO_UDP = @IPPROTO_UDP@;
56#pragma D binding "1.0" IPPROTO_IDP
57inline int IPPROTO_IDP = @IPPROTO_IDP@;
58#pragma D binding "1.0" IPPROTO_IPV6
59inline int IPPROTO_IPV6 = @IPPROTO_IPV6@;
60#pragma D binding "1.0" IPPROTO_ROUTING
61inline int IPPROTO_ROUTING = @IPPROTO_ROUTING@;
62#pragma D binding "1.0" IPPROTO_FRAGMENT
63inline int IPPROTO_FRAGMENT = @IPPROTO_FRAGMENT@;
64#pragma D binding "1.0" IPPROTO_RSVP
65inline int IPPROTO_RSVP = @IPPROTO_RSVP@;
66#pragma D binding "1.0" IPPROTO_ESP
67inline int IPPROTO_ESP = @IPPROTO_ESP@;
68#pragma D binding "1.0" IPPROTO_AH
69inline int IPPROTO_AH = @IPPROTO_AH@;
70#pragma D binding "1.0" IPPROTO_ICMPV6
71inline int IPPROTO_ICMPV6 = @IPPROTO_ICMPV6@;
72#pragma D binding "1.0" IPPROTO_NONE
73inline int IPPROTO_NONE = @IPPROTO_NONE@;
74#pragma D binding "1.0" IPPROTO_DSTOPTS
75inline int IPPROTO_DSTOPTS = @IPPROTO_DSTOPTS@;
76#pragma D binding "1.0" IPPROTO_HELLO
77inline int IPPROTO_HELLO = @IPPROTO_HELLO@;
78#pragma D binding "1.0" IPPROTO_ND
79inline int IPPROTO_ND = @IPPROTO_ND@;
80#pragma D binding "1.0" IPPROTO_EON
81inline int IPPROTO_EON = @IPPROTO_EON@;
82#pragma D binding "1.0" IPPROTO_OSPF
83inline int IPPROTO_OSPF = @IPPROTO_OSPF@;
84#pragma D binding "1.0" IPPROTO_PIM
85inline int IPPROTO_PIM = @IPPROTO_PIM@;
86#pragma D binding "1.0" IPPROTO_SCTP
87inline int IPPROTO_SCTP = @IPPROTO_SCTP@;
88#pragma D binding "1.0" IPPROTO_RAW
89inline int IPPROTO_RAW = @IPPROTO_RAW@;
90#pragma D binding "1.0" IPPROTO_MAX
91inline 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 */
98typedef 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 */
107typedef struct csinfo {
108	uintptr_t cs_addr;
109} csinfo_t;
110
111/*
112 * ipinfo contains common IP info for both IPv4 and IPv6.
113 */
114typedef 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 */
124typedef 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 */
135typedef 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 */
158typedef 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 */
177typedef 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 */
184typedef ill_t __dtrace_ipsr_ill_t;
185
186#pragma D binding "1.0" translator
187translator pktinfo_t < mblk_t *M > {
188	pkt_addr = NULL;
189};
190
191#pragma D binding "1.0" translator
192translator csinfo_t < conn_t *C > {
193	cs_addr = NULL;
194};
195
196#pragma D binding "1.0" translator
197translator ipinfo_t < ipha_t *I > {
198	ip_ver = I->ipha_version_and_hdr_length >> 4;
199	ip_plength = ntohs(I->ipha_length) -
200	    ((I->ipha_version_and_hdr_length & 0xf) << 2);
201	ip_saddr = inet_ntoa(&I->ipha_src);
202	ip_daddr = inet_ntoa(&I->ipha_dst);
203};
204
205#pragma D binding "1.0" translator
206translator ipinfo_t < ip6_t *I > {
207	ip_ver = *(uint8_t *)I >> 4;
208	ip_plength = ntohs(I->ip6_ctlun.ip6_un1.ip6_un1_plen);
209	ip_saddr = inet_ntoa6(&I->ip6_src);
210	ip_daddr = inet_ntoa6(&I->ip6_dst);
211};
212
213#pragma D binding "1.0" translator
214translator ipinfo_t < void_ip_t *I > {
215	ip_ver = I != NULL ? *(uint8_t *)I >> 4 : 0;
216	ip_plength = I != NULL ? (*(uint8_t *)I >> 4 == 4 ?
217	    ntohs(((ipha_t *)I)->ipha_length) -
218	    ((((ipha_t *)I)->ipha_version_and_hdr_length & 0xf) << 2) :
219	    *(uint8_t *)I >> 4 == 6 ?
220	    ntohs(((ip6_t *)I)->ip6_ctlun.ip6_un1.ip6_un1_plen) : 0) : 0;
221	ip_saddr = I != NULL ? (*(uint8_t *)I >> 4 == 4 ?
222	    inet_ntoa(&((ipha_t *)I)->ipha_src) : *(uint8_t *)I >> 4 == 6 ?
223	    inet_ntoa6(&((ip6_t *)I)->ip6_src) : "<unknown>") : "<unknown>";
224	ip_daddr = I != NULL ? (*(uint8_t *)I >> 4 == 4 ?
225	    inet_ntoa(&((ipha_t *)I)->ipha_dst) : *(uint8_t *)I >> 4 == 6 ?
226	    inet_ntoa6(&((ip6_t *)I)->ip6_dst) : "<unknown>") : "<unknown>";
227};
228
229#pragma D binding "1.0" translator
230translator ifinfo_t < __dtrace_ipsr_ill_t *I > {
231	if_name = I != NULL ? stringof(I->ill_name) : "<null>";
232	if_ipstack = I != NULL ? I->ill_ipst->ips_netstack->netstack_stackid
233	    : 0;
234	if_local = arg6;		/* probe dependent */
235	if_addr = (uintptr_t)I;
236};
237
238#pragma D binding "1.0" translator
239translator ipv4info_t < ipha_t *I > {
240	ipv4_ver = I != NULL ? I->ipha_version_and_hdr_length >> 4 : 0;
241	ipv4_ihl = I != NULL ? (I->ipha_version_and_hdr_length & 0xf) << 2 : 0;
242	ipv4_tos = I != NULL ? I->ipha_type_of_service : 0;
243	ipv4_length = I != NULL ? ntohs(I->ipha_length) : 0;
244	ipv4_ident = I != NULL ? ntohs(I->ipha_ident) : 0;
245	ipv4_flags = I != NULL ? ntohs(I->ipha_fragment_offset_and_flags) >>
246	    12 : 0;
247	ipv4_offset = I != NULL ? ntohs(I->ipha_fragment_offset_and_flags) &
248	    0x0fff : 0;
249	ipv4_ttl = I != NULL ? I->ipha_ttl : 0;
250	ipv4_protocol = I != NULL ? I->ipha_protocol : 0;
251	ipv4_protostr = I == NULL ? "<null>" :
252	    I->ipha_protocol == IPPROTO_TCP     ? "TCP"    :
253	    I->ipha_protocol == IPPROTO_UDP     ? "UDP"    :
254	    I->ipha_protocol == IPPROTO_IP      ? "IP"     :
255	    I->ipha_protocol == IPPROTO_ICMP    ? "ICMP"   :
256	    I->ipha_protocol == IPPROTO_IGMP    ? "IGMP"   :
257	    I->ipha_protocol == IPPROTO_EGP     ? "EGP"    :
258	    I->ipha_protocol == IPPROTO_IPV6    ? "IPv6"   :
259	    I->ipha_protocol == IPPROTO_ROUTING ? "ROUTE"  :
260	    I->ipha_protocol == IPPROTO_ESP     ? "ESP"    :
261	    I->ipha_protocol == IPPROTO_AH      ? "AH"     :
262	    I->ipha_protocol == IPPROTO_ICMPV6  ? "ICMPv6" :
263	    I->ipha_protocol == IPPROTO_OSPF    ? "OSPF"   :
264	    I->ipha_protocol == IPPROTO_SCTP    ? "SCTP"   :
265	    I->ipha_protocol == IPPROTO_RAW     ? "RAW"    :
266	    lltostr((uint64_t)I->ipha_protocol);
267	ipv4_checksum = I != NULL ? ntohs(I->ipha_hdr_checksum) : 0;
268	ipv4_src = I != NULL ? I->ipha_src : 0;
269	ipv4_dst = I != NULL ? I->ipha_dst : 0;
270	ipv4_saddr = I != NULL ? inet_ntoa(&I->ipha_src) : "<null>";
271	ipv4_daddr = I != NULL ? inet_ntoa(&I->ipha_dst) : "<null>";
272	ipv4_hdr = I;
273};
274
275#pragma D binding "1.0" translator
276translator ipv6info_t < ip6_t *I > {
277	ipv6_ver = I != NULL ? I->ip6_ctlun.ip6_un2_vfc >> 4 : 0;
278	ipv6_tclass = I != NULL ? ((I->ip6_ctlun.ip6_un1.ip6_un1_flow &&
279	    0x0fffffff) >> 20) : 0;
280	ipv6_flow = I != NULL ? I->ip6_ctlun.ip6_un1.ip6_un1_flow &&
281	    0x000fffff : 0;
282	ipv6_plen = I != NULL ? ntohs(I->ip6_ctlun.ip6_un1.ip6_un1_plen) : 0;
283	ipv6_nexthdr = I != NULL ? I->ip6_ctlun.ip6_un1.ip6_un1_nxt : 0;
284	ipv6_nextstr = I == NULL ? "<null>" :
285	    I->ip6_ctlun.ip6_un1.ip6_un1_nxt == IPPROTO_TCP     ? "TCP"    :
286	    I->ip6_ctlun.ip6_un1.ip6_un1_nxt == IPPROTO_UDP     ? "UDP"    :
287	    I->ip6_ctlun.ip6_un1.ip6_un1_nxt == IPPROTO_IP      ? "IP"     :
288	    I->ip6_ctlun.ip6_un1.ip6_un1_nxt == IPPROTO_ICMP    ? "ICMP"   :
289	    I->ip6_ctlun.ip6_un1.ip6_un1_nxt == IPPROTO_IGMP    ? "IGMP"   :
290	    I->ip6_ctlun.ip6_un1.ip6_un1_nxt == IPPROTO_EGP     ? "EGP"    :
291	    I->ip6_ctlun.ip6_un1.ip6_un1_nxt == IPPROTO_IPV6    ? "IPv6"   :
292	    I->ip6_ctlun.ip6_un1.ip6_un1_nxt == IPPROTO_ROUTING ? "ROUTE"  :
293	    I->ip6_ctlun.ip6_un1.ip6_un1_nxt == IPPROTO_ESP     ? "ESP"    :
294	    I->ip6_ctlun.ip6_un1.ip6_un1_nxt == IPPROTO_AH      ? "AH"     :
295	    I->ip6_ctlun.ip6_un1.ip6_un1_nxt == IPPROTO_ICMPV6  ? "ICMPv6" :
296	    I->ip6_ctlun.ip6_un1.ip6_un1_nxt == IPPROTO_OSPF    ? "OSPF"   :
297	    I->ip6_ctlun.ip6_un1.ip6_un1_nxt == IPPROTO_SCTP    ? "SCTP"   :
298	    I->ip6_ctlun.ip6_un1.ip6_un1_nxt == IPPROTO_RAW     ? "RAW"    :
299	    lltostr((uint64_t)I->ip6_ctlun.ip6_un1.ip6_un1_nxt);
300	ipv6_hlim = I != NULL ? I->ip6_ctlun.ip6_un1.ip6_un1_hlim : 0;
301	ipv6_src = I != NULL ? &I->ip6_src : 0;
302	ipv6_dst = I != NULL ? &I->ip6_dst : 0;
303	ipv6_saddr = I != NULL ? inet_ntoa6(&I->ip6_src) : "<null>";
304	ipv6_daddr = I != NULL ? inet_ntoa6(&I->ip6_dst) : "<null>";
305	ipv6_hdr = I;
306};
307