Skip to content

feat(ServiceDaemon): possibility to use a specific network interface - #119

Closed
Marcondiro wants to merge 6 commits into
keepsimple1:mainfrom
Marcondiro:main
Closed

Marcondiro wants to merge 6 commits into
keepsimple1:mainfrom
Marcondiro:main

Conversation

@Marcondiro

Copy link
Copy Markdown

Add the possibility of using a specific network interface using the on_interface constructor function.

The addition is not a breaking change.

Hello, for my use case I need to use a specific network interface (that is also using a link local address) so I added this feature to your fantastic library.

If you think this could be useful (I do 😁) consider merging this PR or let me know if you want me to change something before merging.

Add the possibility of using a specific network interface using the on_interface constructor function. The addition is not a breaking change.

@keepsimple1 keepsimple1 left a comment •

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Thank you for your PR! Overall looks good to me. I have a couple of comments inline. A general comment: could you please add test(s)? At least testing the new API on_interface.

(There are minor fmt errors in GitHub actions workflow that need to fix)

Comment thread src/service_daemon.rs Resolved
Comment thread src/service_daemon.rs
///
/// The daemon (re)uses the default mDNS port 5353. To keep it simple, we don't
/// ask callers to set the port.
pub fn on_interface(interface: &str) -> Result<Self> {

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Can you specify or give examples about the interface string?

@keepsimple1
keepsimple1 marked this pull request as ready for review September 2, 2023 16:37
@Marcondiro

Copy link
Copy Markdown
Author

I still have to add the tests 🙂

@keepsimple1 keepsimple1 left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Thanks for your updates.

I also have a related thought: a different way to support interface filter is to add a new option in enum DaemonOption, instead of a new constructor. But because we create intf_socks in Zeroconf::new(), it seems a bit better to filter them during new(). So I think a new constructor is fine. Just sharing my thought anyway.

Comment thread Cargo.toml Outdated
[package]
name = "mdns-sd"
version = "0.7.4"
rust-version = "1.60.0"

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

👍

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

And it's okay to bump up it a bit, just not too recent (for example 1.70 is too recent)

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Updated to 1.61, on 1.60 tests are failing because of a dependency.

Comment thread src/service_daemon.rs
}

/// Creates a new daemon using a specific `interface` and spawns a thread to run the daemon.
///

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Can you add a bit more comment here to describe what it means to use a specific interface?

For example, something like: "the daemon will limit its service browsing and service publishing to this interface only". Feel free to word differently.

Comment thread src/service_daemon.rs Outdated

/// Returns valid IPv4 interfaces in the host system.
fn my_ipv4_interfaces() -> Vec<Ifv4Addr> {
fn my_ipv4_interfaces(interface: Option<&str>) -> Vec<Ifv4Addr> {

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

With this change, I realized that the name my_ipv4_interfaces seems not very accurate because it returns only the address info. How about renaming it to my_ipv4_addrs ?

@keepsimple1
keepsimple1 self-requested a review September 5, 2023 05:10
@keepsimple1

Copy link
Copy Markdown
Owner

I still have to add the tests 🙂

@keepsimple1 keepsimple1 closed this Sep 5, 2023
@keepsimple1 keepsimple1 reopened this Sep 5, 2023
@keepsimple1

Copy link
Copy Markdown
Owner

It was closed briefly by mistake, Sorry. I was trying to post a comment saying "I will review again after you add the test".

@Marcondiro

Copy link
Copy Markdown
Author

One question: why do you bind the sockets to 0.0.0.0 ?

let sock = new_socket(Ipv4Addr::new(0, 0, 0, 0), MDNS_PORT, true)?;

@keepsimple1

Copy link
Copy Markdown
Owner

One question: why do you bind the sockets to 0.0.0.0 ?

As I recall, if we bind the socket to a specific address, the join_multicast_v4 and/or set_multicast_if_v4 fails. Does this cause any issues for you?

@Marcondiro

Copy link
Copy Markdown
Author

One question: why do you bind the sockets to 0.0.0.0 ?

As I recall, if we bind the socket to a specific address, the join_multicast_v4 and/or set_multicast_if_v4 fails. Does this cause any issues for you?

Oh, ok thanks. I would prefer to generate traffic only on the interface specified

@keepsimple1

Copy link
Copy Markdown
Owner

One question: why do you bind the sockets to 0.0.0.0 ?

As I recall, if we bind the socket to a specific address, the join_multicast_v4 and/or set_multicast_if_v4 fails. Does this cause any issues for you?

Oh, ok thanks. I would prefer to generate traffic only on the interface specified

Although we bind to INADDR_ANY (0.0.0.0), the multicast traffic only generates on the interface specified. Btw we don't support unicast at this point. If that's not the case for you, then we shall try to fix.

@keepsimple1

Copy link
Copy Markdown
Owner

Just wanted to let you know, I've posted a new release to fix issue #121 . So you would need to update your diff to resolve conflicts. And if you encountered any problems when adding the test, please let me know.

@Marcondiro

Copy link
Copy Markdown
Author

Just wanted to let you know, I've posted a new release to fix issue #121 . So you would need to update your diff to resolve conflicts. And if you encountered any problems when adding the test, please let me know.

Merged, thanks!
I'm sorry but I won't have time to work on this in the short/middle term :(

@keepsimple1 keepsimple1 left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

No problem, whenever you have time.

@keepsimple1 keepsimple1 mentioned this pull request Oct 9, 2023
8 tasks done
@keepsimple1

keepsimple1 commented Oct 16, 2023 •

Copy link
Copy Markdown
Owner

I have created a new PR that solves a problem and support this feature at the same time: #137 . Please take a look if you have time. Any comments are appreciated.

Btw, with this change, you would do the following two steps to use a specific network interface:

daemon.disable_interface(IfKind::All)?;
daemon.enable_interface(IfKind::Name("en0".to_string()))?;

What do you think? The IfKind::Name("en0".to_string()) part could be replaced by just "en0" if needed, by implementing the trait for &str.

@Marcondiro

Copy link
Copy Markdown
Author

That's awesome, thank you! :)

@Marcondiro Marcondiro closed this Oct 18, 2023
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