xref: /freebsd/cddl/lib/libdtrace/udp.d (revision 2f28ceeb34d0de48ec59674099ac4ecbc1d15d8c)
157f60867SMark Johnston /*
257f60867SMark Johnston  * CDDL HEADER START
357f60867SMark Johnston  *
457f60867SMark Johnston  * The contents of this file are subject to the terms of the
557f60867SMark Johnston  * Common Development and Distribution License (the "License").
657f60867SMark Johnston  * You may not use this file except in compliance with the License.
757f60867SMark Johnston  *
857f60867SMark Johnston  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
957f60867SMark Johnston  * or http://www.opensolaris.org/os/licensing.
1057f60867SMark Johnston  * See the License for the specific language governing permissions
1157f60867SMark Johnston  * and limitations under the License.
1257f60867SMark Johnston  *
1357f60867SMark Johnston  * When distributing Covered Code, include this CDDL HEADER in each
1457f60867SMark Johnston  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
1557f60867SMark Johnston  * If applicable, add the following below this CDDL HEADER, with the
1657f60867SMark Johnston  * fields enclosed by brackets "[]" replaced with your own identifying
1757f60867SMark Johnston  * information: Portions Copyright [yyyy] [name of copyright owner]
1857f60867SMark Johnston  *
1957f60867SMark Johnston  * CDDL HEADER END
2057f60867SMark Johnston  *
2157f60867SMark Johnston  * $FreeBSD$
2257f60867SMark Johnston  */
2357f60867SMark Johnston /*
2457f60867SMark Johnston  * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
2557f60867SMark Johnston  * Copyright (c) 2013 Mark Johnston <markj@FreeBSD.org>
2657f60867SMark Johnston  */
2757f60867SMark Johnston 
2857f60867SMark Johnston #pragma D depends_on library ip.d
2957f60867SMark Johnston #pragma D depends_on provider udp
3057f60867SMark Johnston 
3157f60867SMark Johnston /*
3257f60867SMark Johnston  * udpsinfo contains stable UDP details.
3357f60867SMark Johnston  */
3457f60867SMark Johnston typedef struct udpsinfo {
3557f60867SMark Johnston 	uintptr_t udps_addr;
3657f60867SMark Johnston 	uint16_t udps_lport;		/* local port */
3757f60867SMark Johnston 	uint16_t udps_rport;		/* remote port */
3857f60867SMark Johnston 	string udps_laddr;		/* local address, as a string */
3957f60867SMark Johnston 	string udps_raddr;		/* remote address, as a string */
4057f60867SMark Johnston } udpsinfo_t;
4157f60867SMark Johnston 
4257f60867SMark Johnston /*
4357f60867SMark Johnston  * udpinfo is the UDP header fields.
4457f60867SMark Johnston  */
4557f60867SMark Johnston typedef struct udpinfo {
4657f60867SMark Johnston 	uint16_t udp_sport;		/* source port */
4757f60867SMark Johnston 	uint16_t udp_dport;		/* destination port */
4857f60867SMark Johnston 	uint16_t udp_length;		/* total length */
4957f60867SMark Johnston 	uint16_t udp_checksum;          /* headers + data checksum */
5057f60867SMark Johnston 	struct udphdr *udp_hdr;		/* raw UDP header */
5157f60867SMark Johnston } udpinfo_t;
5257f60867SMark Johnston 
53*2f28ceebSMark Johnston #pragma D binding "1.6.3" translator
5457f60867SMark Johnston translator udpsinfo_t < struct inpcb *p > {
5557f60867SMark Johnston 	udps_addr =	(uintptr_t)p;
5657f60867SMark Johnston 	udps_lport =	p == NULL ? 0 : ntohs(p->inp_inc.inc_ie.ie_lport);
5757f60867SMark Johnston 	udps_rport =	p == NULL ? 0 : ntohs(p->inp_inc.inc_ie.ie_fport);
5857f60867SMark Johnston 	udps_laddr =	p == NULL ? "" :
5957f60867SMark Johnston 	    p->inp_vflag == INP_IPV4 ?
6057f60867SMark Johnston 	    inet_ntoa(&p->inp_inc.inc_ie.ie_dependladdr.ie46_local.ia46_addr4.s_addr) :
6157f60867SMark Johnston 	    inet_ntoa6(&p->inp_inc.inc_ie.ie_dependladdr.ie6_local);
6257f60867SMark Johnston 	udps_raddr =	p == NULL ? "" :
6357f60867SMark Johnston 	    p->inp_vflag == INP_IPV4 ?
6457f60867SMark Johnston 	    inet_ntoa(&p->inp_inc.inc_ie.ie_dependfaddr.ie46_foreign.ia46_addr4.s_addr) :
6557f60867SMark Johnston 	    inet_ntoa6(&p->inp_inc.inc_ie.ie_dependfaddr.ie6_foreign);
6657f60867SMark Johnston };
6757f60867SMark Johnston 
68*2f28ceebSMark Johnston #pragma D binding "1.6.3" translator
6957f60867SMark Johnston translator udpinfo_t < struct udphdr *p > {
7057f60867SMark Johnston 	udp_sport =	p == NULL ? 0 : ntohs(p->uh_sport);
7157f60867SMark Johnston 	udp_dport =	p == NULL ? 0 : ntohs(p->uh_dport);
7257f60867SMark Johnston 	udp_length =	p == NULL ? 0 : ntohs(p->uh_ulen);
7357f60867SMark Johnston 	udp_checksum =	p == NULL ? 0 : ntohs(p->uh_sum);
7457f60867SMark Johnston 	udp_hdr =	p;
7557f60867SMark Johnston };
76