Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions pkg/cidata/cidata.TEMPLATE.d/boot/06-enable-mdns-on-systemd.sh
Copy link
Member

Choose a reason for hiding this comment

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

Doesn't this work with other drivers with lima:shared ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It works.

$ limactl start --name bridged --tty=false --network=lima:bridged --containerd=none --log-level=error
...
$ ping -c 1 lima-bridged.local
PING lima-bridged.local (192.168.12.43): 56 data bytes
64 bytes from 192.168.12.43: icmp_seq=0 ttl=64 time=1.068 ms

--- lima-bridged.local ping statistics ---
1 packets transmitted, 1 packets received, 0.0% packet loss
round-trip min/avg/max/stddev = 1.068/1.068/1.068/nan ms
$ limactl start --name host-only --tty=false --network=lima:host --containerd=none --log-level=error
...
$ ping -c 1 lima-host-only.local
PING lima-host-only.local (192.168.106.2): 56 data bytes
64 bytes from 192.168.106.2: icmp_seq=0 ttl=64 time=1.090 ms

--- lima-host-only.local ping statistics ---
1 packets transmitted, 1 packets received, 0.0% packet loss
round-trip min/avg/max/stddev = 1.090/1.090/1.090/nan ms

Copy link
Member

Choose a reason for hiding this comment

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

Does it work with QEMU, krunkit, and other potential drivers too?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sorry, PR's title was not correct. Fixed.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'll test with other drivers on macOS.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It works with qemu and krunkit.

$ ping -c 1 lima-qemu.local
PING lima-qemu.local (192.168.105.6): 56 data bytes
64 bytes from 192.168.105.6: icmp_seq=0 ttl=64 time=0.748 ms

--- lima-qemu.local ping statistics ---
1 packets transmitted, 1 packets received, 0.0% packet loss
round-trip min/avg/max/stddev = 0.748/0.748/0.748/0.000 ms
$ ping -c 1 lima-krunkit.local
PING lima-krunkit.local (192.168.105.5): 56 data bytes
64 bytes from 192.168.105.5: icmp_seq=0 ttl=64 time=1.005 ms

--- lima-krunkit.local ping statistics ---
1 packets transmitted, 1 packets received, 0.0% packet loss
round-trip min/avg/max/stddev = 1.005/1.005/1.005/nan ms

Is there already a way to limit the execution of the boot script by the host OS?

Copy link
Member

Choose a reason for hiding this comment

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

The script shouldn't care about the host OS. There should be a CIDATA variable that indicates the existence of IP-reachable network.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

At first, I tried to enable mDNS on the corresponding interface when Direct IP was detected, not as a boot script.
However, if there is no mDNS environment on the host OS side, I thought it would be meaningless to enable it, so I wanted to limit it to macOS.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Moved 06-enable-mdns-on-systemd.sh from pkg/driver/vz to pkg/cidata.

Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#!/bin/bash

# SPDX-FileCopyrightText: Copyright The Lima Authors
# SPDX-License-Identifier: Apache-2.0

set -eux -o pipefail

# Do nothing on OpenRC systems (e.g., Alpine Linux)
if [[ -f /sbin/openrc-run ]]; then
exit 0
fi

# It depends on systemd-resolved
command -v systemctl >/dev/null 2>&1 || exit 0
command -v resolvectl >/dev/null 2>&1 || exit 0

# Configure systemd-resolved to enable mDNS resolution globally
enable_mdns_conf_path=/etc/systemd/resolved.conf.d/00-lima-enable-mdns.conf
enable_mdns_conf_content="[Resolve]
MulticastDNS=yes
"
# Create /etc/systemd/resolved.conf.d/00-lima-enable-mdns.conf if its content is different
if ! diff -q <(echo "${enable_mdns_conf_content}") "${enable_mdns_conf_path}" >/dev/null 2>&1; then
mkdir -p "$(dirname "${enable_mdns_conf_path}")"
echo "${enable_mdns_conf_content}" >"${enable_mdns_conf_path}"
systemctl daemon-reload
systemctl restart systemd-resolved.service
fi

# On Ubuntu, systemd.network's configuration won't work.
# See: https://unix.stackexchange.com/a/652582
# So we need to enable mDNS per-link using resolvectl.
for iface in $(resolvectl status | sed -n -E 's/^Link +[0-9]+ \(([^)]+)\)/\1/p'); do
# This setting is volatile and will be lost on reboot, so we need to set it every time
resolvectl mdns "${iface}" yes
done