aboutsummaryrefslogtreecommitdiffstats
path: root/net/sched
diff options
context:
space:
mode:
authorDaniel Borkmann <dborkman@redhat.com>2013-12-29 12:27:10 -0500
committerPablo Neira Ayuso <pablo@netfilter.org>2014-01-03 17:41:41 -0500
commitfe1217c4f3f7d7cbf8efdd8dd5fdc7204a1d65a8 (patch)
treeac34c3a9183c96cbe695a29614de6f65a7934849 /net/sched
parent14abfa161d256c60f3ea6ba494704ac634b94f63 (diff)
net: net_cls: move cgroupfs classid handling into core
Zefan Li requested [1] to perform the following cleanup/refactoring: - Split cgroupfs classid handling into net core to better express a possible more generic use. - Disable module support for cgroupfs bits as the majority of other cgroupfs subsystems do not have that, and seems to be not wished from cgroup side. Zefan probably might want to follow-up for netprio later on. - By this, code can be further reduced which previously took care of functionality built when compiled as module. cgroupfs bits are being placed under net/core/netclassid_cgroup.c, so that we are consistent with {netclassid,netprio}_cgroup naming that is under net/core/ as suggested by Zefan. No change in functionality, but only code refactoring that is being done here. [1] http://patchwork.ozlabs.org/patch/304825/ Suggested-by: Li Zefan <lizefan@huawei.com> Signed-off-by: Daniel Borkmann <dborkman@redhat.com> Cc: Zefan Li <lizefan@huawei.com> Cc: Thomas Graf <tgraf@suug.ch> Cc: cgroups@vger.kernel.org Acked-by: Li Zefan <lizefan@huawei.com> Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
Diffstat (limited to 'net/sched')
-rw-r--r--net/sched/Kconfig1
-rw-r--r--net/sched/cls_cgroup.c111
2 files changed, 2 insertions, 110 deletions
diff --git a/net/sched/Kconfig b/net/sched/Kconfig
index ad1f1d819203..f711a471d0b7 100644
--- a/net/sched/Kconfig
+++ b/net/sched/Kconfig
@@ -435,6 +435,7 @@ config NET_CLS_FLOW
435config NET_CLS_CGROUP 435config NET_CLS_CGROUP
436 tristate "Control Group Classifier" 436 tristate "Control Group Classifier"
437 select NET_CLS 437 select NET_CLS
438 select CGROUP_NET_CLASSID
438 depends on CGROUPS 439 depends on CGROUPS
439 ---help--- 440 ---help---
440 Say Y here if you want to classify packets based on the control 441 Say Y here if you want to classify packets based on the control
diff --git a/net/sched/cls_cgroup.c b/net/sched/cls_cgroup.c
index 16006c92c3fd..838fa40abad1 100644
--- a/net/sched/cls_cgroup.c
+++ b/net/sched/cls_cgroup.c
@@ -11,109 +11,13 @@
11 11
12#include <linux/module.h> 12#include <linux/module.h>
13#include <linux/slab.h> 13#include <linux/slab.h>
14#include <linux/types.h>
15#include <linux/string.h>
16#include <linux/errno.h>
17#include <linux/skbuff.h> 14#include <linux/skbuff.h>
18#include <linux/cgroup.h>
19#include <linux/rcupdate.h> 15#include <linux/rcupdate.h>
20#include <linux/fdtable.h>
21#include <net/rtnetlink.h> 16#include <net/rtnetlink.h>
22#include <net/pkt_cls.h> 17#include <net/pkt_cls.h>
23#include <net/sock.h> 18#include <net/sock.h>
24#include <net/cls_cgroup.h> 19#include <net/cls_cgroup.h>
25 20
26static inline struct cgroup_cls_state *css_cls_state(struct cgroup_subsys_state *css)
27{
28 return css ? container_of(css, struct cgroup_cls_state, css) : NULL;
29}
30
31static inline struct cgroup_cls_state *task_cls_state(struct task_struct *p)
32{
33 return css_cls_state(task_css(p, net_cls_subsys_id));
34}
35
36static struct cgroup_subsys_state *
37cgrp_css_alloc(struct cgroup_subsys_state *parent_css)
38{
39 struct cgroup_cls_state *cs;
40
41 cs = kzalloc(sizeof(*cs), GFP_KERNEL);
42 if (!cs)
43 return ERR_PTR(-ENOMEM);
44 return &cs->css;
45}
46
47static int cgrp_css_online(struct cgroup_subsys_state *css)
48{
49 struct cgroup_cls_state *cs = css_cls_state(css);
50 struct cgroup_cls_state *parent = css_cls_state(css_parent(css));
51
52 if (parent)
53 cs->classid = parent->classid;
54 return 0;
55}
56
57static void cgrp_css_free(struct cgroup_subsys_state *css)
58{
59 kfree(css_cls_state(css));
60}
61
62static int update_classid(const void *v, struct file *file, unsigned n)
63{
64 int err;
65 struct socket *sock = sock_from_file(file, &err);
66 if (sock)
67 sock->sk->sk_classid = (u32)(unsigned long)v;
68 return 0;
69}
70
71static void cgrp_attach(struct cgroup_subsys_state *css,
72 struct cgroup_taskset *tset)
73{
74 struct task_struct *p;
75 struct cgroup_cls_state *cs = css_cls_state(css);
76 void *v = (void *)(unsigned long)cs->classid;
77
78 cgroup_taskset_for_each(p, css, tset) {
79 task_lock(p);
80 iterate_fd(p->files, 0, update_classid, v);
81 task_unlock(p);
82 }
83}
84
85static u64 read_classid(struct cgroup_subsys_state *css, struct cftype *cft)
86{
87 return css_cls_state(css)->classid;
88}
89
90static int write_classid(struct cgroup_subsys_state *css, struct cftype *cft,
91 u64 value)
92{
93 css_cls_state(css)->classid = (u32) value;
94 return 0;
95}
96
97static struct cftype ss_files[] = {
98 {
99 .name = "classid",
100 .read_u64 = read_classid,
101 .write_u64 = write_classid,
102 },
103 { } /* terminate */
104};
105
106struct cgroup_subsys net_cls_subsys = {
107 .name = "net_cls",
108 .css_alloc = cgrp_css_alloc,
109 .css_online = cgrp_css_online,
110 .css_free = cgrp_css_free,
111 .attach = cgrp_attach,
112 .subsys_id = net_cls_subsys_id,
113 .base_cftypes = ss_files,
114 .module = THIS_MODULE,
115};
116
117struct cls_cgroup_head { 21struct cls_cgroup_head {
118 u32 handle; 22 u32 handle;
119 struct tcf_exts exts; 23 struct tcf_exts exts;
@@ -309,25 +213,12 @@ static struct tcf_proto_ops cls_cgroup_ops __read_mostly = {
309 213
310static int __init init_cgroup_cls(void) 214static int __init init_cgroup_cls(void)
311{ 215{
312 int ret; 216 return register_tcf_proto_ops(&cls_cgroup_ops);
313
314 ret = cgroup_load_subsys(&net_cls_subsys);
315 if (ret)
316 goto out;
317
318 ret = register_tcf_proto_ops(&cls_cgroup_ops);
319 if (ret)
320 cgroup_unload_subsys(&net_cls_subsys);
321
322out:
323 return ret;
324} 217}
325 218
326static void __exit exit_cgroup_cls(void) 219static void __exit exit_cgroup_cls(void)
327{ 220{
328 unregister_tcf_proto_ops(&cls_cgroup_ops); 221 unregister_tcf_proto_ops(&cls_cgroup_ops);
329
330 cgroup_unload_subsys(&net_cls_subsys);
331} 222}
332 223
333module_init(init_cgroup_cls); 224module_init(init_cgroup_cls);