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

lib/connect: defer port selection until connect() time #6295

Closed
wants to merge 1 commit into from

Conversation

@crrodriguez
Copy link
Contributor

@crrodriguez crrodriguez commented Dec 9, 2020

If supported, defer port selection until connect() time
if --interface is given and source port is 0.

Reproducer:

  • start fast webserver on port 80

  • starve system of ephemeral ports
    $ sysctl net.ipv4.ip_local_port_range="60990 60999"

  • start a curl/libcurl "crawler"
    $curl --keepalive --parallel --parallel-immediate --head --interface
    127.0.0.2 "http://127.0.0.[1-254]/file[001-002].txt"

current result:
(possible some successful data)
curl: (45) bind failed with errno 98: Address already in use

result after patch:
(complete success or few connections failing, higlhy depending on load)

Fail only when all the possible 4-tuple combinations are exhausted, which is
impossible to do when port is selected at bind() time becuse the kernel
does not know if socket will be listen()'ed on or connect'ed yet.

If supported, defer port selection until connect() time
if --interface is given and source port is 0.

Reproducer:

* start fast webserver on port 80
* starve system of ephemeral ports
$  sysctl net.ipv4.ip_local_port_range="60990 60999"

* start a curl/libcurl "crawler"
$curl --keepalive --parallel --parallel-immediate --head --interface
127.0.0.2 "http://127.0.0.[1-254]/file[001-002].txt"

current result:
(possible some successful data)
curl: (45) bind failed with errno 98: Address already in use

result after patch:
(complete success or few connections failing, higlhy depending on load)

Fail only when all the possible 4-tuple combinations are exhausted, which is
impossible to do when port is selected at bind() time becuse the kernel
does not know if socket will be listen()'ed on or connect'ed  yet.
@crrodriguez crrodriguez force-pushed the crrodriguez:IP_BIND_ADDRESS_NO_PORT branch from 076e5c5 to 861c522 Dec 9, 2020
@bagder
bagder approved these changes Dec 9, 2020
@bagder bagder self-assigned this Dec 9, 2020
@crrodriguez
Copy link
Contributor Author

@crrodriguez crrodriguez commented Dec 10, 2020

More agressive test to prove source ports are now shared as long 4-tuple is unique

curl --keepalive --parallel --parallel-immediate --head --interface 127.0.0.2 "http://127.0.[0-254].[1-254]/file[001-002].txt"

@bagder
Copy link
Member

@bagder bagder commented Dec 10, 2020

Thanks!

@bagder bagder closed this in 25b4e15 Dec 10, 2020
@crrodriguez crrodriguez deleted the crrodriguez:IP_BIND_ADDRESS_NO_PORT branch Dec 10, 2020
@crrodriguez crrodriguez restored the crrodriguez:IP_BIND_ADDRESS_NO_PORT branch Dec 17, 2020
@crrodriguez crrodriguez deleted the crrodriguez:IP_BIND_ADDRESS_NO_PORT branch Dec 17, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

2 participants