iptables version defines
PATCH 1/1 iptables version defines
Hi Patrick,
[resent as I somehow sent an HTML email at first]
Quoted 6 lines
Quoted 6 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
#ifdef
_XTABLES_Hinit(struct xt_entry_target *t)
#elseinit(struct ipt_entry_target *t, unsigned int *nfcache)#endif
Quoted 6 lines
Quoted 2 lines
Woah this is ridiculously ugly. (Remember, such constructs were just eliminated from the kernel in the past years.)
I don't care about uglyness as long as it stays in external code. So if someone sends me a patch to add this version define, I'll add it.
External code has to be "ugly" if you want to keep the user experience high. I don't feel like breaking ipt_ACCOUNT for older iptables versions without any real gain, it should work out of the box with iptables 1.4.0 and 1.4.1.
Attached is a patch to add the new defines. The macro XTABLES_VERSION is already in use, so I named it XTABLES_VERSION_CHECK. I've also tested that an empty XTABLES_VERSION_EXTRA in configure.ac works.
Now we can write code like this:
#if XTABLES_VERSION_CODE < XTABLES_VERSION_CHECK(1,5,0) #warning You are obselete and will be assimilated. #endif
Cheers,
Thomas
Add xtables version defines.
configure.ac +17 -1
@@ -1,5 +1,11 @@ +define([_XTABLES_VERSION_MAJOR], 1) +define([_XTABLES_VERSION_MINOR], 4) +define([_XTABLES_VERSION_PATCH], 1) +define([_XTABLES_VERSION_EXTRA], -rc2) -AC_INIT([iptables], [1.4.1-rc2]) +define([_XTABLES_VERSION],_XTABLES_VERSION_MAJOR._XTABLES_VERSION_MINOR._XTABLES_VERSION_PATCH[]_XTABLES_VERSION_EXTRA) + +AC_INIT([iptables], _XTABLES_VERSION) AC_CONFIG_HEADERS([config.h]) AC_PROG_INSTALL AM_INIT_AUTOMAKE
@@ -56,4 +62,14 @@ AC_SUBST([kbuilddir]) AC_SUBST([ksourcedir]) AC_SUBST([xtlibdir]) + +XTABLES_VERSION_MAJOR=_XTABLES_VERSION_MAJOR +XTABLES_VERSION_MINOR=_XTABLES_VERSION_MINOR +XTABLES_VERSION_PATCH=_XTABLES_VERSION_PATCH +XTABLES_VERSION_EXTRA=_XTABLES_VERSION_EXTRA +AC_SUBST([XTABLES_VERSION_MAJOR]) +AC_SUBST([XTABLES_VERSION_MINOR]) +AC_SUBST([XTABLES_VERSION_PATCH]) +AC_SUBST([XTABLES_VERSION_EXTRA]) + AC_OUTPUT([Makefile extensions/GNUmakefile libipq/Makefile include/xtables.h])
include/xtables.h.in +6 -0
@@ -18,6 +18,12 @@ #endif #define XTABLES_VERSION "@PACKAGE_VERSION@" +#define XTABLES_VERSION_CODE (0x10000 * @XTABLES_VERSION_MAJOR@ + 0x100 * @XTABLES_VERSION_MINOR@ + @XTABLES_VERSION_PATCH@) + +#define XTABLES_VERSION_CHECK(x,y,z) (0x10000*(x) + 0x100*(y) + z) +#define XTABLES_VERSION_MAJOR(x) (((x)>>16) & 0xFF) +#define XTABLES_VERSION_MINOR(x) (((x)>> 8) & 0xFF) +#define XTABLES_VERSION_PATCH(x) ( (x) & 0xFF) /* Include file for additions: new matches and targets. */ struct xtables_match
Quoted 8 lines · Thomas Jarosch
Quoted 3 lines
I don't care about uglyness as long as it stays in external code. So if someone sends me a patch to add this version define, I'll add it.
External code has to be "ugly" if you want to keep the user experience high. I don't feel like breaking
ipt_ACCOUNTfor older iptables versions without any real gain, it should work out of the box with iptables 1.4.0 and 1.4.1.
External code does not _necessarily_ have to be ugly; at least one can make it so as to reduce the lot of redundant #if hackery; xt-a does this for the kernel interface already, it should not be hard to do the same for the iptables API once it becomes necessary. For that to work, we need a XTABLES_VERSION_CODE, and since your patch does just that, you get my approval. Comments follow...
Quoted 37 lines
Add xtables version defines.
Signed-off-by Thomas Jarosch <[email protected]>configure.ac +7
-1@@ -1,5 +1,11 @@ +define([_XTABLES_VERSION_MAJOR], 1) +define([_XTABLES_VERSION_MINOR], 4) +define([_XTABLES_VERSION_PATCH], 1) +define([_XTABLES_VERSION_EXTRA], -rc2) -AC_INIT([iptables], [1.4.1-rc2]) +define([_XTABLES_VERSION],_XTABLES_VERSION_MAJOR._XTABLES_VERSION_MINOR._XTABLES_VERSION_PATCH[]_XTABLES_VERSION_EXTRA) + +AC_INIT([iptables], _XTABLES_VERSION) AC_CONFIG_HEADERS([config.h])
AC_PROG_INSTALLAM_INIT_AUTOMAKEconfigure.ac +10
-0@@ -56,4 +62,14 @@ AC_SUBST([kbuilddir]) AC_SUBST([ksourcedir]) AC_SUBST([xtlibdir]) + +XTABLES_VERSION_MAJOR=_XTABLES_VERSION_MAJOR +XTABLES_VERSION_MINOR=_XTABLES_VERSION_MINOR +XTABLES_VERSION_PATCH=_XTABLES_VERSION_PATCH +XTABLES_VERSION_EXTRA=_XTABLES_VERSION_EXTRA +AC_SUBST([XTABLES_VERSION_MAJOR]) +AC_SUBST([XTABLES_VERSION_MINOR]) +AC_SUBST([XTABLES_VERSION_PATCH]) +AC_SUBST([XTABLES_VERSION_EXTRA]) + AC_OUTPUT([Makefile extensions/GNUmakefile libipq/Makefile include/xtables.h])
include/xtables.h.in line 23
Quoted 6 lines
include/xtables.h.in +3
-0@@ -18,6 +18,12 @@ #endif #define XTABLES_VERSION "@PACKAGE_VERSION@" +#define XTABLES_VERSION_CODE (0x10000 * @XTABLES_VERSION_MAJOR@ + 0x100 * @XTABLES_VERSION_MINOR@ + @XTABLES_VERSION_PATCH@) + +#define XTABLES_VERSION_CHECK(x,y,z) (0x10000*(x) + 0x100*(y) + z)
Mh.... too much arithmetic for my taste, just use bitops like linux/version.h. Also, regarding the _CHECK name, I'd propose "XTABLES_API_VERSION" instead, which should look nicer on
#if XTABLES_VERSION_CODE < XTABLES_API_VERSION(1,4,0) #error Upgrade, yo! #endif
#define XTABLES_API_VERSION(a,b,c) (((a) << 16) | ((b) << 8) | (c))
include/xtables.h.in line 26
Quoted 3 lines
include/xtables.h.in +3
-0+#define XTABLES_VERSION_MAJOR(x) (((x)>>16) & 0xFF) +#define XTABLES_VERSION_MINOR(x) (((x)>> 8) & 0xFF) +#define XTABLES_VERSION_PATCH(x) ( (x) & 0xFF)
I do not see a need for these three. The linux kernel does not have such either, so please don't overdesign :)
Jan,
Quoted 8 lines · On Monday, 2. June 2008 16:54:57 you wrote:
Quoted 4 lines
#define
XTABLES_VERSION"@PACKAGE_VERSION@"
+#defineXTABLES_VERSION_CODE(0x10000* @XTABLES_VERSION_MAJOR@ +0x100* @XTABLES_VERSION_MINOR@ + @XTABLES_VERSION_PATCH@) +
+#defineXTABLES_VERSION_CHECK(x,y,z)(0x10000*(x) + 0x100*(y) + z)Mh.... too much arithmetic for my taste, just use bitops like
linux/version.h. Also, regarding the_CHECKname, I'd propose "XTABLES_API_VERSION" instead, which should look nicer on
Quoted 6 lines
#if XTABLES_VERSION_CODE < XTABLES_API_VERSION(1,4,0) #error Upgrade, yo! #endif#define
XTABLES_API_VERSION(a,b,c)(((a) << 16) | ((b) << 8) | (c))
As you already pointed out, it's a matter of taste and neither of both versions will hurt as it will be expanded at compile time.
Infact, imagine we would add another version level like "(x) << 32", on x86 it is only valid to do a left shift operation for 0-31 bits and so it could fail...
Quoted 6 lines
Review
Quoted 3 lines
(quoted diff) +3
-0+#define XTABLES_VERSION_MAJOR(x) (((x)>>16) & 0xFF) +#define XTABLES_VERSION_MINOR(x) (((x)>> 8) & 0xFF) +#define XTABLES_VERSION_PATCH(x) ( (x) & 0xFF)I do not see a need for these three. The linux kernel does not have such either, so please don't overdesign :)
Well, I've created the same macros as there are already in include/iptables.h.
I'm alright with your proposed change to XTABLES_API_VERSION and the drop of _MAJOR, _MINOR and _PATCH macros as
one can easily check for same thing via "xyz < XTABLES_API_VERSION(2,6,0)"
Attached is an updated patch.
Thomas
Add xtables version defines.
configure.ac +17 -1
@@ -1,5 +1,11 @@ +define([_XTABLES_VERSION_MAJOR], 1) +define([_XTABLES_VERSION_MINOR], 4) +define([_XTABLES_VERSION_PATCH], 1) +define([_XTABLES_VERSION_EXTRA], -rc2) -AC_INIT([iptables], [1.4.1-rc2]) +define([_XTABLES_VERSION],_XTABLES_VERSION_MAJOR._XTABLES_VERSION_MINOR._XTABLES_VERSION_PATCH[]_XTABLES_VERSION_EXTRA) + +AC_INIT([iptables], _XTABLES_VERSION) AC_CONFIG_HEADERS([config.h]) AC_PROG_INSTALL AM_INIT_AUTOMAKE
@@ -56,4 +62,14 @@ AC_SUBST([kbuilddir]) AC_SUBST([ksourcedir]) AC_SUBST([xtlibdir]) + +XTABLES_VERSION_MAJOR=_XTABLES_VERSION_MAJOR +XTABLES_VERSION_MINOR=_XTABLES_VERSION_MINOR +XTABLES_VERSION_PATCH=_XTABLES_VERSION_PATCH +XTABLES_VERSION_EXTRA=_XTABLES_VERSION_EXTRA +AC_SUBST([XTABLES_VERSION_MAJOR]) +AC_SUBST([XTABLES_VERSION_MINOR]) +AC_SUBST([XTABLES_VERSION_PATCH]) +AC_SUBST([XTABLES_VERSION_EXTRA]) + AC_OUTPUT([Makefile extensions/GNUmakefile libipq/Makefile include/xtables.h])
include/xtables.h.in +3 -0
@@ -18,6 +18,9 @@ #endif #define XTABLES_VERSION "@PACKAGE_VERSION@" +#define XTABLES_VERSION_CODE (0x10000 * @XTABLES_VERSION_MAJOR@ + 0x100 * @XTABLES_VERSION_MINOR@ + @XTABLES_VERSION_PATCH@) + +#define XTABLES_API_VERSION(x,y,z) (0x10000*(x) + 0x100*(y) + z) /* Include file for additions: new matches and targets. */ struct xtables_match
Quoted 10 lines · Thomas Jarosch
Jan,
Quoted 2 lines
#define
XTABLES_API_VERSION(a,b,c)(((a) << 16) | ((b) << 8) | (c))As you already pointed out, it's a matter of taste and neither of both versions will hurt as it will be expanded at compile time.
Infact, imagine we would add another version level like "(x) << 32", on x86 it is only valid to do a left shift operation for 0-31 bits and so it could fail...
First, you would use << 24 not << 32 :-)
Even so, << 32 is perfectly valid if you correctly declare it as a unsigned long long.
Quoted 8 lines
Quoted 6 lines
Review
Quoted 3 lines
(quoted diff) +3
-0+#define XTABLES_VERSION_MAJOR(x) (((x)>>16) & 0xFF) +#define XTABLES_VERSION_MINOR(x) (((x)>> 8) & 0xFF) +#define XTABLES_VERSION_PATCH(x) ( (x) & 0xFF)I do not see a need for these three. The linux kernel does not have such either, so please don't overdesign :)
Well, I've created the same macros as there are already in
include/iptables.h.
That's just leftover, they are not used either.
Quoted 5 lines
I'm alright with your proposed change to
XTABLES_API_VERSIONand the drop of_MAJOR,_MINORand_PATCHmacros as
one can easily check for same thing via "xyz <XTABLES_API_VERSION(2,6,0)"Attached is an updated patch.
I approve.
Quoted 5 lines · Thomas Jarosch
I'm alright with your proposed change to
XTABLES_API_VERSIONand the drop of_MAJOR,_MINORand_PATCHmacros as
one can easily check for same thing via "xyz <XTABLES_API_VERSION(2,6,0)"Attached is an updated patch.
Applied and pushed out, thanks.