Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix UDP_SEGMENT check on some linux kernels #4447

Closed
wants to merge 1 commit into from

Conversation

requilence
Copy link

Check the UDP_SEGMENT socket option for 0 value(according to https://man7.org/linux/man-pages/man7/udp.7.html) inside isGSOSupported func on linux.

Fixes #4446

@requilence requilence changed the title fix UDP_SEGMENT on some linux kernels fix UDP_SEGMENT check on some linux kernels Apr 19, 2024
@marten-seemann
Copy link
Member

I see the tests on Ubuntu failing here. I thought that these machines support GSOs though. Potential false positive?

Copy link

codecov bot commented Apr 19, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 84.67%. Comparing base (e48e1d4) to head (0624098).

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #4447      +/-   ##
==========================================
- Coverage   84.75%   84.67%   -0.08%     
==========================================
  Files         152      149       -3     
  Lines       14371    14117     -254     
==========================================
- Hits        12179    11953     -226     
+ Misses       1691     1678      -13     
+ Partials      501      486      -15     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@requilence
Copy link
Author

requilence commented Apr 22, 2024

@marten-seemann Hm, yes, I think 0 may mean GSO is supported but disabled for the current connection. I think we need research more. So, as far as I understand the original idea was:

  • check if system support UDP_SEGMENT socket option at all by checking error on unix.GetsockoptInt
  • set it for the specific packet by appending syscall.IPPROTO_UDP msg
  • in case we get error unix.EIO during writePacket, retry without GSO. BTW, according to the comment, isGSOError suppose to only check, whatever tx checksums are disabled on the system

Instead of checking whatever val != 0 I tried this approach:

  • Before getting socketOpt I set it. I put 1500 (because I saw the gso_size to be beyond 1500), but other values >0 give the same result.
if err := conn.Control(func(fd uintptr) {
		gerr := unix.SetsockoptInt(int(fd), unix.IPPROTO_UDP, unix.UDP_SEGMENT, 1500)
		fmt.Printf("SetsockoptInt gsp: %v\n", gerr)
		sval, serr = unix.GetsockoptInt(int(fd), unix.IPPROTO_UDP, unix.UDP_SEGMENT)
}); err != nil {
		return false
}
  • I got nil error on set/get and got the same 1500 on Get
  • Now for all sconn.writePacket calls I get this error: Write: write udp [::]:43377->192.168.184.136:7000: sendmsg: invalid argument. Before manually setting the connection's unix.IPPROTO_UDP it return nil error.

@requilence
Copy link
Author

requilence commented Apr 22, 2024

BTW, according to this linux kernel commit and v4.18 release notes, UDP_SEGMENT control message was added just in v4.18.1. So it's probably a bug that setting it in 4.14.180 return no error. Probably it may be a good idea to add a limitation based on linux kernel version >=4.18

@marten-seemann
Copy link
Member

BTW, according to this linux kernel commit and v4.18 release notes, UDP_SEGMENT control message was added just in v4.18.1. So it's probably a bug that setting it in 4.14.180 return no error. Probably it may be a good idea to add a limitation based on linux kernel version >=4.18

Interesting. Do I understand correctly that we'd fix the problem by disabling GSO on v4.18, or is anything else required as well?

I've tried to avoid checking the kernel version, but it seems like there's a problem with ECN in older kernel versions as well (see #4396), so maybe it makes sense to implement a check like that.

@requilence
Copy link
Author

requilence commented Apr 23, 2024

correct, need to disable GSO on linux kernel versions less than 4.18. 4.18 already should work fine.
I was trying to find a way to detect the support in a more robust way, but looks like it is not achievable.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

isGSOSupported incorrect value on some Android devices
2 participants