[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <655b6508443c52f04be2b2fe9a6a7f2470b47ad1.1559237173.git.dcaratti@redhat.com>
Date: Thu, 30 May 2019 20:03:41 +0200
From: Davide Caratti <dcaratti@...hat.com>
To: Eric Dumazet <eric.dumazet@...il.com>,
Cong Wang <xiyou.wangcong@...il.com>,
Jiri Pirko <jiri@...nulli.us>,
Jamal Hadi Salim <jhs@...atatu.com>,
"David S . Miller" <davem@...emloft.net>, netdev@...r.kernel.org
Cc: shuali@...hat.com, Eli Britstein <elibr@...lanox.com>
Subject: [PATCH net v2 1/3] net/sched: act_csum: pull all VLAN headers before checksumming
TC 'csum' action needs to read the packets' ethertype. In case the value
is encoded in unstripped/nested VLAN headers, call pskb_may_pull() to be
sure that all tags are in the linear part of skb. While at it, move this
code in a helper function: other TC actions (like 'pedit' and 'skbedit')
might need to read the innermost ethertype.
Fixes: 2ecba2d1e45b ("net: sched: act_csum: Fix csum calc for tagged packets")
CC: Eli Britstein <elibr@...lanox.com>
CC: Li Shuang <shuali@...hat.com>
Suggested-by: Eric Dumazet <eric.dumazet@...il.com>
Signed-off-by: Davide Caratti <dcaratti@...hat.com>
---
include/net/pkt_cls.h | 21 +++++++++++++++++++++
net/sched/act_csum.c | 14 ++------------
2 files changed, 23 insertions(+), 12 deletions(-)
diff --git a/include/net/pkt_cls.h b/include/net/pkt_cls.h
index 514e3c80ecc1..0215dfbda9ac 100644
--- a/include/net/pkt_cls.h
+++ b/include/net/pkt_cls.h
@@ -953,4 +953,25 @@ struct tc_root_qopt_offload {
bool ingress;
};
+static inline int tc_skb_pull_vlans(struct sk_buff *skb,
+ unsigned int *hdr_count,
+ __be16 *proto)
+{
+ if (skb_vlan_tag_present(skb))
+ *proto = skb->protocol;
+
+ while (eth_type_vlan(*proto)) {
+ struct vlan_hdr *vlan;
+
+ if (unlikely(!pskb_may_pull(skb, VLAN_HLEN)))
+ return -ENOMEM;
+
+ vlan = (struct vlan_hdr *)skb->data;
+ *proto = vlan->h_vlan_encapsulated_proto;
+ skb_pull(skb, VLAN_HLEN);
+ skb_reset_network_header(skb);
+ (*hdr_count)++;
+ }
+ return 0;
+}
#endif
diff --git a/net/sched/act_csum.c b/net/sched/act_csum.c
index 14bb525e355e..e8308ddcae9d 100644
--- a/net/sched/act_csum.c
+++ b/net/sched/act_csum.c
@@ -574,7 +574,6 @@ static int tcf_csum_act(struct sk_buff *skb, const struct tc_action *a,
struct tcf_result *res)
{
struct tcf_csum *p = to_tcf_csum(a);
- bool orig_vlan_tag_present = false;
unsigned int vlan_hdr_count = 0;
struct tcf_csum_params *params;
u32 update_flags;
@@ -604,17 +603,8 @@ static int tcf_csum_act(struct sk_buff *skb, const struct tc_action *a,
break;
case cpu_to_be16(ETH_P_8021AD): /* fall through */
case cpu_to_be16(ETH_P_8021Q):
- if (skb_vlan_tag_present(skb) && !orig_vlan_tag_present) {
- protocol = skb->protocol;
- orig_vlan_tag_present = true;
- } else {
- struct vlan_hdr *vlan = (struct vlan_hdr *)skb->data;
-
- protocol = vlan->h_vlan_encapsulated_proto;
- skb_pull(skb, VLAN_HLEN);
- skb_reset_network_header(skb);
- vlan_hdr_count++;
- }
+ if (tc_skb_pull_vlans(skb, &vlan_hdr_count, &protocol))
+ goto drop;
goto again;
}
--
2.20.1
Powered by blists - more mailing lists