From mboxrd@z Thu Jan 1 00:00:00 1970 From: Cong Wang Subject: Re: [Patch net] mlx5: check for malformed packets Date: Sun, 2 Dec 2018 21:11:13 -0800 Message-ID: References: <20181201203837.3306-1-xiyou.wangcong@gmail.com> <955711f0-eb24-4512-c9a3-429bdad8bcad@mellanox.com> Mime-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Cc: Linux Kernel Network Developers , Saeed Mahameed To: Tariq Toukan Return-path: Received: from mail-pl1-f196.google.com ([209.85.214.196]:39367 "EHLO mail-pl1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725811AbeLCFL3 (ORCPT ); Mon, 3 Dec 2018 00:11:29 -0500 Received: by mail-pl1-f196.google.com with SMTP id 101so5827274pld.6 for ; Sun, 02 Dec 2018 21:11:25 -0800 (PST) In-Reply-To: <955711f0-eb24-4512-c9a3-429bdad8bcad@mellanox.com> Sender: netdev-owner@vger.kernel.org List-ID: On Sun, Dec 2, 2018 at 12:56 AM Tariq Toukan wrote: > > > > On 01/12/2018 10:38 PM, Cong Wang wrote: > > + if (*proto == htons(ETH_P_IP)) { > > + if (unlikely(*network_depth > skb->len - sizeof(struct iphdr))) > > + return false; > > + return true; > > Or just do the following? > return *network_depth <= skb->len - sizeof(struct iphdr)); > > We'll lose the compiler hint though, so I'm not sure which is better. It is very important to keep this unlikely(), as it is on a hot path. > > > + } else if (*proto == htons(ETH_P_IPV6)) { > > No need for an else here, the first if block always returns. Yeah, but not sure if this makes a difference on the generated asm code. I will give it a try anyway. Thanks.