diff mbox

[PATCHv3] extensions: libip6t_frag: Add translation to nft

Message ID 20160607073309.GA9381@sonyv
State Changes Requested
Delegated to: Pablo Neira
Headers show

Commit Message

nevola June 7, 2016, 7:33 a.m. UTC
Add translation for frag to nftables. According to the --fraglen code:

	case O_FRAGLEN:
		/*
		 * As of Linux 3.0, the kernel does not check for
		 * fraglen at all.
		 */

In addition, the kernel code doesn't show any reference to the flag
IP6T_FRAG_LEN, so this option is deprecated and won't be translated to
nft.

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

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

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

Signed-off-by: Laura Garcia Liebana <nevola@gmail.com>
---
Changes in v2:
        - Include translation for fragfirst and fraglast.
        - fraglen is marked as deprecated.
Changes in v3:
	- Ignore completely IP6T_FRAG_LEN.

 extensions/libip6t_frag.c | 30 ++++++++++++++++++++++++++++++
 1 file changed, 30 insertions(+)

Comments

Pablo Neira Ayuso June 7, 2016, 10:46 a.m. UTC | #1
On Tue, Jun 07, 2016 at 09:33:13AM +0200, Laura Garcia Liebana wrote:
> diff --git a/extensions/libip6t_frag.c b/extensions/libip6t_frag.c
> index 023df62..7871fb9 100644
> --- a/extensions/libip6t_frag.c
> +++ b/extensions/libip6t_frag.c
> @@ -173,6 +173,35 @@ 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->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_FST)
> +		xt_xlate_add(xl, "frag frag-off 0 ");
> +
> +	if ((fraginfo->flags & IP6T_FRAG_MF) ||
> +	    (fraginfo->flags & IP6T_FRAG_NMF))
> +		xt_xlate_add(xl, "frag more-fragments 1 ");

I think IP6T_FRAG_NMF means no more fragments, ie. frag more-fragments 0.
While IP6T_FRAG_MF means more fragments, ie. frag more-fragments 1.

Please, review the logic that we have in the kernel module when
providing correct translations.

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

It would be also good if you test these rules from the packet path, by
generating traffic to trigger matches, not only from a control plane
perspective.

Thanks.
--
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
diff mbox

Patch

diff --git a/extensions/libip6t_frag.c b/extensions/libip6t_frag.c
index 023df62..7871fb9 100644
--- a/extensions/libip6t_frag.c
+++ b/extensions/libip6t_frag.c
@@ -173,6 +173,35 @@  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->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_FST)
+		xt_xlate_add(xl, "frag frag-off 0 ");
+
+	if ((fraginfo->flags & IP6T_FRAG_MF) ||
+	    (fraginfo->flags & IP6T_FRAG_NMF))
+		xt_xlate_add(xl, "frag more-fragments 1 ");
+
+	return 1;
+}
+
 static struct xtables_match frag_mt6_reg = {
 	.name          = "frag",
 	.version       = XTABLES_VERSION,
@@ -185,6 +214,7 @@  static struct xtables_match frag_mt6_reg = {
 	.save          = frag_save,
 	.x6_parse      = frag_parse,
 	.x6_options    = frag_opts,
+	.xlate	       = frag_xlate,
 };
 
 void