Commit 13d70f5a authored by John Fastabend's avatar John Fastabend Committed by Alexei Starovoitov

bpf, sk_msg: Add get socket storage helpers

Add helpers to use local socket storage.
Signed-off-by: default avatarJohn Fastabend <john.fastabend@gmail.com>
Signed-off-by: default avatarDaniel Borkmann <daniel@iogearbox.net>
Acked-by: default avatarYonghong Song <yhs@fb.com>
Link: https://lore.kernel.org/bpf/159033907577.12355.14740125020572756560.stgit@john-Precision-5820-TowerSigned-off-by: default avatarAlexei Starovoitov <ast@kernel.org>
parent f470378c
...@@ -3645,6 +3645,8 @@ struct sk_msg_md { ...@@ -3645,6 +3645,8 @@ struct sk_msg_md {
__u32 remote_port; /* Stored in network byte order */ __u32 remote_port; /* Stored in network byte order */
__u32 local_port; /* stored in host byte order */ __u32 local_port; /* stored in host byte order */
__u32 size; /* Total size of sk_msg */ __u32 size; /* Total size of sk_msg */
__bpf_md_ptr(struct bpf_sock *, sk); /* current socket */
}; };
struct sk_reuseport_md { struct sk_reuseport_md {
......
...@@ -6449,6 +6449,10 @@ sk_msg_func_proto(enum bpf_func_id func_id, const struct bpf_prog *prog) ...@@ -6449,6 +6449,10 @@ sk_msg_func_proto(enum bpf_func_id func_id, const struct bpf_prog *prog)
return &bpf_get_current_uid_gid_proto; return &bpf_get_current_uid_gid_proto;
case BPF_FUNC_get_current_pid_tgid: case BPF_FUNC_get_current_pid_tgid:
return &bpf_get_current_pid_tgid_proto; return &bpf_get_current_pid_tgid_proto;
case BPF_FUNC_sk_storage_get:
return &bpf_sk_storage_get_proto;
case BPF_FUNC_sk_storage_delete:
return &bpf_sk_storage_delete_proto;
#ifdef CONFIG_CGROUPS #ifdef CONFIG_CGROUPS
case BPF_FUNC_get_current_cgroup_id: case BPF_FUNC_get_current_cgroup_id:
return &bpf_get_current_cgroup_id_proto; return &bpf_get_current_cgroup_id_proto;
...@@ -7273,6 +7277,11 @@ static bool sk_msg_is_valid_access(int off, int size, ...@@ -7273,6 +7277,11 @@ static bool sk_msg_is_valid_access(int off, int size,
if (size != sizeof(__u64)) if (size != sizeof(__u64))
return false; return false;
break; break;
case offsetof(struct sk_msg_md, sk):
if (size != sizeof(__u64))
return false;
info->reg_type = PTR_TO_SOCKET;
break;
case bpf_ctx_range(struct sk_msg_md, family): case bpf_ctx_range(struct sk_msg_md, family):
case bpf_ctx_range(struct sk_msg_md, remote_ip4): case bpf_ctx_range(struct sk_msg_md, remote_ip4):
case bpf_ctx_range(struct sk_msg_md, local_ip4): case bpf_ctx_range(struct sk_msg_md, local_ip4):
...@@ -8609,6 +8618,12 @@ static u32 sk_msg_convert_ctx_access(enum bpf_access_type type, ...@@ -8609,6 +8618,12 @@ static u32 sk_msg_convert_ctx_access(enum bpf_access_type type,
si->dst_reg, si->src_reg, si->dst_reg, si->src_reg,
offsetof(struct sk_msg_sg, size)); offsetof(struct sk_msg_sg, size));
break; break;
case offsetof(struct sk_msg_md, sk):
*insn++ = BPF_LDX_MEM(BPF_FIELD_SIZEOF(struct sk_msg, sk),
si->dst_reg, si->src_reg,
offsetof(struct sk_msg, sk));
break;
} }
return insn - insn_buf; return insn - insn_buf;
......
...@@ -3645,6 +3645,8 @@ struct sk_msg_md { ...@@ -3645,6 +3645,8 @@ struct sk_msg_md {
__u32 remote_port; /* Stored in network byte order */ __u32 remote_port; /* Stored in network byte order */
__u32 local_port; /* stored in host byte order */ __u32 local_port; /* stored in host byte order */
__u32 size; /* Total size of sk_msg */ __u32 size; /* Total size of sk_msg */
__bpf_md_ptr(struct bpf_sock *, sk); /* current socket */
}; };
struct sk_reuseport_md { struct sk_reuseport_md {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment