Similarly to 5a52ae4e32a6 ("bpf: Allow to retrieve cgroup v1 classid from v2 hooks"), add a helper to retrieve cgroup v1 classid solely based on the skb->sk, so it can be used as key as part of BPF map lookups out of tc from host ns, in particular given the skb->sk is retained these days when crossing net ns thanks to 9c4c325252c5 ("skbuff: preserve sock reference when scrubbing the skb."). This is similar to bpf_skb_cgroup_id() which implements the same for v2. Kubernetes ecosystem is still operating on v1 however, hence net_cls needs to be used there until this can be dropped in with the v2 helper of bpf_skb_cgroup_id().
Showing the changes to include/uapi/linux (1 of 3 files). Show all
Unified · Split
| @@ -3643,6 +3643,15 @@ union bpf_attr { · 3642 unmodified lines | ||
| 3643 | 3643 | * *flags* are identical to those used for bpf_snprintf_btf. |
| 3644 | 3644 | * Return |
| 3645 | 3645 | * 0 on success or a negative error in case of failure. |
| 3646 | + * | |
| 3647 | + * u64 bpf_skb_cgroup_classid(struct sk_buff *skb) | |
| 3648 | + * Description | |
| 3649 | + * See **bpf_get_cgroup_classid**\ () for the main description. | |
| 3650 | + * This helper differs from **bpf_get_cgroup_classid**\ () in that | |
| 3651 | + * the cgroup v1 net_cls class is retrieved only from the *skb*'s | |
| 3652 | + * associated socket instead of the current process. | |
| 3653 | + * Return | |
| 3654 | + * The id is returned or 0 in case the id could not be retrieved. | |
| 3646 | 3655 | */ |
| 3647 | 3656 | #define __BPF_FUNC_MAPPER(FN) \ |
| 3648 | 3657 | FN(unspec), \ |
| @@ -3796,6 +3805,7 @@ union bpf_attr { · 147 unmodified lines | ||
| 3796 | 3805 | FN(copy_from_user), \ |
| 3797 | 3806 | FN(snprintf_btf), \ |
| 3798 | 3807 | FN(seq_printf_btf), \ |
| 3808 | + FN(skb_cgroup_classid), \ | |
| 3799 | 3809 | /* */ |
| 3800 | 3810 | |
| 3801 | 3811 | /* integer value in 'imm' field of BPF_CALL instruction selects which helper |