Skip to content

Commit 0e53d9e

Browse files
borkmannAlexei Starovoitov
authored andcommitted
bpf: Enable retrieval of socket cookie for bind/post-bind hook
We currently make heavy use of the socket cookie in BPF's connect(), sendmsg() and recvmsg() hooks for load-balancing decisions. However, it is currently not enabled/implemented in BPF {post-}bind hooks where it can later be used in combination for correlation in the tc egress path, for example. Signed-off-by: Daniel Borkmann <[email protected]> Signed-off-by: Alexei Starovoitov <[email protected]> Link: https://lore.kernel.org/bpf/e9d71f310715332f12d238cc650c1edc5be55119.1585323121.git.daniel@iogearbox.net
1 parent f54a5bb commit 0e53d9e

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

net/core/filter.c

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4117,6 +4117,18 @@ static const struct bpf_func_proto bpf_get_socket_cookie_sock_addr_proto = {
41174117
.arg1_type = ARG_PTR_TO_CTX,
41184118
};
41194119

4120+
BPF_CALL_1(bpf_get_socket_cookie_sock, struct sock *, ctx)
4121+
{
4122+
return sock_gen_cookie(ctx);
4123+
}
4124+
4125+
static const struct bpf_func_proto bpf_get_socket_cookie_sock_proto = {
4126+
.func = bpf_get_socket_cookie_sock,
4127+
.gpl_only = false,
4128+
.ret_type = RET_INTEGER,
4129+
.arg1_type = ARG_PTR_TO_CTX,
4130+
};
4131+
41204132
BPF_CALL_1(bpf_get_socket_cookie_sock_ops, struct bpf_sock_ops_kern *, ctx)
41214133
{
41224134
return sock_gen_cookie(ctx->sk);
@@ -5954,6 +5966,8 @@ sock_filter_func_proto(enum bpf_func_id func_id, const struct bpf_prog *prog)
59545966
return &bpf_get_current_uid_gid_proto;
59555967
case BPF_FUNC_get_local_storage:
59565968
return &bpf_get_local_storage_proto;
5969+
case BPF_FUNC_get_socket_cookie:
5970+
return &bpf_get_socket_cookie_sock_proto;
59575971
default:
59585972
return bpf_base_func_proto(func_id);
59595973
}

0 commit comments

Comments
 (0)