forked from iovisor/bcc
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
libbpf-tools: Fix bindsnoop for kernel v6.6+
The freebind field in struct inet_sock gone in recent kernel versions due to some kernel refactor works ([0]). The change breaks the bindsnoop tool. Fix it in a CO-RE way. This should close iovisor#4838. [0]: https://lore.kernel.org/all/[email protected]/ Signed-off-by: Hengqi Chen <[email protected]>
- Loading branch information
1 parent
7266156
commit 970f3be
Showing
2 changed files
with
61 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -249,4 +249,60 @@ static __always_inline __u64 get_sock_ident(struct sock *sk) | |
return (__u64)sk; | ||
} | ||
|
||
/** | ||
* During kernel 6.6 development cycle, several bitfields in struct inet_sock gone, | ||
* they are placed in inet_sock::inet_flags instead ([0]). | ||
* | ||
* References: | ||
* [0]: https://lore.kernel.org/all/[email protected]/ | ||
*/ | ||
struct inet_sock___o { | ||
__u8 freebind: 1; | ||
__u8 transparent: 1; | ||
__u8 bind_address_no_port: 1; | ||
}; | ||
|
||
enum { | ||
INET_FLAGS_FREEBIND___x = 11, | ||
INET_FLAGS_TRANSPARENT___x = 15, | ||
INET_FLAGS_BIND_ADDRESS_NO_PORT___x = 18, | ||
}; | ||
|
||
struct inet_sock___x { | ||
unsigned long inet_flags; | ||
}; | ||
|
||
static __always_inline __u8 get_inet_sock_freebind(void *inet_sock) | ||
{ | ||
unsigned long inet_flags; | ||
|
||
if (bpf_core_field_exists(struct inet_sock___o, freebind)) | ||
return BPF_CORE_READ_BITFIELD_PROBED((struct inet_sock___o *)inet_sock, freebind); | ||
|
||
inet_flags = BPF_CORE_READ((struct inet_sock___x *)inet_sock, inet_flags); | ||
return (1 << INET_FLAGS_FREEBIND___x) & inet_flags ? 1 : 0; | ||
} | ||
|
||
static __always_inline __u8 get_inet_sock_transparent(void *inet_sock) | ||
{ | ||
unsigned long inet_flags; | ||
|
||
if (bpf_core_field_exists(struct inet_sock___o, transparent)) | ||
return BPF_CORE_READ_BITFIELD_PROBED((struct inet_sock___o *)inet_sock, transparent); | ||
|
||
inet_flags = BPF_CORE_READ((struct inet_sock___x *)inet_sock, inet_flags); | ||
return (1 << INET_FLAGS_TRANSPARENT___x) & inet_flags ? 1 : 0; | ||
} | ||
|
||
static __always_inline __u8 get_inet_sock_bind_address_no_port(void *inet_sock) | ||
{ | ||
unsigned long inet_flags; | ||
|
||
if (bpf_core_field_exists(struct inet_sock___o, bind_address_no_port)) | ||
return BPF_CORE_READ_BITFIELD_PROBED((struct inet_sock___o *)inet_sock, bind_address_no_port); | ||
|
||
inet_flags = BPF_CORE_READ((struct inet_sock___x *)inet_sock, inet_flags); | ||
return (1 << INET_FLAGS_BIND_ADDRESS_NO_PORT___x) & inet_flags ? 1 : 0; | ||
} | ||
|
||
#endif /* __CORE_FIXES_BPF_H */ |