aboutsummaryrefslogtreecommitdiffstats
path: root/net/sched/cls_cgroup.c
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@linux-foundation.org>2014-01-25 14:17:34 -0500
committerLinus Torvalds <torvalds@linux-foundation.org>2014-01-25 14:17:34 -0500
commit4ba9920e5e9c0e16b5ed24292d45322907bb9035 (patch)
tree7d023baea59ed0886ded1f0b6d1c6385690b88f7 /net/sched/cls_cgroup.c
parent82c477669a4665eb4e52030792051e0559ee2a36 (diff)
parent8b662fe70c68282f78482dc272df0c4f355e49f5 (diff)
Merge git://git.kernel.org/pub/scm/linux/kernel/git/davem/net-next
Pull networking updates from David Miller: 1) BPF debugger and asm tool by Daniel Borkmann. 2) Speed up create/bind in AF_PACKET, also from Daniel Borkmann. 3) Correct reciprocal_divide and update users, from Hannes Frederic Sowa and Daniel Borkmann. 4) Currently we only have a "set" operation for the hw timestamp socket ioctl, add a "get" operation to match. From Ben Hutchings. 5) Add better trace events for debugging driver datapath problems, also from Ben Hutchings. 6) Implement auto corking in TCP, from Eric Dumazet. Basically, if we have a small send and a previous packet is already in the qdisc or device queue, defer until TX completion or we get more data. 7) Allow userspace to manage ipv6 temporary addresses, from Jiri Pirko. 8) Add a qdisc bypass option for AF_PACKET sockets, from Daniel Borkmann. 9) Share IP header compression code between Bluetooth and IEEE802154 layers, from Jukka Rissanen. 10) Fix ipv6 router reachability probing, from Jiri Benc. 11) Allow packets to be captured on macvtap devices, from Vlad Yasevich. 12) Support tunneling in GRO layer, from Jerry Chu. 13) Allow bonding to be configured fully using netlink, from Scott Feldman. 14) Allow AF_PACKET users to obtain the VLAN TPID, just like they can already get the TCI. From Atzm Watanabe. 15) New "Heavy Hitter" qdisc, from Terry Lam. 16) Significantly improve the IPSEC support in pktgen, from Fan Du. 17) Allow ipv4 tunnels to cache routes, just like sockets. From Tom Herbert. 18) Add Proportional Integral Enhanced packet scheduler, from Vijay Subramanian. 19) Allow openvswitch to mmap'd netlink, from Thomas Graf. 20) Key TCP metrics blobs also by source address, not just destination address. From Christoph Paasch. 21) Support 10G in generic phylib. From Andy Fleming. 22) Try to short-circuit GRO flow compares using device provided RX hash, if provided. From Tom Herbert. The wireless and netfilter folks have been busy little bees too. * git://git.kernel.org/pub/scm/linux/kernel/git/davem/net-next: (2064 commits) net/cxgb4: Fix referencing freed adapter ipv6: reallocate addrconf router for ipv6 address when lo device up fib_frontend: fix possible NULL pointer dereference rtnetlink: remove IFLA_BOND_SLAVE definition rtnetlink: remove check for fill_slave_info in rtnl_have_link_slave_info qlcnic: update version to 5.3.55 qlcnic: Enhance logic to calculate msix vectors. qlcnic: Refactor interrupt coalescing code for all adapters. qlcnic: Update poll controller code path qlcnic: Interrupt code cleanup qlcnic: Enhance Tx timeout debugging. qlcnic: Use bool for rx_mac_learn. bonding: fix u64 division rtnetlink: add missing IFLA_BOND_AD_INFO_UNSPEC sfc: Use the correct maximum TX DMA ring size for SFC9100 Add Shradha Shah as the sfc driver maintainer. net/vxlan: Share RX skb de-marking and checksum checks with ovs tulip: cleanup by using ARRAY_SIZE() ip_tunnel: clear IPCB in ip_tunnel_xmit() in case dst_link_failure() is called net/cxgb4: Don't retrieve stats during recovery ...
Diffstat (limited to 'net/sched/cls_cgroup.c')
-rw-r--r--net/sched/cls_cgroup.c127
1 files changed, 7 insertions, 120 deletions
diff --git a/net/sched/cls_cgroup.c b/net/sched/cls_cgroup.c
index 16006c92c3fd..8e2158ab551c 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;
@@ -172,11 +76,6 @@ static int cls_cgroup_init(struct tcf_proto *tp)
172 return 0; 76 return 0;
173} 77}
174 78
175static const struct tcf_ext_map cgroup_ext_map = {
176 .action = TCA_CGROUP_ACT,
177 .police = TCA_CGROUP_POLICE,
178};
179
180static const struct nla_policy cgroup_policy[TCA_CGROUP_MAX + 1] = { 79static const struct nla_policy cgroup_policy[TCA_CGROUP_MAX + 1] = {
181 [TCA_CGROUP_EMATCHES] = { .type = NLA_NESTED }, 80 [TCA_CGROUP_EMATCHES] = { .type = NLA_NESTED },
182}; 81};
@@ -203,6 +102,7 @@ static int cls_cgroup_change(struct net *net, struct sk_buff *in_skb,
203 if (head == NULL) 102 if (head == NULL)
204 return -ENOBUFS; 103 return -ENOBUFS;
205 104
105 tcf_exts_init(&head->exts, TCA_CGROUP_ACT, TCA_CGROUP_POLICE);
206 head->handle = handle; 106 head->handle = handle;
207 107
208 tcf_tree_lock(tp); 108 tcf_tree_lock(tp);
@@ -218,8 +118,8 @@ static int cls_cgroup_change(struct net *net, struct sk_buff *in_skb,
218 if (err < 0) 118 if (err < 0)
219 return err; 119 return err;
220 120
221 err = tcf_exts_validate(net, tp, tb, tca[TCA_RATE], &e, 121 tcf_exts_init(&e, TCA_CGROUP_ACT, TCA_CGROUP_POLICE);
222 &cgroup_ext_map); 122 err = tcf_exts_validate(net, tp, tb, tca[TCA_RATE], &e);
223 if (err < 0) 123 if (err < 0)
224 return err; 124 return err;
225 125
@@ -264,7 +164,7 @@ skip:
264 arg->count++; 164 arg->count++;
265} 165}
266 166
267static int cls_cgroup_dump(struct tcf_proto *tp, unsigned long fh, 167static int cls_cgroup_dump(struct net *net, struct tcf_proto *tp, unsigned long fh,
268 struct sk_buff *skb, struct tcmsg *t) 168 struct sk_buff *skb, struct tcmsg *t)
269{ 169{
270 struct cls_cgroup_head *head = tp->root; 170 struct cls_cgroup_head *head = tp->root;
@@ -277,13 +177,13 @@ static int cls_cgroup_dump(struct tcf_proto *tp, unsigned long fh,
277 if (nest == NULL) 177 if (nest == NULL)
278 goto nla_put_failure; 178 goto nla_put_failure;
279 179
280 if (tcf_exts_dump(skb, &head->exts, &cgroup_ext_map) < 0 || 180 if (tcf_exts_dump(skb, &head->exts) < 0 ||
281 tcf_em_tree_dump(skb, &head->ematches, TCA_CGROUP_EMATCHES) < 0) 181 tcf_em_tree_dump(skb, &head->ematches, TCA_CGROUP_EMATCHES) < 0)
282 goto nla_put_failure; 182 goto nla_put_failure;
283 183
284 nla_nest_end(skb, nest); 184 nla_nest_end(skb, nest);
285 185
286 if (tcf_exts_dump_stats(skb, &head->exts, &cgroup_ext_map) < 0) 186 if (tcf_exts_dump_stats(skb, &head->exts) < 0)
287 goto nla_put_failure; 187 goto nla_put_failure;
288 188
289 return skb->len; 189 return skb->len;
@@ -309,25 +209,12 @@ static struct tcf_proto_ops cls_cgroup_ops __read_mostly = {
309 209
310static int __init init_cgroup_cls(void) 210static int __init init_cgroup_cls(void)
311{ 211{
312 int ret; 212 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} 213}
325 214
326static void __exit exit_cgroup_cls(void) 215static void __exit exit_cgroup_cls(void)
327{ 216{
328 unregister_tcf_proto_ops(&cls_cgroup_ops); 217 unregister_tcf_proto_ops(&cls_cgroup_ops);
329
330 cgroup_unload_subsys(&net_cls_subsys);
331} 218}
332 219
333module_init(init_cgroup_cls); 220module_init(init_cgroup_cls);