Skip to contentSkip to conversation

extensions: libxt_mark: Add translation to nft

PATCH Superseded Shivani Bhardwaj 2 participants 5 messages Dec 5, 2015 – Dec 6, 2015 netfilter

v1 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

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

Add translation of the metainformation mark to nft.

---
 extensions/libxt_mark.c | 60 +++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 60 insertions(+)
extensions/libxt_mark.c +60 -0
index 7f8c995..5105bf9 100644
@@ -102,6 +102,64 @@ mark_save(const void *ip, const struct xt_entry_match *match)
 	print_mark(info->mark, info->mask);
 }
 
+static void
+print_mark_xlate(struct xt_buf *buf,
+		 unsigned int mark, unsigned int mask)
+{
+        if (mask != 0xffffffffU)
+                xt_buf_add(buf, " 0x%x/0x%x", mark, mask);
+        else
+                xt_buf_add(buf, " 0x%x", mark);
+}
+
+static void
+mark_mt_xlate_print(const struct xt_entry_match *match,
+		    struct xt_buf *buf, int numeric)
+{
+	const struct xt_mark_mtinfo1 *info = (const void *)match->data;
+
+	if (info->invert)      
+		xt_buf_add(buf, " !");
+	print_mark_xlate(buf, info->mark, info->mask);
+}
+
+static int
+mark_mt_xlate(const struct xt_entry_match *match,
+	      struct xt_buf *buf, int numeric)
+{
+	const struct xt_mark_mtinfo1 *info = (const void *)match->data;
+
+        xt_buf_add(buf, "ct mark %s", info->invert ? " !" : "");
+        print_mark_xlate(buf, info->mark, info->mask);
+        xt_buf_add(buf, " ");
+
+        return 1;
+}
+
+static void
+mark_xlate_print(const struct xt_entry_match *match,
+		 struct xt_buf *buf, int numeric)
+{
+       const struct xt_mark_info *info = (const void *)match->data;
+
+        if (info->invert)
+                xt_buf_add(buf, " !");
+        print_mark_xlate(buf, info->mark, info->mask);
+}
+
+static int
+mark_xlate(const struct xt_entry_match *match,
+	   struct xt_buf *buf, int numeric)
+{
+	const struct xt_mark_info *info = (const void *)match->data;
+
+	xt_buf_add(buf, "ct mark %s", info->invert ? " !" : "");
+	print_mark_xlate(buf, info->mark, info->mask);
+	xt_buf_add(buf, " ");
+
+	return 1;
+}
+
 static struct xtables_match mark_mt_reg[] = {
 	{
 		.family        = NFPROTO_UNSPEC,
@@ -115,6 +173,7 @@ static struct xtables_match mark_mt_reg[] = {
 		.save          = mark_save,
 		.x6_parse      = mark_parse,
 		.x6_options    = mark_mt_opts,
+		.xlate	       = mark_xlate,
 	},
 	{
 		.version       = XTABLES_VERSION,
@@ -128,6 +187,7 @@ static struct xtables_match mark_mt_reg[] = {
 		.save          = mark_mt_save,
 		.x6_parse      = mark_mt_parse,
 		.x6_options    = mark_mt_opts,
+		.xlate         = mark_mt_xlate,
 	},
 };
 
Signature · 1 line
1.9.1
#1 lore raw

Hi Shivani,

Quoted 12 lines · Shivani Bhardwaj

Add translation of the metainformation mark to nft.

---
 extensions/libxt_mark.c | 60 +++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 60 insertions(+)
extensions/libxt_mark.c +0 -0
index 7f8c995..5105bf9 100644

extensions/libxt_mark.c mark_save(const void *ip, const struct xt_entry_match *match) · line 110

Quoted 9 lines
extensions/libxt_mark.c +6 -0
@@ -102,6 +102,64 @@ mark_save(const void *ip, const struct xt_entry_match *match)
 	print_mark(info->mark, info->mask);
 }
 
+static void
+print_mark_xlate(struct xt_buf *buf,
+		 unsigned int mark, unsigned int mask)
+{
+        if (mask != 0xffffffffU)
+                xt_buf_add(buf, " 0x%x/0x%x", mark, mask);

In nftables this should be translated to &.

extensions/libxt_mark.c mark_save(const void *ip, const struct xt_entry_match *match) · line 121

Quoted 11 lines
extensions/libxt_mark.c +11 -0
+        else
+                xt_buf_add(buf, " 0x%x", mark);
+}
+
+static void
+mark_mt_xlate_print(const struct xt_entry_match *match,
+		    struct xt_buf *buf, int numeric)
+{
+	const struct xt_mark_mtinfo1 *info = (const void *)match->data;
+
+	if (info->invert)      
                         ^^^^^^

There is a tab that is not needed there. Update your editor configuration to highlight unnecessary spaces before line break,

extensions/libxt_mark.c mark_save(const void *ip, const struct xt_entry_match *match) · line 132

Quoted 11 lines
extensions/libxt_mark.c +11 -0
+		xt_buf_add(buf, " !");
+	print_mark_xlate(buf, info->mark, info->mask);
+}
+
+static int
+mark_mt_xlate(const struct xt_entry_match *match,
+	      struct xt_buf *buf, int numeric)
+{
+	const struct xt_mark_mtinfo1 *info = (const void *)match->data;
+
+        xt_buf_add(buf, "ct mark %s", info->invert ? " !" : "");

Invert in nft is '!='.

Please, make sure that the suggested translation actually works in nft.

But overall this looks good like a good start.

#2 lore raw
Quoted 18 lines · Pablo Neira Ayuso

Hi Shivani,

Quoted 15 lines · Shivani Bhardwaj

Add translation of the metainformation mark to nft.

---
 extensions/libxt_mark.c | 60 +++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 60 insertions(+)
extensions/libxt_mark.c +0 -0
index 7f8c995..5105bf9 100644
@@ -102,6 +102,64 @@ mark_save(const void *ip, const struct xt_entry_match *match)
      print_mark(info->mark, info->mask);
 }
 
Quoted 9 lines

extensions/libxt_mark.c mark_save(const void *ip, const struct xt_entry_match *match) · line 110

Quoted 6 lines
extensions/libxt_mark.c +6 -0
+static void
+print_mark_xlate(struct xt_buf *buf,
+              unsigned int mark, unsigned int mask)
+{
+        if (mask != 0xffffffffU)
+                xt_buf_add(buf, " 0x%x/0x%x", mark, mask);

In nftables this should be translated to &.

Do you mean this?

if (mask & 0xffffffffU)

Quoted 12 lines

extensions/libxt_mark.c mark_save(const void *ip, const struct xt_entry_match *match) · line 121

Quoted 11 lines
extensions/libxt_mark.c +11 -0
+        else
+                xt_buf_add(buf, " 0x%x", mark);
+}
+
+static void
+mark_mt_xlate_print(const struct xt_entry_match *match,
+                 struct xt_buf *buf, int numeric)
+{
+     const struct xt_mark_mtinfo1 *info = (const void *)match->data;
+
+     if (info->invert)
                         ^^^^^^
Quoted 3 lines

There is a tab that is not needed there. Update your editor configuration to highlight unnecessary spaces before line break,

Done.

Quoted 14 lines

extensions/libxt_mark.c mark_save(const void *ip, const struct xt_entry_match *match) · line 132

Quoted 11 lines
extensions/libxt_mark.c +11 -0
+             xt_buf_add(buf, " !");
+     print_mark_xlate(buf, info->mark, info->mask);
+}
+
+static int
+mark_mt_xlate(const struct xt_entry_match *match,
+           struct xt_buf *buf, int numeric)
+{
+     const struct xt_mark_mtinfo1 *info = (const void *)match->data;
+
+        xt_buf_add(buf, "ct mark %s", info->invert ? " !" : "");

Invert in nft is '!='.

Quoted 4 lines

Please, make sure that the suggested translation actually works in nft.

But overall this looks good like a good start.

Thank you. I'll be sending version 2.

#3 lore raw
In reply to Pablo Neira Ayuso
Quoted 18 lines · Pablo Neira Ayuso

Hi Shivani,

Quoted 15 lines · Shivani Bhardwaj

Add translation of the metainformation mark to nft.

---
 extensions/libxt_mark.c | 60 +++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 60 insertions(+)
extensions/libxt_mark.c +0 -0
index 7f8c995..5105bf9 100644
@@ -102,6 +102,64 @@ mark_save(const void *ip, const struct xt_entry_match *match)
 	print_mark(info->mark, info->mask);
 }
 
Quoted 8 lines

extensions/libxt_mark.c mark_save(const void *ip, const struct xt_entry_match *match) · line 110

Quoted 6 lines
extensions/libxt_mark.c +6 -0
+static void
+print_mark_xlate(struct xt_buf *buf,
+		 unsigned int mark, unsigned int mask)
+{
+        if (mask != 0xffffffffU)
+                xt_buf_add(buf, " 0x%x/0x%x", mark, mask);

In nftables this should be translated to &.

I mean:

        xt_buf_add(buf, " & x%x == x%x", mask, mark);
#4 lore raw
Quoted 28 lines · Pablo Neira Ayuso
Quoted 18 lines · Pablo Neira Ayuso

Hi Shivani,

Quoted 15 lines · Shivani Bhardwaj

Add translation of the metainformation mark to nft.

---
 extensions/libxt_mark.c | 60 +++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 60 insertions(+)
extensions/libxt_mark.c +0 -0
index 7f8c995..5105bf9 100644
@@ -102,6 +102,64 @@ mark_save(const void *ip, const struct xt_entry_match *match)
    print_mark(info->mark, info->mask);
 }
 
Quoted 8 lines

extensions/libxt_mark.c mark_save(const void *ip, const struct xt_entry_match *match) · line 110

Quoted 6 lines
extensions/libxt_mark.c +6 -0
+static void
+print_mark_xlate(struct xt_buf *buf,
+            unsigned int mark, unsigned int mask)
+{
+        if (mask != 0xffffffffU)
+                xt_buf_add(buf, " 0x%x/0x%x", mark, mask);

In nftables this should be translated to &.

Quoted 2 lines

I mean:

        xt_buf_add(buf, " & x%x == x%x", mask, mark);

OK. I'm sending version 2. Please check it.

Thank you