Skip to contentSkip to conversation

xtables-addons: make ipv6 optional for RAWNAT and SYSRQ

PATCH Applied Peter Volkov 2 participants 5 messages Feb 19, 2010 – Feb 25, 2010 netfilter

lore
Share & tools
lore
#0 lore raw

Hi, in case kernel was built without ipv6 support xt_RAWNAT and xt_SYSRQ fail to load with unknown symbols. Patches in attachment fix this issue. Please, apply.

Signature · 1 line
Peter.
Quoted 1 line

From 646fd4275f91a6e10823b1d6ad2df1581aec7bb5 Mon Sep 17 00:00:00 2001

From: Peter Volkov <[email protected]>
Date: Fri, 19 Feb 2010 14:06:00 +0300
Subject: [PATCH 1/2] RAWNAT: make ipv6 support conditional

In case kernel is built without ipv6 support this module fails as it assumes ipv6. This patch makes kernel support conditional on kernel .config.

---
 extensions/ip6table_rawpost.c |    4 ++++
 extensions/xt_RAWNAT.c        |   12 ++++++++++++
 2 files changed, 16 insertions(+), 0 deletions(-)
extensions/ip6table_rawpost.c +4 -0
index 1cd9b26..c1e6102 100644
@@ -9,6 +9,8 @@
 #include "compat_xtables.h"
 #include "compat_rawpost.h"
 
+#if defined(CONFIG_IPV6) || defined(CONFIG_IPV6_MODULE)
+
 enum {
 	RAWPOST_VALID_HOOKS = 1 << NF_INET_POST_ROUTING,
 };
@@ -105,3 +107,5 @@ module_init(rawpost6_table_init);
 module_exit(rawpost6_table_exit);
 MODULE_AUTHOR("Jan Engelhardt <[email protected]>");
 MODULE_LICENSE("GPL");
+
+#endif
extensions/xt_RAWNAT.c +12 -0
index 18661a9..b8c7bc7 100644
@@ -22,6 +22,10 @@
 #include "compat_xtables.h"
 #include "xt_RAWNAT.h"
 
+#if defined(CONFIG_IPV6) || defined(CONFIG_IPV6_MODULE)
+#	define WITH_IPV6 1
+#endif
+
 static inline __be32
 remask(__be32 addr, __be32 repl, unsigned int shift)
 {
@@ -29,6 +33,7 @@ remask(__be32 addr, __be32 repl, unsigned int shift)
 	return htonl((ntohl(addr) & mask) | (ntohl(repl) & ~mask));
 }
 
+#ifdef WITH_IPV6
 static void
 rawnat_ipv6_mask(__be32 *addr, const __be32 *repl, unsigned int mask)
 {
@@ -72,6 +77,7 @@ rawnat_ipv6_mask(__be32 *addr, const __be32 *repl, unsigned int mask)
 		break;
 	}
 }
+#endif
 
 static void rawnat4_update_l4(struct sk_buff *skb, __be32 oldip, __be32 newip)
 {
@@ -162,6 +168,7 @@ rawdnat_tg4(struct sk_buff **pskb, const struct xt_target_param *par)
 	return XT_CONTINUE;
 }
 
+#ifdef WITH_IPV6
 static bool rawnat6_prepare_l4(struct sk_buff **pskb, unsigned int *l4offset,
     unsigned int *l4proto)
 {
@@ -274,6 +281,7 @@ rawdnat_tg6(struct sk_buff **pskb, const struct xt_target_param *par)
 	memcpy(&iph->daddr, &new_addr, sizeof(new_addr));
 	return XT_CONTINUE;
 }
