aboutsummaryrefslogtreecommitdiffstats
path: root/net/ipv4
diff options
context:
space:
mode:
Diffstat (limited to 'net/ipv4')
-rw-r--r--net/ipv4/inet_fragment.c40
-rw-r--r--net/ipv4/ip_fragment.c39
2 files changed, 50 insertions, 29 deletions
diff --git a/net/ipv4/inet_fragment.c b/net/ipv4/inet_fragment.c
index ec10e05c6666..15fb2c4a36a7 100644
--- a/net/ipv4/inet_fragment.c
+++ b/net/ipv4/inet_fragment.c
@@ -17,6 +17,8 @@
17#include <linux/timer.h> 17#include <linux/timer.h>
18#include <linux/mm.h> 18#include <linux/mm.h>
19#include <linux/random.h> 19#include <linux/random.h>
20#include <linux/skbuff.h>
21#include <linux/rtnetlink.h>
20 22
21#include <net/inet_frag.h> 23#include <net/inet_frag.h>
22 24
@@ -100,3 +102,41 @@ void inet_frag_kill(struct inet_frag_queue *fq, struct inet_frags *f)
100} 102}
101 103
102EXPORT_SYMBOL(inet_frag_kill); 104EXPORT_SYMBOL(inet_frag_kill);
105
106static inline void frag_kfree_skb(struct inet_frags *f, struct sk_buff *skb,
107 int *work)
108{
109 if (work)
110 *work -= skb->truesize;
111
112 atomic_sub(skb->truesize, &f->mem);
113 if (f->skb_free)
114 f->skb_free(skb);
115 kfree_skb(skb);
116}
117
118void inet_frag_destroy(struct inet_frag_queue *q, struct inet_frags *f,
119 int *work)
120{
121 struct sk_buff *fp;
122
123 BUG_TRAP(q->last_in & COMPLETE);
124 BUG_TRAP(del_timer(&q->timer) == 0);
125
126 /* Release all fragment data. */
127 fp = q->fragments;
128 while (fp) {
129 struct sk_buff *xp = fp->next;
130
131 frag_kfree_skb(f, fp, work);
132 fp = xp;
133 }
134
135 if (work)
136 *work -= f->qsize;
137 atomic_sub(f->qsize, &f->mem);
138
139 f->destructor(q);
140
141}
142EXPORT_SYMBOL(inet_frag_destroy);
diff --git a/net/ipv4/ip_fragment.c b/net/ipv4/ip_fragment.c
index e231c248aea7..e8736632094a 100644
--- a/net/ipv4/ip_fragment.c
+++ b/net/ipv4/ip_fragment.c
@@ -132,11 +132,13 @@ static __inline__ void frag_kfree_skb(struct sk_buff *skb, int *work)
132 kfree_skb(skb); 132 kfree_skb(skb);
133} 133}
134 134
135static __inline__ void frag_free_queue(struct ipq *qp, int *work) 135static __inline__ void ip4_frag_free(struct inet_frag_queue *q)
136{ 136{
137 if (work) 137 struct ipq *qp;
138 *work -= sizeof(struct ipq); 138
139 atomic_sub(sizeof(struct ipq), &ip4_frags.mem); 139 qp = container_of(q, struct ipq, q);
140 if (qp->peer)
141 inet_putpeer(qp->peer);
140 kfree(qp); 142 kfree(qp);
141} 143}
142 144
@@ -153,34 +155,10 @@ static __inline__ struct ipq *frag_alloc_queue(void)
153 155
154/* Destruction primitives. */ 156/* Destruction primitives. */
155 157
156/* Complete destruction of ipq. */
157static void ip_frag_destroy(struct ipq *qp, int *work)
158{
159 struct sk_buff *fp;
160
161 BUG_TRAP(qp->q.last_in&COMPLETE);
162 BUG_TRAP(del_timer(&qp->q.timer) == 0);
163
164 if (qp->peer)
165 inet_putpeer(qp->peer);
166
167 /* Release all fragment data. */
168 fp = qp->q.fragments;
169 while (fp) {
170 struct sk_buff *xp = fp->next;
171
172 frag_kfree_skb(fp, work);
173 fp = xp;
174 }
175
176 /* Finally, release the queue descriptor itself. */
177 frag_free_queue(qp, work);
178}
179
180static __inline__ void ipq_put(struct ipq *ipq, int *work) 158static __inline__ void ipq_put(struct ipq *ipq, int *work)
181{ 159{
182 if (atomic_dec_and_test(&ipq->q.refcnt)) 160 if (atomic_dec_and_test(&ipq->q.refcnt))
183 ip_frag_destroy(ipq, work); 161 inet_frag_destroy(&ipq->q, &ip4_frags, work);
184} 162}
185 163
186/* Kill ipq entry. It is not destroyed immediately, 164/* Kill ipq entry. It is not destroyed immediately,
@@ -721,6 +699,9 @@ void __init ipfrag_init(void)
721{ 699{
722 ip4_frags.ctl = &ip4_frags_ctl; 700 ip4_frags.ctl = &ip4_frags_ctl;
723 ip4_frags.hashfn = ip4_hashfn; 701 ip4_frags.hashfn = ip4_hashfn;
702 ip4_frags.destructor = ip4_frag_free;
703 ip4_frags.skb_free = NULL;
704 ip4_frags.qsize = sizeof(struct ipq);
724 inet_frags_init(&ip4_frags); 705 inet_frags_init(&ip4_frags);
725} 706}
726 707