19 #include <netlink-private/netlink.h> 20 #include <netlink-private/tc.h> 21 #include <netlink/netlink.h> 22 #include <netlink/attr.h> 23 #include <netlink/utils.h> 24 #include <netlink-private/route/tc-api.h> 25 #include <netlink/route/classifier.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] = {
37 static int cgroup_clone(
void *_dst,
void *_src)
39 struct rtnl_cgroup *dst = NULL, *src = _src;
41 dst = calloc(1,
sizeof(*dst));
45 dst->cg_mask = src->cg_mask;
55 static void cgroup_free_data(
struct rtnl_tc *tc,
void *data)
57 struct rtnl_cgroup *c = data;
65 static int cgroup_msg_parser(
struct rtnl_tc *tc,
void *data)
67 struct nlattr *tb[TCA_CGROUP_MAX + 1];
68 struct rtnl_cgroup *c = data;
71 err = tca_parse(tb, TCA_CGROUP_MAX, tc, cgroup_policy);
75 if (tb[TCA_CGROUP_EMATCHES]) {
79 c->cg_mask |= CGROUP_ATTR_EMATCH;
91 static void cgroup_dump_line(
struct rtnl_tc *tc,
void *data,
94 struct rtnl_cgroup *c = data;
99 if (c->cg_mask & CGROUP_ATTR_EMATCH)
105 static void cgroup_dump_details(
struct rtnl_tc *tc,
void *data,
108 struct rtnl_cgroup *c = data;
113 if (c->cg_mask & CGROUP_ATTR_EMATCH) {
114 nl_dump_line(p,
" ematch ");
117 rtnl_ematch_tree_dump(c->cg_ematch, p);
124 static int cgroup_fill_msg(
struct rtnl_tc *tc,
void *data,
127 struct rtnl_cgroup *c = data;
132 if (!(tc->ce_mask & TCA_ATTR_HANDLE))
133 return -NLE_MISSING_ATTR;
135 if (c->cg_mask & CGROUP_ATTR_EMATCH)
136 return rtnl_ematch_fill_attr(msg, TCA_CGROUP_EMATCHES,
148 void rtnl_cgroup_set_ematch(
struct rtnl_cls *cls,
struct rtnl_ematch_tree *tree)
150 struct rtnl_cgroup *c;
157 c->cg_mask &= ~CGROUP_ATTR_EMATCH;
163 c->cg_mask |= CGROUP_ATTR_EMATCH;
166 struct rtnl_ematch_tree *rtnl_cgroup_get_ematch(
struct rtnl_cls *cls)
168 struct rtnl_cgroup *c;
178 static struct rtnl_tc_ops cgroup_ops = {
180 .to_type = RTNL_TC_TYPE_CLS,
181 .to_size =
sizeof(
struct rtnl_cgroup),
182 .to_clone = cgroup_clone,
183 .to_msg_parser = cgroup_msg_parser,
184 .to_free_data = cgroup_free_data,
185 .to_msg_fill = cgroup_fill_msg,
192 static void __init cgroup_init(
void)
197 static void __exit cgroup_exit(
void)
Dump object briefly on one line.
int rtnl_tc_register(struct rtnl_tc_ops *ops)
Register a traffic control module.
Attribute validation policy.
struct rtnl_ematch_tree * rtnl_ematch_tree_clone(struct rtnl_ematch_tree *src)
Clone ematch tree object.
void rtnl_ematch_tree_free(struct rtnl_ematch_tree *tree)
Free ematch tree object.
Dump all attributes but no statistics.
void rtnl_tc_unregister(struct rtnl_tc_ops *ops)
Unregister a traffic control module.
int rtnl_ematch_parse_attr(struct nlattr *attr, struct rtnl_ematch_tree **result)
Parse ematch netlink attributes.
#define TC_CAST(ptr)
Macro to cast qdisc/class/classifier to tc object.
void * rtnl_tc_data(struct rtnl_tc *tc)
Return pointer to private data of traffic control object.
uint16_t type
Type of attribute or NLA_UNSPEC.
void nl_dump(struct nl_dump_params *params, const char *fmt,...)
Dump a formatted character string.