Skip to contentSkip to conversation

MulticastDNS for all connections

DISCUSSION Andrea Pappacoda 2 participants 6 messages Oct 29, 2022 – Nov 2, 2022

lore
Share & tools
lore
#0 lore raw

Hi all!

I have a question regarding the usage of iwd, specifically about the MulticastDNS option. Is it possible to enable it for all the networks?

The iwd.network(5) manual page mentions that one can enable MulticastDNS for a particular network, but it also says that "The group [Network] contains general network settings and any network specific overrides for global defaults defined in the main iwd configuration file.". Unfortunately though, setting MulticastDNS=true in /etc/iwd/main.conf does not lead to my desired result.

I'm not using neither systemd-networkd, ConnMan nor NetworkManager.

If this is not the most appropriate place where to discuss about feature requests, feel free to redirect me to the right place :)

Thanks!

#1 lore raw
Quoted 14 lines · Andrea Pappacoda

Hi all!

I have a question regarding the usage of iwd, specifically about the MulticastDNS option. Is it possible to enable it for all the networks?

The iwd.network(5) manual page mentions that one can enable MulticastDNS for a particular network, but it also says that "The group
[Network] contains general network settings and any network specific overrides for global defaults defined in the main iwd configuration file.". Unfortunately though, setting MulticastDNS=true in /etc/iwd/main.conf does not lead to my desired result.

Quoted 6 lines

I'm not using neither systemd-networkd, ConnMan nor NetworkManager.

If this is not the most appropriate place where to discuss about feature requests, feel free to redirect me to the right place :)

Thanks!

First, I don't know much about mDNS :) but anyways...

Currently the MulticastDNS option is only per-network, but systemd- resolved has a global setting itself according to the docs [1].

But I actually wonder if event setting MulticastDNS in IWD is doing anything:

"Multicast DNS will be enabled on a link only if the per-link and the global setting is on."

This would imply you need to set /etc/systemd/resolved.conf with MulticastDNS=true to even use mDNS at all? Or maybe you have already done this? And I see the problem, per-link settings are only in systemd-networkd, which you don't use...

Like I said, I don't know much about mDNS but would a global option 'break' networks which don't support mDNS? Are you frequently connecting to many networks and needed to add this option to the profile each time?

The fact that this depends on setting systemd-resolved's global option and the per-link option I would say this really should stay in systemd-
* itself. The IWD setting is kinda useless without the global option anyways. Plus systemd-networkd is much more flexible, you can match based on all kinds of things where IWD is very rigid (global or per- network).

[1] https://www.freedesktop.org/software/systemd/man/resolved.conf.html

Quoted 3 lines
#2 lore raw

Hi James, thanks for your reply :)

Il giorno mar 1 nov 2022 alle 13:54:36 -07:00:00, James Prestwood <[email protected]> ha scritto:

Quoted 6 lines

Currently the MulticastDNS option is only per-network, but systemd- resolved has a global setting itself according to the docs [1].

But I actually wonder if event setting MulticastDNS in IWD is doing anything:

Quoted 7 lines

"Multicast DNS will be enabled on a link only if the per-link and the global setting is on."

This would imply you need to set /etc/systemd/resolved.conf with MulticastDNS=true to even use mDNS at all? Or maybe you have already done this? And I see the problem, per-link settings are only in systemd-networkd, which you don't use...

Yes, MulticastDNS needs to be enabled globally in resolved.conf (it is enabled by default) and also be enabled by whoever is managing the network interface.

Enabling mDNS in specific networks by adding MulticastDNS=true in /var/lib/iwd/network-name works as expected.

Quoted 4 lines

Like I said, I don't know much about mDNS but would a global option 'break' networks which don't support mDNS? Are you frequently connecting to many networks and needed to add this option to the profile each time?

I used to have mDNS globally enabled in NetworkManager, and it never created issues. As far as I understand, enabling mDNS simply allows you do to Multicast DNS queries on that network; it shouldn't interfere with non-multicast queries. I use mDNS every once in a while (on three different networks since last week), so I'd like to simply enable the global setting and forget about it.

Quoted 6 lines

