25 #include <netlink-private/netlink.h> 26 #include <netlink-private/tc.h> 27 #include <netlink/netlink.h> 28 #include <netlink-private/route/tc-api.h> 29 #include <netlink/route/classifier.h> 30 #include <netlink/route/action.h> 31 #include <netlink/route/cls/basic.h> 32 #include <netlink/route/cls/ematch.h> 37 struct rtnl_ematch_tree * b_ematch;
39 struct rtnl_act * b_act;
43 #define BASIC_ATTR_TARGET 0x001 44 #define BASIC_ATTR_EMATCH 0x002 45 #define BASIC_ATTR_ACTION 0x004 48 static struct nla_policy basic_policy[TCA_BASIC_MAX+1] = {
53 static int basic_clone(
void *_dst,
void *_src)
55 return -NLE_OPNOTSUPP;
58 static void basic_free_data(
struct rtnl_tc *tc,
void *data)
66 rtnl_act_put_all(&b->b_act);
70 static int basic_msg_parser(
struct rtnl_tc *tc,
void *data)
72 struct nlattr *tb[TCA_BASIC_MAX + 1];
76 err = tca_parse(tb, TCA_BASIC_MAX, tc, basic_policy);
80 if (tb[TCA_BASIC_CLASSID]) {
82 b->b_mask |= BASIC_ATTR_TARGET;
85 if (tb[TCA_BASIC_EMATCHES]) {
91 b->b_mask |= BASIC_ATTR_EMATCH;
93 if (tb[TCA_BASIC_ACT]) {
94 b->b_mask |= BASIC_ATTR_ACTION;
95 err = rtnl_act_parse(&b->b_act, tb[TCA_BASIC_ACT]);
103 static void basic_dump_line(
struct rtnl_tc *tc,
void *data,
112 if (b->b_mask & BASIC_ATTR_EMATCH)
117 if (b->b_mask & BASIC_ATTR_TARGET)
122 static void basic_dump_details(
struct rtnl_tc *tc,
void *data,
130 if (b->b_mask & BASIC_ATTR_EMATCH) {
131 nl_dump_line(p,
" ematch ");
132 rtnl_ematch_tree_dump(b->b_ematch, p);
137 static int basic_msg_fill(
struct rtnl_tc *tc,
void *data,
145 if (b->b_mask & BASIC_ATTR_TARGET)
148 if (b->b_mask & BASIC_ATTR_EMATCH &&
149 rtnl_ematch_fill_attr(msg, TCA_BASIC_EMATCHES, b->b_ematch) < 0)
150 goto nla_put_failure;
152 if (b->b_mask & BASIC_ATTR_ACTION) {
155 err = rtnl_act_fill(msg, TCA_BASIC_ACT, b->b_act);
171 void rtnl_basic_set_target(
struct rtnl_cls *cls, uint32_t target)
178 b->b_target = target;
179 b->b_mask |= BASIC_ATTR_TARGET;
182 uint32_t rtnl_basic_get_target(
struct rtnl_cls *cls)
192 void rtnl_basic_set_ematch(
struct rtnl_cls *cls,
struct rtnl_ematch_tree *tree)
201 b->b_mask &= ~BASIC_ATTR_EMATCH;
207 b->b_mask |= BASIC_ATTR_EMATCH;
210 struct rtnl_ematch_tree *rtnl_basic_get_ematch(
struct rtnl_cls *cls)
220 int rtnl_basic_add_action(
struct rtnl_cls *cls,
struct rtnl_act *act)
231 b->b_mask |= BASIC_ATTR_ACTION;
232 if ((err = rtnl_act_append(&b->b_act, act)))
240 struct rtnl_act* rtnl_basic_get_action(
struct rtnl_cls *cls)
247 if (!(b->b_mask & BASIC_ATTR_ACTION))
253 int rtnl_basic_del_action(
struct rtnl_cls *cls,
struct rtnl_act *act)
264 if (!(b->b_mask & BASIC_ATTR_ACTION))
266 ret = rtnl_act_remove(&b->b_act, act);
271 b->b_mask &= ~BASIC_ATTR_ACTION;
277 static struct rtnl_tc_ops basic_ops = {
279 .to_type = RTNL_TC_TYPE_CLS,
281 .to_msg_parser = basic_msg_parser,
282 .to_clone = basic_clone,
283 .to_free_data = basic_free_data,
284 .to_msg_fill = basic_msg_fill,
291 static void __init basic_init(
void)
296 static void __exit basic_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.
uint32_t nla_get_u32(const struct nlattr *nla)
Return payload of 32 bit integer attribute.
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.
#define NLA_PUT_U32(msg, attrtype, value)
Add 32 bit integer attribute to netlink message.
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.
char * rtnl_tc_handle2str(uint32_t handle, char *buf, size_t len)
Convert a traffic control handle to a character string (Reentrant).
void nl_dump(struct nl_dump_params *params, const char *fmt,...)
Dump a formatted character string.
void * rtnl_tc_data_peek(struct rtnl_tc *tc)
Returns the private data of the traffic control object.