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/nat.h>
20#include <netlink/route/tc.h>
22static struct nla_policy nat_policy[TCA_NAT_MAX + 1] = {
23 [TCA_NAT_PARMS] = { .
minlen =
sizeof(
struct tc_nat) },
30static int nat_msg_parser(
struct rtnl_tc *tc,
void *data)
32 struct tc_nat *nat = data;
33 struct nlattr *tb[TCA_NAT_MAX + 1];
36 err = tca_parse(tb, TCA_NAT_MAX, tc, nat_policy);
40 if (!tb[TCA_NAT_PARMS])
41 return -NLE_MISSING_ATTR;
43 nla_memcpy(nat, tb[TCA_NAT_PARMS],
sizeof(*nat));
48static void nat_free_data(
struct rtnl_tc *tc,
void *data)
52static int nat_msg_fill(
struct rtnl_tc *tc,
void *data,
struct nl_msg *msg)
54 struct tc_nat *nat = data;
57 return -NLE_OBJ_NOTFOUND;
59 NLA_PUT(msg, TCA_NAT_PARMS,
sizeof(*nat), nat);
67static void nat_dump_line(
struct rtnl_tc *tc,
void *data,
70 struct tc_nat *nat = data;
78 if (nat->flags & TCA_NAT_FLAG_EGRESS)
89 inet_ntop(AF_INET, &nat->old_addr, buf,
sizeof(buf));
94 inet_ntop(AF_INET, &nat->new_addr, buf,
sizeof(buf));
119 nat->old_addr = addr;
124int rtnl_nat_get_old_addr(
struct rtnl_act *act, in_addr_t *addr)
131 *addr = nat->old_addr;
150 nat->new_addr = addr;
155int rtnl_nat_get_new_addr(
struct rtnl_act *act, in_addr_t *addr)
162 *addr = nat->new_addr;
186int rtnl_nat_get_mask(
struct rtnl_act *act, in_addr_t *bitmask)
193 *bitmask = nat->mask;
220int rtnl_nat_get_flags(
struct rtnl_act *act, uint32_t *flags)
232int rtnl_nat_set_action(
struct rtnl_act *act,
int action)
239 if (action < TC_ACT_UNSPEC)
242 nat->action = action;
247int rtnl_nat_get_action(
struct rtnl_act *act,
int *action)
254 *action = nat->action;
263static struct rtnl_tc_ops nat_ops = {
265 .to_type = RTNL_TC_TYPE_ACT,
266 .to_size =
sizeof(
struct tc_nat),
267 .to_msg_parser = nat_msg_parser,
268 .to_free_data = nat_free_data,
270 .to_msg_fill = nat_msg_fill,
276static void __init nat_init(
void)
281static void __exit nat_exit(
void)
int rtnl_nat_set_new_addr(struct rtnl_act *act, in_addr_t addr)
Set new IPv4 address on a netlink NAT action object.
int rtnl_nat_set_flags(struct rtnl_act *act, uint32_t flags)
Set flags for a netlink NAT action object.
int rtnl_nat_set_old_addr(struct rtnl_act *act, in_addr_t addr)
Set old IPv4 address on a netlink NAT action object.
int rtnl_nat_set_mask(struct rtnl_act *act, in_addr_t bitmask)
Set IPv4 address mask on a netlink NAT action object.
#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.
void * rtnl_tc_data_peek(struct rtnl_tc *tc)
Returns the private data of the traffic control object.
#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_LINE
Dump object briefly on one line.
Attribute validation policy.
uint16_t minlen
Minimal length of payload required.