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/act/skbedit.h>
21 static struct nla_policy skbedit_policy[TCA_SKBEDIT_MAX + 1] = {
22 [TCA_SKBEDIT_PARMS] = { .
minlen =
sizeof(
struct tc_skbedit) },
23 [TCA_SKBEDIT_PRIORITY] = { .type =
NLA_U32 },
24 [TCA_SKBEDIT_QUEUE_MAPPING] = { .type =
NLA_U16 },
25 [TCA_SKBEDIT_MARK] = { .type =
NLA_U32 },
28 static int skbedit_msg_parser(
struct rtnl_tc *tc,
void *data)
30 struct rtnl_skbedit *u = data;
31 struct nlattr *tb[TCA_SKBEDIT_MAX + 1];
34 err = tca_parse(tb, TCA_SKBEDIT_MAX, tc, skbedit_policy);
38 if (!tb[TCA_SKBEDIT_PARMS])
39 return -NLE_MISSING_ATTR;
42 if (tb[TCA_SKBEDIT_PRIORITY] != NULL) {
43 u->s_flags |= SKBEDIT_F_PRIORITY;
47 if (tb[TCA_SKBEDIT_QUEUE_MAPPING] != NULL) {
48 u->s_flags |= SKBEDIT_F_QUEUE_MAPPING;
49 u->s_queue_mapping =
nla_get_u16(tb[TCA_SKBEDIT_QUEUE_MAPPING]);
52 if (tb[TCA_SKBEDIT_MARK] != NULL) {
53 u->s_flags |= SKBEDIT_F_MARK;
60 static void skbedit_free_data(
struct rtnl_tc *tc,
void *data)
64 static void skbedit_dump_line(
struct rtnl_tc *tc,
void *data,
67 struct rtnl_skbedit *u = data;
72 if (u->s_flags & SKBEDIT_F_PRIORITY)
73 nl_dump(p,
" priority %u", u->s_prio);
75 if (u->s_flags & SKBEDIT_F_MARK)
76 nl_dump(p,
" mark %u", u->s_mark);
78 if (u->s_flags & SKBEDIT_F_QUEUE_MAPPING)
79 nl_dump(p,
" queue_mapping %u", u->s_queue_mapping);
81 switch(u->s_parm.action){
103 static void skbedit_dump_details(
struct rtnl_tc *tc,
void *data,
108 static void skbedit_dump_stats(
struct rtnl_tc *tc,
void *data,
111 struct rtnl_skbedit *u = data;
119 static int skbedit_msg_fill(
struct rtnl_tc *tc,
void *data,
struct nl_msg *msg)
121 struct rtnl_skbedit *u = data;
126 NLA_PUT(msg, TCA_SKBEDIT_PARMS,
sizeof(u->s_parm), &u->s_parm);
128 if (u->s_flags & SKBEDIT_F_MARK)
131 if (u->s_flags & SKBEDIT_F_PRIORITY)
134 if (u->s_flags & SKBEDIT_F_QUEUE_MAPPING)
135 NLA_PUT_U32(msg, TCA_SKBEDIT_QUEUE_MAPPING, u->s_queue_mapping);
148 int rtnl_skbedit_set_action(
struct rtnl_act *act,
int action)
150 struct rtnl_skbedit *u;
155 if (action > TC_ACT_REPEAT || action < TC_ACT_UNSPEC)
158 u->s_parm.action = action;
162 int rtnl_skbedit_get_action(
struct rtnl_act *act)
164 struct rtnl_skbedit *u;
168 return u->s_parm.action;
171 int rtnl_skbedit_set_queue_mapping(
struct rtnl_act *act, uint16_t index)
173 struct rtnl_skbedit *u;
178 u->s_queue_mapping = index;
179 u->s_flags |= SKBEDIT_F_QUEUE_MAPPING;
183 int rtnl_skbedit_get_queue_mapping(
struct rtnl_act *act, uint16_t *index)
185 struct rtnl_skbedit *u;
190 if (!(u->s_flags & SKBEDIT_F_QUEUE_MAPPING))
193 *index = u->s_queue_mapping;
197 int rtnl_skbedit_set_mark(
struct rtnl_act *act, uint32_t mark)
199 struct rtnl_skbedit *u;
205 u->s_flags |= SKBEDIT_F_MARK;
209 int rtnl_skbedit_get_mark(
struct rtnl_act *act, uint32_t *mark)
211 struct rtnl_skbedit *u;
216 if (!(u->s_flags & SKBEDIT_F_MARK))
223 int rtnl_skbedit_set_priority(
struct rtnl_act *act, uint32_t prio)
225 struct rtnl_skbedit *u;
231 u->s_flags |= SKBEDIT_F_PRIORITY;
235 int rtnl_skbedit_get_priority(
struct rtnl_act *act, uint32_t *prio)
237 struct rtnl_skbedit *u;
242 if (!(u->s_flags & SKBEDIT_F_PRIORITY))
251 static struct rtnl_tc_ops skbedit_ops = {
252 .to_kind =
"skbedit",
253 .to_type = RTNL_TC_TYPE_ACT,
254 .to_size =
sizeof(
struct rtnl_skbedit),
255 .to_msg_parser = skbedit_msg_parser,
256 .to_free_data = skbedit_free_data,
258 .to_msg_fill = skbedit_msg_fill,
266 static void __init skbedit_init(
void)
271 static void __exit skbedit_exit(
void)
uint32_t nla_get_u32(const struct nlattr *nla)
Return payload of 32 bit integer attribute.
uint16_t nla_get_u16(const struct nlattr *nla)
Return payload of 16 bit integer attribute.
#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.
void * rtnl_tc_data(struct rtnl_tc *tc)
Return pointer to private data of traffic control object.
#define TC_CAST(ptr)
Macro to cast qdisc/class/classifier to tc 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_STATS
Dump all attributes including statistics.
@ NL_DUMP_LINE
Dump object briefly on one line.
@ NL_DUMP_DETAILS
Dump all attributes but no statistics.
Attribute validation policy.
uint16_t minlen
Minimal length of payload required.