Skip to contentSkip to conversation

Fixed proken MARK target in POM.

PATCH Anders Fugmann 2 participants 7 messages Jan 9, 2003 – Jan 12, 2003

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

Hi.

As I require the BIT-operations provided by the MARK target in POM, attached is a fixed version of this.

The patch extends the MARK target in mangle chains to allow:

# iptables -t mangle -A PRERPUTING -j MARK --set-mark 0x01
# iptables -t mangle -A PRERPUTING -j MARK --and-mark 0x01
# iptables -t mangle -A PRERPUTING -j MARK --or-mark 0x01

The version is widly based on the current one with only minor code fixes. The kernel patch applies cleanly to 2.4.20 and 2.5.54. The userspace patch is against 1.2.7a. The patch has been tested on 2.5.54.

The patch maintains backward compability, and I request that this patch is applied to mainstream (and pushed to the Andrea for kernel inclusion), as I as a software developer of a firewall cannot ask users of the software to appliy patches to POM.

Regards
Anders Fugmann

include/linux/netfilter_ipv4/ipt_MARK.h +7 -0
diff -r -u linux-2.4.20/include/linux/netfilter_ipv4/ipt_MARK.h linux-2.4.20-new/include/linux/netfilter_ipv4/ipt_MARK.h
@@ -1,8 +1,15 @@
 #ifndef _IPT_MARK_H_target
 #define _IPT_MARK_H_target
 
+enum {
+        IPT_MARK_SET=0,
+        IPT_MARK_AND,
+        IPT_MARK_OR
+};
+
 struct ipt_mark_target_info {
 	unsigned long mark;
+	u_int8_t mode;
 };
 
 #endif /*_IPT_MARK_H_target*/
net/ipv4/netfilter/ipt_MARK.c +23 -3
diff -r -u linux-2.4.20/net/ipv4/netfilter/ipt_MARK.c linux-2.4.20-new/net/ipv4/netfilter/ipt_MARK.c
@@ -16,11 +16,31 @@
        void *userinfo)
 {
 	const struct ipt_mark_target_info *markinfo = targinfo;
+	int newmark;
+	
+	switch (markinfo->mode) {
+	case IPT_MARK_SET:
+		newmark = markinfo->mark;
+		break;
+		
+	case IPT_MARK_AND:
+		newmark = (*pskb)->nfmark & markinfo->mark;
+		break;
+		
+	case IPT_MARK_OR:
+		newmark = (*pskb)->nfmark | markinfo->mark;
+		break;
+
+	default:
+                newmark = (*pskb)->nfmark;
+		break;
+	}
 
-	if((*pskb)->nfmark != markinfo->mark) {
-		(*pskb)->nfmark = markinfo->mark;
-		(*pskb)->nfcache |= NFC_ALTERED;
+	if ((*pskb)->nfmark != newmark) {
+	        (*pskb)->nfmark = newmark;
+	        (*pskb)->nfcache |= NFC_ALTERED;
 	}
+
 	return IPT_CONTINUE;
 }
 
extensions/libipt_MARK.c +47 -10

98 lines not on this page · raw message

iptables.8 +14 -0
diff -u -r iptables-1.2.7a/iptables.8 iptables-1.2.7a-new/iptables.8
@@ -690,6 +690,20 @@
 table.  It can for example be used in conjunction with iproute2.
 .TP
 .BI "--set-mark " "mark"
+Sets the marking of the packet to 
+.I mark
+regardless of the current mark value of the packet.
+.TP
+.BI "--and-mark " "mark"
+Binary AND the current mark value of the packet with the supplied
+.I mark 
+value.
+.TP
+.BI "--or-mark " "mark"
+Binary OR the current mark value of the packet with the supplied
+.I mark 
+value.
+
 .SS REJECT
 This is used to send back an error packet in response to the matched
 packet: otherwise it is equivalent to 
#1 lore raw
Quoted 3 lines · Anders Fugmann

The patch maintains backward compability, and I request that this patch is applied to mainstream (and pushed to the Andrea for kernel inclusion),

1) Where is the compatibility? I cannot see how this code change would ensure that
a) old, unpatched kernel works with new, patched userspace
b) new, patched kernel works with old, unpatched userspace
Those two conditions need to be fulfilled, otherwise we cannot make a change during the stable kernel series.

2) Which Andrea are you talking about? Therer is no Andrea involved in netfilter/iptabls updates.

Quoted 2 lines

as I as a software developer of a firewall cannot ask users of the software to appliy patches to POM.

