13#include "nl-default.h"
15#include <netlink/netlink.h>
16#include <netlink/attr.h>
17#include <netlink/utils.h>
18#include <netlink/route/classifier.h>
19#include <netlink/route/cls/matchall.h>
20#include <netlink/route/action.h>
23#include "nl-aux-route/nl-route.h"
32#define MALL_ATTR_CLASSID 0x01
33#define MALL_ATTR_FLAGS 0x02
34#define MALL_ATTR_ACTION 0x03
37static struct nla_policy mall_policy[TCA_MATCHALL_MAX + 1] = {
39 [TCA_MATCHALL_FLAGS] = { .type =
NLA_U32 },
47int rtnl_mall_set_classid(
struct rtnl_cls *cls, uint32_t classid)
53 mall->m_classid = classid;
54 mall->m_mask |= MALL_ATTR_CLASSID;
59int rtnl_mall_get_classid(
struct rtnl_cls *cls, uint32_t *classid)
66 if (!(mall->m_mask & MALL_ATTR_CLASSID))
69 *classid = mall->m_classid;
73int rtnl_mall_set_flags(
struct rtnl_cls *cls, uint32_t flags)
80 mall->m_flags = flags;
81 mall->m_mask |= MALL_ATTR_FLAGS;
86int rtnl_mall_get_flags(
struct rtnl_cls *cls, uint32_t *flags)
93 if (!(mall->m_mask & MALL_ATTR_FLAGS))
96 *flags = mall->m_flags;
100int rtnl_mall_append_action(
struct rtnl_cls *cls,
struct rtnl_act *act)
111 if ((err = _rtnl_act_append_get(&mall->m_act, act)) < 0)
114 mall->m_mask |= MALL_ATTR_ACTION;
118struct rtnl_act *rtnl_mall_get_first_action(
struct rtnl_cls *cls)
126 if (!(mall->m_mask & MALL_ATTR_ACTION))
135int rtnl_mall_del_action(
struct rtnl_cls *cls,
struct rtnl_act *act)
146 if (!(mall->m_mask & MALL_ATTR_ACTION))
149 ret = rtnl_act_remove(&mall->m_act, act);
160static void mall_free_data(
struct rtnl_tc *tc,
void *data)
165 rtnl_act_put_all(&mall->m_act);
168static int mall_msg_parser(
struct rtnl_tc *tc,
void *data)
171 struct nlattr *tb[TCA_MATCHALL_MAX + 1];
174 err = tca_parse(tb, TCA_MATCHALL_MAX, tc, mall_policy);
178 if (tb[TCA_MATCHALL_CLASSID]) {
179 mall->m_classid =
nla_get_u32(tb[TCA_MATCHALL_CLASSID]);
180 mall->m_mask |= MALL_ATTR_CLASSID;
183 if (tb[TCA_MATCHALL_FLAGS]) {
184 mall->m_flags =
nla_get_u32(tb[TCA_MATCHALL_FLAGS]);
185 mall->m_mask |= MALL_ATTR_FLAGS;
188 if (tb[TCA_MATCHALL_ACT]) {
189 mall->m_mask |= MALL_ATTR_ACTION;
190 err = rtnl_act_parse(&mall->m_act, tb[TCA_MATCHALL_ACT]);
198static int mall_msg_fill(
struct rtnl_tc *tc,
void *data,
struct nl_msg *msg)
205 if (mall->m_mask & MALL_ATTR_CLASSID)
206 NLA_PUT_U32(msg, TCA_MATCHALL_CLASSID, mall->m_classid);
208 if (mall->m_mask & MALL_ATTR_FLAGS)
209 NLA_PUT_U32(msg, TCA_MATCHALL_FLAGS, mall->m_flags);
211 if (mall->m_mask & MALL_ATTR_ACTION) {
214 err = rtnl_act_fill(msg, TCA_MATCHALL_ACT, mall->m_act);
225static int mall_clone(
void *_dst,
void *_src)
227 struct rtnl_mall *dst = _dst, *src = _src;
234 if (!(dst->m_act = rtnl_act_alloc()))
238 nl_init_list_head(&dst->m_act->ce_list);
240 memcpy(dst->m_act, src->m_act,
sizeof(
struct rtnl_act));
241 next = rtnl_act_next(src->m_act);
247 err = _rtnl_act_append_take(&dst->m_act,
new);
251 next = rtnl_act_next(next);
258static void mall_dump_line(
struct rtnl_tc *tc,
void *data,
267 if (mall->m_mask & MALL_ATTR_CLASSID)
272static void mall_dump_details(
struct rtnl_tc *tc,
void *data,
280 nl_dump(p,
"no details for match-all");
283static struct rtnl_tc_ops mall_ops = {
284 .to_kind =
"matchall",
285 .to_type = RTNL_TC_TYPE_CLS,
287 .to_msg_parser = mall_msg_parser,
288 .to_free_data = mall_free_data,
289 .to_clone = mall_clone,
290 .to_msg_fill = mall_msg_fill,
297static void _nl_init mall_init(
void)
302static void _nl_exit mall_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.
char * rtnl_tc_handle2str(uint32_t handle, char *buf, size_t len)
Convert a traffic control handle to a character string (Reentrant).
struct nl_object * nl_object_clone(struct nl_object *obj)
Allocate a new object and copy all data from an existing object.
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.