|
11 | 11 |
|
12 | 12 | #include <linux/module.h>
|
13 | 13 | #include <linux/slab.h>
|
14 |
| -#include <linux/types.h> |
15 |
| -#include <linux/string.h> |
16 |
| -#include <linux/errno.h> |
17 | 14 | #include <linux/skbuff.h>
|
18 |
| -#include <linux/cgroup.h> |
19 | 15 | #include <linux/rcupdate.h>
|
20 |
| -#include <linux/fdtable.h> |
21 | 16 | #include <net/rtnetlink.h>
|
22 | 17 | #include <net/pkt_cls.h>
|
23 | 18 | #include <net/sock.h>
|
24 | 19 | #include <net/cls_cgroup.h>
|
25 | 20 |
|
26 |
| -static 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 |
| - |
31 |
| -static 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 |
| - |
36 |
| -static struct cgroup_subsys_state * |
37 |
| -cgrp_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 |
| - |
47 |
| -static 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 |
| - |
57 |
| -static void cgrp_css_free(struct cgroup_subsys_state *css) |
58 |
| -{ |
59 |
| - kfree(css_cls_state(css)); |
60 |
| -} |
61 |
| - |
62 |
| -static 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 |
| - |
71 |
| -static 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 |
| - |
85 |
| -static u64 read_classid(struct cgroup_subsys_state *css, struct cftype *cft) |
86 |
| -{ |
87 |
| - return css_cls_state(css)->classid; |
88 |
| -} |
89 |
| - |
90 |
| -static 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 |
| - |
97 |
| -static struct cftype ss_files[] = { |
98 |
| - { |
99 |
| - .name = "classid", |
100 |
| - .read_u64 = read_classid, |
101 |
| - .write_u64 = write_classid, |
102 |
| - }, |
103 |
| - { } /* terminate */ |
104 |
| -}; |
105 |
| - |
106 |
| -struct 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 |
| - |
117 | 21 | struct cls_cgroup_head {
|
118 | 22 | u32 handle;
|
119 | 23 | struct tcf_exts exts;
|
@@ -309,25 +213,12 @@ static struct tcf_proto_ops cls_cgroup_ops __read_mostly = {
|
309 | 213 |
|
310 | 214 | static int __init init_cgroup_cls(void)
|
311 | 215 | {
|
312 |
| - int ret; |
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 |
| - |
322 |
| -out: |
323 |
| - return ret; |
| 216 | + return register_tcf_proto_ops(&cls_cgroup_ops); |
324 | 217 | }
|
325 | 218 |
|
326 | 219 | static void __exit exit_cgroup_cls(void)
|
327 | 220 | {
|
328 | 221 | unregister_tcf_proto_ops(&cls_cgroup_ops);
|
329 |
| - |
330 |
| - cgroup_unload_subsys(&net_cls_subsys); |
331 | 222 | }
|
332 | 223 |
|
333 | 224 | module_init(init_cgroup_cls);
|
|
0 commit comments