aboutsummaryrefslogtreecommitdiffstats
path: root/net
diff options
context:
space:
mode:
authorPavel Emelyanov <xemul@openvz.org>2007-10-17 22:44:34 -0400
committerDavid S. Miller <davem@davemloft.net>2007-10-17 22:44:34 -0400
commit2588fe1d782f1686847493ad643157d5d10bf602 (patch)
tree7513851819330d4ff6aadc9f76b1b45bc03f8f82 /net
parentfd9e63544cac30a34c951f0ec958038f0529e244 (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')
-rw-r--r--net/ipv4/inet_fragment.c37
-rw-r--r--net/ipv4/ip_fragment.c54
-rw-r--r--net/ipv6/netfilter/nf_conntrack_reasm.c34
-rw-r--r--net/ipv6/reassembly.c46
4 files changed, 75 insertions, 96 deletions
diff --git a/net/ipv4/inet_fragment.c b/net/ipv4/inet_fragment.c
index 484cf512858f..15054eb3d4b9 100644
--- a/net/ipv4/inet_fragment.c
+++ b/net/ipv4/inet_fragment.c
@@ -172,3 +172,40 @@ int inet_frag_evictor(struct inet_frags *f)
172 return evicted; 172 return evicted;
173} 173}
174EXPORT_SYMBOL(inet_frag_evictor); 174EXPORT_SYMBOL(inet_frag_evictor);
175
176struct inet_frag_queue *inet_frag_intern(struct inet_frag_queue *qp_in,
177 struct inet_frags *f, unsigned int hash)
178{
179 struct inet_frag_queue *qp;
180#ifdef CONFIG_SMP
181 struct hlist_node *n;
182#endif
183
184 write_lock(&f->lock);
185#ifdef CONFIG_SMP
186 /* With SMP race we have to recheck hash table, because
187 * such entry could be created on other cpu, while we
188 * promoted read lock to write lock.
189 */
190 hlist_for_each_entry(qp, n, &f->hash[hash], list) {
191 if (f->equal(qp, qp_in)) {
192 atomic_inc(&qp->refcnt);
193 write_unlock(&f->lock);
194 qp_in->last_in |= COMPLETE;
195 inet_frag_put(qp_in, f);
196 return qp;
197 }
198 }
199#endif
200 qp = qp_in;
201 if (!mod_timer(&qp->timer, jiffies + f->ctl->timeout))
202 atomic_inc(&qp->refcnt);
203
204 atomic_inc(&qp->refcnt);
205 hlist_add_head(&qp->list, &f->hash[hash]);
206 list_add_tail(&qp->lru_list, &f->lru_list);
207 f->nqueues++;
208 write_unlock(&f->lock);
209 return qp;
210}
211EXPORT_SYMBOL(inet_frag_intern);
diff --git a/net/ipv4/ip_fragment.c b/net/ipv4/ip_fragment.c
index d12a18b8f568..4b1bbbee22c5 100644
--- a/net/ipv4/ip_fragment.c
+++ b/net/ipv4/ip_fragment.c
@@ -123,6 +123,20 @@ static unsigned int ip4_hashfn(struct inet_frag_queue *q)
123 return ipqhashfn(ipq->id, ipq->saddr, ipq->daddr, ipq->protocol); 123 return ipqhashfn(ipq->id, ipq->saddr, ipq->daddr, ipq->protocol);
124} 124}
125 125
126static int ip4_frag_equal(struct inet_frag_queue *q1,
127 struct inet_frag_queue *q2)
128{
129 struct ipq *qp1, *qp2;
130
131 qp1 = container_of(q1, struct ipq, q);
132 qp2 = container_of(q2, struct ipq, q);
133 return (qp1->id == qp2->id &&
134 qp1->saddr == qp2->saddr &&
135 qp1->daddr == qp2->daddr &&
136 qp1->protocol == qp2->protocol &&
137 qp1->user == qp2->user);
138}
139
126/* Memory Tracking Functions. */ 140/* Memory Tracking Functions. */
127static __inline__ void frag_kfree_skb(struct sk_buff *skb, int *work) 141static __inline__ void frag_kfree_skb(struct sk_buff *skb, int *work)
128{ 142{
@@ -214,43 +228,10 @@ out:
214 228
215static struct ipq *ip_frag_intern(struct ipq *qp_in, unsigned int hash) 229static struct ipq *ip_frag_intern(struct ipq *qp_in, unsigned int hash)
216{ 230{
217 struct ipq *qp; 231 struct inet_frag_queue *q;
218#ifdef CONFIG_SMP
219 struct hlist_node *n;
220#endif
221 232
222 write_lock(&ip4_frags.lock); 233 q = inet_frag_intern(&qp_in->q, &ip4_frags, hash);
223#ifdef CONFIG_SMP 234 return container_of(q, struct ipq, q);
224 /* With SMP race we have to recheck hash table, because
225 * such entry could be created on other cpu, while we
226 * promoted read lock to write lock.
227 */
228 hlist_for_each_entry(qp, n, &ip4_frags.hash[hash], q.list) {
229 if (qp->id == qp_in->id &&
230 qp->saddr == qp_in->saddr &&
231 qp->daddr == qp_in->daddr &&
232 qp->protocol == qp_in->protocol &&
233 qp->user == qp_in->user) {
234 atomic_inc(&qp->q.refcnt);
235 write_unlock(&ip4_frags.lock);
236 qp_in->q.last_in |= COMPLETE;
237 ipq_put(qp_in);
238 return qp;
239 }
240 }
241#endif
242 qp = qp_in;
243
244 if (!mod_timer(&qp->q.timer, jiffies + ip4_frags_ctl.timeout))
245 atomic_inc(&qp->q.refcnt);
246
247 atomic_inc(&qp->q.refcnt);
248 hlist_add_head(&qp->q.list, &ip4_frags.hash[hash]);
249 INIT_LIST_HEAD(&qp->q.lru_list);
250 list_add_tail(&qp->q.lru_list, &ip4_frags.lru_list);
251 ip4_frags.nqueues++;
252 write_unlock(&ip4_frags.lock);
253 return qp;
254} 235}
255 236
256/* Add an entry to the 'ipq' queue for a newly received IP datagram. */ 237/* Add an entry to the 'ipq' queue for a newly received IP datagram. */
@@ -671,6 +652,7 @@ void __init ipfrag_init(void)
671 ip4_frags.destructor = ip4_frag_free; 652 ip4_frags.destructor = ip4_frag_free;
672 ip4_frags.skb_free = NULL; 653 ip4_frags.skb_free = NULL;
673 ip4_frags.qsize = sizeof(struct ipq); 654 ip4_frags.qsize = sizeof(struct ipq);
655 ip4_frags.equal = ip4_frag_equal;
674 inet_frags_init(&ip4_frags); 656 inet_frags_init(&ip4_frags);
675} 657}
676 658
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:
187static struct nf_ct_frag6_queue *nf_ct_frag6_intern(unsigned int hash, 187static 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
146int 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}
156EXPORT_SYMBOL(ip6_frag_equal);
157
146/* Memory Tracking Functions. */ 158/* Memory Tracking Functions. */
147static inline void frag_kfree_skb(struct sk_buff *skb, int *work) 159static inline void frag_kfree_skb(struct sk_buff *skb, int *work)
148{ 160{
@@ -236,37 +248,10 @@ out:
236static struct frag_queue *ip6_frag_intern(struct frag_queue *fq_in, 248static 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}