+#endif
 
 static bool rawnat_tg_check(const struct xt_tgchk_param *par)
 {
@@ -296,6 +304,7 @@ static struct xt_target rawnat_tg_reg[] __read_mostly = {
 		.checkentry = rawnat_tg_check,
 		.me         = THIS_MODULE,
 	},
+#ifdef WITH_IPV6
 	{
 		.name       = "RAWSNAT",
 		.revision   = 0,
@@ -305,6 +314,7 @@ static struct xt_target rawnat_tg_reg[] __read_mostly = {
 		.checkentry = rawnat_tg_check,
 		.me         = THIS_MODULE,
 	},
+#endif
 	{
 		.name       = "RAWDNAT",
 		.revision   = 0,
@@ -314,6 +324,7 @@ static struct xt_target rawnat_tg_reg[] __read_mostly = {
 		.checkentry = rawnat_tg_check,
 		.me         = THIS_MODULE,
 	},
+#ifdef WITH_IPV6
 	{
 		.name       = "RAWDNAT",
 		.revision   = 0,
@@ -323,6 +334,7 @@ static struct xt_target rawnat_tg_reg[] __read_mostly = {
 		.checkentry = rawnat_tg_check,
 		.me         = THIS_MODULE,
 	},
+#endif
 };
 
 static int __init rawnat_tg_init(void)
Signature · 1 line
1.6.4.4
Quoted 1 line

From fdbae5d62bea5775eaf412bbcb2c3d98d26f4c02 Mon Sep 17 00:00:00 2001

From: Peter Volkov <[email protected]>
Date: Fri, 19 Feb 2010 14:46:17 +0300
Subject: [PATCH 2/2] SYSRQ: make ipv6 support conditional

In case kernel is built without ipv6 support this module fails as it assumes ipv6. This patch makes kernel support conditional on kernel .config.

---
 extensions/xt_SYSRQ.c |    8 ++++++++
 1 files changed, 8 insertions(+), 0 deletions(-)
extensions/xt_SYSRQ.c +8 -0
index 3cd223b..95c1184 100644
@@ -23,6 +23,10 @@
 #include <net/ip.h>
 #include "compat_xtables.h"
 
+#if defined(CONFIG_IPV6) || defined(CONFIG_IPV6_MODULE)
+#	define WITH_IPV6 1
+#endif
+
 static bool sysrq_once;
 static char sysrq_password[64];
 static char sysrq_hash[16] = "sha1";
@@ -214,6 +218,7 @@ sysrq_tg4(struct sk_buff **pskb, const struct xt_target_param *par)
 	return sysrq_tg((void *)udph + sizeof(struct udphdr), len);
 }
 
+#ifdef WITH_IPV6
 static unsigned int
 sysrq_tg6(struct sk_buff **pskb, const struct xt_target_param *par)
 {
@@ -242,6 +247,7 @@ sysrq_tg6(struct sk_buff **pskb, const struct xt_target_param *par)
 		       ntohs(udph->dest), len);
 	return sysrq_tg(udph + sizeof(struct udphdr), len);
 }
+#endif
 
 static bool sysrq_tg_check(const struct xt_tgchk_param *par)
 {
@@ -278,6 +284,7 @@ static struct xt_target sysrq_tg_reg[] __read_mostly = {
 		.checkentry = sysrq_tg_check,
 		.me         = THIS_MODULE,
 	},
+#ifdef WITH_IPV6
 	{
 		.name       = "SYSRQ",
 		.revision   = 1,
@@ -286,6 +293,7 @@ static struct xt_target sysrq_tg_reg[] __read_mostly = {
 		.checkentry = sysrq_tg_check,
 		.me         = THIS_MODULE,
 	},
+#endif
 };
 
 static int __init sysrq_tg_init(void)
Signature · 1 line
1.6.4.4
#1 lore raw
Quoted 3 lines · Peter Volkov

Hi, in case kernel was built without ipv6 support xt_RAWNAT and xt_SYSRQ fail to load with unknown symbols. Patches in attachment fix this issue. Please, apply.

For ip6table_rawpost, we could probably do this in the Kbuild file:

ifneq (${CONFIG_IPV6},)
obj-${build_RAWNAT} += ip6table_rawpost.o
endif

Can you test?

For the second patch, I would suggest to move around the structures in rawnat_tg_reg to reduce the number of #ifdefs needed.

#2 lore raw

В Птн, 19/02/2010 в 14:14 +0100, Jan Engelhardt пишет:

Quoted 8 lines · Peter Volkov

For ip6table_rawpost, we could probably do this in the Kbuild file:

ifneq (${CONFIG_IPV6},)
obj-${build_RAWNAT} += ip6table_rawpost.o
endif

Can you test?

Works.

Quoted 2 lines

For the second patch, I would suggest to move around the structures in rawnat_tg_reg to reduce the number of #ifdefs needed.

Done. Updated patch in attachment. Also added #ifdefs around ip6t MODULE_ALIAS.

Also I've updated SYSRQ patch a bit. Added ifdefs around another IPV6 related code and around MODULE_ALIAS.

Signature · 1 line
Peter.
Quoted 1 line

From 097f838fe1abac456f61774a727861a719ac3df3 Mon Sep 17 00:00:00 2001

From: Peter Volkov <[email protected]>
Date: Sat, 20 Feb 2010 14:56:32 +0300
Subject: [PATCH 1/2] RAWNAT: make ipv6 support conditional

In case kernel is built without ipv6 support this module fails as it assumes ipv6. This patch makes kernel support conditional on kernel .config.

---
 extensions/Kbuild      |    5 ++++-
 extensions/xt_RAWNAT.c |   24 ++++++++++++++++++------
 2 files changed, 22 insertions(+), 7 deletions(-)
extensions/Kbuild +4 -1
index 5588c2c..841332d 100644
@@ -12,7 +12,10 @@ obj-${build_DHCPMAC}     += xt_DHCPMAC.o
 obj-${build_ECHO}        += xt_ECHO.o
 obj-${build_IPMARK}      += xt_IPMARK.o
 obj-${build_LOGMARK}     += xt_LOGMARK.o
-obj-${build_RAWNAT}      += xt_RAWNAT.o iptable_rawpost.o ip6table_rawpost.o
+obj-${build_RAWNAT}      += xt_RAWNAT.o iptable_rawpost.o
+ifneq (${CONFIG_IPV6},)
+obj-${build_RAWNAT} += ip6table_rawpost.o
+endif
 obj-${build_SYSRQ}       += xt_SYSRQ.o
 obj-${build_STEAL}       += xt_STEAL.o
 obj-${build_TARPIT}      += xt_TARPIT.o
extensions/xt_RAWNAT.c +18 -6
index 18661a9..e743531 100644
@@ -22,6 +22,10 @@
 #include "compat_xtables.h"
 #include "xt_RAWNAT.h"
 
+#if defined(CONFIG_IPV6) || defined(CONFIG_IPV6_MODULE)
+#	define WITH_IPV6 1
+#endif
+
 static inline __be32
 remask(__be32 addr, __be32 repl, unsigned int shift)
 {
@@ -29,6 +33,7 @@ remask(__be32 addr, __be32 repl, unsigned int shift)
 	return htonl((ntohl(addr) & mask) | (ntohl(repl) & ~mask));
 }
 
+#ifdef WITH_IPV6
 static void
 rawnat_ipv6_mask(__be32 *addr, const __be32 *repl, unsigned int mask)
 {
@@ -72,6 +77,7 @@ rawnat_ipv6_mask(__be32 *addr, const __be32 *repl, unsigned int mask)
 		break;
 	}
 }
+#endif
 
 static void rawnat4_update_l4(struct sk_buff *skb, __be32 oldip, __be32 newip)
 {
@@ -162,6 +168,7 @@ rawdnat_tg4(struct sk_buff **pskb, const struct xt_target_param *par)
 	return XT_CONTINUE;
 }
 
+#ifdef WITH_IPV6
 static bool rawnat6_prepare_l4(struct sk_buff **pskb, unsigned int *l4offset,
     unsigned int *l4proto)
 {
@@ -274,6 +281,7 @@ rawdnat_tg6(struct sk_buff **pskb, const struct xt_target_param *par)
 	memcpy(&iph->daddr, &new_addr, sizeof(new_addr));
 	return XT_CONTINUE;
 }
+#endif
 
 static bool rawnat_tg_check(const struct xt_tgchk_param *par)
 {
@@ -297,19 +305,20 @@ static struct xt_target rawnat_tg_reg[] __read_mostly = {
 		.me         = THIS_MODULE,
 	},
 	{
-		.name       = "RAWSNAT",
+		.name       = "RAWDNAT",
 		.revision   = 0,
-		.family     = NFPROTO_IPV6,
-		.target     = rawsnat_tg6,
+		.family     = NFPROTO_IPV4,
+		.target     = rawdnat_tg4,
 		.targetsize = sizeof(struct xt_rawnat_tginfo),
 		.checkentry = rawnat_tg_check,
 		.me         = THIS_MODULE,
 	},
+#ifdef WITH_IPV6
 	{
-		.name       = "RAWDNAT",
+		.name       = "RAWSNAT",
 		.revision   = 0,
-		.family     = NFPROTO_IPV4,
-		.target     = rawdnat_tg4,
+		.family     = NFPROTO_IPV6,
+		.target     = rawsnat_tg6,
 		.targetsize = sizeof(struct xt_rawnat_tginfo),
 		.checkentry = rawnat_tg_check,
 		.me         = THIS_MODULE,
@@ -323,6 +332,7 @@ static struct xt_target rawnat_tg_reg[] __read_mostly = {
 		.checkentry = rawnat_tg_check,
 		.me         = THIS_MODULE,
 	},
+#endif
 };
 
 static int __init rawnat_tg_init(void)
@@ -342,5 +352,7 @@ MODULE_DESCRIPTION("Xtables: conntrack-less raw NAT");
 MODULE_LICENSE("GPL");
 MODULE_ALIAS("ipt_RAWSNAT");
 MODULE_ALIAS("ipt_RAWDNAT");
+#ifdef WITH_IPV6
 MODULE_ALIAS("ip6t_RAWSNAT");
 MODULE_ALIAS("ip6t_RAWDNAT");
+#endif
Signature · 1 line
1.6.4.4
Quoted 1 line

From 8dfafcf38940c4529845b28505439fd7f03349f0 Mon Sep 17 00:00:00 2001

From: Peter Volkov <[email protected]>
Date: Sat, 20 Feb 2010 14:57:20 +0300
Subject: [PATCH 2/2] SYSRQ: make ipv6 support conditional

In case kernel is built without ipv6 support this module fails as it assumes ipv6. This patch makes kernel support conditional on kernel .config.

---
 extensions/xt_SYSRQ.c |   12 ++++++++++++
 1 files changed, 12 insertions(+), 0 deletions(-)
extensions/xt_SYSRQ.c +12 -0
index 3cd223b..5557b41 100644
@@ -23,6 +23,10 @@
 #include <net/ip.h>
 #include "compat_xtables.h"
 
+#if defined(CONFIG_IPV6) || defined(CONFIG_IPV6_MODULE)
+#	define WITH_IPV6 1
+#endif
+
 static bool sysrq_once;
 static char sysrq_password[64];
 static char sysrq_hash[16] = "sha1";
@@ -214,6 +218,7 @@ sysrq_tg4(struct sk_buff **pskb, const struct xt_target_param *par)
 	return sysrq_tg((void *)udph + sizeof(struct udphdr), len);
 }
 
+#ifdef WITH_IPV6
 static unsigned int
 sysrq_tg6(struct sk_buff **pskb, const struct xt_target_param *par)
 {
@@ -242,6 +247,7 @@ sysrq_tg6(struct sk_buff **pskb, const struct xt_target_param *par)
 		       ntohs(udph->dest), len);
 	return sysrq_tg(udph + sizeof(struct udphdr), len);
 }
