public inbox for passt-dev@passt.top
 help / color / mirror / code / Atom feed
* [PATCH] tap: always set the no_frag flag in IPv4 headers.
@ 2025-02-12 23:50 Jon Maloy
  2025-02-14 11:00 ` Stefano Brivio
  0 siblings, 1 reply; 5+ messages in thread
From: Jon Maloy @ 2025-02-12 23:50 UTC (permalink / raw)
  To: passt-dev, sbrivio, lvivier, dgibson, jmaloy

When studying the Linux source code and Wireshark dumps it seems like
the no_frag flag in the IPv4 header is always set. Following discussions
in the Internet on this subject indicates that modern routers never
fragment packets, and that it isn't even supported in many cases.

Adding to this that incoming messages forwarded on the tap interface
never even pass through a router it seems safe to always set this flag.

This makes the IPv4 headers of forwarded messages identical to those
sent by the external sockets, something we must consider desirable.

Signed-off-by: Jon Maloy <jmaloy@redhat.com>
---
 tap.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/tap.c b/tap.c
index d0673e5..44b0fc0 100644
--- a/tap.c
+++ b/tap.c
@@ -153,7 +153,7 @@ static void *tap_push_ip4h(struct iphdr *ip4h, struct in_addr src,
 	ip4h->tos = 0;
 	ip4h->tot_len = htons(l3len);
 	ip4h->id = 0;
-	ip4h->frag_off = 0;
+	ip4h->frag_off = htons(IP_DF);
 	ip4h->ttl = 255;
 	ip4h->protocol = proto;
 	ip4h->saddr = src.s_addr;
-- 
@@ -153,7 +153,7 @@ static void *tap_push_ip4h(struct iphdr *ip4h, struct in_addr src,
 	ip4h->tos = 0;
 	ip4h->tot_len = htons(l3len);
 	ip4h->id = 0;
-	ip4h->frag_off = 0;
+	ip4h->frag_off = htons(IP_DF);
 	ip4h->ttl = 255;
 	ip4h->protocol = proto;
 	ip4h->saddr = src.s_addr;
-- 
2.48.1


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH] tap: always set the no_frag flag in IPv4 headers.
  2025-02-12 23:50 [PATCH] tap: always set the no_frag flag in IPv4 headers Jon Maloy
@ 2025-02-14 11:00 ` Stefano Brivio
  2025-02-14 22:46   ` Jon Maloy
  0 siblings, 1 reply; 5+ messages in thread
From: Stefano Brivio @ 2025-02-14 11:00 UTC (permalink / raw)
  To: Jon Maloy; +Cc: passt-dev, lvivier, dgibson

On Wed, 12 Feb 2025 18:50:23 -0500
Jon Maloy <jmaloy@redhat.com> wrote:

> When studying the Linux source code and Wireshark dumps it seems like
> the no_frag flag in the IPv4 header is always set. Following discussions
> in the Internet on this subject indicates that modern routers never
> fragment packets, and that it isn't even supported in many cases.
> 
> Adding to this that incoming messages forwarded on the tap interface
> never even pass through a router it seems safe to always set this flag.
> 
> This makes the IPv4 headers of forwarded messages identical to those
> sent by the external sockets, something we must consider desirable.
> 
> Signed-off-by: Jon Maloy <jmaloy@redhat.com>
> ---
>  tap.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/tap.c b/tap.c
> index d0673e5..44b0fc0 100644
> --- a/tap.c
> +++ b/tap.c
> @@ -153,7 +153,7 @@ static void *tap_push_ip4h(struct iphdr *ip4h, struct in_addr src,
>  	ip4h->tos = 0;
>  	ip4h->tot_len = htons(l3len);
>  	ip4h->id = 0;
> -	ip4h->frag_off = 0;
> +	ip4h->frag_off = htons(IP_DF);

$ tshark -r test/test_logs/pasta.pcap -V -Y frame.number==9 | grep "Header Checksum"
    Header Checksum: 0x07d4 incorrect, should be 0xc7d3(may be caused by "IP checksum offload"?)

See L2_BUF_IP4_PSUM().

-- 
Stefano


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] tap: always set the no_frag flag in IPv4 headers.
  2025-02-14 11:00 ` Stefano Brivio
