43df5c
From 7fcb3a907824af6220007d91ef49095f990b1733 Mon Sep 17 00:00:00 2001
43df5c
From: Phil Sutter <psutter@redhat.com>
43df5c
Date: Wed, 3 Apr 2019 20:15:52 +0200
43df5c
Subject: [PATCH] Consolidate DEBUGP macros
43df5c
43df5c
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=1668475
43df5c
Upstream Status: iptables commit 78b9d438037f2
43df5c
Conflicts:
43df5c
* Context change due to missing commit 2963a8df2175b
43df5c
  ("iptables: Remove explicit static variables initalization.")
43df5c
* Dropped changes to non-existing files iptables/nft-shared.h and
43df5c
  iptables/xtables-restore.c.
43df5c
43df5c
commit 78b9d438037f2c83a7bbb73eb1b86cc295967905
43df5c
Author: Phil Sutter <phil@nwl.cc>
43df5c
Date:   Thu Aug 2 17:05:15 2018 +0200
43df5c
43df5c
    Consolidate DEBUGP macros
43df5c
43df5c
    This debug printing macro was defined in various places, always
43df5c
    identical. Move it into xshared.h and drop it from sources including
43df5c
    that header. There are a few exceptions:
43df5c
43df5c
    * iptables-xml.c did not include xshared.h, which this patch changes.
43df5c
43df5c
    * Sources in extensions and libiptc mostly left alone since they don't
