19#include "nl-default.h"
21#include <netlink/netlink.h>
22#include <netlink/route/classifier.h>
23#include <netlink/route/action.h>
24#include <netlink/route/cls/basic.h>
25#include <netlink/route/cls/ematch.h>
32 struct rtnl_ematch_tree * b_ematch;
38#define BASIC_ATTR_TARGET 0x001
39#define BASIC_ATTR_EMATCH 0x002
40#define BASIC_ATTR_ACTION 0x004
43static struct nla_policy basic_policy[TCA_BASIC_MAX+1] = {
48static int basic_clone(
void *_dst,
void *_src)
50 return -NLE_OPNOTSUPP;
53static void basic_free_data(
struct rtnl_tc *tc,
void *data)
61 rtnl_act_put_all(&b->b_act);
65static int basic_msg_parser(
struct rtnl_tc *tc,
void *data)
67 struct nlattr *tb[TCA_BASIC_MAX + 1];
71 err = tca_parse(tb, TCA_BASIC_MAX, tc, basic_policy);
75 if (tb[TCA_BASIC_CLASSID]) {
77 b->b_mask |= BASIC_ATTR_TARGET;
80 if (tb[TCA_BASIC_EMATCHES]) {
86 b->b_mask |= BASIC_ATTR_EMATCH;
88 if (tb[TCA_BASIC_ACT]) {
89 b->b_mask |= BASIC_ATTR_ACTION;
90 err = rtnl_act_parse(&b->b_act, tb[TCA_BASIC_ACT]);
98static void basic_dump_line(
struct rtnl_tc *tc,
void *data,
107 if (b->b_mask & BASIC_ATTR_EMATCH)
112 if (b->b_mask & BASIC_ATTR_TARGET)
117static void basic_dump_details(
struct rtnl_tc *tc,
void *data,
125 if (b->b_mask & BASIC_ATTR_EMATCH) {
126 nl_dump_line(p,
" ematch ");
127 rtnl_ematch_tree_dump(b->b_ematch, p);
132static int basic_msg_fill(
struct rtnl_tc *tc,
void *data,
140 if (b->b_mask & BASIC_ATTR_TARGET)
143 if (b->b_mask & BASIC_ATTR_EMATCH &&
144 rtnl_ematch_fill_attr(msg, TCA_BASIC_EMATCHES, b->b_ematch) < 0)
145 goto nla_put_failure;
147 if (b->b_mask & BASIC_ATTR_ACTION) {
150 err = rtnl_act_fill(msg, TCA_BASIC_ACT, b->b_act);
166void rtnl_basic_set_target(
struct rtnl_cls *cls, uint32_t target)
173 b->b_target = target;
174 b->b_mask |= BASIC_ATTR_TARGET;
177uint32_t rtnl_basic_get_target(
struct rtnl_cls *cls)
187void rtnl_basic_set_ematch(
struct rtnl_cls *cls,
struct rtnl_ematch_tree *tree)
196 b->b_mask &= ~BASIC_ATTR_EMATCH;
202 b->b_mask |= BASIC_ATTR_EMATCH;
205struct rtnl_ematch_tree *rtnl_basic_get_ematch(
struct rtnl_cls *cls)
215int rtnl_basic_add_action(
struct rtnl_cls *cls,
struct rtnl_act *act)
226 b->b_mask |= BASIC_ATTR_ACTION;
227 if ((err = rtnl_act_append(&b->b_act, act)))
235struct rtnl_act* rtnl_basic_get_action(
struct rtnl_cls *cls)
242 if (!(b->b_mask & BASIC_ATTR_ACTION))
248int rtnl_basic_del_action(
struct rtnl_cls *cls,
struct rtnl_act *act)
259 if (!(b->b_mask & BASIC_ATTR_ACTION))
261 ret = rtnl_act_remove(&b->b_act, act);
266 b->b_mask &= ~BASIC_ATTR_ACTION;
272static struct rtnl_tc_ops basic_ops = {
274 .to_type = RTNL_TC_TYPE_CLS,
276 .to_msg_parser = basic_msg_parser,
277 .to_clone = basic_clone,
278 .to_free_data = basic_free_data,
279 .to_msg_fill = basic_msg_fill,
286static void _nl_init basic_init(
void)
291static void _nl_exit basic_exit(
void)
uint32_t nla_get_u32(const struct nlattr *nla)
Return payload of 32 bit integer attribute.
#define NLA_PUT_U32(msg, attrtype, value)
Add 32 bit integer attribute to netlink message.
@ NLA_NESTED
Nested attributes.
char * rtnl_tc_handle2str(uint32_t handle, char *buf, size_t len)
Convert a traffic control handle to a character string (Reentrant).
void rtnl_ematch_tree_free(struct rtnl_ematch_tree *tree)
Free ematch tree object.
int rtnl_ematch_parse_attr(struct nlattr *attr, struct rtnl_ematch_tree **result)
Parse ematch netlink attributes.
void * rtnl_tc_data_peek(struct rtnl_tc *tc)
Returns the private data of the traffic control object.
#define TC_CAST(ptr)
Macro to cast qdisc/class/classifier to tc object.
void * rtnl_tc_data(struct rtnl_tc *)
Return pointer to private data of traffic control object.
int rtnl_tc_register(struct rtnl_tc_ops *)
Register a traffic control module.
void rtnl_tc_unregister(struct rtnl_tc_ops *)
Unregister a traffic control module.
void nl_dump(struct nl_dump_params *params, const char *fmt,...)
Dump a formatted character string.
@ NL_DUMP_LINE
Dump object briefly on one line.
@ NL_DUMP_DETAILS
Dump all attributes but no statistics.
Attribute validation policy.
uint16_t type
Type of attribute or NLA_UNSPEC.