]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
network-generator: allow to create bridge or friends without slave interfaces
authorYu Watanabe <watanabe.yu+github@gmail.com>
Fri, 9 Aug 2024 10:01:40 +0000 (19:01 +0900)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Fri, 9 Aug 2024 10:11:49 +0000 (19:11 +0900)
src/network/generator/network-generator.c
src/network/generator/test-network-generator.c

index de8340ac71b76d54faf8d92c552b945eb126031d..8c96598e2045057413b3d7148f12613ad582f3ad 100644 (file)
@@ -532,7 +532,9 @@ static int network_set_vlan(Context *context, const char *ifname, const char *va
         int r;
 
         assert(context);
-        assert(ifname);
+
+        if (isempty(ifname))
+                return 0;
 
         network = network_get(context, ifname);
         if (!network) {
@@ -549,7 +551,9 @@ static int network_set_bridge(Context *context, const char *ifname, const char *
         int r;
 
         assert(context);
-        assert(ifname);
+
+        if (isempty(ifname))
+                return 0;
 
         network = network_get(context, ifname);
         if (!network) {
@@ -566,7 +570,9 @@ static int network_set_bond(Context *context, const char *ifname, const char *va
         int r;
 
         assert(context);
-        assert(ifname);
+
+        if (isempty(ifname))
+                return 0;
 
         network = network_get(context, ifname);
         if (!network) {
@@ -1011,8 +1017,6 @@ static int parse_cmdline_bridge(Context *context, const char *key, const char *v
         }
 
         p++;
-        if (isempty(p))
-                return log_debug_errno(SYNTHETIC_ERRNO(EINVAL), "Missing slave interfaces for bridge '%s'", name);
 
         for (;;) {
                 _cleanup_free_ char *word = NULL;
@@ -1060,9 +1064,6 @@ static int parse_cmdline_bond(Context *context, const char *key, const char *val
         else
                 slaves = strndupa_safe(value, p - value);
 
-        if (isempty(slaves))
-                return log_debug_errno(SYNTHETIC_ERRNO(EINVAL), "Missing slave interfaces for bond '%s'", name);
-
         for (const char *q = slaves; ; ) {
                 _cleanup_free_ char *word = NULL;
 
index 6577f1a086086227447c76ff8c7c40ca2c717caa..436b6b820d9acf263aba57d7dbfc4fbfddc181d7 100644 (file)
@@ -343,6 +343,31 @@ int main(int argc, char *argv[]) {
                          "\n[DHCP]\n"
                          );
 
+        test_netdev_one("bridge99", "bridge", "bridge99:",
+                        "[NetDev]\n"
+                        "Kind=bridge\n"
+                        "Name=bridge99\n"
+                        );
+
+        test_netdev_one("bridge99", "bridge", "bridge99:,,,",
+                        "[NetDev]\n"
+                        "Kind=bridge\n"
+                        "Name=bridge99\n"
+                        );
+
+        test_netdev_one("bond99", "bond", "bond99:",
+                        "[NetDev]\n"
+                        "Kind=bond\n"
+                        "Name=bond99\n"
+                        );
+
+        test_netdev_one("bond99", "bond", "bond99::hogehoge:1530",
+                        "[NetDev]\n"
+                        "Kind=bond\n"
+                        "Name=bond99\n"
+                        "MTUBytes=1530\n"
+                        );
+
         test_netdev_one("bond99", "bond", "bond99:eth0,eth1::1530",
                         "[NetDev]\n"
                         "Kind=bond\n"