+#endif
 
 static bool sysrq_tg_check(const struct xt_tgchk_param *par)
 {
@@ -253,6 +259,7 @@ static bool sysrq_tg_check(const struct xt_tgchk_param *par)
 		    entry->ip.proto != IPPROTO_UDPLITE) ||
 		    entry->ip.invflags & XT_INV_PROTO)
 			goto out;
+#ifdef WITH_IPV6
 	} else if (par->target->family == NFPROTO_IPV6) {
 		const struct ip6t_entry *entry = par->entryinfo;
 
@@ -260,6 +267,7 @@ static bool sysrq_tg_check(const struct xt_tgchk_param *par)
 		    entry->ipv6.proto != IPPROTO_UDPLITE) ||
 		    entry->ipv6.invflags & XT_INV_PROTO)
 			goto out;
+#endif
 	}
 
 	return true;
@@ -278,6 +286,7 @@ static struct xt_target sysrq_tg_reg[] __read_mostly = {
 		.checkentry = sysrq_tg_check,
 		.me         = THIS_MODULE,
 	},
+#ifdef WITH_IPV6
 	{
 		.name       = "SYSRQ",
 		.revision   = 1,
@@ -286,6 +295,7 @@ static struct xt_target sysrq_tg_reg[] __read_mostly = {
 		.checkentry = sysrq_tg_check,
 		.me         = THIS_MODULE,
 	},
+#endif
 };
 
 static int __init sysrq_tg_init(void)
