xref: /freebsd/cddl/lib/libdtrace/udp.d (revision 57f6086735175ec16d6ba1b51128a7ae2dadd373)
1*57f60867SMark Johnston /*
2*57f60867SMark Johnston  * CDDL HEADER START
3*57f60867SMark Johnston  *
4*57f60867SMark Johnston  * The contents of this file are subject to the terms of the
5*57f60867SMark Johnston  * Common Development and Distribution License (the "License").
6*57f60867SMark Johnston  * You may not use this file except in compliance with the License.
7*57f60867SMark Johnston  *
8*57f60867SMark Johnston  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9*57f60867SMark Johnston  * or http://www.opensolaris.org/os/licensing.
10*57f60867SMark Johnston  * See the License for the specific language governing permissions
11*57f60867SMark Johnston  * and limitations under the License.
12*57f60867SMark Johnston  *
13*57f60867SMark Johnston  * When distributing Covered Code, include this CDDL HEADER in each
14*57f60867SMark Johnston  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15*57f60867SMark Johnston  * If applicable, add the following below this CDDL HEADER, with the
16*57f60867SMark Johnston  * fields enclosed by brackets "[]" replaced with your own identifying
17*57f60867SMark Johnston  * information: Portions Copyright [yyyy] [name of copyright owner]
18*57f60867SMark Johnston  *
19*57f60867SMark Johnston  * CDDL HEADER END
20*57f60867SMark Johnston  *
21*57f60867SMark Johnston  * $FreeBSD$
22*57f60867SMark Johnston  */
23*57f60867SMark Johnston /*
24*57f60867SMark Johnston  * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
25*57f60867SMark Johnston  * Copyright (c) 2013 Mark Johnston <markj@FreeBSD.org>
26*57f60867SMark Johnston  */
27*57f60867SMark Johnston 
28*57f60867SMark Johnston #pragma D depends_on library ip.d
29*57f60867SMark Johnston #pragma D depends_on provider udp
30*57f60867SMark Johnston 
31*57f60867SMark Johnston /*
32*57f60867SMark Johnston  * udpsinfo contains stable UDP details.
33*57f60867SMark Johnston  */
34*57f60867SMark Johnston typedef struct udpsinfo {
35*57f60867SMark Johnston 	uintptr_t udps_addr;
36*57f60867SMark Johnston 	uint16_t udps_lport;		/* local port */
37*57f60867SMark Johnston 	uint16_t udps_rport;		/* remote port */
38*57f60867SMark Johnston 	string udps_laddr;		/* local address, as a string */
39*57f60867SMark Johnston 	string udps_raddr;		/* remote address, as a string */
40*57f60867SMark Johnston } udpsinfo_t;
41*57f60867SMark Johnston 
42*57f60867SMark Johnston /*
43*57f60867SMark Johnston  * udpinfo is the UDP header fields.
44*57f60867SMark Johnston  */
45*57f60867SMark Johnston typedef struct udpinfo {
46*57f60867SMark Johnston 	uint16_t udp_sport;		/* source port */
47*57f60867SMark Johnston 	uint16_t udp_dport;		/* destination port */
48*57f60867SMark Johnston 	uint16_t udp_length;		/* total length */
49*57f60867SMark Johnston 	uint16_t udp_checksum;          /* headers + data checksum */
50*57f60867SMark Johnston 	struct udphdr *udp_hdr;		/* raw UDP header */
51*57f60867SMark Johnston } udpinfo_t;
52*57f60867SMark Johnston 
53*57f60867SMark Johnston #pragma D binding "1.0" translator
54*57f60867SMark Johnston translator udpsinfo_t < struct inpcb *p > {
55*57f60867SMark Johnston 	udps_addr =	(uintptr_t)p;
56*57f60867SMark Johnston 	udps_lport =	p == NULL ? 0 : ntohs(p->inp_inc.inc_ie.ie_lport);
57*57f60867SMark Johnston 	udps_rport =	p == NULL ? 0 : ntohs(p->inp_inc.inc_ie.ie_fport);
58*57f60867SMark Johnston 	udps_laddr =	p == NULL ? "" :
59*57f60867SMark Johnston 	    p->inp_vflag == INP_IPV4 ?
60*57f60867SMark Johnston 	    inet_ntoa(&p->inp_inc.inc_ie.ie_dependladdr.ie46_local.ia46_addr4.s_addr) :
61*57f60867SMark Johnston 	    inet_ntoa6(&p->inp_inc.inc_ie.ie_dependladdr.ie6_local);
62*57f60867SMark Johnston 	udps_raddr =	p == NULL ? "" :
63*57f60867SMark Johnston 	    p->inp_vflag == INP_IPV4 ?
64*57f60867SMark Johnston 	    inet_ntoa(&p->inp_inc.inc_ie.ie_dependfaddr.ie46_foreign.ia46_addr4.s_addr) :
65*57f60867SMark Johnston 	    inet_ntoa6(&p->inp_inc.inc_ie.ie_dependfaddr.ie6_foreign);
66*57f60867SMark Johnston };
67*57f60867SMark Johnston 
68*57f60867SMark Johnston #pragma D binding "1.0" translator
69*57f60867SMark Johnston translator udpinfo_t < struct udphdr *p > {
70*57f60867SMark Johnston 	udp_sport =	p == NULL ? 0 : ntohs(p->uh_sport);
71*57f60867SMark Johnston 	udp_dport =	p == NULL ? 0 : ntohs(p->uh_dport);
72*57f60867SMark Johnston 	udp_length =	p == NULL ? 0 : ntohs(p->uh_ulen);
73*57f60867SMark Johnston 	udp_checksum =	p == NULL ? 0 : ntohs(p->uh_sum);
74*57f60867SMark Johnston 	udp_hdr =	p;
75*57f60867SMark Johnston };
76