* [PATCH] extensions: libip6t_DNAT: Add translation to nft
@ 2015-12-30 8:41 Shivani Bhardwaj
2016-01-03 20:14 ` Pablo Neira Ayuso
0 siblings, 1 reply; 2+ messages in thread
From: Shivani Bhardwaj @ 2015-12-30 8:41 UTC (permalink / raw)
To: netfilter-devel
Add translation for target DNAT to nftables.
Examples:
$ sudo ip6tables-translate -t nat -A prerouting -i eth1 -p tcp --dport 8080 -j DNAT --to-destination [fec0::1234]:80
nft add rule ip6 nat prerouting iifname eth1 tcp dport 8080 counter dnat fec0::1234 :80
$ sudo ip6tables-translate -t nat -A prerouting -p tcp -j DNAT --to-destination [fec0::1234]:1-20
nft add rule ip6 nat prerouting ip6 nexthdr tcp counter dnat fec0::1234 :1-20
$ sudo ip6tables-translate -t nat -A prerouting -p tcp -j DNAT --to-destination [fec0::1234]:80 --persistent
nft add rule ip6 nat prerouting ip6 nexthdr tcp counter dnat fec0::1234 :80 persistent
$ sudo ip6tables-translate -t nat -A prerouting -p tcp -j DNAT --to-destination [fec0::1234]:80 --random --persistent
nft add rule ip6 nat prerouting ip6 nexthdr tcp counter dnat fec0::1234 :80 random,persistent
Signed-off-by: Shivani Bhardwaj <shivanib134@gmail.com>
---
extensions/libip6t_DNAT.c | 44 ++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 44 insertions(+)
diff --git a/extensions/libip6t_DNAT.c b/extensions/libip6t_DNAT.c
index eaa6bf1..3959755 100644
--- a/extensions/libip6t_DNAT.c
+++ b/extensions/libip6t_DNAT.c
@@ -231,6 +231,49 @@ static void DNAT_save(const void *ip, const struct xt_entry_target *target)
printf(" --persistent");
}
+static void print_range_xlate(const struct nf_nat_range *range,
+ struct xt_buf *buf)
+{
+ if (range->flags & NF_NAT_RANGE_MAP_IPS) {
+ xt_buf_add(buf, "%s",
+ xtables_ip6addr_to_numeric(&range->min_addr.in6));
+
+ if (memcmp(&range->min_addr, &range->max_addr,
+ sizeof(range->min_addr)))
+ xt_buf_add(buf, "-%s",
+ xtables_ip6addr_to_numeric(&range->max_addr.in6));
+ }
+ if (range->flags & NF_NAT_RANGE_PROTO_SPECIFIED) {
+ xt_buf_add(buf, " :%hu", ntohs(range->min_proto.tcp.port));
+
+ if (range->max_proto.tcp.port != range->min_proto.tcp.port)
+ xt_buf_add(buf, "-%hu",
+ ntohs(range->max_proto.tcp.port));
+ }
+}
+
+static int DNAT_xlate(const struct xt_entry_target *target,
+ struct xt_buf *buf, int numeric)
+{
+ const struct nf_nat_range *range = (const void *)target->data;
+ bool sep_need = false;
+ const char *sep = " ";
+
+ xt_buf_add(buf, "dnat ");
+ print_range_xlate(range, buf);
+ if (range->flags & NF_NAT_RANGE_PROTO_RANDOM) {
+ xt_buf_add(buf, " random");
+ sep_need = true;
+ }
+ if (range->flags & NF_NAT_RANGE_PERSISTENT) {
+ if (sep_need)
+ sep = ",";
+ xt_buf_add(buf, "%spersistent", sep);
+ }
+
+ return 1;
+}
+
static struct xtables_target snat_tg_reg = {
.name = "DNAT",
.version = XTABLES_VERSION,
@@ -244,6 +287,7 @@ static struct xtables_target snat_tg_reg = {
.print = DNAT_print,
.save = DNAT_save,
.x6_options = DNAT_opts,
+ .xlate = DNAT_xlate,
};
void _init(void)
--
1.9.1
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] extensions: libip6t_DNAT: Add translation to nft
2015-12-30 8:41 [PATCH] extensions: libip6t_DNAT: Add translation to nft Shivani Bhardwaj
@ 2016-01-03 20:14 ` Pablo Neira Ayuso
0 siblings, 0 replies; 2+ messages in thread
From: Pablo Neira Ayuso @ 2016-01-03 20:14 UTC (permalink / raw)
To: Shivani Bhardwaj; +Cc: netfilter-devel
On Wed, Dec 30, 2015 at 02:11:26PM +0530, Shivani Bhardwaj wrote:
> Add translation for target DNAT to nftables.
Applied, thanks.
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2016-01-03 20:15 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-12-30 8:41 [PATCH] extensions: libip6t_DNAT: Add translation to nft Shivani Bhardwaj
2016-01-03 20:14 ` Pablo Neira Ayuso
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).