xref: /freebsd/cddl/lib/libdtrace/udp.d (revision d0b2dbfa0ecf2bbc9709efc5e20baf8e4b44bbbf)
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 (c) 2010, Oracle and/or its affiliates. All rights reserved.
23  * Copyright (c) 2013 Mark Johnston <markj@FreeBSD.org>
24  */
25 
26 #pragma D depends_on library ip.d
27 #pragma D depends_on module kernel
28 #pragma D depends_on provider udp
29 
30 /*
31  * udpsinfo contains stable UDP details.
32  */
33 typedef struct udpsinfo {
34 	uintptr_t udps_addr;
35 	uint16_t udps_lport;		/* local port */
36 	uint16_t udps_rport;		/* remote port */
37 	string udps_laddr;		/* local address, as a string */
38 	string udps_raddr;		/* remote address, as a string */
39 } udpsinfo_t;
40 
41 /*
42  * udpinfo is the UDP header fields.
43  */
44 typedef struct udpinfo {
45 	uint16_t udp_sport;		/* source port */
46 	uint16_t udp_dport;		/* destination port */
47 	uint16_t udp_length;		/* total length */
48 	uint16_t udp_checksum;		/* headers + data checksum */
49 	struct udphdr *udp_hdr;		/* raw UDP header */
50 } udpinfo_t;
51 
52 #pragma D binding "1.6.3" translator
53 translator udpsinfo_t < struct inpcb *p > {
54 	udps_addr =	(uintptr_t)p;
55 	udps_lport =	p == NULL ? 0 : ntohs(p->inp_inc.inc_ie.ie_lport);
56 	udps_rport =	p == NULL ? 0 : ntohs(p->inp_inc.inc_ie.ie_fport);
57 	udps_laddr =	p == NULL ? "<unknown>" :
58 	    p->inp_vflag == INP_IPV4 ?
59 	    inet_ntoa(&p->inp_inc.inc_ie.ie_dependladdr.id46_addr.ia46_addr4.s_addr) :
60 	    inet_ntoa6(&p->inp_inc.inc_ie.ie_dependladdr.id6_addr);
61 	udps_raddr =	p == NULL ? "<unknown>" :
62 	    p->inp_vflag == INP_IPV4 ?
63 	    inet_ntoa(&p->inp_inc.inc_ie.ie_dependfaddr.id46_addr.ia46_addr4.s_addr) :
64 	    inet_ntoa6(&p->inp_inc.inc_ie.ie_dependfaddr.id6_addr);
65 };
66 
67 #pragma D binding "1.6.3" translator
68 translator udpinfo_t < struct udphdr *p > {
69 	udp_sport =	p == NULL ? 0 : ntohs(p->uh_sport);
70 	udp_dport =	p == NULL ? 0 : ntohs(p->uh_dport);
71 	udp_length =	p == NULL ? 0 : ntohs(p->uh_ulen);
72 	udp_checksum =	p == NULL ? 0 : ntohs(p->uh_sum);
73 	udp_hdr =	p;
74 };
75