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>
21static 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 },
28static 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;
60static void skbedit_free_data(
struct rtnl_tc *tc,
void *data)
64static 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){
103static void skbedit_dump_details(
struct rtnl_tc *tc,
void *data,
108static void skbedit_dump_stats(
struct rtnl_tc *tc,
void *data,
111 struct rtnl_skbedit *u = data;
119static 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);
148int rtnl_skbedit_set_action(
struct rtnl_act *act,
int action)
150 struct rtnl_skbedit *u;
155 u->s_parm.action = action;
160int rtnl_skbedit_get_action(
struct rtnl_act *act)
162 struct rtnl_skbedit *u;
166 return u->s_parm.action;
169int rtnl_skbedit_set_queue_mapping(
struct rtnl_act *act, uint16_t index)
171 struct rtnl_skbedit *u;
176 u->s_queue_mapping = index;
177 u->s_flags |= SKBEDIT_F_QUEUE_MAPPING;
181int rtnl_skbedit_get_queue_mapping(
struct rtnl_act *act, uint16_t *index)
183 struct rtnl_skbedit *u;
188 if (!(u->s_flags & SKBEDIT_F_QUEUE_MAPPING))
191 *index = u->s_queue_mapping;
195int rtnl_skbedit_set_mark(
struct rtnl_act *act, uint32_t mark)
197 struct rtnl_skbedit *u;
203 u->s_flags |= SKBEDIT_F_MARK;
207int rtnl_skbedit_get_mark(
struct rtnl_act *act, uint32_t *mark)
209 struct rtnl_skbedit *u;
214 if (!(u->s_flags & SKBEDIT_F_MARK))
221int rtnl_skbedit_set_priority(
struct rtnl_act *act, uint32_t prio)
223 struct rtnl_skbedit *u;
229 u->s_flags |= SKBEDIT_F_PRIORITY;
233int rtnl_skbedit_get_priority(
struct rtnl_act *act, uint32_t *prio)
235 struct rtnl_skbedit *u;
240 if (!(u->s_flags & SKBEDIT_F_PRIORITY))
249static struct rtnl_tc_ops skbedit_ops = {
250 .to_kind =
"skbedit",
251 .to_type = RTNL_TC_TYPE_ACT,
252 .to_size =
sizeof(
struct rtnl_skbedit),
253 .to_msg_parser = skbedit_msg_parser,
254 .to_free_data = skbedit_free_data,
256 .to_msg_fill = skbedit_msg_fill,
264static void __init skbedit_init(
void)
269static 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.
#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_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.