xref: /freebsd/cddl/lib/libdtrace/udp.d (revision b3e7694832e81d7a904a10f525f8797b753bf0d3)
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 /*
2257f60867SMark Johnston  * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
2357f60867SMark Johnston  * Copyright (c) 2013 Mark Johnston <markj@FreeBSD.org>
2457f60867SMark Johnston  */
2557f60867SMark Johnston 
2657f60867SMark Johnston #pragma D depends_on library ip.d
277e518a66SMark Johnston #pragma D depends_on module kernel
2857f60867SMark Johnston #pragma D depends_on provider udp
2957f60867SMark Johnston 
3057f60867SMark Johnston /*
3157f60867SMark Johnston  * udpsinfo contains stable UDP details.
3257f60867SMark Johnston  */
3357f60867SMark Johnston typedef struct udpsinfo {
3457f60867SMark Johnston 	uintptr_t udps_addr;
3557f60867SMark Johnston 	uint16_t udps_lport;		/* local port */
3657f60867SMark Johnston 	uint16_t udps_rport;		/* remote port */
3757f60867SMark Johnston 	string udps_laddr;		/* local address, as a string */
3857f60867SMark Johnston 	string udps_raddr;		/* remote address, as a string */
3957f60867SMark Johnston } udpsinfo_t;
4057f60867SMark Johnston 
4157f60867SMark Johnston /*
4257f60867SMark Johnston  * udpinfo is the UDP header fields.
4357f60867SMark Johnston  */
4457f60867SMark Johnston typedef struct udpinfo {
4557f60867SMark Johnston 	uint16_t udp_sport;		/* source port */
4657f60867SMark Johnston 	uint16_t udp_dport;		/* destination port */
4757f60867SMark Johnston 	uint16_t udp_length;		/* total length */
4857f60867SMark Johnston 	uint16_t udp_checksum;		/* headers + data checksum */
4957f60867SMark Johnston 	struct udphdr *udp_hdr;		/* raw UDP header */
5057f60867SMark Johnston } udpinfo_t;
5157f60867SMark Johnston 
522f28ceebSMark Johnston #pragma D binding "1.6.3" translator
5357f60867SMark Johnston translator udpsinfo_t < struct inpcb *p > {
5457f60867SMark Johnston 	udps_addr =	(uintptr_t)p;
5557f60867SMark Johnston 	udps_lport =	p == NULL ? 0 : ntohs(p->inp_inc.inc_ie.ie_lport);
5657f60867SMark Johnston 	udps_rport =	p == NULL ? 0 : ntohs(p->inp_inc.inc_ie.ie_fport);
57*7575d3dfSMichael Tuexen 	udps_laddr =	p == NULL ? "<unknown>" :
5857f60867SMark Johnston 	    p->inp_vflag == INP_IPV4 ?
598d7181d1SSean Bruno 	    inet_ntoa(&p->inp_inc.inc_ie.ie_dependladdr.id46_addr.ia46_addr4.s_addr) :
608d7181d1SSean Bruno 	    inet_ntoa6(&p->inp_inc.inc_ie.ie_dependladdr.id6_addr);
61*7575d3dfSMichael Tuexen 	udps_raddr =	p == NULL ? "<unknown>" :
6257f60867SMark Johnston 	    p->inp_vflag == INP_IPV4 ?
638d7181d1SSean Bruno 	    inet_ntoa(&p->inp_inc.inc_ie.ie_dependfaddr.id46_addr.ia46_addr4.s_addr) :
648d7181d1SSean Bruno 	    inet_ntoa6(&p->inp_inc.inc_ie.ie_dependfaddr.id6_addr);
6557f60867SMark Johnston };
6657f60867SMark Johnston 
672f28ceebSMark Johnston #pragma D binding "1.6.3" translator
6857f60867SMark Johnston translator udpinfo_t < struct udphdr *p > {
6957f60867SMark Johnston 	udp_sport =	p == NULL ? 0 : ntohs(p->uh_sport);
7057f60867SMark Johnston 	udp_dport =	p == NULL ? 0 : ntohs(p->uh_dport);
7157f60867SMark Johnston 	udp_length =	p == NULL ? 0 : ntohs(p->uh_ulen);
7257f60867SMark Johnston 	udp_checksum =	p == NULL ? 0 : ntohs(p->uh_sum);
7357f60867SMark Johnston 	udp_hdr =	p;
7457f60867SMark Johnston };
75