The fact that this depends on setting systemd-resolved's global option and the per-link option I would say this really should stay in systemd-
* itself. The IWD setting is kinda useless without the global option anyways. Plus systemd-networkd is much more flexible, you can match based on all kinds of things where IWD is very rigid (global or per- network).

iwd has an option that enables it to replace other network managers for simple use cases, EnableNetworkConfiguration=true, so it seems reasonable for somebody to not have any other connection manager installed, and for those use cases I'd say that iwd's coarseness is fine. I've applied a quick and dirty patch on top of version 1.30, and it seems to work without issues; mdns_global probably leaks, but this can't be applied on master anyway and I was just trying to figure out how easy it would be to add this feature.

src/netconfig.c +0 -0
index 4a70b0ca..3e3c36a9 100644
@@ -95,6 +95,7 @@ static struct l_queue *netconfig_list;
 */

static uint32_t ROUTE_PRIORITY_OFFSET;
static bool ipv6_enabled;
+static char* mdns_global;

static void do_debug(const char *str, void *user_data)
{
@@ -1432,6 +1433,11 @@ bool netconfig_load_settings(struct netconfig *netconfig,

	mdns = l_settings_get_string(active_settings,
					"Network", "MulticastDNS");

+ if (!mdns) {
+ const size_t mdns_global_size = strlen(mdns_global) + 1;
+ mdns = malloc(mdns_global_size);
+ memcpy(mdns, mdns_global, mdns_global_size);
+ }

	if (l_settings_has_key(active_settings, "IPv4", "Address")) {
		v4_address = netconfig_get_static4_address(active_settings);
@@ -1757,6 +1763,8 @@ static int netconfig_init(void)
					&ipv6_enabled))
		ipv6_enabled = false;

+ mdns_global = l_settings_get_string(iwd_get_config(), "Network", "MulticastDNS");
+

	netconfig_list = l_queue_new();

	return 0;
#3 lore raw
Quoted 53 lines · Andrea Pappacoda

Hi James, thanks for your reply :)

Il giorno mar 1 nov 2022 alle 13:54:36 -07:00:00, James Prestwood <[email protected]> ha scritto:

Quoted 10 lines

Currently the MulticastDNS option is only per-network, but systemd- resolved has a global setting itself according to the docs [1].

But I actually wonder if event setting MulticastDNS in IWD is doing anything:

"Multicast DNS will be enabled on a link only if the per-link and the
global setting is on."

Quoted 5 lines

This would imply you need to set /etc/systemd/resolved.conf with MulticastDNS=true to even use mDNS at all? Or maybe you have already
done this? And I see the problem, per-link settings are only in systemd-networkd, which you don't use...

Yes, MulticastDNS needs to be enabled globally in resolved.conf (it is
enabled by default) and also be enabled by whoever is managing the network interface.

Enabling mDNS in specific networks by adding MulticastDNS=true in /var/lib/iwd/network-name works as expected.

Quoted 4 lines

Like I said, I don't know much about mDNS but would a global option 'break' networks which don't support mDNS? Are you frequently connecting to many networks and needed to add this option to the profile each time?

I used to have mDNS globally enabled in NetworkManager, and it never created issues. As far as I understand, enabling mDNS simply allows you
do to Multicast DNS queries on that network; it shouldn't interfere with non-multicast queries. I use mDNS every once in a while (on three
different networks since last week), so I'd like to simply enable the global setting and forget about it.

Quoted 10 lines

The fact that this depends on setting systemd-resolved's global option
and the per-link option I would say this really should stay in systemd-
* itself. The IWD setting is kinda useless without the global option
anyways. Plus systemd-networkd is much more flexible, you can match based on all kinds of things where IWD is very rigid (global or per-
network).

Quoted 11 lines

iwd has an option that enables it to replace other network managers for
simple use cases, EnableNetworkConfiguration=true, so it seems reasonable for somebody to not have any other connection manager installed, and for those use cases I'd say that iwd's coarseness is fine. I've applied a quick and dirty patch on top of version 1.30, and
it seems to work without issues; mdns_global probably leaks, but this can't be applied on master anyway and I was just trying to figure out how easy it would be to add this feature.

