File: udp.d

package info (click to toggle)
dtrace 2.0.5-1
  • links: PTS
  • area: main
  • in suites: sid
  • size: 24,408 kB
  • sloc: ansic: 61,247; sh: 17,997; asm: 1,717; lex: 947; awk: 754; yacc: 695; perl: 37; sed: 17; makefile: 15
file content (72 lines) | stat: -rw-r--r-- 2,439 bytes parent folder | download | duplicates (17)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
/*
 * Oracle Linux DTrace.
 * Copyright (c) 2010, 2025, Oracle and/or its affiliates. All rights reserved.
 * Licensed under the Universal Permissive License v 1.0 as shown at
 * http://oss.oracle.com/licenses/upl.
 */

#pragma D depends_on module vmlinux
#pragma D depends_on library net.d
#pragma D depends_on library ip.d
#pragma D depends_on provider udp

/*
 * udpinfo is the UDP header fields.
 */
typedef struct udpinfo {
	uint16_t udp_sport;		/* source port */
	uint16_t udp_dport;		/* destination port */
	uint16_t udp_length;		/* total length */
	uint16_t udp_checksum;          /* headers + data checksum */
	struct udphdr *udp_hdr;		/* raw UDP header */
} udpinfo_t;

/*
 * udpsinfo contains stable UDP details from udp_t.
 */
typedef struct udpsinfo {
	uintptr_t udps_addr;
	uint16_t udps_lport;		/* local port */
	uint16_t udps_rport;		/* remote port */
	string udps_laddr;		/* local address, as a string */
	string udps_raddr;		/* remote address, as a string */
} udpsinfo_t;

#pragma D binding "1.6.3" translator
translator udpinfo_t < struct udphdr *U > {
	udp_sport = ntohs(U->source);
	udp_dport = ntohs(U->dest);
	udp_length = ntohs(U->len);
	udp_checksum = ntohs(U->check);
	udp_hdr = U;
};

#pragma D binding "1.6.3" translator
translator udpsinfo_t < struct udp_sock *S > {
	/*
	 * We source udp info from other args but retain the sock arg here
	 * as it may be used in the future.
	 */
	udps_addr = (uintptr_t)S;
	udps_lport = arg4 ?
	    (arg5 == NET_PROBE_OUTBOUND ? ntohs(((struct udphdr *)arg4)->source) :
	    ntohs(((struct udphdr *)arg4)->dest)) : 0;
	udps_rport = arg4 ?
	    (probename == "send" ? ntohs(((struct udphdr *)arg4)->dest) :
	    ntohs(((struct udphdr *)arg4)->source)) : 0;
	udps_laddr = arg2 && *(uint8_t *)arg2 >> 4 == 4 ?
            inet_ntoa(arg5 == NET_PROBE_OUTBOUND ? &((struct iphdr *)arg2)->saddr :
	    &((struct iphdr *)arg2)->daddr) :
	    arg2 && *(uint8_t *)arg2 >> 4 == 6 ?
	    inet_ntoa6(arg5 == NET_PROBE_OUTBOUND ? &((struct ipv6hdr *)arg2)->saddr :
	    &((struct ipv6hdr *)arg2)->daddr) :
	    "<unknown>";
	udps_raddr =
	    arg2 && *(uint8_t *)arg2 >> 4 == 4 ?
            inet_ntoa(arg5 == NET_PROBE_OUTBOUND ? &((struct iphdr *)arg2)->daddr :
	    &((struct iphdr *)arg2)->saddr) :
	    arg2 && *(uint8_t *)arg2 >> 4 == 6 ?
	    inet_ntoa6(arg5 == NET_PROBE_OUTBOUND ? &((struct ipv6hdr *)arg2)->daddr :
	    &((struct ipv6hdr *)arg2)->saddr) :
	    "<unknown>";
};