diff options
author | Yonghong Song <yhs@fb.com> | 2020-06-23 16:08:15 -0700 |
---|---|---|
committer | Alexei Starovoitov <ast@kernel.org> | 2020-06-24 18:37:59 -0700 |
commit | 0d4fad3e57df2bf61e8ffc8d12a34b1caf9b8835 (patch) | |
tree | a0e1c4d3842e4fcf68b2258de801de5e4a092d1c /net/core | |
parent | 5788b3a07fc5863606c3b92fa7b1ffe125e6eb4c (diff) | |
download | linux-0d4fad3e57df2bf61e8ffc8d12a34b1caf9b8835.tar.gz linux-0d4fad3e57df2bf61e8ffc8d12a34b1caf9b8835.tar.bz2 linux-0d4fad3e57df2bf61e8ffc8d12a34b1caf9b8835.zip |
bpf: Add bpf_skc_to_udp6_sock() helper
The helper is used in tracing programs to cast a socket
pointer to a udp6_sock pointer.
The return value could be NULL if the casting is illegal.
Signed-off-by: Yonghong Song <yhs@fb.com>
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
Acked-by: Martin KaFai Lau <kafai@fb.com>
Cc: Eric Dumazet <edumazet@google.com>
Link: https://lore.kernel.org/bpf/20200623230815.3988481-1-yhs@fb.com
Diffstat (limited to 'net/core')
-rw-r--r-- | net/core/filter.c | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/net/core/filter.c b/net/core/filter.c index 0b4e5aed7e20..c796e141ea8e 100644 --- a/net/core/filter.c +++ b/net/core/filter.c @@ -9369,3 +9369,25 @@ const struct bpf_func_proto bpf_skc_to_tcp_request_sock_proto = { .check_btf_id = check_arg_btf_id, .ret_btf_id = &btf_sock_ids[BTF_SOCK_TYPE_TCP_REQ], }; + +BPF_CALL_1(bpf_skc_to_udp6_sock, struct sock *, sk) +{ + /* udp6_sock type is not generated in dwarf and hence btf, + * trigger an explicit type generation here. + */ + BTF_TYPE_EMIT(struct udp6_sock); + if (sk_fullsock(sk) && sk->sk_protocol == IPPROTO_UDP && + sk->sk_type == SOCK_DGRAM && sk->sk_family == AF_INET6) + return (unsigned long)sk; + + return (unsigned long)NULL; +} + +const struct bpf_func_proto bpf_skc_to_udp6_sock_proto = { + .func = bpf_skc_to_udp6_sock, + .gpl_only = false, + .ret_type = RET_PTR_TO_BTF_ID_OR_NULL, + .arg1_type = ARG_PTR_TO_BTF_ID, + .check_btf_id = check_arg_btf_id, + .ret_btf_id = &btf_sock_ids[BTF_SOCK_TYPE_UDP6], +}; |