Add uid and cookie bpf helper to cg_skb_func_proto
Subsystems (4)
PATCH 1/1 Add uid and cookie bpf helper to cg_skb_func_proto
From: Chenbo Feng <[email protected]>
BPF helper functions get_socket_cookie and get_socket_uid can be used for network traffic classifications, among others. Expose them also to programs of type BPF_PROG_TYPE_CGROUP_SKB. As of commit 8f917bba0042 ("bpf: pass sk to helper functions") the required skb->sk function is available at both cgroup bpf ingress and egress hooks.
--- net/core/filter.c | 4 ++++ 1 file changed, 4 insertions(+)
net/core/filter.c +4 -0
@@ -2769,6 +2769,10 @@ cg_skb_func_proto(enum bpf_func_id func_id)switch (func_id) {case BPF_FUNC_skb_load_bytes:return &bpf_skb_load_bytes_proto; +case BPF_FUNC_get_socket_cookie: +return &bpf_get_socket_cookie_proto; +case BPF_FUNC_get_socket_uid: +return &bpf_get_socket_uid_proto;default :return bpf_base_func_proto (func_id); }
Signature · 1 line
2.7.4
Quoted 10 lines · Chenbo Feng
From: Chenbo Feng <[email protected]>
BPF helper functions
get_socket_cookieandget_socket_uidcan be used for network traffic classifications, among others. Expose them also to programs of typeBPF_PROG_TYPE_CGROUP_SKB. As of commit8f917bba0042("bpf: pass sk to helper functions") the requiredskb->skfunction is available at both cgroup bpf ingress and egress hooks.Signed-off-by Chenbo Feng <[email protected]>
Thanks for follow up.
Another alternative is to docg_skb_func_proto(enum bpf_func_id func_id)
{
return sk_filter_func_proto(func_id);
}I think all socket filter helpers are applicable to cg_skb too.
Daniel Borkmann
maintainerQuoted 12 lines · Alexei Starovoitov
Quoted 10 lines · Chenbo Feng
From: Chenbo Feng <[email protected]>
BPF helper functions
get_socket_cookieandget_socket_uidcan be used for network traffic classifications, among others. Expose them also to programs of typeBPF_PROG_TYPE_CGROUP_SKB. As of commit8f917bba0042("bpf: pass sk to helper functions") the requiredskb->skfunction is available at both cgroup bpf ingress and egress hooks.Signed-off-by Chenbo Feng <[email protected]>
Quoted 8 lines
Thanks for follow up.
Another alternative is to docg_skb_func_proto(enum bpf_func_id func_id){ return sk_filter_func_proto(func_id); }I think all socket filter helpers are applicable to
cg_skbtoo.
Yeah, both will effectively be the same at that point:
static const struct bpf_func_proto *sk_filter_func_proto(enum bpf_func_id func_id)
{
switch (func_id) {
case BPF_FUNC_skb_load_bytes:
return &bpf_skb_load_bytes_proto;
case BPF_FUNC_get_socket_cookie:
return &bpf_get_socket_cookie_proto;
case BPF_FUNC_get_socket_uid:
return &bpf_get_socket_uid_proto;
default:
return bpf_base_func_proto(func_id);
}
}And with the two additions:
static const struct bpf_func_proto *cg_skb_func_proto(enum bpf_func_id func_id)
{
switch (func_id) {
case BPF_FUNC_skb_load_bytes:
return &bpf_skb_load_bytes_proto;
+ case BPF_FUNC_get_socket_cookie:
+ return &bpf_get_socket_cookie_proto;
+ case BPF_FUNC_get_socket_uid:
+ return &bpf_get_socket_uid_proto;
default:
return bpf_base_func_proto(func_id);
}
}