This needs a new helper that: - can work in a sleepable context (using sock_gen_cookie) - takes a struct sock pointer and checks that it's not NULL
Unified · Split
| @@ -1885,6 +1885,7 @@ extern const struct bpf_func_proto bpf_per_cpu_ptr_proto; · 1884 unmodified lines | |||
| 1885 | extern const struct bpf_func_proto bpf_this_cpu_ptr_proto; | 1885 | extern const struct bpf_func_proto bpf_this_cpu_ptr_proto; |
| 1886 | extern const struct bpf_func_proto bpf_ktime_get_coarse_ns_proto; | 1886 | extern const struct bpf_func_proto bpf_ktime_get_coarse_ns_proto; |
| 1887 | extern const struct bpf_func_proto bpf_sock_from_file_proto; | 1887 | extern const struct bpf_func_proto bpf_sock_from_file_proto; |
| 1888 | extern const struct bpf_func_proto bpf_get_socket_ptr_cookie_proto; | ||
| 1888 | 1889 | ||
| 1889 | const struct bpf_func_proto *bpf_tracing_func_proto( | 1890 | const struct bpf_func_proto *bpf_tracing_func_proto( |
| 1890 | enum bpf_func_id func_id, const struct bpf_prog *prog); | 1891 | enum bpf_func_id func_id, const struct bpf_prog *prog); |
| @@ -1673,6 +1673,14 @@ union bpf_attr { · 1672 unmodified lines | |||
| 1673 | * Return | 1673 | * Return |
| 1674 | * A 8-byte long unique number. | 1674 | * A 8-byte long unique number. |
| 1675 | * | 1675 | * |
| 1676 | * u64 bpf_get_socket_cookie(struct sock *sk) | ||
| 1677 | * Description | ||
| 1678 | * Equivalent to **bpf_get_socket_cookie**\ () helper that accepts | ||
| 1679 | * *sk*, but gets socket from a BTF **struct sock**. This helper | ||
| 1680 | * also works for sleepable programs. | ||
| 1681 | * Return | ||
| 1682 | * A 8-byte long unique number or 0 if *sk* is NULL. | ||
| 1683 | * | ||
| 1676 | * u32 bpf_get_socket_uid(struct sk_buff *skb) | 1684 | * u32 bpf_get_socket_uid(struct sk_buff *skb) |
| 1677 | * Return | 1685 | * Return |
| 1678 | * The owner UID of the socket associated to *skb*. If the socket | 1686 | * The owner UID of the socket associated to *skb*. If the socket |
| @@ -1760,6 +1760,8 @@ tracing_prog_func_proto(enum bpf_func_id func_id, const struct bpf_prog *prog) · 1759 unmodified lines | |||
| 1760 | return &bpf_sk_storage_delete_tracing_proto; | 1760 | return &bpf_sk_storage_delete_tracing_proto; |
| 1761 | case BPF_FUNC_sock_from_file: | 1761 | case BPF_FUNC_sock_from_file: |
| 1762 | return &bpf_sock_from_file_proto; | 1762 | return &bpf_sock_from_file_proto; |
| 1763 | case BPF_FUNC_get_socket_cookie: | ||
| 1764 | return &bpf_get_socket_ptr_cookie_proto; | ||
| 1763 | #endif | 1765 | #endif |
| 1764 | case BPF_FUNC_seq_printf: | 1766 | case BPF_FUNC_seq_printf: |
| 1765 | return prog->expected_attach_type == BPF_TRACE_ITER ? | 1767 | return prog->expected_attach_type == BPF_TRACE_ITER ? |
| @@ -4631,6 +4631,18 @@ static const struct bpf_func_proto bpf_get_socket_cookie_sock_proto = { · 4630 unmodified lines | |||
| 4631 | .arg1_type = ARG_PTR_TO_CTX, | 4631 | .arg1_type = ARG_PTR_TO_CTX, |
| 4632 | }; | 4632 | }; |
| 4633 | 4633 | ||
| 4634 | BPF_CALL_1(bpf_get_socket_ptr_cookie, struct sock *, sk) | ||
| 4635 | { | ||
| 4636 | return sk ? sock_gen_cookie(sk) : 0; | ||
| 4637 | } | ||
| 4638 | |||
| 4639 | const struct bpf_func_proto bpf_get_socket_ptr_cookie_proto = { | ||
| 4640 | .func = bpf_get_socket_ptr_cookie, | ||
| 4641 | .gpl_only = false, | ||
| 4642 | .ret_type = RET_INTEGER, | ||
| 4643 | .arg1_type = ARG_PTR_TO_BTF_ID_SOCK_COMMON, | ||
| 4644 | }; | ||
| 4645 | |||
| 4634 | BPF_CALL_1(bpf_get_socket_cookie_sock_ops, struct bpf_sock_ops_kern *, ctx) | 4646 | BPF_CALL_1(bpf_get_socket_cookie_sock_ops, struct bpf_sock_ops_kern *, ctx) |
| 4635 | { | 4647 | { |
| 4636 | return __sock_gen_cookie(ctx->sk); | 4648 | return __sock_gen_cookie(ctx->sk); |
| @@ -1673,6 +1673,14 @@ union bpf_attr { · 1672 unmodified lines | |||
| 1673 | * Return | 1673 | * Return |
| 1674 | * A 8-byte long unique number. | 1674 | * A 8-byte long unique number. |
| 1675 | * | 1675 | * |
| 1676 | * u64 bpf_get_socket_cookie(struct sock *sk) | ||
| 1677 | * Description | ||
| 1678 | * Equivalent to **bpf_get_socket_cookie**\ () helper that accepts | ||
| 1679 | * *sk*, but gets socket from a BTF **struct sock**. This helper | ||
| 1680 | * also works for sleepable programs. | ||
| 1681 | * Return | ||
| 1682 | * A 8-byte long unique number or 0 if *sk* is NULL. | ||
| 1683 | * | ||
| 1676 | * u32 bpf_get_socket_uid(struct sk_buff *skb) | 1684 | * u32 bpf_get_socket_uid(struct sk_buff *skb) |
| 1677 | * Return | 1685 | * Return |
| 1678 | * The owner UID of the socket associated to *skb*. If the socket | 1686 | * The owner UID of the socket associated to *skb*. If the socket |