2 * lib/route/cls/cgroup.c Control Groups Classifier
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation version 2.1
9 * Copyright (c) 2009 Thomas Graf <tgraf@suug.ch>
14 * @defgroup cgroup Control Groups Classifier
19 #include <netlink-local.h>
20 #include <netlink-tc.h>
21 #include <netlink/netlink.h>
22 #include <netlink/attr.h>
23 #include <netlink/utils.h>
24 #include <netlink/route/classifier.h>
25 #include <netlink/route/classifier-modules.h>
26 #include <netlink/route/cls/cgroup.h>
27 #include <netlink/route/cls/ematch.h>
30 #define CGROUP_ATTR_EMATCH 0x001
33 static struct nla_policy cgroup_policy[TCA_CGROUP_MAX+1] = {
34 [TCA_CGROUP_EMATCHES] = { .type = NLA_NESTED },
37 static void cgroup_free_data(struct rtnl_cls *cls)
39 struct rtnl_cgroup *cg = rtnl_cls_data(cls);
41 rtnl_ematch_tree_free(cg->cg_ematch);
44 static int cgroup_msg_parser(struct rtnl_cls *cls)
46 struct rtnl_cgroup *cg = rtnl_cls_data(cls);
47 struct nlattr *tb[TCA_CGROUP_MAX + 1];
50 err = tca_parse(tb, TCA_CGROUP_MAX, (struct rtnl_tca *) cls,
55 if (tb[TCA_CGROUP_EMATCHES]) {
56 if ((err = rtnl_ematch_parse(tb[TCA_CGROUP_EMATCHES],
59 cg->cg_mask |= CGROUP_ATTR_EMATCH;
71 static void cgroup_dump_line(struct rtnl_cls *cls, struct nl_dump_params *p)
73 struct rtnl_cgroup *cg = rtnl_cls_data(cls);
75 if (cg->cg_mask & CGROUP_ATTR_EMATCH)
76 nl_dump(p, " ematch");
78 nl_dump(p, " match-all");
81 static void cgroup_dump_details(struct rtnl_cls *cls, struct nl_dump_params *p)
83 struct rtnl_cgroup *cg = rtnl_cls_data(cls);
85 if (cg->cg_mask & CGROUP_ATTR_EMATCH) {
87 nl_dump_line(p, " ematch ");
88 rtnl_ematch_tree_dump(cg->cg_ematch, p);
93 * @name Attribute Modifications
97 int rtnl_cgroup_set_ematch(struct rtnl_cls *cls, struct rtnl_ematch_tree *tree)
99 struct rtnl_cgroup *cg = rtnl_cls_data(cls);
102 rtnl_ematch_tree_free(cg->cg_ematch);
103 cg->cg_mask &= ~CGROUP_ATTR_EMATCH;
106 cg->cg_ematch = tree;
109 cg->cg_mask |= CGROUP_ATTR_EMATCH;
114 struct rtnl_ematch_tree *rtnl_cgroup_get_ematch(struct rtnl_cls *cls)
116 struct rtnl_cgroup *cg = rtnl_cls_data(cls);
117 return cg->cg_ematch;
120 static struct rtnl_cls_ops cgroup_ops = {
122 .co_size = sizeof(struct rtnl_cgroup),
123 .co_msg_parser = cgroup_msg_parser,
124 .co_free_data = cgroup_free_data,
126 [NL_DUMP_LINE] = cgroup_dump_line,
127 [NL_DUMP_DETAILS] = cgroup_dump_details,
131 static void __init cgroup_init(void)
133 rtnl_cls_register(&cgroup_ops);
136 static void __exit cgroup_exit(void)
138 rtnl_cls_unregister(&cgroup_ops);