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