19#include <netlink-private/netlink.h>
20#include <netlink-private/tc.h>
21#include <netlink/netlink.h>
22#include <netlink-private/route/tc-api.h>
23#include <netlink/route/classifier.h>
24#include <netlink/route/action.h>
25#include <netlink/route/cls/basic.h>
26#include <netlink/route/cls/ematch.h>
31 struct rtnl_ematch_tree * b_ematch;
33 struct rtnl_act * b_act;
37#define BASIC_ATTR_TARGET 0x001
38#define BASIC_ATTR_EMATCH 0x002
39#define BASIC_ATTR_ACTION 0x004
42static struct nla_policy basic_policy[TCA_BASIC_MAX+1] = {
47static int basic_clone(
void *_dst,
void *_src)
49 return -NLE_OPNOTSUPP;
52static void basic_free_data(
struct rtnl_tc *tc,
void *data)
60 rtnl_act_put_all(&b->b_act);
64static int basic_msg_parser(
struct rtnl_tc *tc,
void *data)
66 struct nlattr *tb[TCA_BASIC_MAX + 1];
70 err = tca_parse(tb, TCA_BASIC_MAX, tc, basic_policy);
74 if (tb[TCA_BASIC_CLASSID]) {
76 b->b_mask |= BASIC_ATTR_TARGET;
79 if (tb[TCA_BASIC_EMATCHES]) {
85 b->b_mask |= BASIC_ATTR_EMATCH;
87 if (tb[TCA_BASIC_ACT]) {
88 b->b_mask |= BASIC_ATTR_ACTION;
89 err = rtnl_act_parse(&b->b_act, tb[TCA_BASIC_ACT]);
97static void basic_dump_line(
struct rtnl_tc *tc,
void *data,
106 if (b->b_mask & BASIC_ATTR_EMATCH)
111 if (b->b_mask & BASIC_ATTR_TARGET)
116static void basic_dump_details(
struct rtnl_tc *tc,
void *data,
124 if (b->b_mask & BASIC_ATTR_EMATCH) {
125 nl_dump_line(p,
" ematch ");
126 rtnl_ematch_tree_dump(b->b_ematch, p);
131static int basic_msg_fill(
struct rtnl_tc *tc,
void *data,
139 if (b->b_mask & BASIC_ATTR_TARGET)
142 if (b->b_mask & BASIC_ATTR_EMATCH &&
143 rtnl_ematch_fill_attr(msg, TCA_BASIC_EMATCHES, b->b_ematch) < 0)
144 goto nla_put_failure;
146 if (b->b_mask & BASIC_ATTR_ACTION) {
149 err = rtnl_act_fill(msg, TCA_BASIC_ACT, b->b_act);
165void rtnl_basic_set_target(
struct rtnl_cls *cls, uint32_t target)
172 b->b_target = target;
173 b->b_mask |= BASIC_ATTR_TARGET;
176uint32_t rtnl_basic_get_target(
struct rtnl_cls *cls)
186void rtnl_basic_set_ematch(
struct rtnl_cls *cls,
struct rtnl_ematch_tree *tree)
195 b->b_mask &= ~BASIC_ATTR_EMATCH;
201 b->b_mask |= BASIC_ATTR_EMATCH;
204struct rtnl_ematch_tree *rtnl_basic_get_ematch(
struct rtnl_cls *cls)
214int rtnl_basic_add_action(
struct rtnl_cls *cls,
struct rtnl_act *act)
225 b->b_mask |= BASIC_ATTR_ACTION;
226 if ((err = rtnl_act_append(&b->b_act, act)))
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 __init basic_init(
void)
290static void __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 *tc)
Return pointer to private data of traffic control object.
int rtnl_tc_register(struct rtnl_tc_ops *ops)
Register a traffic control module.
void rtnl_tc_unregister(struct rtnl_tc_ops *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.