[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <939828b0-846c-9e10-df31-afcb77b1150a@gmail.com>
Date: Thu, 15 Oct 2020 09:56:41 -0700
From: Florian Fainelli <f.fainelli@...il.com>
To: Richard Cochran <richardcochran@...il.com>,
Christian Eggers <ceggers@...i.de>
Cc: "David S . Miller" <davem@...emloft.net>,
Jakub Kicinski <kuba@...nel.org>,
Krzysztof Halasa <khalasa@...p.pl>,
Vishal Kulkarni <vishal@...lsio.com>, netdev@...r.kernel.org,
linux-kernel@...r.kernel.org
Subject: Re: [PATCH net-next] net: ptp: get rid of IPV4_HLEN() and OFF_IHL
macros
On 10/14/20 8:36 PM, Richard Cochran wrote:
> On Wed, Oct 14, 2020 at 01:58:05PM +0200, Christian Eggers wrote:
>> Both macros are already marked for removal.
>
> I'm not sure what Daniel Borkmann meant by that comment, but ...
>
>> switch (type & PTP_CLASS_PMASK) {
>> case PTP_CLASS_IPV4:
>> - ptr += IPV4_HLEN(ptr) + UDP_HLEN;
>> + ptr += (((struct iphdr *)ptr)->ihl << 2) + UDP_HLEN;
>
> to my eyes
>
> IPV4_HLEN(ptr)
>
> is way more readable than
>
> (((struct iphdr *)ptr)->ihl << 2)
>
> and this
>
> (struct udphdr *)((char *)ih + (ih->ihl << 2))
>
> is really baroque.
>
> I don't see any improvement here.
Having recently helped someone with a bug that involved using
IPV4_HLEN() instead of ip_hdr() in a driver's transmit path (so with the
transport header correctly set), it would probably help if we could make
IPV4_HLEN()'s semantics clearer with converting it to a static inline
function and put asserts in there about what the transport and MAC
header positions should be.
At the very least, creating a new function, like this maybe in
include/linux/ip.h might help:
static inline u8 __ip_hdr_len(const struct sk_buff *skb)
{
const struct iphdr *ip_hdr = (const struct iphdr *)(skb->data);
return ip_hdr->ihl << 2;
}
--
Florian
Powered by blists - more mailing lists