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>
31#define MALL_ATTR_CLASSID 0x01
32#define MALL_ATTR_FLAGS 0x02
33#define MALL_ATTR_ACTION 0x03
36static struct nla_policy mall_policy[TCA_MATCHALL_MAX + 1] = {
38 [TCA_MATCHALL_FLAGS] = { .type =
NLA_U32 },
46int rtnl_mall_set_classid(
struct rtnl_cls *cls, uint32_t classid)
52 mall->m_classid = classid;
53 mall->m_mask |= MALL_ATTR_CLASSID;
58int rtnl_mall_get_classid(
struct rtnl_cls *cls, uint32_t *classid)
65 if (!(mall->m_mask & MALL_ATTR_CLASSID))
68 *classid = mall->m_classid;
72int rtnl_mall_set_flags(
struct rtnl_cls *cls, uint32_t flags)
79 mall->m_flags = flags;
80 mall->m_mask |= MALL_ATTR_FLAGS;
85int rtnl_mall_get_flags(
struct rtnl_cls *cls, uint32_t *flags)
92 if (!(mall->m_mask & MALL_ATTR_FLAGS))
95 *flags = mall->m_flags;
99int rtnl_mall_append_action(
struct rtnl_cls *cls,
struct rtnl_act *act)
110 mall->m_mask |= MALL_ATTR_ACTION;
111 err = rtnl_act_append(&mall->m_act, act);
119struct rtnl_act *rtnl_mall_get_first_action(
struct rtnl_cls *cls)
127 if (!(mall->m_mask & MALL_ATTR_ACTION))
136int rtnl_mall_del_action(
struct rtnl_cls *cls,
struct rtnl_act *act)
147 if (!(mall->m_mask & MALL_ATTR_ACTION))
150 ret = rtnl_act_remove(&mall->m_act, act);
161static void mall_free_data(
struct rtnl_tc *tc,
void *data)
166 rtnl_act_put_all(&mall->m_act);
169static int mall_msg_parser(
struct rtnl_tc *tc,
void *data)
172 struct nlattr *tb[TCA_MATCHALL_MAX + 1];
175 err = tca_parse(tb, TCA_MATCHALL_MAX, tc, mall_policy);
179 if (tb[TCA_MATCHALL_CLASSID]) {
180 mall->m_classid =
nla_get_u32(tb[TCA_MATCHALL_CLASSID]);
181 mall->m_mask |= MALL_ATTR_CLASSID;
184 if (tb[TCA_MATCHALL_FLAGS]) {
185 mall->m_flags =
nla_get_u32(tb[TCA_MATCHALL_FLAGS]);
186 mall->m_mask |= MALL_ATTR_FLAGS;
189 if (tb[TCA_MATCHALL_ACT]) {
190 mall->m_mask |= MALL_ATTR_ACTION;
191 err = rtnl_act_parse(&mall->m_act, tb[TCA_MATCHALL_ACT]);
199static int mall_msg_fill(
struct rtnl_tc *tc,
void *data,
struct nl_msg *msg)
206 if (mall->m_mask & MALL_ATTR_CLASSID)
207 NLA_PUT_U32(msg, TCA_MATCHALL_CLASSID, mall->m_classid);
209 if (mall->m_mask & MALL_ATTR_FLAGS)
210 NLA_PUT_U32(msg, TCA_MATCHALL_FLAGS, mall->m_flags);
212 if (mall->m_mask & MALL_ATTR_ACTION) {
215 err = rtnl_act_fill(msg, TCA_MATCHALL_ACT, mall->m_act);
226static int mall_clone(
void *_dst,
void *_src)
228 struct rtnl_mall *dst = _dst, *src = _src;
235 if (!(dst->m_act = rtnl_act_alloc()))
239 nl_init_list_head(&dst->m_act->ce_list);
241 memcpy(dst->m_act, src->m_act,
sizeof(
struct rtnl_act));
242 next = rtnl_act_next(src->m_act);
248 err = rtnl_act_append(&dst->m_act,
new);
252 next = rtnl_act_next(next);
259static void mall_dump_line(
struct rtnl_tc *tc,
void *data,
268 if (mall->m_mask & MALL_ATTR_CLASSID)
273static void mall_dump_details(
struct rtnl_tc *tc,
void *data,
281 nl_dump(p,
"no details for match-all");
284static struct rtnl_tc_ops mall_ops = {
285 .to_kind =
"matchall",
286 .to_type = RTNL_TC_TYPE_CLS,
288 .to_msg_parser = mall_msg_parser,
289 .to_free_data = mall_free_data,
290 .to_clone = mall_clone,
291 .to_msg_fill = mall_msg_fill,
298static void _nl_init mall_init(
void)
303static 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.