Re: kernel bug? listening on same port with IPv4 and IPv6

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 




> On 6 Jan 2023, at 14:18, Sjoerd Mullender <sjoerd@xxxxxxx> wrote:
> 
> I have a program that is supposed to listen to the same port on both IPv4 and IPv6 sockets.  In the past, what it did, was basically: create new socket for IPv6, set option IPV6_V6ONLY to off, bind, listen; then create a new socket for IPv4, and also bind and listen.  The first bind is either to a specific port, or to port 0 to let the system assign a port.  The second bind uses the port that the first one used (i.e. what the system assigned).

Are you sure that this is behaviour you can depend on?
Is it documented?

It seems that there is a possibility that the 2nd bind with port 0 can race against other processes. Why should you get the same port bound?

If I was writing this code I would take the port allocated on the 1st bind and use it explicitly in the 2nd bind. Would that work and be deterministic?

I recall working on code that needed two ports N and N+1.
The algorithm looped until the N and N+1 condition was met.

Barry

> 
> With the latest kernel, this still works if listening to localhost ([::1]/127.0.0.1) only, but not when listening to [::]/0.0.0.0.  In that case, the second bind gets a different port number assigned to it. Moreover, the second bind system call returns 1, which it is not supposed to do according to the manual.  Bind is supposed to return 0 on success and -1 on error.
> 
> What is going on?  Is this a kernel bug, or is this the future?
> 
> Kernel is 6.0.16-300.fc37.x86_64, i.e. the latest Fedora 37 kernel.
> 
> -- 
> Sjoerd Mullender
> _______________________________________________
> users mailing list -- users@xxxxxxxxxxxxxxxxxxxxxxx
> To unsubscribe send an email to users-leave@xxxxxxxxxxxxxxxxxxxxxxx
> Fedora Code of Conduct: https://docs.fedoraproject.org/en-US/project/code-of-conduct/
> List Guidelines: https://fedoraproject.org/wiki/Mailing_list_guidelines
> List Archives: https://lists.fedoraproject.org/archives/list/users@xxxxxxxxxxxxxxxxxxxxxxx
> Do not reply to spam, report it: https://pagure.io/fedora-infrastructure/new_issue
_______________________________________________
users mailing list -- users@xxxxxxxxxxxxxxxxxxxxxxx
To unsubscribe send an email to users-leave@xxxxxxxxxxxxxxxxxxxxxxx
Fedora Code of Conduct: https://docs.fedoraproject.org/en-US/project/code-of-conduct/
List Guidelines: https://fedoraproject.org/wiki/Mailing_list_guidelines
List Archives: https://lists.fedoraproject.org/archives/list/users@xxxxxxxxxxxxxxxxxxxxxxx
Do not reply to spam, report it: https://pagure.io/fedora-infrastructure/new_issue



[Index of Archives]     [Older Fedora Users]     [Fedora Announce]     [Fedora Package Announce]     [EPEL Announce]     [EPEL Devel]     [Fedora Magazine]     [Fedora Summer Coding]     [Fedora Laptop]     [Fedora Cloud]     [Fedora Advisory Board]     [Fedora Education]     [Fedora Security]     [Fedora Scitech]     [Fedora Robotics]     [Fedora Infrastructure]     [Fedora Websites]     [Anaconda Devel]     [Fedora Devel Java]     [Fedora Desktop]     [Fedora Fonts]     [Fedora Marketing]     [Fedora Management Tools]     [Fedora Mentors]     [Fedora Package Review]     [Fedora R Devel]     [Fedora PHP Devel]     [Kickstart]     [Fedora Music]     [Fedora Packaging]     [Fedora SELinux]     [Fedora Legal]     [Fedora Kernel]     [Fedora OCaml]     [Coolkey]     [Virtualization Tools]     [ET Management Tools]     [Yum Users]     [Yosemite News]     [Gnome Users]     [KDE Users]     [Fedora Art]     [Fedora Docs]     [Fedora Sparc]     [Libvirt Users]     [Fedora ARM]

  Powered by Linux