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

Support bind to interface and IP #13719

Closed
wants to merge 1 commit into from
Closed

Conversation

orgads
Copy link
Contributor

@orgads orgads commented May 20, 2024

Support bind to interface and IP

Introduce new notation for CURLOPT_INTERFACE / --interface:
ifhost!<interface>!<host>

Binding to an interface doesn't set the address, and an interface can have multiple addresses.

When binding to an address (without interface), the kernel is free to choose the route, and it can route through any device that can access the target address, not necessarily the one with the chosen address.

Moreover, it is possible for different interfaces to have the same IP address, on which case we need to provide a way to be more specific.

Factor out the parsing part of interface option, and add unit tests.

@orgads orgads marked this pull request as draft May 20, 2024 14:09
@github-actions github-actions bot added the CI Continuous Integration label May 21, 2024
@orgads
Copy link
Contributor Author

orgads commented May 21, 2024

Can you suggest a way to add unit tests, at least for the parsing part? I'd love to use real callbacks for the actual bind to interface (setsockopt) and bind to ip (bind) parts, but that would be cumbersome, and require additional exported symbols. Are there tests for similar features?

@orgads orgads force-pushed the bind-iface-and-ip branch 2 times, most recently from 5fdd421 to 75eb8c5 Compare May 21, 2024 06:05
@orgads orgads marked this pull request as ready for review May 21, 2024 09:29
@bagder
Copy link
Member

bagder commented May 21, 2024

Please provide a description when you make a pull request so that we can get a better understanding what is proposed without having to read the patch.

@orgads
Copy link
Contributor Author

orgads commented May 21, 2024

Please provide a description when you make a pull request so that we can get a better understanding what is proposed without having to read the patch.

Sure. Please just let me know which approach you prefer from the ones discussed in #13688 and then I'll prepare a single commit with a proper commit message and update the PR.

docs/libcurl/opts/CURLOPT_INTERFACE.md Outdated Show resolved Hide resolved
lib/cf-socket.c Outdated Show resolved Hide resolved
lib/cf-socket.c Outdated Show resolved Hide resolved
lib/cf-socket.c Outdated Show resolved Hide resolved
lib/cf-socket.c Outdated Show resolved Hide resolved
@bagder
Copy link
Member

bagder commented May 22, 2024

Maybe use dynbufs instead of those local buffers to make it easier to manage without strcpys ?

lib/cf-socket.c Outdated Show resolved Hide resolved
@github-actions github-actions bot added the tests label May 23, 2024
@orgads orgads force-pushed the bind-iface-and-ip branch 2 times, most recently from 971b4a8 to 669b7ed Compare May 23, 2024 09:47
@orgads
Copy link
Contributor Author

orgads commented May 23, 2024

Please provide a description when you make a pull request so that we can get a better understanding what is proposed without having to read the patch.

Done

@orgads orgads force-pushed the bind-iface-and-ip branch 2 times, most recently from 79bc900 to efde1d8 Compare May 23, 2024 09:57
Introduce new notation for CURLOPT_INTERFACE / --interface:
ifhost!<interface>!<host>

Binding to an interface doesn't set the address, and an interface can
have multiple addresses.

When binding to an address (without interface), the kernel is free to
choose the route, and it can route through any device that can access
the target address, not necessarily the one with the chosen address.

Moreover, it is possible for different interfaces to have the same IP
address, on which case we need to provide a way to be more specific.

Factor out the parsing part of interface option, and add unit tests.
@orgads orgads requested a review from bagder May 23, 2024 14:09
@bagder bagder added the feature-window A merge of this requires an open feature window label Jun 1, 2024
@orgads
Copy link
Contributor Author

orgads commented Jun 3, 2024

@bagder any comments on this?

@bagder bagder closed this in 3060557 Jun 4, 2024
@bagder
Copy link
Member

bagder commented Jun 4, 2024

Thanks!

@orgads orgads deleted the bind-iface-and-ip branch June 5, 2024 03:30
panjf2000 pushed a commit to panjf2000/curl that referenced this pull request Jun 5, 2024
Introduce new notation for CURLOPT_INTERFACE / --interface:
ifhost!<interface>!<host>

Binding to an interface doesn't set the address, and an interface can
have multiple addresses.

When binding to an address (without interface), the kernel is free to
choose the route, and it can route through any device that can access
the target address, not necessarily the one with the chosen address.

Moreover, it is possible for different interfaces to have the same IP
address, on which case we need to provide a way to be more specific.

Factor out the parsing part of interface option, and add unit tests:
1663.

Closes curl#13719
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CI Continuous Integration feature-window A merge of this requires an open feature window tests
Development

Successfully merging this pull request may close these issues.

None yet

2 participants