All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2] extensions: libxt_connmark: Add translation to nft
@ 2015-12-22 20:23 Shivani Bhardwaj
  2015-12-22 20:29 ` Shivani Bhardwaj
  0 siblings, 1 reply; 2+ messages in thread
From: Shivani Bhardwaj @ 2015-12-22 20:23 UTC (permalink / raw)
  To: netfilter-devel

Add translation for connmark to nftables.

Examples:

$ sudo iptables-translate -A INPUT -m connmark --mark 10/10 -j ACCEPT
nft add rule ip filter INPUT ct mark and 0xa == 0xa counter accept

$ sudo iptables-translate -A INPUT -m connmark ! --mark 10/10 -j ACCEPT
nft add rule ip filter INPUT ct mark and 0xa != 0xa counter accept

$ sudo iptables-translate -t mangle -A PREROUTING -p tcp --dport 40 -m connmark --mark 0x40
nft add rule ip mangle PREROUTING tcp dport 40 ct mark 0x40 counter

Signed-off-by: Shivani Bhardwaj <shivanib134@gmail.com>
---
Changes in v2:
	Fix coding errors for invert test case

 extensions/libxt_connmark.c | 45 ++++++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 44 insertions(+), 1 deletion(-)

diff --git a/extensions/libxt_connmark.c b/extensions/libxt_connmark.c
index 95477de..385ed6e 100644
--- a/extensions/libxt_connmark.c
+++ b/extensions/libxt_connmark.c
@@ -89,7 +89,8 @@ connmark_print(const void *ip, const struct xt_entry_match *match, int numeric)
 }
 
 static void
-connmark_mt_print(const void *ip, const struct xt_entry_match *match, int numeric)
+connmark_mt_print(const void *ip, const struct xt_entry_match *match,
+		  int numeric)
 {
 	const struct xt_connmark_mtinfo1 *info = (const void *)match->data;
 
@@ -122,6 +123,46 @@ connmark_mt_save(const void *ip, const struct xt_entry_match *match)
 	print_mark(info->mark, info->mask);
 }
 
+static void print_mark_xlate(unsigned int mark, unsigned int mask,
+			     struct xt_buf *buf, const char *str)
+{
+	if (mask != 0xffffffffU)
+		xt_buf_add(buf, " and 0x%x %s 0x%x ", mark, str, mask);
+	else
+		xt_buf_add(buf, " 0x%x ", mark);
+}
+
+static int connmark_xlate(const struct xt_entry_match *match,
+			  struct xt_buf *buf, int numeric)
+{
+	const struct xt_connmark_info *info = (const void *)match->data;
+	const char *str = "==";
+
+	if (info->invert)
+		str = "!=";
+
+	xt_buf_add(buf, "ct mark");
+	print_mark_xlate(info->mark, info->mask, buf, str);
+
+	return 1;
+}
+
+static int
+connmark_mt_xlate(const struct xt_entry_match *match,
+		 struct xt_buf *buf, int numeric)
+{
+	const struct xt_connmark_mtinfo1 *info = (const void *)match->data;
+	const char *str = "==";
+
+	if (info->invert)
+		str = "!=";
+
+	xt_buf_add(buf, "ct mark");
+	print_mark_xlate(info->mark, info->mask, buf, str);
+
+	return 1;
+}
+
 static struct xtables_match connmark_mt_reg[] = {
 	{
 		.family        = NFPROTO_UNSPEC,
@@ -135,6 +176,7 @@ static struct xtables_match connmark_mt_reg[] = {
 		.save          = connmark_save,
 		.x6_parse      = connmark_parse,
 		.x6_options    = connmark_mt_opts,
+		.xlate	       = connmark_xlate,
 	},
 	{
 		.version       = XTABLES_VERSION,
@@ -148,6 +190,7 @@ static struct xtables_match connmark_mt_reg[] = {
 		.save          = connmark_mt_save,
 		.x6_parse      = connmark_mt_parse,
 		.x6_options    = connmark_mt_opts,
+		.xlate	       = connmark_mt_xlate,
 	},
 };
 
-- 
1.9.1


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH v2] extensions: libxt_connmark: Add translation to nft
  2015-12-22 20:23 [PATCH v2] extensions: libxt_connmark: Add translation to nft Shivani Bhardwaj
@ 2015-12-22 20:29 ` Shivani Bhardwaj
  0 siblings, 0 replies; 2+ messages in thread
From: Shivani Bhardwaj @ 2015-12-22 20:29 UTC (permalink / raw)
  To: netfilter-devel

