* [PATCH 1/2] act_mirred: cleanup
@ 2009-11-16 8:33 Changli Gao
2009-11-16 9:24 ` jamal
0 siblings, 1 reply; 5+ messages in thread
From: Changli Gao @ 2009-11-16 8:33 UTC (permalink / raw)
To: Jamal Hadi Salim; +Cc: David S. Miller, Stephen Hemminger, netdev
act_mirred: cleanup
1. don't let go back using goto.
2. don't call skb_act_clone() until it is necessary.
3. one exit of the critical context.
Signed-off-by: Changli Gao <xiaosuo@gmail.com>
----
net/sched/act_mirred.c | 59
+++++++++++++++++++++++++++----------------------
1 file changed, 33 insertions(+), 26 deletions(-)
diff --git a/net/sched/act_mirred.c b/net/sched/act_mirred.c
index b9aaab4..b812c20 100644
--- a/net/sched/act_mirred.c
+++ b/net/sched/act_mirred.c
@@ -148,47 +148,39 @@ static int tcf_mirred(struct sk_buff *skb,
struct tc_action *a,
{
struct tcf_mirred *m = a->priv;
struct net_device *dev;
- struct sk_buff *skb2 = NULL;
- u32 at = G_TC_AT(skb->tc_verd);
+ struct sk_buff *skb2;
+ u32 at;
+ int retval, err = 1;
spin_lock(&m->tcf_lock);
-
- dev = m->tcfm_dev;
m->tcf_tm.lastuse = jiffies;
+ if (m->tcfm_eaction != TCA_EGRESS_MIRROR &&
+ m->tcfm_eaction != TCA_EGRESS_REDIR) {
+ if (net_ratelimit())
+ printk("tcf_mirred unknown action %d\n",
+ m->tcfm_eaction);
+ goto out;
+ }
- if (!(dev->flags&IFF_UP) ) {
+ dev = m->tcfm_dev;
+ if (!(dev->flags & IFF_UP)) {
if (net_ratelimit())
printk("mirred to Houston: device %s is gone!\n",
dev->name);
-bad_mirred:
- if (skb2 != NULL)
- kfree_skb(skb2);
- m->tcf_qstats.overlimits++;
- m->tcf_bstats.bytes += qdisc_pkt_len(skb);
- m->tcf_bstats.packets++;
- spin_unlock(&m->tcf_lock);
- /* should we be asking for packet to be dropped?
- * may make sense for redirect case only
- */
- return TC_ACT_SHOT;
+ goto out;
}
skb2 = skb_act_clone(skb, GFP_ATOMIC);
if (skb2 == NULL)
- goto bad_mirred;
- if (m->tcfm_eaction != TCA_EGRESS_MIRROR &&
- m->tcfm_eaction != TCA_EGRESS_REDIR) {
- if (net_ratelimit())
- printk("tcf_mirred unknown action %d\n",
- m->tcfm_eaction);
- goto bad_mirred;
- }
+ goto out;
m->tcf_bstats.bytes += qdisc_pkt_len(skb2);
m->tcf_bstats.packets++;
- if (!(at & AT_EGRESS))
+ at = G_TC_AT(skb->tc_verd);
+ if (!(at & AT_EGRESS)) {
if (m->tcfm_ok_push)
skb_push(skb2, skb2->dev->hard_header_len);
+ }
/* mirror is always swallowed */
if (m->tcfm_eaction != TCA_EGRESS_MIRROR)
@@ -197,8 +189,23 @@ bad_mirred:
skb2->dev = dev;
skb2->iif = skb->dev->ifindex;
dev_queue_xmit(skb2);
+ err = 0;
+
+out:
+ if (err) {
+ m->tcf_qstats.overlimits++;
+ m->tcf_bstats.bytes += qdisc_pkt_len(skb);
+ m->tcf_bstats.packets++;
+ /* should we be asking for packet to be dropped?
+ * may make sense for redirect case only
+ */
+ retval = TC_ACT_SHOT;
+ } else {
+ retval = m->tcf_action;
+ }
spin_unlock(&m->tcf_lock);
- return m->tcf_action;
+
+ return retval;
}
static int tcf_mirred_dump(struct sk_buff *skb, struct tc_action *a,
int bind, int ref)
^ permalink raw reply related [flat|nested] 5+ messages in thread* Re: [PATCH 1/2] act_mirred: cleanup
2009-11-16 8:33 [PATCH 1/2] act_mirred: cleanup Changli Gao
@ 2009-11-16 9:24 ` jamal
2009-11-16 10:48 ` David Miller
0 siblings, 1 reply; 5+ messages in thread
From: jamal @ 2009-11-16 9:24 UTC (permalink / raw)
To: Changli Gao; +Cc: David S. Miller, Stephen Hemminger, netdev
On Mon, 2009-11-16 at 16:33 +0800, Changli Gao wrote:
> act_mirred: cleanup
>
> 1. don't let go back using goto.
> 2. don't call skb_act_clone() until it is necessary.
> 3. one exit of the critical context.
>
> Signed-off-by: Changli Gao <xiaosuo@gmail.com>
Signed-off-by: Jamal Hadi Salim <hadi@cyberus.ca>
cheers,
jamal
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH 1/2] act_mirred: cleanup
2009-11-16 9:24 ` jamal
@ 2009-11-16 10:48 ` David Miller
2009-11-17 5:48 ` Changli Gao
0 siblings, 1 reply; 5+ messages in thread
From: David Miller @ 2009-11-16 10:48 UTC (permalink / raw)
To: hadi; +Cc: xiaosuo, shemminger, netdev
From: jamal <hadi@cyberus.ca>
Date: Mon, 16 Nov 2009 04:24:39 -0500
> On Mon, 2009-11-16 at 16:33 +0800, Changli Gao wrote:
>> act_mirred: cleanup
>>
>> 1. don't let go back using goto.
>> 2. don't call skb_act_clone() until it is necessary.
>> 3. one exit of the critical context.
>>
>> Signed-off-by: Changli Gao <xiaosuo@gmail.com>
>
> Signed-off-by: Jamal Hadi Salim <hadi@cyberus.ca>
Applied.
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH 1/2] act_mirred: cleanup
2009-11-16 10:48 ` David Miller
@ 2009-11-17 5:48 ` Changli Gao
2009-11-17 12:15 ` David Miller
0 siblings, 1 reply; 5+ messages in thread
From: Changli Gao @ 2009-11-17 5:48 UTC (permalink / raw)
To: David Miller; +Cc: hadi, shemminger, netdev
[-- Attachment #1: Type: text/plain, Size: 602 bytes --]
On Mon, Nov 16, 2009 at 6:48 PM, David Miller <davem@davemloft.net> wrote:
> From: jamal <hadi@cyberus.ca>
> Date: Mon, 16 Nov 2009 04:24:39 -0500
>
>> On Mon, 2009-11-16 at 16:33 +0800, Changli Gao wrote:
>>> act_mirred: cleanup
>>>
>>> 1. don't let go back using goto.
>>> 2. don't call skb_act_clone() until it is necessary.
>>> 3. one exit of the critical context.
>>>
>>> Signed-off-by: Changli Gao <xiaosuo@gmail.com>
>>
>> Signed-off-by: Jamal Hadi Salim <hadi@cyberus.ca>
>
> Applied.
>
Patch is resubmitted as attachment.
--
Regards,
Changli Gao(xiaosuo@gmail.com)
[-- Attachment #2: act_mirred_cleanup.diff --]
[-- Type: application/octet-stream, Size: 2433 bytes --]
diff --git a/net/sched/act_mirred.c b/net/sched/act_mirred.c
index b9aaab4..b812c20 100644
--- a/net/sched/act_mirred.c
+++ b/net/sched/act_mirred.c
@@ -148,47 +148,39 @@ static int tcf_mirred(struct sk_buff *skb, struct tc_action *a,
{
struct tcf_mirred *m = a->priv;
struct net_device *dev;
- struct sk_buff *skb2 = NULL;
- u32 at = G_TC_AT(skb->tc_verd);
+ struct sk_buff *skb2;
+ u32 at;
+ int retval, err = 1;
spin_lock(&m->tcf_lock);
-
- dev = m->tcfm_dev;
m->tcf_tm.lastuse = jiffies;
+ if (m->tcfm_eaction != TCA_EGRESS_MIRROR &&
+ m->tcfm_eaction != TCA_EGRESS_REDIR) {
+ if (net_ratelimit())
+ printk("tcf_mirred unknown action %d\n",
+ m->tcfm_eaction);
+ goto out;
+ }
- if (!(dev->flags&IFF_UP) ) {
+ dev = m->tcfm_dev;
+ if (!(dev->flags & IFF_UP)) {
if (net_ratelimit())
printk("mirred to Houston: device %s is gone!\n",
dev->name);
-bad_mirred:
- if (skb2 != NULL)
- kfree_skb(skb2);
- m->tcf_qstats.overlimits++;
- m->tcf_bstats.bytes += qdisc_pkt_len(skb);
- m->tcf_bstats.packets++;
- spin_unlock(&m->tcf_lock);
- /* should we be asking for packet to be dropped?
- * may make sense for redirect case only
- */
- return TC_ACT_SHOT;
+ goto out;
}
skb2 = skb_act_clone(skb, GFP_ATOMIC);
if (skb2 == NULL)
- goto bad_mirred;
- if (m->tcfm_eaction != TCA_EGRESS_MIRROR &&
- m->tcfm_eaction != TCA_EGRESS_REDIR) {
- if (net_ratelimit())
- printk("tcf_mirred unknown action %d\n",
- m->tcfm_eaction);
- goto bad_mirred;
- }
+ goto out;
m->tcf_bstats.bytes += qdisc_pkt_len(skb2);
m->tcf_bstats.packets++;
- if (!(at & AT_EGRESS))
+ at = G_TC_AT(skb->tc_verd);
+ if (!(at & AT_EGRESS)) {
if (m->tcfm_ok_push)
skb_push(skb2, skb2->dev->hard_header_len);
+ }
/* mirror is always swallowed */
if (m->tcfm_eaction != TCA_EGRESS_MIRROR)
@@ -197,8 +189,23 @@ bad_mirred:
skb2->dev = dev;
skb2->iif = skb->dev->ifindex;
dev_queue_xmit(skb2);
+ err = 0;
+
+out:
+ if (err) {
+ m->tcf_qstats.overlimits++;
+ m->tcf_bstats.bytes += qdisc_pkt_len(skb);
+ m->tcf_bstats.packets++;
+ /* should we be asking for packet to be dropped?
+ * may make sense for redirect case only
+ */
+ retval = TC_ACT_SHOT;
+ } else {
+ retval = m->tcf_action;
+ }
spin_unlock(&m->tcf_lock);
- return m->tcf_action;
+
+ return retval;
}
static int tcf_mirred_dump(struct sk_buff *skb, struct tc_action *a, int bind, int ref)
^ permalink raw reply related [flat|nested] 5+ messages in thread
end of thread, other threads:[~2009-11-17 12:15 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-11-16 8:33 [PATCH 1/2] act_mirred: cleanup Changli Gao
2009-11-16 9:24 ` jamal
2009-11-16 10:48 ` David Miller
2009-11-17 5:48 ` Changli Gao
2009-11-17 12:15 ` David Miller
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox