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/act/skbedit.h>
27 static struct nla_policy skbedit_policy[TCA_SKBEDIT_MAX + 1] = {
28 [TCA_SKBEDIT_PARMS] = { .
minlen =
sizeof(
struct tc_skbedit) },
29 [TCA_SKBEDIT_PRIORITY] = { .type =
NLA_U32 },
30 [TCA_SKBEDIT_QUEUE_MAPPING] = { .type =
NLA_U16 },
31 [TCA_SKBEDIT_MARK] = { .type =
NLA_U32 },
34 static int skbedit_msg_parser(
struct rtnl_tc *tc,
void *data)
36 struct rtnl_skbedit *u = data;
37 struct nlattr *tb[TCA_SKBEDIT_MAX + 1];
40 err = tca_parse(tb, TCA_SKBEDIT_MAX, tc, skbedit_policy);
44 if (!tb[TCA_SKBEDIT_PARMS])
45 return -NLE_MISSING_ATTR;
48 if (tb[TCA_SKBEDIT_PRIORITY] != NULL) {
49 u->s_flags |= SKBEDIT_F_PRIORITY;
53 if (tb[TCA_SKBEDIT_QUEUE_MAPPING] != NULL) {
54 u->s_flags |= SKBEDIT_F_QUEUE_MAPPING;
55 u->s_queue_mapping =
nla_get_u16(tb[TCA_SKBEDIT_QUEUE_MAPPING]);
58 if (tb[TCA_SKBEDIT_MARK] != NULL) {
59 u->s_flags |= SKBEDIT_F_MARK;
66 static void skbedit_free_data(
struct rtnl_tc *tc,
void *data)
70 static int skbedit_clone(
void *_dst,
void *_src)
72 struct rtnl_skbedit *dst = _dst, *src = _src;
74 memcpy(dst, src,
sizeof(*src));
78 static void skbedit_dump_line(
struct rtnl_tc *tc,
void *data,
81 struct rtnl_skbedit *u = data;
86 if (u->s_flags & SKBEDIT_F_PRIORITY)
87 nl_dump(p,
" priority %u", u->s_prio);
89 if (u->s_flags & SKBEDIT_F_MARK)
90 nl_dump(p,
" mark %u", u->s_mark);
92 if (u->s_flags & SKBEDIT_F_QUEUE_MAPPING)
93 nl_dump(p,
" queue_mapping %u", u->s_queue_mapping);
95 switch(u->s_parm.action){
117 static void skbedit_dump_details(
struct rtnl_tc *tc,
void *data,
122 static void skbedit_dump_stats(
struct rtnl_tc *tc,
void *data,
125 struct rtnl_skbedit *u = data;
133 static int skbedit_msg_fill(
struct rtnl_tc *tc,
void *data,
struct nl_msg *msg)
135 struct rtnl_skbedit *u = data;
140 NLA_PUT(msg, TCA_SKBEDIT_PARMS,
sizeof(u->s_parm), &u->s_parm);
142 if (u->s_flags & SKBEDIT_F_MARK)
145 if (u->s_flags & SKBEDIT_F_PRIORITY)
148 if (u->s_flags & SKBEDIT_F_QUEUE_MAPPING)
149 NLA_PUT_U32(msg, TCA_SKBEDIT_QUEUE_MAPPING, u->s_queue_mapping);
162 int rtnl_skbedit_set_action(
struct rtnl_act *act,
int action)
164 struct rtnl_skbedit *u;
169 if (action > TC_ACT_REPEAT || action < TC_ACT_UNSPEC)
172 u->s_parm.action = action;
176 int rtnl_skbedit_get_action(
struct rtnl_act *act)
178 struct rtnl_skbedit *u;
182 return u->s_parm.action;
185 int rtnl_skbedit_set_queue_mapping(
struct rtnl_act *act, uint16_t index)
187 struct rtnl_skbedit *u;
192 u->s_queue_mapping = index;
193 u->s_flags |= SKBEDIT_F_QUEUE_MAPPING;
197 int rtnl_skbedit_get_queue_mapping(
struct rtnl_act *act, uint16_t *index)
199 struct rtnl_skbedit *u;
204 if (!(u->s_flags & SKBEDIT_F_QUEUE_MAPPING))
207 *index = u->s_queue_mapping;
211 int rtnl_skbedit_set_mark(
struct rtnl_act *act, uint32_t mark)
213 struct rtnl_skbedit *u;
219 u->s_flags |= SKBEDIT_F_MARK;
223 int rtnl_skbedit_get_mark(
struct rtnl_act *act, uint32_t *mark)
225 struct rtnl_skbedit *u;
230 if (!(u->s_flags & SKBEDIT_F_MARK))
237 int rtnl_skbedit_set_priority(
struct rtnl_act *act, uint32_t prio)
239 struct rtnl_skbedit *u;
245 u->s_flags |= SKBEDIT_F_PRIORITY;
249 int rtnl_skbedit_get_priority(
struct rtnl_act *act, uint32_t *prio)
251 struct rtnl_skbedit *u;
256 if (!(u->s_flags & SKBEDIT_F_PRIORITY))
265 static struct rtnl_tc_ops skbedit_ops = {
266 .to_kind =
"skbedit",
267 .to_type = RTNL_TC_TYPE_ACT,
268 .to_size =
sizeof(
struct rtnl_skbedit),
269 .to_msg_parser = skbedit_msg_parser,
270 .to_free_data = skbedit_free_data,
271 .to_clone = skbedit_clone,
272 .to_msg_fill = skbedit_msg_fill,
280 static void __init skbedit_init(
void)
285 static void __exit skbedit_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(msg, attrtype, attrlen, data)
Add unspecific attribute to netlink message.
#define NLA_PUT_U32(msg, attrtype, value)
Add 32 bit integer attribute to netlink message.
uint16_t minlen
Minimal length of payload required.
void * rtnl_tc_data(struct rtnl_tc *tc)
Return pointer to private data of traffic control object.
uint16_t nla_get_u16(const struct nlattr *nla)
Return payload of 16 bit integer attribute.
void nl_dump(struct nl_dump_params *params, const char *fmt,...)
Dump a formatted character string.
Dump all attributes including statistics.