Skip to content

Commit 5b8784a

Browse files
azhou-niciradavem330
authored andcommitted
openvswitch: Simplify do_execute_actions().
do_execute_actions() implements a worthwhile optimization: in case an output action is the last action in an action list, skb_clone() can be avoided by outputing the current skb. However, the implementation is more complicated than necessary. This patch simplify this logic. Signed-off-by: Andy Zhou <azhou@ovn.org> Acked-by: Pravin B Shelar <pshelar@ovn.org> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent 6d45408 commit 5b8784a

1 file changed

Lines changed: 20 additions & 22 deletions

File tree

‎net/openvswitch/actions.c‎

Lines changed: 20 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1141,33 +1141,35 @@ static int do_execute_actions(struct datapath *dp, struct sk_buff *skb,
11411141
struct sw_flow_key *key,
11421142
const struct nlattr *attr, int len)
11431143
{
1144-
/* Every output action needs a separate clone of 'skb', but the common
1145-
* case is just a single output action, so that doing a clone and
1146-
* then freeing the original skbuff is wasteful. So the following code
1147-
* is slightly obscure just to avoid that.
1148-
*/
1149-
int prev_port = -1;
11501144
const struct nlattr *a;
11511145
int rem;
11521146

11531147
for (a = attr, rem = len; rem > 0;
11541148
a = nla_next(a, &rem)) {
11551149
int err = 0;
11561150

1157-
if (unlikely(prev_port != -1)) {
1158-
struct sk_buff *out_skb = skb_clone(skb, GFP_ATOMIC);
1159-
1160-
if (out_skb)
1161-
do_output(dp, out_skb, prev_port, key);
1151+
switch (nla_type(a)) {
1152+
case OVS_ACTION_ATTR_OUTPUT: {
1153+
int port = nla_get_u32(a);
1154+
struct sk_buff *clone;
1155+
1156+
/* Every output action needs a separate clone
1157+
* of 'skb', In case the output action is the
1158+
* last action, cloning can be avoided.
1159+
*/
1160+
if (nla_is_last(a, rem)) {
1161+
do_output(dp, skb, port, key);
1162+
/* 'skb' has been used for output.
1163+
*/
1164+
return 0;
1165+
}
11621166

1167+
clone = skb_clone(skb, GFP_ATOMIC);
1168+
if (clone)
1169+
do_output(dp, clone, port, key);
11631170
OVS_CB(skb)->cutlen = 0;
1164-
prev_port = -1;
1165-
}
1166-
1167-
switch (nla_type(a)) {
1168-
case OVS_ACTION_ATTR_OUTPUT:
1169-
prev_port = nla_get_u32(a);
11701171
break;
1172+
}
11711173

11721174
case OVS_ACTION_ATTR_TRUNC: {
11731175
struct ovs_action_trunc *trunc = nla_data(a);
@@ -1257,11 +1259,7 @@ static int do_execute_actions(struct datapath *dp, struct sk_buff *skb,
12571259
}
12581260
}
12591261

1260-
if (prev_port != -1)
1261-
do_output(dp, skb, prev_port, key);
1262-
else
1263-
consume_skb(skb);
1264-
1262+
consume_skb(skb);
12651263
return 0;
12661264
}
12671265

0 commit comments

Comments
 (0)