diff options
author | Pavel Emelyanov <xemul@openvz.org> | 2007-10-17 22:45:23 -0400 |
---|---|---|
committer | David S. Miller <davem@davemloft.net> | 2007-10-17 22:45:23 -0400 |
commit | e521db9d790aaa60ae8920e21cb7faedc280fc36 (patch) | |
tree | c58a138e9729eb61edaf697b9e259001fb92feb2 /net/ipv4 | |
parent | 2588fe1d782f1686847493ad643157d5d10bf602 (diff) |
[INET]: Consolidate xxx_frag_alloc()
Just perform the kzalloc() allocation and setup common
fields in the inet_frag_queue(). Then return the result
to the caller to initialize the rest.
The inet_frag_alloc() may return NULL, so check the
return value before doing the container_of(). This looks
ugly, but the xxx_frag_alloc() will be removed soon.
The xxx_expire() timer callbacks are patches,
because the argument is now the inet_frag_queue, not
the protocol specific queue.
Signed-off-by: Pavel Emelyanov <xemul@openvz.org>
Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'net/ipv4')
-rw-r--r-- | net/ipv4/inet_fragment.c | 17 | ||||
-rw-r--r-- | net/ipv4/ip_fragment.c | 20 |
2 files changed, 24 insertions, 13 deletions
diff --git a/net/ipv4/inet_fragment.c b/net/ipv4/inet_fragment.c index 15054eb3d4b9..57e15fa307dc 100644 --- a/net/ipv4/inet_fragment.c +++ b/net/ipv4/inet_fragment.c | |||
@@ -209,3 +209,20 @@ struct inet_frag_queue *inet_frag_intern(struct inet_frag_queue *qp_in, | |||
209 | return qp; | 209 | return qp; |
210 | } | 210 | } |
211 | EXPORT_SYMBOL(inet_frag_intern); | 211 | EXPORT_SYMBOL(inet_frag_intern); |
212 | |||
213 | struct inet_frag_queue *inet_frag_alloc(struct inet_frags *f) | ||
214 | { | ||
215 | struct inet_frag_queue *q; | ||
216 | |||
217 | q = kzalloc(f->qsize, GFP_ATOMIC); | ||
218 | if (q == NULL) | ||
219 | return NULL; | ||
220 | |||
221 | atomic_add(f->qsize, &f->mem); | ||
222 | setup_timer(&q->timer, f->frag_expire, (unsigned long)q); | ||
223 | spin_lock_init(&q->lock); | ||
224 | atomic_set(&q->refcnt, 1); | ||
225 | |||
226 | return q; | ||
227 | } | ||
228 | EXPORT_SYMBOL(inet_frag_alloc); | ||
diff --git a/net/ipv4/ip_fragment.c b/net/ipv4/ip_fragment.c index 4b1bbbee22c5..fc0d530df522 100644 --- a/net/ipv4/ip_fragment.c +++ b/net/ipv4/ip_fragment.c | |||
@@ -158,12 +158,10 @@ static __inline__ void ip4_frag_free(struct inet_frag_queue *q) | |||
158 | 158 | ||
159 | static __inline__ struct ipq *frag_alloc_queue(void) | 159 | static __inline__ struct ipq *frag_alloc_queue(void) |
160 | { | 160 | { |
161 | struct ipq *qp = kzalloc(sizeof(struct ipq), GFP_ATOMIC); | 161 | struct inet_frag_queue *q; |
162 | 162 | ||
163 | if (!qp) | 163 | q = inet_frag_alloc(&ip4_frags); |
164 | return NULL; | 164 | return q ? container_of(q, struct ipq, q) : NULL; |
165 | atomic_add(sizeof(struct ipq), &ip4_frags.mem); | ||
166 | return qp; | ||
167 | } | 165 | } |
168 | 166 | ||
169 | 167 | ||
@@ -199,7 +197,9 @@ static void ip_evictor(void) | |||
199 | */ | 197 | */ |
200 | static void ip_expire(unsigned long arg) | 198 | static void ip_expire(unsigned long arg) |
201 | { | 199 | { |
202 | struct ipq *qp = (struct ipq *) arg; | 200 | struct ipq *qp; |
201 | |||
202 | qp = container_of((struct inet_frag_queue *) arg, struct ipq, q); | ||
203 | 203 | ||
204 | spin_lock(&qp->q.lock); | 204 | spin_lock(&qp->q.lock); |
205 | 205 | ||
@@ -249,13 +249,6 @@ static struct ipq *ip_frag_create(struct iphdr *iph, u32 user, unsigned int h) | |||
249 | qp->user = user; | 249 | qp->user = user; |
250 | qp->peer = sysctl_ipfrag_max_dist ? inet_getpeer(iph->saddr, 1) : NULL; | 250 | qp->peer = sysctl_ipfrag_max_dist ? inet_getpeer(iph->saddr, 1) : NULL; |
251 | 251 | ||
252 | /* Initialize a timer for this entry. */ | ||
253 | init_timer(&qp->q.timer); | ||
254 | qp->q.timer.data = (unsigned long) qp; /* pointer to queue */ | ||
255 | qp->q.timer.function = ip_expire; /* expire function */ | ||
256 | spin_lock_init(&qp->q.lock); | ||
257 | atomic_set(&qp->q.refcnt, 1); | ||
258 | |||
259 | return ip_frag_intern(qp, h); | 252 | return ip_frag_intern(qp, h); |
260 | 253 | ||
261 | out_nomem: | 254 | out_nomem: |
@@ -653,6 +646,7 @@ void __init ipfrag_init(void) | |||
653 | ip4_frags.skb_free = NULL; | 646 | ip4_frags.skb_free = NULL; |
654 | ip4_frags.qsize = sizeof(struct ipq); | 647 | ip4_frags.qsize = sizeof(struct ipq); |
655 | ip4_frags.equal = ip4_frag_equal; | 648 | ip4_frags.equal = ip4_frag_equal; |
649 | ip4_frags.frag_expire = ip_expire; | ||
656 | inet_frags_init(&ip4_frags); | 650 | inet_frags_init(&ip4_frags); |
657 | } | 651 | } |
658 | 652 | ||