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 via email to