netfilter 00/08: netfilter update
Subsystems (3)
Hi Dave,
following is the probably final netfilter update for 2.6.34, containing:
- an IPv6 reassembly fix for packets "fragmented" into a single fragment from myself
- an fix for an overflow and a false match in the recent match from Tim Gardner
- replacement of the xtables iteration macros by a set of new macros behaving more like the regular list iteration macros from Jan
Please apply or pull from:
git://git.kernel.org/pub/scm/linux/kernel/git/kaber/nf-next-2.6.git master
Thanks!
include/linux/netfilter/x_tables.h | 17 ++ include/linux/netfilter_arp/arp_tables.h | 10 +- include/linux/netfilter_ipv4/ip_tables.h | 15 +- include/linux/netfilter_ipv6/ip6_tables.h | 14 +- net/ipv4/netfilter/arp_tables.c | 301 +++++++++----------- net/ipv4/netfilter/ip_tables.c | 436 ++++++++++++++--------------- net/ipv6/netfilter/ip6_tables.c | 436 ++++++++++++++--------------- net/ipv6/netfilter/nf_conntrack_reasm.c | 8 +- net/netfilter/xt_TCPMSS.c | 12 +- net/netfilter/xt_recent.c | 4 +- 10 files changed, 597 insertions(+), 656 deletions(-)
Jan Engelhardt (5):
netfilter: xtables: replace XT_ENTRY_ITERATE macro
netfilter: xtables: optimize call flow around xt_entry_foreach
netfilter: xtables: replace XT_MATCH_ITERATE macro
netfilter: xtables: optimize call flow around xt_ematch_foreach
netfilter: xtables: reduce arguments to translate_table
Patrick McHardy (1):
netfilter: nf_conntrack_reasm: properly handle packets fragmented into a single fragment
Tim Gardner (2):
netfilter: xt_recent: fix buffer overflow
netfilter: xt_recent: fix false match
netfilter 01/08: nf_conntrack_reasm: properly handle packets fragmented into a single fragment
commit 9e2dcf72023d1447f09c47d77c99b0c49659e5ce
Author: Patrick McHardy <[email protected]> Date: Fri Feb 19 18:18:37 2010 +0100
netfilter: nf_conntrack_reasm: properly handle packets fragmented into a single fragment
When an ICMPV6_PKT_TOOBIG message is received with a MTU below 1280, all further packets include a fragment header.
Unlike regular defragmentation, conntrack also needs to "reassemble" those fragments in order to obtain a packet without the fragment header for connection tracking. Currently nf_conntrack_reasm checks whether a fragment has either IP6_MF set or an offset != 0, which makes it ignore those fragments.
Remove the invalid check and make reassembly handle fragment queues containing only a single fragment.
net/ipv6/netfilter/nf_conntrack_reasm.c +1 -7
@@ -469,7 +469,7 @@ nf_ct_frag6_reasm(struct nf_ct_frag6_queue *fq, struct net_device *dev)/* all original skbs are linked into the NFCT_FRAG6_CB(head).orig */ fp =skb_shinfo (head)->frag_list; -if (NFCT_FRAG6_CB (fp)->orig ==NULL ) +if (fp &&NFCT_FRAG6_CB (fp)->orig ==NULL )/* at above code, head skb is divided into two skbs. */ fp = fp->next;
@@ -595,12 +595,6 @@ struct sk_buff *nf_ct_frag6_gather(struct sk_buff *skb, u32 user) hdr =ipv6_hdr (clone); fhdr = (struct frag_hdr *)skb_transport_header (clone); -if (!(fhdr->frag_off &htons (0xFFF9 ))) { -pr_debug ("Invalid fragment offset\n" ); -/* It is not a fragmented frame */ - goto ret_orig; - } -if (atomic_read (&nf_init_frags.mem) > nf_init_frags.high_thresh)nf_ct_frag6_evictor ();
netfilter 02/08: xt_recent: fix buffer overflow
In reply to Patrick McHardycommit 2c08522e5d2f0af2d6f05be558946dcbf8173683
Author: Tim Gardner <[email protected]> Date: Tue Feb 23 14:55:21 2010 +0100
netfilter: xt_recent: fix buffer overflow
e->index overflows e->stamps[] every ip_pkt_list_tot packets.
Consider the case when ip_pkt_list_tot==1; the first packet received is stored
in e->stamps[0] and e->index is initialized to 1. The next received packet
timestamp is then stored at e->stamps[1] in recent_entry_update(),
a buffer overflow because the maximum e->stamps[] index is 0.
Signed-off-by: Tim Gardner <[email protected]>
Cc: [email protected]
Signed-off-by: Patrick McHardy <[email protected]>net/netfilter/xt_recent.c +1 -1
@@ -177,10 +177,10 @@ recent_entry_init(struct recent_table *t, const union nf_inet_addr *addr,static void recent_entry_update (struct recent_table *t,struct recent_entry *e) { + e->index %= ip_pkt_list_tot; e->stamps[e->index++] = jiffies;if (e->index > e->nstamps) e->nstamps = e->index; - e->index %= ip_pkt_list_tot;list_move_tail (&e->lru_list, &t->lru_list); }
netfilter 03/08: xt_recent: fix false match
In reply to Patrick McHardycommit 8ccb92ad41cb311e52ad1b1fe77992c7f47a3b63
Author: Tim Gardner <[email protected]> Date: Tue Feb 23 14:59:12 2010 +0100
netfilter: xt_recent: fix false match
A rule with a zero hit_count will always match.
net/netfilter/xt_recent.c +1 -1
@@ -267,7 +267,7 @@ recent_mt(const struct sk_buff *skb, const struct xt_match_param *par)for (i =0 ; i < e->nstamps; i++) {if (info->seconds &&time_after (time, e->stamps[i]))continue ; -if (++hits >= info->hit_count) { +if (info->hit_count && ++hits >= info->hit_count) { ret = !ret;break ; }
netfilter 04/08: xtables: replace XT_ENTRY_ITERATE macro
In reply to Patrick McHardycommit 72b2b1dd77e8feb0b7c0b26dee58f2a1e2c9828c
Author: Jan Engelhardt <[email protected]> Date: Wed Feb 24 18:32:59 2010 +0100
netfilter: xtables: replace XT_ENTRY_ITERATE macro
The macro is replaced by a list.h-like foreach loop. This makes the code much more inspectable.
include/linux/netfilter/x_tables.h +9 -0
@@ -139,6 +139,7 @@ struct xt_counters_info { __ret; \ }) +#ifndef __KERNEL__/* fn returns 0 to continue iteration */ #define XT_ENTRY_ITERATE_CONTINUE(type, entries, size, n, fn, args...) \ ({ \
@@ -163,6 +164,14 @@ struct xt_counters_info { #define XT_ENTRY_ITERATE(type, entries, size, fn, args...) \ XT_ENTRY_ITERATE_CONTINUE(type, entries, size, 0, fn, args) +#endif /* !__KERNEL__ */ + +/* pos is normally a struct ipt_entry/ip6t_entry/etc. */ +#define xt_entry_foreach (pos, ehead, esize) \ + for ((pos) = (typeof(pos))(ehead); \ + (pos) < (typeof(pos))((char *)(ehead) + (esize)); \ + (pos) = (typeof(pos))((char *)(pos) + (pos)->next_offset)) +#ifdef __KERNEL__#include <linux/netdevice.h>
include/linux/netfilter_arp/arp_tables.h +2 -8
@@ -211,9 +211,11 @@ static __inline__ struct arpt_entry_target *arpt_get_target(struct arpt_entry *ereturn (void *)e + e->target_offset; } +#ifndef __KERNEL__/* fn returns 0 to continue iteration */ #define ARPT_ENTRY_ITERATE(entries, size, fn, args...) \ XT_ENTRY_ITERATE(struct arpt_entry, entries, size, fn, ## args) +#endif /* * Main firewall chains definitions and global var's definitions.
@@ -291,14 +293,6 @@ compat_arpt_get_target(struct compat_arpt_entry *e)#define COMPAT_ARPT_ALIGN (s) COMPAT_XT_ALIGN(s) -/* fn returns 0 to continue iteration */ -#define COMPAT_ARPT_ENTRY_ITERATE(entries, size, fn, args...) \ - XT_ENTRY_ITERATE(struct compat_arpt_entry, entries, size, fn, ## args) - -#define COMPAT_ARPT_ENTRY_ITERATE_CONTINUE(entries, size, n, fn, args...) \ - XT_ENTRY_ITERATE_CONTINUE(struct compat_arpt_entry, entries, size, n, \ - fn, ## args) -#endif /* CONFIG_COMPAT */ #endif /*__KERNEL__*/ #endif /* _ARPTABLES_H */
include/linux/netfilter_ipv4/ip_tables.h +2 -9
@@ -227,9 +227,11 @@ ipt_get_target(struct ipt_entry *e) #define IPT_MATCH_ITERATE(e, fn, args...) \ XT_MATCH_ITERATE(struct ipt_entry, e, fn, ## args) +#ifndef __KERNEL__/* fn returns 0 to continue iteration */ #define IPT_ENTRY_ITERATE(entries, size, fn, args...) \ XT_ENTRY_ITERATE(struct ipt_entry, entries, size, fn, ## args) +#endif /* * Main firewall chains definitions and global var's definitions.
@@ -317,15 +319,6 @@ compat_ipt_get_target(struct compat_ipt_entry *e) #define COMPAT_IPT_MATCH_ITERATE(e, fn, args...) \ XT_MATCH_ITERATE(struct compat_ipt_entry, e, fn, ## args) -/* fn returns 0 to continue iteration */ -#define COMPAT_IPT_ENTRY_ITERATE(entries, size, fn, args...) \ - XT_ENTRY_ITERATE(struct compat_ipt_entry, entries, size, fn, ## args) - -/* fn returns 0 to continue iteration */ -#define COMPAT_IPT_ENTRY_ITERATE_CONTINUE(entries, size, n, fn, args...) \ - XT_ENTRY_ITERATE_CONTINUE(struct compat_ipt_entry, entries, size, n, \ - fn, ## args) -#endif /* CONFIG_COMPAT */ #endif /*__KERNEL__*/ #endif /* _IPTABLES_H */
include/linux/netfilter_ipv6/ip6_tables.h +2 -8
@@ -284,9 +284,11 @@ ip6t_get_target(struct ip6t_entry *e) #define IP6T_MATCH_ITERATE(e, fn, args...) \ XT_MATCH_ITERATE(struct ip6t_entry, e, fn, ## args) +#ifndef __KERNEL__/* fn returns 0 to continue iteration */ #define IP6T_ENTRY_ITERATE(entries, size, fn, args...) \ XT_ENTRY_ITERATE(struct ip6t_entry, entries, size, fn, ## args) +#endif /* * Main firewall chains definitions and global var's definitions.
@@ -345,14 +347,6 @@ compat_ip6t_get_target(struct compat_ip6t_entry *e) #define COMPAT_IP6T_MATCH_ITERATE(e, fn, args...) \ XT_MATCH_ITERATE(struct compat_ip6t_entry, e, fn, ## args) -/* fn returns 0 to continue iteration */ -#define COMPAT_IP6T_ENTRY_ITERATE(entries, size, fn, args...) \ - XT_ENTRY_ITERATE(struct compat_ip6t_entry, entries, size, fn, ## args) - -#define COMPAT_IP6T_ENTRY_ITERATE_CONTINUE(entries, size, n, fn, args...) \ - XT_ENTRY_ITERATE_CONTINUE(struct compat_ip6t_entry, entries, size, n, \ - fn, ## args) -#endif /* CONFIG_COMPAT */ #endif /*__KERNEL__*/ #endif /* _IP6_TABLES_H */
net/ipv4/netfilter/arp_tables.c +98 -53
307 lines not on this page · raw message
net/ipv4/netfilter/ip_tables.c +104 -56
328 lines not on this page · raw message
net/ipv6/netfilter/ip6_tables.c +104 -56
328 lines not on this page · raw message
netfilter 05/08: xtables: optimize call flow around xt_entry_foreach
In reply to Patrick McHardycommit 0559518b5b99c591226460c0bbf8e6a570c518a8
Author: Jan Engelhardt <[email protected]> Date: Wed Feb 24 18:33:43 2010 +0100
netfilter: xtables: optimize call flow around xt_entry_foreach
net/ipv4/netfilter/arp_tables.c +58 -122
@@ -512,8 +512,7 @@ static inline int check_target(struct arpt_entry *e, const char *name) }static inline int -find_check_entry (struct arpt_entry *e,const char *name,unsigned int size, -unsigned int *i) +find_check_entry (struct arpt_entry *e,const char *name,unsigned int size) {struct arpt_entry_target *t;struct xt_target *target;
@@ -538,8 +537,6 @@ find_check_entry(struct arpt_entry *e, const char *name, unsigned int size, ret =check_target (e, name);if (ret) goto err; - - (*i)++;return 0 ; err:module_put (t->u.kernel.target->me);
@@ -568,8 +565,7 @@ static inline int check_entry_size_and_hooks(struct arpt_entry *e,const unsigned char *limit, const unsigned int *hook_entries, const unsigned int *underflows, - unsigned int valid_hooks, - unsigned int *i) + unsigned int valid_hooks) { unsigned int h;
@@ -606,19 +602,14 @@ static inline int check_entry_size_and_hooks(struct arpt_entry *e,/* Clear counters and comefrom */ e->counters = ((struct xt_counters ) {0 ,0 }); e->comefrom =0 ; - - (*i)++;return 0 ; } -static inline int cleanup_entry (struct arpt_entry *e,unsigned int *i) +static inline void cleanup_entry (struct arpt_entry *e) {struct xt_tgdtor_param par;struct arpt_entry_target *t; -if (i && (*i)-- ==0 ) -return 1 ; - t =arpt_get_target (e); par.target = t->u.kernel.target; par.targinfo = t->data;
@@ -626,7 +617,6 @@ static inline int cleanup_entry(struct arpt_entry *e, unsigned int *i)if (par.target->destroy !=NULL ) par.target->destroy (&par);module_put (par.target->me); -return 0 ; }/* Checks and translates the user-supplied table segment (held in
@@ -660,10 +650,10 @@ static int translate_table(const char *name,/* Walk through entries, checking offsets. */ xt_entry_foreach(iter, entry0, newinfo->size) { ret =check_entry_size_and_hooks (iter, newinfo, entry0, - entry0 + size, hook_entries, underflows, - valid_hooks, &i); + entry0 + size, hook_entries, underflows, valid_hooks);if (ret !=0 )break ; + ++i; }duprintf ("translate_table: ARPT_ENTRY_ITERATE gives %d\n" , ret);if (ret !=0 )
@@ -700,15 +690,18 @@ static int translate_table(const char *name,/* Finally, each sanity check must pass */ i =0 ; xt_entry_foreach(iter, entry0, newinfo->size) { - ret =find_check_entry (iter, name, size, &i); + ret =find_check_entry (iter, name, size);if (ret !=0 )break ; + ++i; }if (ret !=0 ) { - xt_entry_foreach(iter, entry0, newinfo->size) -if (cleanup_entry (iter, &i) !=0 ) + xt_entry_foreach(iter, entry0, newinfo->size) { +if (i-- ==0 )break ; +cleanup_entry (iter); + }return ret; }
@@ -721,27 +714,6 @@ static int translate_table(const char *name,return ret; } -/* Gets counters. */ -static inline int add_entry_to_counter (const struct arpt_entry *e, -struct xt_counters total[], -unsigned int *i) -{ -ADD_COUNTER (total[*i], e->counters.bcnt, e->counters.pcnt); - - (*i)++; -return 0 ; -} - -static inline int set_entry_to_counter (const struct arpt_entry *e, -struct xt_counters total[], -unsigned int *i) -{ -SET_COUNTER (total[*i], e->counters.bcnt, e->counters.pcnt); - - (*i)++; -return 0 ; -} -static void get_counters (const struct xt_table_info *t,struct xt_counters counters[]) {
@@ -761,18 +733,22 @@ static void get_counters(const struct xt_table_info *t, curcpu =smp_processor_id (); i =0 ; - xt_entry_foreach(iter, t->entries[curcpu], t->size) -if (set_entry_to_counter (iter, counters, &i) !=0 ) -break ; + xt_entry_foreach(iter, t->entries[curcpu], t->size) { +SET_COUNTER (counters[i], iter->counters.bcnt, + iter->counters.pcnt); + ++i; + }for_each_possible_cpu (cpu) {if (cpu == curcpu)continue ; i =0 ;xt_info_wrlock (cpu); - xt_entry_foreach(iter, t->entries[cpu], t->size) -if (add_entry_to_counter (iter, counters, &i) !=0 ) -break ; + xt_entry_foreach(iter, t->entries[cpu], t->size) { +ADD_COUNTER (counters[i], iter->counters.bcnt, + iter->counters.pcnt); + ++i; + }xt_info_wrunlock (cpu); }local_bh_enable ();
@@ -904,7 +880,7 @@ static int compat_table_info(const struct xt_table_info *info, {struct arpt_entry *iter;void *loc_cpu_entry; -int ret =0 ; +int ret;if (!newinfo || !info)return -EINVAL ;
@@ -916,9 +892,9 @@ static int compat_table_info(const struct xt_table_info *info, xt_entry_foreach(iter, loc_cpu_entry, info->size) { ret =compat_calc_entry (iter, info, loc_cpu_entry, newinfo);if (ret !=0 ) -break ; +return ret; } - return ret; + return 0; }#endif
@@ -1078,8 +1054,7 @@ static int __do_replace(struct net *net, const char *name,/* Decrease module usage counts and free resource */ loc_cpu_old_entry = oldinfo->entries[raw_smp_processor_id ()]; xt_entry_foreach(iter, loc_cpu_old_entry, oldinfo->size) -if (cleanup_entry (iter,NULL ) !=0 ) -break ; +cleanup_entry (iter);xt_free_table_info (oldinfo); if (copy_to_user(counters_ptr, counters,
@@ -1142,26 +1117,12 @@ static int do_replace(struct net *net, const void __user *user, free_newinfo_untrans: xt_entry_foreach(iter, loc_cpu_entry, newinfo->size) -if (cleanup_entry (iter,NULL ) !=0 ) -break ; +cleanup_entry (iter); free_newinfo:xt_free_table_info (newinfo);return ret; } -/* We're lazy, and add to the first CPU; overflow works its fey magic -* and everything is OK. */ -static int -add_counter_to_entry (struct arpt_entry *e, -const struct xt_counters addme[], -unsigned int *i) -{ -ADD_COUNTER (e->counters, addme[*i].bcnt, addme[*i].pcnt); - - (*i)++; -return 0 ; -} -static int do_add_counters (struct net *net,const void __user *user,unsigned int len,int compat) {
@@ -1234,9 +1195,10 @@ static int do_add_counters(struct net *net, const void __user *user, curcpu =smp_processor_id (); loc_cpu_entry = private->entries[curcpu];xt_info_wrlock (curcpu); - xt_entry_foreach(iter, loc_cpu_entry, private->size) -if (add_counter_to_entry (iter, paddc, &i) !=0 ) -break ; + xt_entry_foreach(iter, loc_cpu_entry, private->size) { +ADD_COUNTER (iter->counters, paddc[i].bcnt, paddc[i].pcnt); + ++i; + }xt_info_wrunlock (curcpu); unlock_up_free:local_bh_enable ();
@@ -1249,17 +1211,12 @@ static int do_add_counters(struct net *net, const void __user *user, }#ifdef CONFIG_COMPAT -static inline int -compat_release_entry (struct compat_arpt_entry *e,unsigned int *i) +static inline void compat_release_entry (struct compat_arpt_entry *e) {struct arpt_entry_target *t; -if (i && (*i)-- ==0 ) -return 1 ; - t =compat_arpt_get_target (e);module_put (t->u.kernel.target->me); -return 0 ; } static inline int
@@ -1270,7 +1227,6 @@ check_compat_entry_size_and_hooks(struct compat_arpt_entry *e,const unsigned char *limit, const unsigned int *hook_entries, const unsigned int *underflows, - unsigned int *i, const char *name) { struct arpt_entry_target *t;
@@ -1330,8 +1286,6 @@ check_compat_entry_size_and_hooks(struct compat_arpt_entry *e,/* Clear counters and comefrom */ memset (&e->counters,0 ,sizeof (e->counters)); e->comefrom =0 ; - - (*i)++;return 0 ; release_target:
@@ -1375,19 +1329,6 @@ compat_copy_entry_from_user(struct compat_arpt_entry *e, void **dstptr,return ret; } -static inline int compat_check_entry (struct arpt_entry *e,const char *name, -unsigned int *i) -{ -int ret; - - ret =check_target (e, name); -if (ret) -return ret; - - (*i)++; -return 0 ; -} - static int translate_compat_table(const char *name, unsigned int valid_hooks, struct xt_table_info **pinfo,
@@ -1423,12 +1364,11 @@ static int translate_compat_table(const char *name, xt_entry_foreach(iter0, entry0, total_size) { ret =check_compat_entry_size_and_hooks (iter0, info, &size, entry0, entry0 + total_size, hook_entries, underflows, - &j, name); + name);if (ret !=0 ) -break ; + goto out_unlock; + ++j; } -if (ret !=0 ) - goto out_unlock; ret = -EINVAL ;if (j != number) {
@@ -1484,9 +1424,10 @@ static int translate_compat_table(const char *name, i =0 ; xt_entry_foreach(iter1, entry1, newinfo->size) { - ret =compat_check_entry (iter1, name, &i); + ret =check_target (iter1, name);if (ret !=0 )break ; + ++i; }if (ret) {/*
@@ -1499,12 +1440,15 @@ static int translate_compat_table(const char *name, xt_entry_foreach(iter0, entry0, newinfo->size) {if (skip-- >0 )continue ; -if (compat_release_entry (iter0, &j) !=0 ) +if (j-- ==0 )break ; +compat_release_entry (iter0); } - xt_entry_foreach(iter1, entry1, newinfo->size) -if (cleanup_entry (iter1, &i) !=0 ) + xt_entry_foreach(iter1, entry1, newinfo->size) { +if (i-- ==0 )break ; +cleanup_entry (iter1); + }xt_free_table_info (newinfo);return ret; }
@@ -1522,9 +1466,11 @@ static int translate_compat_table(const char *name, free_newinfo:xt_free_table_info (newinfo); out: - xt_entry_foreach(iter0, entry0, total_size) -if (compat_release_entry (iter0, &j) !=0 ) + xt_entry_foreach(iter0, entry0, total_size) { +if (j-- ==0 )break ; +compat_release_entry (iter0); + }return ret; out_unlock:xt_compat_flush_offsets (NFPROTO_ARP );
@@ -1590,8 +1536,7 @@ static int compat_do_replace(struct net *net, void __user *user, free_newinfo_untrans: xt_entry_foreach(iter, loc_cpu_entry, newinfo->size) -if (cleanup_entry (iter,NULL ) !=0 ) -break ; +cleanup_entry (iter); free_newinfo:xt_free_table_info (newinfo);return ret;
@@ -1625,7 +1570,7 @@ static int compat_do_arpt_set_ctl(struct sock *sk, int cmd, void __user *user,static int compat_copy_entry_to_user (struct arpt_entry *e,void __user **dstptr,compat_uint_t *size,struct xt_counters *counters, -unsigned int *i) +unsigned int i) {struct arpt_entry_target *t;struct compat_arpt_entry __user *ce;
@@ -1633,14 +1578,12 @@ static int compat_copy_entry_to_user(struct arpt_entry *e, void __user **dstptr,compat_uint_t origsize;int ret; - ret = -EFAULT ; origsize = *size; ce = (struct compat_arpt_entry __user *)*dstptr; -if (copy_to_user (ce, e,sizeof (struct arpt_entry ))) - goto out; - -if (copy_to_user (&ce->counters, &counters[*i],sizeof (counters[*i]))) - goto out; +if (copy_to_user (ce, e,sizeof (struct arpt_entry )) !=0 || +copy_to_user (&ce->counters, &counters[i], +sizeof (counters[i])) !=0 ) +return -EFAULT ; *dstptr +=sizeof (struct compat_arpt_entry ); *size -=sizeof (struct arpt_entry ) -sizeof (struct compat_arpt_entry );
@@ -1650,18 +1593,12 @@ static int compat_copy_entry_to_user(struct arpt_entry *e, void __user **dstptr, t =arpt_get_target (e); ret =xt_compat_target_to_user (t, dstptr, size);if (ret) - goto out; - ret = -EFAULT ; +return ret; next_offset = e->next_offset - (origsize - *size); -if (put_user (target_offset, &ce->target_offset)) - goto out; -if (put_user (next_offset, &ce->next_offset)) - goto out; - - (*i)++; +if (put_user (target_offset, &ce->target_offset) !=0 || +put_user (next_offset, &ce->next_offset) !=0 ) +return -EFAULT ;return 0 ; -out: -return ret; } static int compat_copy_entries_to_user(unsigned int total_size,
@@ -1687,7 +1624,7 @@ static int compat_copy_entries_to_user(unsigned int total_size, size = total_size; xt_entry_foreach(iter, loc_cpu_entry, total_size) { ret =compat_copy_entry_to_user (iter, &pos, - &size, counters, &i); + &size, counters, i++);if (ret !=0 )break ; }
@@ -1893,8 +1830,7 @@ void arpt_unregister_table(struct xt_table *table)/* Decrease module usage counts and free resources */ loc_cpu_entry = private->entries[raw_smp_processor_id ()]; xt_entry_foreach(iter, loc_cpu_entry, private->size) -if (cleanup_entry (iter,NULL ) !=0 ) -break ; +cleanup_entry (iter);if (private->number > private->initial_entries)module_put (table_owner);xt_free_table_info (private);
net/ipv4/netfilter/ip_tables.c +63 -120
412 lines not on this page · raw message
net/ipv6/netfilter/ip6_tables.c +61 -118
402 lines not on this page · raw message
netfilter 06/08: xtables: replace XT_MATCH_ITERATE macro
In reply to Patrick McHardycommit dcea992aca82cb08b4674c4c783e325835408d1e
Author: Jan Engelhardt <[email protected]> Date: Wed Feb 24 18:34:48 2010 +0100
netfilter: xtables: replace XT_MATCH_ITERATE macro
The macro is replaced by a list.h-like foreach loop. This makes the code more inspectable.
include/linux/netfilter/x_tables.h +9 -1
@@ -120,6 +120,7 @@ struct xt_counters_info {#define XT_INV_PROTO 0x40/* Invert the sense of PROTO. */ +#ifndef __KERNEL__/* fn returns 0 to continue iteration */ #define XT_MATCH_ITERATE(type, e, fn, args...) \ ({ \
@@ -139,7 +140,6 @@ struct xt_counters_info { __ret; \ }) -#ifndef __KERNEL__/* fn returns 0 to continue iteration */ #define XT_ENTRY_ITERATE_CONTINUE(type, entries, size, n, fn, args...) \ ({ \
@@ -172,6 +172,14 @@ struct xt_counters_info { (pos) < (typeof (pos))((char *)(ehead) + (esize)); \ (pos) = (typeof(pos))((char *)(pos) + (pos)->next_offset)) +/* can only be xt_entry_match, so no use of typeof here */ +#define xt_ematch_foreach (pos, entry) \ + for ((pos) = (struct xt_entry_match *)entry->elems; \ + (pos) < (struct xt_entry_match *)((char *)(entry) + \ + (entry)->target_offset); \ + (pos) = (struct xt_entry_match *)((char *)(pos) + \ + (pos)->u.match_size)) +#ifdef __KERNEL__#include <linux/netdevice.h>
include/linux/netfilter_ipv4/ip_tables.h +1 -5
@@ -223,11 +223,11 @@ ipt_get_target(struct ipt_entry *e)return (void *)e + e->target_offset; } +#ifndef __KERNEL__/* fn returns 0 to continue iteration */ #define IPT_MATCH_ITERATE(e, fn, args...) \ XT_MATCH_ITERATE(struct ipt_entry, e, fn, ## args) -#ifndef __KERNEL__/* fn returns 0 to continue iteration */ #define IPT_ENTRY_ITERATE(entries, size, fn, args...) \ XT_ENTRY_ITERATE(struct ipt_entry, entries, size, fn, ## args)
@@ -315,10 +315,6 @@ compat_ipt_get_target(struct compat_ipt_entry *e)#define COMPAT_IPT_ALIGN (s) COMPAT_XT_ALIGN(s) -/* fn returns 0 to continue iteration */ -#define COMPAT_IPT_MATCH_ITERATE(e, fn, args...) \ - XT_MATCH_ITERATE(struct compat_ipt_entry, e, fn, ## args) -#endif /* CONFIG_COMPAT */ #endif /*__KERNEL__*/ #endif /* _IPTABLES_H */
include/linux/netfilter_ipv6/ip6_tables.h +1 -5
@@ -280,11 +280,11 @@ ip6t_get_target(struct ip6t_entry *e)return (void *)e + e->target_offset; } +#ifndef __KERNEL__/* fn returns 0 to continue iteration */ #define IP6T_MATCH_ITERATE(e, fn, args...) \ XT_MATCH_ITERATE(struct ip6t_entry, e, fn, ## args) -#ifndef __KERNEL__/* fn returns 0 to continue iteration */ #define IP6T_ENTRY_ITERATE(entries, size, fn, args...) \ XT_ENTRY_ITERATE(struct ip6t_entry, entries, size, fn, ## args)
@@ -343,10 +343,6 @@ compat_ip6t_get_target(struct compat_ip6t_entry *e)#define COMPAT_IP6T_ALIGN (s) COMPAT_XT_ALIGN(s) -/* fn returns 0 to continue iteration */ -#define COMPAT_IP6T_MATCH_ITERATE(e, fn, args...) \ - XT_MATCH_ITERATE(struct compat_ip6t_entry, e, fn, ## args) -#endif /* CONFIG_COMPAT */ #endif /*__KERNEL__*/ #endif /* _IP6_TABLES_H */
net/ipv4/netfilter/ip_tables.c +61 -17
200 lines not on this page · raw message
net/ipv6/netfilter/ip6_tables.c +61 -17
199 lines not on this page · raw message
net/netfilter/xt_TCPMSS.c +8 -4
@@ -239,6 +239,7 @@ static bool tcpmss_tg4_check(const struct xt_tgchk_param *par) {const struct xt_tcpmss_info *info = par->targinfo;const struct ipt_entry *e = par->entryinfo; +const struct xt_entry_match *ematch; if (info->mss == XT_TCPMSS_CLAMP_PMTU && (par->hook_mask & ~((1 << NF_INET_FORWARD) |
@@ -248,8 +249,9 @@ static bool tcpmss_tg4_check(const struct xt_tgchk_param *par) "FORWARD, OUTPUT and POSTROUTING hooks\n");return false; } -if (IPT_MATCH_ITERATE (e, find_syn_match)) -return true; + xt_ematch_foreach(ematch, e) +if (find_syn_match (ematch)) +return true;printk ("xt_TCPMSS: Only works on TCP SYN packets\n" );return false; }
@@ -259,6 +261,7 @@ static bool tcpmss_tg6_check(const struct xt_tgchk_param *par) {const struct xt_tcpmss_info *info = par->targinfo;const struct ip6t_entry *e = par->entryinfo; +const struct xt_entry_match *ematch; if (info->mss == XT_TCPMSS_CLAMP_PMTU && (par->hook_mask & ~((1 << NF_INET_FORWARD) |
@@ -268,8 +271,9 @@ static bool tcpmss_tg6_check(const struct xt_tgchk_param *par) "FORWARD, OUTPUT and POSTROUTING hooks\n");return false; } -if (IP6T_MATCH_ITERATE (e, find_syn_match)) -return true; + xt_ematch_foreach(ematch, e) +if (find_syn_match (ematch)) +return true;printk ("xt_TCPMSS: Only works on TCP SYN packets\n" );return false; }
netfilter 07/08: xtables: optimize call flow around xt_ematch_foreach
In reply to Patrick McHardycommit 6bdb331bc6910d1ccb74dc9852fc858c5916c927
Author: Jan Engelhardt <[email protected]> Date: Wed Feb 24 18:35:37 2010 +0100
netfilter: xtables: optimize call flow around xt_ematch_foreach
net/ipv4/netfilter/ip_tables.c +31 -62
@@ -572,14 +572,10 @@ mark_source_chains(const struct xt_table_info *newinfo,return 1 ; } -static int -cleanup_match (struct ipt_entry_match *m,struct net *net,unsigned int *i) +static void cleanup_match (struct ipt_entry_match *m,struct net *net) {struct xt_mtdtor_param par; -if (i && (*i)-- ==0 ) -return 1 ; - par.net = net; par.match = m->u.kernel.match; par.matchinfo = m->data;
@@ -587,7 +583,6 @@ cleanup_match(struct ipt_entry_match *m, struct net *net, unsigned int *i)if (par.match->destroy !=NULL ) par.match->destroy (&par);module_put (par.match->me); -return 0 ; } static int
@@ -612,8 +607,7 @@ check_entry(const struct ipt_entry *e, const char *name) }static int -check_match (struct ipt_entry_match *m,struct xt_mtchk_param *par, -unsigned int *i) +check_match (struct ipt_entry_match *m,struct xt_mtchk_param *par) {const struct ipt_ip *ip = par->entryinfo;int ret;
@@ -628,13 +622,11 @@ check_match(struct ipt_entry_match *m, struct xt_mtchk_param *par, par.match->name);return ret; } - ++*i;return 0 ; }static int -find_check_match (struct ipt_entry_match *m,struct xt_mtchk_param *par, -unsigned int *i) +find_check_match (struct ipt_entry_match *m,struct xt_mtchk_param *par) {struct xt_match *match;int ret;
@@ -648,7 +640,7 @@ find_check_match(struct ipt_entry_match *m, struct xt_mtchk_param *par, } m->u.kernel.match = match; - ret =check_match (m, par, i); + ret =check_match (m, par);if (ret) goto err;
@@ -704,12 +696,11 @@ find_check_entry(struct ipt_entry *e, struct net *net, const char *name, mtpar.hook_mask = e->comefrom; mtpar.family =NFPROTO_IPV4 ; xt_ematch_foreach(ematch, e) { - ret =find_check_match (ematch, &mtpar, &j); + ret =find_check_match (ematch, &mtpar);if (ret !=0 ) -break ; + goto cleanup_matches; + ++j; } -if (ret !=0 ) - goto cleanup_matches; t =ipt_get_target (e); target = try_then_request_module(xt_find_target(AF_INET,
@@ -730,9 +721,11 @@ find_check_entry(struct ipt_entry *e, struct net *net, const char *name, err:module_put (t->u.kernel.target->me); cleanup_matches: - xt_ematch_foreach(ematch, e) -if (cleanup_match (ematch, net, &j) !=0 ) + xt_ematch_foreach(ematch, e) { +if (j-- ==0 )break ; +cleanup_match (ematch, net); + }return ret; }
@@ -807,8 +800,7 @@ cleanup_entry(struct ipt_entry *e, struct net *net)/* Cleanup all matches */ xt_ematch_foreach(ematch, e) -if (cleanup_match (ematch, net,NULL ) !=0 ) -break ; +cleanup_match (ematch, net); t =ipt_get_target (e); par.net = net;
@@ -1064,13 +1056,6 @@ static int compat_standard_to_user(void __user *dst, const void *src)return copy_to_user (dst, &cv,sizeof (cv)) ? -EFAULT :0 ; } -static inline int -compat_calc_match (const struct ipt_entry_match *m,int *size) -{ - *size +=xt_compat_match_offset (m->u.kernel.match); -return 0 ; -} -static int compat_calc_entry (const struct ipt_entry *e,const struct xt_table_info *info,const void *base,struct xt_table_info *newinfo)
@@ -1083,8 +1068,7 @@ static int compat_calc_entry(const struct ipt_entry *e, off =sizeof (struct ipt_entry ) -sizeof (struct compat_ipt_entry ); entry_offset = (void *)e - base;xt_ematch_foreach (ematch, e) -if (compat_calc_match (ematch, &off) !=0 ) -break ; + off += xt_compat_match_offset(ematch->u.kernel.match); t =ipt_get_target_c (e); off +=xt_compat_target_offset (t->u.kernel.target); newinfo->size -= off;
@@ -1475,11 +1459,9 @@ compat_copy_entry_to_user(struct ipt_entry *e, void __user **dstptr, xt_ematch_foreach(ematch, e) { ret =xt_compat_match_to_user (ematch, dstptr, size);if (ret !=0 ) -break ; +return ret; } target_offset = e->target_offset - (origsize - *size); -if (ret) -return ret; t =ipt_get_target (e); ret =xt_compat_target_to_user (t, dstptr, size);if (ret)
@@ -1496,7 +1478,7 @@ compat_find_calc_match(struct ipt_entry_match *m,const char *name, const struct ipt_ip *ip, unsigned int hookmask, - int *size, unsigned int *i) + int *size) { struct xt_match *match;
@@ -1510,18 +1492,6 @@ compat_find_calc_match(struct ipt_entry_match *m, } m->u.kernel.match = match; *size +=xt_compat_match_offset (match); - - (*i)++; -return 0 ; -} - -static int -compat_release_match (struct ipt_entry_match *m,unsigned int *i) -{ -if (i && (*i)-- ==0 ) -return 1 ; - -module_put (m->u.kernel.match->me);return 0 ; }
@@ -1532,8 +1502,7 @@ static void compat_release_entry(struct compat_ipt_entry *e)/* Cleanup all matches */ xt_ematch_foreach(ematch, e) -if (compat_release_match (ematch,NULL ) !=0 ) -break ; +module_put (ematch->u.kernel.match->me); t =compat_ipt_get_target (e);module_put (t->u.kernel.target->me); }
@@ -1579,12 +1548,11 @@ check_compat_entry_size_and_hooks(struct compat_ipt_entry *e, j =0 ; xt_ematch_foreach(ematch, e) { ret =compat_find_calc_match (ematch, name, - &e->ip, e->comefrom, &off, &j); + &e->ip, e->comefrom, &off);if (ret !=0 ) -break ; + goto release_matches; + ++j; } -if (ret !=0 ) - goto release_matches; t =compat_ipt_get_target (e); target = try_then_request_module(xt_find_target(AF_INET,
@@ -1621,9 +1589,11 @@ check_compat_entry_size_and_hooks(struct compat_ipt_entry *e, out:module_put (t->u.kernel.target->me); release_matches: - xt_ematch_foreach(ematch, e) -if (compat_release_match (ematch, &j) !=0 ) + xt_ematch_foreach(ematch, e) { +if (j-- ==0 )break ; +module_put (ematch->u.kernel.match->me); + }return ret; }
@@ -1651,10 +1621,8 @@ compat_copy_entry_from_user(struct compat_ipt_entry *e, void **dstptr, xt_ematch_foreach(ematch, e) { ret =xt_compat_match_from_user (ematch, dstptr, size);if (ret !=0 ) -break ; +return ret; } -if (ret) -return ret; de->target_offset = e->target_offset - (origsize - *size); t =compat_ipt_get_target (e); target = t->u.kernel.target;
@@ -1685,12 +1653,11 @@ compat_check_entry(struct ipt_entry *e, struct net *net, const char *name) mtpar.hook_mask = e->comefrom; mtpar.family =NFPROTO_IPV4 ; xt_ematch_foreach(ematch, e) { - ret =check_match (ematch, &mtpar, &j); + ret =check_match (ematch, &mtpar);if (ret !=0 ) -break ; + goto cleanup_matches; + ++j; } -if (ret) - goto cleanup_matches; ret =check_target (e, net, name);if (ret)
@@ -1698,9 +1665,11 @@ compat_check_entry(struct ipt_entry *e, struct net *net, const char *name)return 0 ; cleanup_matches: - xt_ematch_foreach(ematch, e) -if (cleanup_match (ematch, net, &j) !=0 ) + xt_ematch_foreach(ematch, e) { +if (j-- ==0 )break ; +cleanup_match (ematch, net); + }return ret; }
net/ipv6/netfilter/ip6_tables.c +31 -62
226 lines not on this page · raw message
netfilter 08/08: xtables: reduce arguments to translate_table
In reply to Patrick McHardycommit 0f234214d15fa914436d304ecf5c3e43449e79f9
Author: Jan Engelhardt <[email protected]> Date: Wed Feb 24 18:36:04 2010 +0100
netfilter: xtables: reduce arguments to translate_table
Just pass in the entire repl struct. In case of a new table (e.g. ip6t_register_table), the repldata has been previously filled with table->name and table->size already (in ip6t_alloc_initial_table).
net/ipv4/netfilter/arp_tables.c +15 -27
@@ -622,21 +622,15 @@ static inline void cleanup_entry(struct arpt_entry *e)/* Checks and translates the user-supplied table segment (held in * newinfo). */ -static int translate_table (const char *name, -unsigned int valid_hooks, -struct xt_table_info *newinfo, -void *entry0, -unsigned int size, -unsigned int number, -const unsigned int *hook_entries, -const unsigned int *underflows) +static int translate_table (struct xt_table_info *newinfo,void *entry0, +const struct arpt_replace *repl) {struct arpt_entry *iter;unsigned int i;int ret =0 ; - newinfo->size = size; - newinfo->number = number; + newinfo->size = repl->size; + newinfo->number = repl->num_entries;/* Init all hooks to impossible value. */ for (i =0 ; i <NF_ARP_NUMHOOKS ; i++) {
@@ -650,7 +644,8 @@ static int translate_table(const char *name,/* Walk through entries, checking offsets. */ xt_entry_foreach(iter, entry0, newinfo->size) { ret =check_entry_size_and_hooks (iter, newinfo, entry0, - entry0 + size, hook_entries, underflows, valid_hooks); + entry0 + repl->size, repl->hook_entry, repl->underflow, + repl->valid_hooks);if (ret !=0 )break ; ++i;
@@ -659,30 +654,30 @@ static int translate_table(const char *name,if (ret !=0 )return ret; -if (i != number) { +if (i != repl->num_entries) {duprintf ("translate_table: %u not %u entries\n" , - i, number); + i, repl->num_entries);return -EINVAL ; }/* Check hooks all assigned */ for (i =0 ; i <NF_ARP_NUMHOOKS ; i++) {/* Only hooks which are valid */ -if (!(valid_hooks & (1 << i))) +if (!(repl->valid_hooks & (1 << i)))continue ;if (newinfo->hook_entry[i] ==0xFFFFFFFF ) {duprintf ("Invalid hook entry %u %u\n" , - i, hook_entries[i]); + i, repl->hook_entry[i]);return -EINVAL ; }if (newinfo->underflow[i] ==0xFFFFFFFF ) {duprintf ("Invalid underflow %u %u\n" , - i, underflows[i]); + i, repl->underflow[i]);return -EINVAL ; } } -if (!mark_source_chains (newinfo, valid_hooks, entry0)) { +if (!mark_source_chains (newinfo, repl->valid_hooks, entry0)) {duprintf ("Looping hook\n" );return -ELOOP ; }
@@ -690,7 +685,7 @@ static int translate_table(const char *name,/* Finally, each sanity check must pass */ i =0 ; xt_entry_foreach(iter, entry0, newinfo->size) { - ret =find_check_entry (iter, name, size); + ret =find_check_entry (iter, repl->name, repl->size);if (ret !=0 )break ; ++i;
@@ -1101,9 +1096,7 @@ static int do_replace(struct net *net, const void __user *user, goto free_newinfo; } - ret =translate_table (tmp.name, tmp.valid_hooks, - newinfo, loc_cpu_entry, tmp.size, tmp.num_entries, - tmp.hook_entry, tmp.underflow); + ret =translate_table (newinfo, loc_cpu_entry, &tmp);if (ret !=0 ) goto free_newinfo;
@@ -1795,12 +1788,7 @@ struct xt_table *arpt_register_table(struct net *net, loc_cpu_entry = newinfo->entries[raw_smp_processor_id ()];memcpy (loc_cpu_entry, repl->entries, repl->size); - ret =translate_table (table->name, table->valid_hooks, - newinfo, loc_cpu_entry, repl->size, - repl->num_entries, - repl->hook_entry, - repl->underflow); - + ret =translate_table (newinfo, loc_cpu_entry, repl);duprintf ("arpt_register_table: translate table gives %d\n" , ret);if (ret !=0 ) goto out_free;
net/ipv4/netfilter/ip_tables.c +15 -27
99 lines not on this page · raw message
net/ipv6/netfilter/ip6_tables.c +15 -27
99 lines not on this page · raw message
Patrick McHardy wrote, at 02/25/2010 01:49 AM:
Quoted 3 lines
Hi Dave,
following is the probably final netfilter update for 2.6.34, containing:
2.6.33 is just released, and Linus Torvalds said that this merger window period is about ten-to-twelve days.
Is it enough for us to review patch-set with title "IPv6:netfilter: defragment"? Is there hope to merger this patch-set for 2.6.34?
Signature · 3 lines
Best Regards ----- Shan Wei
Quoted 10 lines · Shan Wei
Patrick McHardy wrote, at 02/25/2010 01:49 AM:
Quoted 3 lines
Hi Dave,
following is the probably final netfilter update for 2.6.34, containing:
2.6.33 is just released, and Linus Torvalds said that this merger window period is about ten-to-twelve days.
Is it enough for us to review patch-set with title "IPv6:netfilter: defragment"? Is there hope to merger this patch-set for 2.6.34?
The networking merge window closes earlier than that. These patches are quite small however and almost classify as bugfixes, so I'm fine with them if you send them over very quickly and Dave doesn't object.