43df5c
      include xshared.h (and maybe shouldn't). Only libxt_set.h does, so
43df5c
      it's converted, too.
43df5c
43df5c
    This also converts DEBUG define use in libip6t_hbh.c to avoid a compiler
43df5c
    warning.
43df5c
43df5c
    Signed-off-by: Phil Sutter <phil@nwl.cc>
43df5c
    Signed-off-by: Florian Westphal <fw@strlen.de>
43df5c
43df5c
Signed-off-by: Phil Sutter <psutter@redhat.com>
43df5c
---
43df5c
 extensions/libip6t_hbh.c     | 6 ++----
43df5c
 extensions/libxt_set.h       | 6 ------
43df5c
 iptables/ip6tables-restore.c | 6 ------
43df5c
 iptables/iptables-restore.c  | 6 ------
43df5c
 iptables/iptables-xml.c      | 7 +------
43df5c
 iptables/xshared.h           | 6 ++++++
43df5c
 6 files changed, 9 insertions(+), 28 deletions(-)
43df5c
43df5c
diff --git a/extensions/libip6t_hbh.c b/extensions/libip6t_hbh.c
43df5c
index c0389ed8bafde..1c49ee71ada13 100644
43df5c
--- a/extensions/libip6t_hbh.c
43df5c
+++ b/extensions/libip6t_hbh.c
43df5c
@@ -5,8 +5,6 @@
43df5c
 #include <xtables.h>
43df5c
 #include <linux/netfilter_ipv6/ip6t_opts.h>
43df5c
 
43df5c
-#define DEBUG		0
43df5c
-
43df5c
 enum {
43df5c
 	O_HBH_LEN = 0,
43df5c
 	O_HBH_OPTS,
43df5c
@@ -83,7 +81,7 @@ parse_options(const char *optsstr, uint16_t *opts)
43df5c
                         opts[i] |= (0x00FF);
43df5c
 		}
43df5c
 
43df5c
-#if DEBUG
43df5c
+#ifdef DEBUG
43df5c
 		printf("opts str: %s %s\n", cp, range);
43df5c
 		printf("opts opt: %04X\n", opts[i]);
43df5c
 #endif
43df5c
@@ -92,7 +90,7 @@ parse_options(const char *optsstr, uint16_t *opts)
43df5c
 
43df5c
 	free(buffer);
43df5c
 
43df5c
-#if DEBUG
43df5c
+#ifdef DEBUG
43df5c
 	printf("addr nr: %d\n", i);
43df5c
 #endif
43df5c
 
43df5c
diff --git a/extensions/libxt_set.h b/extensions/libxt_set.h
43df5c
index 5a1bdcf730cf2..41dfbd30fc7c1 100644
43df5c
--- a/extensions/libxt_set.h
43df5c
+++ b/extensions/libxt_set.h
43df5c
@@ -8,12 +8,6 @@
43df5c
 #include <errno.h>
43df5c
 #include "../iptables/xshared.h"
43df5c
 
43df5c
-#ifdef DEBUG
43df5c
-#define DEBUGP(x, args...) fprintf(stderr, x , ## args)
43df5c
-#else
43df5c
-#define DEBUGP(x, args...) 
43df5c
-#endif
43df5c
-
43df5c
 static int
43df5c
 get_version(unsigned *version)
43df5c
 {
43df5c
diff --git a/iptables/ip6tables-restore.c b/iptables/ip6tables-restore.c
43df5c
index fdcc0cb5b2c06..611430d930eda 100644
43df5c
--- a/iptables/ip6tables-restore.c
43df5c
+++ b/iptables/ip6tables-restore.c
43df5c
@@ -20,12 +20,6 @@
43df5c
 #include "libiptc/libip6tc.h"
43df5c
 #include "ip6tables-multi.h"
43df5c
 
43df5c
-#ifdef DEBUG
43df5c
-#define DEBUGP(x, args...) fprintf(stderr, x, ## args)
43df5c
-#else
43df5c
-#define DEBUGP(x, args...)
43df5c
-#endif
43df5c
-
43df5c
 static int binary = 0, counters = 0, verbose = 0, noflush = 0, wait = 0;
43df5c
 
43df5c
 static struct timeval wait_interval = {
43df5c
diff --git a/iptables/iptables-restore.c b/iptables/iptables-restore.c
43df5c
index 5a8c2c738bb0f..b0da96d45d297 100644
43df5c
--- a/iptables/iptables-restore.c
43df5c
+++ b/iptables/iptables-restore.c
43df5c
@@ -17,12 +17,6 @@
43df5c
 #include "libiptc/libiptc.h"
43df5c
 #include "iptables-multi.h"
43df5c
 
43df5c
-#ifdef DEBUG
43df5c
-#define DEBUGP(x, args...) fprintf(stderr, x, ## args)
43df5c
-#else
43df5c
-#define DEBUGP(x, args...)
43df5c
-#endif
43df5c
-
43df5c
 static int binary = 0, counters = 0, verbose = 0, noflush = 0, wait = 0;
43df5c
 
43df5c
 static struct timeval wait_interval = {
43df5c
diff --git a/iptables/iptables-xml.c b/iptables/iptables-xml.c
43df5c
index 92a5768f86903..c523a132b2240 100644
43df5c
--- a/iptables/iptables-xml.c
43df5c
+++ b/iptables/iptables-xml.c
43df5c
@@ -16,12 +16,7 @@
43df5c
 #include "libiptc/libiptc.h"
43df5c
 #include "xtables-multi.h"
43df5c
 #include <xtables.h>
43df5c
-
43df5c
-#ifdef DEBUG
43df5c
-#define DEBUGP(x, args...) fprintf(stderr, x, ## args)
43df5c
-#else
43df5c
-#define DEBUGP(x, args...)
43df5c
-#endif
43df5c
+#include "xshared.h"
43df5c
 
43df5c
 struct xtables_globals iptables_xml_globals = {
43df5c
 	.option_offset = 0,
43df5c
diff --git a/iptables/xshared.h b/iptables/xshared.h
43df5c
index 20dbbd12118ad..bfdb10b2701e5 100644
43df5c
--- a/iptables/xshared.h
43df5c
+++ b/iptables/xshared.h
43df5c
@@ -9,6 +9,12 @@
43df5c
 #include <linux/netfilter_ipv4/ip_tables.h>
43df5c
 #include <linux/netfilter_ipv6/ip6_tables.h>
43df5c
 
43df5c
+#ifdef DEBUG
43df5c
+#define DEBUGP(x, args...) fprintf(stdout, x, ## args)
43df5c
+#else
43df5c
+#define DEBUGP(x, args...)
43df5c
+#endif
43df5c
+
43df5c
 enum {
43df5c
 	OPT_NONE        = 0,
43df5c
 	OPT_NUMERIC     = 1 << 0,
43df5c
-- 
43df5c
2.21.0
43df5c