netfilter-devel Digest, Vol 6, Issue 30
netfilter-devel-request,您好!
Hi,everyone,how can I remove a connection track entry from hash table,is there any user lib :)
======= 2005-01-11 19:52:09 您在来信中写道:=======
Quoted 775 lines
Send netfilter-devel mailing list submissions to
[email protected]To subscribe or unsubscribe via the World Wide Web, visit
https://lists.netfilter.org/mailman/listinfo/netfilter-devel
or, via email, send a message with subject or body 'help' to
[email protected]You can reach the person managing the list at
[email protected]When replying, please edit your Subject line so it is more specific than "Re: Contents of netfilter-devel digest..."
Today's Topics:
1. Re: [PATCH 2/8] Netfilter: Call NAT Helper Modules Directly
from Conntrack Modules, fixup FTP (Harald Welte)
2. [PATCH 1/3] Netfilter: Removeip_conntrack_tuple_hash
"ctrack" pointer (Rusty Russell)
3. [PATCH 2/3] Netfilter: Use a bit in conntrack status to
indicate sequence number adjustment (Rusty Russell)
4. [PATCH 3/3] Netfilter: Get rid of initialized in nat
structure: use conntrack status bits (Rusty Russell)----------------------------------------------------------------------
Message: 1
Date: Tue, 11 Jan 2005 12:13:14 +0100
From: Harald Welte <[email protected]>
Subject: Re: [PATCH 2/8] Netfilter: Call NAT Helper Modules Directly
from Conntrack Modules, fixup FTP
To: Rusty Russell <[email protected]>
Cc: Netfilter development mailing list
<[email protected]>
Message-ID: <[email protected]>
Content-Type: text/plain; charset="us-ascii"Quoted 3 lines · Rusty Russell
Name: Call NAT Helper Modules Directly from Conntrack Modules, fixup FTP
Signed-off-by Rusty Russell <[email protected]>Status: Tested under nfsim
Thanks, Rusty.
I agree with all your changes but the removal of the copyright and GPL notice ;)
Signature · 42 lines
- Harald Welte <[email protected]> http://www.netfilter.org/ ============================================================================ "Fragmentation is like classful addressing -- an interesting early architectural error that shows how much experimentation was going on while IP was being designed." -- Paul Vixie -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 189 bytes Desc: Digital signature Url : /pipermail/netfilter-devel/attachments/20050111/c39673ef/attachment-0001.bin ------------------------------ Message: 2 Date: Tue, 11 Jan 2005 22:50:54 +1100 From: Rusty Russell <[email protected]> Subject: [PATCH 1/3] Netfilter: Remove ip_conntrack_tuple_hash "ctrack" pointer To: Harald Welte <[email protected]> Cc: Netfilter development mailing list <[email protected]> Message-ID: <[email protected]> Content-Type: text/plain Oops, these three are part of the previous chain. Name: Remove ip_conntrack_tuple_hash "ctrack" pointer Status: Tested under nfsim Signed-off-by: Rusty Russell <[email protected]> We keep a pointer from the hash table entry into the connection tracking entry it's a part of. However, there's a spare byte in the hash entry anyway, which we can use to indicate which of the two tuples it is, and the simply use container_of() to access the conntrack. This saves two pointers per connection tracking entry. Index: linux-2.6.10-bk13-Netfilter/net/ipv4/netfilter/ip_conntrack_amanda.c ===================================================================net/ipv4/netfilter/ip_conntrack_amanda.c +2
-2@@ -120,7 +120,7 @@ exp->mask.src.ip =0xFFFFFFFF ; exp->mask.src.u.tcp.port =0 ; exp->mask.dst.ip =0xFFFFFFFF ; - exp->mask.dst.protonum =0xFFFF ; + exp->mask.dst.protonum =0xFF ; exp->mask.dst.u.tcp.port =0xFFFF ;if (ip_nat_amanda_hook)@@ -149,7 +149,7 @@ .dst = { .protonum = IPPROTO_UDP }, }, .mask = { .src = { .u = { 0xFFFF } }, - .dst = { .protonum = 0xFFFF }, + .dst = { .protonum = 0xFF }, }, };Index:
linux-2.6.10-bk13-Netfilter/net/ipv4/netfilter/ip_conntrack_standalone.c
===================================================================net/ipv4/netfilter/ip_conntrack_standalone.c +0
-0@@ -66,7 +66,8 @@#ifdef CONFIG_IP_NF_CT_ACCT static unsigned int
net/ipv4/netfilter/ip_conntrack_standalone.c +2
-1-seq_print_counters(struct seq_file *s, struct ip_conntrack_counter *counter) +seq_print_counters(struct seq_file *s, + const struct ip_conntrack_counter *counter){ return seq_printf(s, "packets=%llu bytes=%llu ", (unsigned long long)counter->packets,net/ipv4/netfilter/ip_conntrack_standalone.c +1
-1@@ -99,7 +100,7 @@static int ct_seq_real_show (const struct ip_conntrack_tuple_hash *hash,struct seq_file *s) { -struct ip_conntrack *conntrack = hash->ctrack; +const struct ip_conntrack *conntrack =tuplehash_to_ctrack (hash);struct ip_conntrack_protocol *proto;MUST_BE_READ_LOCKED (&ip_conntrack_lock);Index:
linux-2.6.10-bk13-Netfilter/include/linux/netfilter_ipv4/ip_nat.h
===================================================================include/linux/netfilter_ipv4/ip_nat.h +2
-0@@ -66,6 +66,8 @@struct ip_nat_seq seq[IP_CT_DIR_MAX ]; }; +struct ip_conntrack ; +/* Set up the info structure to map into this range. */ extern unsigned int ip_nat_setup_info(struct ip_conntrack *conntrack, const struct ip_nat_range *range,Index:
linux-2.6.10-bk13-Netfilter/include/linux/netfilter_ipv4/ip_conntrack.h
===================================================================include/linux/netfilter_ipv4/ip_conntrack.h +7
-0@@ -192,6 +192,13 @@struct ip_conntrack_tuple_hash tuplehash[IP_CT_DIR_MAX ]; }; +static inline struct ip_conntrack * +tuplehash_to_ctrack (const struct ip_conntrack_tuple_hash *hash) +{ + return container_of(hash, struct ip_conntrack, + tuplehash[hash->tuple.dst.dir]); +} +/* get master conntrack via master expectation */ #define master_ct (conntr) (conntr->master)Index:
linux-2.6.10-bk13-Netfilter/net/ipv4/netfilter/ip_conntrack_tftp.c
===================================================================net/ipv4/netfilter/ip_conntrack_tftp.c +2
-2@@ -73,7 +73,7 @@ exp->mask.src.ip =0xffffffff ; exp->mask.dst.ip =0xffffffff ; exp->mask.dst.u.udp.port =0xffff ; - exp->mask.dst.protonum =0xffff ; + exp->mask.dst.protonum =0xff ; exp->expectfn =NULL ; exp->master = ct;@@ -128,7 +128,7 @@ tftp[i].tuple.dst.protonum =IPPROTO_UDP ; tftp[i].tuple.src.u.udp.port =htons (ports[i]); - tftp[i].mask.dst.protonum =0xFFFF ; + tftp[i].mask.dst.protonum =0xFF ; tftp[i].mask.src.u.udp.port =0xFFFF ; tftp[i].max_expected =1 ; tftp[i].timeout =5 *60 ;/* 5 minutes */ Index:
linux-2.6.10-bk13-Netfilter/net/ipv4/netfilter/ip_conntrack_ftp.c
===================================================================net/ipv4/netfilter/ip_conntrack_ftp.c +2
-2@@ -418,7 +418,7 @@ exp->tuple.dst.protonum =IPPROTO_TCP ; exp->mask = ((struct ip_conntrack_tuple ) { {0xFFFFFFFF , {0 } }, - {0xFFFFFFFF , { .tcp = {0xFFFF } },0xFFFF }}); + {0xFFFFFFFF , { .tcp = {0xFFFF } },0xFF }}); exp->expectfn =NULL ; exp->master = ct;@@ -473,7 +473,7 @@ ftp[i].tuple.src.u.tcp.port =htons (ports[i]); ftp[i].tuple.dst.protonum =IPPROTO_TCP ; ftp[i].mask.src.u.tcp.port =0xFFFF ; - ftp[i].mask.dst.protonum =0xFFFF ; + ftp[i].mask.dst.protonum =0xFF ; ftp[i].max_expected =1 ; ftp[i].timeout =5 *60 ;/* 5 minutes */ ftp[i].me =THIS_MODULE ;Index:
linux-2.6.10-bk13-Netfilter/net/ipv4/netfilter/ip_conntrack_proto_icmp.c
===================================================================net/ipv4/netfilter/ip_conntrack_proto_icmp.c +1
-1@@ -196,7 +196,7 @@ }/* Update skb to refer to this connection */ - skb->nfct = &h->ctrack->ct_general; + skb->nfct = &tuplehash_to_ctrack (h)->ct_general; skb->nfctinfo = *ctinfo;return -NF_ACCEPT ; }Index:
linux-2.6.10-bk13-Netfilter/net/ipv4/netfilter/ip_conntrack_irc.c
===================================================================net/ipv4/netfilter/ip_conntrack_irc.c +2
-2@@ -215,7 +215,7 @@ IPPROTO_TCP }}); exp->mask = ((struct ip_conntrack_tuple ) { {0 , {0 } }, - {0xFFFFFFFF , { .tcp = {0xFFFF } },0xFFFF }}); + {0xFFFFFFFF , { .tcp = {0xFFFF } },0xFF }}); exp->expectfn =NULL ; exp->master = ct;if (ip_nat_irc_hook)@@ -265,7 +265,7 @@ hlpr->tuple.src.u.tcp.port =htons (ports[i]); hlpr->tuple.dst.protonum =IPPROTO_TCP ; hlpr->mask.src.u.tcp.port =0xFFFF ; - hlpr->mask.dst.protonum =0xFFFF ; + hlpr->mask.dst.protonum =0xFF ; hlpr->max_expected = max_dcc_channels; hlpr->timeout = dcc_timeout; hlpr->me =THIS_MODULE ;Index:
linux-2.6.10-bk13-Netfilter/include/linux/netfilter_ipv4/ip_conntrack_tuple.h
===================================================================include/linux/netfilter_ipv4/ip_conntrack_tuple.h +5
-2@@ -64,7 +64,10 @@ } u;/* The protocol. */ -u_int16_t protonum; +u8 protonum; + +/* The direction (for tuplehash) */ +u8 dir; } dst; };@@ -94,7 +97,7 @@#define CTINFO2DIR (ctinfo) ((ctinfo) >= IP_CT_IS_REPLY ? IP_CT_DIR_REPLY : IP_CT_DIR_ORIGINAL)/* If we're the first tuple, it's the original dir. */ -#define DIRECTION (h) ((enum ip_conntrack_dir)(&(h)->ctrack->tuplehash[1] == (h))) +#define DIRECTION (h) ((enum ip_conntrack_dir)(h)->tuple.dst.dir)/* Connections have two entries in the hash table: one for each way */ struct
ip_conntrack_tuple_hashinclude/linux/netfilter_ipv4/ip_conntrack_tuple.h +0
-3@@ -102,9 +105,6 @@struct list_head list; struct ip_conntrack_tuple tuple; - -/* this == &ctrack->tuplehash[DIRECTION(this)]. */ - struct ip_conntrack *ctrack; };#endif /* __KERNEL__ */ Index:
linux-2.6.10-bk13-Netfilter/net/ipv4/netfilter/ip_conntrack_core.c
===================================================================net/ipv4/netfilter/ip_conntrack_core.c +35
-29@@ -117,6 +117,7 @@ tuple->src.ip = iph->saddr; tuple->dst.ip = iph->daddr; tuple->dst.protonum = iph->protocol; + tuple->dst.dir =IP_CT_DIR_ORIGINAL ;return protocol->pkt_to_tuple (skb, dataoff, tuple); }@@ -129,6 +130,7 @@ inverse->src.ip = orig->dst.ip; inverse->dst.ip = orig->src.ip; inverse->dst.protonum = orig->dst.protonum; + inverse->dst.dir = !orig->dst.dir;return protocol->invert_tuple (inverse, orig); }@@ -281,7 +283,7 @@ const struct ip_conntrack *ignored_conntrack) {MUST_BE_READ_LOCKED (&ip_conntrack_lock); -return i->ctrack != ignored_conntrack +return tuplehash_to_ctrack (i) != ignored_conntrack &&ip_ct_tuple_equal (tuple, &i->tuple); }@@ -314,7 +316,7 @@READ_LOCK (&ip_conntrack_lock); h =__ip_conntrack_find (tuple, ignored_conntrack);if (h) -atomic_inc (&h->ctrack->ct_general.use); +atomic_inc (&tuplehash_to_ctrack (h)->ct_general.use);READ_UNLOCK (&ip_conntrack_lock);return h;@@ -407,30 +409,33 @@connection. Too bad: we're in trouble anyway. */ static inline int unreplied (const struct ip_conntrack_tuple_hash *i) { -return !(test_bit (IPS_ASSURED_BIT , &i->ctrack->status)); +return !(test_bit (IPS_ASSURED_BIT , &tuplehash_to_ctrack (i)->status)); }static int early_drop (struct list_head *chain) {/* Traverse backwards: gives us oldest, which is roughly LRU */ struct ip_conntrack_tuple_hash *h; +struct ip_conntrack *ct =NULL ;int dropped =0 ;READ_LOCK (&ip_conntrack_lock); h = LIST_FIND_B(chain, unreplied, struct ip_conntrack_tuple_hash *); -if (h) -atomic_inc (&h->ctrack->ct_general.use); +if (h) { + ct =tuplehash_to_ctrack (h); +atomic_inc (&ct->ct_general.use); + }READ_UNLOCK (&ip_conntrack_lock); -if (!h) +if (!ct)return dropped; -if (del_timer (&h->ctrack->timeout)) { -death_by_timeout ((unsigned long )h->ctrack); +if (del_timer (&ct->timeout)) { +death_by_timeout ((unsigned long )ct); dropped =1 ;CONNTRACK_STAT_INC (early_drop); } -ip_conntrack_put (h->ctrack); +ip_conntrack_put (ct);return dropped; }@@ -493,9 +498,7 @@atomic_set (&conntrack->ct_general.use,1 ); conntrack->ct_general.destroy = destroy_conntrack; conntrack->tuplehash[IP_CT_DIR_ORIGINAL ].tuple = *tuple; - conntrack->tuplehash[IP_CT_DIR_ORIGINAL ].ctrack = conntrack; conntrack->tuplehash[IP_CT_DIR_REPLY ].tuple = repl_tuple; - conntrack->tuplehash[IP_CT_DIR_REPLY ].ctrack = conntrack;if (!protocol->new (conntrack, skb)) {kmem_cache_free (ip_conntrack_cachep, conntrack);return NULL ;@@ -550,6 +553,7 @@ {struct ip_conntrack_tuple tuple;struct ip_conntrack_tuple_hash *h; +struct ip_conntrack *ct;IP_NF_ASSERT ((skb->nh.iph->frag_off &htons (IP_OFFSET )) ==0 );@@ -566,6 +570,7 @@if (IS_ERR (h))return (void *)h; } + ct =tuplehash_to_ctrack (h);/* It exists; we have (non-exclusive) reference. */ if (DIRECTION (h) ==IP_CT_DIR_REPLY ) {@@ -574,24 +579,24 @@ *set_reply =1 ; }else {/* Once we've had two way comms, always ESTABLISHED. */ -if (test_bit (IPS_SEEN_REPLY_BIT , &h->ctrack->status)) { +if (test_bit (IPS_SEEN_REPLY_BIT , &ct->status)) {DEBUGP ("ip_conntrack_in: normal packet for %p\n" , - h->ctrack); + ct); *ctinfo =IP_CT_ESTABLISHED ; - }else if (test_bit (IPS_EXPECTED_BIT , &h->ctrack->status)) { + }else if (test_bit (IPS_EXPECTED_BIT , &ct->status)) {DEBUGP ("ip_conntrack_in: related packet for %p\n" , - h->ctrack); + ct); *ctinfo =IP_CT_RELATED ; }else {DEBUGP ("ip_conntrack_in: new packet for %p\n" , - h->ctrack); + ct); *ctinfo =IP_CT_NEW ; } *set_reply =0 ; } - skb->nfct = &h->ctrack->ct_general; + skb->nfct = &ct->ct_general; skb->nfctinfo = *ctinfo; -return h->ctrack; +return ct; }/* Netfilter hook itself. */ @@ -862,8 +867,8 @@static inline int unhelp (struct ip_conntrack_tuple_hash *i,const struct ip_conntrack_helper *me) { -if (i->ctrack->helper == me) - i->ctrack->helper =NULL ; +if (tuplehash_to_ctrack (i)->helper == me) +tuplehash_to_ctrack (i)->helper =NULL ;return 0 ; }@@ -1001,7 +1006,7 @@int (*iter)(struct ip_conntrack *i,void *data), void *data) { - return iter(i->ctrack, data); + return iter(tuplehash_to_ctrack(i), data); }/* Bring out ya dead! */ @@ -1022,7 +1027,7 @@ h =LIST_FIND_W (&unconfirmed, do_iter, struct ip_conntrack_tuple_hash *, iter, data);if (h) -atomic_inc (&h->ctrack->ct_general.use); +atomic_inc (&tuplehash_to_ctrack (h)->ct_general.use);WRITE_UNLOCK (&ip_conntrack_lock);return h;@@ -1035,12 +1040,13 @@unsigned int bucket =0 ;while ((h =get_next_corpse (iter, data, &bucket)) !=NULL ) { +struct ip_conntrack *ct =tuplehash_to_ctrack (h);/* Time to push up daises... */ -if (del_timer (&h->ctrack->timeout)) -death_by_timeout ((unsigned long )h->ctrack); +if (del_timer (&ct->timeout)) +death_by_timeout ((unsigned long )ct);/* ... else the timer will get him soon. */ -ip_conntrack_put (h->ctrack); +ip_conntrack_put (ct); } }@@ -1077,16 +1083,17 @@ h =ip_conntrack_find_get (&tuple,NULL );if (h) {struct sockaddr_in sin; +struct ip_conntrack *ct =tuplehash_to_ctrack (h); sin.sin_family =AF_INET ; - sin.sin_port = h->ctrack->tuplehash[IP_CT_DIR_ORIGINAL ] + sin.sin_port = ct->tuplehash[IP_CT_DIR_ORIGINAL ] .tuple.dst.u.tcp.port; - sin.sin_addr.s_addr = h->ctrack->tuplehash[IP_CT_DIR_ORIGINAL ] + sin.sin_addr.s_addr = ct->tuplehash[IP_CT_DIR_ORIGINAL ] .tuple.dst.ip;DEBUGP ("SO_ORIGINAL_DST: %u.%u.%u.%u %u\n" ,NIPQUAD (sin.sin_addr.s_addr),ntohs (sin.sin_port)); -ip_conntrack_put (h->ctrack); +ip_conntrack_put (ct);if (copy_to_user (user, &sin,sizeof (sin)) !=0 )return -EFAULT ;else ------------------------------Message: 3
Date: Tue, 11 Jan 2005 22:51:21 +1100
From: Rusty Russell <[email protected]>
Subject: [PATCH 2/3] Netfilter: Use a bit in conntrack status to
indicate sequence number adjustment
To: Harald Welte <[email protected]>
Cc: Netfilter development mailing list
<[email protected]>
Message-ID: <[email protected]>
Content-Type: text/plainName: Use a bit in conntrack status to indicate sequence number adjustment
Status: Tested under nfsimSigned-off-by Rusty Russell <[email protected]>Rather than calling the sequence adjustment code on every connection which has a helper, we can set a status bit on the conntrack when we change the length of a TCP packet, and use that to indicate that we should call the routine.
Index:
linux-2.6.10-bk13-Netfilter/net/ipv4/netfilter/ip_nat_core.c
===================================================================net/ipv4/netfilter/ip_nat_core.c +1
-3@@ -354,9 +354,7 @@unsigned long statusbit;enum ip_nat_manip_type mtype =HOOK2MANIP (hooknum); -/* FIXME: use a bit in status for this. */ -if (ct->helper - && ct->tuplehash[0 ].tuple.dst.protonum ==IPPROTO_TCP +if (test_bit (IPS_SEQ_ADJUST_BIT , &ct->status) && (hooknum ==NF_IP_POST_ROUTING || hooknum ==NF_IP_LOCAL_IN )) {DEBUGP ("ip_nat_core: adjusting sequence number\n" );/* future: put this in a l4-proto specific function, Index:
linux-2.6.10-bk13-Netfilter/net/ipv4/netfilter/ip_nat_helper.c
===================================================================net/ipv4/netfilter/ip_nat_helper.c +8
-10@@ -192,11 +192,14 @@ tcph->check =tcp_v4_check (tcph, datalen, iph->saddr, iph->daddr,csum_partial ((char *)tcph, datalen,0 )); -adjust_tcp_sequence (ntohl (tcph->seq), - (int )rep_len - (int )match_len, - ct, ctinfo); -/* Tell connection tracking about seq change, to expand window */ -ip_conntrack_tcp_update (*pskb, ct,CTINFO2DIR (ctinfo)); +if (rep_len != match_len) { +set_bit (IPS_SEQ_ADJUST_BIT , &ct->status); +adjust_tcp_sequence (ntohl (tcph->seq), + (int )rep_len - (int )match_len, + ct, ctinfo); +/* Tell TCP window tracking about seq change */ +ip_conntrack_tcp_update (*pskb, ct,CTINFO2DIR (ctinfo)); + }return 1 ; }@@ -363,11 +366,6 @@ this_way = &ct->nat.info.seq[dir]; other_way = &ct->nat.info.seq[!dir]; -/* No adjustments to make? Very common case. */ -if (!this_way->offset_before && !this_way->offset_after - && !other_way->offset_before && !other_way->offset_after) -return 1 ; -if (!skb_ip_make_writable (pskb, (*pskb)->nh.iph->ihl*4 +sizeof (*tcph)))return 0 ;Index:
linux-2.6.10-bk13-Netfilter/include/linux/netfilter_ipv4/ip_conntrack.h
===================================================================include/linux/netfilter_ipv4/ip_conntrack.h +4
-1@@ -51,6 +51,10 @@/* Both together. */ IPS_NAT_MASK = (IPS_DST_NAT |IPS_SRC_NAT ), + +/* Connection needs TCP sequence adjusted. */ +IPS_SEQ_ADJUST_BIT =6 , + IPS_SEQ_ADJUST = (1 << IPS_SEQ_ADJUST_BIT), };#ifdef __KERNEL__ ------------------------------Message: 4
Date: Tue, 11 Jan 2005 22:51:31 +1100
From: Rusty Russell <[email protected]>
Subject: [PATCH 3/3] Netfilter: Get rid of initialized in nat
structure: use conntrack status bits
To: Harald Welte <[email protected]>
Cc: Netfilter development mailing list
<[email protected]>
Message-ID: <[email protected]>
Content-Type: text/plainName: Get rid of initialized in nat structure: use conntrack status bits
Status: Tested under nfsimSigned-off-by Rusty Russell <[email protected]>Fairly simple patch to move the "initialized" NAT bitfield to bits in the 'status' word. This saves the size of a pointer from the connection tracking structure.
Index:
linux-2.6.10-bk13-Netfilter/net/ipv4/netfilter/ip_nat_core.c
===================================================================net/ipv4/netfilter/ip_nat_core.c +16
-15@@ -62,13 +62,11 @@/* Noone using conntrack by the time this called. */ static void ip_nat_cleanup_conntrack (struct ip_conntrack *conn) { -struct ip_nat_info *info = &conn->nat.info; - -if (!info->initialized) +if (!(conn->status &IPS_NAT_DONE_MASK ))return ;WRITE_LOCK (&ip_nat_lock); -list_del (&info->bysource); +list_del (&conn->nat.info.bysource);WRITE_UNLOCK (&ip_nat_lock); }@@ -261,14 +259,14 @@ {struct ip_conntrack_tuple curr_tuple, new_tuple;struct ip_nat_info *info = &conntrack->nat.info; -int have_to_hash = !info->initialized; +int have_to_hash = !(conntrack->status &IPS_NAT_DONE_MASK );enum ip_nat_manip_type maniptype =HOOK2MANIP (hooknum);IP_NF_ASSERT (hooknum ==NF_IP_PRE_ROUTING || hooknum ==NF_IP_POST_ROUTING || hooknum ==NF_IP_LOCAL_IN || hooknum ==NF_IP_LOCAL_OUT ); -IP_NF_ASSERT (!(info->initialized & (1 << maniptype))); +BUG_ON (ip_nat_initialized (conntrack, maniptype));/* What we've got will look like inverse of reply. Normally this is what is in the conntrack, except for prior @@ -305,7 +303,11 @@ }/* It's done. */ - info->initialized |= (1 << maniptype); +if (maniptype ==IP_NAT_MANIP_DST ) +set_bit (IPS_DST_NAT_DONE_BIT , &conntrack->status); +else +set_bit (IPS_SRC_NAT_DONE_BIT , &conntrack->status); +return NF_ACCEPT ; }@@ -420,10 +422,11 @@start talking to each other without our translation, and be confused... --RR */ if (inside->icmp.type ==ICMP_REDIRECT ) { -/* Don't care about races here. */ -if (ct->nat.info.initialized - != ((1 <<IP_NAT_MANIP_SRC ) | (1 <<IP_NAT_MANIP_DST )) - || (ct->status &IPS_NAT_MASK )) +/* If NAT isn't finished, assume it and drop. */ +if ((ct->status &IPS_NAT_DONE_MASK ) !=IPS_NAT_DONE_MASK ) +return 0 ; + +if (ct->status &IPS_NAT_MASK )return 0 ; }@@ -503,11 +506,9 @@/* FIXME: Man, this is a hack. <SIGH> */ IP_NF_ASSERT (ip_conntrack_destroyed ==NULL ); ip_conntrack_destroyed = &ip_nat_cleanup_conntrack; - -/* Initialize fake conntrack so that NAT will skip it */ - ip_conntrack_untracked.nat.info.initialized |= - (1 <<IP_NAT_MANIP_SRC ) | (1 <<IP_NAT_MANIP_DST ); +/* Initialize fake conntrack so that NAT will skip it */ + ip_conntrack_untracked.status |=IPS_NAT_DONE_MASK ;return 0 ; }Index:
linux-2.6.10-bk13-Netfilter/net/ipv4/netfilter/ip_nat_helper.c
===================================================================net/ipv4/netfilter/ip_nat_helper.c +1
-1@@ -411,7 +411,7 @@struct ip_nat_range range;/* This must be a fresh one. */ -BUG_ON (ct->nat.info.initialized); +BUG_ON (ct->status &IPS_NAT_DONE_MASK );/* Change src to where master sends to */ range.flags =IP_NAT_RANGE_MAP_IPS ;Index:
linux-2.6.10-bk13-Netfilter/net/ipv4/netfilter/ip_nat_rule.c
===================================================================net/ipv4/netfilter/ip_nat_rule.c +1
-1@@ -287,7 +287,7 @@ ret =ipt_do_table (pskb, hooknum, in, out, &nat_table,NULL );if (ret ==NF_ACCEPT ) { -if (!(info->initialized & (1 <<HOOK2MANIP (hooknum)))) +if (!ip_nat_initialized (ct,HOOK2MANIP (hooknum)))/* NUL mapping */ ret =alloc_null_binding (ct, info, hooknum); }Index:
linux-2.6.10-bk13-Netfilter/include/linux/netfilter_ipv4/ip_nat.h
===================================================================include/linux/netfilter_ipv4/ip_nat.h +0
-0@@ -55,9 +55,6 @@/* The structure embedded in the conntrack structure. */ struct
ip_nat_info
{include/linux/netfilter_ipv4/ip_nat.h +0
-3-/* Set to zero when conntrack created: bitmask of maniptypes */ -u_int16_t initialized; -struct list_head bysource; /* Helper (NULL if none). */Index:
linux-2.6.10-bk13-Netfilter/include/linux/netfilter_ipv4/ip_conntrack.h
===================================================================include/linux/netfilter_ipv4/ip_conntrack.h +17
-0@@ -55,6 +55,16 @@/* Connection needs TCP sequence adjusted. */ IPS_SEQ_ADJUST_BIT =6 ,IPS_SEQ_ADJUST = (1 <<IPS_SEQ_ADJUST_BIT ), + +/* NAT initialization bits. */ +IPS_SRC_NAT_DONE_BIT =7 , +IPS_SRC_NAT_DONE = (1 <<IPS_SRC_NAT_DONE_BIT ), + +IPS_DST_NAT_DONE_BIT =8 , +IPS_DST_NAT_DONE = (1 <<IPS_DST_NAT_DONE_BIT ), + +/* Both together */ + IPS_NAT_DONE_MASK = (IPS_DST_NAT_DONE | IPS_SRC_NAT_DONE), };#ifdef __KERNEL__@@ -291,5 +301,12 @@#define CONNTRACK_STAT_INC (count) (__get_cpu_var(ip_conntrack_stat).count++) +static inline int ip_nat_initialized (struct ip_conntrack *conntrack, +enum ip_nat_manip_type manip) +{ +if (manip ==IP_NAT_MANIP_SRC ) +return test_bit (IPS_SRC_NAT_DONE_BIT , &conntrack->status); +return test_bit (IPS_DST_NAT_DONE_BIT , &conntrack->status); +}#endif /* __KERNEL__ */ #endif /* _IP_CONNTRACK_H */ Index:
linux-2.6.10-bk13-Netfilter/net/ipv4/netfilter/ip_nat_standalone.c
===================================================================net/ipv4/netfilter/ip_nat_standalone.c +1
-2@@ -118,7 +118,7 @@/* Seen it before? This can happen for loopback, retrans, or local packets.. */ -if (!(info->initialized & (1 << maniptype))) { +if (!ip_nat_initialized (ct, maniptype)) {unsigned int ret;/* LOCAL_IN hook doesn't have a chain! */ ------------------------------
Quoted 9 lines
_______________________________________________
netfilter-devel mailing list
[email protected]
https://lists.netfilter.org/mailman/listinfo/netfilter-develEnd of netfilter-devel Digest, Vol 6, Issue 30
**********************************************
= = = = = = = = = = = = = = = = = = = =
致
礼!
linkai
[email protected]
2005-01-12