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

Minimum port is ignored if port on local is 0 #23

Closed
BxOxSxS opened this issue Apr 13, 2022 · 6 comments
Closed

Minimum port is ignored if port on local is 0 #23

BxOxSxS opened this issue Apr 13, 2022 · 6 comments

Comments

@BxOxSxS
Copy link
Contributor

BxOxSxS commented Apr 13, 2022

Hello,
I was trying to add option for max port however I discovered issue and wanted to discuss it before any action.

When you set minimum port on server and the client send wanted port using -p option the server correctly check if it's in range or not.

But when the port is set to 0 (or not given) by local the check is skipped because of condition:

if port != 0 && port < self.min_port {

Port is selected by TcpListener from tokio which is bypassing the setting.

The simplest solution that came to my mind is to generate random port on server within given range so currently MIN_PORT and 65535

What do you think?

@BxOxSxS
Copy link
Contributor Author

BxOxSxS commented Apr 13, 2022

Steps to reproduce:

  • run bore server --min-port 65535 on server
  • run bore local --to <server ip> <any port> -p 65534 on local
    You can see it does not work and there is proper message on the server
  • run bore local --to <server ip> <any port> -p 0 on local
    You can see assigned port is in most cases under MIN_PORT value

@ekzhang
Copy link
Owner

ekzhang commented Apr 14, 2022

Hi @BxOxSxS, this is actually intended behavior. min_port is only used to specify port numbers specified by the user bore local ... --port x that are accepted. Unfortunately I don't believe it's possible to ask the operating system for a TCP listener on any given port :0 with the added constraint of being within a range of port numbers.

@BxOxSxS
Copy link
Contributor Author

BxOxSxS commented Apr 14, 2022

Yes it's not possible that way but bore could somehow choose and assign specyfic port if local gave value 0. Currently--min-port option is much less useful that it could be and description can also lead to missunderstanding. It can be problematic with firewalls and general management of server

@ekzhang
Copy link
Owner

ekzhang commented Apr 14, 2022

Yes it's not possible that way but bore could somehow choose and assign specyfic port if local gave value 0.

I don't believe this is possible, but if you have a specific technical approach to doing this then we can reopen. Closing this issue.

@ekzhang ekzhang closed this as completed Apr 14, 2022
@BxOxSxS
Copy link
Contributor Author

BxOxSxS commented Apr 14, 2022

Here is more technical example:
rust-lang-nursery/rust-cookbook#500

I tried that first approach with for loop and it's working fine under linux but does now work on windows as someone commented on the issue. I will try to experiment with second way and report back

@DesignsWithDavid
Copy link

DesignsWithDavid commented Apr 6, 2023

Here is a means of limiting random port selection to a range via "ip_local_port_range": https://unix.stackexchange.com/questions/305308/how-to-limit-range-of-random-port-sockets

EDIT:
I am embarassed at how long it took me to figure this out, but there is a very easy way to implement this is using docker compose. Just add the following to your compose file:

sysctls:
  net.ipv4.ip_local_port_range: "1024 65535"

Just change the range to your preference

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 a pull request may close this issue.

3 participants