aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHerbert Xu <herbert@gondor.apana.org.au>2009-06-21 22:25:25 -0400
committerDavid S. Miller <davem@davemloft.net>2009-06-23 19:36:25 -0400
commitd55d87fdff8252d0e2f7c28c2d443aee17e9d70f (patch)
treea4bfb0a47525672c690b63e85bf3f47f4ab014f7
parentd5fdd6babcfc2b0e6a8da1acf492a69fb54b4c47 (diff)
net: Move rx skb_orphan call to where needed
In order to get the tun driver to account packets, we need to be able to receive packets with destructors set. To be on the safe side, I added an skb_orphan call for all protocols by default since some of them (IP in particular) cannot handle receiving packets destructors properly. Now it seems that at least one protocol (CAN) expects to be able to pass skb->sk through the rx path without getting clobbered. So this patch attempts to fix this properly by moving the skb_orphan call to where it's actually needed. In particular, I've added it to skb_set_owner_[rw] which is what most users of skb->destructor call. This is actually an improvement for tun too since it means that we only give back the amount charged to the socket when the skb is passed to another socket that will also be charged accordingly. Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au> Tested-by: Oliver Hartkopp <olver@hartkopp.net> Signed-off-by: David S. Miller <davem@davemloft.net>
-rw-r--r--include/net/sctp/sctp.h1
-rw-r--r--include/net/sock.h2
-rw-r--r--net/ax25/ax25_in.c3
-rw-r--r--net/core/dev.c2
-rw-r--r--net/irda/af_irda.c3
-rw-r--r--net/irda/ircomm/ircomm_lmp.c1
6 files changed, 5 insertions, 7 deletions
diff --git a/include/net/sctp/sctp.h b/include/net/sctp/sctp.h
index 9f80a7668289..d16a304cbed4 100644
--- a/include/net/sctp/sctp.h
+++ b/include/net/sctp/sctp.h
@@ -448,6 +448,7 @@ static inline void sctp_skb_set_owner_r(struct sk_buff *skb, struct sock *sk)
448{ 448{
449 struct sctp_ulpevent *event = sctp_skb2event(skb); 449 struct sctp_ulpevent *event = sctp_skb2event(skb);
450 450
451 skb_orphan(skb);
451 skb->sk = sk; 452 skb->sk = sk;
452 skb->destructor = sctp_sock_rfree; 453 skb->destructor = sctp_sock_rfree;
453 atomic_add(event->rmem_len, &sk->sk_rmem_alloc); 454 atomic_add(event->rmem_len, &sk->sk_rmem_alloc);
diff --git a/include/net/sock.h b/include/net/sock.h
index 570c7a12b54e..7f5c41cc45a9 100644
--- a/include/net/sock.h
+++ b/include/net/sock.h
@@ -1250,6 +1250,7 @@ static inline int sk_has_allocations(const struct sock *sk)
1250 1250
1251static inline void skb_set_owner_w(struct sk_buff *skb, struct sock *sk) 1251static inline void skb_set_owner_w(struct sk_buff *skb, struct sock *sk)
1252{ 1252{
1253 skb_orphan(skb);
1253 skb->sk = sk; 1254 skb->sk = sk;
1254 skb->destructor = sock_wfree; 1255 skb->destructor = sock_wfree;
1255 /* 1256 /*
@@ -1262,6 +1263,7 @@ static inline void skb_set_owner_w(struct sk_buff *skb, struct sock *sk)
1262 1263
1263static inline void skb_set_owner_r(struct sk_buff *skb, struct sock *sk) 1264static inline void skb_set_owner_r(struct sk_buff *skb, struct sock *sk)
1264{ 1265{
1266 skb_orphan(skb);
1265 skb->sk = sk; 1267 skb->sk = sk;
1266 skb->destructor = sock_rfree; 1268 skb->destructor = sock_rfree;
1267 atomic_add(skb->truesize, &sk->sk_rmem_alloc); 1269 atomic_add(skb->truesize, &sk->sk_rmem_alloc);
diff --git a/net/ax25/ax25_in.c b/net/ax25/ax25_in.c
index 5f1d2107a1dd..de56d3983de0 100644
--- a/net/ax25/ax25_in.c
+++ b/net/ax25/ax25_in.c
@@ -437,8 +437,7 @@ free:
437int ax25_kiss_rcv(struct sk_buff *skb, struct net_device *dev, 437int ax25_kiss_rcv(struct sk_buff *skb, struct net_device *dev,
438 struct packet_type *ptype, struct net_device *orig_dev) 438 struct packet_type *ptype, struct net_device *orig_dev)
439{ 439{
440 skb->sk = NULL; /* Initially we don't know who it's for */ 440 skb_orphan(skb);
441 skb->destructor = NULL; /* Who initializes this, dammit?! */
442 441
443 if (!net_eq(dev_net(dev), &init_net)) { 442 if (!net_eq(dev_net(dev), &init_net)) {
444 kfree_skb(skb); 443 kfree_skb(skb);
diff --git a/net/core/dev.c b/net/core/dev.c
index baf2dc13a34a..60b572812278 100644
--- a/net/core/dev.c
+++ b/net/core/dev.c
@@ -2310,8 +2310,6 @@ ncls:
2310 if (!skb) 2310 if (!skb)
2311 goto out; 2311 goto out;
2312 2312
2313 skb_orphan(skb);
2314
2315 type = skb->protocol; 2313 type = skb->protocol;
2316 list_for_each_entry_rcu(ptype, 2314 list_for_each_entry_rcu(ptype,
2317 &ptype_base[ntohs(type) & PTYPE_HASH_MASK], list) { 2315 &ptype_base[ntohs(type) & PTYPE_HASH_MASK], list) {
diff --git a/net/irda/af_irda.c b/net/irda/af_irda.c
index 5922febe25c4..cb762c8723ea 100644
--- a/net/irda/af_irda.c
+++ b/net/irda/af_irda.c
@@ -913,9 +913,6 @@ static int irda_accept(struct socket *sock, struct socket *newsock, int flags)
913 /* Clean up the original one to keep it in listen state */ 913 /* Clean up the original one to keep it in listen state */
914 irttp_listen(self->tsap); 914 irttp_listen(self->tsap);
915 915
916 /* Wow ! What is that ? Jean II */
917 skb->sk = NULL;
918 skb->destructor = NULL;
919 kfree_skb(skb); 916 kfree_skb(skb);
920 sk->sk_ack_backlog--; 917 sk->sk_ack_backlog--;
921 918
diff --git a/net/irda/ircomm/ircomm_lmp.c b/net/irda/ircomm/ircomm_lmp.c
index 67c99d20857f..7ba96618660e 100644
--- a/net/irda/ircomm/ircomm_lmp.c
+++ b/net/irda/ircomm/ircomm_lmp.c
@@ -196,6 +196,7 @@ static int ircomm_lmp_data_request(struct ircomm_cb *self,
196 /* Don't forget to refcount it - see ircomm_tty_do_softint() */ 196 /* Don't forget to refcount it - see ircomm_tty_do_softint() */
197 skb_get(skb); 197 skb_get(skb);
198 198
199 skb_orphan(skb);
199 skb->destructor = ircomm_lmp_flow_control; 200 skb->destructor = ircomm_lmp_flow_control;
200 201
201 if ((self->pkt_count++ > 7) && (self->flow_status == FLOW_START)) { 202 if ((self->pkt_count++ > 7) && (self->flow_status == FLOW_START)) {