13#include "nl-default.h"
15#include <netlink/netlink.h>
16#include <netlink/attr.h>
17#include <netlink/utils.h>
18#include <netlink/route/act/skbedit.h>
24 struct tc_skbedit s_parm;
28 uint16_t s_queue_mapping;
33 [TCA_SKBEDIT_PRIORITY] = { .type =
NLA_U32 },
34 [TCA_SKBEDIT_QUEUE_MAPPING] = { .type =
NLA_U16 },
35 [TCA_SKBEDIT_MARK] = { .type =
NLA_U32 },
38static int skbedit_msg_parser(
struct rtnl_tc *tc,
void *data)
41 struct nlattr *tb[TCA_SKBEDIT_MAX + 1];
44 err = tca_parse(tb, TCA_SKBEDIT_MAX, tc, skbedit_policy);
48 if (!tb[TCA_SKBEDIT_PARMS])
49 return -NLE_MISSING_ATTR;
52 if (tb[TCA_SKBEDIT_PRIORITY] != NULL) {
53 u->s_flags |= SKBEDIT_F_PRIORITY;
57 if (tb[TCA_SKBEDIT_QUEUE_MAPPING] != NULL) {
58 u->s_flags |= SKBEDIT_F_QUEUE_MAPPING;
59 u->s_queue_mapping =
nla_get_u16(tb[TCA_SKBEDIT_QUEUE_MAPPING]);
62 if (tb[TCA_SKBEDIT_MARK] != NULL) {
63 u->s_flags |= SKBEDIT_F_MARK;
70static void skbedit_free_data(
struct rtnl_tc *tc,
void *data)
74static void skbedit_dump_line(
struct rtnl_tc *tc,
void *data,
82 if (u->s_flags & SKBEDIT_F_PRIORITY)
83 nl_dump(p,
" priority %u", u->s_prio);
85 if (u->s_flags & SKBEDIT_F_MARK)
86 nl_dump(p,
" mark %u", u->s_mark);
88 if (u->s_flags & SKBEDIT_F_QUEUE_MAPPING)
89 nl_dump(p,
" queue_mapping %u", u->s_queue_mapping);
91 switch(u->s_parm.action){
113static void skbedit_dump_details(
struct rtnl_tc *tc,
void *data,
118static void skbedit_dump_stats(
struct rtnl_tc *tc,
void *data,
129static int skbedit_msg_fill(
struct rtnl_tc *tc,
void *data,
struct nl_msg *msg)
136 NLA_PUT(msg, TCA_SKBEDIT_PARMS,
sizeof(u->s_parm), &u->s_parm);
138 if (u->s_flags & SKBEDIT_F_MARK)
141 if (u->s_flags & SKBEDIT_F_PRIORITY)
144 if (u->s_flags & SKBEDIT_F_QUEUE_MAPPING)
145 NLA_PUT_U32(msg, TCA_SKBEDIT_QUEUE_MAPPING, u->s_queue_mapping);
158int rtnl_skbedit_set_action(
struct rtnl_act *act,
int action)
165 u->s_parm.action = action;
170int rtnl_skbedit_get_action(
struct rtnl_act *act)
176 return u->s_parm.action;
179int rtnl_skbedit_set_queue_mapping(
struct rtnl_act *act, uint16_t index)
186 u->s_queue_mapping = index;
187 u->s_flags |= SKBEDIT_F_QUEUE_MAPPING;
191int rtnl_skbedit_get_queue_mapping(
struct rtnl_act *act, uint16_t *index)
198 if (!(u->s_flags & SKBEDIT_F_QUEUE_MAPPING))
201 *index = u->s_queue_mapping;
205int rtnl_skbedit_set_mark(
struct rtnl_act *act, uint32_t mark)
213 u->s_flags |= SKBEDIT_F_MARK;
217int rtnl_skbedit_get_mark(
struct rtnl_act *act, uint32_t *mark)
224 if (!(u->s_flags & SKBEDIT_F_MARK))
231int rtnl_skbedit_set_priority(
struct rtnl_act *act, uint32_t prio)
239 u->s_flags |= SKBEDIT_F_PRIORITY;
243int rtnl_skbedit_get_priority(
struct rtnl_act *act, uint32_t *prio)
250 if (!(u->s_flags & SKBEDIT_F_PRIORITY))
259static struct rtnl_tc_ops skbedit_ops = {
260 .to_kind =
"skbedit",
261 .to_type = RTNL_TC_TYPE_ACT,
263 .to_msg_parser = skbedit_msg_parser,
264 .to_free_data = skbedit_free_data,
266 .to_msg_fill = skbedit_msg_fill,
274static void _nl_init skbedit_init(
void)
279static void _nl_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 *)
Return pointer to private data of traffic control object.
int rtnl_tc_register(struct rtnl_tc_ops *)
Register a traffic control module.
void rtnl_tc_unregister(struct rtnl_tc_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.
uint16_t type
Type of attribute or NLA_UNSPEC.