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

implement IPv6 scoped addresses (RFC4007) #15263

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

foxxx0
Copy link

@foxxx0 foxxx0 commented Dec 10, 2024

In order to translate interface names in such scoped addresses the
required LibC binding to if_nametoindex() has been added.
This method obviously only works for interfaces (devices) that are
actually present on the system.

The binding for the reverse operation if_indextoname() has also been
added, although its usage is a bit more cumbersome due to LibC::Char*
buffer handling. The necessary buffer length has been placed into the
constant LibC::IF_NAMESIZE, which appears to be 16u8 on unix-like
systems and 257u16 on windows.
This could potentially be reworked via a preprocessor block at
compile-time as indicated by some folks over on discord, I currently do
not know how to achieve that though.

Scoped identifiers are only valid for link-local (fe80::) addresses, e.g. fe80::1%eth0

References:

TODO (to be resolved during the PR discussion):

  • discuss the preprocessor option for retrieving the constant value IF_NAMESIZE (No clue how do that, haven't found any event of this constant ever changing in the past, might not be worth the trouble?)
  • clarify whether scope_id parsing should raise ArgumentError or Socket::Error
  • clarify whether Socket::Address spec #scope_id looks up interface name by index should remain in the Socket::Address spec, since it only calls the LibC binding

I'm happy to adjust/rebase if needed based on feedback or other merges into master in the mean time.

Fixes #15264 .

 In order to translate interface names in such scoped addresses the
 required `LibC` binding to `if_nametoindex()` has been added.
 This method obviously only works for interfaces (devices) that are
 actually present on the system.

 The binding for the reverse operation `if_indextoname()` has also been
 added, although its usage is a bit more cumbersome due to LibC::Char*
 buffer handling. The necessary buffer length has been placed into the
 constant `LibC::IF_NAMESIZE`, which appears to be `16u8` on unix-like
 systems and `257u16` on windows.
 This could potentially be reworked via a preprocessor block at
 compile-time as indicated by some folks over on discord, I currently do
 not know how to achieve that though.

Scoped identifiers are only valid for link-local (`fe80::`) addresses,
e.g. `fe80::1%eth0`

References:
  - https://datatracker.ietf.org/doc/html/rfc4007

TODO (to be resolved during the PR discussion):
 - discuss the preprocessor option for retrieving the constant value
   `IF_NAMESIZE` (No clue how do that, haven't found any event of this
   constant ever changing in the past, might not be worth the trouble?)
 - clarify whether scope_id parsing should raise `ArgumentError` or
   `Socket::Error`
 - clarify whether `Socket::Address` spec `#scope_id` `looks up
   interface name by index` should remain in the `Socket::Address` spec,
   since it only calls the `LibC` binding

I'm happy to adjust/rebase if needed based on feedback or other merges
into `master` in the mean time.
@straight-shoota
Copy link
Member

straight-shoota commented Dec 10, 2024

Could you please open an issue as a feature request first? We ask this to separate high-level discussion of the feature (in the issue discussion) from details of this specific PR (PR discussion). Ref: https://github.com/crystal-lang/crystal/blob/master/CONTRIBUTING.md#using-the-issue-tracker

I'm marking this PR as draft for now.

@foxxx0
Copy link
Author

foxxx0 commented Dec 10, 2024

ah well, shame on me.

I've just created #15264 now to discuss the feature itself.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

IPv6 scoped link-local addresses (RFC4007)
2 participants