From ca169c9e8be3ade4627acdb9460663a755cb9a64 Mon Sep 17 00:00:00 2001 From: Yu Watanabe Date: Wed, 7 Aug 2024 15:03:59 +0900 Subject: [PATCH] network-generator: vlan= can be specified multiple times (cherry picked from commit 9eee6b1b3f00d46459eebefb70be50ea6af30ddb) (cherry picked from commit f3baba94425e6ccaf7a672903148dbb2b9e022f7) (cherry picked from commit be571ff64808c30c1d5566600c86084768138bc4) --- src/network/generator/network-generator.c | 8 ++++---- src/network/generator/network-generator.h | 2 +- src/network/generator/test-network-generator.c | 3 ++- 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/src/network/generator/network-generator.c b/src/network/generator/network-generator.c index cf9305ea10..ce424d83e1 100644 --- a/src/network/generator/network-generator.c +++ b/src/network/generator/network-generator.c @@ -159,7 +159,7 @@ static Network *network_free(Network *network) { free(network->ifname); free(network->hostname); strv_free(network->dns); - free(network->vlan); + strv_free(network->vlan); free(network->bridge); free(network->bond); @@ -509,7 +509,7 @@ static int network_set_vlan(Context *context, const char *ifname, const char *va return r; } - return free_and_strdup(&network->vlan, value); + return strv_extend(&network->vlan, value); } static int network_set_bridge(Context *context, const char *ifname, const char *value) { @@ -1283,8 +1283,8 @@ void network_dump(Network *network, FILE *f) { STRV_FOREACH(dns, network->dns) fprintf(f, "DNS=%s\n", *dns); - if (network->vlan) - fprintf(f, "VLAN=%s\n", network->vlan); + STRV_FOREACH(v, network->vlan) + fprintf(f, "VLAN=%s\n", *v); if (network->bridge) fprintf(f, "Bridge=%s\n", network->bridge); diff --git a/src/network/generator/network-generator.h b/src/network/generator/network-generator.h index 0e0da2a57a..08e6ac9c1a 100644 --- a/src/network/generator/network-generator.h +++ b/src/network/generator/network-generator.h @@ -61,7 +61,7 @@ struct Network { /* [Network] */ DHCPType dhcp_type; char **dns; - char *vlan; + char **vlan; char *bridge; char *bond; diff --git a/src/network/generator/test-network-generator.c b/src/network/generator/test-network-generator.c index 318b9e98c3..26a37fd4f6 100644 --- a/src/network/generator/test-network-generator.c +++ b/src/network/generator/test-network-generator.c @@ -280,12 +280,13 @@ int main(int argc, char *argv[]) { "UseDNS=yes\n" ); - test_network_one("eth0", "vlan", "vlan99:eth0", + test_network_two("eth0", "vlan", "vlan99:eth0", "vlan", "vlan98:eth0", "[Match]\n" "Name=eth0\n" "\n[Link]\n" "\n[Network]\n" "VLAN=vlan99\n" + "VLAN=vlan98\n" "\n[DHCP]\n" );