I regard this as critic to my recent patch-o-matic announcement, where I was asking people to use patch-o-matic. I was talking about bugfixes/updates which are in 2.4.20 (or 2.4.21-preX)... but people are still running older kernels than that... and they should indeed use patch-o-matic for the netfilter fixes.

Apart from that, everything in patch-o-matic are new features or extensions, which are either not fully stable or we strongly doubt that they are useful for the big public. And if somebody wants to test one of those non-standard extensions, we can ask people to use patch-o-matic.

Quoted 2 lines

Regards
Anders Fugmann

Signature · 4 lines
- Harald Welte / [email protected]               http://www.gnumonks.org/
============================================================================
"If this were a dictatorship, it'd be a heck of a lot easier, just so long
 as I'm the dictator."  --  George W. Bush Dec 18, 2000
#2 lore raw
Quoted 6 lines · Harald Welte
Quoted 1 line · Anders Fugmann

The patch maintains backward compability, and I request that this patch is applied to mainstream (and pushed to the Andrea for kernel inclusion),

Quoted 6 lines

1) Where is the compatibility? I cannot see how this code change would ensure that
a) old, unpatched kernel works with new, patched userspace
b) new, patched kernel works with old, unpatched userspace
Those two conditions need to be fulfilled, otherwise we cannot make a change during the stable kernel series.

I meant compability in form of userspace syntax, but I will make a new patch that sorts out the things above (if possible).

Quoted 3 lines

2) Which Andrea are you talking about? Therer is no Andrea involved in netfilter/iptabls updates.

Andrea Arcangeli (2.4.x maintainer, just to recite what you already know), but as you wrote in the previous mail, all patches will go through netfilter-devel (And let the core team choose what to have included in the kernel).

Quoted 7 lines
Quoted 3 lines

as I as a software developer of a firewall cannot ask users of the software to appliy patches to POM.

I regard this as critic to my recent patch-o-matic announcement, where I was asking people to use patch-o-matic. I was talking about

Actually not, but thats ok.

Quoted 3 lines

bugfixes/updates which are in 2.4.20 (or 2.4.21-preX)... but people are still running older kernels than that... and they should indeed use patch-o-matic for the netfilter fixes.

Agreed. Compability between kernel and userspace should be maintained no matter version, and patches exist in POM for users of older kernels.

Quoted 5 lines

Apart from that, everything in patch-o-matic are new features or extensions, which are either not fully stable or we strongly doubt that they are useful for the big public. And if somebody wants to test one of those non-standard extensions, we can ask people to use patch-o-matic.

Yes. I'm aware of that. My question is "How can a patch be proven stable enough to be included, and is the functionality provided 'importent' enough for the general public?

Regards
Anders Fugmann

#3 lore raw
Quoted 9 lines · Anders Fugmann
Quoted 7 lines · Harald Welte
Quoted 1 line · Anders Fugmann

The patch maintains backward compability, and I request that this patch is applied to mainstream (and pushed to the Andrea for kernel inclusion),

Quoted 6 lines
Quoted 6 lines

1) Where is the compatibility? I cannot see how this code change would ensure that
a) old, unpatched kernel works with new, patched userspace
b) new, patched kernel works with old, unpatched userspace
Those two conditions need to be fulfilled, otherwise we cannot make a change during the stable kernel series.

Looking at bit further, this seems non-trivial as I guess that the userspace should compile no matter kernel-headers version - no?

Are defines tolerated? Something like:
#define MARK_BITOPS

and then in the userspace do a:
#ifdef MARK_BITOPS
Whenever the new fileds in the structure is used.

But IMHO this clutters the code up and I would rather avoid that.
Do you know of modules that had the same problem, or do you regard it as unresolvable to add an extra field to a structure in the stable series?

Regards
Anders Fugmann

#4 lore raw
Quoted 2 lines · Anders Fugmann

Looking at bit further, this seems non-trivial as I guess that the userspace should compile no matter kernel-headers version - no?

yes, exactly. This would be the ideal case.

If this is not possible (or at least not feasible), we have a set of kernel headers inside the iptables package itself. (CVS:userspace/include/linux/...)

The current include path order makes 'real' kernel headers precede the iptables-supplied headers. If necessarry, we could change this order, making the iptables-supplied headers precede.

Quoted 6 lines

Are defines tolerated? Something like:
#define MARK_BITOPS

and then in the userspace do a:
#ifdef MARK_BITOPS
Whenever the new fileds in the structure is used.

