diff options
author | Yu Watanabe <watanabe.yu+github@gmail.com> | 2023-08-02 19:12:10 +0200 |
---|---|---|
committer | Yu Watanabe <watanabe.yu+github@gmail.com> | 2023-08-02 19:51:53 +0200 |
commit | c25aa6c8acc6d95eaacae7858a7057907d61a25e (patch) | |
tree | 26da33cabf8ac6275ea7b9f52f42d224b3b478c6 | |
parent | meson: fix name of test-network-generator (diff) | |
download | systemd-c25aa6c8acc6d95eaacae7858a7057907d61a25e.tar.xz systemd-c25aa6c8acc6d95eaacae7858a7057907d61a25e.zip |
network-generator: make network file generated from ip=dhcp matches only physical interfaces
Otherwise, it also matches later created virtual devices, and that
breaks networks generated and managed by container management services,
like docker.
Closes #28626.
3 files changed, 21 insertions, 10 deletions
diff --git a/src/network/generator/network-generator.c b/src/network/generator/network-generator.c index 823cd41f7e..f1bcc32591 100644 --- a/src/network/generator/network-generator.c +++ b/src/network/generator/network-generator.c @@ -1108,10 +1108,15 @@ void network_dump(Network *network, FILE *f) { assert(network); assert(f); - fprintf(f, - "[Match]\n" - "Name=%s\n", - isempty(network->ifname) ? "*" : network->ifname); + fputs("[Match]\n", f); + + if (isempty(network->ifname)) + /* If the interface name is not specified, then let's make the .network file match the all + * physical interfaces. */ + fputs("Kind=!*\n" + "Type=!loopback\n", f); + else + fprintf(f, "Name=%s\n", network->ifname); fputs("\n[Link]\n", f); diff --git a/src/network/generator/test-network-generator.c b/src/network/generator/test-network-generator.c index bcd4b1d9e4..318b9e98c3 100644 --- a/src/network/generator/test-network-generator.c +++ b/src/network/generator/test-network-generator.c @@ -65,7 +65,8 @@ static void test_link_one(const char *filename, const char *key, const char *val int main(int argc, char *argv[]) { test_network_one("", "ip", "dhcp6", "[Match]\n" - "Name=*\n" + "Kind=!*\n" + "Type=!loopback\n" "\n[Link]\n" "\n[Network]\n" "DHCP=ipv6\n" @@ -228,7 +229,8 @@ int main(int argc, char *argv[]) { test_network_one("", "rd.route", "10.1.2.3/16:10.0.2.3", "[Match]\n" - "Name=*\n" + "Kind=!*\n" + "Type=!loopback\n" "\n[Link]\n" "\n[Network]\n" "\n[DHCP]\n" @@ -250,7 +252,8 @@ int main(int argc, char *argv[]) { test_network_one("", "nameserver", "10.1.2.3", "[Match]\n" - "Name=*\n" + "Kind=!*\n" + "Type=!loopback\n" "\n[Link]\n" "\n[Network]\n" "DNS=10.1.2.3\n" @@ -259,7 +262,8 @@ int main(int argc, char *argv[]) { test_network_one("", "rd.peerdns", "0", "[Match]\n" - "Name=*\n" + "Kind=!*\n" + "Type=!loopback\n" "\n[Link]\n" "\n[Network]\n" "\n[DHCP]\n" @@ -268,7 +272,8 @@ int main(int argc, char *argv[]) { test_network_one("", "rd.peerdns", "1", "[Match]\n" - "Name=*\n" + "Kind=!*\n" + "Type=!loopback\n" "\n[Link]\n" "\n[Network]\n" "\n[DHCP]\n" diff --git a/test/test-network-generator-conversion/test-01-dhcp.expected/91-default.network b/test/test-network-generator-conversion/test-01-dhcp.expected/91-default.network index e42ce1e311..657cde79ae 100644 --- a/test/test-network-generator-conversion/test-01-dhcp.expected/91-default.network +++ b/test/test-network-generator-conversion/test-01-dhcp.expected/91-default.network @@ -1,7 +1,8 @@ # Automatically generated by systemd-network-generator [Match] -Name=* +Kind=!* +Type=!loopback [Link] |