mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Eddy Tao <taoyuan_eddy@hotmail.com>
To: netdev@vger.kernel.org
Cc: Eddy Tao <taoyuan_eddy@hotmail.com>,
	Pravin B Shelar <pshelar@ovn.org>,
	"David S. Miller" <davem@davemloft.net>,
	Eric Dumazet <edumazet@google.com>,
	Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>,
	dev@openvswitch.org, linux-kernel@vger.kernel.org
Subject: [PATCH net-next v1 1/1] net: openvswitch: remove unnecessary vlan init in key_extract
Date: Tue,  7 Feb 2023 12:31:33 +0800	[thread overview]
Message-ID: <OS3P286MB229551D6705894E6578778DCF5DB9@OS3P286MB2295.JPNP286.PROD.OUTLOOK.COM> (raw)

Redefine clear_vlan to initialize one struct vlan_head
Define   clear_vlans to initialize key.eth.vlan and key.eth.cvlan
Calls the revised functions accurately

Reasoning:

For vlan packet, current code calls clear_vlan unnecessarily,
since parse_vlan sets key->eth.vlan and key->eth.cvlan correctly.
Only special case where return value <=0 needs inialization
certail key.eth.vlan or key.eth.cvlan specifically.

For none-vlan case, parse_vlan returns on the first parse_vlan_tag
which returns 0, in this case, calls clear_vlan

For MAC_PROTO_NONE, logic is intact after this revision

Signed-off-by: Eddy Tao <taoyuan_eddy@hotmail.com>
---
 net/openvswitch/flow.c | 24 ++++++++++++++++--------
 1 file changed, 16 insertions(+), 8 deletions(-)

diff --git a/net/openvswitch/flow.c b/net/openvswitch/flow.c
index e20d1a973417..30a90597cab6 100644
--- a/net/openvswitch/flow.c
+++ b/net/openvswitch/flow.c
@@ -480,12 +480,16 @@ static int parse_vlan_tag(struct sk_buff *skb, struct vlan_head *key_vh,
 	return 1;
 }
 
-static void clear_vlan(struct sw_flow_key *key)
+static inline void clear_vlan(struct vlan_head *vlan)
 {
-	key->eth.vlan.tci = 0;
-	key->eth.vlan.tpid = 0;
-	key->eth.cvlan.tci = 0;
-	key->eth.cvlan.tpid = 0;
+	vlan->tci = 0;
+	vlan->tpid = 0;
+}
+
+static inline void clear_vlans(struct sw_flow_key *key)
+{
+	clear_vlan(&key->eth.vlan);
+	clear_vlan(&key->eth.cvlan);
 }
 
 static int parse_vlan(struct sk_buff *skb, struct sw_flow_key *key)
@@ -498,14 +502,18 @@ static int parse_vlan(struct sk_buff *skb, struct sw_flow_key *key)
 	} else {
 		/* Parse outer vlan tag in the non-accelerated case. */
 		res = parse_vlan_tag(skb, &key->eth.vlan, true);
-		if (res <= 0)
+		if (res <= 0) {
+			clear_vlans(key);
 			return res;
+		}
 	}
 
 	/* Parse inner vlan tag. */
 	res = parse_vlan_tag(skb, &key->eth.cvlan, false);
-	if (res <= 0)
+	if (res <= 0) {
+		clear_vlan(&key->eth.cvlan);
 		return res;
+	}
 
 	return 0;
 }
@@ -918,8 +926,8 @@ static int key_extract(struct sk_buff *skb, struct sw_flow_key *key)
 	skb_reset_mac_header(skb);
 
 	/* Link layer. */
-	clear_vlan(key);
 	if (ovs_key_mac_proto(key) == MAC_PROTO_NONE) {
+		clear_vlans(key);
 		if (unlikely(eth_type_vlan(skb->protocol)))
 			return -EINVAL;
 
-- 
2.27.0


             reply	other threads:[~2023-02-07  4:32 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-02-07  4:31 Eddy Tao [this message]
2023-02-07 17:21 ` Simon Horman
2023-02-08  3:08   ` Eddy Tao

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=OS3P286MB229551D6705894E6578778DCF5DB9@OS3P286MB2295.JPNP286.PROD.OUTLOOK.COM \
    --to=taoyuan_eddy@hotmail.com \
    --cc=davem@davemloft.net \
    --cc=dev@openvswitch.org \
    --cc=edumazet@google.com \
    --cc=kuba@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=pshelar@ovn.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®