netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Florian Fainelli <f.fainelli@gmail.com>
To: Richard Cochran <richardcochran@gmail.com>,
	Christian Eggers <ceggers@arri.de>
Cc: "David S . Miller" <davem@davemloft.net>,
	Jakub Kicinski <kuba@kernel.org>,
	Krzysztof Halasa <khalasa@piap.pl>,
	Vishal Kulkarni <vishal@chelsio.com>,
	netdev@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH net-next] net: ptp: get rid of IPV4_HLEN() and OFF_IHL macros
Date: Thu, 15 Oct 2020 09:56:41 -0700	[thread overview]
Message-ID: <939828b0-846c-9e10-df31-afcb77b1150a@gmail.com> (raw)
In-Reply-To: <20201015033648.GA24901@hoboy>

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

  reply	other threads:[~2020-10-15 16:56 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-10-14 11:58 [PATCH net-next] net: ptp: get rid of IPV4_HLEN() and OFF_IHL macros Christian Eggers
2020-10-15  3:36 ` Richard Cochran
2020-10-15 16:56   ` Florian Fainelli [this message]
2020-10-16  7:04     ` Christian Eggers
2020-10-16 12:52       ` Richard Cochran

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=939828b0-846c-9e10-df31-afcb77b1150a@gmail.com \
    --to=f.fainelli@gmail.com \
    --cc=ceggers@arri.de \
    --cc=davem@davemloft.net \
    --cc=khalasa@piap.pl \
    --cc=kuba@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=richardcochran@gmail.com \
    --cc=vishal@chelsio.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).