diff options
-rw-r--r-- | include/net/inet_frag.h | 4 | ||||
-rw-r--r-- | include/net/ipv6.h | 3 | ||||
-rw-r--r-- | net/ipv4/inet_fragment.c | 37 | ||||
-rw-r--r-- | net/ipv4/ip_fragment.c | 54 | ||||
-rw-r--r-- | net/ipv6/netfilter/nf_conntrack_reasm.c | 34 | ||||
-rw-r--r-- | net/ipv6/reassembly.c | 46 |
6 files changed, 82 insertions, 96 deletions
diff --git a/include/net/inet_frag.h b/include/net/inet_frag.h index 911c2cd02941..133e187fbc98 100644 --- a/include/net/inet_frag.h +++ b/include/net/inet_frag.h | |||
@@ -41,6 +41,8 @@ struct inet_frags { | |||
41 | unsigned int (*hashfn)(struct inet_frag_queue *); | 41 | unsigned int (*hashfn)(struct inet_frag_queue *); |
42 | void (*destructor)(struct inet_frag_queue *); | 42 | void (*destructor)(struct inet_frag_queue *); |
43 | void (*skb_free)(struct sk_buff *); | 43 | void (*skb_free)(struct sk_buff *); |
44 | int (*equal)(struct inet_frag_queue *q1, | ||
45 | struct inet_frag_queue *q2); | ||
44 | }; | 46 | }; |
45 | 47 | ||
46 | void inet_frags_init(struct inet_frags *); | 48 | void inet_frags_init(struct inet_frags *); |
@@ -50,6 +52,8 @@ void inet_frag_kill(struct inet_frag_queue *q, struct inet_frags *f); | |||
50 | void inet_frag_destroy(struct inet_frag_queue *q, | 52 | void inet_frag_destroy(struct inet_frag_queue *q, |
51 | struct inet_frags *f, int *work); | 53 | struct inet_frags *f, int *work); |
52 | int inet_frag_evictor(struct inet_frags *f); | 54 | int inet_frag_evictor(struct inet_frags *f); |
55 | struct inet_frag_queue *inet_frag_intern(struct inet_frag_queue *q, | ||
56 | struct inet_frags *f, unsigned int hash); | ||
53 | 57 | ||
54 | static inline void inet_frag_put(struct inet_frag_queue *q, struct inet_frags *f) | 58 | static inline void inet_frag_put(struct inet_frag_queue *q, struct inet_frags *f) |
55 | { | 59 | { |
diff --git a/include/net/ipv6.h b/include/net/ipv6.h index cc796cbc1b26..ff1269713462 100644 --- a/include/net/ipv6.h +++ b/include/net/ipv6.h | |||
@@ -377,6 +377,9 @@ static inline int ipv6_prefix_equal(const struct in6_addr *a1, | |||
377 | prefixlen); | 377 | prefixlen); |
378 | } | 378 | } |
379 | 379 | ||
380 | struct inet_frag_queue; | ||
381 | int ip6_frag_equal(struct inet_frag_queue *q1, struct inet_frag_queue *q2); | ||
382 | |||
380 | static inline int ipv6_addr_any(const struct in6_addr *a) | 383 | static inline int ipv6_addr_any(const struct in6_addr *a) |
381 | { | 384 | { |
382 | return ((a->s6_addr32[0] | a->s6_addr32[1] | | 385 | return ((a->s6_addr32[0] | a->s6_addr32[1] | |
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 | } |
174 | EXPORT_SYMBOL(inet_frag_evictor); | 174 | EXPORT_SYMBOL(inet_frag_evictor); |
175 | |||
176 | struct 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 | } | ||
211 | EXPORT_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 | ||
126 | static 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. */ |
127 | static __inline__ void frag_kfree_skb(struct sk_buff *skb, int *work) | 141 | static __inline__ void frag_kfree_skb(struct sk_buff *skb, int *work) |
128 | { | 142 | { |
@@ -214,43 +228,10 @@ out: | |||
214 | 228 | ||
215 | static struct ipq *ip_frag_intern(struct ipq *qp_in, unsigned int hash) | 229 | static 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: | |||
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 | } |