cls_cgroup.c revision 5a0e3ad6af8660be21ca98a971cd00f331318c05
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> 135a0e3ad6af8660be21ca98a971cd00f331318c05Tejun Heo#include <linux/slab.h> 14f400923735ecbb67cbe4a3606c9479f694754f51Thomas Graf#include <linux/types.h> 15f400923735ecbb67cbe4a3606c9479f694754f51Thomas Graf#include <linux/string.h> 16f400923735ecbb67cbe4a3606c9479f694754f51Thomas Graf#include <linux/errno.h> 17f400923735ecbb67cbe4a3606c9479f694754f51Thomas Graf#include <linux/skbuff.h> 18f400923735ecbb67cbe4a3606c9479f694754f51Thomas Graf#include <linux/cgroup.h> 19f400923735ecbb67cbe4a3606c9479f694754f51Thomas Graf#include <net/rtnetlink.h> 20f400923735ecbb67cbe4a3606c9479f694754f51Thomas Graf#include <net/pkt_cls.h> 21f400923735ecbb67cbe4a3606c9479f694754f51Thomas Graf 22f400923735ecbb67cbe4a3606c9479f694754f51Thomas Grafstruct cgroup_cls_state 23f400923735ecbb67cbe4a3606c9479f694754f51Thomas Graf{ 24f400923735ecbb67cbe4a3606c9479f694754f51Thomas Graf struct cgroup_subsys_state css; 25f400923735ecbb67cbe4a3606c9479f694754f51Thomas Graf u32 classid; 26f400923735ecbb67cbe4a3606c9479f694754f51Thomas Graf}; 27f400923735ecbb67cbe4a3606c9479f694754f51Thomas Graf 288e039d84b323c4503c4d56863faa47c783660826Ben Blumstatic struct cgroup_subsys_state *cgrp_create(struct cgroup_subsys *ss, 298e039d84b323c4503c4d56863faa47c783660826Ben Blum struct cgroup *cgrp); 308e039d84b323c4503c4d56863faa47c783660826Ben Blumstatic void cgrp_destroy(struct cgroup_subsys *ss, struct cgroup *cgrp); 318e039d84b323c4503c4d56863faa47c783660826Ben Blumstatic int cgrp_populate(struct cgroup_subsys *ss, struct cgroup *cgrp); 328e039d84b323c4503c4d56863faa47c783660826Ben Blum 338e039d84b323c4503c4d56863faa47c783660826Ben Blumstruct cgroup_subsys net_cls_subsys = { 348e039d84b323c4503c4d56863faa47c783660826Ben Blum .name = "net_cls", 358e039d84b323c4503c4d56863faa47c783660826Ben Blum .create = cgrp_create, 368e039d84b323c4503c4d56863faa47c783660826Ben Blum .destroy = cgrp_destroy, 378e039d84b323c4503c4d56863faa47c783660826Ben Blum .populate = cgrp_populate, 388e039d84b323c4503c4d56863faa47c783660826Ben Blum#ifdef CONFIG_NET_CLS_CGROUP 398e039d84b323c4503c4d56863faa47c783660826Ben Blum .subsys_id = net_cls_subsys_id, 408e039d84b323c4503c4d56863faa47c783660826Ben Blum#else 418e039d84b323c4503c4d56863faa47c783660826Ben Blum#define net_cls_subsys_id net_cls_subsys.subsys_id 428e039d84b323c4503c4d56863faa47c783660826Ben Blum#endif 438e039d84b323c4503c4d56863faa47c783660826Ben Blum .module = THIS_MODULE, 448e039d84b323c4503c4d56863faa47c783660826Ben Blum}; 458e039d84b323c4503c4d56863faa47c783660826Ben Blum 468e039d84b323c4503c4d56863faa47c783660826Ben Blum 478e8ba85417366afd2361e315c6ba5949d3eff56fLi Zefanstatic inline struct cgroup_cls_state *cgrp_cls_state(struct cgroup *cgrp) 48f400923735ecbb67cbe4a3606c9479f694754f51Thomas Graf{ 498e8ba85417366afd2361e315c6ba5949d3eff56fLi Zefan return container_of(cgroup_subsys_state(cgrp, net_cls_subsys_id), 508e8ba85417366afd2361e315c6ba5949d3eff56fLi Zefan struct cgroup_cls_state, css); 518e8ba85417366afd2361e315c6ba5949d3eff56fLi Zefan} 528e8ba85417366afd2361e315c6ba5949d3eff56fLi Zefan 538e8ba85417366afd2361e315c6ba5949d3eff56fLi Zefanstatic inline struct cgroup_cls_state *task_cls_state(struct task_struct *p) 548e8ba85417366afd2361e315c6ba5949d3eff56fLi Zefan{ 558e8ba85417366afd2361e315c6ba5949d3eff56fLi Zefan return container_of(task_subsys_state(p, net_cls_subsys_id), 568e8ba85417366afd2361e315c6ba5949d3eff56fLi Zefan struct cgroup_cls_state, css); 57f400923735ecbb67cbe4a3606c9479f694754f51Thomas Graf} 58f400923735ecbb67cbe4a3606c9479f694754f51Thomas Graf 59f400923735ecbb67cbe4a3606c9479f694754f51Thomas Grafstatic struct cgroup_subsys_state *cgrp_create(struct cgroup_subsys *ss, 60f400923735ecbb67cbe4a3606c9479f694754f51Thomas Graf struct cgroup *cgrp) 61f400923735ecbb67cbe4a3606c9479f694754f51Thomas Graf{ 62f400923735ecbb67cbe4a3606c9479f694754f51Thomas Graf struct cgroup_cls_state *cs; 63f400923735ecbb67cbe4a3606c9479f694754f51Thomas Graf 64f400923735ecbb67cbe4a3606c9479f694754f51Thomas Graf if (!(cs = kzalloc(sizeof(*cs), GFP_KERNEL))) 65f400923735ecbb67cbe4a3606c9479f694754f51Thomas Graf return ERR_PTR(-ENOMEM); 66f400923735ecbb67cbe4a3606c9479f694754f51Thomas Graf 67f400923735ecbb67cbe4a3606c9479f694754f51Thomas Graf if (cgrp->parent) 688e8ba85417366afd2361e315c6ba5949d3eff56fLi Zefan cs->classid = cgrp_cls_state(cgrp->parent)->classid; 69f400923735ecbb67cbe4a3606c9479f694754f51Thomas Graf 70f400923735ecbb67cbe4a3606c9479f694754f51Thomas Graf return &cs->css; 71f400923735ecbb67cbe4a3606c9479f694754f51Thomas Graf} 72f400923735ecbb67cbe4a3606c9479f694754f51Thomas Graf 73f400923735ecbb67cbe4a3606c9479f694754f51Thomas Grafstatic void cgrp_destroy(struct cgroup_subsys *ss, struct cgroup *cgrp) 74f400923735ecbb67cbe4a3606c9479f694754f51Thomas Graf{ 758e8ba85417366afd2361e315c6ba5949d3eff56fLi Zefan kfree(cgrp_cls_state(cgrp)); 76f400923735ecbb67cbe4a3606c9479f694754f51Thomas Graf} 77f400923735ecbb67cbe4a3606c9479f694754f51Thomas Graf 78f400923735ecbb67cbe4a3606c9479f694754f51Thomas Grafstatic u64 read_classid(struct cgroup *cgrp, struct cftype *cft) 79f400923735ecbb67cbe4a3606c9479f694754f51Thomas Graf{ 808e8ba85417366afd2361e315c6ba5949d3eff56fLi Zefan return cgrp_cls_state(cgrp)->classid; 81f400923735ecbb67cbe4a3606c9479f694754f51Thomas Graf} 82f400923735ecbb67cbe4a3606c9479f694754f51Thomas Graf 83f400923735ecbb67cbe4a3606c9479f694754f51Thomas Grafstatic int write_classid(struct cgroup *cgrp, struct cftype *cft, u64 value) 84f400923735ecbb67cbe4a3606c9479f694754f51Thomas Graf{ 858e8ba85417366afd2361e315c6ba5949d3eff56fLi Zefan cgrp_cls_state(cgrp)->classid = (u32) value; 86f400923735ecbb67cbe4a3606c9479f694754f51Thomas Graf return 0; 87f400923735ecbb67cbe4a3606c9479f694754f51Thomas Graf} 88f400923735ecbb67cbe4a3606c9479f694754f51Thomas Graf 89f400923735ecbb67cbe4a3606c9479f694754f51Thomas Grafstatic struct cftype ss_files[] = { 90f400923735ecbb67cbe4a3606c9479f694754f51Thomas Graf { 91f400923735ecbb67cbe4a3606c9479f694754f51Thomas Graf .name = "classid", 92f400923735ecbb67cbe4a3606c9479f694754f51Thomas Graf .read_u64 = read_classid, 93f400923735ecbb67cbe4a3606c9479f694754f51Thomas Graf .write_u64 = write_classid, 94f400923735ecbb67cbe4a3606c9479f694754f51Thomas Graf }, 95f400923735ecbb67cbe4a3606c9479f694754f51Thomas Graf}; 96f400923735ecbb67cbe4a3606c9479f694754f51Thomas Graf 97f400923735ecbb67cbe4a3606c9479f694754f51Thomas Grafstatic int cgrp_populate(struct cgroup_subsys *ss, struct cgroup *cgrp) 98f400923735ecbb67cbe4a3606c9479f694754f51Thomas Graf{ 99f400923735ecbb67cbe4a3606c9479f694754f51Thomas Graf return cgroup_add_files(cgrp, ss, ss_files, ARRAY_SIZE(ss_files)); 100f400923735ecbb67cbe4a3606c9479f694754f51Thomas Graf} 101f400923735ecbb67cbe4a3606c9479f694754f51Thomas Graf 102f400923735ecbb67cbe4a3606c9479f694754f51Thomas Grafstruct cls_cgroup_head 103f400923735ecbb67cbe4a3606c9479f694754f51Thomas Graf{ 104f400923735ecbb67cbe4a3606c9479f694754f51Thomas Graf u32 handle; 105f400923735ecbb67cbe4a3606c9479f694754f51Thomas Graf struct tcf_exts exts; 106f400923735ecbb67cbe4a3606c9479f694754f51Thomas Graf struct tcf_ematch_tree ematches; 107f400923735ecbb67cbe4a3606c9479f694754f51Thomas Graf}; 108f400923735ecbb67cbe4a3606c9479f694754f51Thomas Graf 109f400923735ecbb67cbe4a3606c9479f694754f51Thomas Grafstatic int cls_cgroup_classify(struct sk_buff *skb, struct tcf_proto *tp, 110f400923735ecbb67cbe4a3606c9479f694754f51Thomas Graf struct tcf_result *res) 111f400923735ecbb67cbe4a3606c9479f694754f51Thomas Graf{ 112f400923735ecbb67cbe4a3606c9479f694754f51Thomas Graf struct cls_cgroup_head *head = tp->root; 113e65fcfd63a9a62baa5708484ff8edbe56eb3e7ecPaul Menage u32 classid; 114f400923735ecbb67cbe4a3606c9479f694754f51Thomas Graf 115f400923735ecbb67cbe4a3606c9479f694754f51Thomas Graf /* 116f400923735ecbb67cbe4a3606c9479f694754f51Thomas Graf * Due to the nature of the classifier it is required to ignore all 117f400923735ecbb67cbe4a3606c9479f694754f51Thomas Graf * packets originating from softirq context as accessing `current' 118f400923735ecbb67cbe4a3606c9479f694754f51Thomas Graf * would lead to false results. 119f400923735ecbb67cbe4a3606c9479f694754f51Thomas Graf * 120f400923735ecbb67cbe4a3606c9479f694754f51Thomas Graf * This test assumes that all callers of dev_queue_xmit() explicitely 121f400923735ecbb67cbe4a3606c9479f694754f51Thomas Graf * disable bh. Knowing this, it is possible to detect softirq based 122f400923735ecbb67cbe4a3606c9479f694754f51Thomas Graf * calls by looking at the number of nested bh disable calls because 123f400923735ecbb67cbe4a3606c9479f694754f51Thomas Graf * softirqs always disables bh. 124f400923735ecbb67cbe4a3606c9479f694754f51Thomas Graf */ 125f400923735ecbb67cbe4a3606c9479f694754f51Thomas Graf if (softirq_count() != SOFTIRQ_OFFSET) 126f400923735ecbb67cbe4a3606c9479f694754f51Thomas Graf return -1; 127f400923735ecbb67cbe4a3606c9479f694754f51Thomas Graf 128f400923735ecbb67cbe4a3606c9479f694754f51Thomas Graf rcu_read_lock(); 129e65fcfd63a9a62baa5708484ff8edbe56eb3e7ecPaul Menage classid = task_cls_state(current)->classid; 130f400923735ecbb67cbe4a3606c9479f694754f51Thomas Graf rcu_read_unlock(); 131f400923735ecbb67cbe4a3606c9479f694754f51Thomas Graf 132e65fcfd63a9a62baa5708484ff8edbe56eb3e7ecPaul Menage if (!classid) 133e65fcfd63a9a62baa5708484ff8edbe56eb3e7ecPaul Menage return -1; 134e65fcfd63a9a62baa5708484ff8edbe56eb3e7ecPaul Menage 135e65fcfd63a9a62baa5708484ff8edbe56eb3e7ecPaul Menage if (!tcf_em_tree_match(skb, &head->ematches, NULL)) 136e65fcfd63a9a62baa5708484ff8edbe56eb3e7ecPaul Menage return -1; 137e65fcfd63a9a62baa5708484ff8edbe56eb3e7ecPaul Menage 138e65fcfd63a9a62baa5708484ff8edbe56eb3e7ecPaul Menage res->classid = classid; 139e65fcfd63a9a62baa5708484ff8edbe56eb3e7ecPaul Menage res->class = 0; 140e65fcfd63a9a62baa5708484ff8edbe56eb3e7ecPaul Menage return tcf_exts_exec(skb, &head->exts, res); 141f400923735ecbb67cbe4a3606c9479f694754f51Thomas Graf} 142f400923735ecbb67cbe4a3606c9479f694754f51Thomas Graf 143f400923735ecbb67cbe4a3606c9479f694754f51Thomas Grafstatic unsigned long cls_cgroup_get(struct tcf_proto *tp, u32 handle) 144f400923735ecbb67cbe4a3606c9479f694754f51Thomas Graf{ 145f400923735ecbb67cbe4a3606c9479f694754f51Thomas Graf return 0UL; 146f400923735ecbb67cbe4a3606c9479f694754f51Thomas Graf} 147f400923735ecbb67cbe4a3606c9479f694754f51Thomas Graf 148f400923735ecbb67cbe4a3606c9479f694754f51Thomas Grafstatic void cls_cgroup_put(struct tcf_proto *tp, unsigned long f) 149f400923735ecbb67cbe4a3606c9479f694754f51Thomas Graf{ 150f400923735ecbb67cbe4a3606c9479f694754f51Thomas Graf} 151f400923735ecbb67cbe4a3606c9479f694754f51Thomas Graf 152f400923735ecbb67cbe4a3606c9479f694754f51Thomas Grafstatic int cls_cgroup_init(struct tcf_proto *tp) 153f400923735ecbb67cbe4a3606c9479f694754f51Thomas Graf{ 154f400923735ecbb67cbe4a3606c9479f694754f51Thomas Graf return 0; 155f400923735ecbb67cbe4a3606c9479f694754f51Thomas Graf} 156f400923735ecbb67cbe4a3606c9479f694754f51Thomas Graf 157f400923735ecbb67cbe4a3606c9479f694754f51Thomas Grafstatic const struct tcf_ext_map cgroup_ext_map = { 158f400923735ecbb67cbe4a3606c9479f694754f51Thomas Graf .action = TCA_CGROUP_ACT, 159f400923735ecbb67cbe4a3606c9479f694754f51Thomas Graf .police = TCA_CGROUP_POLICE, 160f400923735ecbb67cbe4a3606c9479f694754f51Thomas Graf}; 161f400923735ecbb67cbe4a3606c9479f694754f51Thomas Graf 162f400923735ecbb67cbe4a3606c9479f694754f51Thomas Grafstatic const struct nla_policy cgroup_policy[TCA_CGROUP_MAX + 1] = { 163f400923735ecbb67cbe4a3606c9479f694754f51Thomas Graf [TCA_CGROUP_EMATCHES] = { .type = NLA_NESTED }, 164f400923735ecbb67cbe4a3606c9479f694754f51Thomas Graf}; 165f400923735ecbb67cbe4a3606c9479f694754f51Thomas Graf 166f400923735ecbb67cbe4a3606c9479f694754f51Thomas Grafstatic int cls_cgroup_change(struct tcf_proto *tp, unsigned long base, 167f400923735ecbb67cbe4a3606c9479f694754f51Thomas Graf u32 handle, struct nlattr **tca, 168f400923735ecbb67cbe4a3606c9479f694754f51Thomas Graf unsigned long *arg) 169f400923735ecbb67cbe4a3606c9479f694754f51Thomas Graf{ 170f400923735ecbb67cbe4a3606c9479f694754f51Thomas Graf struct nlattr *tb[TCA_CGROUP_MAX+1]; 171f400923735ecbb67cbe4a3606c9479f694754f51Thomas Graf struct cls_cgroup_head *head = tp->root; 172f400923735ecbb67cbe4a3606c9479f694754f51Thomas Graf struct tcf_ematch_tree t; 173f400923735ecbb67cbe4a3606c9479f694754f51Thomas Graf struct tcf_exts e; 174f400923735ecbb67cbe4a3606c9479f694754f51Thomas Graf int err; 175f400923735ecbb67cbe4a3606c9479f694754f51Thomas Graf 17652ea3a56a3268bc2a5a7c75e98c81463004e38efMinoru Usui if (!tca[TCA_OPTIONS]) 17752ea3a56a3268bc2a5a7c75e98c81463004e38efMinoru Usui return -EINVAL; 17852ea3a56a3268bc2a5a7c75e98c81463004e38efMinoru Usui 179f400923735ecbb67cbe4a3606c9479f694754f51Thomas Graf if (head == NULL) { 180f400923735ecbb67cbe4a3606c9479f694754f51Thomas Graf if (!handle) 181f400923735ecbb67cbe4a3606c9479f694754f51Thomas Graf return -EINVAL; 182f400923735ecbb67cbe4a3606c9479f694754f51Thomas Graf 183f400923735ecbb67cbe4a3606c9479f694754f51Thomas Graf head = kzalloc(sizeof(*head), GFP_KERNEL); 184f400923735ecbb67cbe4a3606c9479f694754f51Thomas Graf if (head == NULL) 185f400923735ecbb67cbe4a3606c9479f694754f51Thomas Graf return -ENOBUFS; 186f400923735ecbb67cbe4a3606c9479f694754f51Thomas Graf 187f400923735ecbb67cbe4a3606c9479f694754f51Thomas Graf head->handle = handle; 188f400923735ecbb67cbe4a3606c9479f694754f51Thomas Graf 189f400923735ecbb67cbe4a3606c9479f694754f51Thomas Graf tcf_tree_lock(tp); 190f400923735ecbb67cbe4a3606c9479f694754f51Thomas Graf tp->root = head; 191f400923735ecbb67cbe4a3606c9479f694754f51Thomas Graf tcf_tree_unlock(tp); 192f400923735ecbb67cbe4a3606c9479f694754f51Thomas Graf } 193f400923735ecbb67cbe4a3606c9479f694754f51Thomas Graf 194f400923735ecbb67cbe4a3606c9479f694754f51Thomas Graf if (handle != head->handle) 195f400923735ecbb67cbe4a3606c9479f694754f51Thomas Graf return -ENOENT; 196f400923735ecbb67cbe4a3606c9479f694754f51Thomas Graf 197f400923735ecbb67cbe4a3606c9479f694754f51Thomas Graf err = nla_parse_nested(tb, TCA_CGROUP_MAX, tca[TCA_OPTIONS], 198f400923735ecbb67cbe4a3606c9479f694754f51Thomas Graf cgroup_policy); 199f400923735ecbb67cbe4a3606c9479f694754f51Thomas Graf if (err < 0) 200f400923735ecbb67cbe4a3606c9479f694754f51Thomas Graf return err; 201f400923735ecbb67cbe4a3606c9479f694754f51Thomas Graf 202f400923735ecbb67cbe4a3606c9479f694754f51Thomas Graf err = tcf_exts_validate(tp, tb, tca[TCA_RATE], &e, &cgroup_ext_map); 203f400923735ecbb67cbe4a3606c9479f694754f51Thomas Graf if (err < 0) 204f400923735ecbb67cbe4a3606c9479f694754f51Thomas Graf return err; 205f400923735ecbb67cbe4a3606c9479f694754f51Thomas Graf 206f400923735ecbb67cbe4a3606c9479f694754f51Thomas Graf err = tcf_em_tree_validate(tp, tb[TCA_CGROUP_EMATCHES], &t); 207f400923735ecbb67cbe4a3606c9479f694754f51Thomas Graf if (err < 0) 208f400923735ecbb67cbe4a3606c9479f694754f51Thomas Graf return err; 209f400923735ecbb67cbe4a3606c9479f694754f51Thomas Graf 210f400923735ecbb67cbe4a3606c9479f694754f51Thomas Graf tcf_exts_change(tp, &head->exts, &e); 211f400923735ecbb67cbe4a3606c9479f694754f51Thomas Graf tcf_em_tree_change(tp, &head->ematches, &t); 212f400923735ecbb67cbe4a3606c9479f694754f51Thomas Graf 213f400923735ecbb67cbe4a3606c9479f694754f51Thomas Graf return 0; 214f400923735ecbb67cbe4a3606c9479f694754f51Thomas Graf} 215f400923735ecbb67cbe4a3606c9479f694754f51Thomas Graf 216f400923735ecbb67cbe4a3606c9479f694754f51Thomas Grafstatic void cls_cgroup_destroy(struct tcf_proto *tp) 217f400923735ecbb67cbe4a3606c9479f694754f51Thomas Graf{ 21847a1a1d4be2910b13a8e90f75c17e253c39531ffPatrick McHardy struct cls_cgroup_head *head = tp->root; 219f400923735ecbb67cbe4a3606c9479f694754f51Thomas Graf 220f400923735ecbb67cbe4a3606c9479f694754f51Thomas Graf if (head) { 221f400923735ecbb67cbe4a3606c9479f694754f51Thomas Graf tcf_exts_destroy(tp, &head->exts); 222f400923735ecbb67cbe4a3606c9479f694754f51Thomas Graf tcf_em_tree_destroy(tp, &head->ematches); 223f400923735ecbb67cbe4a3606c9479f694754f51Thomas Graf kfree(head); 224f400923735ecbb67cbe4a3606c9479f694754f51Thomas Graf } 225f400923735ecbb67cbe4a3606c9479f694754f51Thomas Graf} 226f400923735ecbb67cbe4a3606c9479f694754f51Thomas Graf 227f400923735ecbb67cbe4a3606c9479f694754f51Thomas Grafstatic int cls_cgroup_delete(struct tcf_proto *tp, unsigned long arg) 228f400923735ecbb67cbe4a3606c9479f694754f51Thomas Graf{ 229f400923735ecbb67cbe4a3606c9479f694754f51Thomas Graf return -EOPNOTSUPP; 230f400923735ecbb67cbe4a3606c9479f694754f51Thomas Graf} 231f400923735ecbb67cbe4a3606c9479f694754f51Thomas Graf 232f400923735ecbb67cbe4a3606c9479f694754f51Thomas Grafstatic void cls_cgroup_walk(struct tcf_proto *tp, struct tcf_walker *arg) 233f400923735ecbb67cbe4a3606c9479f694754f51Thomas Graf{ 234f400923735ecbb67cbe4a3606c9479f694754f51Thomas Graf struct cls_cgroup_head *head = tp->root; 235f400923735ecbb67cbe4a3606c9479f694754f51Thomas Graf 236f400923735ecbb67cbe4a3606c9479f694754f51Thomas Graf if (arg->count < arg->skip) 237f400923735ecbb67cbe4a3606c9479f694754f51Thomas Graf goto skip; 238f400923735ecbb67cbe4a3606c9479f694754f51Thomas Graf 239f400923735ecbb67cbe4a3606c9479f694754f51Thomas Graf if (arg->fn(tp, (unsigned long) head, arg) < 0) { 240f400923735ecbb67cbe4a3606c9479f694754f51Thomas Graf arg->stop = 1; 241f400923735ecbb67cbe4a3606c9479f694754f51Thomas Graf return; 242f400923735ecbb67cbe4a3606c9479f694754f51Thomas Graf } 243f400923735ecbb67cbe4a3606c9479f694754f51Thomas Grafskip: 244f400923735ecbb67cbe4a3606c9479f694754f51Thomas Graf arg->count++; 245f400923735ecbb67cbe4a3606c9479f694754f51Thomas Graf} 246f400923735ecbb67cbe4a3606c9479f694754f51Thomas Graf 247f400923735ecbb67cbe4a3606c9479f694754f51Thomas Grafstatic int cls_cgroup_dump(struct tcf_proto *tp, unsigned long fh, 248f400923735ecbb67cbe4a3606c9479f694754f51Thomas Graf struct sk_buff *skb, struct tcmsg *t) 249f400923735ecbb67cbe4a3606c9479f694754f51Thomas Graf{ 250f400923735ecbb67cbe4a3606c9479f694754f51Thomas Graf struct cls_cgroup_head *head = tp->root; 251f400923735ecbb67cbe4a3606c9479f694754f51Thomas Graf unsigned char *b = skb_tail_pointer(skb); 252f400923735ecbb67cbe4a3606c9479f694754f51Thomas Graf struct nlattr *nest; 253f400923735ecbb67cbe4a3606c9479f694754f51Thomas Graf 254f400923735ecbb67cbe4a3606c9479f694754f51Thomas Graf t->tcm_handle = head->handle; 255f400923735ecbb67cbe4a3606c9479f694754f51Thomas Graf 256f400923735ecbb67cbe4a3606c9479f694754f51Thomas Graf nest = nla_nest_start(skb, TCA_OPTIONS); 257f400923735ecbb67cbe4a3606c9479f694754f51Thomas Graf if (nest == NULL) 258f400923735ecbb67cbe4a3606c9479f694754f51Thomas Graf goto nla_put_failure; 259f400923735ecbb67cbe4a3606c9479f694754f51Thomas Graf 260f400923735ecbb67cbe4a3606c9479f694754f51Thomas Graf if (tcf_exts_dump(skb, &head->exts, &cgroup_ext_map) < 0 || 261f400923735ecbb67cbe4a3606c9479f694754f51Thomas Graf tcf_em_tree_dump(skb, &head->ematches, TCA_CGROUP_EMATCHES) < 0) 262f400923735ecbb67cbe4a3606c9479f694754f51Thomas Graf goto nla_put_failure; 263f400923735ecbb67cbe4a3606c9479f694754f51Thomas Graf 264f400923735ecbb67cbe4a3606c9479f694754f51Thomas Graf nla_nest_end(skb, nest); 265f400923735ecbb67cbe4a3606c9479f694754f51Thomas Graf 266f400923735ecbb67cbe4a3606c9479f694754f51Thomas Graf if (tcf_exts_dump_stats(skb, &head->exts, &cgroup_ext_map) < 0) 267f400923735ecbb67cbe4a3606c9479f694754f51Thomas Graf goto nla_put_failure; 268f400923735ecbb67cbe4a3606c9479f694754f51Thomas Graf 269f400923735ecbb67cbe4a3606c9479f694754f51Thomas Graf return skb->len; 270f400923735ecbb67cbe4a3606c9479f694754f51Thomas Graf 271f400923735ecbb67cbe4a3606c9479f694754f51Thomas Grafnla_put_failure: 272f400923735ecbb67cbe4a3606c9479f694754f51Thomas Graf nlmsg_trim(skb, b); 273f400923735ecbb67cbe4a3606c9479f694754f51Thomas Graf return -1; 274f400923735ecbb67cbe4a3606c9479f694754f51Thomas Graf} 275f400923735ecbb67cbe4a3606c9479f694754f51Thomas Graf 276f400923735ecbb67cbe4a3606c9479f694754f51Thomas Grafstatic struct tcf_proto_ops cls_cgroup_ops __read_mostly = { 277f400923735ecbb67cbe4a3606c9479f694754f51Thomas Graf .kind = "cgroup", 278f400923735ecbb67cbe4a3606c9479f694754f51Thomas Graf .init = cls_cgroup_init, 279f400923735ecbb67cbe4a3606c9479f694754f51Thomas Graf .change = cls_cgroup_change, 280f400923735ecbb67cbe4a3606c9479f694754f51Thomas Graf .classify = cls_cgroup_classify, 281f400923735ecbb67cbe4a3606c9479f694754f51Thomas Graf .destroy = cls_cgroup_destroy, 282f400923735ecbb67cbe4a3606c9479f694754f51Thomas Graf .get = cls_cgroup_get, 283f400923735ecbb67cbe4a3606c9479f694754f51Thomas Graf .put = cls_cgroup_put, 284f400923735ecbb67cbe4a3606c9479f694754f51Thomas Graf .delete = cls_cgroup_delete, 285f400923735ecbb67cbe4a3606c9479f694754f51Thomas Graf .walk = cls_cgroup_walk, 286f400923735ecbb67cbe4a3606c9479f694754f51Thomas Graf .dump = cls_cgroup_dump, 287f400923735ecbb67cbe4a3606c9479f694754f51Thomas Graf .owner = THIS_MODULE, 288f400923735ecbb67cbe4a3606c9479f694754f51Thomas Graf}; 289f400923735ecbb67cbe4a3606c9479f694754f51Thomas Graf 290f400923735ecbb67cbe4a3606c9479f694754f51Thomas Grafstatic int __init init_cgroup_cls(void) 291f400923735ecbb67cbe4a3606c9479f694754f51Thomas Graf{ 2928e039d84b323c4503c4d56863faa47c783660826Ben Blum int ret = register_tcf_proto_ops(&cls_cgroup_ops); 2938e039d84b323c4503c4d56863faa47c783660826Ben Blum if (ret) 2948e039d84b323c4503c4d56863faa47c783660826Ben Blum return ret; 2958e039d84b323c4503c4d56863faa47c783660826Ben Blum ret = cgroup_load_subsys(&net_cls_subsys); 2968e039d84b323c4503c4d56863faa47c783660826Ben Blum if (ret) 2978e039d84b323c4503c4d56863faa47c783660826Ben Blum unregister_tcf_proto_ops(&cls_cgroup_ops); 2988e039d84b323c4503c4d56863faa47c783660826Ben Blum return ret; 299f400923735ecbb67cbe4a3606c9479f694754f51Thomas Graf} 300f400923735ecbb67cbe4a3606c9479f694754f51Thomas Graf 301f400923735ecbb67cbe4a3606c9479f694754f51Thomas Grafstatic void __exit exit_cgroup_cls(void) 302f400923735ecbb67cbe4a3606c9479f694754f51Thomas Graf{ 303f400923735ecbb67cbe4a3606c9479f694754f51Thomas Graf unregister_tcf_proto_ops(&cls_cgroup_ops); 3048e039d84b323c4503c4d56863faa47c783660826Ben Blum cgroup_unload_subsys(&net_cls_subsys); 305f400923735ecbb67cbe4a3606c9479f694754f51Thomas Graf} 306f400923735ecbb67cbe4a3606c9479f694754f51Thomas Graf 307f400923735ecbb67cbe4a3606c9479f694754f51Thomas Grafmodule_init(init_cgroup_cls); 308f400923735ecbb67cbe4a3606c9479f694754f51Thomas Grafmodule_exit(exit_cgroup_cls); 309f400923735ecbb67cbe4a3606c9479f694754f51Thomas GrafMODULE_LICENSE("GPL"); 310