Skip to contentSkip to conversation

add "revision" support to arp_tables and ip6_tables

PATCH/RFC/RFT Harald Welte 5 participants 6 messages Oct 9, 2005 – Oct 14, 2005

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

Hi Dave + Yasuyuki,
Dear ip6_tables and arp_tables maintainers ;)

I've added "revision" (i.e. support for multiple match/target versions) to arp_tables and ip6_tables.

This is mainly a step to synchronize the two "evil twins" of ip_tables, in order to provide a foundation for the "x_tables" code (which I already have implemented on top of it).

At least according to some simple tests, I didn't break anything. It's already in my git tree's 'master' branch, and I intend to submit it during early 2.6.15.

Please test/comment/fix,
Harald

Signature · 5 lines
- Harald Welte <[email protected]>                 http://netfilter.org/
============================================================================
  "Fragmentation is like classful addressing -- an interesting early
   architectural error that shows how much experimentation was going
   on while IP was being designed."                    -- Paul Vixie

[NETFILTER] {ip6,arp}_tables: Add support for match/target revisions

This patch synchronizes {ip6,arp}_tables with recent changes in ip_tables. It adds support for multiple revisions per match/target.

---
commit b472176079a50f0c61c6a5f915a7c9129f20dd2b
tree a5b853d18b28bb2a821e1568e235622bea4c7991
parent 0dc2bc0656b4b1c5ba3524dadc8fbf36881903b7
author Harald Welte <[email protected]> Sun, 09 Oct 2005 16:22:51 +0200 committer Harald Welte <[email protected]> Sun, 09 Oct 2005 16:22:51 +0200

 include/linux/netfilter_arp/arp_tables.h  |   20 ++
 include/linux/netfilter_ipv6/ip6_tables.h |   27 ++-
 net/ipv4/netfilter/arp_tables.c           |  205 +++++++++++++------
 net/ipv6/netfilter/ip6_tables.c           |  307 ++++++++++++++++++-----------
 4 files changed, 363 insertions(+), 196 deletions(-)
include/linux/netfilter_arp/arp_tables.h +17 -3
@@ -68,7 +68,8 @@ struct arpt_entry_target
 			u_int16_t target_size;
 
 			/* Used by userspace */
-			char name[ARPT_FUNCTION_MAXNAMELEN];
+			char name[ARPT_FUNCTION_MAXNAMELEN-1];
+			u_int8_t revision;
 		} user;
 		struct {
 			u_int16_t target_size;
@@ -148,7 +149,9 @@ struct arpt_entry
 
 #define ARPT_SO_GET_INFO		(ARPT_BASE_CTL)
 #define ARPT_SO_GET_ENTRIES		(ARPT_BASE_CTL + 1)
-#define ARPT_SO_GET_MAX			ARPT_SO_GET_ENTRIES
+/* #define ARPT_SO_GET_REVISION_MATCH	(ARPT_BASE_CTL + 2)*/
+#define ARPT_SO_GET_REVISION_TARGET	(ARPT_BASE_CTL + 3)
+#define ARPT_SO_GET_MAX			ARPT_SO_GET_REVISION_TARGET
 
 /* CONTINUE verdict for targets */
 #define ARPT_CONTINUE 0xFFFFFFFF
@@ -236,6 +239,15 @@ struct arpt_get_entries
 	struct arpt_entry entrytable[0];
 };
 
+/* The argument to ARPT_SO_GET_REVISION_*.  Returns highest revision
+ * kernel supports, if >= revision. */
+struct arpt_get_revision
+{
+	char name[ARPT_FUNCTION_MAXNAMELEN-1];
+
+	u_int8_t revision;
+};
+
 /* Standard return verdict, or do jump. */
 #define ARPT_STANDARD_TARGET ""
 /* Error verdict. */