On Wed, Dec 23, 2015 at 1:53 AM, Shivani Bhardwaj <shivanib134@gmail.com> wrote:
> Add translation for connmark to nftables.
>
> Examples:
>
> $ sudo iptables-translate -A INPUT -m connmark --mark 10/10 -j ACCEPT
> nft add rule ip filter INPUT ct mark and 0xa == 0xa counter accept
>
> $ sudo iptables-translate -A INPUT -m connmark ! --mark 10/10 -j ACCEPT
> nft add rule ip filter INPUT ct mark and 0xa != 0xa counter accept
>
> $ sudo iptables-translate -t mangle -A PREROUTING -p tcp --dport 40 -m connmark --mark 0x40
> nft add rule ip mangle PREROUTING tcp dport 40 ct mark 0x40 counter
>
> Signed-off-by: Shivani Bhardwaj <shivanib134@gmail.com>
> ---
> Changes in v2:
>         Fix coding errors for invert test case
>
>  extensions/libxt_connmark.c | 45 ++++++++++++++++++++++++++++++++++++++++++++-
>  1 file changed, 44 insertions(+), 1 deletion(-)
>
> diff --git a/extensions/libxt_connmark.c b/extensions/libxt_connmark.c
> index 95477de..385ed6e 100644
> --- a/extensions/libxt_connmark.c
> +++ b/extensions/libxt_connmark.c
> @@ -89,7 +89,8 @@ connmark_print(const void *ip, const struct xt_entry_match *match, int numeric)
>  }
>
>  static void
> -connmark_mt_print(const void *ip, const struct xt_entry_match *match, int numeric)
> +connmark_mt_print(const void *ip, const struct xt_entry_match *match,
> +                 int numeric)
>  {
>         const struct xt_connmark_mtinfo1 *info = (const void *)match->data;
>
> @@ -122,6 +123,46 @@ connmark_mt_save(const void *ip, const struct xt_entry_match *match)
>         print_mark(info->mark, info->mask);
>  }
>
> +static void print_mark_xlate(unsigned int mark, unsigned int mask,
> +                            struct xt_buf *buf, const char *str)
> +{
> +       if (mask != 0xffffffffU)
> +               xt_buf_add(buf, " and 0x%x %s 0x%x ", mark, str, mask);
> +       else
> +               xt_buf_add(buf, " 0x%x ", mark);
> +}
> +
> +static int connmark_xlate(const struct xt_entry_match *match,
> +                         struct xt_buf *buf, int numeric)
> +{
> +       const struct xt_connmark_info *info = (const void *)match->data;
> +       const char *str = "==";
> +
> +       if (info->invert)
> +               str = "!=";
> +
> +       xt_buf_add(buf, "ct mark");
> +       print_mark_xlate(info->mark, info->mask, buf, str);
> +
> +       return 1;
> +}
> +
> +static int
> +connmark_mt_xlate(const struct xt_entry_match *match,
> +                struct xt_buf *buf, int numeric)
> +{
> +       const struct xt_connmark_mtinfo1 *info = (const void *)match->data;
> +       const char *str = "==";
> +
> +       if (info->invert)
> +               str = "!=";
> +
> +       xt_buf_add(buf, "ct mark");
> +       print_mark_xlate(info->mark, info->mask, buf, str);
> +
> +       return 1;
> +}
> +
>  static struct xtables_match connmark_mt_reg[] = {
>         {
>                 .family        = NFPROTO_UNSPEC,
> @@ -135,6 +176,7 @@ static struct xtables_match connmark_mt_reg[] = {
>                 .save          = connmark_save,
>                 .x6_parse      = connmark_parse,
>                 .x6_options    = connmark_mt_opts,
> +               .xlate         = connmark_xlate,
>         },
>         {
>                 .version       = XTABLES_VERSION,
> @@ -148,6 +190,7 @@ static struct xtables_match connmark_mt_reg[] = {
>                 .save          = connmark_mt_save,
>                 .x6_parse      = connmark_mt_parse,
>                 .x6_options    = connmark_mt_opts,
> +               .xlate         = connmark_mt_xlate,
>         },
>  };
>
> --
> 1.9.1
>

Please do not consider this one. There's still a case left to be fixed.
Sorry for the inconvenience.
Sending v3.
Thank you.

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2015-12-22 20:29 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-12-22 20:23 [PATCH v2] extensions: libxt_connmark: Add translation to nft Shivani Bhardwaj
2015-12-22 20:29 ` Shivani Bhardwaj

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.