]> git.proxmox.com Git - mirror_ubuntu-bionic-kernel.git/blame - include/net/cls_cgroup.h
futex: Split futex_mm_release() for exit/exec
[mirror_ubuntu-bionic-kernel.git] / include / net / cls_cgroup.h
CommitLineData
f8451725
HX
1/*
2 * cls_cgroup.h Control Group Classifier
3 *
4 * Authors: Thomas Graf <tgraf@suug.ch>
5 *
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License as published by the Free
8 * Software Foundation; either version 2 of the License, or (at your option)
9 * any later version.
10 *
11 */
12
13#ifndef _NET_CLS_CGROUP_H
14#define _NET_CLS_CGROUP_H
15
16#include <linux/cgroup.h>
17#include <linux/hardirq.h>
18#include <linux/rcupdate.h>
fe1217c4 19#include <net/sock.h>
2309236c 20#include <net/inet_sock.h>
f8451725 21
fe1217c4
DB
22#ifdef CONFIG_CGROUP_NET_CLASSID
23struct cgroup_cls_state {
f8451725
HX
24 struct cgroup_subsys_state css;
25 u32 classid;
26};
27
fe1217c4 28struct cgroup_cls_state *task_cls_state(struct task_struct *p);
f3419807 29
f8451725
HX
30static inline u32 task_cls_classid(struct task_struct *p)
31{
920750ce 32 u32 classid;
3fb5a991 33
f8451725
HX
34 if (in_interrupt())
35 return 0;
36
3fb5a991 37 rcu_read_lock();
073219e9 38 classid = container_of(task_css(p, net_cls_cgrp_id),
3fb5a991
LZ
39 struct cgroup_cls_state, css)->classid;
40 rcu_read_unlock();
41
42 return classid;
f8451725 43}
f8451725 44
2a56a1fe 45static inline void sock_update_classid(struct sock_cgroup_data *skcd)
f3419807 46{
fe1217c4 47 u32 classid;
f3419807 48
fe1217c4 49 classid = task_cls_classid(current);
2a56a1fe 50 sock_cgroup_set_classid(skcd, classid);
fe1217c4 51}
b87a173e
DB
52
53static inline u32 task_get_classid(const struct sk_buff *skb)
54{
55 u32 classid = task_cls_state(current)->classid;
56
57 /* Due to the nature of the classifier it is required to ignore all
58 * packets originating from softirq context as accessing `current'
59 * would lead to false results.
60 *
61 * This test assumes that all callers of dev_queue_xmit() explicitly
62 * disable bh. Knowing this, it is possible to detect softirq based
63 * calls by looking at the number of nested bh disable calls because
64 * softirqs always disables bh.
65 */
66 if (in_serving_softirq()) {
2309236c
KK
67 struct sock *sk = skb_to_full_sk(skb);
68
2a56a1fe 69 /* If there is an sock_cgroup_classid we'll use that. */
2309236c 70 if (!sk || !sk_fullsock(sk))
b87a173e
DB
71 return 0;
72
2309236c 73 classid = sock_cgroup_classid(&sk->sk_cgrp_data);
b87a173e
DB
74 }
75
76 return classid;
77}
fe1217c4 78#else /* !CONFIG_CGROUP_NET_CLASSID */
2a56a1fe 79static inline void sock_update_classid(struct sock_cgroup_data *skcd)
f8451725 80{
f8451725 81}
b87a173e
DB
82
83static inline u32 task_get_classid(const struct sk_buff *skb)
84{
85 return 0;
86}
fe1217c4 87#endif /* CONFIG_CGROUP_NET_CLASSID */
f8451725 88#endif /* _NET_CLS_CGROUP_H */