I don't understand how this could solve the problem. #defines are about compile time. We need one runtime iptables that copes with old and new kernels (and vice-versa).

Quoted 3 lines

But IMHO this clutters the code up and I would rather avoid that. Do you know of modules that had the same problem, or do you regard it as unresolvable to add an extra field to a structure in the stable series?

We have quite a couple of other cases where we have the same problem - without any solution :(( But during a stable kernel series, we cannot put compatibility aside. People are not supposed to upgrade their iptables after they upgraded their kernel...

Quoted 2 lines

Regards
Anders Fugmann

Signature · 5 lines
Live long and prosper
- Harald Welte / [email protected]               http://www.gnumonks.org/
============================================================================
GCS/E/IT d- s-: a-- C+++ UL++++$ P+++ L++++$ E--- W- N++ o? K- w--- O- M- 
V-- PS+ PE-- Y+ PGP++ t++ 5-- !X !R tv-- b+++ DI? !D G+ e* h+ r% y+(*)
#5 lore raw
Quoted 11 lines · Harald Welte
Quoted 6 lines

Are defines tolerated? Something like:
#define MARK_BITOPS

and then in the userspace do a:
#ifdef MARK_BITOPS
Whenever the new fileds in the structure is used.

I don't understand how this could solve the problem. #defines are about compile time. We need one runtime iptables that copes with old and new kernels (and vice-versa).

I can see a way to make it somewhat compatible.

Kernel:
Make a totally new structure (Keep the old one for compability) When checkentry is called, examine the size of argument:
If it equals the old size, set a module-global variable meaning that the module should run in compability mode.
Othervice use the new structure.

This should sort out kernel compability with whatever iptables version.

Userspace:
This is a bit more tricky, as compability is defined by compile time.
That is, if iptables is compiled against 2.4.21 with the new MARK target, it will not work with a kernel without the MARK target. If this is acceptable, then a #define MARK_BITOPS can help solve the userspace compability. Something like

#ifdef MARK_BITOPS
Accept --or-mark and --and-mark, and use the new structure.
#else
Only accept --set-mark and usethe old structure.
#endif

Is this acceptable (no backward compability with iptables - it only works with the kernel its compiled against and newer, but not older)?

Quoted 5 lines

We have quite a couple of other cases where we have the same problem - without any solution :(( But during a stable kernel series, we cannot put compatibility aside. People are not supposed to upgrade their iptables after they upgraded their kernel...

If the above procedure is acceptable, then it migh be a template for such updates in the stable kernel series. It is important that the old structures are removed for 2.6 though.

Regards
Anders Fugmann

#6 lore raw
In reply to Anders Fugmann
Quoted 8 lines · Anders Fugmann
Quoted 4 lines

Apart from that, everything in patch-o-matic are new features or extensions, which are either not fully stable or we strongly doubt that they are useful for the big public. And if somebody wants to test one of those non-standard extensions, we can ask people to use patch-o-matic.

Yes. I'm aware of that. My question is "How can a patch be proven stable enough to be included, and is the functionality provided 'importent' enough for the general public?

Well, It's hard to give a set of rules for this. Mainly it reduces to the case that I (or somebody else of the coreteam) has the personal feeling that the code is OK and the functionality is important enough.

This sounds a bit like dictatorship, but our impression of what is 'important' is not a fixed one. We judge by the practical cases we know of, and by what users tell us. So if there is a discussion about a particular patch [or feature] on the list, and we see there is a big demand by the users, we are likely to be inclined that this feature is 'needed'. This has just happeed with the 'string' match, which I personally dislike, but I am now convinced that there is a reasonable demand for that particular function [and which will now be submitted to the kernel anytime soon].

It's not different than in other subsystems of the kernel. If you want a feature to get into the core network stack, you need to write good code and convince Alexey, DaveM and/or Andi Kleen that it is needed ;)

btw: having a bit-wise mark match and MARK target has always been one of my favourites. So if we can solve the compatibility issue, the patch will certainly make it ;)

Quoted 2 lines

Regards
Anders Fugmann

Signature · 5 lines
Live long and prosper
- Harald Welte / [email protected]               http://www.gnumonks.org/
============================================================================
GCS/E/IT d- s-: a-- C+++ UL++++$ P+++ L++++$ E--- W- N++ o? K- w--- O- M- 
V-- PS+ PE-- Y+ PGP++ t++ 5-- !X !R tv-- b+++ DI? !D G+ e* h+ r% y+(*)