@ 2025-02-14 22:46   ` Jon Maloy
  2025-02-14 22:57     ` Stefano Brivio
  0 siblings, 1 reply; 5+ messages in thread
From: Jon Maloy @ 2025-02-14 22:46 UTC (permalink / raw)
  To: Stefano Brivio; +Cc: passt-dev, lvivier, dgibson



On 2025-02-14 06:00, Stefano Brivio wrote:
> On Wed, 12 Feb 2025 18:50:23 -0500
> Jon Maloy <jmaloy@redhat.com> wrote:
> 
>> When studying the Linux source code and Wireshark dumps it seems like
>> the no_frag flag in the IPv4 header is always set. Following discussions
>> in the Internet on this subject indicates that modern routers never
>> fragment packets, and that it isn't even supported in many cases.
>>
>> Adding to this that incoming messages forwarded on the tap interface
>> never even pass through a router it seems safe to always set this flag.
>>
>> This makes the IPv4 headers of forwarded messages identical to those
>> sent by the external sockets, something we must consider desirable.
>>
>> Signed-off-by: Jon Maloy <jmaloy@redhat.com>
>> ---
>>   tap.c | 2 +-
>>   1 file changed, 1 insertion(+), 1 deletion(-)
>>
>> diff --git a/tap.c b/tap.c
>> index d0673e5..44b0fc0 100644
>> --- a/tap.c
>> +++ b/tap.c
>> @@ -153,7 +153,7 @@ static void *tap_push_ip4h(struct iphdr *ip4h, struct in_addr src,
>>   	ip4h->tos = 0;
>>   	ip4h->tot_len = htons(l3len);
>>   	ip4h->id = 0;
>> -	ip4h->frag_off = 0;
>> +	ip4h->frag_off = htons(IP_DF);
> 
> $ tshark -r test/test_logs/pasta.pcap -V -Y frame.number==9 | grep "Header Checksum"
>      Header Checksum: 0x07d4 incorrect, should be 0xc7d3(may be caused by "IP checksum offload"?)
> 
> See L2_BUF_IP4_PSUM().
> 

Not sure what to do about this. I don't even see we calculate the 
checksum in our code, so does it matter?

///jon


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] tap: always set the no_frag flag in IPv4 headers.
  2025-02-14 22:46   ` Jon Maloy
@ 2025-02-14 22:57     ` Stefano Brivio
  2025-02-16 14:26       ` Jon Maloy
  0 siblings, 1 reply; 5+ messages in thread
From: Stefano Brivio @ 2025-02-14 22:57 UTC (permalink / raw)
  To: Jon Maloy; +Cc: passt-dev, lvivier, dgibson

On Fri, 14 Feb 2025 17:46:21 -0500
Jon Maloy <jmaloy@redhat.com> wrote:

> On 2025-02-14 06:00, Stefano Brivio wrote:
> > On Wed, 12 Feb 2025 18:50:23 -0500
> > Jon Maloy <jmaloy@redhat.com> wrote:
> >   
> >> When studying the Linux source code and Wireshark dumps it seems like
> >> the no_frag flag in the IPv4 header is always set. Following discussions
> >> in the Internet on this subject indicates that modern routers never
> >> fragment packets, and that it isn't even supported in many cases.
> >>
> >> Adding to this that incoming messages forwarded on the tap interface
> >> never even pass through a router it seems safe to always set this flag.
> >>
> >> This makes the IPv4 headers of forwarded messages identical to those
> >> sent by the external sockets, something we must consider desirable.
> >>
> >> Signed-off-by: Jon Maloy <jmaloy@redhat.com>
> >> ---
> >>   tap.c | 2 +-
> >>   1 file changed, 1 insertion(+), 1 deletion(-)
> >>
> >> diff --git a/tap.c b/tap.c
> >> index d0673e5..44b0fc0 100644
> >> --- a/tap.c
> >> +++ b/tap.c
> >> @@ -153,7 +153,7 @@ static void *tap_push_ip4h(struct iphdr *ip4h, struct in_addr src,
> >>   	ip4h->tos = 0;
> >>   	ip4h->tot_len = htons(l3len);
> >>   	ip4h->id = 0;
> >> -	ip4h->frag_off = 0;
> >> +	ip4h->frag_off = htons(IP_DF);  
> > 
> > $ tshark -r test/test_logs/pasta.pcap -V -Y frame.number==9 | grep "Header Checksum"
> >      Header Checksum: 0x07d4 incorrect, should be 0xc7d3(may be caused by "IP checksum offload"?)
> > 
> > See L2_BUF_IP4_PSUM().
> 
> Not sure what to do about this. I don't even see we calculate the 
> checksum in our code

We precalculate that part, see L2_BUF_IP4_PSUM() (and also
L2_BUF_IP4_INIT()).

> so does it matter?

Well, I think it matters that we send out valid IPv4 packets. Try this
change and see for yourself.

-- 
Stefano


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] tap: always set the no_frag flag in IPv4 headers.
  2025-02-14 22:57     ` Stefano Brivio
