19 #include <netlink-private/netlink.h> 20 #include <netlink-private/tc.h> 21 #include <netlink/netlink.h> 22 #include <netlink/attr.h> 23 #include <netlink/utils.h> 24 #include <netlink-private/route/tc-api.h> 25 #include <netlink/route/classifier.h> 26 #include <netlink/route/cls/matchall.h> 27 #include <netlink/route/action.h> 30 #define MALL_ATTR_CLASSID 0x01 31 #define MALL_ATTR_FLAGS 0x02 32 #define MALL_ATTR_ACTION 0x03 35 static struct nla_policy mall_policy[TCA_MATCHALL_MAX + 1] = {
37 [TCA_MATCHALL_FLAGS] = { .type =
NLA_U32 },
45 int rtnl_mall_set_classid(
struct rtnl_cls *cls, uint32_t classid)
47 struct rtnl_mall *mall;
51 mall->m_classid = classid;
52 mall->m_mask |= MALL_ATTR_CLASSID;
57 int rtnl_mall_get_classid(
struct rtnl_cls *cls, uint32_t *classid)
59 struct rtnl_mall *mall;
64 if (!(mall->m_mask & MALL_ATTR_CLASSID))
67 *classid = mall->m_classid;
71 int rtnl_mall_set_flags(
struct rtnl_cls *cls, uint32_t flags)
73 struct rtnl_mall *mall;
78 mall->m_flags = flags;
79 mall->m_mask |= MALL_ATTR_FLAGS;
84 int rtnl_mall_get_flags(
struct rtnl_cls *cls, uint32_t *flags)
86 struct rtnl_mall *mall;
91 if (!(mall->m_mask & MALL_ATTR_FLAGS))
94 *flags = mall->m_flags;
98 int rtnl_mall_append_action(
struct rtnl_cls *cls,
struct rtnl_act *act)
100 struct rtnl_mall *mall;
109 mall->m_mask |= MALL_ATTR_ACTION;
110 err = rtnl_act_append(&mall->m_act, act);
118 struct rtnl_act *rtnl_mall_get_first_action(
struct rtnl_cls *cls)
120 struct rtnl_mall *mall;
121 struct rtnl_act *act;
126 if (!(mall->m_mask & MALL_ATTR_ACTION))
135 int rtnl_mall_del_action(
struct rtnl_cls *cls,
struct rtnl_act *act)
137 struct rtnl_mall *mall;
146 if (!(mall->m_mask & MALL_ATTR_ACTION))
149 ret = rtnl_act_remove(&mall->m_act, act);
160 static void mall_free_data(
struct rtnl_tc *tc,
void *data)
162 struct rtnl_mall *mall = data;
165 rtnl_act_put_all(&mall->m_act);
168 static int mall_msg_parser(
struct rtnl_tc *tc,
void *data)
170 struct rtnl_mall *mall = 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]);
198 static int mall_msg_fill(
struct rtnl_tc *tc,
void *data,
struct nl_msg *msg)
200 struct rtnl_mall *mall = data;
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);
225 static int mall_clone(
void *_dst,
void *_src)
227 struct rtnl_mall *dst = _dst, *src = _src;
228 struct rtnl_act *next, *
new;
232 if (!(dst->m_act = rtnl_act_alloc()))
236 nl_init_list_head(&dst->m_act->ce_list);
238 memcpy(dst->m_act, src->m_act,
sizeof(
struct rtnl_act));
239 next = rtnl_act_next(src->m_act);
245 err = rtnl_act_append(&dst->m_act,
new);
249 next = rtnl_act_next(next);
256 static void mall_dump_line(
struct rtnl_tc *tc,
void *data,
259 struct rtnl_mall *mall = data;
265 if (mall->m_mask & MALL_ATTR_CLASSID)
270 static void mall_dump_details(
struct rtnl_tc *tc,
void *data,
273 struct rtnl_mall *mall = data;
278 nl_dump(p,
"no details for match-all");
281 static struct rtnl_tc_ops mall_ops = {
282 .to_kind =
"matchall",
283 .to_type = RTNL_TC_TYPE_CLS,
284 .to_size =
sizeof(
struct rtnl_mall),
285 .to_msg_parser = mall_msg_parser,
286 .to_free_data = mall_free_data,
287 .to_clone = mall_clone,
288 .to_msg_fill = mall_msg_fill,
295 static void __init mall_init(
void)
300 static void __exit mall_exit(
void)
Dump object briefly on one line.
int rtnl_tc_register(struct rtnl_tc_ops *ops)
Register a traffic control module.
Attribute validation policy.
uint32_t nla_get_u32(const struct nlattr *nla)
Return payload of 32 bit integer attribute.
Dump all attributes but no statistics.
void rtnl_tc_unregister(struct rtnl_tc_ops *ops)
Unregister a traffic control module.
#define TC_CAST(ptr)
Macro to cast qdisc/class/classifier to tc object.
#define NLA_PUT_U32(msg, attrtype, value)
Add 32 bit integer attribute to netlink message.
void * rtnl_tc_data(struct rtnl_tc *tc)
Return pointer to private data of traffic control object.
uint16_t type
Type of attribute or NLA_UNSPEC.
char * rtnl_tc_handle2str(uint32_t handle, char *buf, size_t len)
Convert a traffic control handle to a character string (Reentrant).
void nl_dump(struct nl_dump_params *params, const char *fmt,...)
Dump a formatted character string.
void * rtnl_tc_data_peek(struct rtnl_tc *tc)
Returns the private data of the traffic control object.
struct nl_object * nl_object_clone(struct nl_object *obj)
Allocate a new object and copy all data from an existing object.