From mboxrd@z Thu Jan 1 00:00:00 1970 From: William Tu Subject: [PATCH net-next] erspan: set bso bit based on mirrored packet's len Date: Mon, 14 May 2018 16:54:36 -0700 Message-ID: <1526342076-43714-1-git-send-email-u9012063@gmail.com> To: netdev@vger.kernel.org Return-path: Received: from mail-pl0-f66.google.com ([209.85.160.66]:37084 "EHLO mail-pl0-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752391AbeENXzW (ORCPT ); Mon, 14 May 2018 19:55:22 -0400 Received: by mail-pl0-f66.google.com with SMTP id w19-v6so5658779plq.4 for ; Mon, 14 May 2018 16:55:22 -0700 (PDT) Received: from sc9-mailhost2.vmware.com ([66.170.99.2]) by smtp.gmail.com with ESMTPSA id f13-v6sm14239701pgs.84.2018.05.14.16.55.21 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 14 May 2018 16:55:21 -0700 (PDT) Sender: netdev-owner@vger.kernel.org List-ID: Before the patch, the erspan BSO bit (Bad/Short/Oversized) is not handled. BSO has 4 possible values: 00 --> Good frame with no error, or unknown integrity 11 --> Payload is a Bad Frame with CRC or Alignment Error 01 --> Payload is a Short Frame 10 --> Payload is an Oversized Frame Based the short/oversized definitions in RFC1757, the patch sets the bso bit based on the mirrored packet's size. Reported-by: Xiaoyan Jin Signed-off-by: William Tu --- include/net/erspan.h | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/include/net/erspan.h b/include/net/erspan.h index d044aa60cc76..5eb95f78ad45 100644 --- a/include/net/erspan.h +++ b/include/net/erspan.h @@ -219,6 +219,30 @@ static inline __be32 erspan_get_timestamp(void) return htonl((u32)h_usecs); } +/* ERSPAN BSO (Bad/Short/Oversized) + * 00b --> Good frame with no error, or unknown integrity + * 01b --> Payload is a Short Frame + * 10b --> Payload is an Oversized Frame + * 11b --> Payload is a Bad Frame with CRC or Alignment Error + */ +enum erspan_bso { + BSO_NOERROR, + BSO_SHORT, + BSO_OVERSIZED, + BSO_BAD, +}; + +static inline u8 erspan_detect_bso(struct sk_buff *skb) +{ + if (skb->len < ETH_ZLEN) + return BSO_SHORT; + + if (skb->len > ETH_FRAME_LEN) + return BSO_OVERSIZED; + + return BSO_NOERROR; +} + static inline void erspan_build_header_v2(struct sk_buff *skb, u32 id, u8 direction, u16 hwid, bool truncate, bool is_ipv4) @@ -248,6 +272,7 @@ static inline void erspan_build_header_v2(struct sk_buff *skb, vlan_tci = ntohs(qp->tci); } + bso = erspan_detect_bso(skb); skb_push(skb, sizeof(*ershdr) + ERSPAN_V2_MDSIZE); ershdr = (struct erspan_base_hdr *)skb->data; memset(ershdr, 0, sizeof(*ershdr) + ERSPAN_V2_MDSIZE); -- 2.7.4