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/mirred.h>
21static struct nla_policy mirred_policy[TCA_MIRRED_MAX + 1] = {
22 [TCA_MIRRED_PARMS] = { .
minlen =
sizeof(
struct tc_mirred) },
25static int mirred_msg_parser(
struct rtnl_tc *tc,
void *data)
27 struct rtnl_mirred *u = data;
28 struct nlattr *tb[TCA_MIRRED_MAX + 1];
31 err = tca_parse(tb, TCA_MIRRED_MAX, tc, mirred_policy);
35 if (!tb[TCA_MIRRED_PARMS])
36 return -NLE_MISSING_ATTR;
38 nla_memcpy(&u->m_parm, tb[TCA_MIRRED_PARMS],
sizeof(u->m_parm));
42static void mirred_free_data(
struct rtnl_tc *tc,
void *data)
46static void mirred_dump_line(
struct rtnl_tc *tc,
void *data,
49 struct rtnl_mirred *u = data;
53 nl_dump(p,
" index %u", u->m_parm.ifindex);
55 if (u->m_parm.eaction == TCA_EGRESS_MIRROR)
57 else if (u->m_parm.eaction == TCA_EGRESS_REDIR)
60 switch(u->m_parm.action) {
82static void mirred_dump_details(
struct rtnl_tc *tc,
void *data,
87static void mirred_dump_stats(
struct rtnl_tc *tc,
void *data,
90 struct rtnl_mirred *u = data;
98static int mirred_msg_fill(
struct rtnl_tc *tc,
void *data,
struct nl_msg *msg)
100 struct rtnl_mirred *u = data;
105 NLA_PUT(msg, TCA_MIRRED_PARMS,
sizeof(u->m_parm), &u->m_parm);
117int rtnl_mirred_set_action(
struct rtnl_act *act,
int action)
119 struct rtnl_mirred *u;
124 if (action > TCA_INGRESS_MIRROR || action < TCA_EGRESS_REDIR)
128 case TCA_EGRESS_MIRROR:
129 case TCA_EGRESS_REDIR:
130 u->m_parm.eaction = action;
132 case TCA_INGRESS_REDIR:
133 case TCA_INGRESS_MIRROR:
135 return NLE_OPNOTSUPP;
140int rtnl_mirred_get_action(
struct rtnl_act *act)
142 struct rtnl_mirred *u;
146 return u->m_parm.eaction;
149int rtnl_mirred_set_ifindex(
struct rtnl_act *act, uint32_t ifindex)
151 struct rtnl_mirred *u;
156 u->m_parm.ifindex = ifindex;
160uint32_t rtnl_mirred_get_ifindex(
struct rtnl_act *act)
162 struct rtnl_mirred *u;
165 return u->m_parm.ifindex;
169int rtnl_mirred_set_policy(
struct rtnl_act *act,
int policy)
171 struct rtnl_mirred *u;
176 u->m_parm.action = policy;
181int rtnl_mirred_get_policy(
struct rtnl_act *act)
183 struct rtnl_mirred *u;
187 return u->m_parm.action;
192static struct rtnl_tc_ops mirred_ops = {
194 .to_type = RTNL_TC_TYPE_ACT,
195 .to_size =
sizeof(
struct rtnl_mirred),
196 .to_msg_parser = mirred_msg_parser,
197 .to_free_data = mirred_free_data,
199 .to_msg_fill = mirred_msg_fill,
207static void __init mirred_init(
void)
212static void __exit mirred_exit(
void)
#define NLA_PUT(msg, attrtype, attrlen, data)
Add unspecific attribute to netlink message.
int nla_memcpy(void *dest, const struct nlattr *src, int count)
Copy attribute payload to another memory area.
#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.