patch for iptables
Hi,
I was so careful testing my new version of condition for binary compatiblity that I didnt't notice it breaks recompilation of the userspace utilities. :)
Here is a patch that uses the new include for the XT version. While I was at it, I updated the sanity checks in order to match the module ones.
One caveat: I break compatibility with older kernels that don't have XT. What's the policy for backward compatibility in iptables? Shall I put a few #ifdefs?
Signature · 2 lines
Saluti, Massimiliano Hofer
extensions/.condition-test +1 -1
@@ -1,3 +1,3 @@ #!/bin/sh # True if condition is applied. -[ -f $KERNEL_DIR/include/linux/netfilter_ipv4/ipt_condition.h ] && echo condition +[ -f $KERNEL_DIR/include/linux/netfilter/xt_condition.h ] && echo condition
extensions/.condition-test6 +1 -1
@@ -1,3 +1,3 @@ #!/bin/sh # True if condition6 is applied. -[ -f $KERNEL_DIR/include/linux/netfilter_ipv6/ip6t_condition.h ] && echo condition +[ -f $KERNEL_DIR/include/linux/netfilter/xt_condition.h ] && echo condition
extensions/libip6t_condition.c +30 -13
82 lines not on this page · raw message
extensions/libipt_condition.c +22 -5
@@ -5,8 +5,7 @@#include <getopt.h> #include <iptables.h> -#include <linux/netfilter_ipv4/ip_tables.h> -#include <linux/netfilter_ipv4/ipt_condition.h> +#include <linux/netfilter/xt_condition.h> static void
@@ -29,6 +28,10 @@ const struct ipt_entry *entry, unsigned int *nfcache, struct ipt_entry_match **match) { + static const char * const forbidden_names[]={ "", ".", ".." }; +const char *name; +int i; +struct condition_info *info = (struct condition_info *) (*match)->data;
@@ -39,12 +42,26 @@check_inverse (optarg, &invert, &optind,0 ); -if (strlen (argv[optind -1 ]) <CONDITION_NAME_LEN ) -strcpy (info->name, argv[optind -1 ]); -else + name = argv[optind -1 ]; +/* We don't want a '/' in a proc file name. */ +for (i=0 ; i <CONDITION_NAME_LEN && name[i] !='\0' ; i++) +if (name[i] =='/' ) +exit_error (PARAMETER_PROBLEM , +"Can't have a '/' in a condition name" ); + +/* We can't handle file names longer than CONDITION_NAME_LEN and */ +/* we want a NULL terminated string. */ +if (i ==CONDITION_NAME_LEN )exit_error (PARAMETER_PROBLEM ,"File name too long" ); +/* We don't want certain reserved names. */ +for (i=0 ; i <sizeof (forbidden_names)/sizeof (char *); i++) +if (strcmp (name, forbidden_names[i])==0 ) +exit_error (PARAMETER_PROBLEM , +"Forbidden condition name" ); + +strcpy (info->name, name); info->invert = invert; *flags =1 ;return 1 ;
include/linux/netfilter/xt_condition.h +11 -0
@@ -0,0 +1,11 @@ +#ifndef _XT_CONDITION_H +#define _XT_CONDITION_H + +#define CONDITION_NAME_LEN 32 + +struct condition_info { +char name[CONDITION_NAME_LEN ]; +int invert; +}; + +#endif /* _XT_CONDITION_H */
Quoted 2 lines · Massimiliano Hofer
Here is a patch that uses the new include for the XT version. While I was at it, I updated the sanity checks in order to match the module ones.
Please disregard this patch. I uploaded a version made before a cleanup. This is the real patch.
Signature · 2 lines
Saluti, Massimiliano Hofer
extensions/.condition-test +1 -1
@@ -1,3 +1,3 @@ #!/bin/sh # True if condition is applied. -[ -f $KERNEL_DIR/include/linux/netfilter_ipv4/ipt_condition.h ] && echo condition +[ -f $KERNEL_DIR/include/linux/netfilter/xt_condition.h ] && echo condition
extensions/.condition-test6 +1 -1
@@ -1,3 +1,3 @@ #!/bin/sh # True if condition6 is applied. -[ -f $KERNEL_DIR/include/linux/netfilter_ipv6/ip6t_condition.h ] && echo condition +[ -f $KERNEL_DIR/include/linux/netfilter/xt_condition.h ] && echo condition
extensions/libip6t_condition.c +30 -13
82 lines not on this page · raw message
extensions/libipt_condition.c +22 -5
@@ -5,8 +5,7 @@#include <getopt.h> #include <iptables.h> -#include <linux/netfilter_ipv4/ip_tables.h> -#include <linux/netfilter_ipv4/ipt_condition.h> +#include <linux/netfilter/xt_condition.h> static void
@@ -29,6 +28,10 @@ const struct ipt_entry *entry, unsigned int *nfcache, struct ipt_entry_match **match) { + static const char * const forbidden_names[]={ "", ".", ".." }; +const char *name; +int i; +struct condition_info *info = (struct condition_info *) (*match)->data;
@@ -39,12 +42,26 @@check_inverse (optarg, &invert, &optind,0 ); -if (strlen (argv[optind -1 ]) <CONDITION_NAME_LEN ) -strcpy (info->name, argv[optind -1 ]); -else + name = argv[optind -1 ]; +/* We don't want a '/' in a proc file name. */ +for (i=0 ; i <CONDITION_NAME_LEN && name[i] !='\0' ; i++) +if (name[i] =='/' ) +exit_error (PARAMETER_PROBLEM , +"Can't have a '/' in a condition name" ); + +/* We can't handle file names longer than CONDITION_NAME_LEN and */ +/* we want a NULL terminated string. */ +if (i ==CONDITION_NAME_LEN )exit_error (PARAMETER_PROBLEM ,"File name too long" ); +/* We don't want certain reserved names. */ +for (i=0 ; i <sizeof (forbidden_names)/sizeof (char *); i++) +if (strcmp (name, forbidden_names[i])==0 ) +exit_error (PARAMETER_PROBLEM , +"Forbidden condition name" ); + +strcpy (info->name, name); info->invert = invert; *flags =1 ;return 1 ;
Pablo Neira Ayuso
maintainerQuoted 5 lines · Massimiliano Hofer
I was so careful testing my new version of condition for binary compatiblity that I didnt't notice it breaks recompilation of the userspace utilities. :)
Here is a patch that uses the new include for the XT version. While I was at it, I updated the sanity checks in order to match the module ones.
One caveat: I break compatibility with older kernels that don't have XT. What's the policy for backward compatibility in iptables? Shall I put a few #ifdefs?
The official policy is "do not break backward" :). IHMO, if we want to go further with iptables we need to think about providing a netlink API.
For out-of-tree stuff the thing can be different, I have seen breakages if it really required it. For example, the string match is not compatible with the old and broken match for 2.4.
Please see below a comment about your patch:
extensions/.condition-test line 3
Quoted 10 lines
------------------------------------------------------------------------
diff -Nru iptables-1.3.5-20060820.orig/extensions/.condition-test iptables-1.3.5-20060820/extensions/.condition-test
extensions/.condition-test +1
-1@@ -1,3 +1,3 @@ #!/bin/sh # True if condition is applied. -[ -f $KERNEL_DIR/include/linux/netfilter_ipv4/ipt_condition.h ] && echo condition +[ -f $KERNEL_DIR/include/linux/netfilter/xt_condition.h ] && echo condition
You don't need to break it. Just put a dummy ipt_condition.h file that points to xt_condition.h
Signature · 1 line
The dawn of the fourth age of Linux firewalling is coming; a time of great struggle and heroic deeds -- J.Kadlecsik got inspired by J.Morris
Quoted 6 lines · Pablo Neira Ayuso
The official policy is "do not break backward" :). IHMO, if we want to go further with iptables we need to think about providing a netlink API.
For out-of-tree stuff the thing can be different, I have seen breakages if it really required it. For example, the string match is not compatible with the old and broken match for 2.4.
OK. I will send a backward compatible version in a few hours. With new things as XT, however, many things may move on the kernel side and there's no reason for the userspace build system to meddle in the kernel includes.
Maybe we sould just do a non-mandatory check in $KERNEL/.config (or /proc/config.gz where available) and just keep a coherent set of includes with proper structures and associated version numbers?
Signature · 3 lines
Saluti,
Massimiliano Hofer
NucleusQuoted 6 lines · Pablo Neira Ayuso
The official policy is "do not break backward" :). IHMO, if we want to go further with iptables we need to think about providing a netlink API.
For out-of-tree stuff the thing can be different, I have seen breakages if it really required it. For example, the string match is not compatible with the old and broken match for 2.4.
I'd like to make it backward compatible, but, so far, I've seen only these possibilities:
a) put a legacy include in the kernel part (ugly);
b) put a kernel version #ifdef in the userspace part (invasive of the build system, since, as far as I can tell, no such #defines are present);
c) drop support (it's... well... unsupportive :)).
Of course you could add "d) you're boneheaded and there's a great solution, it's just that you can't find it". :)
To be frank, I'm not a great fan of userspace build systems that meddle too much in the kernel, especially if it's just a few structures and you're committed to keep backward compatibility anyway. It would be more convinient if, for example, I could build iptables with lots of extension I don't have in my kernel. It would be even more convenient if I tried to package an RPM and I didn't want to depend on specific kernel patches being installed.
Anyway, I'd tend to discard a) and would like not to choose c). Would you accept a patch that introduces kernel version #defines? Do you have better solutions?
Signature · 3 lines
Saluti,
Massimiliano Hofer
NucleusPablo Neira Ayuso
maintainerQuoted 16 lines · Massimiliano Hofer
Quoted 6 lines · Pablo Neira Ayuso
The official policy is "do not break backward" :). IHMO, if we want to go further with iptables we need to think about providing a netlink API.
For out-of-tree stuff the thing can be different, I have seen breakages if it really required it. For example, the string match is not compatible with the old and broken match for 2.4.
I'd like to make it backward compatible, but, so far, I've seen only these possibilities:
a) put a legacy include in the kernel part (ugly);
b) put a kernel version #ifdef in the userspace part (invasive of the build system, since, as far as I can tell, no such #defines are present);
c) drop support (it's... well... unsupportive :)).
Quoted 5 lines
Of course you could add "d) you're boneheaded and there's a great solution, it's just that you can't find it". :)
To be frank, I'm not a great fan of userspace build systems that meddle too much in the kernel,
Nor me but this is something that we have to live with. I think we all have learnt the lesson: the new netlink libraries for queue, log, conntrack don't share whole structures between kernel and userspace, so we don't need to get fixed to a certain layout.
Quoted 5 lines
especially if it's just a few structures and you're
committed to keep backward compatibility anyway. It would be more convinient if, for example, I could build iptables with lots of extension I don't have in my kernel. It would be even more convenient if I tried to package an RPM and I didn't want to depend on specific kernel patches being installed.
I understand your situation but breaking backward compatibility is not the solution. About the possibility of including the version support, I proposed the revision thing for matches/targets time ago and I must confess that I don't like it so much: it was a hack, we need it for popular revisions of multiport and mark but we decided that people might have really good reasons to add a new version. So, introducing another revision thing is not something that I like.
Quoted 3 lines
Anyway, I'd tend to discard a) and would like not to choose c). Would you accept a patch that introduces kernel version #defines? Do you have better solutions?
To implement a netlink interface for iptables.
Signature · 2 lines
The dawn of the fourth age of Linux firewalling is coming; a time of great struggle and heroic deeds -- J.Kadlecsik got inspired by J.Morris
Quoted 7 lines · Pablo Neira Ayuso
I understand your situation but breaking backward compatibility is not the solution. About the possibility of including the version support, I proposed the revision thing for matches/targets time ago and I must confess that I don't like it so much: it was a hack, we need it for popular revisions of multiport and mark but we decided that people might have really good reasons to add a new version. So, introducing another revision thing is not something that I like.
I wasn't all that convinced myself. We would end up with multiple userspace revision support in kernel and multiple kernel revision support in userspace. This has the potential of becoming a real mess.
I found a better hack (but a hack nonetheless) using #defines and I attach it. It's been tested with kernels 2.6.1[5-8].
Please consider it for inclusion in the current iptables.
Quoted 5 lines
Quoted 3 lines
Anyway, I'd tend to discard a) and would like not to choose c). Would you accept a patch that introduces kernel version #defines? Do you have better solutions?
To implement a netlink interface for iptables.
I hoped for something less drastic and more immediate. In the long run you may be right.
Signature · 3 lines
Saluti,
Massimiliano Hofer
Nucleusextensions/.condition-test +3 -1
@@ -1,3 +1,5 @@ #!/bin/sh # True if condition is applied. -[ -f $KERNEL_DIR/include/linux/netfilter_ipv4/ipt_condition.h ] && echo condition +( [ -f $KERNEL_DIR/include/linux/netfilter_ipv4/ipt_condition.h ] || + [ -f $KERNEL_DIR/include/linux/netfilter/xt_condition.h ] ) && + echo condition
extensions/.condition-test6 +3 -1
@@ -1,3 +1,5 @@ #!/bin/sh # True if condition6 is applied. -[ -f $KERNEL_DIR/include/linux/netfilter_ipv6/ip6t_condition.h ] && echo condition +( [ -f $KERNEL_DIR/include/linux/netfilter_ipv6/ip6t_condition.h ] || + [ -f $KERNEL_DIR/include/linux/netfilter/xt_condition.h ] ) && + echo condition
extensions/libip6t_condition.c +36 -11
87 lines not on this page · raw message
extensions/libip6t_condition.man +1 -1
@@ -1,4 +1,4 @@ This matches if a specific /proc filename is '0' or '1'. .TP .BR "--condition " "[!] \fIfilename" -Match on boolean value stored in /proc/net/ip6t_condition/filename file +Match on boolean value stored in /proc/net/nf_condition/filename file
extensions/libipt_condition.c +26 -3
@@ -6,7 +6,12 @@#include <iptables.h> #include <linux/netfilter_ipv4/ip_tables.h> + +#ifndef _X_TABLES_H#include <linux/netfilter_ipv4/ipt_condition.h> +#else +#include <linux/netfilter/xt_condition.h> +#endif static void
@@ -29,6 +34,10 @@ const struct ipt_entry *entry, unsigned int *nfcache, struct ipt_entry_match **match) { + static const char * const forbidden_names[]={ "", ".", ".." }; +const char *name; +int i; +struct condition_info *info = (struct condition_info *) (*match)->data;
@@ -39,12 +48,26 @@check_inverse (optarg, &invert, &optind,0 ); -if (strlen (argv[optind -1 ]) <CONDITION_NAME_LEN ) -strcpy (info->name, argv[optind -1 ]); -else + name = argv[optind -1 ]; +/* We don't want a '/' in a proc file name. */ +for (i=0 ; i <CONDITION_NAME_LEN && name[i] !='\0' ; i++) +if (name[i] =='/' ) +exit_error (PARAMETER_PROBLEM , +"Can't have a '/' in a condition name" ); + +/* We can't handle file names longer than CONDITION_NAME_LEN and */ +/* we want a NULL terminated string. */ +if (i ==CONDITION_NAME_LEN )exit_error (PARAMETER_PROBLEM ,"File name too long" ); +/* We don't want certain reserved names. */ +for (i=0 ; i <sizeof (forbidden_names)/sizeof (char *); i++) +if (strcmp (name, forbidden_names[i])==0 ) +exit_error (PARAMETER_PROBLEM , +"Forbidden condition name" ); + +strcpy (info->name, name); info->invert = invert; *flags =1 ;return 1 ;
extensions/libipt_condition.man +1 -1
@@ -1,4 +1,4 @@ This matches if a specific /proc filename is '0' or '1'. .TP .BI "--condition " "[!] \fIfilename\fP" -Match on boolean value stored in /proc/net/ipt_condition/filename file +Match on boolean value stored in /proc/net/nf_condition/filename file