diff options
author | Pavel Emelyanov <xemul@openvz.org> | 2007-10-17 22:44:34 -0400 |
---|---|---|
committer | David S. Miller <davem@davemloft.net> | 2007-10-17 22:44:34 -0400 |
commit | 2588fe1d782f1686847493ad643157d5d10bf602 (patch) | |
tree | 7513851819330d4ff6aadc9f76b1b45bc03f8f82 /net/ipv6 | |
parent | fd9e63544cac30a34c951f0ec958038f0529e244 (diff) |
[INET]: Consolidate xxx_frag_intern
This routine checks for the existence of a given entry
in the hash table and inserts the new one if needed.
The ->equal callback is used to compare two frag_queue-s
together, but this one is temporary and will be removed
later. The netfilter code and the ipv6 one use the same
routine to compare frags.
The inet_frag_intern() always returns non-NULL pointer,
so convert the inet_frag_queue into protocol specific
one (with the container_of) without any checks.
Signed-off-by: Pavel Emelyanov <xemul@openvz.org>
Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'net/ipv6')
-rw-r--r-- | net/ipv6/netfilter/nf_conntrack_reasm.c | 34 | ||||
-rw-r--r-- | net/ipv6/reassembly.c | 46 |
2 files changed, 20 insertions, 60 deletions
diff --git a/net/ipv6/netfilter/nf_conntrack_reasm.c b/net/ipv6/netfilter/nf_conntrack_reasm.c index 726fafd41961..d7dc444ec48f 100644 --- a/net/ipv6/netfilter/nf_conntrack_reasm.c +++ b/net/ipv6/netfilter/nf_conntrack_reasm.c | |||
@@ -187,37 +187,10 @@ out: | |||
187 | static struct nf_ct_frag6_queue *nf_ct_frag6_intern(unsigned int hash, | 187 | static struct nf_ct_frag6_queue *nf_ct_frag6_intern(unsigned int hash, |
188 | struct nf_ct_frag6_queue *fq_in) | 188 | struct nf_ct_frag6_queue *fq_in) |
189 | { | 189 | { |
190 | struct nf_ct_frag6_queue *fq; | 190 | struct inet_frag_queue *q; |
191 | #ifdef CONFIG_SMP | ||
192 | struct hlist_node *n; | ||
193 | #endif | ||
194 | |||
195 | write_lock(&nf_frags.lock); | ||
196 | #ifdef CONFIG_SMP | ||
197 | hlist_for_each_entry(fq, n, &nf_frags.hash[hash], q.list) { | ||
198 | if (fq->id == fq_in->id && | ||
199 | ipv6_addr_equal(&fq_in->saddr, &fq->saddr) && | ||
200 | ipv6_addr_equal(&fq_in->daddr, &fq->daddr)) { | ||
201 | atomic_inc(&fq->q.refcnt); | ||
202 | write_unlock(&nf_frags.lock); | ||
203 | fq_in->q.last_in |= COMPLETE; | ||
204 | fq_put(fq_in); | ||
205 | return fq; | ||
206 | } | ||
207 | } | ||
208 | #endif | ||
209 | fq = fq_in; | ||
210 | 191 | ||
211 | if (!mod_timer(&fq->q.timer, jiffies + nf_frags_ctl.timeout)) | 192 | q = inet_frag_intern(&fq_in->q, &nf_frags, hash); |
212 | atomic_inc(&fq->q.refcnt); | 193 | return container_of(q, struct nf_ct_frag6_queue, q); |
213 | |||
214 | atomic_inc(&fq->q.refcnt); | ||
215 | hlist_add_head(&fq->q.list, &nf_frags.hash[hash]); | ||
216 | INIT_LIST_HEAD(&fq->q.lru_list); | ||
217 | list_add_tail(&fq->q.lru_list, &nf_frags.lru_list); | ||
218 | nf_frags.nqueues++; | ||
219 | write_unlock(&nf_frags.lock); | ||
220 | return fq; | ||
221 | } | 194 | } |
222 | 195 | ||
223 | 196 | ||
@@ -752,6 +725,7 @@ int nf_ct_frag6_init(void) | |||
752 | nf_frags.destructor = nf_frag_free; | 725 | nf_frags.destructor = nf_frag_free; |
753 | nf_frags.skb_free = nf_skb_free; | 726 | nf_frags.skb_free = nf_skb_free; |
754 | nf_frags.qsize = sizeof(struct nf_ct_frag6_queue); | 727 | nf_frags.qsize = sizeof(struct nf_ct_frag6_queue); |
728 | nf_frags.equal = ip6_frag_equal; | ||
755 | inet_frags_init(&nf_frags); | 729 | inet_frags_init(&nf_frags); |
756 | 730 | ||
757 | return 0; | 731 | return 0; |
diff --git a/net/ipv6/reassembly.c b/net/ipv6/reassembly.c index 0a1bf43bd489..73ea204eaa6f 100644 --- a/net/ipv6/reassembly.c +++ b/net/ipv6/reassembly.c | |||
@@ -143,6 +143,18 @@ static unsigned int ip6_hashfn(struct inet_frag_queue *q) | |||
143 | return ip6qhashfn(fq->id, &fq->saddr, &fq->daddr); | 143 | return ip6qhashfn(fq->id, &fq->saddr, &fq->daddr); |
144 | } | 144 | } |
145 | 145 | ||
146 | int ip6_frag_equal(struct inet_frag_queue *q1, struct inet_frag_queue *q2) | ||
147 | { | ||
148 | struct frag_queue *fq1, *fq2; | ||
149 | |||
150 | fq1 = container_of(q1, struct frag_queue, q); | ||
151 | fq2 = container_of(q2, struct frag_queue, q); | ||
152 | return (fq1->id == fq2->id && | ||
153 | ipv6_addr_equal(&fq2->saddr, &fq1->saddr) && | ||
154 | ipv6_addr_equal(&fq2->daddr, &fq1->daddr)); | ||
155 | } | ||
156 | EXPORT_SYMBOL(ip6_frag_equal); | ||
157 | |||
146 | /* Memory Tracking Functions. */ | 158 | /* Memory Tracking Functions. */ |
147 | static inline void frag_kfree_skb(struct sk_buff *skb, int *work) | 159 | static inline void frag_kfree_skb(struct sk_buff *skb, int *work) |
148 | { | 160 | { |
@@ -236,37 +248,10 @@ out: | |||
236 | static struct frag_queue *ip6_frag_intern(struct frag_queue *fq_in, | 248 | static struct frag_queue *ip6_frag_intern(struct frag_queue *fq_in, |
237 | unsigned int hash) | 249 | unsigned int hash) |
238 | { | 250 | { |
239 | struct frag_queue *fq; | 251 | struct inet_frag_queue *q; |
240 | #ifdef CONFIG_SMP | ||
241 | struct hlist_node *n; | ||
242 | #endif | ||
243 | |||
244 | write_lock(&ip6_frags.lock); | ||
245 | #ifdef CONFIG_SMP | ||
246 | hlist_for_each_entry(fq, n, &ip6_frags.hash[hash], q.list) { | ||
247 | if (fq->id == fq_in->id && | ||
248 | ipv6_addr_equal(&fq_in->saddr, &fq->saddr) && | ||
249 | ipv6_addr_equal(&fq_in->daddr, &fq->daddr)) { | ||
250 | atomic_inc(&fq->q.refcnt); | ||
251 | write_unlock(&ip6_frags.lock); | ||
252 | fq_in->q.last_in |= COMPLETE; | ||
253 | fq_put(fq_in); | ||
254 | return fq; | ||
255 | } | ||
256 | } | ||
257 | #endif | ||
258 | fq = fq_in; | ||
259 | |||
260 | if (!mod_timer(&fq->q.timer, jiffies + ip6_frags_ctl.timeout)) | ||
261 | atomic_inc(&fq->q.refcnt); | ||
262 | 252 | ||
263 | atomic_inc(&fq->q.refcnt); | 253 | q = inet_frag_intern(&fq_in->q, &ip6_frags, hash); |
264 | hlist_add_head(&fq->q.list, &ip6_frags.hash[hash]); | 254 | return container_of(q, struct frag_queue, q); |
265 | INIT_LIST_HEAD(&fq->q.lru_list); | ||
266 | list_add_tail(&fq->q.lru_list, &ip6_frags.lru_list); | ||
267 | ip6_frags.nqueues++; | ||
268 | write_unlock(&ip6_frags.lock); | ||
269 | return fq; | ||
270 | } | 255 | } |
271 | 256 | ||
272 | 257 | ||
@@ -699,5 +684,6 @@ void __init ipv6_frag_init(void) | |||
699 | ip6_frags.destructor = ip6_frag_free; | 684 | ip6_frags.destructor = ip6_frag_free; |
700 | ip6_frags.skb_free = NULL; | 685 | ip6_frags.skb_free = NULL; |
701 | ip6_frags.qsize = sizeof(struct frag_queue); | 686 | ip6_frags.qsize = sizeof(struct frag_queue); |
687 | ip6_frags.equal = ip6_frag_equal; | ||
702 | inet_frags_init(&ip6_frags); | 688 | inet_frags_init(&ip6_frags); |
703 | } | 689 | } |