: Netfilter update for 2.6.19
Subsystems (4)
cover : Netfilter update for 2.6.19
Hi Dave,
following is another netfilter update for 2.6.19, consisting of a number of random cleanup and fixes, a rework of the iptables compat code including compat support for (AFAICT) all missing matches/targets and some cleanup and fixes for the PPtP connection tracking helper. Some of these should also go in -stable, I'll prepare backports and send them seperately.
Please apply, thanks.
include/linux/netfilter/nf_conntrack_tcp.h | 1 include/linux/netfilter/x_tables.h | 33 include/linux/netfilter_ipv4/ip_conntrack_helper.h | 2 include/linux/netfilter_ipv4/ip_conntrack_pptp.h | 45 - include/linux/netfilter_ipv4/ip_conntrack_proto_gre.h | 22 include/linux/netfilter_ipv4/ip_nat_pptp.h | 4 include/linux/netfilter_ipv6.h | 1 include/linux/netfilter_logging.h | 33 include/net/ip6_route.h | 2 net/bridge/netfilter/ebtables.c | 76 +- net/ipv4/netfilter/arp_tables.c | 4 net/ipv4/netfilter/ip_conntrack_core.c | 209 ++--- net/ipv4/netfilter/ip_conntrack_helper_pptp.c | 634 +++++++----------- net/ipv4/netfilter/ip_conntrack_netlink.c | 63 - net/ipv4/netfilter/ip_conntrack_proto_gre.c | 52 - net/ipv4/netfilter/ip_conntrack_proto_tcp.c | 4 net/ipv4/netfilter/ip_conntrack_standalone.c | 1 net/ipv4/netfilter/ip_nat_core.c | 4 net/ipv4/netfilter/ip_nat_helper.c | 4 net/ipv4/netfilter/ip_nat_helper_pptp.c | 210 ++--- net/ipv4/netfilter/ip_nat_proto_gre.c | 22 net/ipv4/netfilter/ip_nat_rule.c | 4 net/ipv4/netfilter/ip_nat_standalone.c | 4 net/ipv4/netfilter/ip_queue.c | 8 net/ipv4/netfilter/ip_tables.c | 161 +--- net/ipv4/netfilter/ipt_TCPMSS.c | 101 -- net/ipv4/netfilter/ipt_TTL.c | 4 net/ipv4/netfilter/ipt_hashlimit.c | 29 net/ipv6/netfilter/ip6_queue.c | 8 net/ipv6/netfilter/ip6_tables.c | 5 net/ipv6/netfilter/ip6t_HL.c | 6 net/ipv6/netfilter/ip6table_mangle.c | 8 net/netfilter/nf_conntrack_core.c | 205 ++--- net/netfilter/nf_conntrack_netlink.c | 67 - net/netfilter/nf_conntrack_proto_tcp.c | 4 net/netfilter/nf_conntrack_standalone.c | 1 net/netfilter/x_tables.c | 209 +++-- net/netfilter/xt_CONNMARK.c | 36 + net/netfilter/xt_MARK.c | 34 net/netfilter/xt_connmark.c | 36 + net/netfilter/xt_conntrack.c | 179 ++--- net/netfilter/xt_limit.c | 65 + net/netfilter/xt_mark.c | 36 + net/netfilter/xt_policy.c | 2 44 files changed, 1238 insertions(+), 1400 deletions(-)
Alexey Dobriyan:
[NETFILTER]: xt_policy: remove dups in .family
Brian Haley:
[NETFILTER]: make some netfilter globals __read_mostly
Dmitry Mishin:
[NETFILTER]: x_tables: small check_entry & module_refcount cleanup
George Hansper:
[NETFILTER]: TCP conntrack: improve dead connection detection
Pablo Neira Ayuso:
[NETFILTER]: ctnetlink: simplify the code to dump the conntrack table [NETFILTER]: conntrack: fix race condition in early_drop
Patrick McHardy:
[NETFILTER]: remove unused include file
[NETFILTER]: kill listhelp.h
[NETFILTER]: xt_conntrack: clean up overly long lines [NETFILTER]: ipt_TCPMSS: reformat
[NETFILTER]: ipt_TCPMSS: remove impossible condition [NETFILTER]: ipt_TCPMSS: misc cleanup
[NETFILTER]: xt_limit: don't reset state on unrelated rule updates [NETFILTER]: ip6table_mangle: reroute when nfmark changes in NF_IP6_LOCAL_OUT [NETFILTER]: ipt_TTL: fix checksum update bug
[NETFILTER]: ip6t_HL: remove write-only variable
[NETFILTER]: ip_tables: fix module refcount leaks in compat error paths [NETFILTER]: ip_tables: revision support for compat code [NETFILTER]: x_tables: simplify compat API
[NETFILTER]: xt_mark: add compat conversion functions [NETFILTER]: xt_MARK: add compat conversion functions [NETFILTER]: xt_connmark: add compat conversion functions [NETFILTER]: xt_CONNMARK: add compat conversion functions [NETFILTER]: xt_limit: add compat conversion functions [NETFILTER]: ipt_hashlimit: add compat conversion functions [NETFILTER]: PPTP conntrack: fix whitespace errors
[NETFILTER]: PPTP conntrack: get rid of unnecessary byte order conversions [NETFILTER]: PPTP conntrack: remove dead code
[NETFILTER]: PPTP conntrack: remove more dead code
[NETFILTER]: PPTP conntrack: fix header definitions
[NETFILTER]: PPTP conntrack: remove unnecessary cid/pcid header pointers [NETFILTER]: PPTP conntrack: simplify expectation handling [NETFILTER]: PPTP conntrack: consolidate header size checks [NETFILTER]: PPTP conntrack: consolidate header parsing [NETFILTER]: PPTP conntrack: clean up debugging cruft [NETFILTER]: PPTP conntrack: check call ID before changing state [NETFILTER]: PPTP conntrack: fix PPTP_IN_CALL message types [NETFILTER]: PPTP conntrack: fix GRE keymap leak
[NETFILTER]: PPTP conntrack: fix another GRE keymap leak
PATCH 1/39 : remove unused include file
[NETFILTER]: remove unused include file
---
commit 2b9aa10745a14bddfcac991b5b11f809c02a6ffd
tree a6504d5995a92ad65bab428ad0861cba2d5576e7
parent 03789adae76100f1102dc35d8d7af9abdb1ac99c
author Patrick McHardy <[email protected]> Wed, 20 Sep 2006 09:27:35 +0200 committer Patrick McHardy <[email protected]> Wed, 20 Sep 2006 09:27:35 +0200
include/linux/netfilter_logging.h | 33 --------------------------------- 1 files changed, 0 insertions(+), 33 deletions(-)
include/linux/netfilter_logging.h deleted +0 -33
@@ -1,33 +0,0 @@ -/* Internal logging interface, which relies on the real -LOG target modules */ -#ifndef __LINUX_NETFILTER_LOGGING_H -#define __LINUX_NETFILTER_LOGGING_H - -#ifdef __KERNEL__ -#include <asm/atomic.h> - -struct nf_logging_t { -void (*nf_log_packet)(struct sk_buff **pskb, -unsigned int hooknum, -const struct net_device *in, -const struct net_device *out, -const char *prefix); -void (*nf_log)(char *pfh,size_t len, -const char *prefix); -}; - -extern void nf_log_register (int pf,const struct nf_logging_t *logging); -extern void nf_log_unregister (int pf,const struct nf_logging_t *logging); - -extern void nf_log_packet (int pf, -struct sk_buff **pskb, -unsigned int hooknum, -const struct net_device *in, -const struct net_device *out, -const char *fmt, ...); -extern void nf_log (int pf, -char *pfh,size_t len, -const char *fmt, ...); -#endif /*__KERNEL__*/ - -#endif /*__LINUX_NETFILTER_LOGGING_H*/
PATCH 2/39 : kill listhelp.h
In reply to Patrick McHardy[NETFILTER]: kill listhelp.h
Kill listhelp.h and use the list.h functions instead.
---
commit 02f2210c487d5c2c48fb2b30d15d6dec688e1152
tree 8355de20842352f169ed61e8499f2ffb58c87d9c
parent 2b9aa10745a14bddfcac991b5b11f809c02a6ffd
author Patrick McHardy <[email protected]> Wed, 20 Sep 2006 09:27:42 +0200 committer Patrick McHardy <[email protected]> Wed, 20 Sep 2006 09:27:42 +0200
include/linux/netfilter/x_tables.h | 4 - net/bridge/netfilter/ebtables.c | 76 ++++++---- net/ipv4/netfilter/arp_tables.c | 2 net/ipv4/netfilter/ip_conntrack_core.c | 189 ++++++++++++-------------- net/ipv4/netfilter/ip_conntrack_proto_gre.c | 24 ++- net/ipv4/netfilter/ip_conntrack_standalone.c | 1 net/ipv4/netfilter/ip_nat_core.c | 4 - net/ipv4/netfilter/ip_nat_helper.c | 4 - net/ipv4/netfilter/ip_nat_rule.c | 4 - net/ipv4/netfilter/ip_nat_standalone.c | 4 - net/ipv6/netfilter/ip6_tables.c | 3 net/netfilter/nf_conntrack_core.c | 185 ++++++++++++------------- net/netfilter/nf_conntrack_standalone.c | 1 net/netfilter/x_tables.c | 17 +- 14 files changed, 237 insertions(+), 281 deletions(-)
include/linux/netfilter/x_tables.h +0 -4
@@ -138,10 +138,6 @@ #ifdef __KERNEL__#include <linux/netdevice.h> -#define ASSERT_READ_LOCK (x) -#define ASSERT_WRITE_LOCK (x) -#include <linux/netfilter_ipv4/listhelp.h> -#ifdef CONFIG_COMPAT #define COMPAT_TO_USER 1#define COMPAT_FROM_USER -1
net/bridge/netfilter/ebtables.c +45 -31
182 lines not on this page · raw message
net/ipv4/netfilter/arp_tables.c +0 -2
@@ -56,8 +56,6 @@ #else#define ARP_NF_ASSERT (x)#endif -#include <linux/netfilter_ipv4/listhelp.h> -static inline int arp_devaddr_compare (const struct arpt_devaddr_info *ap,char *hdr_addr,int len) {
net/ipv4/netfilter/ip_conntrack_core.c +85 -104
317 lines not on this page · raw message
net/ipv4/netfilter/ip_conntrack_proto_gre.c +11 -13
@@ -37,7 +37,6 @@ static DEFINE_RWLOCK(ip_ct_gre_lock);#define ASSERT_READ_LOCK (x)#define ASSERT_WRITE_LOCK (x) -#include <linux/netfilter_ipv4/listhelp.h> #include <linux/netfilter_ipv4/ip_conntrack_protocol.h> #include <linux/netfilter_ipv4/ip_conntrack_helper.h> #include <linux/netfilter_ipv4/ip_conntrack_core.h>
@@ -82,10 +81,12 @@ static __be16 gre_keymap_lookup(struct i__be16 key =0 ;read_lock_bh (&ip_ct_gre_lock); - km =LIST_FIND (&gre_keymap_list, gre_key_cmpfn, - struct ip_ct_gre_keymap *, t); -if (km) - key = km->tuple.src.u.gre.key; +list_for_each_entry (km, &gre_keymap_list, list) { +if (gre_key_cmpfn (km, t)) { + key = km->tuple.src.u.gre.key; +break ; + } + }read_unlock_bh (&ip_ct_gre_lock);DEBUGP ("lookup src key 0x%x up key for " , key);
@@ -99,7 +100,7 @@ int ip_ct_gre_keymap_add(struct ip_conntrack *ct, struct ip_conntrack_tuple *t, int reply) { - struct ip_ct_gre_keymap **exist_km, *km, *old; + struct ip_ct_gre_keymap **exist_km, *km;if (!ct->helper ||strcmp (ct->helper->name,"pptp" )) {DEBUGP ("refusing to add GRE keymap to non-pptp session\n" );
@@ -113,13 +114,10 @@ ip_ct_gre_keymap_add(struct ip_conntrackif (*exist_km) {/* check whether it's a retransmission */ - old =LIST_FIND (&gre_keymap_list, gre_key_cmpfn, - struct ip_ct_gre_keymap *, t); -if (old == *exist_km) { -DEBUGP ("retransmission\n" ); -return 0 ; +list_for_each_entry (km, &gre_keymap_list, list) { +if (gre_key_cmpfn (km, t) && km == *exist_km) +return 0 ; } -DEBUGP ("trying to override keymap_%s for ct %p\n" , reply?"reply" :"orig" , ct);return -EEXIST ;
@@ -136,7 +134,7 @@ ip_ct_gre_keymap_add(struct ip_conntrackDUMP_TUPLE_GRE (&km->tuple);write_lock_bh (&ip_ct_gre_lock); -list_append (&gre_keymap_list, km); +list_add_tail (&km->list, &gre_keymap_list);write_unlock_bh (&ip_ct_gre_lock);return 0 ;
net/ipv4/netfilter/ip_conntrack_standalone.c +0 -1
@@ -35,7 +35,6 @@ #include <linux/netfilter_ipv4/ip_conntr#include <linux/netfilter_ipv4/ip_conntrack_protocol.h> #include <linux/netfilter_ipv4/ip_conntrack_core.h> #include <linux/netfilter_ipv4/ip_conntrack_helper.h> -#include <linux/netfilter_ipv4/listhelp.h> #if 0 #define DEBUGP printk
net/ipv4/netfilter/ip_nat_core.c +0 -4
@@ -22,9 +22,6 @@ #include <linux/icmp.h>#include <linux/udp.h> #include <linux/jhash.h> -#define ASSERT_READ_LOCK (x) -#define ASSERT_WRITE_LOCK (x) -#include <linux/netfilter_ipv4/ip_conntrack.h> #include <linux/netfilter_ipv4/ip_conntrack_core.h> #include <linux/netfilter_ipv4/ip_conntrack_protocol.h>
@@ -33,7 +30,6 @@ #include <linux/netfilter_ipv4/ip_nat_pr#include <linux/netfilter_ipv4/ip_nat_core.h> #include <linux/netfilter_ipv4/ip_nat_helper.h> #include <linux/netfilter_ipv4/ip_conntrack_helper.h> -#include <linux/netfilter_ipv4/listhelp.h> #if 0 #define DEBUGP printk
net/ipv4/netfilter/ip_nat_helper.c +0 -4
@@ -27,16 +27,12 @@ #include <net/ip.h>#include <net/tcp.h> #include <net/udp.h> -#define ASSERT_READ_LOCK (x) -#define ASSERT_WRITE_LOCK (x) -#include <linux/netfilter_ipv4/ip_conntrack.h> #include <linux/netfilter_ipv4/ip_conntrack_helper.h> #include <linux/netfilter_ipv4/ip_nat.h> #include <linux/netfilter_ipv4/ip_nat_protocol.h> #include <linux/netfilter_ipv4/ip_nat_core.h> #include <linux/netfilter_ipv4/ip_nat_helper.h> -#include <linux/netfilter_ipv4/listhelp.h> #if 0 #define DEBUGP printk
net/ipv4/netfilter/ip_nat_rule.c +0 -4
@@ -19,14 +19,10 @@ #include <net/checksum.h>#include <net/route.h> #include <linux/bitops.h> -#define ASSERT_READ_LOCK (x) -#define ASSERT_WRITE_LOCK (x) -#include <linux/netfilter_ipv4/ip_tables.h> #include <linux/netfilter_ipv4/ip_nat.h> #include <linux/netfilter_ipv4/ip_nat_core.h> #include <linux/netfilter_ipv4/ip_nat_rule.h> -#include <linux/netfilter_ipv4/listhelp.h> #if 0 #define DEBUGP printk
net/ipv4/netfilter/ip_nat_standalone.c +0 -4
@@ -30,9 +30,6 @@ #include <net/ip.h>#include <net/checksum.h> #include <linux/spinlock.h> -#define ASSERT_READ_LOCK (x) -#define ASSERT_WRITE_LOCK (x) -#include <linux/netfilter_ipv4/ip_nat.h> #include <linux/netfilter_ipv4/ip_nat_rule.h> #include <linux/netfilter_ipv4/ip_nat_protocol.h>
@@ -40,7 +37,6 @@ #include <linux/netfilter_ipv4/ip_nat_co#include <linux/netfilter_ipv4/ip_nat_helper.h> #include <linux/netfilter_ipv4/ip_tables.h> #include <linux/netfilter_ipv4/ip_conntrack_core.h> -#include <linux/netfilter_ipv4/listhelp.h> #if 0 #define DEBUGP printk
net/ipv6/netfilter/ip6_tables.c +0 -3
@@ -70,9 +70,6 @@ #else#define IP_NF_ASSERT (x)#endif - -#include <linux/netfilter_ipv4/listhelp.h> -#if 0 /* All the better to debug you with... */ #define static
net/netfilter/nf_conntrack_core.c +86 -99
310 lines not on this page · raw message
net/netfilter/nf_conntrack_standalone.c +0 -1
@@ -37,7 +37,6 @@ #include <net/netfilter/nf_conntrack_l3p#include <net/netfilter/nf_conntrack_protocol.h> #include <net/netfilter/nf_conntrack_core.h> #include <net/netfilter/nf_conntrack_helper.h> -#include <linux/netfilter_ipv4/listhelp.h> #if 0 #define DEBUGP printk
net/netfilter/x_tables.c +10 -7
@@ -81,7 +81,7 @@ xt_unregister_target(struct xt_target *tint af = target->family;mutex_lock (&xt[af].mutex); -LIST_DELETE (&xt[af].target, target); +list_del (&target->list);mutex_unlock (&xt[af].mutex); }EXPORT_SYMBOL (xt_unregister_target);
@@ -138,7 +138,7 @@ xt_unregister_match(struct xt_match *matint af = match->family;mutex_lock (&xt[af].mutex); -LIST_DELETE (&xt[af].match, match); +list_del (&match->list);mutex_unlock (&xt[af].mutex); }EXPORT_SYMBOL (xt_unregister_match);
@@ -575,15 +575,18 @@ int xt_register_table(struct xt_table *t {int ret;struct xt_table_info *private; +struct xt_table *t; ret =mutex_lock_interruptible (&xt[table->af].mutex);if (ret !=0 )return ret;/* Don't autoload: we'd eat our tail... */ -if (list_named_find (&xt[table->af].tables, table->name)) { - ret = -EEXIST ; - goto unlock; +list_for_each_entry (t, &xt[table->af].tables, list) { +if (strcmp (t->name, table->name) ==0 ) { + ret = -EEXIST ; + goto unlock; + } }/* Simplifies replace_table code. */
@@ -598,7 +601,7 @@ int xt_register_table(struct xt_table *t/* save number of initial entries */ private->initial_entries = private->number; -list_prepend (&xt[table->af].tables, table); +list_add (&table->list, &xt[table->af].tables); ret =0 ; unlock:
@@ -613,7 +616,7 @@ void *xt_unregister_table(struct xt_tablmutex_lock (&xt[table->af].mutex); private = table->private; -LIST_DELETE (&xt[table->af].tables, table); +list_del (&table->list);mutex_unlock (&xt[table->af].mutex);return private;
PATCH 3/39 : xt_conntrack: clean up overly long lines
In reply to Patrick McHardy[NETFILTER]: xt_conntrack: clean up overly long lines
Also fix some whitespace errors and use the NAT bits instead of deriving the state manually.
---
commit 9e49956af011aa3825b17ab6edd18a9eafa19bc2
tree 55415a6fa0ce4faa16296e2a1dbf2dcafdf3503b
parent 02f2210c487d5c2c48fb2b30d15d6dec688e1152
author Patrick McHardy <[email protected]> Wed, 20 Sep 2006 09:27:54 +0200 committer Patrick McHardy <[email protected]> Wed, 20 Sep 2006 09:27:54 +0200
net/netfilter/xt_conntrack.c | 179 +++++++++++++++++++++++------------------- 1 files changed, 98 insertions(+), 81 deletions(-)
net/netfilter/xt_conntrack.c +98 -81
@@ -45,7 +45,7 @@ match(const struct sk_buff *skb, ct =ip_conntrack_get ((struct sk_buff *)skb, &ctinfo); -#define FWINV (bool,invflg) ((bool) ^ !!(sinfo->invflags & invflg)) +#define FWINV (bool, invflg) ((bool) ^ !!(sinfo->invflags & invflg))if (ct == &ip_conntrack_untracked) statebit =XT_CONNTRACK_STATE_UNTRACKED ;
@@ -54,63 +54,72 @@ #define FWINV(bool,invflg) ((bool) ^ !!(else statebit =XT_CONNTRACK_STATE_INVALID ; -if (sinfo->flags &XT_CONNTRACK_STATE ) { +if (sinfo->flags &XT_CONNTRACK_STATE ) {if (ct) { -if (ct->tuplehash[IP_CT_DIR_ORIGINAL ].tuple.src.ip != - ct->tuplehash[IP_CT_DIR_REPLY ].tuple.dst.ip) +if (test_bit (IPS_SRC_NAT_BIT , &ct->status)) statebit |=XT_CONNTRACK_STATE_SNAT ; - -if (ct->tuplehash[IP_CT_DIR_ORIGINAL ].tuple.dst.ip != - ct->tuplehash[IP_CT_DIR_REPLY ].tuple.src.ip) +if (test_bit (IPS_DST_NAT_BIT , &ct->status)) statebit |=XT_CONNTRACK_STATE_DNAT ; } - -if (FWINV ((statebit & sinfo->statemask) ==0 ,XT_CONNTRACK_STATE )) +if (FWINV ((statebit & sinfo->statemask) ==0 , +XT_CONNTRACK_STATE ))return 0 ; } -if (sinfo->flags &XT_CONNTRACK_PROTO ) { -if (!ct ||FWINV (ct->tuplehash[IP_CT_DIR_ORIGINAL ].tuple.dst.protonum != sinfo->tuple[IP_CT_DIR_ORIGINAL ].dst.protonum,XT_CONNTRACK_PROTO )) -return 0 ; - } - -if (sinfo->flags &XT_CONNTRACK_ORIGSRC ) { -if (!ct ||FWINV ((ct->tuplehash[IP_CT_DIR_ORIGINAL ].tuple.src.ip&sinfo->sipmsk[IP_CT_DIR_ORIGINAL ].s_addr) != sinfo->tuple[IP_CT_DIR_ORIGINAL ].src.ip,XT_CONNTRACK_ORIGSRC )) +if (ct ==NULL ) { +if (sinfo->flags & ~XT_CONNTRACK_STATE )return 0 ; +return 1 ; } -if (sinfo->flags &XT_CONNTRACK_ORIGDST ) { -if (!ct ||FWINV ((ct->tuplehash[IP_CT_DIR_ORIGINAL ].tuple.dst.ip&sinfo->dipmsk[IP_CT_DIR_ORIGINAL ].s_addr) != sinfo->tuple[IP_CT_DIR_ORIGINAL ].dst.ip,XT_CONNTRACK_ORIGDST )) -return 0 ; - } - -if (sinfo->flags &XT_CONNTRACK_REPLSRC ) { -if (!ct ||FWINV ((ct->tuplehash[IP_CT_DIR_REPLY ].tuple.src.ip&sinfo->sipmsk[IP_CT_DIR_REPLY ].s_addr) != sinfo->tuple[IP_CT_DIR_REPLY ].src.ip,XT_CONNTRACK_REPLSRC )) -return 0 ; - } +if (sinfo->flags &XT_CONNTRACK_PROTO && +FWINV (ct->tuplehash[IP_CT_DIR_ORIGINAL ].tuple.dst.protonum != + sinfo->tuple[IP_CT_DIR_ORIGINAL ].dst.protonum, +XT_CONNTRACK_PROTO )) +return 0 ; + +if (sinfo->flags &XT_CONNTRACK_ORIGSRC && +FWINV ((ct->tuplehash[IP_CT_DIR_ORIGINAL ].tuple.src.ip & + sinfo->sipmsk[IP_CT_DIR_ORIGINAL ].s_addr) != + sinfo->tuple[IP_CT_DIR_ORIGINAL ].src.ip, +XT_CONNTRACK_ORIGSRC )) +return 0 ; -if (sinfo->flags &XT_CONNTRACK_REPLDST ) { -if (!ct ||FWINV ((ct->tuplehash[IP_CT_DIR_REPLY ].tuple.dst.ip&sinfo->dipmsk[IP_CT_DIR_REPLY ].s_addr) != sinfo->tuple[IP_CT_DIR_REPLY ].dst.ip,XT_CONNTRACK_REPLDST )) -return 0 ; - } +if (sinfo->flags &XT_CONNTRACK_ORIGDST && +FWINV ((ct->tuplehash[IP_CT_DIR_ORIGINAL ].tuple.dst.ip & + sinfo->dipmsk[IP_CT_DIR_ORIGINAL ].s_addr) != + sinfo->tuple[IP_CT_DIR_ORIGINAL ].dst.ip, +XT_CONNTRACK_ORIGDST )) +return 0 ; -if (sinfo->flags &XT_CONNTRACK_STATUS ) { -if (!ct ||FWINV ((ct->status & sinfo->statusmask) ==0 ,XT_CONNTRACK_STATUS )) -return 0 ; - } +if (sinfo->flags &XT_CONNTRACK_REPLSRC && +FWINV ((ct->tuplehash[IP_CT_DIR_REPLY ].tuple.src.ip & + sinfo->sipmsk[IP_CT_DIR_REPLY ].s_addr) != + sinfo->tuple[IP_CT_DIR_REPLY ].src.ip, +XT_CONNTRACK_REPLSRC )) +return 0 ; -if (sinfo->flags &XT_CONNTRACK_EXPIRES ) { -unsigned long expires; +if (sinfo->flags &XT_CONNTRACK_REPLDST && +FWINV ((ct->tuplehash[IP_CT_DIR_REPLY ].tuple.dst.ip & + sinfo->dipmsk[IP_CT_DIR_REPLY ].s_addr) != + sinfo->tuple[IP_CT_DIR_REPLY ].dst.ip, +XT_CONNTRACK_REPLDST )) +return 0 ; -if (!ct) -return 0 ; +if (sinfo->flags &XT_CONNTRACK_STATUS && +FWINV ((ct->status & sinfo->statusmask) ==0 , +XT_CONNTRACK_STATUS )) +return 0 ; - expires =timer_pending (&ct->timeout) ? (ct->timeout.expires - jiffies)/HZ :0 ; +if (sinfo->flags &XT_CONNTRACK_EXPIRES ) { +unsigned long expires =timer_pending (&ct->timeout) ? + (ct->timeout.expires - jiffies)/HZ :0 ; -if (FWINV (!(expires >= sinfo->expires_min && expires <= sinfo->expires_max),XT_CONNTRACK_EXPIRES )) +if (FWINV (!(expires >= sinfo->expires_min && + expires <= sinfo->expires_max), +XT_CONNTRACK_EXPIRES ))return 0 ; } -return 1 ; }
@@ -141,63 +150,72 @@ #define FWINV(bool,invflg) ((bool) ^ !!(else statebit =XT_CONNTRACK_STATE_INVALID ; -if (sinfo->flags &XT_CONNTRACK_STATE ) { +if (sinfo->flags &XT_CONNTRACK_STATE ) {if (ct) { -if (ct->tuplehash[IP_CT_DIR_ORIGINAL ].tuple.src.u3.ip != - ct->tuplehash[IP_CT_DIR_REPLY ].tuple.dst.u3.ip) +if (test_bit (IPS_SRC_NAT_BIT , &ct->status)) statebit |=XT_CONNTRACK_STATE_SNAT ; - -if (ct->tuplehash[IP_CT_DIR_ORIGINAL ].tuple.dst.u3.ip != - ct->tuplehash[IP_CT_DIR_REPLY ].tuple.src.u3.ip) +if (test_bit (IPS_DST_NAT_BIT , &ct->status)) statebit |=XT_CONNTRACK_STATE_DNAT ; } - -if (FWINV ((statebit & sinfo->statemask) ==0 ,XT_CONNTRACK_STATE )) +if (FWINV ((statebit & sinfo->statemask) ==0 , +XT_CONNTRACK_STATE ))return 0 ; } -if (sinfo->flags &XT_CONNTRACK_PROTO ) { -if (!ct ||FWINV (ct->tuplehash[IP_CT_DIR_ORIGINAL ].tuple.dst.protonum != sinfo->tuple[IP_CT_DIR_ORIGINAL ].dst.protonum,XT_CONNTRACK_PROTO )) -return 0 ; - } - -if (sinfo->flags &XT_CONNTRACK_ORIGSRC ) { -if (!ct ||FWINV ((ct->tuplehash[IP_CT_DIR_ORIGINAL ].tuple.src.u3.ip&sinfo->sipmsk[IP_CT_DIR_ORIGINAL ].s_addr) != sinfo->tuple[IP_CT_DIR_ORIGINAL ].src.ip,XT_CONNTRACK_ORIGSRC )) +if (ct ==NULL ) { +if (sinfo->flags & ~XT_CONNTRACK_STATE )return 0 ; +return 1 ; } -if (sinfo->flags &XT_CONNTRACK_ORIGDST ) { -if (!ct ||FWINV ((ct->tuplehash[IP_CT_DIR_ORIGINAL ].tuple.dst.u3.ip&sinfo->dipmsk[IP_CT_DIR_ORIGINAL ].s_addr) != sinfo->tuple[IP_CT_DIR_ORIGINAL ].dst.ip,XT_CONNTRACK_ORIGDST )) -return 0 ; - } - -if (sinfo->flags &XT_CONNTRACK_REPLSRC ) { -if (!ct ||FWINV ((ct->tuplehash[IP_CT_DIR_REPLY ].tuple.src.u3.ip&sinfo->sipmsk[IP_CT_DIR_REPLY ].s_addr) != sinfo->tuple[IP_CT_DIR_REPLY ].src.ip,XT_CONNTRACK_REPLSRC )) -return 0 ; - } +if (sinfo->flags &XT_CONNTRACK_PROTO && +FWINV (ct->tuplehash[IP_CT_DIR_ORIGINAL ].tuple.dst.protonum != + sinfo->tuple[IP_CT_DIR_ORIGINAL ].dst.protonum, +XT_CONNTRACK_PROTO )) +return 0 ; + +if (sinfo->flags &XT_CONNTRACK_ORIGSRC && +FWINV ((ct->tuplehash[IP_CT_DIR_ORIGINAL ].tuple.src.u3.ip & + sinfo->sipmsk[IP_CT_DIR_ORIGINAL ].s_addr) != + sinfo->tuple[IP_CT_DIR_ORIGINAL ].src.ip, +XT_CONNTRACK_ORIGSRC )) +return 0 ; -if (sinfo->flags &XT_CONNTRACK_REPLDST ) { -if (!ct ||FWINV ((ct->tuplehash[IP_CT_DIR_REPLY ].tuple.dst.u3.ip&sinfo->dipmsk[IP_CT_DIR_REPLY ].s_addr) != sinfo->tuple[IP_CT_DIR_REPLY ].dst.ip,XT_CONNTRACK_REPLDST )) -return 0 ; - } +if (sinfo->flags &XT_CONNTRACK_ORIGDST && +FWINV ((ct->tuplehash[IP_CT_DIR_ORIGINAL ].tuple.dst.u3.ip & + sinfo->dipmsk[IP_CT_DIR_ORIGINAL ].s_addr) != + sinfo->tuple[IP_CT_DIR_ORIGINAL ].dst.ip, +XT_CONNTRACK_ORIGDST )) +return 0 ; -if (sinfo->flags &XT_CONNTRACK_STATUS ) { -if (!ct ||FWINV ((ct->status & sinfo->statusmask) ==0 ,XT_CONNTRACK_STATUS )) -return 0 ; - } +if (sinfo->flags &XT_CONNTRACK_REPLSRC && +FWINV ((ct->tuplehash[IP_CT_DIR_REPLY ].tuple.src.u3.ip & + sinfo->sipmsk[IP_CT_DIR_REPLY ].s_addr) != + sinfo->tuple[IP_CT_DIR_REPLY ].src.ip, +XT_CONNTRACK_REPLSRC )) +return 0 ; -if (sinfo->flags &XT_CONNTRACK_EXPIRES ) { -unsigned long expires; +if (sinfo->flags &XT_CONNTRACK_REPLDST && +FWINV ((ct->tuplehash[IP_CT_DIR_REPLY ].tuple.dst.u3.ip & + sinfo->dipmsk[IP_CT_DIR_REPLY ].s_addr) != + sinfo->tuple[IP_CT_DIR_REPLY ].dst.ip, +XT_CONNTRACK_REPLDST )) +return 0 ; -if (!ct) -return 0 ; +if (sinfo->flags &XT_CONNTRACK_STATUS && +FWINV ((ct->status & sinfo->statusmask) ==0 , +XT_CONNTRACK_STATUS )) +return 0 ; - expires =timer_pending (&ct->timeout) ? (ct->timeout.expires - jiffies)/HZ :0 ; +if (sinfo->flags &XT_CONNTRACK_EXPIRES ) { +unsigned long expires =timer_pending (&ct->timeout) ? + (ct->timeout.expires - jiffies)/HZ :0 ; -if (FWINV (!(expires >= sinfo->expires_min && expires <= sinfo->expires_max),XT_CONNTRACK_EXPIRES )) +if (FWINV (!(expires >= sinfo->expires_min && + expires <= sinfo->expires_max), +XT_CONNTRACK_EXPIRES ))return 0 ; } -return 1 ; }
@@ -220,8 +238,7 @@ #endifreturn 1 ; } -static void -destroy (const struct xt_match *match,void *matchinfo) +static void destroy (const struct xt_match *match,void *matchinfo) {#if defined(CONFIG_NF_CONNTRACK ) || defined(CONFIG_NF_CONNTRACK_MODULE )nf_ct_l3proto_module_put (match->family);
PATCH 4/39 : ipt_TCPMSS: reformat
In reply to Patrick McHardy[NETFILTER]: ipt_TCPMSS: reformat
- fix whitespace error
- break lines at 80 characters
- reformat some expressions to be more readable
---
commit feaf79fd9c26309b0bffa69e7b4f835fc8f30179
tree 2cb4ada2adc12cc4cc2130948678893899cfb14f
parent 9e49956af011aa3825b17ab6edd18a9eafa19bc2
author Patrick McHardy <[email protected]> Wed, 20 Sep 2006 09:28:00 +0200 committer Patrick McHardy <[email protected]> Wed, 20 Sep 2006 09:28:00 +0200
net/ipv4/netfilter/ipt_TCPMSS.c | 58 +++++++++++++++++++++------------------ 1 files changed, 31 insertions(+), 27 deletions(-)
net/ipv4/netfilter/ipt_TCPMSS.c +31 -27
@@ -31,8 +31,10 @@ static inline unsigned int optlen(const u_int8_t *opt, unsigned int offset) {/* Beware zero-length options: make finite progress */ -if (opt[offset] <=TCPOPT_NOP || opt[offset+1 ] ==0 )return 1 ; -else return opt[offset+1 ]; +if (opt[offset] <=TCPOPT_NOP || opt[offset+1 ] ==0 ) +return 1 ; +else +return opt[offset+1 ]; } static unsigned int
@@ -55,7 +57,6 @@ ipt_tcpmss_target(struct sk_buff **pskb, iph = (*pskb)->nh.iph; tcplen = (*pskb)->len - iph->ihl*4 ; - tcph = (void *)iph + iph->ihl*4 ;/* Since it passed flags test in tcp match, we know it is is
@@ -71,37 +72,39 @@ ipt_tcpmss_target(struct sk_buff **pskb,return NF_DROP ; } -if (tcpmssinfo->mss ==IPT_TCPMSS_CLAMP_PMTU ) { -if (!(*pskb)->dst) { +if (tcpmssinfo->mss ==IPT_TCPMSS_CLAMP_PMTU ) { +if (!(*pskb)->dst) {if (net_ratelimit ()) -printk (KERN_ERR -"ipt_tcpmss_target: no dst?! can't determine path-MTU\n" ); +printk (KERN_ERR "ipt_tcpmss_target: " +"no dst?! can't determine path-MTU\n" );return NF_DROP ;/* or IPT_CONTINUE ?? */ } -if (dst_mtu ((*pskb)->dst) <= (sizeof (struct iphdr ) +sizeof (struct tcphdr ))) { +if (dst_mtu ((*pskb)->dst) <=sizeof (struct iphdr ) + +sizeof (struct tcphdr )) {if (net_ratelimit ()) -printk (KERN_ERR -"ipt_tcpmss_target: unknown or invalid path-MTU (%d)\n" ,dst_mtu ((*pskb)->dst)); +printk (KERN_ERR "ipt_tcpmss_target: " +"unknown or invalid path-MTU (%d)\n" , +dst_mtu ((*pskb)->dst));return NF_DROP ;/* or IPT_CONTINUE ?? */ } - newmss =dst_mtu ((*pskb)->dst) -sizeof (struct iphdr ) -sizeof (struct tcphdr ); + newmss =dst_mtu ((*pskb)->dst) -sizeof (struct iphdr ) - +sizeof (struct tcphdr ); }else newmss = tcpmssinfo->mss; opt = (u_int8_t *)tcph; -for (i =sizeof (struct tcphdr ); i < tcph->doff*4 ; i +=optlen (opt, i)){ -if ((opt[i] ==TCPOPT_MSS ) && - ((tcph->doff*4 - i) >=TCPOLEN_MSS ) && - (opt[i+1 ] ==TCPOLEN_MSS )) { +for (i =sizeof (struct tcphdr ); i < tcph->doff*4 ; i +=optlen (opt, i)) { +if (opt[i] ==TCPOPT_MSS && tcph->doff*4 - i >=TCPOLEN_MSS && + opt[i+1 ] ==TCPOLEN_MSS ) {u_int16_t oldmss; oldmss = (opt[i+2 ] <<8 ) | opt[i+3 ]; -if ((tcpmssinfo->mss ==IPT_TCPMSS_CLAMP_PMTU ) && - (oldmss <= newmss)) -return IPT_CONTINUE ; +if (tcpmssinfo->mss ==IPT_TCPMSS_CLAMP_PMTU && + oldmss <= newmss) +return IPT_CONTINUE ; opt[i+2 ] = (newmss &0xff00 ) >>8 ; opt[i+3 ] = (newmss &0x00ff );
@@ -113,7 +116,7 @@ ipt_tcpmss_target(struct sk_buff **pskb, DEBUGP(KERN_INFO "ipt_tcpmss_target: %u.%u.%u.%u:%hu" "->%u.%u.%u.%u:%hu changed TCP MSS option" - " (from %u to %u)\n", + " (from %u to %u)\n", NIPQUAD((*pskb)->nh.iph->saddr), ntohs(tcph->source), NIPQUAD((*pskb)->nh.iph->daddr),
@@ -193,9 +196,9 @@ static inline int find_syn_match(const s {const struct ipt_tcp *tcpinfo = (const struct ipt_tcp *)m->data; -if (strcmp (m->u.kernel.match->name,"tcp" ) ==0 - && (tcpinfo->flg_cmp &TH_SYN ) - && !(tcpinfo->invflags &IPT_TCP_INV_FLAGS )) +if (strcmp (m->u.kernel.match->name,"tcp" ) ==0 && + tcpinfo->flg_cmp &TH_SYN && + !(tcpinfo->invflags &IPT_TCP_INV_FLAGS ))return 1 ;return 0 ;
@@ -212,11 +215,12 @@ ipt_tcpmss_checkentry(const char *tablenconst struct ipt_tcpmss_info *tcpmssinfo = targinfo;const struct ipt_entry *e = e_void; -if ((tcpmssinfo->mss ==IPT_TCPMSS_CLAMP_PMTU ) && - ((hook_mask & ~((1 <<NF_IP_FORWARD ) - | (1 <<NF_IP_LOCAL_OUT ) - | (1 <<NF_IP_POST_ROUTING ))) !=0 )) { -printk ("TCPMSS: path-MTU clamping only supported in FORWARD, OUTPUT and POSTROUTING hooks\n" ); +if (tcpmssinfo->mss ==IPT_TCPMSS_CLAMP_PMTU && + (hook_mask & ~((1 <<NF_IP_FORWARD ) | + (1 <<NF_IP_LOCAL_OUT ) | + (1 <<NF_IP_POST_ROUTING ))) !=0 ) { +printk ("TCPMSS: path-MTU clamping only supported in " +"FORWARD, OUTPUT and POSTROUTING hooks\n" );return 0 ; }
PATCH 5/39 : ipt_TCPMSS: remove impossible condition
In reply to Patrick McHardy[NETFILTER]: ipt_TCPMSS: remove impossible condition
Every skb must have a dst_entry at this point.
---
commit a33f866d48a8ce0f83293a6ee1dbfd4a5345499f
tree de65c4992e63b67d2dd968c26000ea6ee36085a6
parent feaf79fd9c26309b0bffa69e7b4f835fc8f30179
author Patrick McHardy <[email protected]> Wed, 20 Sep 2006 09:28:04 +0200 committer Patrick McHardy <[email protected]> Wed, 20 Sep 2006 09:28:04 +0200
net/ipv4/netfilter/ipt_TCPMSS.c | 7 ------- 1 files changed, 0 insertions(+), 7 deletions(-)
net/ipv4/netfilter/ipt_TCPMSS.c +0 -7
@@ -73,13 +73,6 @@ ipt_tcpmss_target(struct sk_buff **pskb, }if (tcpmssinfo->mss ==IPT_TCPMSS_CLAMP_PMTU ) { -if (!(*pskb)->dst) { -if (net_ratelimit ()) -printk (KERN_ERR "ipt_tcpmss_target: " -"no dst?! can't determine path-MTU\n" ); -return NF_DROP ;/* or IPT_CONTINUE ?? */ - } -if (dst_mtu ((*pskb)->dst) <=sizeof (struct iphdr ) +sizeof (struct tcphdr )) {if (net_ratelimit ())
PATCH 6/39 : ipt_TCPMSS: misc cleanup
In reply to Patrick McHardy[NETFILTER]: ipt_TCPMSS: misc cleanup
- remove debugging cruft
- remove printk for reallocation failures
- remove unused addition
---
commit 78cd435225fca1420030a898433ae7eae9ab0cf6
tree eb429a0d0fddd69a4bcafc05def8b7521e1d6ced
parent a33f866d48a8ce0f83293a6ee1dbfd4a5345499f
author Patrick McHardy <[email protected]> Wed, 20 Sep 2006 09:28:11 +0200 committer Patrick McHardy <[email protected]> Wed, 20 Sep 2006 09:28:11 +0200
net/ipv4/netfilter/ipt_TCPMSS.c | 36 ++---------------------------------- 1 files changed, 2 insertions(+), 34 deletions(-)
net/ipv4/netfilter/ipt_TCPMSS.c +2 -34
@@ -21,12 +21,6 @@ MODULE_LICENSE("GPL");MODULE_AUTHOR ("Marc Boucher <[email protected]>" );MODULE_DESCRIPTION ("iptables TCP MSS modification module" ); -#if 0 -#define DEBUGP printk -#else -#define DEBUGP(format, args...) -#endif -static inline unsigned int optlen (const u_int8_t *opt,unsigned int offset) {
@@ -106,16 +100,7 @@ ipt_tcpmss_target(struct sk_buff **pskb,htons (oldmss)^0xFFFF ,htons (newmss), tcph->check, 0); - -DEBUGP (KERN_INFO "ipt_tcpmss_target: %u.%u.%u.%u:%hu" -"->%u.%u.%u.%u:%hu changed TCP MSS option" -" (from %u to %u)\n" , -NIPQUAD ((*pskb)->nh.iph->saddr), -ntohs (tcph->source), -NIPQUAD ((*pskb)->nh.iph->daddr), -ntohs (tcph->dest), - oldmss, newmss); - goto retmodified; +return IPT_CONTINUE ; } }
@@ -127,13 +112,8 @@ ipt_tcpmss_target(struct sk_buff **pskb, newskb =skb_copy_expand (*pskb,skb_headroom (*pskb),TCPOLEN_MSS ,GFP_ATOMIC ); -if (!newskb) { -if (net_ratelimit ()) -printk (KERN_ERR "ipt_tcpmss_target:" -" unable to allocate larger skb\n" ); +if (!newskb)return NF_DROP ; - } -kfree_skb (*pskb); *pskb = newskb; iph = (*pskb)->nh.iph;
@@ -149,8 +129,6 @@ ipt_tcpmss_target(struct sk_buff **pskb,htons (tcplen) ^0xFFFF ,htons (tcplen +TCPOLEN_MSS ), tcph->check, 1); - tcplen +=TCPOLEN_MSS ; - opt[0 ] =TCPOPT_MSS ; opt[1 ] =TCPOLEN_MSS ; opt[2 ] = (newmss &0xff00 ) >>8 ;
@@ -170,16 +148,6 @@ ipt_tcpmss_target(struct sk_buff **pskb, iph->check =nf_csum_update (iph->tot_len ^0xFFFF , newtotlen, iph->check); iph->tot_len = newtotlen; - -DEBUGP (KERN_INFO "ipt_tcpmss_target: %u.%u.%u.%u:%hu" -"->%u.%u.%u.%u:%hu added TCP MSS option (%u)\n" , -NIPQUAD ((*pskb)->nh.iph->saddr), -ntohs (tcph->source), -NIPQUAD ((*pskb)->nh.iph->daddr), -ntohs (tcph->dest), - newmss); - - retmodified:return IPT_CONTINUE ; }
PATCH 7/39 : xt_limit: don't reset state on unrelated rule updates
In reply to Patrick McHardy[NETFILTER]: xt_limit: don't reset state on unrelated rule updates
The limit match reinitializes its state whenever the ruleset changes, which means it will forget about previously used credits.
---
commit 9bab1a93f9739bf8346f256181e971dabf0ea775
tree 5880436a577221212da57efd669a2cc6f35f0e69
parent 78cd435225fca1420030a898433ae7eae9ab0cf6
author Patrick McHardy <[email protected]> Wed, 20 Sep 2006 09:28:15 +0200 committer Patrick McHardy <[email protected]> Wed, 20 Sep 2006 09:28:15 +0200
net/netfilter/xt_limit.c | 16 ++++++++-------- 1 files changed, 8 insertions(+), 8 deletions(-)
net/netfilter/xt_limit.c +8 -8
@@ -122,16 +122,16 @@ ipt_limit_checkentry(const char *tablenareturn 0 ; } -/* User avg in seconds * XT_LIMIT_SCALE: convert to jiffies * -128. */ - r->prev = jiffies; - r->credit =user2credits (r->avg * r->burst);/* Credits full. */ - r->credit_cap =user2credits (r->avg * r->burst);/* Credits full. */ - r->cost =user2credits (r->avg); -/* For SMP, we only want to use one set of counters. */ r->master = r; - +if (r->cost ==0 ) { +/* User avg in seconds * XT_LIMIT_SCALE: convert to jiffies * +128. */ + r->prev = jiffies; + r->credit =user2credits (r->avg * r->burst);/* Credits full. */ + r->credit_cap =user2credits (r->avg * r->burst);/* Credits full. */ + r->cost =user2credits (r->avg); + }return 1 ; }
PATCH 8/39 : ip6table_mangle: reroute when nfmark changes in NF_IP6_LOCAL_OUT
In reply to Patrick McHardy[NETFILTER]: ip6table_mangle: reroute when nfmark changes in NF_IP6_LOCAL_OUT
Now that IPv6 supports policy routing we need to reroute in NF_IP6_LOCAL_OUT when the mark value changes.
---
commit 488390a83da9b1bee0eabf6bf31d9fd1bca88b7d
tree f5b9e7754ec69ded1930ced6a901f2ec5250e745
parent 9bab1a93f9739bf8346f256181e971dabf0ea775
author Patrick McHardy <[email protected]> Wed, 20 Sep 2006 09:28:22 +0200 committer Patrick McHardy <[email protected]> Wed, 20 Sep 2006 09:28:22 +0200
include/linux/netfilter_ipv6.h | 1 + include/net/ip6_route.h | 2 -- net/ipv6/netfilter/ip6table_mangle.c | 8 ++------ 3 files changed, 3 insertions(+), 8 deletions(-)
include/linux/netfilter_ipv6.h +1 -0
@@ -73,6 +73,7 @@ enum nf_ip6_hook_priorities { };#ifdef CONFIG_NETFILTER +extern int ip6_route_me_harder (struct sk_buff *skb);extern unsigned int nf_ip6_checksum (struct sk_buff *skb,unsigned int hook,unsigned int dataoff,u_int8_t protocol);
include/net/ip6_route.h +0 -2
@@ -57,8 +57,6 @@ extern void ip6_route_input(struct sk_extern struct dst_entry *ip6_route_output (struct sock *sk,struct flowi *fl); -extern int ip6_route_me_harder (struct sk_buff *skb); -extern void ip6_route_init (void );extern void ip6_route_cleanup (void );
net/ipv6/netfilter/ip6table_mangle.c +2 -6
@@ -180,12 +180,8 @@ #endif && (memcmp(&(*pskb)->nh.ipv6h->saddr, &saddr, sizeof(saddr)) || memcmp(&(*pskb)->nh.ipv6h->daddr, &daddr, sizeof(daddr)) || (*pskb)->nfmark != nfmark - || (*pskb)->nh.ipv6h->hop_limit != hop_limit)) { - -/* something which could affect routing has changed */ - -DEBUGP ("ip6table_mangle: we'd need to re-route a packet\n" ); - } + || (*pskb)->nh.ipv6h->hop_limit != hop_limit)) +return ip6_route_me_harder (*pskb) ==0 ? ret :NF_DROP ;return ret; }
PATCH 9/39 : x_tables: small check_entry & module_refcount cleanup
In reply to Patrick McHardy[NETFILTER]: x_tables: small check_entry & module_refcount cleanup
While standard_target has target->me == NULL, module_put() should be called for it as for others, because there were try_module_get() before.
---
commit ac65877cea178bc9100074a0f778e01761be8634
tree eb19de08a1671d1a4cbec06b4cd10fcc97156236
parent 488390a83da9b1bee0eabf6bf31d9fd1bca88b7d
author Dmitry Mishin <[email protected]> Wed, 20 Sep 2006 09:28:30 +0200 committer Patrick McHardy <[email protected]> Wed, 20 Sep 2006 09:28:30 +0200
net/ipv4/netfilter/arp_tables.c | 2 +- net/ipv4/netfilter/ip_tables.c | 2 +- net/ipv6/netfilter/ip6_tables.c | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-)
net/ipv4/netfilter/arp_tables.c +1 -1
@@ -485,7 +485,7 @@ static inline int check_entry(struct arpif (t->u.kernel.target == &arpt_standard_target) {if (!standard_check (t, size)) { ret = -EINVAL ; - goto out; + goto err; } }else if (t->u.kernel.target->checkentry && !t->u.kernel.target->checkentry(name, e, target, t->data,
net/ipv4/netfilter/ip_tables.c +1 -1
@@ -573,7 +573,7 @@ check_entry(struct ipt_entry *e, const cif (t->u.kernel.target == &ipt_standard_target) {if (!standard_check (t, size)) { ret = -EINVAL ; - goto cleanup_matches; + goto err; } }else if (t->u.kernel.target->checkentry && !t->u.kernel.target->checkentry(name, e, target, t->data,
net/ipv6/netfilter/ip6_tables.c +1 -1
@@ -610,7 +610,7 @@ check_entry(struct ip6t_entry *e, constif (t->u.kernel.target == &ip6t_standard_target) {if (!standard_check (t, size)) { ret = -EINVAL ; - goto cleanup_matches; + goto err; } }else if (t->u.kernel.target->checkentry && !t->u.kernel.target->checkentry(name, e, target, t->data,
PATCH 10/39 : ctnetlink: simplify the code to dump the conntrack table
In reply to Patrick McHardy[NETFILTER]: ctnetlink: simplify the code to dump the conntrack table
Merge the bits to dump the conntrack table and the ones to dump and zero counters in a single piece of code. This patch does not change the default behaviour if accounting is not enabled.
---
commit 2d7b5900c6ec411811c3ec01ea7caf75dc694f3e
tree 9f54c5119b690be9c524e590257138f6e4a1569d
parent ac65877cea178bc9100074a0f778e01761be8634
author Pablo Neira Ayuso <[email protected]> Wed, 20 Sep 2006 09:28:35 +0200 committer Patrick McHardy <[email protected]> Wed, 20 Sep 2006 09:28:35 +0200
net/ipv4/netfilter/ip_conntrack_netlink.c | 63 ++++----------------------- net/netfilter/nf_conntrack_netlink.c | 67 ++++------------------------- 2 files changed, 20 insertions(+), 110 deletions(-)
net/ipv4/netfilter/ip_conntrack_netlink.c +10 -53
@@ -436,6 +436,11 @@ restart: cb->args[1 ] = (unsigned long )ct; goto out; } +#ifdef CONFIG_NF_CT_ACCT +if (NFNL_MSG_TYPE (cb->nlh->nlmsg_type) == +IPCTNL_MSG_CT_GET_CTRZERO ) +memset (&ct->counters,0 ,sizeof (ct->counters)); +#endif }if (cb->args[1 ]) { cb->args[1 ] =0 ;
@@ -451,46 +456,6 @@ out:return skb->len; } -#ifdef CONFIG_IP_NF_CT_ACCT -static int -ctnetlink_dump_table_w (struct sk_buff *skb,struct netlink_callback *cb) -{ -struct ip_conntrack *ct =NULL ; -struct ip_conntrack_tuple_hash *h; -struct list_head *i; -u_int32_t *id = (u_int32_t *) &cb->args[1 ]; - -DEBUGP ("entered %s, last bucket=%u id=%u\n" , __FUNCTION__, - cb->args[0 ], *id); - -write_lock_bh (&ip_conntrack_lock); -for (; cb->args[0 ] < ip_conntrack_htable_size; cb->args[0 ]++, *id =0 ) { -list_for_each_prev (i, &ip_conntrack_hash[cb->args[0 ]]) { - h = (struct ip_conntrack_tuple_hash *) i; -if (DIRECTION (h) !=IP_CT_DIR_ORIGINAL ) -continue ; - ct =tuplehash_to_ctrack (h); -if (ct->id <= *id) -continue ; -if (ctnetlink_fill_info (skb,NETLINK_CB (cb->skb).pid, - cb->nlh->nlmsg_seq, -IPCTNL_MSG_CT_NEW , -1 , ct) <0 ) - goto out; - *id = ct->id; - -memset (&ct->counters,0 ,sizeof (ct->counters)); - } - } -out: -write_unlock_bh (&ip_conntrack_lock); - -DEBUGP ("leaving, last bucket=%lu id=%u\n" , cb->args[0 ], *id); - -return skb->len; -} -#endif -static const size_t cta_min_ip[CTA_IP_MAX ] = { [CTA_IP_V4_SRC -1 ] =sizeof (u_int32_t), [CTA_IP_V4_DST -1 ] =sizeof (u_int32_t),
@@ -775,22 +740,14 @@ ctnetlink_get_conntrack(struct sock *ctnif (msg->nfgen_family !=AF_INET )return -EAFNOSUPPORT ; -if (NFNL_MSG_TYPE (nlh->nlmsg_type) == -IPCTNL_MSG_CT_GET_CTRZERO ) { -#ifdef CONFIG_IP_NF_CT_ACCT -if ((*errp =netlink_dump_start (ctnl, skb, nlh, - ctnetlink_dump_table_w, - ctnetlink_done)) !=0 ) -return -EINVAL ; -#else +#ifndef CONFIG_IP_NF_CT_ACCT +if (NFNL_MSG_TYPE (nlh->nlmsg_type) ==IPCTNL_MSG_CT_GET_CTRZERO )return -ENOTSUPP ;#endif - }else { -if ((*errp =netlink_dump_start (ctnl, skb, nlh, - ctnetlink_dump_table, - ctnetlink_done)) !=0 ) +if ((*errp =netlink_dump_start (ctnl, skb, nlh, + ctnetlink_dump_table, + ctnetlink_done)) !=0 )return -EINVAL ; - } rlen =NLMSG_ALIGN (nlh->nlmsg_len);if (rlen > skb->len)
net/netfilter/nf_conntrack_netlink.c +10 -57
88 lines not on this page · raw message
PATCH 11/39 : conntrack: fix race condition in early_drop
In reply to Patrick McHardy[NETFILTER]: conntrack: fix race condition in early_drop
On SMP environments the maximum number of conntracks can be overpassed under heavy stress situations due to an existing race condition.
CPU A CPU B
atomic_read() ...
early_drop() ...
... atomic_read()
allocate conntrack allocate conntrack
atomic_inc() atomic_inc()
This patch moves the counter incrementation before the early drop stage.
---
commit 56a0ea23e536624ad1ea186289bb5d686ca19425
tree c56f7cbb8b47d1e153440062f34f26604c250aa8
parent 2d7b5900c6ec411811c3ec01ea7caf75dc694f3e
author Pablo Neira Ayuso <[email protected]> Wed, 20 Sep 2006 09:28:41 +0200 committer Patrick McHardy <[email protected]> Wed, 20 Sep 2006 09:28:41 +0200
net/ipv4/netfilter/ip_conntrack_core.c | 9 ++++++--- net/netfilter/nf_conntrack_core.c | 10 ++++++++-- 2 files changed, 14 insertions(+), 5 deletions(-)
net/ipv4/netfilter/ip_conntrack_core.c +6 -3
@@ -622,11 +622,15 @@ struct ip_conntrack *ip_conntrack_alloc( ip_conntrack_hash_rnd_initted =1 ; } +/* We don't want any race condition at early drop stage */ +atomic_inc (&ip_conntrack_count); +if (ip_conntrack_max - &&atomic_read (&ip_conntrack_count) >= ip_conntrack_max) { + &&atomic_read (&ip_conntrack_count) > ip_conntrack_max) {unsigned int hash =hash_conntrack (orig);/* Try dropping from this hash chain. */ if (!early_drop (&ip_conntrack_hash[hash])) { +atomic_dec (&ip_conntrack_count);if (net_ratelimit ())printk (KERN_WARNING "ip_conntrack: table full, dropping"
@@ -638,6 +642,7 @@ struct ip_conntrack *ip_conntrack_alloc( conntrack =kmem_cache_alloc (ip_conntrack_cachep,GFP_ATOMIC );if (!conntrack) {DEBUGP ("Can't allocate conntrack.\n" ); +atomic_dec (&ip_conntrack_count);return ERR_PTR (-ENOMEM ); }
@@ -651,8 +656,6 @@ struct ip_conntrack *ip_conntrack_alloc( conntrack->timeout.data = (unsigned long )conntrack; conntrack->timeout.function = death_by_timeout; -atomic_inc (&ip_conntrack_count); -return conntrack; }
net/netfilter/nf_conntrack_core.c +8 -2
@@ -848,11 +848,15 @@ __nf_conntrack_alloc(const struct nf_con nf_conntrack_hash_rnd_initted =1 ; } +/* We don't want any race condition at early drop stage */ +atomic_inc (&nf_conntrack_count); +if (nf_conntrack_max - &&atomic_read (&nf_conntrack_count) >= nf_conntrack_max) { + &&atomic_read (&nf_conntrack_count) > nf_conntrack_max) {unsigned int hash =hash_conntrack (orig);/* Try dropping from this hash chain. */ if (!early_drop (&nf_conntrack_hash[hash])) { +atomic_dec (&nf_conntrack_count);if (net_ratelimit ())printk (KERN_WARNING "nf_conntrack: table full, dropping"
@@ -903,10 +907,12 @@ __nf_conntrack_alloc(const struct nf_coninit_timer (&conntrack->timeout); conntrack->timeout.data = (unsigned long )conntrack; conntrack->timeout.function = death_by_timeout; +read_unlock_bh (&nf_ct_cache_lock); -atomic_inc (&nf_conntrack_count); +return conntrack; out:read_unlock_bh (&nf_ct_cache_lock); +atomic_dec (&nf_conntrack_count);return conntrack; }
PATCH 12/39 : ipt_TTL: fix checksum update bug
In reply to Patrick McHardy[NETFILTER]: ipt_TTL: fix checksum update bug
Fix regression introduced by the incremental checksum patches.
---
commit 0c081f02b0a8b3a08aa5ddc888f9af834585d431
tree ff630777fb523976961ac8303d680c7cc0a00975
parent 56a0ea23e536624ad1ea186289bb5d686ca19425
author Patrick McHardy <[email protected]> Wed, 20 Sep 2006 09:28:47 +0200 committer Patrick McHardy <[email protected]> Wed, 20 Sep 2006 09:28:47 +0200
net/ipv4/netfilter/ipt_TTL.c | 4 ++-- 1 files changed, 2 insertions(+), 2 deletions(-)
net/ipv4/netfilter/ipt_TTL.c +2 -2
@@ -54,8 +54,8 @@ ipt_ttl_target(struct sk_buff **pskb, }if (new_ttl != iph->ttl) { - iph->check =nf_csum_update ((iph->ttl <<8 ) ^0xFFFF , - new_ttl <<8 , + iph->check =nf_csum_update (ntohs ((iph->ttl <<8 )) ^0xFFFF , +ntohs (new_ttl <<8 ), iph->check); iph->ttl = new_ttl; }
PATCH 13/39 : ip6t_HL: remove write-only variable
In reply to Patrick McHardy[NETFILTER]: ip6t_HL: remove write-only variable
Noticed by Alexey Dobriyan <[email protected]>
---
commit bbd34939b0f748864400c9b12ecc3f43b7dbddc8
tree 68d33bcbae9b298594ccf3f8bdbc50929d0e60ec
parent 0c081f02b0a8b3a08aa5ddc888f9af834585d431
author Patrick McHardy <[email protected]> Wed, 20 Sep 2006 09:28:52 +0200 committer Patrick McHardy <[email protected]> Wed, 20 Sep 2006 09:28:52 +0200
net/ipv6/netfilter/ip6t_HL.c | 6 +----- 1 files changed, 1 insertions(+), 5 deletions(-)
net/ipv6/netfilter/ip6t_HL.c +1 -5
@@ -26,7 +26,6 @@ static unsigned int ip6t_hl_target(struc {struct ipv6hdr *ip6h;const struct ip6t_HL_info *info = targinfo; -u_int16_t diffs[2 ];int new_hl;if (!skb_make_writable (pskb, (*pskb)->len))
@@ -53,11 +52,8 @@ static unsigned int ip6t_hl_target(strucbreak ; } -if (new_hl != ip6h->hop_limit) { - diffs[0 ] =htons (((unsigned )ip6h->hop_limit) <<8 ) ^0xFFFF ; +if (new_hl != ip6h->hop_limit) ip6h->hop_limit = new_hl; - diffs[1 ] =htons (((unsigned )ip6h->hop_limit) <<8 ); - }return IP6T_CONTINUE ; }
PATCH 14/39 : xt_policy: remove dups in .family
In reply to Patrick McHardy[NETFILTER]: xt_policy: remove dups in .family
sparse "defined twice" warning
---
commit 4a96b874e237df6f156bd186bf7671da3875ee6a
tree 9f3620858c365d2b6441eeee1e4c369e05962fc7
parent bbd34939b0f748864400c9b12ecc3f43b7dbddc8
author Alexey Dobriyan <[email protected]> Wed, 20 Sep 2006 09:28:59 +0200 committer Patrick McHardy <[email protected]> Wed, 20 Sep 2006 09:28:59 +0200
net/netfilter/xt_policy.c | 2 -- 1 files changed, 0 insertions(+), 2 deletions(-)
net/netfilter/xt_policy.c +0 -2
@@ -171,7 +171,6 @@ static struct xt_match xt_policy_match[] .checkentry = checkentry, .match = match, .matchsize = sizeof(struct xt_policy_info), - .family = AF_INET, .me = THIS_MODULE, }, {
@@ -180,7 +179,6 @@ static struct xt_match xt_policy_match[] .checkentry = checkentry, .match = match, .matchsize = sizeof(struct xt_policy_info), - .family = AF_INET6, .me = THIS_MODULE, }, };
PATCH 15/39 : TCP conntrack: improve dead connection detection
In reply to Patrick McHardy[NETFILTER]: TCP conntrack: improve dead connection detection
Don't count window updates as retransmissions.
---
commit 21df1122e9ade53430f3c3a7e188ec194baedb93
tree d56625d297a4cc820ed085b15d32558bafa87c39
parent 4a96b874e237df6f156bd186bf7671da3875ee6a
author George Hansper <[email protected]> Wed, 20 Sep 2006 09:29:05 +0200 committer Patrick McHardy <[email protected]> Wed, 20 Sep 2006 09:29:05 +0200
include/linux/netfilter/nf_conntrack_tcp.h | 1 + net/ipv4/netfilter/ip_conntrack_proto_tcp.c | 4 +++- net/netfilter/nf_conntrack_proto_tcp.c | 4 +++- 3 files changed, 7 insertions(+), 2 deletions(-)
include/linux/netfilter/nf_conntrack_tcp.h +1 -0
@@ -49,6 +49,7 @@ struct ip_ct_tcpu_int32_t last_seq;/* Last sequence number seen in dir */ u_int32_t last_ack;/* Last sequence number seen in opposite dir */ u_int32_t last_end;/* Last seq + len */ + u_int16_t last_win; /* Last window advertisement seen in dir */ };#endif /* __KERNEL__ */
net/ipv4/netfilter/ip_conntrack_proto_tcp.c +3 -1
@@ -731,13 +731,15 @@ static int tcp_in_window(struct ip_ct_tcif (state->last_dir == dir && state->last_seq == seq && state->last_ack == ack - && state->last_end == end) + && state->last_end == end + && state->last_win == win) state->retrans++;else { state->last_dir = dir; state->last_seq = seq; state->last_ack = ack; state->last_end = end; + state->last_win = win; state->retrans =0 ; } }
net/netfilter/nf_conntrack_proto_tcp.c +3 -1
@@ -688,13 +688,15 @@ static int tcp_in_window(struct ip_ct_tcif (state->last_dir == dir && state->last_seq == seq && state->last_ack == ack - && state->last_end == end) + && state->last_end == end + && state->last_win == win) state->retrans++;else { state->last_dir = dir; state->last_seq = seq; state->last_ack = ack; state->last_end = end; + state->last_win = win; state->retrans =0 ; } }
PATCH 16/39 : make some netfilter globals __read_mostly
In reply to Patrick McHardy[NETFILTER]: make some netfilter globals __read_mostly
---
commit 850a4981b57001c022d4b69a24d163404823ddb3
tree 2c28cff31a435bf021029b68b049fc8168592ff4
parent 21df1122e9ade53430f3c3a7e188ec194baedb93
author Brian Haley <[email protected]> Wed, 20 Sep 2006 09:35:56 +0200 committer Patrick McHardy <[email protected]> Wed, 20 Sep 2006 09:35:56 +0200
net/ipv4/netfilter/ip_conntrack_core.c | 6 +++--- net/ipv4/netfilter/ip_queue.c | 8 ++++---- net/ipv6/netfilter/ip6_queue.c | 8 ++++---- net/netfilter/nf_conntrack_core.c | 10 +++++----- 4 files changed, 16 insertions(+), 16 deletions(-)
net/ipv4/netfilter/ip_conntrack_core.c +3 -3
@@ -63,17 +63,17 @@ atomic_t ip_conntrack_count = ATOMIC_INIvoid (*ip_conntrack_destroyed)(struct ip_conntrack *conntrack) =NULL ;LIST_HEAD (ip_conntrack_expect_list); -struct ip_conntrack_protocol *ip_ct_protos[MAX_IP_CT_PROTO ]; +struct ip_conntrack_protocol *ip_ct_protos[MAX_IP_CT_PROTO ]__read_mostly ;static LIST_HEAD (helpers);unsigned int ip_conntrack_htable_size__read_mostly =0 ;int ip_conntrack_max__read_mostly ; -struct list_head *ip_conntrack_hash; +struct list_head *ip_conntrack_hash__read_mostly ;static kmem_cache_t *ip_conntrack_cachep__read_mostly ;static kmem_cache_t *ip_conntrack_expect_cachep__read_mostly ;struct ip_conntrack ip_conntrack_untracked;unsigned int ip_ct_log_invalid__read_mostly ;static LIST_HEAD (unconfirmed); -static int ip_conntrack_vmalloc; +static int ip_conntrack_vmalloc__read_mostly ;static unsigned int ip_conntrack_next_id;static unsigned int ip_conntrack_expect_next_id;
net/ipv4/netfilter/ip_queue.c +4 -4
@@ -52,15 +52,15 @@ struct ipq_queue_entry {typedef int (*ipq_cmpfn )(struct ipq_queue_entry *,unsigned long ); -static unsigned char copy_mode =IPQ_COPY_NONE ; +static unsigned char copy_mode__read_mostly =IPQ_COPY_NONE ;static unsigned int queue_maxlen__read_mostly =IPQ_QMAX_DEFAULT ;static DEFINE_RWLOCK (queue_lock); -static int peer_pid; -static unsigned int copy_range; +static int peer_pid__read_mostly ; +static unsigned int copy_range__read_mostly ;static unsigned int queue_total;static unsigned int queue_dropped =0 ;static unsigned int queue_user_dropped =0 ; -static struct sock *ipqnl; +static struct sock *ipqnl__read_mostly ;static LIST_HEAD (queue_list);static DEFINE_MUTEX (ipqnl_mutex);
net/ipv6/netfilter/ip6_queue.c +4 -4
@@ -56,15 +56,15 @@ struct ipq_queue_entry {typedef int (*ipq_cmpfn )(struct ipq_queue_entry *,unsigned long ); -static unsigned char copy_mode =IPQ_COPY_NONE ; +static unsigned char copy_mode__read_mostly =IPQ_COPY_NONE ;static unsigned int queue_maxlen__read_mostly =IPQ_QMAX_DEFAULT ;static DEFINE_RWLOCK (queue_lock); -static int peer_pid; -static unsigned int copy_range; +static int peer_pid__read_mostly ; +static unsigned int copy_range__read_mostly ;static unsigned int queue_total;static unsigned int queue_dropped =0 ;static unsigned int queue_user_dropped =0 ; -static struct sock *ipqnl; +static struct sock *ipqnl__read_mostly ;static LIST_HEAD (queue_list);static DEFINE_MUTEX (ipqnl_mutex);
net/netfilter/nf_conntrack_core.c +5 -5
@@ -73,17 +73,17 @@ atomic_t nf_conntrack_count = ATOMIC_INIvoid (*nf_conntrack_destroyed)(struct nf_conn *conntrack) =NULL ;LIST_HEAD (nf_conntrack_expect_list); -struct nf_conntrack_protocol **nf_ct_protos[PF_MAX ]; -struct nf_conntrack_l3proto *nf_ct_l3protos[PF_MAX ]; +struct nf_conntrack_protocol **nf_ct_protos[PF_MAX ]__read_mostly ; +struct nf_conntrack_l3proto *nf_ct_l3protos[PF_MAX ]__read_mostly ;static LIST_HEAD (helpers);unsigned int nf_conntrack_htable_size__read_mostly =0 ;int nf_conntrack_max__read_mostly ; -struct list_head *nf_conntrack_hash; -static kmem_cache_t *nf_conntrack_expect_cachep; +struct list_head *nf_conntrack_hash__read_mostly ; +static kmem_cache_t *nf_conntrack_expect_cachep__read_mostly ;struct nf_conn nf_conntrack_untracked;unsigned int nf_ct_log_invalid__read_mostly ;static LIST_HEAD (unconfirmed); -static int nf_conntrack_vmalloc; +static int nf_conntrack_vmalloc__read_mostly ;static unsigned int nf_conntrack_next_id;static unsigned int nf_conntrack_expect_next_id;
PATCH 17/39 : ip_tables: fix module refcount leaks in compat error paths
In reply to Patrick McHardy[NETFILTER]: ip_tables: fix module refcount leaks in compat error paths
---
commit 6f432129cbce18fb8d5de208e49552dcc473b4be
tree 57d41f85a2b8a2334d481a7fcd8ff13c137561a0
parent 850a4981b57001c022d4b69a24d163404823ddb3
author Patrick McHardy <[email protected]> Wed, 20 Sep 2006 09:36:19 +0200 committer Patrick McHardy <[email protected]> Wed, 20 Sep 2006 09:36:19 +0200
net/ipv4/netfilter/ip_tables.c | 39 +++++++++++++++++++++++++++------------ 1 files changed, 27 insertions(+), 12 deletions(-)
net/ipv4/netfilter/ip_tables.c +27 -12
@@ -1529,7 +1529,7 @@ check_compat_entry_size_and_hooks(struct ret =IPT_MATCH_ITERATE (e, compat_check_calc_match, name, &e->ip, e->comefrom, &off, &j);if (ret !=0 ) - goto out; + goto cleanup_matches; t =ipt_get_target (e); target = try_then_request_module(xt_find_target(AF_INET,
@@ -1539,7 +1539,7 @@ check_compat_entry_size_and_hooks(structif (IS_ERR (target) || !target) {duprintf ("check_entry: `%s' not found\n" , t->u.user.name); ret = target ?PTR_ERR (target) : -ENOENT ; - goto out; + goto cleanup_matches; } t->u.kernel.target = target;
@@ -1566,14 +1566,17 @@ check_compat_entry_size_and_hooks(struct (*i)++;return 0 ; + out: +module_put (t->u.kernel.target->me); +cleanup_matches:IPT_MATCH_ITERATE (e, cleanup_match, &j);return ret; }static inline int compat_copy_match_from_user (struct ipt_entry_match *m,void **dstptr,compat_uint_t *size,const char *name, -const struct ipt_ip *ip,unsigned int hookmask) +const struct ipt_ip *ip,unsigned int hookmask,int *i) {struct ipt_entry_match *dm;struct ipt_match *match;
@@ -1590,16 +1593,22 @@ static inline int compat_copy_match_from name, hookmask, ip->proto, ip->invflags & IPT_INV_PROTO);if (ret) -return ret; + goto err;if (m->u.kernel.match->checkentry && !m->u.kernel.match->checkentry (name, ip, match, dm->data, hookmask)) {duprintf ("ip_tables: check failed for `%s'.\n" , m->u.kernel.match->name); -return -EINVAL ; + ret = -EINVAL ; + goto err; } + (*i)++;return 0 ; + +err: +module_put (m->u.kernel.match->me); +return ret; } static int compat_copy_entry_from_user(struct ipt_entry *e, void **dstptr,
@@ -1610,18 +1619,19 @@ static int compat_copy_entry_from_user(sstruct ipt_target *target;struct ipt_entry *de;unsigned int origsize; -int ret, h; +int ret, h, j; ret =0 ; origsize = *size; de = (struct ipt_entry *)*dstptr;memcpy (de, e,sizeof (struct ipt_entry )); + j =0 ; *dstptr +=sizeof (struct compat_ipt_entry ); ret =IPT_MATCH_ITERATE (e, compat_copy_match_from_user, dstptr, size, - name, &de->ip, de->comefrom); + name, &de->ip, de->comefrom, &j);if (ret) - goto out; + goto cleanup_matches; de->target_offset = e->target_offset - (origsize - *size); t =ipt_get_target (e); target = t->u.kernel.target;
@@ -1644,21 +1654,26 @@ static int compat_copy_entry_from_user(s name, e->comefrom, e->ip.proto, e->ip.invflags & IPT_INV_PROTO);if (ret) - goto out; + goto err; ret = -EINVAL ;if (t->u.kernel.target == &ipt_standard_target) {if (!standard_check (t, *size)) - goto out; + goto err; }else if (t->u.kernel.target->checkentry && !t->u.kernel.target->checkentry (name, de, target, t->data, de->comefrom)) {duprintf ("ip_tables: compat: check failed for `%s'.\n" , t->u.kernel.target->name); - goto out; + goto err; } ret =0 ; -out: +return ret; + +err: +module_put (t->u.kernel.target->me); +cleanup_matches: +IPT_MATCH_ITERATE (e, cleanup_match, &j);return ret; }
PATCH 18/39 : ip_tables: revision support for compat code
In reply to Patrick McHardy[NETFILTER]: ip_tables: revision support for compat code
---
commit 26b5f5e93fbd2a19bf304b01e7e2eece398ba3a2
tree 3d190beda0a0fc29b4741b9cbc663a097b7590fc
parent 6f432129cbce18fb8d5de208e49552dcc473b4be
author Patrick McHardy <[email protected]> Wed, 20 Sep 2006 09:36:28 +0200 committer Patrick McHardy <[email protected]> Wed, 20 Sep 2006 09:36:28 +0200
net/ipv4/netfilter/ip_tables.c | 5 +++-- 1 files changed, 3 insertions(+), 2 deletions(-)
net/ipv4/netfilter/ip_tables.c +3 -2
@@ -1994,6 +1994,8 @@ compat_get_entries(struct compat_ipt_getreturn ret; } +static int do_ipt_get_ctl (struct sock *,int ,void __user *,int *); +static int compat_do_ipt_get_ctl (struct sock *sk,int cmd,void __user *user,int *len) {
@@ -2007,8 +2009,7 @@ compat_do_ipt_get_ctl(struct sock *sk, i ret =compat_get_entries (user, len);break ;default : -duprintf ("compat_do_ipt_get_ctl: unknown request %i\n" , cmd); - ret = -EINVAL ; + ret =do_ipt_get_ctl (sk, cmd, user, len); }return ret; }
PATCH 19/39 : x_tables: simplify compat API
In reply to Patrick McHardy[NETFILTER]: x_tables: simplify compat API
Split the xt_compat_match/xt_compat_target into smaller type-safe functions performing just one operation. Handle all alignment and size-related conversions centrally in these function instead of requiring each module to implement a full-blown conversion function. Replace ->compat callback by ->compat_from_user and ->compat_to_user callbacks, responsible for converting just a single private structure.
---
commit 0e38bba8d1cb49b414eb4301ef89f128974ee059
tree b2d988dc961593e1247496531a04a89a53695c85
parent 26b5f5e93fbd2a19bf304b01e7e2eece398ba3a2
author Patrick McHardy <[email protected]> Wed, 20 Sep 2006 09:37:04 +0200 committer Patrick McHardy <[email protected]> Wed, 20 Sep 2006 09:37:04 +0200
include/linux/netfilter/x_tables.h | 29 +++-- net/ipv4/netfilter/ip_tables.c | 115 +++++----------------- net/netfilter/x_tables.c | 192 ++++++++++++++++++++---------------- 3 files changed, 151 insertions(+), 185 deletions(-)
include/linux/netfilter/x_tables.h +18 -11
@@ -138,12 +138,6 @@ #ifdef __KERNEL__#include <linux/netdevice.h> -#ifdef CONFIG_COMPAT -#define COMPAT_TO_USER 1 -#define COMPAT_FROM_USER -1 -#define COMPAT_CALC_SIZE 0 -#endif -struct xt_match {struct list_head list;
@@ -176,7 +170,8 @@ struct xt_matchvoid (*destroy)(const struct xt_match *match,void *matchinfo);/* Called when userspace align differs from kernel space one */ -int (*compat)(void *match,void **dstptr,int *size,int convert); +void (*compat_from_user)(void *dst,void *src); +int (*compat_to_user)(void __user *dst,void *src);/* Set this to THIS_MODULE if you are a module, otherwise NULL */ struct module *me;
@@ -186,6 +181,7 @@ struct xt_matchchar *table;unsigned int matchsize; +unsigned int compatsize;unsigned int hooks;unsigned short proto;
@@ -224,13 +220,15 @@ struct xt_targetvoid (*destroy)(const struct xt_target *target,void *targinfo);/* Called when userspace align differs from kernel space one */ -int (*compat)(void *target,void **dstptr,int *size,int convert); +void (*compat_from_user)(void *dst,void *src); +int (*compat_to_user)(void __user *dst,void *src);/* Set this to THIS_MODULE if you are a module, otherwise NULL */ struct module *me;char *table;unsigned int targetsize; +unsigned int compatsize;unsigned int hooks;unsigned short proto;
@@ -387,9 +385,18 @@ #define COMPAT_XT_ALIGN(s) (((s) + (__alextern void xt_compat_lock (int af);extern void xt_compat_unlock (int af); -extern int xt_compat_match (void *match,void **dstptr,int *size,int convert); -extern int xt_compat_target (void *target,void **dstptr,int *size, -int convert); + +extern int xt_compat_match_offset (struct xt_match *match); +extern void xt_compat_match_from_user (struct xt_entry_match *m, +void **dstptr,int *size); +extern int xt_compat_match_to_user (struct xt_entry_match *m, +void *__user *dstptr,int *size); + +extern int xt_compat_target_offset (struct xt_target *target); +extern void xt_compat_target_from_user (struct xt_entry_target *t, +void **dstptr,int *size); +extern int xt_compat_target_to_user (struct xt_entry_target *t, +void *__user *dstptr,int *size);#endif /* CONFIG_COMPAT */ #endif /* __KERNEL__ */
net/ipv4/netfilter/ip_tables.c +24 -91
183 lines not on this page · raw message
net/netfilter/x_tables.c +109 -83
212 lines not on this page · raw message
PATCH 20/39 : xt_mark: add compat conversion functions
In reply to Patrick McHardy[NETFILTER]: xt_mark: add compat conversion functions
---
commit fe51418f5b14027a01508b5e1285610ff001e2b0
tree 9594ed918996a180b28ab37c4999b8042c1ec26f
parent 0e38bba8d1cb49b414eb4301ef89f128974ee059
author Patrick McHardy <[email protected]> Wed, 20 Sep 2006 09:37:10 +0200 committer Patrick McHardy <[email protected]> Wed, 20 Sep 2006 09:37:10 +0200
net/netfilter/xt_mark.c | 36 ++++++++++++++++++++++++++++++++++++ 1 files changed, 36 insertions(+), 0 deletions(-)
net/netfilter/xt_mark.c +36 -0
@@ -50,6 +50,37 @@ checkentry(const char *tablename,return 1 ; } +#ifdef CONFIG_COMPAT +struct compat_xt_mark_info { +compat_ulong_t mark, mask; +u_int8_t invert; +u_int8_t __pad1; +u_int16_t __pad2; +}; + +static void compat_from_user (void *dst,void *src) +{ +struct compat_xt_mark_info *cm = src; +struct xt_mark_info m = { + .mark = cm->mark, + .mask = cm->mask, + .invert = cm->invert, + }; +memcpy (dst, &m,sizeof (m)); +} + +static int compat_to_user (void __user *dst,void *src) +{ +struct xt_mark_info *m = src; +struct compat_xt_mark_info cm = { + .mark = m->mark, + .mask = m->mask, + .invert = m->invert, + }; +return copy_to_user (dst, &cm,sizeof (cm)) ? -EFAULT :0 ; +} +#endif /* CONFIG_COMPAT */ +static struct xt_match xt_mark_match[] = { { .name ="mark" ,
@@ -57,6 +88,11 @@ static struct xt_match xt_mark_match[] = .checkentry = checkentry, .match = match, .matchsize =sizeof (struct xt_mark_info ), +#ifdef CONFIG_COMPAT + .compatsize =sizeof (struct compat_xt_mark_info ), + .compat_from_user = compat_from_user, + .compat_to_user = compat_to_user, +#endif .me = THIS_MODULE, }, {
PATCH 21/39 : xt_MARK: add compat conversion functions
In reply to Patrick McHardy[NETFILTER]: xt_MARK: add compat conversion functions
---
commit 6bd8301e88d5f11642e183546ce60747901de11c
tree 269043300eb5d79d725c4e0459e35e9962e9e9a4
parent fe51418f5b14027a01508b5e1285610ff001e2b0
author Patrick McHardy <[email protected]> Wed, 20 Sep 2006 09:37:14 +0200 committer Patrick McHardy <[email protected]> Wed, 20 Sep 2006 09:37:14 +0200
net/netfilter/xt_MARK.c | 34 ++++++++++++++++++++++++++++++++++ 1 files changed, 34 insertions(+), 0 deletions(-)
net/netfilter/xt_MARK.c +34 -0
@@ -108,6 +108,35 @@ checkentry_v1(const char *tablename,return 1 ; } +#ifdef CONFIG_COMPAT +struct compat_xt_mark_target_info_v1 { +compat_ulong_t mark; +u_int8_t mode; +u_int8_t __pad1; +u_int16_t __pad2; +}; + +static void compat_from_user_v1 (void *dst,void *src) +{ +struct compat_xt_mark_target_info_v1 *cm = src; +struct xt_mark_target_info_v1 m = { + .mark = cm->mark, + .mode = cm->mode, + }; +memcpy (dst, &m,sizeof (m)); +} + +static int compat_to_user_v1 (void __user *dst,void *src) +{ +struct xt_mark_target_info_v1 *m = src; +struct compat_xt_mark_target_info_v1 cm = { + .mark = m->mark, + .mode = m->mode, + }; +return copy_to_user (dst, &cm,sizeof (cm)) ? -EFAULT :0 ; +} +#endif /* CONFIG_COMPAT */ +static struct xt_target xt_mark_target[] = { { .name ="MARK" ,
@@ -126,6 +155,11 @@ static struct xt_target xt_mark_target[] .checkentry = checkentry_v1, .target = target_v1, .targetsize =sizeof (struct xt_mark_target_info_v1 ), +#ifdef CONFIG_COMPAT + .compatsize =sizeof (struct compat_xt_mark_target_info_v1 ), + .compat_from_user = compat_from_user_v1, + .compat_to_user = compat_to_user_v1, +#endif .table ="mangle" , .me = THIS_MODULE, },
PATCH 22/39 : xt_connmark: add compat conversion functions
In reply to Patrick McHardy[NETFILTER]: xt_connmark: add compat conversion functions
---
commit f0934e232d6e3db2091a14f3acccf2c53a0638dd
tree 954ed7f838b56351e8e80492296f051a3dc4dd13
parent 6bd8301e88d5f11642e183546ce60747901de11c
author Patrick McHardy <[email protected]> Wed, 20 Sep 2006 09:37:18 +0200 committer Patrick McHardy <[email protected]> Wed, 20 Sep 2006 09:37:18 +0200
net/netfilter/xt_connmark.c | 36 ++++++++++++++++++++++++++++++++++++ 1 files changed, 36 insertions(+), 0 deletions(-)
net/netfilter/xt_connmark.c +36 -0
@@ -81,6 +81,37 @@ #if defined(CONFIG_NF_CONNTRACK) || defi#endif } +#ifdef CONFIG_COMPAT +struct compat_xt_connmark_info { +compat_ulong_t mark, mask; +u_int8_t invert; +u_int8_t __pad1; +u_int16_t __pad2; +}; + +static void compat_from_user (void *dst,void *src) +{ +struct compat_xt_connmark_info *cm = src; +struct xt_connmark_info m = { + .mark = cm->mark, + .mask = cm->mask, + .invert = cm->invert, + }; +memcpy (dst, &m,sizeof (m)); +} + +static int compat_to_user (void __user *dst,void *src) +{ +struct xt_connmark_info *m = src; +struct compat_xt_connmark_info cm = { + .mark = m->mark, + .mask = m->mask, + .invert = m->invert, + }; +return copy_to_user (dst, &cm,sizeof (cm)) ? -EFAULT :0 ; +} +#endif /* CONFIG_COMPAT */ +static struct xt_match xt_connmark_match[] = { { .name ="connmark" ,
@@ -89,6 +120,11 @@ static struct xt_match xt_connmark_match .match = match, .destroy = destroy, .matchsize =sizeof (struct xt_connmark_info ), +#ifdef CONFIG_COMPAT + .compatsize =sizeof (struct compat_xt_connmark_info ), + .compat_from_user = compat_from_user, + .compat_to_user = compat_to_user, +#endif .me =THIS_MODULE }, {
PATCH 23/39 : xt_CONNMARK: add compat conversion functions
In reply to Patrick McHardy[NETFILTER]: xt_CONNMARK: add compat conversion functions
---
commit 7474394e41d53dc236b955bc3d3fd2fa11804ea4
tree ec46e54209d259ec89e82b5bfb256e06184caef5
parent f0934e232d6e3db2091a14f3acccf2c53a0638dd
author Patrick McHardy <[email protected]> Wed, 20 Sep 2006 09:37:25 +0200 committer Patrick McHardy <[email protected]> Wed, 20 Sep 2006 09:37:25 +0200
net/netfilter/xt_CONNMARK.c | 36 ++++++++++++++++++++++++++++++++++++ 1 files changed, 36 insertions(+), 0 deletions(-)
net/netfilter/xt_CONNMARK.c +36 -0
@@ -108,6 +108,37 @@ checkentry(const char *tablename,return 1 ; } +#ifdef CONFIG_COMPAT +struct compat_xt_connmark_target_info { +compat_ulong_t mark, mask; +u_int8_t mode; +u_int8_t __pad1; +u_int16_t __pad2; +}; + +static void compat_from_user (void *dst,void *src) +{ +struct compat_xt_connmark_target_info *cm = src; +struct xt_connmark_target_info m = { + .mark = cm->mark, + .mask = cm->mask, + .mode = cm->mode, + }; +memcpy (dst, &m,sizeof (m)); +} + +static int compat_to_user (void __user *dst,void *src) +{ +struct xt_connmark_target_info *m = src; +struct compat_xt_connmark_target_info cm = { + .mark = m->mark, + .mask = m->mask, + .mode = m->mode, + }; +return copy_to_user (dst, &cm,sizeof (cm)) ? -EFAULT :0 ; +} +#endif /* CONFIG_COMPAT */ +static struct xt_target xt_connmark_target[] = { { .name ="CONNMARK" ,
@@ -115,6 +146,11 @@ static struct xt_target xt_connmark_targ .checkentry = checkentry, .target = target, .targetsize =sizeof (struct xt_connmark_target_info ), +#ifdef CONFIG_COMPAT + .compatsize =sizeof (struct compat_xt_connmark_target_info ), + .compat_from_user = compat_from_user, + .compat_to_user = compat_to_user, +#endif .me =THIS_MODULE }, {
PATCH 24/39 : xt_limit: add compat conversion functions
In reply to Patrick McHardy[NETFILTER]: xt_limit: add compat conversion functions
---
commit 04bbf99594fdd99e6eb70ad78f532d3e1ca88750
tree 2edef62b3efcb300407739e4a6e8f5a984695b6b
parent 7474394e41d53dc236b955bc3d3fd2fa11804ea4
author Patrick McHardy <[email protected]> Wed, 20 Sep 2006 09:37:29 +0200 committer Patrick McHardy <[email protected]> Wed, 20 Sep 2006 09:37:29 +0200
net/netfilter/xt_limit.c | 49 ++++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 49 insertions(+), 0 deletions(-)
net/netfilter/xt_limit.c +49 -0
@@ -135,6 +135,50 @@ ipt_limit_checkentry(const char *tablenareturn 1 ; } +#ifdef CONFIG_COMPAT +struct compat_xt_rateinfo { +u_int32_t avg; +u_int32_t burst; + +compat_ulong_t prev; +u_int32_t credit; +u_int32_t credit_cap, cost; + +u_int32_t master; +}; + +/* To keep the full "prev" timestamp, the upper 32 bits are stored in the +* master pointer, which does not need to be preserved. */ +static void compat_from_user (void *dst,void *src) +{ +struct compat_xt_rateinfo *cm = src; +struct xt_rateinfo m = { + .avg = cm->avg, + .burst = cm->burst, + .prev = cm->prev | (unsigned long )cm->master <<32 , + .credit = cm->credit, + .credit_cap = cm->credit_cap, + .cost = cm->cost, + }; +memcpy (dst, &m,sizeof (m)); +} + +static int compat_to_user (void __user *dst,void *src) +{ +struct xt_rateinfo *m = src; +struct compat_xt_rateinfo cm = { + .avg = m->avg, + .burst = m->burst, + .prev = m->prev, + .credit = m->credit, + .credit_cap = m->credit_cap, + .cost = m->cost, + .master = m->prev >>32 , + }; +return copy_to_user (dst, &cm,sizeof (cm)) ? -EFAULT :0 ; +} +#endif /* CONFIG_COMPAT */ +static struct xt_match xt_limit_match[] = { { .name ="limit" ,
@@ -142,6 +186,11 @@ static struct xt_match xt_limit_match[] .checkentry = ipt_limit_checkentry, .match = ipt_limit_match, .matchsize =sizeof (struct xt_rateinfo ), +#ifdef CONFIG_COMPAT + .compatsize =sizeof (struct compat_xt_rateinfo ), + .compat_from_user = compat_from_user, + .compat_to_user = compat_to_user, +#endif .me = THIS_MODULE, }, {
PATCH 25/39 : ipt_hashlimit: add compat conversion functions
In reply to Patrick McHardy[NETFILTER]: ipt_hashlimit: add compat conversion functions
---
commit 6e24611afad533e7fe460dafcb14812a5591ce17
tree 5d5cb3167a069b4add7f434c59a6b36c9e5096ec
parent 04bbf99594fdd99e6eb70ad78f532d3e1ca88750
author Patrick McHardy <[email protected]> Wed, 20 Sep 2006 09:37:33 +0200 committer Patrick McHardy <[email protected]> Wed, 20 Sep 2006 09:37:33 +0200
net/ipv4/netfilter/ipt_hashlimit.c | 29 +++++++++++++++++++++++++++++ 1 files changed, 29 insertions(+), 0 deletions(-)
net/ipv4/netfilter/ipt_hashlimit.c +29 -0
@@ -535,10 +535,39 @@ hashlimit_destroy(const struct xt_matchhtable_put (r->hinfo); } +#ifdef CONFIG_COMPAT +struct compat_ipt_hashlimit_info { +char name[IFNAMSIZ ]; +struct hashlimit_cfg cfg; +compat_uptr_t hinfo; +compat_uptr_t master; +}; + +static void compat_from_user (void *dst,void *src) +{ +int off = offsetof(struct compat_ipt_hashlimit_info , hinfo); + +memcpy (dst, src, off); +memset (dst + off,0 ,sizeof (struct compat_ipt_hashlimit_info ) - off); +} + +static int compat_to_user (void __user *dst,void *src) +{ +int off = offsetof(struct compat_ipt_hashlimit_info , hinfo); + +return copy_to_user (dst, src, off) ? -EFAULT :0 ; +} +#endif +static struct ipt_match ipt_hashlimit = { .name ="hashlimit" , .match = hashlimit_match, .matchsize =sizeof (struct ipt_hashlimit_info ), +#ifdef CONFIG_COMPAT + .compatsize =sizeof (struct compat_ipt_hashlimit_info ), + .compat_from_user = compat_from_user, + .compat_to_user = compat_to_user, +#endif .checkentry = hashlimit_checkentry, .destroy = hashlimit_destroy, .me =THIS_MODULE
PATCH 26/39 : PPTP conntrack: fix whitespace errors
In reply to Patrick McHardy[NETFILTER]: PPTP conntrack: fix whitespace errors
---
commit fdb933d1bab11555cfd4e89823329deabec5a44b
tree c0f568e1aeb6f1f92265aad748942ebd313333a4
parent 6e24611afad533e7fe460dafcb14812a5591ce17
author Patrick McHardy <[email protected]> Wed, 20 Sep 2006 09:38:49 +0200 committer Patrick McHardy <[email protected]> Wed, 20 Sep 2006 09:38:49 +0200
include/linux/netfilter_ipv4/ip_conntrack_pptp.h | 26 +++--- net/ipv4/netfilter/ip_conntrack_helper_pptp.c | 76 +++++++++--------- net/ipv4/netfilter/ip_conntrack_proto_gre.c | 28 +++---- net/ipv4/netfilter/ip_nat_helper_pptp.c | 92 +++++++++++----------- net/ipv4/netfilter/ip_nat_proto_gre.c | 20 ++--- 5 files changed, 121 insertions(+), 121 deletions(-)
include/linux/netfilter_ipv4/ip_conntrack_pptp.h +13 -13
@@ -285,19 +285,19 @@ struct PptpSetLinkInfo { };union pptp_ctrl_union { -struct PptpStartSessionRequest sreq; -struct PptpStartSessionReply srep; -struct PptpStopSessionRequest streq; -struct PptpStopSessionReply strep; -struct PptpOutCallRequest ocreq; -struct PptpOutCallReply ocack; -struct PptpInCallRequest icreq; -struct PptpInCallReply icack; -struct PptpInCallConnected iccon; -struct PptpClearCallRequest clrreq; -struct PptpCallDisconnectNotify disc; -struct PptpWanErrorNotify wanerr; -struct PptpSetLinkInfo setlink; +struct PptpStartSessionRequest sreq; +struct PptpStartSessionReply srep; +struct PptpStopSessionRequest streq; +struct PptpStopSessionReply strep; +struct PptpOutCallRequest ocreq; +struct PptpOutCallReply ocack; +struct PptpInCallRequest icreq; +struct PptpInCallReply icack; +struct PptpInCallConnected iccon; +struct PptpClearCallRequest clrreq; +struct PptpCallDisconnectNotify disc; +struct PptpWanErrorNotify wanerr; +struct PptpSetLinkInfo setlink; }; extern int
net/ipv4/netfilter/ip_conntrack_helper_pptp.c +38 -38
214 lines not on this page · raw message
net/ipv4/netfilter/ip_conntrack_proto_gre.c +14 -14
@@ -1,15 +1,15 @@/* -* ip_conntrack_proto_gre.c - Version 3.0 +* ip_conntrack_proto_gre.c - Version 3.0 * * Connection tracking protocol helper module for GRE. * * GRE is a generic encapsulation protocol, which is generally not very * suited for NAT, as it has no protocol-specific part as port numbers. * -* It has an optional key field, which may help us distinguishing two +* It has an optional key field, which may help us distinguishing two * connections between the same two hosts. * -* GRE is defined in RFC 1701 and RFC 1702, as well as RFC 2784 +* GRE is defined in RFC 1701 and RFC 1702, as well as RFC 2784 * * PPTP is built on top of a modified version of GRE, and has a mandatory * field called "CallID", which serves us for the same purpose as the key
@@ -61,7 +61,7 @@ #else #define DEBUGP(x, args...)#define DUMP_TUPLE_GRE (x)#endif - +/* GRE KEYMAP HANDLING FUNCTIONS */ static LIST_HEAD (gre_keymap_list);
@@ -88,7 +88,7 @@ static __be16 gre_keymap_lookup(struct i } }read_unlock_bh (&ip_ct_gre_lock); - +DEBUGP ("lookup src key 0x%x up key for " , key);DUMP_TUPLE_GRE (t);
@@ -107,7 +107,7 @@ ip_ct_gre_keymap_add(struct ip_conntrackreturn -1 ; } -if (!reply) +if (!reply) exist_km = &ct->help.ct_pptp_info.keymap_orig;else exist_km = &ct->help.ct_pptp_info.keymap_reply;
@@ -118,7 +118,7 @@ ip_ct_gre_keymap_add(struct ip_conntrackif (gre_key_cmpfn (km, t) && km == *exist_km)return 0 ; } -DEBUGP ("trying to override keymap_%s for ct %p\n" , +DEBUGP ("trying to override keymap_%s for ct %p\n" , reply?"reply" :"orig" , ct);return -EEXIST ; }
@@ -152,7 +152,7 @@ void ip_ct_gre_keymap_destroy(struct ip_write_lock_bh (&ip_ct_gre_lock);if (ct->help.ct_pptp_info.keymap_orig) { -DEBUGP ("removing %p from list\n" , +DEBUGP ("removing %p from list\n" , ct->help.ct_pptp_info.keymap_orig);list_del (&ct->help.ct_pptp_info.keymap_orig->list);kfree (ct->help.ct_pptp_info.keymap_orig);
@@ -220,7 +220,7 @@ static int gre_pkt_to_tuple(const structstatic int gre_print_tuple (struct seq_file *s,const struct ip_conntrack_tuple *tuple) { -return seq_printf (s,"srckey=0x%x dstkey=0x%x " , +return seq_printf (s,"srckey=0x%x dstkey=0x%x " ,ntohs (tuple->src.u.gre.key),ntohs (tuple->dst.u.gre.key)); }
@@ -250,14 +250,14 @@ static int gre_packet(struct ip_conntrac }else ip_ct_refresh_acct (ct, conntrackinfo, skb, ct->proto.gre.timeout); - +return NF_ACCEPT ; }/* Called when a new connection for this protocol found. */ static int gre_new (struct ip_conntrack *ct,const struct sk_buff *skb) -{ +{DEBUGP (": " );DUMP_TUPLE_GRE (&ct->tuplehash[IP_CT_DIR_ORIGINAL ].tuple);
@@ -283,9 +283,9 @@ static void gre_destroy(struct ip_conntr }/* protocol helper struct */ -static struct ip_conntrack_protocol gre = { +static struct ip_conntrack_protocol gre = { .proto =IPPROTO_GRE , - .name ="gre" , + .name ="gre" , .pkt_to_tuple = gre_pkt_to_tuple, .invert_tuple = gre_invert_tuple, .print_tuple = gre_print_tuple,
@@ -323,7 +323,7 @@ void ip_ct_proto_gre_fini(void) }write_unlock_bh (&ip_ct_gre_lock); -ip_conntrack_protocol_unregister (&gre); +ip_conntrack_protocol_unregister (&gre); }EXPORT_SYMBOL (ip_ct_gre_keymap_add);
net/ipv4/netfilter/ip_nat_helper_pptp.c +46 -46
126 lines not on this page · raw message
net/ipv4/netfilter/ip_nat_proto_gre.c +10 -10
@@ -6,10 +6,10 @@* GRE is a generic encapsulation protocol, which is generally not very * suited for NAT, as it has no protocol-specific part as port numbers. * -* It has an optional key field, which may help us distinguishing two +* It has an optional key field, which may help us distinguishing two * connections between the same two hosts. * -* GRE is defined in RFC 1701 and RFC 1702, as well as RFC 2784 +* GRE is defined in RFC 1701 and RFC 1702, as well as RFC 2784 * * PPTP is built on top of a modified version of GRE, and has a mandatory * field called "CallID", which serves us for the same purpose as the key
@@ -60,7 +60,7 @@ gre_in_range(const struct ip_conntrack_t }/* generate unique tuple ... */ -static int +static int gre_unique_tuple(struct ip_conntrack_tuple *tuple, const struct ip_nat_range *range, enum ip_nat_manip_type maniptype,
@@ -84,7 +84,7 @@ gre_unique_tuple(struct ip_conntrack_tup range_size =ntohs (range->max.gre.key) - min +1 ; } -DEBUGP ("min = %u, range_size = %u\n" , min, range_size); +DEBUGP ("min = %u, range_size = %u\n" , min, range_size);for (i =0 ; i < range_size; i++, key++) { *keyptr =htons (min + key % range_size);
@@ -117,7 +117,7 @@ gre_manip_pkt(struct sk_buff **pskb, greh = (void *)(*pskb)->data + hdroff; pgreh = (struct gre_hdr_pptp *) greh; -/* we only have destination manip of a packet, since 'source key' +/* we only have destination manip of a packet, since 'source key' * is not present in the packet itself */ if (maniptype ==IP_NAT_MANIP_DST ) {/* key manipulation is always dest */
@@ -129,7 +129,7 @@ gre_manip_pkt(struct sk_buff **pskb, }if (greh->csum) {/* FIXME: Never tested this code... */ - *(gre_csum (greh)) = + *(gre_csum (greh)) = nf_proto_csum_update(*pskb, ~*(gre_key(greh)), tuple->dst.u.gre.key,
@@ -138,7 +138,7 @@ gre_manip_pkt(struct sk_buff **pskb, *(gre_key (greh)) = tuple->dst.u.gre.key;break ;case GRE_VERSION_PPTP : -DEBUGP ("call_id -> 0x%04x\n" , +DEBUGP ("call_id -> 0x%04x\n" ,ntohs (tuple->dst.u.gre.key)); pgreh->call_id = tuple->dst.u.gre.key;break ;
@@ -152,8 +152,8 @@ gre_manip_pkt(struct sk_buff **pskb, }/* nat helper struct */ -static struct ip_nat_protocol gre = { - .name ="GRE" , +static struct ip_nat_protocol gre = { + .name ="GRE" , .protonum =IPPROTO_GRE , .manip_pkt = gre_manip_pkt, .in_range = gre_in_range,
@@ -164,7 +164,7 @@ #if defined(CONFIG_IP_NF_CONNTRACK_NETLI .nfattr_to_range = ip_nat_port_nfattr_to_range,#endif }; - +int __init ip_nat_proto_gre_init (void ) {return ip_nat_protocol_register (&gre);
PATCH 27/39 : PPTP conntrack: get rid of unnecessary byte order conversions
In reply to Patrick McHardy[NETFILTER]: PPTP conntrack: get rid of unnecessary byte order conversions
The conntrack structure contains the call ID in host byte order for no reason, get rid of back and forth conversions.
---
commit a1495e7210e4ed162b958b06ffe11623bd0a2b0a
tree d072ce1843019e49bd9c41ba49d6e714f457746f
parent fdb933d1bab11555cfd4e89823329deabec5a44b
author Patrick McHardy <[email protected]> Wed, 20 Sep 2006 09:38:50 +0200 committer Patrick McHardy <[email protected]> Wed, 20 Sep 2006 09:38:50 +0200
include/linux/netfilter_ipv4/ip_conntrack_pptp.h | 8 ++-- .../linux/netfilter_ipv4/ip_conntrack_proto_gre.h | 22 ++++++------ include/linux/netfilter_ipv4/ip_nat_pptp.h | 4 +- net/ipv4/netfilter/ip_conntrack_helper_pptp.c | 22 +++++----- net/ipv4/netfilter/ip_nat_helper_pptp.c | 42 ++++++++++---------- net/ipv4/netfilter/ip_nat_proto_gre.c | 2 - 6 files changed, 50 insertions(+), 50 deletions(-)
include/linux/netfilter_ipv4/ip_conntrack_pptp.h +4 -4
@@ -31,8 +31,8 @@ struct ip_ct_pptp_master {/* everything below is going to be per-expectation in newnat, * since there could be more than one call within one session */ enum pptp_ctrlcall_state cstate;/* call state */ -u_int16_t pac_call_id;/* call id of PAC, host byte order */ -u_int16_t pns_call_id;/* call id of PNS, host byte order */ +__be16 pac_call_id;/* call id of PAC, host byte order */ +__be16 pns_call_id;/* call id of PNS, host byte order */ /* in pre-2.6.11 this used to be per-expect. Now it is per-conntrack * and therefore imposes a fixed limit on the number of maps */
@@ -42,8 +42,8 @@ struct ip_ct_pptp_master {/* conntrack_expect private member */ struct ip_ct_pptp_expect {enum pptp_ctrlcall_state cstate;/* call state */ -u_int16_t pac_call_id;/* call id of PAC */ -u_int16_t pns_call_id;/* call id of PNS */ +__be16 pac_call_id;/* call id of PAC */ +__be16 pns_call_id;/* call id of PNS */ };
include/linux/netfilter_ipv4/ip_conntrack_proto_gre.h +11 -11
@@ -49,18 +49,18 @@ #elif defined(__BIG_ENDIAN_BITFIELD)#else #error "Adjust your <asm/byteorder.h> defines"#endif -__u16 protocol; +__be16 protocol; };/* modified GRE header for PPTP */ struct gre_hdr_pptp { -__u8 flags;/* bitfield */ -__u8 version;/* should be GRE_VERSION_PPTP */ -__u16 protocol;/* should be GRE_PROTOCOL_PPTP */ -__u16 payload_len;/* size of ppp payload, not inc. gre header */ -__u16 call_id;/* peer's call_id for this session */ -__u32 seq;/* sequence number. Present if S==1 */ -__u32 ack;/* seq number of highest packet recieved by */ +__u8 flags;/* bitfield */ +__u8 version;/* should be GRE_VERSION_PPTP */ +__be16 protocol;/* should be GRE_PROTOCOL_PPTP */ +__be16 payload_len;/* size of ppp payload, not inc. gre header */ +__be16 call_id;/* peer's call_id for this session */ +__be32 seq;/* sequence number. Present if S==1 */ +__be32 ack;/* seq number of highest packet recieved by */ /* sender in this session */ };
@@ -92,13 +92,13 @@ void ip_ct_gre_keymap_destroy(struct ip_/* get pointer to gre key, if present */ -static inline u_int32_t *gre_key (struct gre_hdr *greh) +static inline __be32 *gre_key (struct gre_hdr *greh) {if (!greh->key)return NULL ;if (greh->csum || greh->routing) -return (u_int32_t *) (greh+sizeof (*greh)+4 ); -return (u_int32_t *) (greh+sizeof (*greh)); +return (__be32 *) (greh+sizeof (*greh)+4 ); +return (__be32 *) (greh+sizeof (*greh)); }/* get pointer ot gre csum, if present */
include/linux/netfilter_ipv4/ip_nat_pptp.h +2 -2
@@ -4,8 +4,8 @@ #define _NAT_PPTP_H/* conntrack private data */ struct ip_nat_pptp { -u_int16_t pns_call_id;/* NAT'ed PNS call id */ -u_int16_t pac_call_id;/* NAT'ed PAC call id */ +__be16 pns_call_id;/* NAT'ed PNS call id */ +__be16 pac_call_id;/* NAT'ed PAC call id */ };#endif /* _NAT_PPTP_H */
net/ipv4/netfilter/ip_conntrack_helper_pptp.c +11 -11
@@ -201,8 +201,8 @@ static void pptp_destroy_siblings(struct/* try original (pns->pac) tuple */ memcpy (&t, &ct->tuplehash[IP_CT_DIR_ORIGINAL ].tuple,sizeof (t)); t.dst.protonum =IPPROTO_GRE ; - t.src.u.gre.key =htons (ct->help.ct_pptp_info.pns_call_id); - t.dst.u.gre.key =htons (ct->help.ct_pptp_info.pac_call_id); + t.src.u.gre.key = ct->help.ct_pptp_info.pns_call_id; + t.dst.u.gre.key = ct->help.ct_pptp_info.pac_call_id;if (!destroy_sibling_or_exp (&t))DEBUGP ("failed to timeout original pns->pac ct/exp\n" );
@@ -210,8 +210,8 @@ static void pptp_destroy_siblings(struct/* try reply (pac->pns) tuple */ memcpy (&t, &ct->tuplehash[IP_CT_DIR_REPLY ].tuple,sizeof (t)); t.dst.protonum =IPPROTO_GRE ; - t.src.u.gre.key =htons (ct->help.ct_pptp_info.pac_call_id); - t.dst.u.gre.key =htons (ct->help.ct_pptp_info.pns_call_id); + t.src.u.gre.key = ct->help.ct_pptp_info.pac_call_id; + t.dst.u.gre.key = ct->help.ct_pptp_info.pns_call_id;if (!destroy_sibling_or_exp (&t))DEBUGP ("failed to timeout reply pac->pns ct/exp\n" );
@@ -419,9 +419,9 @@ pptp_inbound_pkt(struct sk_buff **pskb, cid = &pptpReq->ocack.callID; pcid = &pptpReq->ocack.peersCallID; - info->pac_call_id =ntohs (*cid); + info->pac_call_id = *cid; -if (htons (info->pns_call_id) != *pcid) { +if (info->pns_call_id != *pcid) {DEBUGP ("%s for unknown callid %u\n" , pptp_msg_name[msg],ntohs (*pcid));break ;
@@ -454,7 +454,7 @@ pptp_inbound_pkt(struct sk_buff **pskb, pcid = &pptpReq->icack.peersCallID;DEBUGP ("%s, PCID=%X\n" , pptp_msg_name[msg],ntohs (*pcid)); info->cstate =PPTP_CALL_IN_REQ ; - info->pac_call_id =ntohs (*pcid); + info->pac_call_id = *pcid;break ;case PPTP_IN_CALL_CONNECT :
@@ -478,7 +478,7 @@ pptp_inbound_pkt(struct sk_buff **pskb, pcid = &pptpReq->iccon.peersCallID; cid = &info->pac_call_id; -if (info->pns_call_id !=ntohs (*pcid)) { +if (info->pns_call_id != *pcid) {DEBUGP ("%s for unknown CallID %u\n" , pptp_msg_name[msg],ntohs (*pcid));break ;
@@ -595,7 +595,7 @@ pptp_outbound_pkt(struct sk_buff **pskb,/* track PNS call id */ cid = &pptpReq->ocreq.callID;DEBUGP ("%s, CID=%X\n" , pptp_msg_name[msg],ntohs (*cid)); - info->pns_call_id =ntohs (*cid); + info->pns_call_id = *cid;break ;case PPTP_IN_CALL_REPLY :if (reqlen <sizeof (_pptpReq.icack)) {
@@ -615,7 +615,7 @@ pptp_outbound_pkt(struct sk_buff **pskb,break ; } pcid = &pptpReq->icack.peersCallID; -if (info->pac_call_id !=ntohs (*pcid)) { +if (info->pac_call_id != *pcid) {DEBUGP ("%s for unknown call %u\n" , pptp_msg_name[msg],ntohs (*pcid));break ;
@@ -623,7 +623,7 @@ pptp_outbound_pkt(struct sk_buff **pskb,DEBUGP ("%s, CID=%X\n" , pptp_msg_name[msg],ntohs (*pcid));/* part two of the three-way handshake */ info->cstate =PPTP_CALL_IN_REP ; - info->pns_call_id =ntohs (pptpReq->icack.callID); + info->pns_call_id = pptpReq->icack.callID;break ;case PPTP_CALL_CLEAR_REQUEST :
net/ipv4/netfilter/ip_nat_helper_pptp.c +21 -21
95 lines not on this page · raw message
net/ipv4/netfilter/ip_nat_proto_gre.c +1 -1
@@ -67,7 +67,7 @@ gre_unique_tuple(struct ip_conntrack_tup const struct ip_conntrack *conntrack) {static u_int16_t key; -u_int16_t *keyptr; +__be16 *keyptr;unsigned int min, i, range_size;if (maniptype ==IP_NAT_MANIP_SRC )
PATCH 28/39 : PPTP conntrack: remove dead code
In reply to Patrick McHardy[NETFILTER]: PPTP conntrack: remove dead code
The call ID in reply packets is never changed, remove the code.
---
commit d263f9e4341b81008f743428b00674aeeb36f63c
tree 5576686063a9d88b2bcef4e80734bbb98b2da145
parent a1495e7210e4ed162b958b06ffe11623bd0a2b0a
author Patrick McHardy <[email protected]> Wed, 20 Sep 2006 09:38:52 +0200 committer Patrick McHardy <[email protected]> Wed, 20 Sep 2006 09:38:52 +0200
net/ipv4/netfilter/ip_nat_helper_pptp.c | 16 ++-------------- 1 files changed, 2 insertions(+), 14 deletions(-)
net/ipv4/netfilter/ip_nat_helper_pptp.c +2 -14
@@ -296,16 +296,15 @@ pptp_inbound_pkt(struct sk_buff **pskb, union pptp_ctrl_union *pptpReq) {struct ip_nat_pptp *nat_pptp_info = &ct->nat.help.nat_pptp_info; -u_int16_t msg, new_cid =0 ; +u_int16_t msg;__be16 new_pcid; -unsigned int pcid_off, cid_off =0 ; +unsigned int pcid_off; new_pcid = nat_pptp_info->pns_call_id;switch (msg =ntohs (ctlh->messageType)) {case PPTP_OUT_CALL_REPLY : pcid_off = offsetof(union pptp_ctrl_union, ocack.peersCallID); - cid_off = offsetof(union pptp_ctrl_union, ocack.callID);break ;case PPTP_IN_CALL_CONNECT : pcid_off = offsetof(union pptp_ctrl_union, iccon.peersCallID);
@@ -351,17 +350,6 @@ pptp_inbound_pkt(struct sk_buff **pskb, sizeof(new_pcid), (char *)&new_pcid, sizeof(new_pcid)) == 0)return NF_DROP ; - -if (new_cid) { -DEBUGP ("altering call id from 0x%04x to 0x%04x\n" , -ntohs (REQ_CID (pptpReq, cid_off)),ntohs (new_cid)); -if (ip_nat_mangle_tcp_packet (pskb, ct, ctinfo, - cid_off +sizeof (struct pptp_pkt_hdr ) + -sizeof (struct PptpControlHeader ), -sizeof (new_cid), (char *)&new_cid, -sizeof (new_cid)) ==0 ) -return NF_DROP ; - }return NF_ACCEPT ; }
PATCH 29/39 : PPTP conntrack: remove more dead code
In reply to Patrick McHardy[NETFILTER]: PPTP conntrack: remove more dead code
The calculated sequence numbers are not used for anything.
---
commit 079c04abd728cd903f44bb1db0a0e835cf23e8b5
tree 8fb3b96f07ddfec21ea94223c9319a42191109bc
parent d263f9e4341b81008f743428b00674aeeb36f63c
author Patrick McHardy <[email protected]> Wed, 20 Sep 2006 09:38:53 +0200 committer Patrick McHardy <[email protected]> Wed, 20 Sep 2006 09:38:53 +0200
net/ipv4/netfilter/ip_conntrack_helper_pptp.c | 17 ++--------------- 1 files changed, 2 insertions(+), 15 deletions(-)
net/ipv4/netfilter/ip_conntrack_helper_pptp.c +2 -15
@@ -220,7 +220,6 @@ static void pptp_destroy_siblings(struct/* expect GRE connections (PNS->PAC and PAC->PNS direction) */ static inline int exp_gre (struct ip_conntrack *master, -u_int32_t seq,__be16 callid,__be16 peer_callid) {
@@ -336,7 +335,6 @@ pptp_inbound_pkt(struct sk_buff **pskb,struct ip_ct_pptp_master *info = &ct->help.ct_pptp_info;u_int16_t msg;__be16 *cid, *pcid; -u_int32_t seq; ctlh =skb_header_pointer (*pskb, nexthdr_off,sizeof (_ctlh), &_ctlh);if (!ctlh) {
@@ -432,12 +430,7 @@ pptp_inbound_pkt(struct sk_buff **pskb, info->cstate =PPTP_CALL_OUT_CONF ; - seq =ntohl (tcph->seq) +sizeof (struct pptp_pkt_hdr ) - +sizeof (struct PptpControlHeader ) - + ((void *)pcid - (void *)pptpReq); - -if (exp_gre (ct, seq, *cid, *pcid) !=0 ) -printk ("ip_conntrack_pptp: error during exp_gre\n" ); +exp_gre (ct, *cid, *pcid);break ;case PPTP_IN_CALL_REQUEST :
@@ -488,13 +481,7 @@ pptp_inbound_pkt(struct sk_buff **pskb, info->cstate =PPTP_CALL_IN_CONF ;/* we expect a GRE connection from PAC to PNS */ - seq =ntohl (tcph->seq) +sizeof (struct pptp_pkt_hdr ) - +sizeof (struct PptpControlHeader ) - + ((void *)pcid - (void *)pptpReq); - -if (exp_gre (ct, seq, *cid, *pcid) !=0 ) -printk ("ip_conntrack_pptp: error during exp_gre\n" ); - +exp_gre (ct, *cid, *pcid);break ;case PPTP_CALL_DISCONNECT_NOTIFY :
PATCH 30/39 : PPTP conntrack: fix header definitions
In reply to Patrick McHardy[NETFILTER]: PPTP conntrack: fix header definitions
Fix a few header definitions to match RFC2637. Most importantly the PptpOutCallRequest header included an invalid padding field and a size check was disabled because of this.
---
commit d6d938738d5bea57063ead3a04405f0f729b99c3
tree 2dcab7d71b72f13f1940be0b8c7fa902dace45f6
parent 079c04abd728cd903f44bb1db0a0e835cf23e8b5
author Patrick McHardy <[email protected]> Wed, 20 Sep 2006 09:38:55 +0200 committer Patrick McHardy <[email protected]> Wed, 20 Sep 2006 09:38:55 +0200
include/linux/netfilter_ipv4/ip_conntrack_pptp.h | 9 +++++---- net/ipv4/netfilter/ip_conntrack_helper_pptp.c | 2 +- 2 files changed, 6 insertions(+), 5 deletions(-)
include/linux/netfilter_ipv4/ip_conntrack_pptp.h +5 -4
@@ -107,8 +107,7 @@ #define PPTP_BEARER_CAP_DIGITAL 0x2struct PptpStartSessionRequest {__be16 protocolVersion; -__u8 reserved1; -__u8 reserved2; +__u16 reserved1;__be32 framingCapability;__be32 bearerCapability;__be16 maxChannels;
@@ -143,6 +142,8 @@ #define PPTP_STOP_LOCAL_SHUTDOWN 3struct PptpStopSessionRequest {__u8 reason; +__u8 reserved1; +__u16 reserved2; };/* PptpStopSessionResultCode */
@@ -152,6 +153,7 @@ #define PPTP_STOP_GENERAL_ERROR 2struct PptpStopSessionReply {__u8 resultCode;__u8 generalErrorCode; +__u16 reserved1; };struct PptpEchoRequest {
@@ -188,9 +190,8 @@ struct PptpOutCallRequest {__be32 framingType;__be16 packetWindow;__be16 packetProcDelay; -__u16 reserved1;__be16 phoneNumberLength; -__u16 reserved2; +__u16 reserved1;__u8 phoneNumber[64 ];__u8 subAddress[64 ]; };
net/ipv4/netfilter/ip_conntrack_helper_pptp.c +1 -1
@@ -569,7 +569,7 @@ pptp_outbound_pkt(struct sk_buff **pskb,case PPTP_OUT_CALL_REQUEST :if (reqlen <sizeof (_pptpReq.ocreq)) {DEBUGP ("%s: short packet\n" , pptp_msg_name[msg]); -/* FIXME: break; */ +break ; }/* client initiating connection to server */
PATCH 31/39 : PPTP conntrack: remove unnecessary cid/pcid header pointers
In reply to Patrick McHardy[NETFILTER]: PPTP conntrack: remove unnecessary cid/pcid header pointers
Just the values are needed, not the memory locations.
---
commit 3a6a0d83459e3dc898f2b81eda4be07e5b3dc858
tree 6b232a4b768e2c48efd2d97cb756e924dd643c92
parent d6d938738d5bea57063ead3a04405f0f729b99c3
author Patrick McHardy <[email protected]> Wed, 20 Sep 2006 09:38:56 +0200 committer Patrick McHardy <[email protected]> Wed, 20 Sep 2006 09:38:56 +0200
net/ipv4/netfilter/ip_conntrack_helper_pptp.c | 56 +++++++++++++------------ 1 files changed, 28 insertions(+), 28 deletions(-)
net/ipv4/netfilter/ip_conntrack_helper_pptp.c +28 -28
@@ -334,7 +334,7 @@ pptp_inbound_pkt(struct sk_buff **pskb,union pptp_ctrl_union _pptpReq, *pptpReq;struct ip_ct_pptp_master *info = &ct->help.ct_pptp_info;u_int16_t msg; -__be16 *cid, *pcid; +__be16 cid, pcid; ctlh =skb_header_pointer (*pskb, nexthdr_off,sizeof (_ctlh), &_ctlh);if (!ctlh) {
@@ -414,23 +414,23 @@ pptp_inbound_pkt(struct sk_buff **pskb,break ; } - cid = &pptpReq->ocack.callID; - pcid = &pptpReq->ocack.peersCallID; + cid = pptpReq->ocack.callID; + pcid = pptpReq->ocack.peersCallID; - info->pac_call_id = *cid; + info->pac_call_id = cid; -if (info->pns_call_id != *pcid) { +if (info->pns_call_id != pcid) {DEBUGP ("%s for unknown callid %u\n" , - pptp_msg_name[msg],ntohs (*pcid)); + pptp_msg_name[msg],ntohs (pcid));break ; }DEBUGP ("%s, CID=%X, PCID=%X\n" , pptp_msg_name[msg], -ntohs (*cid),ntohs (*pcid)); +ntohs (cid),ntohs (pcid)); info->cstate =PPTP_CALL_OUT_CONF ; -exp_gre (ct, *cid, *pcid); +exp_gre (ct, cid, pcid);break ;case PPTP_IN_CALL_REQUEST :
@@ -444,10 +444,10 @@ pptp_inbound_pkt(struct sk_buff **pskb,DEBUGP ("%s but no session\n" , pptp_msg_name[msg]);break ; } - pcid = &pptpReq->icack.peersCallID; -DEBUGP ("%s, PCID=%X\n" , pptp_msg_name[msg],ntohs (*pcid)); + pcid = pptpReq->icack.peersCallID; +DEBUGP ("%s, PCID=%X\n" , pptp_msg_name[msg],ntohs (pcid)); info->cstate =PPTP_CALL_IN_REQ ; - info->pac_call_id = *pcid; + info->pac_call_id = pcid;break ;case PPTP_IN_CALL_CONNECT :
@@ -468,20 +468,20 @@ pptp_inbound_pkt(struct sk_buff **pskb,break ; } - pcid = &pptpReq->iccon.peersCallID; - cid = &info->pac_call_id; + pcid = pptpReq->iccon.peersCallID; + cid = info->pac_call_id; -if (info->pns_call_id != *pcid) { +if (info->pns_call_id != pcid) {DEBUGP ("%s for unknown CallID %u\n" , - pptp_msg_name[msg],ntohs (*pcid)); + pptp_msg_name[msg],ntohs (pcid));break ; } -DEBUGP ("%s, PCID=%X\n" , pptp_msg_name[msg],ntohs (*pcid)); +DEBUGP ("%s, PCID=%X\n" , pptp_msg_name[msg],ntohs (pcid)); info->cstate =PPTP_CALL_IN_CONF ;/* we expect a GRE connection from PAC to PNS */ -exp_gre (ct, *cid, *pcid); +exp_gre (ct, cid, pcid);break ;case PPTP_CALL_DISCONNECT_NOTIFY :
@@ -491,8 +491,8 @@ pptp_inbound_pkt(struct sk_buff **pskb, }/* server confirms disconnect */ - cid = &pptpReq->disc.callID; -DEBUGP ("%s, CID=%X\n" , pptp_msg_name[msg],ntohs (*cid)); + cid = pptpReq->disc.callID; +DEBUGP ("%s, CID=%X\n" , pptp_msg_name[msg],ntohs (cid)); info->cstate =PPTP_CALL_NONE ;/* untrack this call id, unexpect GRE packets */
@@ -534,7 +534,7 @@ pptp_outbound_pkt(struct sk_buff **pskb,union pptp_ctrl_union _pptpReq, *pptpReq;struct ip_ct_pptp_master *info = &ct->help.ct_pptp_info;u_int16_t msg; -__be16 *cid, *pcid; +__be16 cid, pcid; ctlh =skb_header_pointer (*pskb, nexthdr_off,sizeof (_ctlh), &_ctlh);if (!ctlh)
@@ -580,9 +580,9 @@ pptp_outbound_pkt(struct sk_buff **pskb, } info->cstate =PPTP_CALL_OUT_REQ ;/* track PNS call id */ - cid = &pptpReq->ocreq.callID; -DEBUGP ("%s, CID=%X\n" , pptp_msg_name[msg],ntohs (*cid)); - info->pns_call_id = *cid; + cid = pptpReq->ocreq.callID; +DEBUGP ("%s, CID=%X\n" , pptp_msg_name[msg],ntohs (cid)); + info->pns_call_id = cid;break ;case PPTP_IN_CALL_REPLY :if (reqlen <sizeof (_pptpReq.icack)) {
@@ -601,16 +601,16 @@ pptp_outbound_pkt(struct sk_buff **pskb, info->cstate =PPTP_CALL_NONE ;break ; } - pcid = &pptpReq->icack.peersCallID; -if (info->pac_call_id != *pcid) { + pcid = pptpReq->icack.peersCallID; +if (info->pac_call_id != pcid) {DEBUGP ("%s for unknown call %u\n" , - pptp_msg_name[msg],ntohs (*pcid)); + pptp_msg_name[msg],ntohs (pcid));break ; } -DEBUGP ("%s, CID=%X\n" , pptp_msg_name[msg],ntohs (*pcid)); +DEBUGP ("%s, CID=%X\n" , pptp_msg_name[msg],ntohs (pcid));/* part two of the three-way handshake */ info->cstate =PPTP_CALL_IN_REP ; - info->pns_call_id = pptpReq->icack.callID; + info->pns_call_id = pcid;break ;case PPTP_CALL_CLEAR_REQUEST :
PATCH 32/39 : PPTP conntrack: simplify expectation handling
In reply to Patrick McHardy[NETFILTER]: PPTP conntrack: simplify expectation handling
Remove duplicated expectation handling in the NAT helper and simplify the remains in the conntrack helper.
---
commit 5bf78ee628377db21c4a025e6c4e4955c581af1d
tree d309ce8083305691668ddc049f1c9d870689e512
parent 3a6a0d83459e3dc898f2b81eda4be07e5b3dc858
author Patrick McHardy <[email protected]> Wed, 20 Sep 2006 09:38:57 +0200 committer Patrick McHardy <[email protected]> Wed, 20 Sep 2006 09:38:57 +0200
include/linux/netfilter_ipv4/ip_conntrack_pptp.h | 2 net/ipv4/netfilter/ip_conntrack_helper_pptp.c | 92 +++++++--------------- net/ipv4/netfilter/ip_nat_helper_pptp.c | 58 +------------- 3 files changed, 35 insertions(+), 117 deletions(-)
include/linux/netfilter_ipv4/ip_conntrack_pptp.h +1 -1
@@ -315,7 +315,7 @@ (*ip_nat_pptp_hook_inbound)(struct sk_bustruct PptpControlHeader *ctlh, union pptp_ctrl_union *pptpReq); -extern int +extern void (*ip_nat_pptp_hook_exp_gre)(struct ip_conntrack_expect *exp_orig,struct ip_conntrack_expect *exp_reply);
net/ipv4/netfilter/ip_conntrack_helper_pptp.c +31 -61
131 lines not on this page · raw message
net/ipv4/netfilter/ip_nat_helper_pptp.c +3 -55
83 lines not on this page · raw message
PATCH 33/39 : PPTP conntrack: consolidate header size checks
In reply to Patrick McHardy[NETFILTER]: PPTP conntrack: consolidate header size checks
Also make sure not to pass undersized messages to the NAT helper.
---
commit d38269d3e44ca6ae4529ed6d0822dae300a8fb87
tree 12aa473b01b221f5e3eab3150084273c66029069
parent 5bf78ee628377db21c4a025e6c4e4955c581af1d
author Patrick McHardy <[email protected]> Wed, 20 Sep 2006 09:38:59 +0200 committer Patrick McHardy <[email protected]> Wed, 20 Sep 2006 09:38:59 +0200
net/ipv4/netfilter/ip_conntrack_helper_pptp.c | 65 ++++++++----------------- 1 files changed, 22 insertions(+), 43 deletions(-)
net/ipv4/netfilter/ip_conntrack_helper_pptp.c +22 -43
@@ -291,6 +291,22 @@ out_unexpect_orig: goto out_put_both; } +static const unsigned int pptp_msg_size[] = { + [PPTP_START_SESSION_REQUEST ] =sizeof (struct PptpStartSessionRequest ), + [PPTP_START_SESSION_REPLY ] =sizeof (struct PptpStartSessionReply ), + [PPTP_STOP_SESSION_REQUEST ] =sizeof (struct PptpStopSessionRequest ), + [PPTP_STOP_SESSION_REPLY ] =sizeof (struct PptpStopSessionReply ), + [PPTP_OUT_CALL_REQUEST ] =sizeof (struct PptpOutCallRequest ), + [PPTP_OUT_CALL_REPLY ] =sizeof (struct PptpOutCallReply ), + [PPTP_IN_CALL_REQUEST ] =sizeof (struct PptpInCallRequest ), + [PPTP_IN_CALL_REPLY ] =sizeof (struct PptpInCallReply ), + [PPTP_IN_CALL_CONNECT ] =sizeof (struct PptpInCallConnected ), + [PPTP_CALL_CLEAR_REQUEST ] =sizeof (struct PptpClearCallRequest ), + [PPTP_CALL_DISCONNECT_NOTIFY ] =sizeof (struct PptpCallDisconnectNotify ), + [PPTP_WAN_ERROR_NOTIFY ] =sizeof (struct PptpWanErrorNotify ), + [PPTP_SET_LINK_INFO ] =sizeof (struct PptpSetLinkInfo ), +}; + static inline int pptp_inbound_pkt(struct sk_buff **pskb, struct tcphdr *tcph,
@@ -326,13 +342,11 @@ pptp_inbound_pkt(struct sk_buff **pskb, msg =ntohs (ctlh->messageType);DEBUGP ("inbound control message %s\n" , pptp_msg_name[msg]); +if (msg >0 && msg <=PPTP_MSG_MAX && reqlen < pptp_msg_size[msg]) +return NF_ACCEPT ; +switch (msg) {case PPTP_START_SESSION_REPLY : -if (reqlen <sizeof (_pptpReq.srep)) { -DEBUGP ("%s: short packet\n" , pptp_msg_name[msg]); -break ; - } -/* server confirms new control session */ if (info->sstate <PPTP_SESSION_REQUESTED ) { DEBUGP("%s without START_SESS_REQUEST\n",
@@ -346,11 +360,6 @@ pptp_inbound_pkt(struct sk_buff **pskb,break ;case PPTP_STOP_SESSION_REPLY : -if (reqlen <sizeof (_pptpReq.strep)) { -DEBUGP ("%s: short packet\n" , pptp_msg_name[msg]); -break ; - } -/* server confirms end of control session */ if (info->sstate >PPTP_SESSION_STOPREQ ) { DEBUGP("%s without STOP_SESS_REQUEST\n",
@@ -364,11 +373,6 @@ pptp_inbound_pkt(struct sk_buff **pskb,break ;case PPTP_OUT_CALL_REPLY : -if (reqlen <sizeof (_pptpReq.ocack)) { -DEBUGP ("%s: short packet\n" , pptp_msg_name[msg]); -break ; - } -/* server accepted call, we now expect GRE frames */ if (info->sstate !=PPTP_SESSION_CONFIRMED ) {DEBUGP ("%s but no session\n" , pptp_msg_name[msg]);
@@ -404,11 +408,6 @@ pptp_inbound_pkt(struct sk_buff **pskb,break ;case PPTP_IN_CALL_REQUEST : -if (reqlen <sizeof (_pptpReq.icack)) { -DEBUGP ("%s: short packet\n" , pptp_msg_name[msg]); -break ; - } -/* server tells us about incoming call request */ if (info->sstate !=PPTP_SESSION_CONFIRMED ) {DEBUGP ("%s but no session\n" , pptp_msg_name[msg]);
@@ -421,11 +420,6 @@ pptp_inbound_pkt(struct sk_buff **pskb,break ;case PPTP_IN_CALL_CONNECT : -if (reqlen <sizeof (_pptpReq.iccon)) { -DEBUGP ("%s: short packet\n" , pptp_msg_name[msg]); -break ; - } -/* server tells us about incoming call established */ if (info->sstate !=PPTP_SESSION_CONFIRMED ) {DEBUGP ("%s but no session\n" , pptp_msg_name[msg]);
@@ -455,11 +449,6 @@ pptp_inbound_pkt(struct sk_buff **pskb,break ;case PPTP_CALL_DISCONNECT_NOTIFY : -if (reqlen <sizeof (_pptpReq.disc)) { -DEBUGP ("%s: short packet\n" , pptp_msg_name[msg]); -break ; - } -/* server confirms disconnect */ cid = pptpReq->disc.callID;DEBUGP ("%s, CID=%X\n" , pptp_msg_name[msg],ntohs (cid));
@@ -470,8 +459,6 @@ pptp_inbound_pkt(struct sk_buff **pskb,break ;case PPTP_WAN_ERROR_NOTIFY : -break ; -case PPTP_ECHO_REQUEST :case PPTP_ECHO_REPLY :/* I don't have to explain these ;) */
@@ -522,6 +509,9 @@ pptp_outbound_pkt(struct sk_buff **pskb, msg =ntohs (ctlh->messageType);DEBUGP ("outbound control message %s\n" , pptp_msg_name[msg]); +if (msg >0 && msg <=PPTP_MSG_MAX && reqlen < pptp_msg_size[msg]) +return NF_ACCEPT ; +switch (msg) {case PPTP_START_SESSION_REQUEST :/* client requests for new control session */
@@ -537,11 +527,6 @@ pptp_outbound_pkt(struct sk_buff **pskb,break ;case PPTP_OUT_CALL_REQUEST : -if (reqlen <sizeof (_pptpReq.ocreq)) { -DEBUGP ("%s: short packet\n" , pptp_msg_name[msg]); -break ; - } -/* client initiating connection to server */ if (info->sstate !=PPTP_SESSION_CONFIRMED ) { DEBUGP("%s but no session\n",
@@ -555,11 +540,6 @@ pptp_outbound_pkt(struct sk_buff **pskb, info->pns_call_id = cid;break ;case PPTP_IN_CALL_REPLY : -if (reqlen <sizeof (_pptpReq.icack)) { -DEBUGP ("%s: short packet\n" , pptp_msg_name[msg]); -break ; - } -/* client answers incoming call */ if (info->cstate !=PPTP_CALL_IN_REQ && info->cstate !=PPTP_CALL_IN_REP ) {
@@ -595,7 +575,6 @@ pptp_outbound_pkt(struct sk_buff **pskb, info->cstate =PPTP_CALL_CLEAR_REQ ;break ;case PPTP_SET_LINK_INFO : -break ;case PPTP_ECHO_REQUEST :case PPTP_ECHO_REPLY :/* I don't have to explain these ;) */
PATCH 34/39 : PPTP conntrack: consolidate header parsing
In reply to Patrick McHardy[NETFILTER]: PPTP conntrack: consolidate header parsing
---
commit d6e07cd63adbc8c291e8166b3e5d4779251ca8a3
tree 19a432f34d8660c061cdfa1b7ebcf000972a9cb0
parent d38269d3e44ca6ae4529ed6d0822dae300a8fb87
author Patrick McHardy <[email protected]> Wed, 20 Sep 2006 09:39:00 +0200 committer Patrick McHardy <[email protected]> Wed, 20 Sep 2006 09:39:00 +0200
net/ipv4/netfilter/ip_conntrack_helper_pptp.c | 119 ++++++++++--------------- 1 files changed, 47 insertions(+), 72 deletions(-)
net/ipv4/netfilter/ip_conntrack_helper_pptp.c +47 -72
@@ -291,60 +291,21 @@ out_unexpect_orig: goto out_put_both; } -static const unsigned int pptp_msg_size[] = { - [PPTP_START_SESSION_REQUEST ] =sizeof (struct PptpStartSessionRequest ), - [PPTP_START_SESSION_REPLY ] =sizeof (struct PptpStartSessionReply ), - [PPTP_STOP_SESSION_REQUEST ] =sizeof (struct PptpStopSessionRequest ), - [PPTP_STOP_SESSION_REPLY ] =sizeof (struct PptpStopSessionReply ), - [PPTP_OUT_CALL_REQUEST ] =sizeof (struct PptpOutCallRequest ), - [PPTP_OUT_CALL_REPLY ] =sizeof (struct PptpOutCallReply ), - [PPTP_IN_CALL_REQUEST ] =sizeof (struct PptpInCallRequest ), - [PPTP_IN_CALL_REPLY ] =sizeof (struct PptpInCallReply ), - [PPTP_IN_CALL_CONNECT ] =sizeof (struct PptpInCallConnected ), - [PPTP_CALL_CLEAR_REQUEST ] =sizeof (struct PptpClearCallRequest ), - [PPTP_CALL_DISCONNECT_NOTIFY ] =sizeof (struct PptpCallDisconnectNotify ), - [PPTP_WAN_ERROR_NOTIFY ] =sizeof (struct PptpWanErrorNotify ), - [PPTP_SET_LINK_INFO ] =sizeof (struct PptpSetLinkInfo ), -}; -static inline int pptp_inbound_pkt (struct sk_buff **pskb, -struct tcphdr *tcph, -unsigned int nexthdr_off, -unsigned int datalen, +struct PptpControlHeader *ctlh, +union pptp_ctrl_union *pptpReq, +unsigned int reqlen,struct ip_conntrack *ct,enum ip_conntrack_info ctinfo) { -struct PptpControlHeader _ctlh, *ctlh; -unsigned int reqlen; -union pptp_ctrl_union _pptpReq, *pptpReq;struct ip_ct_pptp_master *info = &ct->help.ct_pptp_info;u_int16_t msg;__be16 cid, pcid; - ctlh =skb_header_pointer (*pskb, nexthdr_off,sizeof (_ctlh), &_ctlh); -if (!ctlh) { -DEBUGP ("error during skb_header_pointer\n" ); -return NF_ACCEPT ; - } - nexthdr_off +=sizeof (_ctlh); - datalen -=sizeof (_ctlh); - - reqlen = datalen; -if (reqlen >sizeof (*pptpReq)) - reqlen =sizeof (*pptpReq); - pptpReq =skb_header_pointer (*pskb, nexthdr_off, reqlen, &_pptpReq); -if (!pptpReq) { -DEBUGP ("error during skb_header_pointer\n" ); -return NF_ACCEPT ; - } - msg =ntohs (ctlh->messageType);DEBUGP ("inbound control message %s\n" , pptp_msg_name[msg]); -if (msg >0 && msg <=PPTP_MSG_MAX && reqlen < pptp_msg_size[msg]) -return NF_ACCEPT ; -switch (msg) {case PPTP_START_SESSION_REPLY :/* server confirms new control session */
@@ -480,38 +441,19 @@ pptp_inbound_pkt(struct sk_buff **pskb,static inline int pptp_outbound_pkt (struct sk_buff **pskb, -struct tcphdr *tcph, -unsigned int nexthdr_off, -unsigned int datalen, +struct PptpControlHeader *ctlh, +union pptp_ctrl_union *pptpReq, +unsigned int reqlen,struct ip_conntrack *ct,enum ip_conntrack_info ctinfo) { -struct PptpControlHeader _ctlh, *ctlh; -unsigned int reqlen; -union pptp_ctrl_union _pptpReq, *pptpReq;struct ip_ct_pptp_master *info = &ct->help.ct_pptp_info;u_int16_t msg;__be16 cid, pcid; - ctlh =skb_header_pointer (*pskb, nexthdr_off,sizeof (_ctlh), &_ctlh); -if (!ctlh) -return NF_ACCEPT ; - nexthdr_off +=sizeof (_ctlh); - datalen -=sizeof (_ctlh); - - reqlen = datalen; -if (reqlen >sizeof (*pptpReq)) - reqlen =sizeof (*pptpReq); - pptpReq =skb_header_pointer (*pskb, nexthdr_off, reqlen, &_pptpReq); -if (!pptpReq) -return NF_ACCEPT ; - msg =ntohs (ctlh->messageType);DEBUGP ("outbound control message %s\n" , pptp_msg_name[msg]); -if (msg >0 && msg <=PPTP_MSG_MAX && reqlen < pptp_msg_size[msg]) -return NF_ACCEPT ; -switch (msg) {case PPTP_START_SESSION_REQUEST :/* client requests for new control session */
@@ -593,6 +535,21 @@ pptp_outbound_pkt(struct sk_buff **pskb,return NF_ACCEPT ; } +static const unsigned int pptp_msg_size[] = { + [PPTP_START_SESSION_REQUEST ] =sizeof (struct PptpStartSessionRequest ), + [PPTP_START_SESSION_REPLY ] =sizeof (struct PptpStartSessionReply ), + [PPTP_STOP_SESSION_REQUEST ] =sizeof (struct PptpStopSessionRequest ), + [PPTP_STOP_SESSION_REPLY ] =sizeof (struct PptpStopSessionReply ), + [PPTP_OUT_CALL_REQUEST ] =sizeof (struct PptpOutCallRequest ), + [PPTP_OUT_CALL_REPLY ] =sizeof (struct PptpOutCallReply ), + [PPTP_IN_CALL_REQUEST ] =sizeof (struct PptpInCallRequest ), + [PPTP_IN_CALL_REPLY ] =sizeof (struct PptpInCallReply ), + [PPTP_IN_CALL_CONNECT ] =sizeof (struct PptpInCallConnected ), + [PPTP_CALL_CLEAR_REQUEST ] =sizeof (struct PptpClearCallRequest ), + [PPTP_CALL_DISCONNECT_NOTIFY ] =sizeof (struct PptpCallDisconnectNotify ), + [PPTP_WAN_ERROR_NOTIFY ] =sizeof (struct PptpWanErrorNotify ), + [PPTP_SET_LINK_INFO ] =sizeof (struct PptpSetLinkInfo ), +};/* track caller id inside control connection, call expect_related */ static int
@@ -600,16 +557,17 @@ conntrack_pptp_help(struct sk_buff **psk struct ip_conntrack *ct, enum ip_conntrack_info ctinfo) { - struct pptp_pkt_hdr _pptph, *pptph; -struct tcphdr _tcph, *tcph; -u_int32_t tcplen = (*pskb)->len - (*pskb)->nh.iph->ihl *4 ; -u_int32_t datalen; int dir = CTINFO2DIR(ctinfo);struct ip_ct_pptp_master *info = &ct->help.ct_pptp_info; -unsigned int nexthdr_off; - +struct tcphdr _tcph, *tcph; +struct pptp_pkt_hdr _pptph, *pptph; +struct PptpControlHeader _ctlh, *ctlh; +union pptp_ctrl_union _pptpReq, *pptpReq; +unsigned int tcplen = (*pskb)->len - (*pskb)->nh.iph->ihl *4 ; +unsigned int datalen, reqlen, nexthdr_off;int oldsstate, oldcstate;int ret; +u_int16_t msg;/* don't do any tracking before tcp handshake complete */ if (ctinfo != IP_CT_ESTABLISHED
@@ -648,6 +606,23 @@ conntrack_pptp_help(struct sk_buff **pskreturn NF_ACCEPT ; } + ctlh =skb_header_pointer (*pskb, nexthdr_off,sizeof (_ctlh), &_ctlh); +if (!ctlh) +return NF_ACCEPT ; + nexthdr_off +=sizeof (_ctlh); + datalen -=sizeof (_ctlh); + + reqlen = datalen; + msg =ntohs (ctlh->messageType); +if (msg >0 && msg <=PPTP_MSG_MAX && reqlen < pptp_msg_size[msg]) +return NF_ACCEPT ; +if (reqlen >sizeof (*pptpReq)) + reqlen =sizeof (*pptpReq); + + pptpReq =skb_header_pointer (*pskb, nexthdr_off, reqlen, &_pptpReq); +if (!pptpReq) +return NF_ACCEPT ; + oldsstate = info->sstate; oldcstate = info->cstate;
@@ -657,11 +632,11 @@ conntrack_pptp_help(struct sk_buff **psk* established from PNS->PAC. However, RFC makes no guarantee */ if (dir ==IP_CT_DIR_ORIGINAL )/* client -> server (PNS -> PAC) */ - ret =pptp_outbound_pkt (pskb, tcph, nexthdr_off, datalen, ct, + ret =pptp_outbound_pkt (pskb, ctlh, pptpReq, reqlen, ct, ctinfo);else /* server -> client (PAC -> PNS) */ - ret =pptp_inbound_pkt (pskb, tcph, nexthdr_off, datalen, ct, + ret =pptp_inbound_pkt (pskb, ctlh, pptpReq, reqlen, ct, ctinfo);DEBUGP ("sstate: %d->%d, cstate: %d->%d\n" , oldsstate, info->sstate, oldcstate, info->cstate);
PATCH 35/39 : PPTP conntrack: clean up debugging cruft
In reply to Patrick McHardy[NETFILTER]: PPTP conntrack: clean up debugging cruft
Also make sure not to hand packets received in an invalid state to the NAT helper since it will mangle the packet with invalid data.
---
commit d76093560bcc1bfe36ef0075661169247fd7a4c1
tree 661cebc886d62079b5ecb798bfcff6d7afc83100
parent d6e07cd63adbc8c291e8166b3e5d4779251ca8a3
author Patrick McHardy <[email protected]> Wed, 20 Sep 2006 09:39:01 +0200 committer Patrick McHardy <[email protected]> Wed, 20 Sep 2006 09:39:01 +0200
net/ipv4/netfilter/ip_conntrack_helper_pptp.c | 128 ++++++++++--------------- 1 files changed, 51 insertions(+), 77 deletions(-)
net/ipv4/netfilter/ip_conntrack_helper_pptp.c +51 -77
@@ -301,7 +301,7 @@ pptp_inbound_pkt(struct sk_buff **pskb, {struct ip_ct_pptp_master *info = &ct->help.ct_pptp_info;u_int16_t msg; -__be16 cid, pcid; +__be16 cid =0 , pcid =0 ; msg =ntohs (ctlh->messageType);DEBUGP ("inbound control message %s\n" , pptp_msg_name[msg]);
@@ -309,11 +309,8 @@ pptp_inbound_pkt(struct sk_buff **pskb,switch (msg) {case PPTP_START_SESSION_REPLY :/* server confirms new control session */ -if (info->sstate <PPTP_SESSION_REQUESTED ) { -DEBUGP ("%s without START_SESS_REQUEST\n" , - pptp_msg_name[msg]); -break ; - } +if (info->sstate <PPTP_SESSION_REQUESTED ) + goto invalid;if (pptpReq->srep.resultCode ==PPTP_START_OK ) info->sstate =PPTP_SESSION_CONFIRMED ;else
@@ -322,11 +319,8 @@ pptp_inbound_pkt(struct sk_buff **pskb,case PPTP_STOP_SESSION_REPLY :/* server confirms end of control session */ -if (info->sstate >PPTP_SESSION_STOPREQ ) { -DEBUGP ("%s without STOP_SESS_REQUEST\n" , - pptp_msg_name[msg]); -break ; - } +if (info->sstate >PPTP_SESSION_STOPREQ ) + goto invalid;if (pptpReq->strep.resultCode ==PPTP_STOP_OK ) info->sstate =PPTP_SESSION_NONE ;else
@@ -335,15 +329,12 @@ pptp_inbound_pkt(struct sk_buff **pskb,case PPTP_OUT_CALL_REPLY :/* server accepted call, we now expect GRE frames */ -if (info->sstate !=PPTP_SESSION_CONFIRMED ) { -DEBUGP ("%s but no session\n" , pptp_msg_name[msg]); -break ; - } +if (info->sstate !=PPTP_SESSION_CONFIRMED ) + goto invalid;if (info->cstate !=PPTP_CALL_OUT_REQ && - info->cstate !=PPTP_CALL_OUT_CONF ) { -DEBUGP ("%s without OUTCALL_REQ\n" , pptp_msg_name[msg]); -break ; - } + info->cstate !=PPTP_CALL_OUT_CONF ) + goto invalid; +if (pptpReq->ocack.resultCode !=PPTP_OUTCALL_CONNECT ) { info->cstate =PPTP_CALL_NONE ;break ;
@@ -354,11 +345,8 @@ pptp_inbound_pkt(struct sk_buff **pskb, info->pac_call_id = cid; -if (info->pns_call_id != pcid) { -DEBUGP ("%s for unknown callid %u\n" , - pptp_msg_name[msg],ntohs (pcid)); -break ; - } +if (info->pns_call_id != pcid) + goto invalid;DEBUGP ("%s, CID=%X, PCID=%X\n" , pptp_msg_name[msg],ntohs (cid),ntohs (pcid));
@@ -370,10 +358,9 @@ pptp_inbound_pkt(struct sk_buff **pskb,case PPTP_IN_CALL_REQUEST :/* server tells us about incoming call request */ -if (info->sstate !=PPTP_SESSION_CONFIRMED ) { -DEBUGP ("%s but no session\n" , pptp_msg_name[msg]); -break ; - } +if (info->sstate !=PPTP_SESSION_CONFIRMED ) + goto invalid; + pcid = pptpReq->icack.peersCallID;DEBUGP ("%s, PCID=%X\n" , pptp_msg_name[msg],ntohs (pcid)); info->cstate =PPTP_CALL_IN_REQ ;
@@ -382,25 +369,17 @@ pptp_inbound_pkt(struct sk_buff **pskb,case PPTP_IN_CALL_CONNECT :/* server tells us about incoming call established */ -if (info->sstate !=PPTP_SESSION_CONFIRMED ) { -DEBUGP ("%s but no session\n" , pptp_msg_name[msg]); -break ; - } -if (info->cstate !=PPTP_CALL_IN_REP - && info->cstate !=PPTP_CALL_IN_CONF ) { -DEBUGP ("%s but never sent IN_CALL_REPLY\n" , - pptp_msg_name[msg]); -break ; - } +if (info->sstate !=PPTP_SESSION_CONFIRMED ) + goto invalid; +if (info->cstate !=PPTP_CALL_IN_REP && + info->cstate !=PPTP_CALL_IN_CONF ) + goto invalid; pcid = pptpReq->iccon.peersCallID; cid = info->pac_call_id; -if (info->pns_call_id != pcid) { -DEBUGP ("%s for unknown CallID %u\n" , - pptp_msg_name[msg],ntohs (pcid)); -break ; - } +if (info->pns_call_id != pcid) + goto invalid;DEBUGP ("%s, PCID=%X\n" , pptp_msg_name[msg],ntohs (pcid)); info->cstate =PPTP_CALL_IN_CONF ;
@@ -425,18 +404,21 @@ pptp_inbound_pkt(struct sk_buff **pskb,/* I don't have to explain these ;) */ break ;default : -DEBUGP ("invalid %s (TY=%d)\n" , (msg <=PPTP_MSG_MAX ) - ? pptp_msg_name[msg]:pptp_msg_name[0 ], msg); -break ; + goto invalid; } -if (ip_nat_pptp_hook_inbound)return ip_nat_pptp_hook_inbound (pskb, ct, ctinfo, ctlh, pptpReq); -return NF_ACCEPT ; +invalid: +DEBUGP ("invalid %s: type=%d cid=%u pcid=%u " +"cstate=%d sstate=%d pns_cid=%u pac_cid=%u\n" , + msg <=PPTP_MSG_MAX ? pptp_msg_name[msg] : pptp_msg_name[0 ], + msg,ntohs (cid),ntohs (pcid), info->cstate, info->sstate, +ntohs (info->pns_call_id),ntohs (info->pac_call_id)); +return NF_ACCEPT ; } static inline int
@@ -449,7 +431,7 @@ pptp_outbound_pkt(struct sk_buff **pskb, {struct ip_ct_pptp_master *info = &ct->help.ct_pptp_info;u_int16_t msg; -__be16 cid, pcid; +__be16 cid =0 , pcid =0 ; msg =ntohs (ctlh->messageType);DEBUGP ("outbound control message %s\n" , pptp_msg_name[msg]);
@@ -457,10 +439,8 @@ pptp_outbound_pkt(struct sk_buff **pskb,switch (msg) {case PPTP_START_SESSION_REQUEST :/* client requests for new control session */ -if (info->sstate !=PPTP_SESSION_NONE ) { -DEBUGP ("%s but we already have one" , - pptp_msg_name[msg]); - } +if (info->sstate !=PPTP_SESSION_NONE ) + goto invalid; info->sstate =PPTP_SESSION_REQUESTED ;break ;case PPTP_STOP_SESSION_REQUEST :
@@ -470,11 +450,8 @@ pptp_outbound_pkt(struct sk_buff **pskb,case PPTP_OUT_CALL_REQUEST :/* client initiating connection to server */ -if (info->sstate !=PPTP_SESSION_CONFIRMED ) { -DEBUGP ("%s but no session\n" , - pptp_msg_name[msg]); -break ; - } +if (info->sstate !=PPTP_SESSION_CONFIRMED ) + goto invalid; info->cstate =PPTP_CALL_OUT_REQ ;/* track PNS call id */ cid = pptpReq->ocreq.callID;
@@ -483,22 +460,17 @@ pptp_outbound_pkt(struct sk_buff **pskb,break ;case PPTP_IN_CALL_REPLY :/* client answers incoming call */ -if (info->cstate !=PPTP_CALL_IN_REQ - && info->cstate !=PPTP_CALL_IN_REP ) { -DEBUGP ("%s without incall_req\n" , - pptp_msg_name[msg]); -break ; - } +if (info->cstate !=PPTP_CALL_IN_REQ && + info->cstate !=PPTP_CALL_IN_REP ) + goto invalid; +if (pptpReq->icack.resultCode !=PPTP_INCALL_ACCEPT ) { info->cstate =PPTP_CALL_NONE ;break ; } pcid = pptpReq->icack.peersCallID; -if (info->pac_call_id != pcid) { -DEBUGP ("%s for unknown call %u\n" , - pptp_msg_name[msg],ntohs (pcid)); -break ; - } +if (info->pac_call_id != pcid) + goto invalid;DEBUGP ("%s, CID=%X\n" , pptp_msg_name[msg],ntohs (pcid));/* part two of the three-way handshake */ info->cstate =PPTP_CALL_IN_REP ;
@@ -507,10 +479,8 @@ pptp_outbound_pkt(struct sk_buff **pskb,case PPTP_CALL_CLEAR_REQUEST :/* client requests hangup of call */ -if (info->sstate !=PPTP_SESSION_CONFIRMED ) { -DEBUGP ("CLEAR_CALL but no session\n" ); -break ; - } +if (info->sstate !=PPTP_SESSION_CONFIRMED ) + goto invalid;/* FUTURE: iterate over all calls and check if * call ID is valid. We don't do this without newnat, * because we only know about last call */
@@ -522,16 +492,20 @@ pptp_outbound_pkt(struct sk_buff **pskb,/* I don't have to explain these ;) */ break ;default : -DEBUGP ("invalid %s (TY=%d)\n" , (msg <=PPTP_MSG_MAX )? - pptp_msg_name[msg]:pptp_msg_name[0 ], msg); -/* unknown: no need to create GRE masq table entry */ -break ; + goto invalid; }if (ip_nat_pptp_hook_outbound)return ip_nat_pptp_hook_outbound (pskb, ct, ctinfo, ctlh, pptpReq); +return NF_ACCEPT ; +invalid: +DEBUGP ("invalid %s: type=%d cid=%u pcid=%u " +"cstate=%d sstate=%d pns_cid=%u pac_cid=%u\n" , + msg <=PPTP_MSG_MAX ? pptp_msg_name[msg] : pptp_msg_name[0 ], + msg,ntohs (cid),ntohs (pcid), info->cstate, info->sstate, +ntohs (info->pns_call_id),ntohs (info->pac_call_id));return NF_ACCEPT ; }
PATCH 36/39 : PPTP conntrack: check call ID before changing state
In reply to Patrick McHardy[NETFILTER]: PPTP conntrack: check call ID before changing state
For rejected calls the state is set to PPTP_CALL_NONE even for non-matching call ids.
---
commit 0b844f188be93039e9b65b91c5e5ca50c8aca1c3
tree bdc9707f013a30c11f1484d1ce54e67980ee78d2
parent d76093560bcc1bfe36ef0075661169247fd7a4c1
author Patrick McHardy <[email protected]> Wed, 20 Sep 2006 09:39:03 +0200 committer Patrick McHardy <[email protected]> Wed, 20 Sep 2006 09:39:03 +0200
net/ipv4/netfilter/ip_conntrack_helper_pptp.c | 32 ++++++++++--------------- 1 files changed, 13 insertions(+), 19 deletions(-)
net/ipv4/netfilter/ip_conntrack_helper_pptp.c +13 -19
@@ -335,25 +335,19 @@ pptp_inbound_pkt(struct sk_buff **pskb, info->cstate != PPTP_CALL_OUT_CONF) goto invalid; -if (pptpReq->ocack.resultCode !=PPTP_OUTCALL_CONNECT ) { - info->cstate =PPTP_CALL_NONE ; -break ; - } - cid = pptpReq->ocack.callID; pcid = pptpReq->ocack.peersCallID; - - info->pac_call_id = cid; -if (info->pns_call_id != pcid) goto invalid; -DEBUGP ("%s, CID=%X, PCID=%X\n" , pptp_msg_name[msg],ntohs (cid),ntohs (pcid)); - info->cstate =PPTP_CALL_OUT_CONF ; - -exp_gre (ct, cid, pcid); +if (pptpReq->ocack.resultCode ==PPTP_OUTCALL_CONNECT ) { + info->cstate =PPTP_CALL_OUT_CONF ; + info->pac_call_id = cid; +exp_gre (ct, cid, pcid); + }else + info->cstate =PPTP_CALL_NONE ;break ;case PPTP_IN_CALL_REQUEST :
@@ -464,17 +458,17 @@ pptp_outbound_pkt(struct sk_buff **pskb, info->cstate != PPTP_CALL_IN_REP) goto invalid; -if (pptpReq->icack.resultCode !=PPTP_INCALL_ACCEPT ) { - info->cstate =PPTP_CALL_NONE ; -break ; - } pcid = pptpReq->icack.peersCallID;if (info->pac_call_id != pcid) goto invalid;DEBUGP ("%s, CID=%X\n" , pptp_msg_name[msg],ntohs (pcid)); -/* part two of the three-way handshake */ - info->cstate =PPTP_CALL_IN_REP ; - info->pns_call_id = pcid; + +if (pptpReq->icack.resultCode ==PPTP_INCALL_ACCEPT ) { +/* part two of the three-way handshake */ + info->cstate =PPTP_CALL_IN_REP ; + info->pns_call_id = pcid; + }else + info->cstate =PPTP_CALL_NONE ;break ;case PPTP_CALL_CLEAR_REQUEST :
PATCH 37/39 : PPTP conntrack: fix PPTP_IN_CALL message types
In reply to Patrick McHardy[NETFILTER]: PPTP conntrack: fix PPTP_IN_CALL message types
Fix incorrectly used message types and call IDs:
- PPTP_IN_CALL_REQUEST (PAC->PNS) contains a PptpInCallRequest (icreq) message and the PAC call ID
- PPTP_IN_CALL_REPLY (PNS->PAC) contains a PptpInCallReply (icack) message and the PNS call ID
---
commit ba51b5a0b572b684c58b32391335d4a3e4a67c0b
tree 1109a5e88bb01dfa43d43042c85ef2d1be1a52e5
parent 0b844f188be93039e9b65b91c5e5ca50c8aca1c3
author Patrick McHardy <[email protected]> Wed, 20 Sep 2006 09:39:04 +0200 committer Patrick McHardy <[email protected]> Wed, 20 Sep 2006 09:39:04 +0200
net/ipv4/netfilter/ip_conntrack_helper_pptp.c | 12 +++++++----- net/ipv4/netfilter/ip_nat_helper_pptp.c | 2 +- 2 files changed, 8 insertions(+), 6 deletions(-)
net/ipv4/netfilter/ip_conntrack_helper_pptp.c +7 -5
@@ -355,10 +355,10 @@ pptp_inbound_pkt(struct sk_buff **pskb,if (info->sstate !=PPTP_SESSION_CONFIRMED ) goto invalid; - pcid = pptpReq->icack.peersCallID; -DEBUGP ("%s, PCID=%X\n" , pptp_msg_name[msg],ntohs (pcid)); + cid = pptpReq->icreq.callID; +DEBUGP ("%s, CID=%X\n" , pptp_msg_name[msg],ntohs (cid)); info->cstate =PPTP_CALL_IN_REQ ; - info->pac_call_id = pcid; + info->pac_call_id = cid;break ;case PPTP_IN_CALL_CONNECT :
@@ -458,15 +458,17 @@ pptp_outbound_pkt(struct sk_buff **pskb, info->cstate != PPTP_CALL_IN_REP) goto invalid; + cid = pptpReq->icack.callID; pcid = pptpReq->icack.peersCallID;if (info->pac_call_id != pcid) goto invalid; -DEBUGP ("%s, CID=%X\n" , pptp_msg_name[msg],ntohs (pcid)); +DEBUGP ("%s, CID=%X PCID=%X\n" , pptp_msg_name[msg], +ntohs (cid),ntohs (pcid));if (pptpReq->icack.resultCode ==PPTP_INCALL_ACCEPT ) {/* part two of the three-way handshake */ info->cstate =PPTP_CALL_IN_REP ; - info->pns_call_id = pcid; + info->pns_call_id = cid; }else info->cstate =PPTP_CALL_NONE ;break ;
net/ipv4/netfilter/ip_nat_helper_pptp.c +1 -1
@@ -172,7 +172,7 @@ pptp_outbound_pkt(struct sk_buff **pskb, ct_pptp_info->pns_call_id = new_callid;break ;case PPTP_IN_CALL_REPLY : - cid_off = offsetof(union pptp_ctrl_union, icreq.callID); + cid_off = offsetof(union pptp_ctrl_union, icack.callID);break ;case PPTP_CALL_CLEAR_REQUEST : cid_off = offsetof(union pptp_ctrl_union, clrreq.callID);
PATCH 38/39 : PPTP conntrack: fix GRE keymap leak
In reply to Patrick McHardy[NETFILTER]: PPTP conntrack: fix GRE keymap leak
When destroying the GRE expectations without having seen the GRE connection the keymap entry is not freed, leading to a memory leak and, in case of a following call within the same session, failure during expectation setup.
---
commit 0646fc2fe542b914d8d379c26f773854d9628815
tree ef3d357c1b271ebd9ad570c0fed49a822716b7e3
parent ba51b5a0b572b684c58b32391335d4a3e4a67c0b
author Patrick McHardy <[email protected]> Wed, 20 Sep 2006 09:39:05 +0200 committer Patrick McHardy <[email protected]> Wed, 20 Sep 2006 09:39:05 +0200
net/ipv4/netfilter/ip_conntrack_helper_pptp.c | 1 + 1 files changed, 1 insertions(+), 0 deletions(-)
net/ipv4/netfilter/ip_conntrack_helper_pptp.c +1 -0
@@ -194,6 +194,7 @@ static void pptp_destroy_siblings(struct {struct ip_conntrack_tuple t; +ip_ct_gre_keymap_destroy (ct);/* Since ct->sibling_list has literally rusted away in 2.6.11, * we now need another way to find out about our sibling * contrack and expects... -HW */
PATCH 39/39 : PPTP conntrack: fix another GRE keymap leak
In reply to Patrick McHardy[NETFILTER]: PPTP conntrack: fix another GRE keymap leak
When the master PPTP connection times out while still having unfullfilled expectations (and a GRE keymap entry) associated with it, the keymap entry is not destroyed.
Add a destroy callback to struct ip_conntrack_helper and use it to destroy PPTP siblings when the master is destroyed.
---
commit cdd7e9b9a5974273373402873c86f8a349b630d2
tree 18a8f3ed4912aaa4ae2311ff65a87e9238a72712
parent 0646fc2fe542b914d8d379c26f773854d9628815
author Patrick McHardy <[email protected]> Wed, 20 Sep 2006 09:39:07 +0200 committer Patrick McHardy <[email protected]> Wed, 20 Sep 2006 09:39:07 +0200
include/linux/netfilter_ipv4/ip_conntrack_helper.h | 2 ++ net/ipv4/netfilter/ip_conntrack_core.c | 5 +++++ net/ipv4/netfilter/ip_conntrack_helper_pptp.c | 12 ++---------- 3 files changed, 9 insertions(+), 10 deletions(-)
include/linux/netfilter_ipv4/ip_conntrack_helper.h +2 -0
@@ -25,6 +25,8 @@ struct ip_conntrack_helperstruct ip_conntrack *ct, enum ip_conntrack_info conntrackinfo); +void (*destroy)(struct ip_conntrack *ct); +int (*to_nfattr)(struct sk_buff *skb,const struct ip_conntrack *ct); };
net/ipv4/netfilter/ip_conntrack_core.c +5 -0
@@ -307,6 +307,7 @@ destroy_conntrack(struct nf_conntrack *n {struct ip_conntrack *ct = (struct ip_conntrack *)nfct;struct ip_conntrack_protocol *proto; +struct ip_conntrack_helper *helper;DEBUGP ("destroy_conntrack(%p)\n" , ct);IP_NF_ASSERT (atomic_read (&nfct->use) ==0 );
@@ -315,6 +316,10 @@ destroy_conntrack(struct nf_conntrack *nip_conntrack_event (IPCT_DESTROY , ct);set_bit (IPS_DYING_BIT , &ct->status); + helper = ct->helper; +if (helper && helper->destroy) + helper->destroy (ct); +/* To make sure we don't get any weird locking issues here: * destroy_conntrack() MUST NOT be called with a write lock * to ip_conntrack_lock!!! -HW */
net/ipv4/netfilter/ip_conntrack_helper_pptp.c +2 -10
@@ -553,15 +553,6 @@ conntrack_pptp_help(struct sk_buff **psk nexthdr_off += tcph->doff *4 ; datalen = tcplen - tcph->doff *4 ; -if (tcph->fin || tcph->rst) { -DEBUGP ("RST/FIN received, timeouting GRE\n" ); -/* can't do this after real newnat */ - info->cstate =PPTP_CALL_NONE ; - -/* untrack this call id, unexpect GRE packets */ -pptp_destroy_siblings (ct); - } - pptph =skb_header_pointer (*pskb, nexthdr_off,sizeof (_pptph), &_pptph);if (!pptph) {DEBUGP ("no full PPTP header, can't track\n" );
@@ -640,7 +631,8 @@ static struct ip_conntrack_helper pptp = .protonum = 0xff } }, - .help = conntrack_pptp_help + .help = conntrack_pptp_help, + .destroy = pptp_destroy_siblings, };extern void ip_ct_proto_gre_fini (void );
Re: [NETFILTER 04/39]: ipt_TCPMSS: reformat
In reply to Patrick McHardyQuoted 5 lines · Patrick McHardy
[NETFILTER]:
ipt_TCPMSS: reformat- fix whitespace error
- break lines at 80 characters
- reformat some expressions to be more readable
Would something like this be a candidate for 2.4 as well? When reading the code I often compare 2.6 and 2.4 kernel code and the more equal they look the easier it is.
OTOH, it's really not a bugfix and definitely not important.
Cheers,
Roberto Nibali, ratz
Signature · 1 line
echo '[q]sa[ln0=aln256%Pln256/snlbx]sb3135071790101768542287578439snlbxq' | dc
Re: [NETFILTER 05/39]: ipt_TCPMSS: remove impossible condition
In reply to Patrick McHardyQuoted 3 lines
[NETFILTER]:
ipt_TCPMSS: remove impossible conditionEvery skb must have a
dst_entryat this point.
[...]
Quoted 9 lines
net/ipv4/netfilter/ipt_TCPMSS.c +0
-0@@ -73,13 +73,6 @@ ipt_tcpmss_target(struct sk_buff **pskb, }if (tcpmssinfo->mss ==IPT_TCPMSS_CLAMP_PMTU ) {
net/ipv4/netfilter/ipt_TCPMSS.c ipt_tcpmss_target(struct sk_buff **pskb, · line 78
Quoted 10 lines
net/ipv4/netfilter/ipt_TCPMSS.c +0
-7-if (!(*pskb)->dst) { -if (net_ratelimit ()) -printk (KERN_ERR "ipt_tcpmss_target: " -"no dst?! can't determine path-MTU\n" ); -return NF_DROP ;/* or IPT_CONTINUE ?? */ - } -if (dst_mtu ((*pskb)->dst) <=sizeof (struct iphdr ) +sizeof (struct tcphdr )) {if (net_ratelimit ())
Could be a candidate for 2.4 kernels as well. Although, it's not a strict bugfix, only a performance improvement, at best.
Regards,
Roberto Nibali, ratz
Signature · 1 line
echo '[q]sa[ln0=aln256%Pln256/snlbx]sb3135071790101768542287578439snlbxq' | dc
Re: [NETFILTER 11/39]: conntrack: fix race condition in early_drop
In reply to Patrick McHardyQuoted 90 lines · Patrick McHardy
[NETFILTER]: conntrack: fix race condition in
early_dropOn SMP environments the maximum number of conntracks can be overpassed under heavy stress situations due to an existing race condition.
CPU A CPU B
atomic_read()...
early_drop()...
...atomic_read()
allocate conntrack allocate conntrack
atomic_inc()atomic_inc()This patch moves the counter incrementation before the early drop stage.
Signed-off-by Pablo Neira Ayuso <[email protected]>Signed-off-by Patrick McHardy <[email protected]>---
commit56a0ea23e536624ad1ea186289bb5d686ca19425
treec56f7cbb8b47d1e153440062f34f26604c250aa8
parent2d7b5900c6ec411811c3ec01ea7caf75dc694f3e
author Pablo Neira Ayuso <[email protected]> Wed, 20 Sep 2006 09:28:41 +0200 committer Patrick McHardy <[email protected]> Wed, 20 Sep 2006 09:28:41 +0200net/ipv4/netfilter/ip_conntrack_core.c | 9 ++++++--- net/netfilter/nf_conntrack_core.c | 10 ++++++++-- 2 files changed, 14 insertions(+), 5 deletions(-)net/ipv4/netfilter/ip_conntrack_core.c +6
-3@@ -622,11 +622,15 @@ struct ip_conntrack *ip_conntrack_alloc( ip_conntrack_hash_rnd_initted =1 ; } +/* We don't want any race condition at early drop stage */ +atomic_inc (&ip_conntrack_count); +if (ip_conntrack_max - &&atomic_read (&ip_conntrack_count) >= ip_conntrack_max) { + &&atomic_read (&ip_conntrack_count) > ip_conntrack_max) {unsigned int hash =hash_conntrack (orig);/* Try dropping from this hash chain. */ if (!early_drop (&ip_conntrack_hash[hash])) { +atomic_dec (&ip_conntrack_count);if (net_ratelimit ())printk (KERN_WARNING "ip_conntrack: table full, dropping"@@ -638,6 +642,7 @@ struct ip_conntrack *ip_conntrack_alloc( conntrack =kmem_cache_alloc (ip_conntrack_cachep,GFP_ATOMIC );if (!conntrack) {DEBUGP ("Can't allocate conntrack.\n" ); +atomic_dec (&ip_conntrack_count);return ERR_PTR (-ENOMEM ); }@@ -651,8 +656,6 @@ struct ip_conntrack *ip_conntrack_alloc( conntrack->timeout.data = (unsigned long )conntrack; conntrack->timeout.function = death_by_timeout; -atomic_inc (&ip_conntrack_count); -return conntrack; }net/netfilter/nf_conntrack_core.c +5
-1@@ -848,11 +848,15 @@ __nf_conntrack_alloc(const struct nf_con nf_conntrack_hash_rnd_initted =1 ; } +/* We don't want any race condition at early drop stage */ +atomic_inc (&nf_conntrack_count); +if (nf_conntrack_max - &&atomic_read (&nf_conntrack_count) >= nf_conntrack_max) { + &&atomic_read (&nf_conntrack_count) > nf_conntrack_max) {unsigned int hash =hash_conntrack (orig);/* Try dropping from this hash chain. */ if (!early_drop (&nf_conntrack_hash[hash])) { +atomic_dec (&nf_conntrack_count);if (net_ratelimit ())printk (KERN_WARNING "nf_conntrack: table full, dropping"@@ -903,10 +907,12 @@ __nf_conntrack_alloc(const struct nf_coninit_timer (&conntrack->timeout); conntrack->timeout.data = (unsigned long )conntrack;
net/netfilter/nf_conntrack_core.c __nf_conntrack_alloc(const struct nf_con · line 917
Quoted 10 lines
net/netfilter/nf_conntrack_core.c +3
-1conntrack->timeout.function = death_by_timeout; +read_unlock_bh (&nf_ct_cache_lock); -atomic_inc (&nf_conntrack_count); +return conntrack; out:read_unlock_bh (&nf_ct_cache_lock); +atomic_dec (&nf_conntrack_count);return conntrack; }
Candidate for 2.4?
Best regards,
Roberto Nibali, ratz
Signature · 1 line
echo '[q]sa[ln0=aln256%Pln256/snlbx]sb3135071790101768542287578439snlbxq' | dc
Re: [NETFILTER 05/39]: ipt_TCPMSS: remove impossible condition
In reply to Roberto NibaliQuoted 2 lines · Roberto Nibali
Could be a candidate for 2.4 kernels as well. Although, it's not a strict bugfix, only a performance improvement, at best.
No, both are definitely not 2.4 candidates. I only pass on bugfixes for bugs that were also reported by 2.4 users and security fixes.
Re: [NETFILTER 11/39]: conntrack: fix race condition in early_drop
In reply to Roberto NibaliQuoted 9 lines · Roberto Nibali
Quoted 5 lines · Patrick McHardy
[NETFILTER]: conntrack: fix race condition in
early_dropOn SMP environments the maximum number of conntracks can be overpassed under heavy stress situations due to an existing race condition.
Candidate for 2.4?
Not really. We can exceed the limit by a few entries, but its still bounded. The same can happen anyway because only entries in the hash are counted.
Re: [NETFILTER 11/39]: conntrack: fix race condition in early_drop
Quoted 5 lines · Patrick McHardy
Quoted 4 lines · Roberto Nibali
Quoted 2 lines · Patrick McHardy
[NETFILTER]: conntrack: fix race condition in
early_drop
Quoted 8 lines
Quoted 4 lines
Quoted 3 lines
On SMP environments the maximum number of conntracks can be overpassed under heavy stress situations due to an existing race condition.
Candidate for 2.4?
Not really. We can exceed the limit by a few entries, but its still bounded. The same can happen anyway because only entries in the hash are counted.
Ok, thanks for your time. We have a similar situation in 2.4 LVS code (unpatched for years now) and I was just curious if defects like this get addressed in 2.4 kernels nowadays. I reckon so long as noone complains, we don't do anything; at least that's how I understood you.
Regards,
Roberto Nibali, ratz
Signature · 1 line
echo '[q]sa[ln0=aln256%Pln256/snlbx]sb3135071790101768542287578439snlbxq' | dc
Re: [NETFILTER 11/39]: conntrack: fix race condition in early_drop
Quoted 11 lines · Roberto Nibali
Quoted 3 lines · Patrick McHardy
Not really. We can exceed the limit by a few entries, but its still bounded. The same can happen anyway because only entries in the hash are counted.
Ok, thanks for your time. We have a similar situation in 2.4 LVS code (unpatched for years now) and I was just curious if defects like this get addressed in 2.4 kernels nowadays. I reckon so long as noone complains, we don't do anything; at least that's how I understood you.
Yes, I don't want to break anything in 2.4 by "fixing" problems noone is experiencing.
Re: [NETFILTER 27/39]: PPTP conntrack: get rid of unnecessary byte order conversions
In reply to Patrick McHardyQuoted 4 lines
include/linux/netfilter_ipv4/ip_conntrack_pptp.h +0
-0@@ -31,8 +31,8 @@ struct ip_ct_pptp_master {
...
include/linux/netfilter_ipv4/ip_conntrack_pptp.h struct ip_ct_pptp_master { · line 35
Quoted 4 lines
include/linux/netfilter_ipv4/ip_conntrack_pptp.h +2
-2-u_int16_t pac_call_id;/* call id of PAC, host byte order */ -u_int16_t pns_call_id;/* call id of PNS, host byte order */ +__be16 pac_call_id;/* call id of PAC, host byte order */ +__be16 pns_call_id;/* call id of PNS, host byte order */
Uhm, how about updating the comments here? :-)
/Jones
Re: [NETFILTER 27/39]: PPTP conntrack: get rid of unnecessary byte order conversions
Quoted 6 lines · Jones Desougi
Quoted 3 lines
include/linux/netfilter_ipv4/ip_conntrack_pptp.h +0
-0@@ -31,8 +31,8 @@ struct ip_ct_pptp_master {...
Quoted 7 lines
include/linux/netfilter_ipv4/ip_conntrack_pptp.h struct ip_ct_pptp_master { · line 35
Quoted 4 lines
include/linux/netfilter_ipv4/ip_conntrack_pptp.h +2
-2-u_int16_t pac_call_id;/* call id of PAC, host byte order */ -u_int16_t pns_call_id;/* call id of PNS, host byte order */ +__be16 pac_call_id;/* call id of PAC, host byte order */ +__be16 pns_call_id;/* call id of PNS, host byte order */ Uhm, how about updating the comments here? :-)
Yes, I missed those. I'll fix them in the next batch, I'm not completely done with PPTP yet.
Re: [NETFILTER 02/39]: kill listhelp.h
In reply to Patrick McHardyQuoted 17 lines · Patrick McHardy
[NETFILTER]: kill
listhelp.hinclude/linux/netfilter/x_tables.h | 4 - net/bridge/netfilter/ebtables.c | 76 ++++++---- net/ipv4/netfilter/arp_tables.c | 2 net/ipv4/netfilter/ip_conntrack_core.c | 189 ++++++++++++-------------- net/ipv4/netfilter/ip_conntrack_proto_gre.c | 24 ++- net/ipv4/netfilter/ip_conntrack_standalone.c | 1 net/ipv4/netfilter/ip_nat_core.c | 4 - net/ipv4/netfilter/ip_nat_helper.c | 4 - net/ipv4/netfilter/ip_nat_rule.c | 4 - net/ipv4/netfilter/ip_nat_standalone.c | 4 - net/ipv6/netfilter/ip6_tables.c | 3 net/netfilter/nf_conntrack_core.c | 185 ++++++++++++------------- net/netfilter/nf_conntrack_standalone.c | 1 net/netfilter/x_tables.c | 17 +- 14 files changed, 237 insertions(+), 281 deletions(-)
That damn file is resistant, the actual removal must have been lost during rebasing the patches to the current tree :)
Please take this corrected patch instead.
[NETFILTER]: kill listhelp.h
Kill listhelp.h and use the list.h functions instead.
---
commit 5305bddbd3d13b43525d91a438396744e5d90a70
tree 4a8522f453feff79f60c11e7e461a291a5169594
parent 18ad5392d9e06e66a42600ca7b252d46cfb4f443
author Patrick McHardy <[email protected]> Wed, 20 Sep 2006 18:55:06 +0200 committer Patrick McHardy <[email protected]> Wed, 20 Sep 2006 18:55:06 +0200
include/linux/netfilter/x_tables.h | 4 - include/linux/netfilter_ipv4/listhelp.h | 123 ----------------- net/bridge/netfilter/ebtables.c | 76 ++++++---- net/ipv4/netfilter/arp_tables.c | 2 net/ipv4/netfilter/ip_conntrack_core.c | 189 ++++++++++++-------------- net/ipv4/netfilter/ip_conntrack_proto_gre.c | 24 ++- net/ipv4/netfilter/ip_conntrack_standalone.c | 1 net/ipv4/netfilter/ip_nat_core.c | 4 - net/ipv4/netfilter/ip_nat_helper.c | 4 - net/ipv4/netfilter/ip_nat_rule.c | 4 - net/ipv4/netfilter/ip_nat_standalone.c | 4 - net/ipv6/netfilter/ip6_tables.c | 3 net/netfilter/nf_conntrack_core.c | 185 ++++++++++++------------- net/netfilter/nf_conntrack_standalone.c | 1 net/netfilter/x_tables.c | 17 +- 15 files changed, 237 insertions(+), 404 deletions(-)
include/linux/netfilter/x_tables.h +0 -4
@@ -138,10 +138,6 @@ #ifdef __KERNEL__#include <linux/netdevice.h> -#define ASSERT_READ_LOCK (x) -#define ASSERT_WRITE_LOCK (x) -#include <linux/netfilter_ipv4/listhelp.h> -#ifdef CONFIG_COMPAT #define COMPAT_TO_USER 1#define COMPAT_FROM_USER -1
include/linux/netfilter_ipv4/listhelp.h deleted +0 -123
123 lines not on this page · raw message
net/bridge/netfilter/ebtables.c +45 -31
182 lines not on this page · raw message
net/ipv4/netfilter/arp_tables.c +0 -2
@@ -56,8 +56,6 @@ #else#define ARP_NF_ASSERT (x)#endif -#include <linux/netfilter_ipv4/listhelp.h> -static inline int arp_devaddr_compare (const struct arpt_devaddr_info *ap,char *hdr_addr,int len) {
net/ipv4/netfilter/ip_conntrack_core.c +85 -104
317 lines not on this page · raw message
net/ipv4/netfilter/ip_conntrack_proto_gre.c +11 -13
@@ -37,7 +37,6 @@ static DEFINE_RWLOCK(ip_ct_gre_lock);#define ASSERT_READ_LOCK (x)#define ASSERT_WRITE_LOCK (x) -#include <linux/netfilter_ipv4/listhelp.h> #include <linux/netfilter_ipv4/ip_conntrack_protocol.h> #include <linux/netfilter_ipv4/ip_conntrack_helper.h> #include <linux/netfilter_ipv4/ip_conntrack_core.h>
@@ -82,10 +81,12 @@ static __be16 gre_keymap_lookup(struct i__be16 key =0 ;read_lock_bh (&ip_ct_gre_lock); - km =LIST_FIND (&gre_keymap_list, gre_key_cmpfn, - struct ip_ct_gre_keymap *, t); -if (km) - key = km->tuple.src.u.gre.key; +list_for_each_entry (km, &gre_keymap_list, list) { +if (gre_key_cmpfn (km, t)) { + key = km->tuple.src.u.gre.key; +break ; + } + }read_unlock_bh (&ip_ct_gre_lock);DEBUGP ("lookup src key 0x%x up key for " , key);
@@ -99,7 +100,7 @@ int ip_ct_gre_keymap_add(struct ip_conntrack *ct, struct ip_conntrack_tuple *t, int reply) { - struct ip_ct_gre_keymap **exist_km, *km, *old; + struct ip_ct_gre_keymap **exist_km, *km;if (!ct->helper ||strcmp (ct->helper->name,"pptp" )) {DEBUGP ("refusing to add GRE keymap to non-pptp session\n" );
@@ -113,13 +114,10 @@ ip_ct_gre_keymap_add(struct ip_conntrackif (*exist_km) {/* check whether it's a retransmission */ - old =LIST_FIND (&gre_keymap_list, gre_key_cmpfn, - struct ip_ct_gre_keymap *, t); -if (old == *exist_km) { -DEBUGP ("retransmission\n" ); -return 0 ; +list_for_each_entry (km, &gre_keymap_list, list) { +if (gre_key_cmpfn (km, t) && km == *exist_km) +return 0 ; } -DEBUGP ("trying to override keymap_%s for ct %p\n" , reply?"reply" :"orig" , ct);return -EEXIST ;
@@ -136,7 +134,7 @@ ip_ct_gre_keymap_add(struct ip_conntrackDUMP_TUPLE_GRE (&km->tuple);write_lock_bh (&ip_ct_gre_lock); -list_append (&gre_keymap_list, km); +list_add_tail (&km->list, &gre_keymap_list);write_unlock_bh (&ip_ct_gre_lock);return 0 ;
net/ipv4/netfilter/ip_conntrack_standalone.c +0 -1
@@ -35,7 +35,6 @@ #include <linux/netfilter_ipv4/ip_conntr#include <linux/netfilter_ipv4/ip_conntrack_protocol.h> #include <linux/netfilter_ipv4/ip_conntrack_core.h> #include <linux/netfilter_ipv4/ip_conntrack_helper.h> -#include <linux/netfilter_ipv4/listhelp.h> #if 0 #define DEBUGP printk
net/ipv4/netfilter/ip_nat_core.c +0 -4
@@ -22,9 +22,6 @@ #include <linux/icmp.h>#include <linux/udp.h> #include <linux/jhash.h> -#define ASSERT_READ_LOCK (x) -#define ASSERT_WRITE_LOCK (x) -#include <linux/netfilter_ipv4/ip_conntrack.h> #include <linux/netfilter_ipv4/ip_conntrack_core.h> #include <linux/netfilter_ipv4/ip_conntrack_protocol.h>
@@ -33,7 +30,6 @@ #include <linux/netfilter_ipv4/ip_nat_pr#include <linux/netfilter_ipv4/ip_nat_core.h> #include <linux/netfilter_ipv4/ip_nat_helper.h> #include <linux/netfilter_ipv4/ip_conntrack_helper.h> -#include <linux/netfilter_ipv4/listhelp.h> #if 0 #define DEBUGP printk
net/ipv4/netfilter/ip_nat_helper.c +0 -4
@@ -27,16 +27,12 @@ #include <net/ip.h>#include <net/tcp.h> #include <net/udp.h> -#define ASSERT_READ_LOCK (x) -#define ASSERT_WRITE_LOCK (x) -#include <linux/netfilter_ipv4/ip_conntrack.h> #include <linux/netfilter_ipv4/ip_conntrack_helper.h> #include <linux/netfilter_ipv4/ip_nat.h> #include <linux/netfilter_ipv4/ip_nat_protocol.h> #include <linux/netfilter_ipv4/ip_nat_core.h> #include <linux/netfilter_ipv4/ip_nat_helper.h> -#include <linux/netfilter_ipv4/listhelp.h> #if 0 #define DEBUGP printk
net/ipv4/netfilter/ip_nat_rule.c +0 -4
@@ -19,14 +19,10 @@ #include <net/checksum.h>#include <net/route.h> #include <linux/bitops.h> -#define ASSERT_READ_LOCK (x) -#define ASSERT_WRITE_LOCK (x) -#include <linux/netfilter_ipv4/ip_tables.h> #include <linux/netfilter_ipv4/ip_nat.h> #include <linux/netfilter_ipv4/ip_nat_core.h> #include <linux/netfilter_ipv4/ip_nat_rule.h> -#include <linux/netfilter_ipv4/listhelp.h> #if 0 #define DEBUGP printk
net/ipv4/netfilter/ip_nat_standalone.c +0 -4
@@ -30,9 +30,6 @@ #include <net/ip.h>#include <net/checksum.h> #include <linux/spinlock.h> -#define ASSERT_READ_LOCK (x) -#define ASSERT_WRITE_LOCK (x) -#include <linux/netfilter_ipv4/ip_nat.h> #include <linux/netfilter_ipv4/ip_nat_rule.h> #include <linux/netfilter_ipv4/ip_nat_protocol.h>
@@ -40,7 +37,6 @@ #include <linux/netfilter_ipv4/ip_nat_co#include <linux/netfilter_ipv4/ip_nat_helper.h> #include <linux/netfilter_ipv4/ip_tables.h> #include <linux/netfilter_ipv4/ip_conntrack_core.h> -#include <linux/netfilter_ipv4/listhelp.h> #if 0 #define DEBUGP printk
net/ipv6/netfilter/ip6_tables.c +0 -3
@@ -70,9 +70,6 @@ #else#define IP_NF_ASSERT (x)#endif - -#include <linux/netfilter_ipv4/listhelp.h> -#if 0 /* All the better to debug you with... */ #define static
net/netfilter/nf_conntrack_core.c +86 -99
310 lines not on this page · raw message
net/netfilter/nf_conntrack_standalone.c +0 -1
@@ -37,7 +37,6 @@ #include <net/netfilter/nf_conntrack_l3p#include <net/netfilter/nf_conntrack_protocol.h> #include <net/netfilter/nf_conntrack_core.h> #include <net/netfilter/nf_conntrack_helper.h> -#include <linux/netfilter_ipv4/listhelp.h> #if 0 #define DEBUGP printk
net/netfilter/x_tables.c +10 -7
@@ -81,7 +81,7 @@ xt_unregister_target(struct xt_target *tint af = target->family;mutex_lock (&xt[af].mutex); -LIST_DELETE (&xt[af].target, target); +list_del (&target->list);mutex_unlock (&xt[af].mutex); }EXPORT_SYMBOL (xt_unregister_target);
@@ -138,7 +138,7 @@ xt_unregister_match(struct xt_match *matint af = match->family;mutex_lock (&xt[af].mutex); -LIST_DELETE (&xt[af].match, match); +list_del (&match->list);mutex_unlock (&xt[af].mutex); }EXPORT_SYMBOL (xt_unregister_match);
@@ -575,15 +575,18 @@ int xt_register_table(struct xt_table *t {int ret;struct xt_table_info *private; +struct xt_table *t; ret =mutex_lock_interruptible (&xt[table->af].mutex);if (ret !=0 )return ret;/* Don't autoload: we'd eat our tail... */ -if (list_named_find (&xt[table->af].tables, table->name)) { - ret = -EEXIST ; - goto unlock; +list_for_each_entry (t, &xt[table->af].tables, list) { +if (strcmp (t->name, table->name) ==0 ) { + ret = -EEXIST ; + goto unlock; + } }/* Simplifies replace_table code. */
@@ -598,7 +601,7 @@ int xt_register_table(struct xt_table *t/* save number of initial entries */ private->initial_entries = private->number; -list_prepend (&xt[table->af].tables, table); +list_add (&table->list, &xt[table->af].tables); ret =0 ; unlock:
@@ -613,7 +616,7 @@ void *xt_unregister_table(struct xt_tablmutex_lock (&xt[table->af].mutex); private = table->private; -LIST_DELETE (&xt[table->af].tables, table); +list_del (&table->list);mutex_unlock (&xt[table->af].mutex);return private;
David Miller
maintainerRe: [NETFILTER 04/39]: ipt_TCPMSS: reformat
In reply to Roberto NibaliFrom: Roberto Nibali <[email protected]>
Date: Wed, 20 Sep 2006 13:03:40 +0200
Quoted 1 line
Would something like this be a candidate for 2.4 as well?
Like Patrick, I believe that 2.4.x is in such deep extreme maintainence mode that we should only ever consider pushing patches that users are actually hitting, or else we'll be backporting a lot of stuff and potentially causing more harm than good via potential regressions.
I really don't like this trigger-happy "maybe backport this fix to 2.4.x" reaction some people have. :-/
Heck, for many of us 2.4.x is so old that we don't even have systems any longer that we can test them on since most distributions compile glibc in such a way that using kernels older than 2.6.x is basically impossible.
David Miller
maintainerFrom: Patrick McHardy <[email protected]>
Date: Wed, 20 Sep 2006 10:23:51 +0200 (MEST)
Quoted 7 lines
following is another netfilter update for 2.6.19, consisting of a number of random cleanup and fixes, a rework of the iptables compat code including compat support for (AFAICT) all missing matches/targets and some cleanup and fixes for the PPtP connection tracking helper. Some of these should also go in -stable, I'll prepare backports and send them seperately.
Please apply, thanks.
All applied, thanks Patrick.
I'll push this out to net-2.6.19 once I do some test build.
Thanks again.
Re: [NETFILTER 04/39]: ipt_TCPMSS: reformat
In reply to David MillerHi David,
Quoted 10 lines · David Miller
From: Roberto Nibali <[email protected]>
Date: Wed, 20 Sep 2006 13:03:40 +0200Quoted 1 line
Would something like this be a candidate for 2.4 as well?
Like Patrick, I believe that 2.4.x is in such deep extreme maintainence mode that we should only ever consider pushing patches that users are actually hitting, or else we'll be backporting a lot of stuff and potentially causing more harm than good via potential regressions.
I'm not really fond of pure cleanups either. We're all humans and a bug in trivial changes is likely to happen once in a while. Also, it sometimes causes rejects to some external patches.
Quoted 2 lines
I really don't like this trigger-happy "maybe backport this fix to 2.4.x" reaction some people have. :-/
I can understand why. It's often easier to compare identical code sections, particularly when security fixes are needed, so the little risk of introducing new bugs is really tempting. And I've been tempted several times in the past too.
Quoted 4 lines
Heck, for many of us 2.4.x is so old that we don't even have systems any longer that we can test them on since most distributions compile glibc in such a way that using kernels older than 2.6.x is basically impossible.
[OT]
It's interesting to see the shift between developpers (and desktop) on one side, and production servers on the other side. Believe it or not, I've not yet encountered 2.6 in places I work at. Mostly 2.4 and some rare times 2.2. BTW, RHEL3 is supported till 2010 !
I predict that 2.4 quality will degrade again in a few years by lack of testers for fixes. By this time, hopefully 2.6 will have reached the same level of reliability.
[/OT]
Cheers,
Willy