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

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