diff options
| author | David S. Miller <davem@davemloft.net> | 2015-07-20 22:41:30 +0300 |
|---|---|---|
| committer | David S. Miller <davem@davemloft.net> | 2015-07-20 22:41:30 +0300 |
| commit | 03b6dc7d172fb46891d25e6cff43bd5762a918c1 (patch) | |
| tree | be182dc2e3829040518d72c41363ffec458f1245 /include | |
| parent | d9382bda4ef97d73c77ecaed7a8d5df20da8b8dd (diff) | |
| parent | 8d20aabe1c76cccac544d9fcc3ad7823d9e98a2d (diff) | |
| download | linux-03b6dc7d172fb46891d25e6cff43bd5762a918c1.tar.xz | |
Merge branch 'bpf_cgroup_classid'
Daniel Borkmann says:
====================
BPF update
This small helper allows for accessing net_cls cgroups classid. Please
see individual patches for more details.
====================
Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'include')
| -rw-r--r-- | include/net/cls_cgroup.h | 29 | ||||
| -rw-r--r-- | include/uapi/linux/bpf.h | 7 |
2 files changed, 36 insertions, 0 deletions
diff --git a/include/net/cls_cgroup.h b/include/net/cls_cgroup.h index c15d39456e14..ccd6d8bffa4d 100644 --- a/include/net/cls_cgroup.h +++ b/include/net/cls_cgroup.h @@ -49,9 +49,38 @@ static inline void sock_update_classid(struct sock *sk) if (classid != sk->sk_classid) sk->sk_classid = classid; } + +static inline u32 task_get_classid(const struct sk_buff *skb) +{ + u32 classid = task_cls_state(current)->classid; + + /* Due to the nature of the classifier it is required to ignore all + * packets originating from softirq context as accessing `current' + * would lead to false results. + * + * This test assumes that all callers of dev_queue_xmit() explicitly + * disable bh. Knowing this, it is possible to detect softirq based + * calls by looking at the number of nested bh disable calls because + * softirqs always disables bh. + */ + if (in_serving_softirq()) { + /* If there is an sk_classid we'll use that. */ + if (!skb->sk) + return 0; + + classid = skb->sk->sk_classid; + } + + return classid; +} #else /* !CONFIG_CGROUP_NET_CLASSID */ static inline void sock_update_classid(struct sock *sk) { } + +static inline u32 task_get_classid(const struct sk_buff *skb) +{ + return 0; +} #endif /* CONFIG_CGROUP_NET_CLASSID */ #endif /* _NET_CLS_CGROUP_H */ diff --git a/include/uapi/linux/bpf.h b/include/uapi/linux/bpf.h index 29ef6f99e43d..2de87e58b12b 100644 --- a/include/uapi/linux/bpf.h +++ b/include/uapi/linux/bpf.h @@ -249,6 +249,13 @@ enum bpf_func_id { * Return: 0 on success */ BPF_FUNC_get_current_comm, + + /** + * bpf_get_cgroup_classid(skb) - retrieve a proc's classid + * @skb: pointer to skb + * Return: classid if != 0 + */ + BPF_FUNC_get_cgroup_classid, __BPF_FUNC_MAX_ID, }; |
