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>
28#include "nl-aux-route/nl-route.h"
33 struct rtnl_ematch_tree * b_ematch;
39#define BASIC_ATTR_TARGET 0x001
40#define BASIC_ATTR_EMATCH 0x002
41#define BASIC_ATTR_ACTION 0x004
44static struct nla_policy basic_policy[TCA_BASIC_MAX+1] = {
49static int basic_clone(
void *_dst,
void *_src)
51 return -NLE_OPNOTSUPP;
54static void basic_free_data(
struct rtnl_tc *tc,
void *data)
62 rtnl_act_put_all(&b->b_act);
66static int basic_msg_parser(
struct rtnl_tc *tc,
void *data)
68 struct nlattr *tb[TCA_BASIC_MAX + 1];
72 err = tca_parse(tb, TCA_BASIC_MAX, tc, basic_policy);
76 if (tb[TCA_BASIC_CLASSID]) {
78 b->b_mask |= BASIC_ATTR_TARGET;
81 if (tb[TCA_BASIC_EMATCHES]) {
87 b->b_mask |= BASIC_ATTR_EMATCH;
89 if (tb[TCA_BASIC_ACT]) {
90 b->b_mask |= BASIC_ATTR_ACTION;
91 err = rtnl_act_parse(&b->b_act, tb[TCA_BASIC_ACT]);
99static void basic_dump_line(
struct rtnl_tc *tc,
void *data,
108 if (b->b_mask & BASIC_ATTR_EMATCH)
113 if (b->b_mask & BASIC_ATTR_TARGET)
118static void basic_dump_details(
struct rtnl_tc *tc,
void *data,
126 if (b->b_mask & BASIC_ATTR_EMATCH) {
127 nl_dump_line(p,
" ematch ");
128 rtnl_ematch_tree_dump(b->b_ematch, p);
133static int basic_msg_fill(
struct rtnl_tc *tc,
void *data,
141 if (b->b_mask & BASIC_ATTR_TARGET)
144 if (b->b_mask & BASIC_ATTR_EMATCH &&
145 rtnl_ematch_fill_attr(msg, TCA_BASIC_EMATCHES, b->b_ematch) < 0)
146 goto nla_put_failure;
148 if (b->b_mask & BASIC_ATTR_ACTION) {
151 err = rtnl_act_fill(msg, TCA_BASIC_ACT, b->b_act);
167void rtnl_basic_set_target(
struct rtnl_cls *cls, uint32_t target)
174 b->b_target = target;
175 b->b_mask |= BASIC_ATTR_TARGET;
178uint32_t rtnl_basic_get_target(
struct rtnl_cls *cls)
188void rtnl_basic_set_ematch(
struct rtnl_cls *cls,
struct rtnl_ematch_tree *tree)
197 b->b_mask &= ~BASIC_ATTR_EMATCH;
203 b->b_mask |= BASIC_ATTR_EMATCH;
206struct rtnl_ematch_tree *rtnl_basic_get_ematch(
struct rtnl_cls *cls)
216int rtnl_basic_add_action(
struct rtnl_cls *cls,
struct rtnl_act *act)
227 if ((err = _rtnl_act_append_get(&b->b_act, act)) < 0)
230 b->b_mask |= BASIC_ATTR_ACTION;
234struct rtnl_act* rtnl_basic_get_action(
struct rtnl_cls *cls)
241 if (!(b->b_mask & BASIC_ATTR_ACTION))
247int rtnl_basic_del_action(
struct rtnl_cls *cls,
struct rtnl_act *act)
258 if (!(b->b_mask & BASIC_ATTR_ACTION))
260 ret = rtnl_act_remove(&b->b_act, act);
265 b->b_mask &= ~BASIC_ATTR_ACTION;
271static struct rtnl_tc_ops basic_ops = {
273 .to_type = RTNL_TC_TYPE_CLS,
275 .to_msg_parser = basic_msg_parser,
276 .to_clone = basic_clone,
277 .to_free_data = basic_free_data,
278 .to_msg_fill = basic_msg_fill,
285static void _nl_init basic_init(
void)
290static 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.