@@ -274,7 +286,9 @@ struct arpt_target
 {
 	struct list_head list;
 
-	const char name[ARPT_FUNCTION_MAXNAMELEN];
+	const char name[ARPT_FUNCTION_MAXNAMELEN-1];
+
+	u_int8_t revision;
 
 	/* Returns verdict. */
 	unsigned int (*target)(struct sk_buff **pskb,
include/linux/netfilter_ipv6/ip6_tables.h +22 -5
@@ -57,7 +57,8 @@ struct ip6t_entry_match
 			u_int16_t match_size;
 
 			/* Used by userspace */
-			char name[IP6T_FUNCTION_MAXNAMELEN];
+			char name[IP6T_FUNCTION_MAXNAMELEN-1];
+			u_int8_t revision;
 		} user;
 		struct {
 			u_int16_t match_size;
@@ -80,7 +81,8 @@ struct ip6t_entry_target
 			u_int16_t target_size;
 
 			/* Used by userspace */
-			char name[IP6T_FUNCTION_MAXNAMELEN];
+			char name[IP6T_FUNCTION_MAXNAMELEN-1];
+			u_int8_t revision;
 		} user;
 		struct {
 			u_int16_t target_size;
@@ -161,7 +163,9 @@ struct ip6t_entry
 
 #define IP6T_SO_GET_INFO		(IP6T_BASE_CTL)
 #define IP6T_SO_GET_ENTRIES		(IP6T_BASE_CTL + 1)
-#define IP6T_SO_GET_MAX			IP6T_SO_GET_ENTRIES
+#define	IP6T_SO_GET_REVISION_MATCH	(IP6T_BASE_CTL + 2)
+#define	IP6T_SO_GET_REVISION_TARGET	(IP6T_BASE_CTL + 3)
+#define IP6T_SO_GET_MAX			IP6T_SO_GET_REVISION_TARGET
 
 /* CONTINUE verdict for targets */
 #define IP6T_CONTINUE 0xFFFFFFFF
@@ -291,6 +295,15 @@ struct ip6t_get_entries
 	struct ip6t_entry entrytable[0];
 };
 
+/* The argument to IP6T_SO_GET_REVISION_*.  Returns highest revision
+ * kernel supports, if >= revision. */
+struct ip6t_get_revision
+{
+	char name[IP6T_FUNCTION_MAXNAMELEN-1];
+
+	u_int8_t revision;
+};
+
 /* Standard return verdict, or do jump. */
 #define IP6T_STANDARD_TARGET ""
 /* Error verdict. */
@@ -352,7 +365,9 @@ struct ip6t_match
 {
 	struct list_head list;
 
-	const char name[IP6T_FUNCTION_MAXNAMELEN];
+	const char name[IP6T_FUNCTION_MAXNAMELEN-1];
+
+	u_int8_t revision;
 
 	/* Return true or false: return FALSE and set *hotdrop = 1 to
            force immediate packet drop. */
@@ -387,7 +402,9 @@ struct ip6t_target
 {
 	struct list_head list;
 
-	const char name[IP6T_FUNCTION_MAXNAMELEN];
+	const char name[IP6T_FUNCTION_MAXNAMELEN-1];
+
+	u_int8_t revision;
 
 	/* Returns verdict. Argument order changed since 2.6.9, as this
 	   must now handle non-linear skbs, using skb_copy_bits and
net/ipv4/netfilter/arp_tables.c +133 -72

320 lines not on this page · raw message

net/ipv6/netfilter/ip6_tables.c +190 -116

470 lines not on this page · raw message

#1 lore raw

Hi,

Quoted 21 lines · Harald Welte

I've added "revision" (i.e. support for multiple match/target versions) to arp_tables and ip6_tables.

At least according to some simple tests, I didn't break anything. It's already in my git tree's 'master' branch, and I intend to submit it during early 2.6.15.

Please test/comment/fix,
Harald

[NETFILTER] {ip6,arp}_tables: Add support for match/target revisions

This patch synchronizes {ip6,arp}_tables with recent changes in ip_tables. It adds support for multiple revisions per match/target.

include/linux/netfilter_arp/arp_tables.h struct arpt_entry_target · line 75

Quoted 9 lines
include/linux/netfilter_arp/arp_tables.h +2 -1
@@ -68,7 +68,8 @@ struct arpt_entry_target
 			u_int16_t target_size;
 
 			/* Used by userspace */
-			char name[ARPT_FUNCTION_MAXNAMELEN];
+			char name[ARPT_FUNCTION_MAXNAMELEN-1];
+			u_int8_t revision;
 		} user;
 		struct {
 			u_int16_t target_size;

This will explode once revision!=0 because the string stored in name is not NULL-terminated anymore if it is ARPT_FUNCTION_MAXNAMELEN-1 long.

Regards,
Carl-Daniel

#2 lore raw
Quoted 11 lines · Carl-Daniel Hailfinger
Quoted 11 lines

[NETFILTER] {ip6,arp}_tables: Add support for match/target revisions This patch synchronizes {ip6,arp}_tables with recent changes in ip_tables. It adds support for multiple revisions per match/target.

include/linux/netfilter_arp/arp_tables.h +0 -1
@@ -68,7 +68,8 @@ struct arpt_entry_target
 			u_int16_t target_size;
 			/* Used by userspace */
-			char name[ARPT_FUNCTION_MAXNAMELEN];
Quoted 8 lines

include/linux/netfilter_arp/arp_tables.h struct arpt_entry_target · line 75

Quoted 5 lines
include/linux/netfilter_arp/arp_tables.h +2 -0
+			char name[ARPT_FUNCTION_MAXNAMELEN-1];
+			u_int8_t revision;
 		} user;
 		struct {
 			u_int16_t target_size;

This will explode once revision!=0 because the string stored in name is not NULL-terminated anymore if it is ARPT_FUNCTION_MAXNAMELEN-1 long.

Are you referring to something specific inside arp_tables kernel or userspace code? We had a similar change in ip_tables some time ago, and just made sure that the userspace program ("iptables") didn't generate any strings longer than IPT_FUNCTION_NAMELEN-2. Since we never had any matches or targets that used the full length, there is no problem.

At least inside the mainline kernel, I cannot see any targets/matches for ip6_tables or arp_tables that actually have 30 characters of length.

Signature · 5 lines
- Harald Welte <[email protected]>                 http://netfilter.org/
============================================================================
  "Fragmentation is like classful addressing -- an interesting early
   architectural error that shows how much experimentation was going
   on while IP was being designed."                    -- Paul Vixie
#3 lore raw

From: Harald Welte <[email protected]>
Date: Mon, 10 Oct 2005 18:32:56 +0200

Quoted 22 lines · Carl-Daniel Hailfinger
Quoted 12 lines
Quoted 12 lines

[NETFILTER] {ip6,arp}_tables: Add support for match/target revisions This patch synchronizes {ip6,arp}_tables with recent changes in ip_tables. It adds support for multiple revisions per match/target.

include/linux/netfilter_arp/arp_tables.h +0 -1
@@ -68,7 +68,8 @@ struct arpt_entry_target
 			u_int16_t target_size;
 			/* Used by userspace */
-			char name[ARPT_FUNCTION_MAXNAMELEN];
Quoted 8 lines

include/linux/netfilter_arp/arp_tables.h struct arpt_entry_target · line 75

Quoted 5 lines
include/linux/netfilter_arp/arp_tables.h +2 -0
+			char name[ARPT_FUNCTION_MAXNAMELEN-1];
+			u_int8_t revision;
 		} user;
 		struct {
 			u_int16_t target_size;

This will explode once revision!=0 because the string stored in name is not NULL-terminated anymore if it is ARPT_FUNCTION_MAXNAMELEN-1 long.

Quoted 8 lines

Are you referring to something specific inside arp_tables kernel or userspace code? We had a similar change in ip_tables some time ago, and just made sure that the userspace program ("iptables") didn't generate any strings longer than IPT_FUNCTION_NAMELEN-2. Since we never had any matches or targets that used the full length, there is no problem.

At least inside the mainline kernel, I cannot see any targets/matches for ip6_tables or arp_tables that actually have 30 characters of length.

I think that the point of issue what Carl want to say is size of "name". He worries about that the memory address of "revision" became different in the kernel and userspace.

I think the change like this is invalid in logical as Carl said, but there might be no problem in real by help of alignment in this time.
-----------------------------------------------------------------
Yasuyuki Kozakai @ USAGI Project <[email protected]>

#4 lore raw
In reply to Harald Welte
Quoted 5 lines · Harald Welte

Are you referring to something specific inside arp_tables kernel or userspace code? We had a similar change in ip_tables some time ago, and just made sure that the userspace program ("iptables") didn't generate any strings longer than IPT_FUNCTION_NAMELEN-2. Since we never had any matches or targets that used the full length, there is no problem.

And if it becomes a problem it is not hard to change the code to support IPT_FUNCTION_NAMELEN-1 length targets/matches again by implicitly null-terminating the string after extracting the version or using strncmp to compare the names (no null termination required if within n).

So even if there today exists a target/match with a name of this length it is not unfixable.

The versioning support only reduces the theoretical max target/match length which can be supported by the structures by one character from IPT_FUNCTION_NAMELEN to IPT_FUNCTION_NAMELEN-1. To keep implementation simple the change it actually reduces the max length from IPT_FUNCTION_NAMELEN-1 to IPT_FUNCTION_NAMELEN-2 by keeping the null termination of the string but this is not stricly required.

Regards
Henrik

maintainer
#5 lore raw
In reply to Harald Welte

From: Harald Welte <[email protected]>
Date: Mon, 10 Oct 2005 00:26:28 +0200

Quoted 5 lines

At least according to some simple tests, I didn't break anything. It's already in my git tree's 'master' branch, and I intend to submit it during early 2.6.15.

Please test/comment/fix,

No objection from me :)