History

bpf: Add classid helper only based on skb->sk

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().

Daniel Borkmann committed 6 years ago

Commit b426ce81 parent 963ec273 files · +41 −0Browse files

Showing the changes to include/uapi/linux (1 of 3 files). Show all

Unified · Split

include/uapi/linux/bpf.h+10−0
@@ -3643,6 +3643,15 @@ union bpf_attr { · 3642 unmodified lines
36433643 * *flags* are identical to those used for bpf_snprintf_btf.
36443644 * Return
36453645 * 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.
36463655 */
36473656 #define __BPF_FUNC_MAPPER(FN) \
36483657 FN(unspec), \
@@ -3796,6 +3805,7 @@ union bpf_attr { · 147 unmodified lines
37963805 FN(copy_from_user), \
37973806 FN(snprintf_btf), \
37983807 FN(seq_printf_btf), \
3808+ FN(skb_cgroup_classid), \
37993809 /* */
38003810
38013811 /* integer value in 'imm' field of BPF_CALL instruction selects which helper