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

Add setter and getter for multicast_ifv4 and multicast_ifv6 #1291

Merged
merged 6 commits into from
Jan 30, 2025

Conversation

al8n
Copy link
Contributor

@al8n al8n commented Jan 27, 2025

Hi, this is the PR for #1299.

Copy link
Member

@sunfishcode sunfishcode left a comment

Choose a reason for hiding this comment

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

Thanks for working on these!

pub fn set_ip_multicast_ifv4<Fd: AsFd>(fd: Fd, value: &Ipv4Addr) -> io::Result<()> {
backend::net::sockopt::set_ip_multicast_ifv4(fd.as_fd(), value)
}

Copy link
Member

Choose a reason for hiding this comment

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

The Linux docs for IP_MULTICAST_IF say "The argument for setsockopt(2) is an ip_mreqn or (since Linux 3.5) ip_mreq structure similar to IP_ADD_MEMBERSHIP, or an
in_addr structure.". Would it make sense here to also add set_ip_multicast_ifv4_with_ifindex, similar to the existing set_ip_add_membership_with_ifindex, which uses the ip_mreqn form?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, add it.

/// [module-level documentation]: self#references-for-get_ip_-and-set_ip_-functions
#[inline]
#[doc(alias = "IP_MULTICAST_IF")]
pub fn set_ip_multicast_ifv4<Fd: AsFd>(fd: Fd, value: &Ipv4Addr) -> io::Result<()> {
Copy link
Member

Choose a reason for hiding this comment

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

For naming, the *_ip_* names are all specific to IPv4, so we shouldn't need the v4 suffix here and in similar functions.

/// [module-level documentation]: self#references-for-get_ip_-and-set_ip_-functions
#[inline]
#[doc(alias = "IPV6_MULTICAST_IF")]
pub fn set_ip_multicast_ifv6<Fd: AsFd>(fd: Fd, value: u32) -> io::Result<()> {
Copy link
Member

Choose a reason for hiding this comment

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

IPv6 sockopt functions should use _ipv6_ instead of _ip_, and then they don't need a v6 suffix.

/// [module-level documentation]: self#references-for-get_ip_-and-set_ip_-functions
#[inline]
#[doc(alias = "IPV6_MULTICAST_IF")]
pub fn set_ip_multicast_ifv6<Fd: AsFd>(fd: Fd, value: u32) -> io::Result<()> {
Copy link
Member

Choose a reason for hiding this comment

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

Other sockopts that have an interface index argument use i32, rather than u32. Is there a reason to prefer u32?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hi, u32 is just for the compatible with socket2::set_multicast_if_v6.

Copy link
Member

Choose a reason for hiding this comment

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

Ah. Well, rustix is preparing for a major semver bump soon, so we can change that if we want. Or we can change set_ip_add_membership_with_ifindex and set_ip_drop_membership_with_ifindex to use u32. Which do you think is better?

Copy link
Contributor Author

@al8n al8n Jan 30, 2025

Choose a reason for hiding this comment

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

IMO, changing it to u32 is better:

  1. compatible with socket2's set_ip_add_membership_with_ifindex and set_ip_drop_membership_with_ifindex
  2. A negative interface index makes no sense and it is an invalid value, so u32 can avoid misusing.

Should I change it in this PR?

Copy link
Member

Choose a reason for hiding this comment

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

Yes, changing it in this PR would be good. Thanks!

@al8n al8n requested a review from sunfishcode January 30, 2025 16:51
@sunfishcode sunfishcode merged commit 06ad93d into bytecodealliance:main Jan 30, 2025
45 checks passed
@sunfishcode
Copy link
Member

Thanks!

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