cls_cgroup.c revision 47a1a1d4be2910b13a8e90f75c17e253c39531ff
1f400923735ecbb67cbe4a3606c9479f694754f51Thomas Graf/*
2f400923735ecbb67cbe4a3606c9479f694754f51Thomas Graf * net/sched/cls_cgroup.c	Control Group Classifier
3f400923735ecbb67cbe4a3606c9479f694754f51Thomas Graf *
4f400923735ecbb67cbe4a3606c9479f694754f51Thomas Graf *		This program is free software; you can redistribute it and/or
5f400923735ecbb67cbe4a3606c9479f694754f51Thomas Graf *		modify it under the terms of the GNU General Public License
6f400923735ecbb67cbe4a3606c9479f694754f51Thomas Graf *		as published by the Free Software Foundation; either version
7f400923735ecbb67cbe4a3606c9479f694754f51Thomas Graf *		2 of the License, or (at your option) any later version.
8f400923735ecbb67cbe4a3606c9479f694754f51Thomas Graf *
9f400923735ecbb67cbe4a3606c9479f694754f51Thomas Graf * Authors:	Thomas Graf <tgraf@suug.ch>
10f400923735ecbb67cbe4a3606c9479f694754f51Thomas Graf */
11f400923735ecbb67cbe4a3606c9479f694754f51Thomas Graf
12f400923735ecbb67cbe4a3606c9479f694754f51Thomas Graf#include <linux/module.h>
13f400923735ecbb67cbe4a3606c9479f694754f51Thomas Graf#include <linux/types.h>
14f400923735ecbb67cbe4a3606c9479f694754f51Thomas Graf#include <linux/string.h>
15f400923735ecbb67cbe4a3606c9479f694754f51Thomas Graf#include <linux/errno.h>
16f400923735ecbb67cbe4a3606c9479f694754f51Thomas Graf#include <linux/skbuff.h>
17f400923735ecbb67cbe4a3606c9479f694754f51Thomas Graf#include <linux/cgroup.h>
18f400923735ecbb67cbe4a3606c9479f694754f51Thomas Graf#include <net/rtnetlink.h>
19f400923735ecbb67cbe4a3606c9479f694754f51Thomas Graf#include <net/pkt_cls.h>
20f400923735ecbb67cbe4a3606c9479f694754f51Thomas Graf
21f400923735ecbb67cbe4a3606c9479f694754f51Thomas Grafstruct cgroup_cls_state
22f400923735ecbb67cbe4a3606c9479f694754f51Thomas Graf{
23f400923735ecbb67cbe4a3606c9479f694754f51Thomas Graf	struct cgroup_subsys_state css;
24f400923735ecbb67cbe4a3606c9479f694754f51Thomas Graf	u32 classid;
25f400923735ecbb67cbe4a3606c9479f694754f51Thomas Graf};
26f400923735ecbb67cbe4a3606c9479f694754f51Thomas Graf
27f400923735ecbb67cbe4a3606c9479f694754f51Thomas Grafstatic inline struct cgroup_cls_state *net_cls_state(struct cgroup *cgrp)
28f400923735ecbb67cbe4a3606c9479f694754f51Thomas Graf{
29f400923735ecbb67cbe4a3606c9479f694754f51Thomas Graf	return (struct cgroup_cls_state *)
30f400923735ecbb67cbe4a3606c9479f694754f51Thomas Graf		cgroup_subsys_state(cgrp, net_cls_subsys_id);
31f400923735ecbb67cbe4a3606c9479f694754f51Thomas Graf}
32f400923735ecbb67cbe4a3606c9479f694754f51Thomas Graf
33f400923735ecbb67cbe4a3606c9479f694754f51Thomas Grafstatic struct cgroup_subsys_state *cgrp_create(struct cgroup_subsys *ss,
34f400923735ecbb67cbe4a3606c9479f694754f51Thomas Graf						 struct cgroup *cgrp)
35f400923735ecbb67cbe4a3606c9479f694754f51Thomas Graf{
36f400923735ecbb67cbe4a3606c9479f694754f51Thomas Graf	struct cgroup_cls_state *cs;
37f400923735ecbb67cbe4a3606c9479f694754f51Thomas Graf
38f400923735ecbb67cbe4a3606c9479f694754f51Thomas Graf	if (!(cs = kzalloc(sizeof(*cs), GFP_KERNEL)))
39f400923735ecbb67cbe4a3606c9479f694754f51Thomas Graf		return ERR_PTR(-ENOMEM);
40f400923735ecbb67cbe4a3606c9479f694754f51Thomas Graf
41f400923735ecbb67cbe4a3606c9479f694754f51Thomas Graf	if (cgrp->parent)
42f400923735ecbb67cbe4a3606c9479f694754f51Thomas Graf		cs->classid = net_cls_state(cgrp->parent)->classid;
43f400923735ecbb67cbe4a3606c9479f694754f51Thomas Graf
44f400923735ecbb67cbe4a3606c9479f694754f51Thomas Graf	return &cs->css;
45f400923735ecbb67cbe4a3606c9479f694754f51Thomas Graf}
46f400923735ecbb67cbe4a3606c9479f694754f51Thomas Graf
47f400923735ecbb67cbe4a3606c9479f694754f51Thomas Grafstatic void cgrp_destroy(struct cgroup_subsys *ss, struct cgroup *cgrp)
48f400923735ecbb67cbe4a3606c9479f694754f51Thomas Graf{
49f400923735ecbb67cbe4a3606c9479f694754f51Thomas Graf	kfree(ss);
50f400923735ecbb67cbe4a3606c9479f694754f51Thomas Graf}
51f400923735ecbb67cbe4a3606c9479f694754f51Thomas Graf
52f400923735ecbb67cbe4a3606c9479f694754f51Thomas Grafstatic u64 read_classid(struct cgroup *cgrp, struct cftype *cft)
53f400923735ecbb67cbe4a3606c9479f694754f51Thomas Graf{
54f400923735ecbb67cbe4a3606c9479f694754f51Thomas Graf	return net_cls_state(cgrp)->classid;
55f400923735ecbb67cbe4a3606c9479f694754f51Thomas Graf}
56f400923735ecbb67cbe4a3606c9479f694754f51Thomas Graf
57f400923735ecbb67cbe4a3606c9479f694754f51Thomas Grafstatic int write_classid(struct cgroup *cgrp, struct cftype *cft, u64 value)
58f400923735ecbb67cbe4a3606c9479f694754f51Thomas Graf{
59f400923735ecbb67cbe4a3606c9479f694754f51Thomas Graf	if (!cgroup_lock_live_group(cgrp))
60f400923735ecbb67cbe4a3606c9479f694754f51Thomas Graf		return -ENODEV;
61f400923735ecbb67cbe4a3606c9479f694754f51Thomas Graf
62f400923735ecbb67cbe4a3606c9479f694754f51Thomas Graf	net_cls_state(cgrp)->classid = (u32) value;
63f400923735ecbb67cbe4a3606c9479f694754f51Thomas Graf
64f400923735ecbb67cbe4a3606c9479f694754f51Thomas Graf	cgroup_unlock();
65f400923735ecbb67cbe4a3606c9479f694754f51Thomas Graf
66f400923735ecbb67cbe4a3606c9479f694754f51Thomas Graf	return 0;
67f400923735ecbb67cbe4a3606c9479f694754f51Thomas Graf}
68f400923735ecbb67cbe4a3606c9479f694754f51Thomas Graf
69f400923735ecbb67cbe4a3606c9479f694754f51Thomas Grafstatic struct cftype ss_files[] = {
70f400923735ecbb67cbe4a3606c9479f694754f51Thomas Graf	{
71f400923735ecbb67cbe4a3606c9479f694754f51Thomas Graf		.name = "classid",
72f400923735ecbb67cbe4a3606c9479f694754f51Thomas Graf		.read_u64 = read_classid,
73f400923735ecbb67cbe4a3606c9479f694754f51Thomas Graf		.write_u64 = write_classid,
74f400923735ecbb67cbe4a3606c9479f694754f51Thomas Graf	},
75f400923735ecbb67cbe4a3606c9479f694754f51Thomas Graf};
76f400923735ecbb67cbe4a3606c9479f694754f51Thomas Graf
77f400923735ecbb67cbe4a3606c9479f694754f51Thomas Grafstatic int cgrp_populate(struct cgroup_subsys *ss, struct cgroup *cgrp)
78f400923735ecbb67cbe4a3606c9479f694754f51Thomas Graf{
79f400923735ecbb67cbe4a3606c9479f694754f51Thomas Graf	return cgroup_add_files(cgrp, ss, ss_files, ARRAY_SIZE(ss_files));
80f400923735ecbb67cbe4a3606c9479f694754f51Thomas Graf}
81f400923735ecbb67cbe4a3606c9479f694754f51Thomas Graf
82f400923735ecbb67cbe4a3606c9479f694754f51Thomas Grafstruct cgroup_subsys net_cls_subsys = {
83f400923735ecbb67cbe4a3606c9479f694754f51Thomas Graf	.name		= "net_cls",
84f400923735ecbb67cbe4a3606c9479f694754f51Thomas Graf	.create		= cgrp_create,
85f400923735ecbb67cbe4a3606c9479f694754f51Thomas Graf	.destroy	= cgrp_destroy,
86f400923735ecbb67cbe4a3606c9479f694754f51Thomas Graf	.populate	= cgrp_populate,
87f400923735ecbb67cbe4a3606c9479f694754f51Thomas Graf	.subsys_id	= net_cls_subsys_id,
88f400923735ecbb67cbe4a3606c9479f694754f51Thomas Graf};
89f400923735ecbb67cbe4a3606c9479f694754f51Thomas Graf
90f400923735ecbb67cbe4a3606c9479f694754f51Thomas Grafstruct cls_cgroup_head
91f400923735ecbb67cbe4a3606c9479f694754f51Thomas Graf{
92f400923735ecbb67cbe4a3606c9479f694754f51Thomas Graf	u32			handle;
93f400923735ecbb67cbe4a3606c9479f694754f51Thomas Graf	struct tcf_exts		exts;
94f400923735ecbb67cbe4a3606c9479f694754f51Thomas Graf	struct tcf_ematch_tree	ematches;
95f400923735ecbb67cbe4a3606c9479f694754f51Thomas Graf};
96f400923735ecbb67cbe4a3606c9479f694754f51Thomas Graf
97f400923735ecbb67cbe4a3606c9479f694754f51Thomas Grafstatic int cls_cgroup_classify(struct sk_buff *skb, struct tcf_proto *tp,
98f400923735ecbb67cbe4a3606c9479f694754f51Thomas Graf			       struct tcf_result *res)
99f400923735ecbb67cbe4a3606c9479f694754f51Thomas Graf{
100f400923735ecbb67cbe4a3606c9479f694754f51Thomas Graf	struct cls_cgroup_head *head = tp->root;
101f400923735ecbb67cbe4a3606c9479f694754f51Thomas Graf	struct cgroup_cls_state *cs;
102f400923735ecbb67cbe4a3606c9479f694754f51Thomas Graf	int ret = 0;
103f400923735ecbb67cbe4a3606c9479f694754f51Thomas Graf
104f400923735ecbb67cbe4a3606c9479f694754f51Thomas Graf	/*
105f400923735ecbb67cbe4a3606c9479f694754f51Thomas Graf	 * Due to the nature of the classifier it is required to ignore all
106f400923735ecbb67cbe4a3606c9479f694754f51Thomas Graf	 * packets originating from softirq context as accessing `current'
107f400923735ecbb67cbe4a3606c9479f694754f51Thomas Graf	 * would lead to false results.
108f400923735ecbb67cbe4a3606c9479f694754f51Thomas Graf	 *
109f400923735ecbb67cbe4a3606c9479f694754f51Thomas Graf	 * This test assumes that all callers of dev_queue_xmit() explicitely
110f400923735ecbb67cbe4a3606c9479f694754f51Thomas Graf	 * disable bh. Knowing this, it is possible to detect softirq based
111f400923735ecbb67cbe4a3606c9479f694754f51Thomas Graf	 * calls by looking at the number of nested bh disable calls because
112f400923735ecbb67cbe4a3606c9479f694754f51Thomas Graf	 * softirqs always disables bh.
113f400923735ecbb67cbe4a3606c9479f694754f51Thomas Graf	 */
114f400923735ecbb67cbe4a3606c9479f694754f51Thomas Graf	if (softirq_count() != SOFTIRQ_OFFSET)
115f400923735ecbb67cbe4a3606c9479f694754f51Thomas Graf		return -1;
116f400923735ecbb67cbe4a3606c9479f694754f51Thomas Graf
117f400923735ecbb67cbe4a3606c9479f694754f51Thomas Graf	rcu_read_lock();
118f400923735ecbb67cbe4a3606c9479f694754f51Thomas Graf	cs = (struct cgroup_cls_state *) task_subsys_state(current,
119f400923735ecbb67cbe4a3606c9479f694754f51Thomas Graf							   net_cls_subsys_id);
120f400923735ecbb67cbe4a3606c9479f694754f51Thomas Graf	if (cs->classid && tcf_em_tree_match(skb, &head->ematches, NULL)) {
121f400923735ecbb67cbe4a3606c9479f694754f51Thomas Graf		res->classid = cs->classid;
122f400923735ecbb67cbe4a3606c9479f694754f51Thomas Graf		res->class = 0;
123f400923735ecbb67cbe4a3606c9479f694754f51Thomas Graf		ret = tcf_exts_exec(skb, &head->exts, res);
124f400923735ecbb67cbe4a3606c9479f694754f51Thomas Graf	} else
125f400923735ecbb67cbe4a3606c9479f694754f51Thomas Graf		ret = -1;
126f400923735ecbb67cbe4a3606c9479f694754f51Thomas Graf
127f400923735ecbb67cbe4a3606c9479f694754f51Thomas Graf	rcu_read_unlock();
128f400923735ecbb67cbe4a3606c9479f694754f51Thomas Graf
129f400923735ecbb67cbe4a3606c9479f694754f51Thomas Graf	return ret;
130f400923735ecbb67cbe4a3606c9479f694754f51Thomas Graf}
131f400923735ecbb67cbe4a3606c9479f694754f51Thomas Graf
132f400923735ecbb67cbe4a3606c9479f694754f51Thomas Grafstatic unsigned long cls_cgroup_get(struct tcf_proto *tp, u32 handle)
133f400923735ecbb67cbe4a3606c9479f694754f51Thomas Graf{
134f400923735ecbb67cbe4a3606c9479f694754f51Thomas Graf	return 0UL;
135f400923735ecbb67cbe4a3606c9479f694754f51Thomas Graf}
136f400923735ecbb67cbe4a3606c9479f694754f51Thomas Graf
137f400923735ecbb67cbe4a3606c9479f694754f51Thomas Grafstatic void cls_cgroup_put(struct tcf_proto *tp, unsigned long f)
138f400923735ecbb67cbe4a3606c9479f694754f51Thomas Graf{
139f400923735ecbb67cbe4a3606c9479f694754f51Thomas Graf}
140f400923735ecbb67cbe4a3606c9479f694754f51Thomas Graf
141f400923735ecbb67cbe4a3606c9479f694754f51Thomas Grafstatic int cls_cgroup_init(struct tcf_proto *tp)
142f400923735ecbb67cbe4a3606c9479f694754f51Thomas Graf{
143f400923735ecbb67cbe4a3606c9479f694754f51Thomas Graf	return 0;
144f400923735ecbb67cbe4a3606c9479f694754f51Thomas Graf}
145f400923735ecbb67cbe4a3606c9479f694754f51Thomas Graf
146f400923735ecbb67cbe4a3606c9479f694754f51Thomas Grafstatic const struct tcf_ext_map cgroup_ext_map = {
147f400923735ecbb67cbe4a3606c9479f694754f51Thomas Graf	.action = TCA_CGROUP_ACT,
148f400923735ecbb67cbe4a3606c9479f694754f51Thomas Graf	.police = TCA_CGROUP_POLICE,
149f400923735ecbb67cbe4a3606c9479f694754f51Thomas Graf};
150f400923735ecbb67cbe4a3606c9479f694754f51Thomas Graf
151f400923735ecbb67cbe4a3606c9479f694754f51Thomas Grafstatic const struct nla_policy cgroup_policy[TCA_CGROUP_MAX + 1] = {
152f400923735ecbb67cbe4a3606c9479f694754f51Thomas Graf	[TCA_CGROUP_EMATCHES]	= { .type = NLA_NESTED },
153f400923735ecbb67cbe4a3606c9479f694754f51Thomas Graf};
154f400923735ecbb67cbe4a3606c9479f694754f51Thomas Graf
155f400923735ecbb67cbe4a3606c9479f694754f51Thomas Grafstatic int cls_cgroup_change(struct tcf_proto *tp, unsigned long base,
156f400923735ecbb67cbe4a3606c9479f694754f51Thomas Graf			     u32 handle, struct nlattr **tca,
157f400923735ecbb67cbe4a3606c9479f694754f51Thomas Graf			     unsigned long *arg)
158f400923735ecbb67cbe4a3606c9479f694754f51Thomas Graf{
159f400923735ecbb67cbe4a3606c9479f694754f51Thomas Graf	struct nlattr *tb[TCA_CGROUP_MAX+1];
160f400923735ecbb67cbe4a3606c9479f694754f51Thomas Graf	struct cls_cgroup_head *head = tp->root;
161f400923735ecbb67cbe4a3606c9479f694754f51Thomas Graf	struct tcf_ematch_tree t;
162f400923735ecbb67cbe4a3606c9479f694754f51Thomas Graf	struct tcf_exts e;
163f400923735ecbb67cbe4a3606c9479f694754f51Thomas Graf	int err;
164f400923735ecbb67cbe4a3606c9479f694754f51Thomas Graf
165f400923735ecbb67cbe4a3606c9479f694754f51Thomas Graf	if (head == NULL) {
166f400923735ecbb67cbe4a3606c9479f694754f51Thomas Graf		if (!handle)
167f400923735ecbb67cbe4a3606c9479f694754f51Thomas Graf			return -EINVAL;
168f400923735ecbb67cbe4a3606c9479f694754f51Thomas Graf
169f400923735ecbb67cbe4a3606c9479f694754f51Thomas Graf		head = kzalloc(sizeof(*head), GFP_KERNEL);
170f400923735ecbb67cbe4a3606c9479f694754f51Thomas Graf		if (head == NULL)
171f400923735ecbb67cbe4a3606c9479f694754f51Thomas Graf			return -ENOBUFS;
172f400923735ecbb67cbe4a3606c9479f694754f51Thomas Graf
173f400923735ecbb67cbe4a3606c9479f694754f51Thomas Graf		head->handle = handle;
174f400923735ecbb67cbe4a3606c9479f694754f51Thomas Graf
175f400923735ecbb67cbe4a3606c9479f694754f51Thomas Graf		tcf_tree_lock(tp);
176f400923735ecbb67cbe4a3606c9479f694754f51Thomas Graf		tp->root = head;
177f400923735ecbb67cbe4a3606c9479f694754f51Thomas Graf		tcf_tree_unlock(tp);
178f400923735ecbb67cbe4a3606c9479f694754f51Thomas Graf	}
179f400923735ecbb67cbe4a3606c9479f694754f51Thomas Graf
180f400923735ecbb67cbe4a3606c9479f694754f51Thomas Graf	if (handle != head->handle)
181f400923735ecbb67cbe4a3606c9479f694754f51Thomas Graf		return -ENOENT;
182f400923735ecbb67cbe4a3606c9479f694754f51Thomas Graf
183f400923735ecbb67cbe4a3606c9479f694754f51Thomas Graf	err = nla_parse_nested(tb, TCA_CGROUP_MAX, tca[TCA_OPTIONS],
184f400923735ecbb67cbe4a3606c9479f694754f51Thomas Graf			       cgroup_policy);
185f400923735ecbb67cbe4a3606c9479f694754f51Thomas Graf	if (err < 0)
186f400923735ecbb67cbe4a3606c9479f694754f51Thomas Graf		return err;
187f400923735ecbb67cbe4a3606c9479f694754f51Thomas Graf
188f400923735ecbb67cbe4a3606c9479f694754f51Thomas Graf	err = tcf_exts_validate(tp, tb, tca[TCA_RATE], &e, &cgroup_ext_map);
189f400923735ecbb67cbe4a3606c9479f694754f51Thomas Graf	if (err < 0)
190f400923735ecbb67cbe4a3606c9479f694754f51Thomas Graf		return err;
191f400923735ecbb67cbe4a3606c9479f694754f51Thomas Graf
192f400923735ecbb67cbe4a3606c9479f694754f51Thomas Graf	err = tcf_em_tree_validate(tp, tb[TCA_CGROUP_EMATCHES], &t);
193f400923735ecbb67cbe4a3606c9479f694754f51Thomas Graf	if (err < 0)
194f400923735ecbb67cbe4a3606c9479f694754f51Thomas Graf		return err;
195f400923735ecbb67cbe4a3606c9479f694754f51Thomas Graf
196f400923735ecbb67cbe4a3606c9479f694754f51Thomas Graf	tcf_exts_change(tp, &head->exts, &e);
197f400923735ecbb67cbe4a3606c9479f694754f51Thomas Graf	tcf_em_tree_change(tp, &head->ematches, &t);
198f400923735ecbb67cbe4a3606c9479f694754f51Thomas Graf
199f400923735ecbb67cbe4a3606c9479f694754f51Thomas Graf	return 0;
200f400923735ecbb67cbe4a3606c9479f694754f51Thomas Graf}
201f400923735ecbb67cbe4a3606c9479f694754f51Thomas Graf
202f400923735ecbb67cbe4a3606c9479f694754f51Thomas Grafstatic void cls_cgroup_destroy(struct tcf_proto *tp)
203f400923735ecbb67cbe4a3606c9479f694754f51Thomas Graf{
20447a1a1d4be2910b13a8e90f75c17e253c39531ffPatrick McHardy	struct cls_cgroup_head *head = tp->root;
205f400923735ecbb67cbe4a3606c9479f694754f51Thomas Graf
206f400923735ecbb67cbe4a3606c9479f694754f51Thomas Graf	if (head) {
207f400923735ecbb67cbe4a3606c9479f694754f51Thomas Graf		tcf_exts_destroy(tp, &head->exts);
208f400923735ecbb67cbe4a3606c9479f694754f51Thomas Graf		tcf_em_tree_destroy(tp, &head->ematches);
209f400923735ecbb67cbe4a3606c9479f694754f51Thomas Graf		kfree(head);
210f400923735ecbb67cbe4a3606c9479f694754f51Thomas Graf	}
211f400923735ecbb67cbe4a3606c9479f694754f51Thomas Graf}
212f400923735ecbb67cbe4a3606c9479f694754f51Thomas Graf
213f400923735ecbb67cbe4a3606c9479f694754f51Thomas Grafstatic int cls_cgroup_delete(struct tcf_proto *tp, unsigned long arg)
214f400923735ecbb67cbe4a3606c9479f694754f51Thomas Graf{
215f400923735ecbb67cbe4a3606c9479f694754f51Thomas Graf	return -EOPNOTSUPP;
216f400923735ecbb67cbe4a3606c9479f694754f51Thomas Graf}
217f400923735ecbb67cbe4a3606c9479f694754f51Thomas Graf
218f400923735ecbb67cbe4a3606c9479f694754f51Thomas Grafstatic void cls_cgroup_walk(struct tcf_proto *tp, struct tcf_walker *arg)
219f400923735ecbb67cbe4a3606c9479f694754f51Thomas Graf{
220f400923735ecbb67cbe4a3606c9479f694754f51Thomas Graf	struct cls_cgroup_head *head = tp->root;
221f400923735ecbb67cbe4a3606c9479f694754f51Thomas Graf
222f400923735ecbb67cbe4a3606c9479f694754f51Thomas Graf	if (arg->count < arg->skip)
223f400923735ecbb67cbe4a3606c9479f694754f51Thomas Graf		goto skip;
224f400923735ecbb67cbe4a3606c9479f694754f51Thomas Graf
225f400923735ecbb67cbe4a3606c9479f694754f51Thomas Graf	if (arg->fn(tp, (unsigned long) head, arg) < 0) {
226f400923735ecbb67cbe4a3606c9479f694754f51Thomas Graf		arg->stop = 1;
227f400923735ecbb67cbe4a3606c9479f694754f51Thomas Graf		return;
228f400923735ecbb67cbe4a3606c9479f694754f51Thomas Graf	}
229f400923735ecbb67cbe4a3606c9479f694754f51Thomas Grafskip:
230f400923735ecbb67cbe4a3606c9479f694754f51Thomas Graf	arg->count++;
231f400923735ecbb67cbe4a3606c9479f694754f51Thomas Graf}
232f400923735ecbb67cbe4a3606c9479f694754f51Thomas Graf
233f400923735ecbb67cbe4a3606c9479f694754f51Thomas Grafstatic int cls_cgroup_dump(struct tcf_proto *tp, unsigned long fh,
234f400923735ecbb67cbe4a3606c9479f694754f51Thomas Graf			   struct sk_buff *skb, struct tcmsg *t)
235f400923735ecbb67cbe4a3606c9479f694754f51Thomas Graf{
236f400923735ecbb67cbe4a3606c9479f694754f51Thomas Graf	struct cls_cgroup_head *head = tp->root;
237f400923735ecbb67cbe4a3606c9479f694754f51Thomas Graf	unsigned char *b = skb_tail_pointer(skb);
238f400923735ecbb67cbe4a3606c9479f694754f51Thomas Graf	struct nlattr *nest;
239f400923735ecbb67cbe4a3606c9479f694754f51Thomas Graf
240f400923735ecbb67cbe4a3606c9479f694754f51Thomas Graf	t->tcm_handle = head->handle;
241f400923735ecbb67cbe4a3606c9479f694754f51Thomas Graf
242f400923735ecbb67cbe4a3606c9479f694754f51Thomas Graf	nest = nla_nest_start(skb, TCA_OPTIONS);
243f400923735ecbb67cbe4a3606c9479f694754f51Thomas Graf	if (nest == NULL)
244f400923735ecbb67cbe4a3606c9479f694754f51Thomas Graf		goto nla_put_failure;
245f400923735ecbb67cbe4a3606c9479f694754f51Thomas Graf
246f400923735ecbb67cbe4a3606c9479f694754f51Thomas Graf	if (tcf_exts_dump(skb, &head->exts, &cgroup_ext_map) < 0 ||
247f400923735ecbb67cbe4a3606c9479f694754f51Thomas Graf	    tcf_em_tree_dump(skb, &head->ematches, TCA_CGROUP_EMATCHES) < 0)
248f400923735ecbb67cbe4a3606c9479f694754f51Thomas Graf		goto nla_put_failure;
249f400923735ecbb67cbe4a3606c9479f694754f51Thomas Graf
250f400923735ecbb67cbe4a3606c9479f694754f51Thomas Graf	nla_nest_end(skb, nest);
251f400923735ecbb67cbe4a3606c9479f694754f51Thomas Graf
252f400923735ecbb67cbe4a3606c9479f694754f51Thomas Graf	if (tcf_exts_dump_stats(skb, &head->exts, &cgroup_ext_map) < 0)
253f400923735ecbb67cbe4a3606c9479f694754f51Thomas Graf		goto nla_put_failure;
254f400923735ecbb67cbe4a3606c9479f694754f51Thomas Graf
255f400923735ecbb67cbe4a3606c9479f694754f51Thomas Graf	return skb->len;
256f400923735ecbb67cbe4a3606c9479f694754f51Thomas Graf
257f400923735ecbb67cbe4a3606c9479f694754f51Thomas Grafnla_put_failure:
258f400923735ecbb67cbe4a3606c9479f694754f51Thomas Graf	nlmsg_trim(skb, b);
259f400923735ecbb67cbe4a3606c9479f694754f51Thomas Graf	return -1;
260f400923735ecbb67cbe4a3606c9479f694754f51Thomas Graf}
261f400923735ecbb67cbe4a3606c9479f694754f51Thomas Graf
262f400923735ecbb67cbe4a3606c9479f694754f51Thomas Grafstatic struct tcf_proto_ops cls_cgroup_ops __read_mostly = {
263f400923735ecbb67cbe4a3606c9479f694754f51Thomas Graf	.kind		=	"cgroup",
264f400923735ecbb67cbe4a3606c9479f694754f51Thomas Graf	.init		=	cls_cgroup_init,
265f400923735ecbb67cbe4a3606c9479f694754f51Thomas Graf	.change		=	cls_cgroup_change,
266f400923735ecbb67cbe4a3606c9479f694754f51Thomas Graf	.classify	=	cls_cgroup_classify,
267f400923735ecbb67cbe4a3606c9479f694754f51Thomas Graf	.destroy	=	cls_cgroup_destroy,
268f400923735ecbb67cbe4a3606c9479f694754f51Thomas Graf	.get		=	cls_cgroup_get,
269f400923735ecbb67cbe4a3606c9479f694754f51Thomas Graf	.put		=	cls_cgroup_put,
270f400923735ecbb67cbe4a3606c9479f694754f51Thomas Graf	.delete		=	cls_cgroup_delete,
271f400923735ecbb67cbe4a3606c9479f694754f51Thomas Graf	.walk		=	cls_cgroup_walk,
272f400923735ecbb67cbe4a3606c9479f694754f51Thomas Graf	.dump		=	cls_cgroup_dump,
273f400923735ecbb67cbe4a3606c9479f694754f51Thomas Graf	.owner		=	THIS_MODULE,
274f400923735ecbb67cbe4a3606c9479f694754f51Thomas Graf};
275f400923735ecbb67cbe4a3606c9479f694754f51Thomas Graf
276f400923735ecbb67cbe4a3606c9479f694754f51Thomas Grafstatic int __init init_cgroup_cls(void)
277f400923735ecbb67cbe4a3606c9479f694754f51Thomas Graf{
278f400923735ecbb67cbe4a3606c9479f694754f51Thomas Graf	return register_tcf_proto_ops(&cls_cgroup_ops);
279f400923735ecbb67cbe4a3606c9479f694754f51Thomas Graf}
280f400923735ecbb67cbe4a3606c9479f694754f51Thomas Graf
281f400923735ecbb67cbe4a3606c9479f694754f51Thomas Grafstatic void __exit exit_cgroup_cls(void)
282f400923735ecbb67cbe4a3606c9479f694754f51Thomas Graf{
283f400923735ecbb67cbe4a3606c9479f694754f51Thomas Graf	unregister_tcf_proto_ops(&cls_cgroup_ops);
284f400923735ecbb67cbe4a3606c9479f694754f51Thomas Graf}
285f400923735ecbb67cbe4a3606c9479f694754f51Thomas Graf
286f400923735ecbb67cbe4a3606c9479f694754f51Thomas Grafmodule_init(init_cgroup_cls);
287f400923735ecbb67cbe4a3606c9479f694754f51Thomas Grafmodule_exit(exit_cgroup_cls);
288f400923735ecbb67cbe4a3606c9479f694754f51Thomas GrafMODULE_LICENSE("GPL");
289