Received: by 2002:a6b:500f:0:0:0:0:0 with SMTP id e15csp1000610iob; Fri, 13 May 2022 19:10:49 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwqpcBQ+jqk2AX2fEpjTF0PToVyDUWrC7kI9UbFzlZ3X9rtOYJAZI3g7Q+COeqzUECaqCgY X-Received: by 2002:a7b:cd98:0:b0:394:2431:2393 with SMTP id y24-20020a7bcd98000000b0039424312393mr7002659wmj.122.1652494249302; Fri, 13 May 2022 19:10:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1652494249; cv=none; d=google.com; s=arc-20160816; b=ZSG0ZZ+O477vh9RPfE08Os3xUt+Ke1IcSP6Ln5myWSmRJgHOFf++GbtYGPcNcfbnUa uFG/wtUZlr6EiWBDbU2uCoTzy1VywoURKqZ0LCTJQvndBnIcnupwcmsxlph/TRP2avyo Yt/5uMh4XJkQB7B8sUx+/jUEur25JD0PvfnlR4u1FtulF0VkdJzq9mmSq87FabSh3pox YWoN7T5kjTEP9MMd1oQe16wRUZuxpjHIc75xCk8r5zB82orvbh3cd88eNpBmR/l59vSQ +rY2bmNB71Tz7DB1/p4Im1+BGqVrBJtpa2ppQqIWTK+FcnmKYlfE2KVhQ3B28eSO9IuZ Kc2g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from:sender :dkim-signature; bh=I7l1Xm9qehIrYZIkT6lmz4zbqDX5vJCIeT/thGsyl/E=; b=fgOCNpKscKA9W8my+ukuH5RMTC40gDm6DAzGpUb+CZCyPkuE661xadHWIdEyTMTLna sDXvpbuLL7JXrzixEkjGK8v9sVMjt2WXkFjFNxjoYDDcktJa+U9m2g9GJ/+RjrViga4V 82kCxN5V2GA+wDfCRnpNMCsEh3JcH4oguKjzNKAVnqzvvGsFvOmx28TPi75wWJYaDCxj I5xuaxFZ7UIZDNkJcgrCIvwskYOBI1m14DkXsBVA2ryqH60uHShaHYbBJ5//ULTCy+cI H7iSkedAXtY+00vS+J8FBt/BX92jBUMTESS4luIdsNbmNzK/J1jpMcXlnFlNWDZMCXmJ UMOg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=VRWAuALO; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id z4-20020a05600c220400b0038eb8546a77si6341335wml.66.2022.05.13.19.10.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 13 May 2022 19:10:49 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=VRWAuALO; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id E58664986E3; Fri, 13 May 2022 17:29:52 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1382149AbiEMPgl (ORCPT + 99 others); Fri, 13 May 2022 11:36:41 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46458 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1382219AbiEMPg2 (ORCPT ); Fri, 13 May 2022 11:36:28 -0400 Received: from mail-pl1-x62c.google.com (mail-pl1-x62c.google.com [IPv6:2607:f8b0:4864:20::62c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5184F2DC6; Fri, 13 May 2022 08:36:27 -0700 (PDT) Received: by mail-pl1-x62c.google.com with SMTP id d22so8284913plr.9; Fri, 13 May 2022 08:36:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=I7l1Xm9qehIrYZIkT6lmz4zbqDX5vJCIeT/thGsyl/E=; b=VRWAuALO2Af7o/62+j66JdKdxL0rMt2KMj/NaWp9Si4SMu++SSGKzBG6uOls+/wRn1 JZGr8eVqcmg1+ljceUfzl5iIP7Q/7kuOahMYEkyJ/bWL6Fl3W8Uq4wcgxWvNcjmkKlr1 o3NaZGaOjYBJsrOORMuHHyxKFGc/1wMak/oQTnE8BppGXSO4oknfp42KdB+ZaQnIFTU3 h94hPlAC5pv/AF0rSwQ2lb6kDlznKYmeslyr1h6ciLcQKCF33GEUz2n2g32P1ooJPLaU CoQjiM3r1Zfa7pN4eKe21DpcQDJWM1+/nnWKOiqnmhgrR+8nHofh/LaRP+JtqarmQOhL Mg7Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=I7l1Xm9qehIrYZIkT6lmz4zbqDX5vJCIeT/thGsyl/E=; b=a5UguZMxtKkDYWtEibbdpUm802ZvHiZVcp6GqI5FH2m49rKlXWTpipsPYmVYa++SMj Tl0SqnO0PN+1c39WuX434ZGS+CBG5noDYwTogDXPCIbguSJXRcu/zvTWNQst+TIjQ2dz N7nzxeq7BtKcj8gy8TLpCdvJZNA/FMtzf2mTTXjQun1I+WHky+F0ZSJzPjS5Is9xuizs BsotAEWglqSC1x1H1DRrdCWYF3ZF+lbUV6+dKEJbAVnqLcifjeQp4uN/DBDsk8tKGgYb dp5E611sS3qHSuvHkp6C1oGEvbZwDyhFRdy9stmoyHr6rEof67pIhKGw8WomPomI+r4q maMA== X-Gm-Message-State: AOAM533gg6Q1RIfApGfDZhNS0AwsLANlUOHGGUo2a07DqtP7DmWSRwte iNd8y+gboBdjl+XzfBs1BGIqz8HexyVt7int X-Received: by 2002:a17:902:cec9:b0:15e:cbf4:c246 with SMTP id d9-20020a170902cec900b0015ecbf4c246mr5132972plg.1.1652456186689; Fri, 13 May 2022 08:36:26 -0700 (PDT) Received: from localhost.localdomain (124x33x176x97.ap124.ftth.ucom.ne.jp. [124.33.176.97]) by smtp.gmail.com with ESMTPSA id b10-20020a62a10a000000b0050dc762817dsm1942137pff.87.2022.05.13.08.36.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 13 May 2022 08:36:26 -0700 (PDT) Sender: Vincent Mailhol From: Vincent Mailhol To: Marc Kleine-Budde Cc: linux-can@vger.kernel.org, linux-kernel@vger.kernel.org, Max Staudt , Vincent Mailhol Subject: [PATCH v2 1/2] can: skb:: move can_dropped_invalid_skb and can_skb_headroom_valid to skb.c Date: Sat, 14 May 2022 00:36:05 +0900 Message-Id: <20220513153606.302464-2-mailhol.vincent@wanadoo.fr> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220513153606.302464-1-mailhol.vincent@wanadoo.fr> References: <20220513142355.250389-1-mailhol.vincent@wanadoo.fr> <20220513153606.302464-1-mailhol.vincent@wanadoo.fr> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,RDNS_NONE, SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The functions can_dropped_invalid_skb() and can_skb_headroom_valid() grew a lot over the years to a point which it does make much sense to have them defined as static inline in header files. Move those two functions to the .c counterpart of skb.h. can_skb_headroom_valid() only caller being can_dropped_invalid_skb(), the declaration is removed from the header. Only can_dropped_invalid_skb() gets its symbol exported. While doing so, do a small cleanup: add brackets around the else block in can_dropped_invalid_skb(). Signed-off-by: Vincent Mailhol --- drivers/net/can/dev/skb.c | 58 ++++++++++++++++++++++++++++++++++++++ include/linux/can/skb.h | 59 +-------------------------------------- 2 files changed, 59 insertions(+), 58 deletions(-) diff --git a/drivers/net/can/dev/skb.c b/drivers/net/can/dev/skb.c index 61660248c69e..8b1991130de5 100644 --- a/drivers/net/can/dev/skb.c +++ b/drivers/net/can/dev/skb.c @@ -252,3 +252,61 @@ struct sk_buff *alloc_can_err_skb(struct net_device *dev, struct can_frame **cf) return skb; } EXPORT_SYMBOL_GPL(alloc_can_err_skb); + +/* Check for outgoing skbs that have not been created by the CAN subsystem */ +static bool can_skb_headroom_valid(struct net_device *dev, struct sk_buff *skb) +{ + /* af_packet creates a headroom of HH_DATA_MOD bytes which is fine */ + if (WARN_ON_ONCE(skb_headroom(skb) < sizeof(struct can_skb_priv))) + return false; + + /* af_packet does not apply CAN skb specific settings */ + if (skb->ip_summed == CHECKSUM_NONE) { + /* init headroom */ + can_skb_prv(skb)->ifindex = dev->ifindex; + can_skb_prv(skb)->skbcnt = 0; + + skb->ip_summed = CHECKSUM_UNNECESSARY; + + /* perform proper loopback on capable devices */ + if (dev->flags & IFF_ECHO) + skb->pkt_type = PACKET_LOOPBACK; + else + skb->pkt_type = PACKET_HOST; + + skb_reset_mac_header(skb); + skb_reset_network_header(skb); + skb_reset_transport_header(skb); + } + + return true; +} + +/* Drop a given socketbuffer if it does not contain a valid CAN frame. */ +bool can_dropped_invalid_skb(struct net_device *dev, struct sk_buff *skb) +{ + const struct canfd_frame *cfd = (struct canfd_frame *)skb->data; + + if (skb->protocol == htons(ETH_P_CAN)) { + if (unlikely(skb->len != CAN_MTU || + cfd->len > CAN_MAX_DLEN)) + goto inval_skb; + } else if (skb->protocol == htons(ETH_P_CANFD)) { + if (unlikely(skb->len != CANFD_MTU || + cfd->len > CANFD_MAX_DLEN)) + goto inval_skb; + } else { + goto inval_skb; + } + + if (!can_skb_headroom_valid(dev, skb)) + goto inval_skb; + + return false; + +inval_skb: + kfree_skb(skb); + dev->stats.tx_dropped++; + return true; +} +EXPORT_SYMBOL_GPL(can_dropped_invalid_skb); diff --git a/include/linux/can/skb.h b/include/linux/can/skb.h index fdb22b00674a..182749e858b3 100644 --- a/include/linux/can/skb.h +++ b/include/linux/can/skb.h @@ -31,6 +31,7 @@ struct sk_buff *alloc_canfd_skb(struct net_device *dev, struct canfd_frame **cfd); struct sk_buff *alloc_can_err_skb(struct net_device *dev, struct can_frame **cf); +bool can_dropped_invalid_skb(struct net_device *dev, struct sk_buff *skb); /* * The struct can_skb_priv is used to transport additional information along @@ -96,64 +97,6 @@ static inline struct sk_buff *can_create_echo_skb(struct sk_buff *skb) return nskb; } -/* Check for outgoing skbs that have not been created by the CAN subsystem */ -static inline bool can_skb_headroom_valid(struct net_device *dev, - struct sk_buff *skb) -{ - /* af_packet creates a headroom of HH_DATA_MOD bytes which is fine */ - if (WARN_ON_ONCE(skb_headroom(skb) < sizeof(struct can_skb_priv))) - return false; - - /* af_packet does not apply CAN skb specific settings */ - if (skb->ip_summed == CHECKSUM_NONE) { - /* init headroom */ - can_skb_prv(skb)->ifindex = dev->ifindex; - can_skb_prv(skb)->skbcnt = 0; - - skb->ip_summed = CHECKSUM_UNNECESSARY; - - /* perform proper loopback on capable devices */ - if (dev->flags & IFF_ECHO) - skb->pkt_type = PACKET_LOOPBACK; - else - skb->pkt_type = PACKET_HOST; - - skb_reset_mac_header(skb); - skb_reset_network_header(skb); - skb_reset_transport_header(skb); - } - - return true; -} - -/* Drop a given socketbuffer if it does not contain a valid CAN frame. */ -static inline bool can_dropped_invalid_skb(struct net_device *dev, - struct sk_buff *skb) -{ - const struct canfd_frame *cfd = (struct canfd_frame *)skb->data; - - if (skb->protocol == htons(ETH_P_CAN)) { - if (unlikely(skb->len != CAN_MTU || - cfd->len > CAN_MAX_DLEN)) - goto inval_skb; - } else if (skb->protocol == htons(ETH_P_CANFD)) { - if (unlikely(skb->len != CANFD_MTU || - cfd->len > CANFD_MAX_DLEN)) - goto inval_skb; - } else - goto inval_skb; - - if (!can_skb_headroom_valid(dev, skb)) - goto inval_skb; - - return false; - -inval_skb: - kfree_skb(skb); - dev->stats.tx_dropped++; - return true; -} - static inline bool can_is_canfd_skb(const struct sk_buff *skb) { /* the CAN specific type of skb is identified by its data length */ -- 2.35.1