Skip to contentSkip to conversation

MARK bit operations patch #2

PATCH Anders Fugmann 2 participants 6 messages Jan 14, 2003 – Feb 16, 2003

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

Hi.

I have tried to make the MARK target include
two new operations '--or-mark' and '--and-mark'.

The patch is compatible in the following ways:

new kernel - old userspace: OK
new kernel - old userspace: OK
old kernel - new userspace: OK(*)

* - Only if the new userspace is compiled against the old kernel.

Please comment. I'm not use if the compatibility satifies the requirements needed for such a patch to go into the 2.4 series.

Attached: MARK_TARGET.patch - patch against 2.4 (applies to 2.5 aswell))
Attached: MARK_operations.patch.userspace - patch against iptables .1.2.7a)

Regards
Anders Fugmann

include/linux/netfilter_ipv4/ipt_MARK.h +13 -0
@@ -5,4 +5,17 @@
 	unsigned long mark;
 };
 
+#define MARK_BITOPS 1
+
+enum {
+	IPT_MARK_SET=0,
+	IPT_MARK_AND,
+	IPT_MARK_OR
+};
+
+struct ipt_mark_bitops_target_info {
+	unsigned long mark;
+	u_int8_t mode;
+};
+
 #endif /*_IPT_MARK_H_target*/
net/ipv4/netfilter/ipt_MARK.c +49 -11

92 lines not on this page · raw message

extensions/libipt_MARK.c +76 -18

158 lines not on this page · raw message

#1 lore raw
Quoted 9 lines · Anders Fugmann

Hi.

I have tried to make the MARK target include
two new operations '--or-mark' and '--and-mark'.

The patch is compatible in the following ways:

new kernel - old userspace: OK
new kernel - old userspace: OK

twice the same?

Quoted 6 lines

old kernel - new userspace: OK(*)

* - Only if the new userspace is compiled against the old kernel.

Please comment. I'm not use if the compatibility satifies the requirements needed for such a patch to go into the 2.4 series.

I think this is fine. The major cases we have to think about are:

1) user updates kernel (new kernel, old userspace)
The firewall should start up as expected without any changes in userspace

2) user has old kenel running and is updating iptables userspace In this case iptables userspace has to compile without any warnings.

Quoted 2 lines

Attached: MARK_TARGET.patch - patch against 2.4 (applies to 2.5 aswell))
Attached: MARK_operations.patch.userspace - patch against iptables .1.2.7a)

Looks fine so far. The only issue remaining is:

You are assuming that

IPT_ALIGN(sizeof(struct ipt_mark_target_info))

	!= IPT_ALIGN(sizeof(struct ipt_mark_bitops_target_info))

while this may be true on x86, I assume it is different on 64bit plaforms. Do you have access to any ia64/sparc64/ppc64/mips64 machine with linux?

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 9 lines · Harald Welte
Quoted 4 lines · Anders Fugmann

The patch is compatible in the following ways:

new kernel - old userspace: OK
new kernel - old userspace: OK

twice the same?

My bad, should have said:
new kernel - new userspace: OK
old kernel - new userspace: OK
new kernel - old userspace: OK(*)
* - Only if the new userspace is compiled against the old kernel.

(And of course: old kernel - old userspace :-))

Quoted 9 lines
Quoted 2 lines

Please comment. I'm not use if the compatibility satifies the requirements needed for such a patch to go into the 2.4 series.

I think this is fine. The major cases we have to think about are:

1) user updates kernel (new kernel, old userspace)
The firewall should start up as expected without any changes in userspace

Works.

Quoted 3 lines

2) user has old kenel running and is updating iptables userspace In this case iptables userspace has to compile without any warnings.

Also Works.

Quoted 8 lines
Quoted 4 lines

Attached: MARK_TARGET.patch - patch against 2.4 (applies to 2.5 aswell))
Attached: MARK_operations.patch.userspace - patch against iptables .1.2.7a)

Looks fine so far. The only issue remaining is:

Quoted 8 lines

You are assuming that

IPT_ALIGN(sizeof(struct ipt_mark_target_info))

	!= IPT_ALIGN(sizeof(struct ipt_mark_bitops_target_info))

while this may be true on x86, I assume it is different on 64bit plaforms. Do you have access to any ia64/sparc64/ppc64/mips64 machine with linux?

Unfortunatly not. But why could this introduce an problem on a non x86 platform? Also do you know where to look for more information on this?

I also forgot the manpage update. It will come in the next batch. Thanks for the positive feedback.

Regards
Anders Fugmann

#3 lore raw
Quoted 6 lines · Anders Fugmann

My bad, should have said:
new kernel - new userspace: OK
old kernel - new userspace: OK

new kernel - old userspace: OK(*)
* - Only if the new userspace is compiled against the old kernel.

sorry if I am a PITA, but where does the (*) case have new userspace and old kernel? Either the first or the second line are wrong.

Quoted 11 lines
Quoted 8 lines

You are assuming that

IPT_ALIGN(sizeof(struct ipt_mark_target_info))

	!= IPT_ALIGN(sizeof(struct ipt_mark_bitops_target_info))

while this may be true on x86, I assume it is different on 64bit plaforms. Do you have access to any ia64/sparc64/ppc64/mips64 machine with linux?

Unfortunatly not. But why could this introduce an problem on a non x86 platform? Also do you know where to look for more information on this?

let's assume IPT_ALIGN aligns to 32bit boundaries on a 32bit platform, and 64bit on 64bit platforms.

now we have an old structure containing a 32bit integer IPT_ALIGN()ed to 32bit. Then there is a new structure, aligned to 2*32bit == 64bit.