I've attached a patch if you want to try it out. I quickly tested only that "resolvectl status" showed +mDNS or -mDNS depending on what it was set to. In actuality this is probably enough since all we do is set the value to systemd and let it handle it.

From 67ca889a3075f59b03f857e2ae548a21e7738349 Mon Sep 17 00:00:00 2001
From: James Prestwood <[email protected]>
Date: Wed, 2 Nov 2022 13:35:53 -0700
Subject: [PATCH] netconfig: add global MulticastDNS option

Adds the MulticastDNS option globally to main.conf. If set all network connections (when netconfig is enabled) will set mDNS support into the resolver. Note that an individual network profile can still override the global value if it sets MulticastDNS.

---
 src/netconfig.c | 22 +++++++++++++++-------
 1 file changed, 15 insertions(+), 7 deletions(-)
src/netconfig.c +15 -7
index e6779d7c..8b798e0b 100644
@@ -56,6 +56,7 @@
  */
 static uint32_t ROUTE_PRIORITY_OFFSET;
 static bool ipv6_enabled;
+static char *mdns_global;
 
 static void do_debug(const char *str, void *user_data)
 {
@@ -396,13 +397,16 @@ send_hostname:
 	}
 
 mdns:
-	if (l_settings_has_key(active_settings, "Network", "MulticastDNS") &&
-			!(mdns = l_settings_get_string(active_settings,
-							"Network",
-							"MulticastDNS"))) {
-		l_error("netconfig: Can't load Network.MulticastDNS");
-		success = false;
-	}
+	/* If the networks has this set take that over the global */
+	if (l_settings_has_key(active_settings, "Network", "MulticastDNS")) {
+		mdns = l_settings_get_string(active_settings, "Network",
+							"MulticastDNS");
+		if (!mdns) {
+			l_error("netconfig: Can't load Network.MulticastDNS");
+			success = false;
+		}
+	} else if (mdns_global)
+		mdns = l_strdup(mdns_global);
 
 	if (mdns && !L_IN_STRSET(mdns, "true", "false", "resolve")) {
 		l_error("netconfig: Bad Network.MulticastDNS value '%s'", mdns);
@@ -753,11 +757,15 @@ static int netconfig_init(void)
 					&ipv6_enabled))
 		ipv6_enabled = false;
 
+	mdns_global = l_settings_get_string(iwd_get_config(), "Network",
+						"MulticastDNS");
+
 	return 0;
 }
 
 static void netconfig_exit(void)
 {
+	l_free(mdns_global);
 }
 
 IWD_MODULE(netconfig, netconfig_init, netconfig_exit)
Signature · 1 line
2.34.3
#4 lore raw

Il giorno mer 2 nov 2022 alle 13:47:57 -07:00:00, James Prestwood <[email protected]> ha scritto:

Quoted 4 lines

I've attached a patch if you want to try it out. I quickly tested only that "resolvectl status" showed +mDNS or -mDNS depending on what it was set to. In actuality this is probably enough since all we do is set the value to systemd and let it handle it.

Thanks James, I can confirm that this works for me too.

I'll be using this patch locally for the time being, but it would be great to get this merged; I can update the documentation too and submit everything as a patch to the mailing list if you want (of course, you could do this yourself if you prefer) :)

Thanks again!

#5 lore raw
Quoted 10 lines · Andrea Pappacoda

Il giorno mer 2 nov 2022 alle 13:47:57 -07:00:00, James Prestwood <[email protected]> ha scritto:

Quoted 7 lines

I've attached a patch if you want to try it out. I quickly tested only
that "resolvectl status" showed +mDNS or -mDNS depending on what it was
set to. In actuality this is probably enough since all we do is set the
value to systemd and let it handle it.

Quoted 7 lines

Thanks James, I can confirm that this works for me too.

I'll be using this patch locally for the time being, but it would be great to get this merged; I can update the documentation too and submit
everything as a patch to the mailing list if you want (of course, you could do this yourself if you prefer) :)

I think Denis could merge the patch I attached, if he's ok with it of course. If you want to do the documentation go for it! If not I'll get around to it this week.

Thanks,
James

Quoted 4 lines

Thanks again!