13#include <netlink-private/netlink.h>
14#include <netlink-private/tc.h>
15#include <netlink/netlink.h>
16#include <netlink/attr.h>
17#include <netlink/utils.h>
18#include <netlink-private/route/tc-api.h>
19#include <netlink/route/classifier.h>
20#include <netlink/route/cls/matchall.h>
21#include <netlink/route/action.h>
24#define MALL_ATTR_CLASSID 0x01
25#define MALL_ATTR_FLAGS 0x02
26#define MALL_ATTR_ACTION 0x03
29static struct nla_policy mall_policy[TCA_MATCHALL_MAX + 1] = {
31 [TCA_MATCHALL_FLAGS] = { .type =
NLA_U32 },
39int rtnl_mall_set_classid(
struct rtnl_cls *cls, uint32_t classid)
41 struct rtnl_mall *mall;
45 mall->m_classid = classid;
46 mall->m_mask |= MALL_ATTR_CLASSID;
51int rtnl_mall_get_classid(
struct rtnl_cls *cls, uint32_t *classid)
53 struct rtnl_mall *mall;
58 if (!(mall->m_mask & MALL_ATTR_CLASSID))
61 *classid = mall->m_classid;
65int rtnl_mall_set_flags(
struct rtnl_cls *cls, uint32_t flags)
67 struct rtnl_mall *mall;
72 mall->m_flags = flags;
73 mall->m_mask |= MALL_ATTR_FLAGS;
78int rtnl_mall_get_flags(
struct rtnl_cls *cls, uint32_t *flags)
80 struct rtnl_mall *mall;
85 if (!(mall->m_mask & MALL_ATTR_FLAGS))
88 *flags = mall->m_flags;
92int rtnl_mall_append_action(
struct rtnl_cls *cls,
struct rtnl_act *act)
94 struct rtnl_mall *mall;
103 mall->m_mask |= MALL_ATTR_ACTION;
104 err = rtnl_act_append(&mall->m_act, act);
112struct rtnl_act *rtnl_mall_get_first_action(
struct rtnl_cls *cls)
114 struct rtnl_mall *mall;
115 struct rtnl_act *act;
120 if (!(mall->m_mask & MALL_ATTR_ACTION))
129int rtnl_mall_del_action(
struct rtnl_cls *cls,
struct rtnl_act *act)
131 struct rtnl_mall *mall;
140 if (!(mall->m_mask & MALL_ATTR_ACTION))
143 ret = rtnl_act_remove(&mall->m_act, act);
154static void mall_free_data(
struct rtnl_tc *tc,
void *data)
156 struct rtnl_mall *mall = data;
159 rtnl_act_put_all(&mall->m_act);
162static int mall_msg_parser(
struct rtnl_tc *tc,
void *data)
164 struct rtnl_mall *mall = data;
165 struct nlattr *tb[TCA_MATCHALL_MAX + 1];
168 err = tca_parse(tb, TCA_MATCHALL_MAX, tc, mall_policy);
172 if (tb[TCA_MATCHALL_CLASSID]) {
173 mall->m_classid =
nla_get_u32(tb[TCA_MATCHALL_CLASSID]);
174 mall->m_mask |= MALL_ATTR_CLASSID;
177 if (tb[TCA_MATCHALL_FLAGS]) {
178 mall->m_flags =
nla_get_u32(tb[TCA_MATCHALL_FLAGS]);
179 mall->m_mask |= MALL_ATTR_FLAGS;
182 if (tb[TCA_MATCHALL_ACT]) {
183 mall->m_mask |= MALL_ATTR_ACTION;
184 err = rtnl_act_parse(&mall->m_act, tb[TCA_MATCHALL_ACT]);
192static int mall_msg_fill(
struct rtnl_tc *tc,
void *data,
struct nl_msg *msg)
194 struct rtnl_mall *mall = data;
199 if (mall->m_mask & MALL_ATTR_CLASSID)
200 NLA_PUT_U32(msg, TCA_MATCHALL_CLASSID, mall->m_classid);
202 if (mall->m_mask & MALL_ATTR_FLAGS)
203 NLA_PUT_U32(msg, TCA_MATCHALL_FLAGS, mall->m_flags);
205 if (mall->m_mask & MALL_ATTR_ACTION) {
208 err = rtnl_act_fill(msg, TCA_MATCHALL_ACT, mall->m_act);
219static int mall_clone(
void *_dst,
void *_src)
221 struct rtnl_mall *dst = _dst, *src = _src;
222 struct rtnl_act *next, *
new;
228 if (!(dst->m_act = rtnl_act_alloc()))
232 nl_init_list_head(&dst->m_act->ce_list);
234 memcpy(dst->m_act, src->m_act,
sizeof(
struct rtnl_act));
235 next = rtnl_act_next(src->m_act);
241 err = rtnl_act_append(&dst->m_act,
new);
245 next = rtnl_act_next(next);
252static void mall_dump_line(
struct rtnl_tc *tc,
void *data,
255 struct rtnl_mall *mall = data;
261 if (mall->m_mask & MALL_ATTR_CLASSID)
266static void mall_dump_details(
struct rtnl_tc *tc,
void *data,
269 struct rtnl_mall *mall = data;
274 nl_dump(p,
"no details for match-all");
277static struct rtnl_tc_ops mall_ops = {
278 .to_kind =
"matchall",
279 .to_type = RTNL_TC_TYPE_CLS,
280 .to_size =
sizeof(
struct rtnl_mall),
281 .to_msg_parser = mall_msg_parser,
282 .to_free_data = mall_free_data,
283 .to_clone = mall_clone,
284 .to_msg_fill = mall_msg_fill,
291static void __init mall_init(
void)
296static void __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 *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.