Skip to contentSkip to conversation

extensions: libxt_helper: Add translation to nft

PATCH Superseded Shivani Bhardwaj 2 participants 3 messages Dec 23, 2015 netfilter

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 extensions: libxt_helper: Add translation to nft

Add translation for helper module to nftables.

Examples:

$ sudo iptables-translate -A FORWARD -m helper --helper sip
nft add rule ip filter FORWARD ct helper \"sip\" counter
$ sudo iptables-translate -A FORWARD -m helper ! --helper ftp
nft add rule ip filter FORWARD ct helper != \"ftp\" counter
---
 extensions/libxt_helper.c | 14 ++++++++++++++
 1 file changed, 14 insertions(+)
extensions/libxt_helper.c +14 -0
index c9f9435..5f1d8b1 100644
@@ -45,6 +45,19 @@ static void helper_save(const void *ip, const struct xt_entry_match *match)
 	xtables_save_string(info->name);
 }
 
+static int helper_xlate(const struct xt_entry_match *match,
+			struct xt_buf *buf, int numeric)
+{
+	const struct xt_helper_info *info = (const void *)match->data;
+
+	xt_buf_add(buf, "ct helper");
+
+	xt_buf_add(buf, "%s \\\"%s\\\" ",
+		   info->invert ? " !=" : "", info->name);
+
+	return 1;
+}
+
 static struct xtables_match helper_match = {
 	.family		= NFPROTO_UNSPEC,
 	.name		= "helper",
@@ -55,6 +68,7 @@ static struct xtables_match helper_match = {
 	.save		= helper_save,
 	.x6_parse	= helper_parse,
 	.x6_options	= helper_opts,
+	.xlate		= helper_xlate,
 };
 
 void _init(void)
Signature · 1 line
1.9.1
#1 lore raw
Quoted 22 lines · Shivani Bhardwaj

Add translation for helper module to nftables.

Examples:

$ sudo iptables-translate -A FORWARD -m helper --helper sip
nft add rule ip filter FORWARD ct helper \"sip\" counter
$ sudo iptables-translate -A FORWARD -m helper ! --helper ftp
nft add rule ip filter FORWARD ct helper != \"ftp\" counter
---
 extensions/libxt_helper.c | 14 ++++++++++++++
 1 file changed, 14 insertions(+)
extensions/libxt_helper.c +0 -0
index c9f9435..5f1d8b1 100644
@@ -45,6 +45,19 @@ static void helper_save(const void *ip, const struct xt_entry_match *match)
 	xtables_save_string(info->name);
 }

extensions/libxt_helper.c static void helper_save(const void *ip, const struct xt_entry_match *match) · line 56

Quoted 10 lines
extensions/libxt_helper.c +9 -0
 
+static int helper_xlate(const struct xt_entry_match *match,
+			struct xt_buf *buf, int numeric)
+{
+	const struct xt_helper_info *info = (const void *)match->data;
+
+	xt_buf_add(buf, "ct helper");
+
+	xt_buf_add(buf, "%s \\\"%s\\\" ",
+		   info->invert ? " !=" : "", info->name);

You can place this in one single call of xt_buf_add(), right?

#2 lore raw
Quoted 24 lines · Pablo Neira Ayuso
Quoted 23 lines · Shivani Bhardwaj

Add translation for helper module to nftables.

Examples:

$ sudo iptables-translate -A FORWARD -m helper --helper sip
nft add rule ip filter FORWARD ct helper \"sip\" counter
$ sudo iptables-translate -A FORWARD -m helper ! --helper ftp
nft add rule ip filter FORWARD ct helper != \"ftp\" counter
---
 extensions/libxt_helper.c | 14 ++++++++++++++
 1 file changed, 14 insertions(+)
extensions/libxt_helper.c +0 -0
index c9f9435..5f1d8b1 100644
@@ -45,6 +45,19 @@ static void helper_save(const void *ip, const struct xt_entry_match *match)
      xtables_save_string(info->name);
 }
 
Quoted 11 lines

extensions/libxt_helper.c static void helper_save(const void *ip, const struct xt_entry_match *match) · line 56

Quoted 9 lines
extensions/libxt_helper.c +9 -0
+static int helper_xlate(const struct xt_entry_match *match,
+                     struct xt_buf *buf, int numeric)
+{
+     const struct xt_helper_info *info = (const void *)match->data;
+
+     xt_buf_add(buf, "ct helper");
+
+     xt_buf_add(buf, "%s \\\"%s\\\" ",
+                info->invert ? " !=" : "", info->name);

You can place this in one single call of xt_buf_add(), right?

Sending v2.
Thank you