@ 2025-02-16 14:26       ` Jon Maloy
  0 siblings, 0 replies; 5+ messages in thread
From: Jon Maloy @ 2025-02-16 14:26 UTC (permalink / raw)
  To: Stefano Brivio; +Cc: passt-dev, lvivier, dgibson



On 2025-02-14 17:57, Stefano Brivio wrote:
> On Fri, 14 Feb 2025 17:46:21 -0500
> Jon Maloy <jmaloy@redhat.com> wrote:
> 
>> On 2025-02-14 06:00, Stefano Brivio wrote:
>>> On Wed, 12 Feb 2025 18:50:23 -0500
>>> Jon Maloy <jmaloy@redhat.com> wrote:
>>>    
>>>> When studying the Linux source code and Wireshark dumps it seems like
>>>> the no_frag flag in the IPv4 header is always set. Following discussions
>>>> in the Internet on this subject indicates that modern routers never
>>>> fragment packets, and that it isn't even supported in many cases.
>>>>
>>>> Adding to this that incoming messages forwarded on the tap interface
>>>> never even pass through a router it seems safe to always set this flag.
>>>>
>>>> This makes the IPv4 headers of forwarded messages identical to those
>>>> sent by the external sockets, something we must consider desirable.
>>>>
>>>> Signed-off-by: Jon Maloy <jmaloy@redhat.com>
>>>> ---
>>>>    tap.c | 2 +-
>>>>    1 file changed, 1 insertion(+), 1 deletion(-)
>>>>
>>>> diff --git a/tap.c b/tap.c
>>>> index d0673e5..44b0fc0 100644
>>>> --- a/tap.c
>>>> +++ b/tap.c
>>>> @@ -153,7 +153,7 @@ static void *tap_push_ip4h(struct iphdr *ip4h, struct in_addr src,
>>>>    	ip4h->tos = 0;
>>>>    	ip4h->tot_len = htons(l3len);
>>>>    	ip4h->id = 0;
>>>> -	ip4h->frag_off = 0;
>>>> +	ip4h->frag_off = htons(IP_DF);
>>>
>>> $ tshark -r test/test_logs/pasta.pcap -V -Y frame.number==9 | grep "Header Checksum"
>>>       Header Checksum: 0x07d4 incorrect, should be 0xc7d3(may be caused by "IP checksum offload"?)
>>>
>>> See L2_BUF_IP4_PSUM().
>>
>> Not sure what to do about this. I don't even see we calculate the
>> checksum in our code
> 
> We precalculate that part, see L2_BUF_IP4_PSUM() (and also
> L2_BUF_IP4_INIT()).
> 
>> so does it matter?
Brain fart. I was thinking about the UDP header checksum, which
is optional we don't caluclate in current code.
Of course it matters.
> 
> Well, I think it matters that we send out valid IPv4 packets. Try this
> change and see for yourself.
> 

Ok. Now I see what you mean. I will try this.

///jon


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2025-02-16 14:27 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-02-12 23:50 [PATCH] tap: always set the no_frag flag in IPv4 headers Jon Maloy
2025-02-14 11:00 ` Stefano Brivio
2025-02-14 22:46   ` Jon Maloy
2025-02-14 22:57     ` Stefano Brivio
2025-02-16 14:26       ` Jon Maloy

Code repositories for project(s) associated with this public inbox

	https://passt.top/passt

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 IMAP folder(s).