network-generator: allow to create bridge or friends without slave interfaces

This commit is contained in:
Yu Watanabe
2024-08-09 19:01:40 +09:00
parent 9eee6b1b3f
commit c40ef3f8ff
2 changed files with 34 additions and 8 deletions

View 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;

View 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"