]> git.proxmox.com Git - mirror_ubuntu-disco-kernel.git/commitdiff
act_mirred: don't clone skb when skb isn't shared
authorChangli Gao <xiaosuo@gmail.com>
Thu, 24 Jun 2010 16:25:12 +0000 (16:25 +0000)
committerDavid S. Miller <davem@davemloft.net>
Tue, 29 Jun 2010 06:24:32 +0000 (23:24 -0700)
don't clone skb when skb isn't shared

When the tcf_action is TC_ACT_STOLEN, and the skb isn't shared, we don't need
to clone a new skb. As the skb will be freed after this function returns, we
can use it freely once we get a reference to it.

Signed-off-by: Changli Gao <xiaosuo@gmail.com>
----
 include/net/sch_generic.h |   11 +++++++++--
 net/sched/act_mirred.c    |    6 +++---
 2 files changed, 12 insertions(+), 5 deletions(-)
Signed-off-by: Jamal Hadi Salim <hadi@cyberus.ca>
Signed-off-by: David S. Miller <davem@davemloft.net>
include/net/sch_generic.h
net/sched/act_mirred.c

index b35301b0c7b6e5b6002d351d8edabf439d23bbed..977ec06ed0c7962174d9543f9c8cde0ee561c478 100644 (file)
@@ -594,9 +594,16 @@ static inline u32 qdisc_l2t(struct qdisc_rate_table* rtab, unsigned int pktlen)
 }
 
 #ifdef CONFIG_NET_CLS_ACT
-static inline struct sk_buff *skb_act_clone(struct sk_buff *skb, gfp_t gfp_mask)
+static inline struct sk_buff *skb_act_clone(struct sk_buff *skb, gfp_t gfp_mask,
+                                           int action)
 {
-       struct sk_buff *n = skb_clone(skb, gfp_mask);
+       struct sk_buff *n;
+
+       if ((action == TC_ACT_STOLEN || action == TC_ACT_QUEUED) &&
+           !skb_shared(skb))
+               n = skb_get(skb);
+       else
+               n = skb_clone(skb, gfp_mask);
 
        if (n) {
                n->tc_verd = SET_TC_VERD(n->tc_verd, 0);
index c0b6863e3b87dbe91679638b83a169f099ab887f..2e9a7b91aa10cc0f5bbcb67d4a9b630d1f3f0cc0 100644 (file)
@@ -169,13 +169,13 @@ static int tcf_mirred(struct sk_buff *skb, struct tc_action *a,
                goto out;
        }
 
-       skb2 = skb_act_clone(skb, GFP_ATOMIC);
+       at = G_TC_AT(skb->tc_verd);
+       skb2 = skb_act_clone(skb, GFP_ATOMIC, m->tcf_action);
        if (skb2 == NULL)
                goto out;
 
        m->tcf_bstats.bytes += qdisc_pkt_len(skb2);
        m->tcf_bstats.packets++;
-       at = G_TC_AT(skb->tc_verd);
        if (!(at & AT_EGRESS)) {
                if (m->tcfm_ok_push)
                        skb_push(skb2, skb2->dev->hard_header_len);
@@ -185,8 +185,8 @@ static int tcf_mirred(struct sk_buff *skb, struct tc_action *a,
        if (m->tcfm_eaction != TCA_EGRESS_MIRROR)
                skb2->tc_verd = SET_TC_FROM(skb2->tc_verd, at);
 
-       skb2->dev = dev;
        skb2->skb_iif = skb->dev->ifindex;
+       skb2->dev = dev;
        dev_queue_xmit(skb2);
        err = 0;