on the 64bit platform, the old 32bit structure is already aligned to 64bit. And the new structure is aligned to 64bit as well.

Resulting in IPT_ALIGN(sizeof(struct ipt_mark_target_info)) bein exactly the same as IPT_ALIGN(sizeof(struct ipt_mark_bitops_target_info)).

I'm not saying that it really happens right now (I would need to test it) - but theoretically it is possible.

I'd say you make your final patch and I test it on my sparc64 box.

If there are any problems, we have two options

1) assure that IPT_ALIGN(sizeof(struct ipt_mark_bitops_target_info)) is way larger than the older structure (resulting in 128bit)

2) find some other way not depending on the size of the structure (which would be preferred - but how?)

Quoted 2 lines

I also forgot the manpage update. It will come in the next batch. Thanks for the positive feedback.

Thanks for working on this issue.

Quoted 1 line

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
#4 lore raw
Quoted 7 lines · Harald Welte
Quoted 3 lines · Anders Fugmann

My bad, should have said:
new kernel - new userspace: OK
old kernel - new userspace: OK

Quoted 6 lines
Quoted 2 lines

new kernel - old userspace: OK(*)
* - Only if the new userspace is compiled against the old kernel.

sorry if I am a PITA, but where does the (*) case have new userspace and old kernel? Either the first or the second line are wrong.

Sorry, I must be tired. The (*) is for "Old kernel - New userspace". In this case iptables has to be compiled against the correct headers, othervice it will not work.

Quoted 10 lines

let's assume IPT_ALIGN aligns to 32bit boundaries on a 32bit platform, and 64bit on 64bit platforms.

now we have an old structure containing a 32bit integer IPT_ALIGN()ed to 32bit. Then there is a new structure, aligned to 2*32bit == 64bit.

on the 64bit platform, the old 32bit structure is already aligned to 64bit. And the new structure is aligned to 64bit as well.

I see your concern.

Quoted 8 lines

Resulting in IPT_ALIGN(sizeof(struct ipt_mark_target_info)) bein exactly the same as IPT_ALIGN(sizeof(struct ipt_mark_bitops_target_info)).

I'm not saying that it really happens right now (I would need to test it) - but theoretically it is possible.

I'd say you make your final patch and I test it on my sparc64 box.

Perfect. I have attached final patch for kernel/iptables inclusion for you to test and evaluate. The changes include only manpage changes. If included, please update the kernel version for which the extended functionality works (see the userspace patch).

If ok, I will start on making a IPv6 version of the patch (which would follow the same priciple - if you want.

Quoted 5 lines

If there are any problems, we have two options

1) assure that IPT_ALIGN(sizeof(struct ipt_mark_bitops_target_info)) is way larger than the older structure (resulting in 128bit)

Thats not a very good solution - We would be waisting kernel space and most importently it would trach the cache for no reason. Also, in some point in the future 128bit machines will become available, and then the bug is reintroduced.

The structure uses an unsigned long. I thought that this defines the biggest integer machine word available, that is 32 bit on a 32bit arch, and 64 bit on a 64bit arch. Extending the struct by 1 byte, the new alignment of the new struct would always increase.

A bit of googling came up with:
Making code 64 bit clean: http://www.treblig.org/articles/64bits.html

From this article:
"So how long is a long? Well there is no really good definition of that in general! So if you start using a 'long' in place of an 'int' for some reason don't be surprised if it is a different size on a 64 bit platform. So if you are writing values to a hardware register then a 'long' probably isn't a good idea because it will be 64 bits on 64 bit Linux platforms and 32 bit on 32 bit Linux platforms. Other OSs may still keep long at 32 bits on 64 bit systems - so being portable can be difficult."

If this is correct, then there should be no problem. IIRC, there are systems that use 64 bit for the kernel and 32 bit for the userspace, which would really give strange results.

Quoted 3 lines

2) find some other way not depending on the size of the structure (which would be preferred - but how?)

Yes. Testing on the size of the structure is actually not that nice, but
I have no idea of how to do this in a clean manner.
Actually a general "nice to have" feature would be to send along an identifier (magic number), which can be used by modules to see who is calling them. This would require checkentry function signatures to change, which is definatly not 2.4 material.

Quoted 2 lines

Thanks for working on this issue.

My pleasure.

Regards
Anders Fugmann

include/linux/netfilter_ipv4/ipt_MARK.h +13 -0
@@ -5,4 +5,17 @@
 	unsigned long mark;
 };
 
+#define MARK_BITOPS 1
+
+enum {
+	IPT_MARK_SET=0,
+	IPT_MARK_AND,
+	IPT_MARK_OR
+};
+
+struct ipt_mark_bitops_target_info {
+	unsigned long mark;
+	u_int8_t mode;
+};
+
 #endif /*_IPT_MARK_H_target*/
net/ipv4/netfilter/ipt_MARK.c +49 -11

92 lines not on this page · raw message

extensions/libipt_MARK.c +76 -19

158 lines not on this page · raw message

iptables.8 +17 -0
@@ -690,6 +690,23 @@
 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.
+.P
+Since kernel 2.4.21 two additional options to the MARK target have been
+made available. The new options are:
+.TP
+.BI "--and-mark " "mark"
+Binary AND between the current mark value of the packet and the supplied
+.I mark 
+value.
+.TP
+.BI "--or-mark " "mark"
+Binary OR between the current mark value of the packet and 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 
#5 lore raw

Hi Harald.

Did you have the time to test the patch for new mark operations on a 64 bit platform?

Regards
Anders Fugmann