Skip to content

ares_socket: set IP_BIND_ADDRESS_NO_PORT on ares_set_local_ip* tcp sockets#887

Merged
bradh352 merged 1 commit intoc-ares:mainfrom
crrodriguez:bind_no_port
Sep 24, 2024
Merged

ares_socket: set IP_BIND_ADDRESS_NO_PORT on ares_set_local_ip* tcp sockets#887
bradh352 merged 1 commit intoc-ares:mainfrom
crrodriguez:bind_no_port

Conversation

@crrodriguez
Copy link
Copy Markdown
Contributor

If you bind to a local address, you now only have approx 32k possible source ports to initiate connections.
In modern days that can quickly run out.
setting IP_BIND_ADDRESS_NO_PORT let's the kernel choose a port at connect time, increasing the limit of combinations to around a million.

Copy link
Copy Markdown
Member

@bradh352 bradh352 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you use the same pattern as SO_NOSIGPIPE? int opt = 1; and pass that in instead of the form you're using?

@crrodriguez
Copy link
Copy Markdown
Contributor Author

ook. compound literals are valid c99 thou..

@bradh352
Copy link
Copy Markdown
Member

ook. compound literals are valid c99 thou..

we use ANSI C89 / ISO C90 still which is why compilation generates these warnings:

/home/runner/work/c-ares/c-ares/src/lib/ares_socket.c: In function ‘ares_socket_configure’:
/home/runner/work/c-ares/c-ares/src/lib/ares_socket.c:579:67: warning: ISO C90 forbids compound literals [-Wpedantic]
  579 |     (void) setsockopt(fd, SOL_IP, IP_BIND_ADDRESS_NO_PORT, &(int) {1}, sizeof(int));
      |                                                                   ^

…ckets

If you bind to a local address, you now only have approx 32k possible source
ports to initiate connections.
In modern days that can quickly run out.
setting IP_BIND_ADDRESS_NO_PORT let's the kernel choose a port at
connect time, increasing the limit of combinations to around a million.
@crrodriguez
Copy link
Copy Markdown
Contributor Author

ok fixed now.

@bradh352 bradh352 merged commit 3c4084c into c-ares:main Sep 24, 2024
@crrodriguez crrodriguez deleted the bind_no_port branch September 26, 2024 18:23
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.

2 participants