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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
|
From ebb12512f6ea0a1113ad8ddf30db26128f7a3426 Mon Sep 17 00:00:00 2001
From: Dominique Martinet <asmadeus@codewreck.org>
Date: Sun, 23 Jun 2024 20:41:01 +0900
Subject: [PATCH] With BTF, users do not need libc headers installed for
AF_INET/AF_INET6
Signed-off-by: Bernhard Kaindl <bernhardkaindl7@gmail.com>
(cherry picked from commit c0b9d252a43f99b9091245dedb178a6874803306)
---
tools/tcpaccept.bt | 8 +++++++-
tools/tcpconnect.bt | 8 +++++++-
tools/tcpdrop.bt | 8 +++++++-
tools/tcplife.bt | 8 +++++++-
tools/tcpretrans.bt | 8 +++++++-
5 files changed, 35 insertions(+), 5 deletions(-)
diff --git a/tools/tcpaccept.bt b/tools/tcpaccept.bt
index 08e6af0158fc..cbffe36889ee 100755
--- a/tools/tcpaccept.bt
+++ b/tools/tcpaccept.bt
@@ -20,7 +20,13 @@
#include <linux/socket.h>
#include <net/sock.h>
#else
-#include <sys/socket.h>
+/*
+ * With BTF providing types, socket headers are not needed.
+ * We only need to supply the preprocessor defines in this script.
+ * AF_INET/AF_INET6 are part of the stable arch-independent Linux ABI
+ */
+#define AF_INET 2
+#define AF_INET6 10
#endif
BEGIN
diff --git a/tools/tcpconnect.bt b/tools/tcpconnect.bt
index 1ac1eb99e9ad..636337275cd8 100755
--- a/tools/tcpconnect.bt
+++ b/tools/tcpconnect.bt
@@ -22,7 +22,13 @@
#include <linux/socket.h>
#include <net/sock.h>
#else
-#include <sys/socket.h>
+/*
+ * BTF provides the types, we just need to define AF_INET and AF_INET6.
+ * These are Linux ABI defines, and are not architecture-specific.
+ * With BTF, this allows tcpconnect.bt to work without glibc headers:
+ */
+#define AF_INET 2 /* IPv4 */
+#define AF_INET6 10 /* IPv6 */
#endif
BEGIN
diff --git a/tools/tcpdrop.bt b/tools/tcpdrop.bt
index fd3e55f490bf..a56bf69fcc6c 100755
--- a/tools/tcpdrop.bt
+++ b/tools/tcpdrop.bt
@@ -24,7 +24,13 @@
#include <linux/socket.h>
#include <net/sock.h>
#else
-#include <sys/socket.h>
+/*
+ * With BTF providing types, socket headers are not needed.
+ * We only need to supply the preprocessor defines in this script.
+ * AF_INET/AF_INET6 are part of the stable arch-independent Linux ABI
+ */
+#define AF_INET 2
+#define AF_INET6 10
#endif
BEGIN
diff --git a/tools/tcplife.bt b/tools/tcplife.bt
index dd4c1d68284e..d5a09c4e5da9 100755
--- a/tools/tcplife.bt
+++ b/tools/tcplife.bt
@@ -19,7 +19,13 @@
#include <linux/socket.h>
#include <linux/tcp.h>
#else
-#include <sys/socket.h>
+/*
+ * With BTF providing types, socket headers are not needed.
+ * We only need to supply the preprocessor defines in this script.
+ * AF_INET/AF_INET6 are part of the stable arch-independent Linux ABI
+ */
+#define AF_INET 2
+#define AF_INET6 10
#endif
BEGIN
diff --git a/tools/tcpretrans.bt b/tools/tcpretrans.bt
index ee2975d6e545..32a11bfa81b2 100755
--- a/tools/tcpretrans.bt
+++ b/tools/tcpretrans.bt
@@ -21,7 +21,13 @@
#include <linux/socket.h>
#include <net/sock.h>
#else
-#include <sys/socket.h>
+/*
+ * With BTF providing types, socket headers are not needed.
+ * We only need to supply the preprocessor defines in this script.
+ * AF_INET/AF_INET6 are part of the stable arch-independent Linux ABI
+ */
+#define AF_INET 2
+#define AF_INET6 10
#endif
BEGIN
--
2.45.2
|