On 4/21/23 9:27 AM, Daan De Meyer wrote:
As prep for adding unix socket support to the cgroup sockaddr hooks,
let's expose the sockaddr addrlen in bpf_sock_addr_kern. While not
important for AF_INET or AF_INET6, the sockaddr length is important
when working with AF_UNIX sockaddrs as the size of the sockaddr cannot
be determined just from the address family or the sockaddr's contents.
__cgroup_bpf_run_filter_sock_addr() is modified to return the addr_len
in preparation for adding unix socket support for which we'll need to
return the modified address length.
Signed-off-by: Daan De Meyer <daan.j.demeyer@xxxxxxxxx>
---
include/linux/bpf-cgroup.h | 73 +++++++++++++++++++-------------------
include/linux/filter.h | 1 +
kernel/bpf/cgroup.c | 16 +++++++--
net/ipv4/af_inet.c | 8 ++---
net/ipv4/ping.c | 8 ++++-
net/ipv4/tcp_ipv4.c | 8 ++++-
net/ipv4/udp.c | 17 ++++++---
net/ipv6/af_inet6.c | 8 ++---
net/ipv6/ping.c | 8 ++++-
net/ipv6/tcp_ipv6.c | 8 ++++-
net/ipv6/udp.c | 14 ++++++--
11 files changed, 111 insertions(+), 58 deletions(-)
diff --git a/include/linux/bpf-cgroup.h b/include/linux/bpf-cgroup.h
index 57e9e109257e..f3f5adf3881f 100644
--- a/include/linux/bpf-cgroup.h
+++ b/include/linux/bpf-cgroup.h
@@ -120,6 +120,7 @@ int __cgroup_bpf_run_filter_sk(struct sock *sk,
int __cgroup_bpf_run_filter_sock_addr(struct sock *sk,
struct sockaddr *uaddr,
+ u32 uaddrlen,
If the bpf_sock_addr_set() kfunc can only change the sin[6]_addr and unix_path
(the comment in patch 5), the "u32 uaddrlen" can be changed to "u32 *uaddrlen"
here. The new unix_path length can be passed back to af_unix.c in "*uaddrlen".
The inet[6] code path can just pass NULL and most of the code churn in this
patch will no longer be needed?