@@ -357,4 +367,6 @@ MODULE_DESCRIPTION("Xtables: triggering SYSRQ remotely");
 MODULE_AUTHOR("Jan Engelhardt <[email protected]>");
 MODULE_LICENSE("GPL");
 MODULE_ALIAS("ipt_SYSRQ");
+#ifdef WITH_IPV6
 MODULE_ALIAS("ip6t_SYSRQ");
+#endif
Signature · 1 line
1.6.4.4
#3 lore raw
Quoted 8 lines · Peter Volkov

В Птн, 19/02/2010 в 14:14 +0100, Jan Engelhardt пишет:

Quoted 7 lines · Peter Volkov

For ip6table_rawpost, we could probably do this in the Kbuild file:

ifneq (${CONFIG_IPV6},)
obj-${build_RAWNAT} += ip6table_rawpost.o
endif

Quoted 8 lines
Quoted 1 line

Can you test?

Works.

Quoted 2 lines

For the second patch, I would suggest to move around the structures in rawnat_tg_reg to reduce the number of #ifdefs needed.

Done. Updated patch in attachment.

Too late, I already merged it manually this morning :p (there was a reply to your mail)

Quoted 4 lines

Also added #ifdefs around ip6t MODULE_ALIAS.

Also I've updated SYSRQ patch a bit. Added ifdefs around another IPV6 related code and around MODULE_ALIAS.

I don't think we need to do it to such extremes - after all one of the goals was to have less #macros than pom-ng.
--
To unsubscribe from this list: send the line "unsubscribe netfilter-devel" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

#4 lore raw
In reply to Peter Volkov
Quoted 3 lines · Peter Volkov

Hi, in case kernel was built without ipv6 support xt_RAWNAT and xt_SYSRQ fail to load with unknown symbols. Patches in attachment fix this issue. Please, apply.

Applied, thanks.