laurenceman / rpms / iptables

Forked from rpms/iptables 5 years ago
Clone

Blame SOURCES/0036-arptables-nft-Fix-CLASSIFY-target-printing.patch

029dc7
From fabed9f23311cdf42180613123309307b5c6add5 Mon Sep 17 00:00:00 2001
029dc7
From: Phil Sutter <phil@nwl.cc>
029dc7
Date: Thu, 31 Jan 2019 16:12:52 +0100
029dc7
Subject: [PATCH] arptables-nft: Fix CLASSIFY target printing
029dc7
029dc7
In legacy arptables, CLASSIFY target is not printed with fixed hex
029dc7
number lengths. Counter this by introducing a dedicated target
029dc7
definition for NFPROTO_ARP only having own print/save callbacks.
029dc7
029dc7
Signed-off-by: Phil Sutter <phil@nwl.cc>
029dc7
Signed-off-by: Florian Westphal <fw@strlen.de>
029dc7
(cherry picked from commit 756bea26a3dad89c467c703725ce6d3c6b29c871)
029dc7
Signed-off-by: Phil Sutter <psutter@redhat.com>
029dc7
---
029dc7
 extensions/libxt_CLASSIFY.c | 59 +++++++++++++++++++++++++++++--------
029dc7
 1 file changed, 46 insertions(+), 13 deletions(-)
029dc7
029dc7
diff --git a/extensions/libxt_CLASSIFY.c b/extensions/libxt_CLASSIFY.c
029dc7
index f90082dc7c50e..75aaf0c41b61a 100644
029dc7
--- a/extensions/libxt_CLASSIFY.c
029dc7
+++ b/extensions/libxt_CLASSIFY.c
029dc7
@@ -73,6 +73,24 @@ CLASSIFY_save(const void *ip, const struct xt_entry_target *target)
029dc7
 	       TC_H_MAJ(clinfo->priority)>>16, TC_H_MIN(clinfo->priority));
029dc7
 }
029dc7
 
029dc7
+static void
029dc7
+CLASSIFY_arp_save(const void *ip, const struct xt_entry_target *target)
029dc7
+{
029dc7
+	const struct xt_classify_target_info *clinfo =
029dc7
+		(const struct xt_classify_target_info *)target->data;
029dc7
+
029dc7
+	printf(" --set-class %x:%x",
029dc7
+	       TC_H_MAJ(clinfo->priority)>>16, TC_H_MIN(clinfo->priority));
029dc7
+}
029dc7
+
029dc7
+static void
029dc7
+CLASSIFY_arp_print(const void *ip,
029dc7
+      const struct xt_entry_target *target,
029dc7
+      int numeric)
029dc7
+{
029dc7
+	CLASSIFY_arp_save(ip, target);
029dc7
+}
029dc7
+
029dc7
 static int CLASSIFY_xlate(struct xt_xlate *xl,
029dc7
 			  const struct xt_xlate_tg_params *params)
029dc7
 {
029dc7
@@ -98,21 +116,36 @@ static int CLASSIFY_xlate(struct xt_xlate *xl,
029dc7
 	return 1;
029dc7
 }
029dc7
 
029dc7
-static struct xtables_target classify_target = { 
029dc7
-	.family		= NFPROTO_UNSPEC,
029dc7
-	.name		= "CLASSIFY",
029dc7
-	.version	= XTABLES_VERSION,
029dc7
-	.size		= XT_ALIGN(sizeof(struct xt_classify_target_info)),
029dc7
-	.userspacesize	= XT_ALIGN(sizeof(struct xt_classify_target_info)),
029dc7
-	.help		= CLASSIFY_help,
029dc7
-	.print		= CLASSIFY_print,
029dc7
-	.save		= CLASSIFY_save,
029dc7
-	.x6_parse	= CLASSIFY_parse,
029dc7
-	.x6_options	= CLASSIFY_opts,
029dc7
-	.xlate          = CLASSIFY_xlate,
029dc7
+static struct xtables_target classify_tg_reg[] = {
029dc7
+	{
029dc7
+		.family		= NFPROTO_UNSPEC,
029dc7
+		.name		= "CLASSIFY",
029dc7
+		.version	= XTABLES_VERSION,
029dc7
+		.size		= XT_ALIGN(sizeof(struct xt_classify_target_info)),
029dc7
+		.userspacesize	= XT_ALIGN(sizeof(struct xt_classify_target_info)),
029dc7
+		.help		= CLASSIFY_help,
029dc7
+		.print		= CLASSIFY_print,
029dc7
+		.save		= CLASSIFY_save,
029dc7
+		.x6_parse	= CLASSIFY_parse,
029dc7
+		.x6_options	= CLASSIFY_opts,
029dc7
+		.xlate          = CLASSIFY_xlate,
029dc7
+	},
029dc7
+	{
029dc7
+		.family		= NFPROTO_ARP,
029dc7
+		.name		= "CLASSIFY",
029dc7
+		.version	= XTABLES_VERSION,
029dc7
+		.size		= XT_ALIGN(sizeof(struct xt_classify_target_info)),
029dc7
+		.userspacesize	= XT_ALIGN(sizeof(struct xt_classify_target_info)),
029dc7
+		.help		= CLASSIFY_help,
029dc7
+		.print		= CLASSIFY_arp_print,
029dc7
+		.save		= CLASSIFY_arp_save,
029dc7
+		.x6_parse	= CLASSIFY_parse,
029dc7
+		.x6_options	= CLASSIFY_opts,
029dc7
+		.xlate          = CLASSIFY_xlate,
029dc7
+	}
029dc7
 };
029dc7
 
029dc7
 void _init(void)
029dc7
 {
029dc7
-	xtables_register_target(&classify_target);
029dc7
+	xtables_register_targets(classify_tg_reg, ARRAY_SIZE(classify_tg_reg));
029dc7
 }
029dc7
-- 
029dc7
2.21.0
029dc7