extensions: libip6t_frag: Add translation to nft
diff mbox

Message ID 20160602165756.GA21013@sonyv
State Changes Requested
Delegated to: Pablo Neira
Headers show

Commit Message

Laura Garcia Liebana June 2, 2016, 4:57 p.m. UTC
Add translation for frag to nftables. Not supported yet in nft: fraglen,
fragfirst and fraglast.

Examples:

$ sudo iptables-translate -t filter -A INPUT -m frag --fragid 100:200 -j ACCEPT
nft add rule ip6 filter INPUT frag id 100-200 counter accept

$ sudo iptables-translate -t filter -A INPUT -m frag --fragid 100 --fragres --fragmore -j ACCEPT
nft add rule ip6 filter INPUT frag id 100 frag reserved 1 frag
more-fragments 1 counter accept

$ sudo iptables-translate -t filter -A INPUT -m frag ! --fragid 100:200 -j ACCEPT
nft add rule ip6 filter INPUT frag id != 100-200 counter accept

Signed-off-by: Laura Garcia Liebana <nevola@gmail.com>
---
 extensions/libip6t_frag.c | 31 +++++++++++++++++++++++++++++++
 1 file changed, 31 insertions(+)

Comments

Pablo Neira Ayuso June 6, 2016, 11:35 a.m. UTC | #1
On Thu, Jun 02, 2016 at 06:57:58PM +0200, Laura Garcia Liebana wrote:
> Add translation for frag to nftables. Not supported yet in nft: fraglen,
> fragfirst and fraglast.

You can provide translations for fragfirst and fraglast.

'--fragfirst' is actually frag-off 0.
and '--fraglast' is more-fragments 1.

Note that because there is no 1:1 mapping, it doesn't mean you can
translate things.

And regarding --fraglen, if you look at
iptables/extensions/libip6t_frag.c, you'll see:

        case O_FRAGLEN:
                /*
                 * As of Linux 3.0, the kernel does not check for
                 * fraglen at all.
                 */
                if (cb->invert)
                        fraginfo->invflags |= IP6T_FRAG_INV_LEN;
                fraginfo->flags |= IP6T_FRAG_LEN;
                break;

Then, browsing:

http://lxr.free-electrons.com/source/net/ipv6/netfilter/ip6t_frag.c

shows no references to IP6T_FRAG_LEN in the kernel, so this confirms
this option was already deprecated time ago and the comment in the
iptables source code is correct.

Please, respin and send a v2 including this useful information on the
commit message so we keep this in the record.
--
To unsubscribe from this list: send the line "unsubscribe netfilter-devel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Patch
diff mbox

diff --git a/extensions/libip6t_frag.c b/extensions/libip6t_frag.c
index 023df62..00ba00f 100644
--- a/extensions/libip6t_frag.c
+++ b/extensions/libip6t_frag.c
@@ -173,6 +173,36 @@  static void frag_save(const void *ip, const struct xt_entry_match *match)
 		printf(" --fraglast");
 }
 
+static int frag_xlate(const void *ip, const struct xt_entry_match *match,
+		      struct xt_xlate *xl, int numeric)
+{
+	const struct ip6t_frag *fraginfo = (struct ip6t_frag *)match->data;
+
+	if ((fraginfo->flags & IP6T_FRAG_LEN) ||
+	    (fraginfo->flags & IP6T_FRAG_FST) ||
+	    (fraginfo->flags & IP6T_FRAG_NMF)) {
+		return 0;
+	}
+
+	if (!(fraginfo->ids[0] == 0 && fraginfo->ids[1] == 0xFFFFFFFF)) {
+		xt_xlate_add(xl, "frag id %s",
+			(fraginfo->invflags & IP6T_FRAG_INV_IDS) ? "!= " : "");
+		if (fraginfo->ids[0] != fraginfo->ids[1])
+			xt_xlate_add(xl, "%u-%u ", fraginfo->ids[0],
+				     fraginfo->ids[1]);
+		else
+			xt_xlate_add(xl, "%u ", fraginfo->ids[0]);
+	}
+
+	if (fraginfo->flags & IP6T_FRAG_RES)
+		xt_xlate_add(xl, "frag reserved 1 ");
+
+	if (fraginfo->flags & IP6T_FRAG_MF)
+		xt_xlate_add(xl, "frag more-fragments 1 ");
+
+	return 1;
+}
+
 static struct xtables_match frag_mt6_reg = {
 	.name          = "frag",
 	.version       = XTABLES_VERSION,
@@ -185,6 +215,7 @@  static struct xtables_match frag_mt6_reg = {
 	.save          = frag_save,
 	.x6_parse      = frag_parse,
 	.x6_options    = frag_opts,
+	.xlate	       = frag_xlate,
 };
 
 void