From 821145bd0ab7268e5f092bd7e137d1de81c2cfb7 Mon Sep 17 00:00:00 2001 From: Nitesh Kumar Date: Tue, 23 Jul 2024 12:08:30 +0530 Subject: [PATCH 1/9] network-config-manager: Fix incorrect IPv6 config source Issue - nmctl status -j is showing ConfigSource as foreign for all kind of address like static, dynamic and foreign. Now on existing flow to get a link address info nmctl get the info from dbus and parse the info similar for address as well. While parsing the address from json object to ip, prefix length is not appended to address. Hence ip matching with address always failing for IPv6, cause of this ConfigSource always set to foreign regardless of address is static or dynamic. Fix - Fixed in json_array_to_ip parsing to take care of prefix value as well while returning the ip address after parsing the json object. --- src/json/network-json.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/json/network-json.c b/src/json/network-json.c index 61ee73cf..a4c3b261 100644 --- a/src/json/network-json.c +++ b/src/json/network-json.c @@ -1157,22 +1157,22 @@ static int json_array_to_ip(const json_object *obj, const int family, const int } } + if (prefix > 0) + g_string_append_printf(v, "/%d", prefix); + if (family == AF_INET6) { _auto_cleanup_ IPAddress *addr = NULL; int r; - r = parse_ipv6(v->str, &addr); + r = parse_ip_from_str(v->str, &addr); if (r < 0) return r; - r = ip_to_str(AF_INET6, addr, &ip); + r = ip_to_str_prefix(AF_INET6, addr, &ip); if (r < 0) return r; } - if (prefix > 0) - g_string_append_printf(v, "/%d", prefix); - if (family == AF_INET6) *ret = steal_ptr(ip); else { From 2a97fd33ab42a0d197847c13eb7e8fdeec5f249c Mon Sep 17 00:00:00 2001 From: Nitesh Kumar Date: Fri, 2 Aug 2024 13:28:42 +0530 Subject: [PATCH 2/9] LinkLocalAddressing: Fixing overriden LinkLocalAddressing Value. Issue: This issue exist with set-ipv4 and set-ipv6 command. While setting LinkLocalAddressing for both IPv4 and IPv6 one after another the LinkLocalAddressing only preserving the last command value in this case it would be LinkLocalAddressing=ipv6 instead it should be LinkLocalAddressing=yes. Fix: Addressing this issue in both commands now nmctl check for existing value and based on that it will update the LinkLocalAddressing parameter. --- src/manager/network-manager.c | 64 ++++++++++++++++++++++++++++------- src/manager/network-manager.h | 3 +- src/manager/network.c | 4 +-- src/manager/network.h | 2 +- 4 files changed, 56 insertions(+), 17 deletions(-) diff --git a/src/manager/network-manager.c b/src/manager/network-manager.c index 4c70c33c..a204e6e2 100644 --- a/src/manager/network-manager.c +++ b/src/manager/network-manager.c @@ -222,6 +222,28 @@ int manager_set_link_dhcp_client(const IfNameIndex *p, return dbus_network_reload(); } +int manager_acquire_link_local_addressing_kind(const IfNameIndex *p, LinkLocalAddress *lla_mode) { + _auto_cleanup_ char *network = NULL, *config_lla = NULL; + int r; + + assert(p); + + r = network_parse_link_network_file(p->ifindex, &network); + if (r < 0) + return r; + + r = parse_config_file(network, "Network", "LinkLocalAddressing", &config_lla); + if (r < 0) + return r; + + r = link_local_address_type_to_kind(config_lla); + if (r < 0) + return r; + + *lla_mode = r; + return 0; +} + int manager_acquire_link_dhcp_client_kind(const IfNameIndex *p, DHCPClient *mode) { _auto_cleanup_ char *network = NULL, *config_dhcp = NULL; int r; @@ -2686,7 +2708,7 @@ int manager_enable_ipv6(const IfNameIndex *i, bool enable) { int manager_set_ipv6(const IfNameIndex *p, const int dhcp, const int accept_ra, - const int lla, + int lla, char **addrs, Route *rt6, char **dns, @@ -2694,6 +2716,7 @@ int manager_set_ipv6(const IfNameIndex *p, const int send_release, bool keep) { + LinkLocalAddress lla_mode = _LINK_LOCAL_ADDRESS_INVALID; _cleanup_(key_file_freep) KeyFile *key_file = NULL; _cleanup_(section_freep) Section *section = NULL; DHCPClient mode = _DHCP_CLIENT_INVALID; @@ -2717,32 +2740,39 @@ int manager_set_ipv6(const IfNameIndex *p, if (dhcp > 0) { if (mode == DHCP_CLIENT_NO || mode == _DHCP_CLIENT_INVALID) set_config(key_file, "Network", "DHCP", "ipv6"); - else if (mode == DHCP_CLIENT_IPV4) + else if (mode == DHCP_CLIENT_IPV4) set_config(key_file, "Network", "DHCP", "yes"); /* Automatically turn on LinkLocalAddressing= and IPv6AcceptRA= */ - set_config(key_file, "Network", "LinkLocalAddressing", "ipv6"); + lla = LINK_LOCAL_ADDRESS_IPV6; set_config(key_file, "Network", "IPv6AcceptRA", "yes"); } else if (dhcp == DHCP_CLIENT_NO) { if (mode == DHCP_CLIENT_YES) set_config(key_file, "Network", "DHCP", "ipv4"); - else if (mode == DHCP_CLIENT_IPV6 || mode == _DHCP_CLIENT_INVALID) + else if (mode == DHCP_CLIENT_IPV6 || mode == _DHCP_CLIENT_INVALID) set_config(key_file, "Network", "DHCP", "no"); } /* override */ if (accept_ra >= 0) { if (accept_ra > 0) - set_config(key_file, "Network", "LinkLocalAddressing", "ipv6"); + lla = LINK_LOCAL_ADDRESS_IPV6; set_config(key_file, "Network", "IPv6AcceptRA", bool_to_str(accept_ra)); } - if (lla >= 0) { - r = key_file_set_str(key_file, "Network", "LinkLocalAddressing", link_local_address_type_to_name(lla)); - if (r < 0) - return r; + r = manager_acquire_link_local_addressing_kind(p, &lla_mode); + if (lla > 0) { + if (lla_mode == LINK_LOCAL_ADDRESS_NO || lla_mode == _LINK_LOCAL_ADDRESS_INVALID) + set_config(key_file, "Network", "LinkLocalAddressing", "ipv6"); + else if (lla_mode == LINK_LOCAL_ADDRESS_IPV4) + set_config(key_file, "Network", "LinkLocalAddressing", "yes"); + } else if (lla == LINK_LOCAL_ADDRESS_NO) { + if (lla_mode == LINK_LOCAL_ADDRESS_YES) + set_config(key_file, "Network", "LinkLocalAddressing", "ipv4"); + else if (lla_mode == LINK_LOCAL_ADDRESS_IPV4 || lla_mode == _LINK_LOCAL_ADDRESS_INVALID) + set_config(key_file, "Network", "LinkLocalAddressing", "no"); } if (dns) { @@ -2807,6 +2837,7 @@ int manager_set_ipv4(const IfNameIndex *p, bool keep) { _auto_cleanup_ char *network = NULL, *gw = NULL, *addr = NULL; + LinkLocalAddress lla_mode = _LINK_LOCAL_ADDRESS_INVALID; _cleanup_(key_file_freep) KeyFile *key_file = NULL; _cleanup_(section_freep) Section *section = NULL; DHCPClient mode = _DHCP_CLIENT_INVALID; @@ -2825,10 +2856,17 @@ int manager_set_ipv4(const IfNameIndex *p, if (r < 0) return r; - if (lla >= 0) { - r = key_file_set_str(key_file, "Network", "LinkLocalAddressing", link_local_address_type_to_name(lla)); - if (r < 0) - return r; + r = manager_acquire_link_local_addressing_kind(p, &lla_mode); + if (lla > 0) { + if (lla_mode == LINK_LOCAL_ADDRESS_NO || lla_mode == _LINK_LOCAL_ADDRESS_INVALID) + set_config(key_file, "Network", "LinkLocalAddressing", "ipv4"); + else if (lla_mode == LINK_LOCAL_ADDRESS_IPV6) + set_config(key_file, "Network", "LinkLocalAddressing", "yes"); + } else if (lla == LINK_LOCAL_ADDRESS_NO) { + if (lla_mode == LINK_LOCAL_ADDRESS_YES) + set_config(key_file, "Network", "LinkLocalAddressing", "ipv6"); + else if (lla_mode == LINK_LOCAL_ADDRESS_IPV4 || lla_mode == _LINK_LOCAL_ADDRESS_INVALID) + set_config(key_file, "Network", "LinkLocalAddressing", "no"); } r = manager_acquire_link_dhcp_client_kind(p, &mode); diff --git a/src/manager/network-manager.h b/src/manager/network-manager.h index 8ec8861d..22c543a7 100644 --- a/src/manager/network-manager.h +++ b/src/manager/network-manager.h @@ -148,6 +148,7 @@ int manager_network_dhcp4_section_configs_new(ConfigManager **ret); int manager_network_dhcp6_section_configs_new(ConfigManager **ret); int manager_network_link_section_configs_new(ConfigManager **ret); +int manager_acquire_link_local_addressing_kind(const IfNameIndex *p, LinkLocalAddress *lla_mode); int manager_set_link_local_address(const IfNameIndex *p, const char *k, const char *v); int manager_set_network_section_bool(const IfNameIndex *p, const char *k, bool v); int manager_set_network_section(const IfNameIndex *p, const char *k, const char *v); @@ -222,7 +223,7 @@ bool manager_config_exists(const char *section, const char *k, const char *v); int manager_set_ipv6(const IfNameIndex *p, const int dhcp, const int accept_ra, - const int lla, + int lla, char **addrs, Route *rt6, char **dns, diff --git a/src/manager/network.c b/src/manager/network.c index 38a40d23..420cb44c 100644 --- a/src/manager/network.c +++ b/src/manager/network.c @@ -131,8 +131,8 @@ int dhcp_client_duid_name_to_type(char *name) { } static const char *const link_local_address_type[_LINK_LOCAL_ADDRESS_MAX] = { - [LINK_LOCAL_ADDRESS_YES] = "yes", [LINK_LOCAL_ADDRESS_NO] = "no", + [LINK_LOCAL_ADDRESS_YES] = "yes", [LINK_LOCAL_ADDRESS_IPV4] = "ipv4", [LINK_LOCAL_ADDRESS_IPV6] = "ipv6", }; @@ -150,7 +150,7 @@ const char *link_local_address_type_to_name(int id) { int link_local_address_type_to_kind(const char *name) { assert(name); - for (size_t i = LINK_LOCAL_ADDRESS_YES; i < (size_t) ELEMENTSOF(link_local_address_type); i++) + for (size_t i = LINK_LOCAL_ADDRESS_NO; i < (size_t) ELEMENTSOF(link_local_address_type); i++) if (streq_fold(name, link_local_address_type[i])) return i; diff --git a/src/manager/network.h b/src/manager/network.h index 4932df8f..a87c72b3 100644 --- a/src/manager/network.h +++ b/src/manager/network.h @@ -37,8 +37,8 @@ typedef enum DHCPClientDUIDType { } DHCPClientDUIDType; typedef enum LinkLocalAddress { - LINK_LOCAL_ADDRESS_YES, LINK_LOCAL_ADDRESS_NO, + LINK_LOCAL_ADDRESS_YES, LINK_LOCAL_ADDRESS_IPV4, LINK_LOCAL_ADDRESS_IPV6, _LINK_LOCAL_ADDRESS_MAX, From 13b95fc2b8182e5e5fcd659c889b40a228db7352 Mon Sep 17 00:00:00 2001 From: Nitesh Kumar Date: Fri, 2 Aug 2024 14:01:56 +0530 Subject: [PATCH 3/9] DNS: Fix DNS= override issue in set-ipv4 and set-ipv6 command. Issue: While Setting DNS for IPv4 or IPv6 it always override the existing DNS with newly added one even its not duplicate. Fix: nmctl is now taking care of existing DNS value and newly added as well while setting IPv4 DNS or IPv6 DNS. It will keep all the unique DNS addresses irrespective of IPv4/IPv6. --- src/manager/network-config-manager.c | 2 ++ src/manager/network-manager.c | 46 ++++++++++++++++++++++++++-- 2 files changed, 46 insertions(+), 2 deletions(-) diff --git a/src/manager/network-config-manager.c b/src/manager/network-config-manager.c index 528aeb49..c675497d 100644 --- a/src/manager/network-config-manager.c +++ b/src/manager/network-config-manager.c @@ -4714,6 +4714,7 @@ _public_ int ncm_link_set_ipv6(int argc, char *argv[]) { return -EINVAL; } + dns = strv_remove_duplicates(dns); r = manager_set_ipv6(p, dhcp, accept_ra, lla, addrs, rt6, dns, use_dns, send_release, keep); if (r < 0) { log_warning("Failed to configure IPv6 on device '%s': %s", p->ifname, strerror(-r)); @@ -4877,6 +4878,7 @@ _public_ int ncm_link_set_ipv4(int argc, char *argv[]) { return -EINVAL; } + dns = strv_remove_duplicates(dns); r = manager_set_ipv4(p, lla, dhcp, addrs, rt4, dns, use_dns, send_release, keep); if (r < 0) { log_warning("Failed to configure IPv4 on device '%s': %s", p->ifname, strerror(-r)); diff --git a/src/manager/network-manager.c b/src/manager/network-manager.c index a204e6e2..e674ecf1 100644 --- a/src/manager/network-manager.c +++ b/src/manager/network-manager.c @@ -2719,8 +2719,10 @@ int manager_set_ipv6(const IfNameIndex *p, LinkLocalAddress lla_mode = _LINK_LOCAL_ADDRESS_INVALID; _cleanup_(key_file_freep) KeyFile *key_file = NULL; _cleanup_(section_freep) Section *section = NULL; + _auto_cleanup_strv_ char **s = NULL, **t = NULL; DHCPClient mode = _DHCP_CLIENT_INVALID; _auto_cleanup_ char *network = NULL; + char **l; int r; assert(p); @@ -2776,7 +2778,26 @@ int manager_set_ipv6(const IfNameIndex *p, } if (dns) { - r = set_config(key_file, "Network", "DNS", strv_join(" ", dns)); + if (keep) { + r = key_file_network_parse_dns(network, &s); + if (r < 0) + return r; + + if (strv_empty((const char **) s)) { + t = strv_dup(dns); + if (!t) + return log_oom(); + } else { + t = strv_unique(dns, s); + if (!t) + return log_oom(); + } + + l = t; + } else + l = dns; + + r = set_config(key_file, "Network", "DNS", strv_join(" ", l)); if (r < 0) { log_warning("Failed to write Network DNS= '%s': %s", network, strerror(-r)); return r; @@ -2840,7 +2861,9 @@ int manager_set_ipv4(const IfNameIndex *p, LinkLocalAddress lla_mode = _LINK_LOCAL_ADDRESS_INVALID; _cleanup_(key_file_freep) KeyFile *key_file = NULL; _cleanup_(section_freep) Section *section = NULL; + _auto_cleanup_strv_ char **s = NULL, **t = NULL; DHCPClient mode = _DHCP_CLIENT_INVALID; + char **l; int r; assert(p); @@ -2883,7 +2906,26 @@ int manager_set_ipv4(const IfNameIndex *p, } if (dns) { - r = set_config(key_file, "Network", "DNS", strv_join(" ", dns)); + if (keep) { + r = key_file_network_parse_dns(network, &s); + if (r < 0) + return r; + + if (strv_empty((const char **) s)) { + t = strv_dup(dns); + if (!t) + return log_oom(); + } else { + t = strv_unique(dns, s); + if (!t) + return log_oom(); + } + + l = t; + } else + l = dns; + + r = set_config(key_file, "Network", "DNS", strv_join(" ", l)); if (r < 0) { log_warning("Failed to write Network DNS= '%s': %s", network, strerror(-r)); return r; From b154a3e04d1ef4e03a2eb5256bb1ac4689005adb Mon Sep 17 00:00:00 2001 From: Nitesh Kumar Date: Fri, 2 Aug 2024 14:55:30 +0530 Subject: [PATCH 4/9] Domains: Adding an option to add Domains= using set-ipv4 and set-ipv4 command. Syntax - nmctl set-ipv4/set-ipv6 dev domains Example - nmctl set-ipv4 dev test99 domains example1.com,example2.com nmctl set-ipv6 dev test99 domains example3.com,example3.com --- src/manager/network-config-manager.c | 72 ++++++++++++++++++++++++++-- src/manager/network-manager-ctl.c | 4 +- src/manager/network-manager.c | 56 ++++++++++++++++++++++ src/manager/network-manager.h | 3 ++ 4 files changed, 129 insertions(+), 6 deletions(-) diff --git a/src/manager/network-config-manager.c b/src/manager/network-config-manager.c index c675497d..95bc2646 100644 --- a/src/manager/network-config-manager.c +++ b/src/manager/network-config-manager.c @@ -4555,7 +4555,7 @@ _public_ int ncm_link_enable_ipv6(int argc, char *argv[]) { _public_ int ncm_link_set_ipv6(int argc, char *argv[]) { int accept_ra = -1, dhcp = -1, use_dns = -1, lla = -1, send_release = -1; - _auto_cleanup_strv_ char **addrs = NULL, **dns = NULL; + _auto_cleanup_strv_ char **addrs = NULL, **dns = NULL, **domains = NULL; _auto_cleanup_ IfNameIndex *p = NULL; _auto_cleanup_ Route *rt6 = NULL; bool keep = true; @@ -4668,6 +4668,37 @@ _public_ int ncm_link_set_ipv6(int argc, char *argv[]) { return -EINVAL; } + continue; + } else if (streq_fold(argv[i], "domains")) { + parse_next_arg(argv, argc, i); + + if (strchr(argv[i], ',')) { + char **d; + + d = strsplit(argv[i], ",", -1); + if (!d) { + log_warning("Failed to parse DNS Search domains '%s': %s", argv[i], strerror(EINVAL)); + return -EINVAL; + } + + d = strv_remove(d, ""); + if (!d) { + log_warning("Failed to parse DNS Search domains '%s': %s", argv[i], strerror(EINVAL)); + return -EINVAL; + } + + if (!domains) + domains = d; + else { + domains = strv_merge(domains, d); + if (!domains) + return log_oom(); + } + } else { + r = strv_extend(&domains, argv[i]); + if (r < 0) + return log_oom(); + } continue; } else if (streq_fold(argv[i], "use-dns")) { parse_next_arg(argv, argc, i); @@ -4715,7 +4746,8 @@ _public_ int ncm_link_set_ipv6(int argc, char *argv[]) { } dns = strv_remove_duplicates(dns); - r = manager_set_ipv6(p, dhcp, accept_ra, lla, addrs, rt6, dns, use_dns, send_release, keep); + domains = strv_remove_duplicates(domains); + r = manager_set_ipv6(p, dhcp, accept_ra, lla, addrs, rt6, dns, domains, use_dns, send_release, keep); if (r < 0) { log_warning("Failed to configure IPv6 on device '%s': %s", p->ifname, strerror(-r)); return r; @@ -4725,8 +4757,8 @@ _public_ int ncm_link_set_ipv6(int argc, char *argv[]) { } _public_ int ncm_link_set_ipv4(int argc, char *argv[]) { + _auto_cleanup_strv_ char **addrs = NULL, **dns = NULL, **domains = NULL; int dhcp = -1, use_dns = -1, lla = -1, send_release = -1; - _auto_cleanup_strv_ char **addrs = NULL, **dns = NULL; _auto_cleanup_ IfNameIndex *p = NULL; _auto_cleanup_ Route *rt4 = NULL; bool keep = true; @@ -4820,6 +4852,37 @@ _public_ int ncm_link_set_ipv4(int argc, char *argv[]) { return -EINVAL; } + continue; + } else if (streq_fold(argv[i], "domains")) { + parse_next_arg(argv, argc, i); + + if (strchr(argv[i], ',')) { + char **d; + + d = strsplit(argv[i], ",", -1); + if (!d) { + log_warning("Failed to parse DNS Search domains '%s': %s", argv[i], strerror(EINVAL)); + return -EINVAL; + } + + d = strv_remove(d, ""); + if (!d) { + log_warning("Failed to parse DNS Search domains '%s': %s", argv[i], strerror(EINVAL)); + return -EINVAL; + } + + if (!domains) + domains = d; + else { + domains = strv_merge(domains, d); + if (!domains) + return log_oom(); + } + } else { + r = strv_extend(&domains, argv[i]); + if (r < 0) + return log_oom(); + } continue; } else if (streq_fold(argv[i], "use-dns")) { parse_next_arg(argv, argc, i); @@ -4879,7 +4942,8 @@ _public_ int ncm_link_set_ipv4(int argc, char *argv[]) { } dns = strv_remove_duplicates(dns); - r = manager_set_ipv4(p, lla, dhcp, addrs, rt4, dns, use_dns, send_release, keep); + domains = strv_remove_duplicates(domains); + r = manager_set_ipv4(p, lla, dhcp, addrs, rt4, dns, domains, use_dns, send_release, keep); if (r < 0) { log_warning("Failed to configure IPv4 on device '%s': %s", p->ifname, strerror(-r)); return r; diff --git a/src/manager/network-manager-ctl.c b/src/manager/network-manager-ctl.c index bd1a8ad3..018d7a56 100644 --- a/src/manager/network-manager-ctl.c +++ b/src/manager/network-manager-ctl.c @@ -216,10 +216,10 @@ static int help(void) { "\n\t\t\t\t route [Prefix ADDRESS] route-lifetime [LifetimeSec NUMBER] Configures IPv6 Router Advertisement.\n" " remove-ipv6ra dev [DEVICE] Removes Ipv6 Router Advertisement.\n" " enable-ipv6 dev [DEVICE] [BOOLEAN] Enable or disables IPv6 on the link.\n" - " set-ipv4 dev [DEVICE] dhcp [BOOLEAN] addr [ADDRESS] many [ADDRESS1,ADDRESS2...] gw|gw4|g [GATEWAY] dns [SERVER1,SERVER2...]" + " set-ipv4 dev [DEVICE] dhcp [BOOLEAN] addr [ADDRESS] many [ADDRESS1,ADDRESS2...] gw|gw4|g [GATEWAY] dns [SERVER1,SERVER2...] domains [DOMAIN1,DOMAIN2 ...]" "\n\t\t\t\t lla [BOOLEAN|ipv6|ipv4] use-dns [BOOLEAN send-release [BOOLEAN] keep [BOOLEAN] Configures device IPv4.\n" " set-ipv6 dev [DEVICE] accept-ra [BOOLEAN] dhcp [BOOLEAN] address|a|addr [ADDRESS] many [ADDRESS1,ADDRESS2...] gw|gw6|g [GATEWAY]" - "\n\t\t\t\t lla [BOOLEAN|ipv6|ipv4] dns [SERVER1,SERVER2...] use-dns [BOOLEAN] send-release [BOOLEAN] keep [BOOLEAN] Configures device IPv6.\n" + "\n\t\t\t\t lla [BOOLEAN|ipv6|ipv4] dns [SERVER1,SERVER2...] domains [DOMAIN1,DOMAIN2 ...] use-dns [BOOLEAN] send-release [BOOLEAN] keep [BOOLEAN] Configures device IPv6.\n" " add-sr-iov dev [DEVICE] [vf INTEGER] [vlanid INTEGER] [qos INTEGER] [vlanproto STRING] [macspoofck BOOLEAN] [qrss BOOLEAN]" "\n\t\t\t\t [trust BOOLEAN] [linkstate BOOLEAN or STRING] [macaddr ADDRESS] Configures SR-IOV VirtualFunction, " "\n\t\t\t\t VLANId, QualityOfService, VLANProtocol, MACSpoofCheck, QueryReceiveSideScaling, Trust, LinkState, MACAddress \n" diff --git a/src/manager/network-manager.c b/src/manager/network-manager.c index e674ecf1..a837bd46 100644 --- a/src/manager/network-manager.c +++ b/src/manager/network-manager.c @@ -2712,6 +2712,7 @@ int manager_set_ipv6(const IfNameIndex *p, char **addrs, Route *rt6, char **dns, + char **domains, const int use_dns, const int send_release, bool keep) { @@ -2804,6 +2805,33 @@ int manager_set_ipv6(const IfNameIndex *p, } } + if (domains) { + if (keep) { + r = key_file_network_parse_search_domains(network, &s); + if (r < 0) + return r; + + if (strv_empty((const char **) s)) { + t = strv_dup(domains); + if (!t) + return log_oom(); + } else { + t = strv_unique(domains, s); + if (!t) + return log_oom(); + } + + l = t; + } else + l = domains; + + r = set_config(key_file, "Network", "Domains", strv_join(" ", l)); + if (r < 0) { + log_warning("Failed to write Network Domains= '%s': %s", network, strerror(-r)); + return r; + } + } + if (use_dns >= 0) { r = key_file_set_str(key_file, "DHCPv6", "UseDNS", bool_to_str(use_dns)); if (r < 0) @@ -2853,6 +2881,7 @@ int manager_set_ipv4(const IfNameIndex *p, char **addrs, Route *rt4, char **dns, + char **domains, const int use_dns, const int send_release, bool keep) { @@ -2932,6 +2961,33 @@ int manager_set_ipv4(const IfNameIndex *p, } } + if (domains) { + if (keep) { + r = key_file_network_parse_search_domains(network, &s); + if (r < 0) + return r; + + if (strv_empty((const char **) s)) { + t = strv_dup(domains); + if (!t) + return log_oom(); + } else { + t = strv_unique(domains, s); + if (!t) + return log_oom(); + } + + l = t; + } else + l = domains; + + r = set_config(key_file, "Network", "Domains", strv_join(" ", l)); + if (r < 0) { + log_warning("Failed to write Network Domains= '%s': %s", network, strerror(-r)); + return r; + } + } + if (use_dns >= 0) { r = key_file_set_str(key_file, "DHCPv4", "UseDNS", bool_to_str(use_dns)); if (r < 0) diff --git a/src/manager/network-manager.h b/src/manager/network-manager.h index 22c543a7..2188a9ab 100644 --- a/src/manager/network-manager.h +++ b/src/manager/network-manager.h @@ -227,15 +227,18 @@ int manager_set_ipv6(const IfNameIndex *p, char **addrs, Route *rt6, char **dns, + char **domains, const int use_dns, const int send_release, const bool keep); + int manager_set_ipv4(const IfNameIndex *p, const int lla, const int dhcp, char **addrs, Route *rt4, char **dns, + char **domains, const int use_dns, const int send_release, bool keep); From e5d074d590019b630d6219f469be6bf2513c35de Mon Sep 17 00:00:00 2001 From: Nitesh Kumar Date: Fri, 2 Aug 2024 15:24:13 +0530 Subject: [PATCH 5/9] UseDomains: Adding an option to set UseDomains= using set-ipv4 and set-ipv6 command. Syntax: nmctl set-ipv4/set-ipv6 dev use-domains Example: nmctl set-ipv4 dev dummy1 use-domains yes nmctl set-ipv6 dev dummy1 use-domains route --- src/manager/network-config-manager.c | 38 ++++++++++++++++++++++++---- src/manager/network-manager-ctl.c | 4 +-- src/manager/network-manager.c | 14 ++++++++++ src/manager/network-manager.h | 2 ++ src/manager/network.c | 26 +++++++++++++++++++ src/manager/network.h | 11 ++++++++ 6 files changed, 88 insertions(+), 7 deletions(-) diff --git a/src/manager/network-config-manager.c b/src/manager/network-config-manager.c index 95bc2646..e8860dfe 100644 --- a/src/manager/network-config-manager.c +++ b/src/manager/network-config-manager.c @@ -4556,6 +4556,7 @@ _public_ int ncm_link_enable_ipv6(int argc, char *argv[]) { _public_ int ncm_link_set_ipv6(int argc, char *argv[]) { int accept_ra = -1, dhcp = -1, use_dns = -1, lla = -1, send_release = -1; _auto_cleanup_strv_ char **addrs = NULL, **dns = NULL, **domains = NULL; + UseDomains use_domains = _USE_DOMAINS_INVALID; _auto_cleanup_ IfNameIndex *p = NULL; _auto_cleanup_ Route *rt6 = NULL; bool keep = true; @@ -4570,7 +4571,8 @@ _public_ int ncm_link_set_ipv6(int argc, char *argv[]) { log_warning("Failed to find device: %s", argv[i]); return r; } - continue; + + continue; } else if (streq_fold(argv[i], "accept-ra") || streq_fold(argv[i], "ara")) { parse_next_arg(argv, argc, i); @@ -4579,6 +4581,7 @@ _public_ int ncm_link_set_ipv6(int argc, char *argv[]) { log_warning("Failed to parse accept-ra %s': %s", argv[i], strerror(-r)); return r; } + accept_ra = r; continue; } else if (streq_fold(argv[i], "lla") || streq_fold(argv[i], "link-local")) { @@ -4589,6 +4592,7 @@ _public_ int ncm_link_set_ipv6(int argc, char *argv[]) { log_warning("Failed to parse link-local %s': %s", argv[2], strerror(-r)); return r; } + lla = r; continue; } else if (streq_fold(argv[i], "dhcp")) { @@ -4599,6 +4603,7 @@ _public_ int ncm_link_set_ipv6(int argc, char *argv[]) { log_warning("Failed to parse dhcp: %s", argv[i]); return -EINVAL; } + dhcp = r; continue; } else if (streq_fold(argv[i], "gateway") || streq_fold(argv[i], "gw") || streq_fold(argv[i], "gw6") || streq_fold(argv[i], "g")) { @@ -4657,6 +4662,7 @@ _public_ int ncm_link_set_ipv6(int argc, char *argv[]) { log_warning("Failed to parse many addresses '%s': %s", argv[i], strerror(EINVAL)); return r; } + continue; } else if (streq_fold(argv[i], "dns")) { parse_next_arg(argv, argc, i); @@ -4699,6 +4705,7 @@ _public_ int ncm_link_set_ipv6(int argc, char *argv[]) { if (r < 0) return log_oom(); } + continue; } else if (streq_fold(argv[i], "use-dns")) { parse_next_arg(argv, argc, i); @@ -4711,7 +4718,16 @@ _public_ int ncm_link_set_ipv6(int argc, char *argv[]) { use_dns = r; continue; + } else if (streq_fold(argv[i], "use-domains")) { + parse_next_arg(argv, argc, i); + + use_domains = use_domains_name_to_mode(argv[i]); + if (use_domains < 0) { + log_warning("Failed to parse use-domains='%s': %s", argv[i], strerror(-r)); + return -EINVAL; + } + continue; } else if (streq_fold(argv[i], "send-release")) { parse_next_arg(argv, argc, i); @@ -4747,7 +4763,7 @@ _public_ int ncm_link_set_ipv6(int argc, char *argv[]) { dns = strv_remove_duplicates(dns); domains = strv_remove_duplicates(domains); - r = manager_set_ipv6(p, dhcp, accept_ra, lla, addrs, rt6, dns, domains, use_dns, send_release, keep); + r = manager_set_ipv6(p, dhcp, accept_ra, lla, addrs, rt6, dns, domains, use_dns, use_domains, send_release, keep); if (r < 0) { log_warning("Failed to configure IPv6 on device '%s': %s", p->ifname, strerror(-r)); return r; @@ -4759,6 +4775,7 @@ _public_ int ncm_link_set_ipv6(int argc, char *argv[]) { _public_ int ncm_link_set_ipv4(int argc, char *argv[]) { _auto_cleanup_strv_ char **addrs = NULL, **dns = NULL, **domains = NULL; int dhcp = -1, use_dns = -1, lla = -1, send_release = -1; + UseDomains use_domains = _USE_DOMAINS_INVALID; _auto_cleanup_ IfNameIndex *p = NULL; _auto_cleanup_ Route *rt4 = NULL; bool keep = true; @@ -4773,6 +4790,7 @@ _public_ int ncm_link_set_ipv4(int argc, char *argv[]) { log_warning("Failed to find device: %s", argv[i]); return r; } + continue; } else if (streq_fold(argv[i], "gateway") || streq_fold(argv[i], "gw") || streq_fold(argv[i], "gw4") || streq_fold(argv[i], "g")) { _auto_cleanup_ IPAddress *gw = NULL; @@ -4830,6 +4848,7 @@ _public_ int ncm_link_set_ipv4(int argc, char *argv[]) { log_warning("Failed to parse many addresses '%s': %s", argv[i], strerror(EINVAL)); return r; } + continue; } else if (streq_fold(argv[i], "dhcp")) { parse_next_arg(argv, argc, i); @@ -4883,6 +4902,7 @@ _public_ int ncm_link_set_ipv4(int argc, char *argv[]) { if (r < 0) return log_oom(); } + continue; } else if (streq_fold(argv[i], "use-dns")) { parse_next_arg(argv, argc, i); @@ -4895,7 +4915,16 @@ _public_ int ncm_link_set_ipv4(int argc, char *argv[]) { use_dns = r; continue; + } else if (streq_fold(argv[i], "use-domains")) { + parse_next_arg(argv, argc, i); + use_domains = use_domains_name_to_mode(argv[i]); + if (use_domains < 0) { + log_warning("Failed to parse use-domains='%s': %s", argv[i], strerror(-r)); + return -EINVAL; + } + + continue; } else if (streq_fold(argv[i], "send-release")) { parse_next_arg(argv, argc, i); @@ -4906,9 +4935,7 @@ _public_ int ncm_link_set_ipv4(int argc, char *argv[]) { } send_release = r; - continue; - } else if (streq_fold(argv[i], "lla") || streq_fold(argv[i], "link-local")) { parse_next_arg(argv, argc, i); @@ -4917,6 +4944,7 @@ _public_ int ncm_link_set_ipv4(int argc, char *argv[]) { log_warning("Failed to parse link-local %s': %s", argv[2], strerror(-r)); return r; } + lla = r; continue; } else if (streq_fold(argv[i], "keep")) { @@ -4943,7 +4971,7 @@ _public_ int ncm_link_set_ipv4(int argc, char *argv[]) { dns = strv_remove_duplicates(dns); domains = strv_remove_duplicates(domains); - r = manager_set_ipv4(p, lla, dhcp, addrs, rt4, dns, domains, use_dns, send_release, keep); + r = manager_set_ipv4(p, lla, dhcp, addrs, rt4, dns, domains, use_dns, use_domains, send_release, keep); if (r < 0) { log_warning("Failed to configure IPv4 on device '%s': %s", p->ifname, strerror(-r)); return r; diff --git a/src/manager/network-manager-ctl.c b/src/manager/network-manager-ctl.c index 018d7a56..0d5b96fe 100644 --- a/src/manager/network-manager-ctl.c +++ b/src/manager/network-manager-ctl.c @@ -217,9 +217,9 @@ static int help(void) { " remove-ipv6ra dev [DEVICE] Removes Ipv6 Router Advertisement.\n" " enable-ipv6 dev [DEVICE] [BOOLEAN] Enable or disables IPv6 on the link.\n" " set-ipv4 dev [DEVICE] dhcp [BOOLEAN] addr [ADDRESS] many [ADDRESS1,ADDRESS2...] gw|gw4|g [GATEWAY] dns [SERVER1,SERVER2...] domains [DOMAIN1,DOMAIN2 ...]" - "\n\t\t\t\t lla [BOOLEAN|ipv6|ipv4] use-dns [BOOLEAN send-release [BOOLEAN] keep [BOOLEAN] Configures device IPv4.\n" + "\n\t\t\t\t lla [BOOLEAN|ipv6|ipv4] use-dns [BOOLEAN use-domains [route|BOOLEAN] send-release [BOOLEAN] keep [BOOLEAN] Configures device IPv4.\n" " set-ipv6 dev [DEVICE] accept-ra [BOOLEAN] dhcp [BOOLEAN] address|a|addr [ADDRESS] many [ADDRESS1,ADDRESS2...] gw|gw6|g [GATEWAY]" - "\n\t\t\t\t lla [BOOLEAN|ipv6|ipv4] dns [SERVER1,SERVER2...] domains [DOMAIN1,DOMAIN2 ...] use-dns [BOOLEAN] send-release [BOOLEAN] keep [BOOLEAN] Configures device IPv6.\n" + "\n\t\t\t\t lla [BOOLEAN|ipv6|ipv4] dns [SERVER1,SERVER2...] domains [DOMAIN1,DOMAIN2 ...] use-dns [BOOLEAN] use-domains [route|BOOLEAN] send-release [BOOLEAN] keep [BOOLEAN] Configures device IPv6.\n" " add-sr-iov dev [DEVICE] [vf INTEGER] [vlanid INTEGER] [qos INTEGER] [vlanproto STRING] [macspoofck BOOLEAN] [qrss BOOLEAN]" "\n\t\t\t\t [trust BOOLEAN] [linkstate BOOLEAN or STRING] [macaddr ADDRESS] Configures SR-IOV VirtualFunction, " "\n\t\t\t\t VLANId, QualityOfService, VLANProtocol, MACSpoofCheck, QueryReceiveSideScaling, Trust, LinkState, MACAddress \n" diff --git a/src/manager/network-manager.c b/src/manager/network-manager.c index a837bd46..b4cb8f2d 100644 --- a/src/manager/network-manager.c +++ b/src/manager/network-manager.c @@ -2714,6 +2714,7 @@ int manager_set_ipv6(const IfNameIndex *p, char **dns, char **domains, const int use_dns, + UseDomains use_domains, const int send_release, bool keep) { @@ -2832,6 +2833,12 @@ int manager_set_ipv6(const IfNameIndex *p, } } + if (use_domains >= 0) { + r = key_file_set_str(key_file, "DHCPv6", "UseDomains", use_domains_modes_to_name(use_domains)); + if (r < 0) + return r; + } + if (use_dns >= 0) { r = key_file_set_str(key_file, "DHCPv6", "UseDNS", bool_to_str(use_dns)); if (r < 0) @@ -2883,6 +2890,7 @@ int manager_set_ipv4(const IfNameIndex *p, char **dns, char **domains, const int use_dns, + UseDomains use_domains, const int send_release, bool keep) { @@ -2988,6 +2996,12 @@ int manager_set_ipv4(const IfNameIndex *p, } } + if (use_domains >= 0) { + r = key_file_set_str(key_file, "DHCPv4", "UseDomains", use_domains_modes_to_name(use_domains)); + if (r < 0) + return r; + } + if (use_dns >= 0) { r = key_file_set_str(key_file, "DHCPv4", "UseDNS", bool_to_str(use_dns)); if (r < 0) diff --git a/src/manager/network-manager.h b/src/manager/network-manager.h index 2188a9ab..9da06c17 100644 --- a/src/manager/network-manager.h +++ b/src/manager/network-manager.h @@ -229,6 +229,7 @@ int manager_set_ipv6(const IfNameIndex *p, char **dns, char **domains, const int use_dns, + UseDomains use_domains, const int send_release, const bool keep); @@ -240,6 +241,7 @@ int manager_set_ipv4(const IfNameIndex *p, char **dns, char **domains, const int use_dns, + UseDomains use_domains, const int send_release, bool keep); diff --git a/src/manager/network.c b/src/manager/network.c index 420cb44c..d7e1b92b 100644 --- a/src/manager/network.c +++ b/src/manager/network.c @@ -20,6 +20,32 @@ #define BRIDGE_PRIORITY_MAX 63 +static const char *const use_domains_mode_table[_USE_DOMAINS_MAX] = { + [USE_DOMAINS_NO] = "no", + [USE_DOMAINS_YES] = "yes", + [USE_DOMAINS_ROUTE] = "route", +}; + +const char *use_domains_modes_to_name(int id) { + if (id < 0) + return NULL; + + if ((size_t) id >= ELEMENTSOF(use_domains_mode_table)) + return NULL; + + return use_domains_mode_table[id]; +} + +int use_domains_name_to_mode(char *name) { + assert(name); + + for (size_t i = USE_DOMAINS_NO; i < (size_t) ELEMENTSOF(use_domains_mode_table); i++) + if (streq_fold(name, use_domains_mode_table[i])) + return i; + + return _USE_DOMAINS_INVALID; +} + static const char *const dhcp_client_mode_table[_DHCP_CLIENT_MAX] = { [DHCP_CLIENT_NO] = "no", [DHCP_CLIENT_YES] = "yes", diff --git a/src/manager/network.h b/src/manager/network.h index a87c72b3..21750701 100644 --- a/src/manager/network.h +++ b/src/manager/network.h @@ -10,6 +10,14 @@ #include "network-address.h" #include "network-route.h" +typedef enum UseDomains { + USE_DOMAINS_NO, + USE_DOMAINS_YES, + USE_DOMAINS_ROUTE, + _USE_DOMAINS_MAX, + _USE_DOMAINS_INVALID = -EINVAL +} UseDomains; + typedef enum DHCPClient { DHCP_CLIENT_NO, DHCP_CLIENT_YES, @@ -346,3 +354,6 @@ int link_event_type_to_mode(const char *name); int generate_network_config(Network *n); int generate_master_device_network(Network *n); int generate_wifi_config(Network *n, GString **ret); + +const char *use_domains_modes_to_name(int id); +int use_domains_name_to_mode(char *name); From 9eed4a3316189dc0c5bd628711d601fd91b797a1 Mon Sep 17 00:00:00 2001 From: Nitesh Kumar Date: Fri, 2 Aug 2024 15:37:11 +0530 Subject: [PATCH 6/9] ClientIdentifier: Adding an option to set ClientIdentifier= in set-ipv4 command. Syntax: nmctl set-ipv4 dev cid nmctl set-ipv4 dev dummy1 cid mac --- src/manager/network-config-manager.c | 13 ++++++++++++- src/manager/network-manager-ctl.c | 2 +- src/manager/network-manager.c | 7 +++++++ src/manager/network-manager.h | 1 + 4 files changed, 21 insertions(+), 2 deletions(-) diff --git a/src/manager/network-config-manager.c b/src/manager/network-config-manager.c index e8860dfe..ad9ddeaa 100644 --- a/src/manager/network-config-manager.c +++ b/src/manager/network-config-manager.c @@ -4774,6 +4774,7 @@ _public_ int ncm_link_set_ipv6(int argc, char *argv[]) { _public_ int ncm_link_set_ipv4(int argc, char *argv[]) { _auto_cleanup_strv_ char **addrs = NULL, **dns = NULL, **domains = NULL; + DHCPClientIdentifier client_id = _DHCP_CLIENT_IDENTIFIER_INVALID; int dhcp = -1, use_dns = -1, lla = -1, send_release = -1; UseDomains use_domains = _USE_DOMAINS_INVALID; _auto_cleanup_ IfNameIndex *p = NULL; @@ -4903,6 +4904,16 @@ _public_ int ncm_link_set_ipv4(int argc, char *argv[]) { return log_oom(); } + continue; + } else if (streq_fold(argv[i], "cid") || streq_fold(argv[i], "client-id")) { + parse_next_arg(argv, argc, i); + + client_id = dhcp_client_identifier_to_kind(argv[i]); + if (client_id == _DHCP_CLIENT_IDENTIFIER_INVALID) { + log_warning("Failed to parse DHCP4 client identifier: %s", argv[i]); + return -EINVAL; + } + continue; } else if (streq_fold(argv[i], "use-dns")) { parse_next_arg(argv, argc, i); @@ -4971,7 +4982,7 @@ _public_ int ncm_link_set_ipv4(int argc, char *argv[]) { dns = strv_remove_duplicates(dns); domains = strv_remove_duplicates(domains); - r = manager_set_ipv4(p, lla, dhcp, addrs, rt4, dns, domains, use_dns, use_domains, send_release, keep); + r = manager_set_ipv4(p, lla, dhcp, addrs, rt4, dns, domains, client_id, use_dns, use_domains, send_release, keep); if (r < 0) { log_warning("Failed to configure IPv4 on device '%s': %s", p->ifname, strerror(-r)); return r; diff --git a/src/manager/network-manager-ctl.c b/src/manager/network-manager-ctl.c index 0d5b96fe..19049676 100644 --- a/src/manager/network-manager-ctl.c +++ b/src/manager/network-manager-ctl.c @@ -217,7 +217,7 @@ static int help(void) { " remove-ipv6ra dev [DEVICE] Removes Ipv6 Router Advertisement.\n" " enable-ipv6 dev [DEVICE] [BOOLEAN] Enable or disables IPv6 on the link.\n" " set-ipv4 dev [DEVICE] dhcp [BOOLEAN] addr [ADDRESS] many [ADDRESS1,ADDRESS2...] gw|gw4|g [GATEWAY] dns [SERVER1,SERVER2...] domains [DOMAIN1,DOMAIN2 ...]" - "\n\t\t\t\t lla [BOOLEAN|ipv6|ipv4] use-dns [BOOLEAN use-domains [route|BOOLEAN] send-release [BOOLEAN] keep [BOOLEAN] Configures device IPv4.\n" + "\n\t\t\t\t lla [BOOLEAN|ipv6|ipv4] cid|client-id [IDENTIFIER {mac|duid|duid-only} use-dns [BOOLEAN use-domains [route|BOOLEAN] send-release [BOOLEAN] keep [BOOLEAN] Configures device IPv4.\n" " set-ipv6 dev [DEVICE] accept-ra [BOOLEAN] dhcp [BOOLEAN] address|a|addr [ADDRESS] many [ADDRESS1,ADDRESS2...] gw|gw6|g [GATEWAY]" "\n\t\t\t\t lla [BOOLEAN|ipv6|ipv4] dns [SERVER1,SERVER2...] domains [DOMAIN1,DOMAIN2 ...] use-dns [BOOLEAN] use-domains [route|BOOLEAN] send-release [BOOLEAN] keep [BOOLEAN] Configures device IPv6.\n" " add-sr-iov dev [DEVICE] [vf INTEGER] [vlanid INTEGER] [qos INTEGER] [vlanproto STRING] [macspoofck BOOLEAN] [qrss BOOLEAN]" diff --git a/src/manager/network-manager.c b/src/manager/network-manager.c index b4cb8f2d..b1b1d787 100644 --- a/src/manager/network-manager.c +++ b/src/manager/network-manager.c @@ -2889,6 +2889,7 @@ int manager_set_ipv4(const IfNameIndex *p, Route *rt4, char **dns, char **domains, + const DHCPClientIdentifier client_id, const int use_dns, UseDomains use_domains, const int send_release, @@ -2996,6 +2997,12 @@ int manager_set_ipv4(const IfNameIndex *p, } } + if (client_id >= 0) { + r = key_file_set_str(key_file, "DHCPv4", "ClientIdentifier", dhcp_client_identifier_to_name(client_id)); + if (r < 0) + return r; + } + if (use_domains >= 0) { r = key_file_set_str(key_file, "DHCPv4", "UseDomains", use_domains_modes_to_name(use_domains)); if (r < 0) diff --git a/src/manager/network-manager.h b/src/manager/network-manager.h index 9da06c17..ec0e7194 100644 --- a/src/manager/network-manager.h +++ b/src/manager/network-manager.h @@ -240,6 +240,7 @@ int manager_set_ipv4(const IfNameIndex *p, Route *rt4, char **dns, char **domains, + const DHCPClientIdentifier client_id, const int use_dns, UseDomains use_domains, const int send_release, From 87a7bc68b16b15f80648119c25c7bcdedbf2342f Mon Sep 17 00:00:00 2001 From: Nitesh Kumar Date: Fri, 2 Aug 2024 22:55:45 +0530 Subject: [PATCH 7/9] test: Adding multiple test for set-ipv4 and set-ipv6 command. The test is a combination of IPv4, IPv6, DNS, Domains, UseDns, UseDomains, SendRelease, LinkLocalAddressing, ClientIdentifier etc. --- tests/cmocka/basic.c | 13 ++ tests/cmocka/set-network.c | 324 +++++++++++++++++++++++++++++++++++++ tests/cmocka/set-network.h | 14 ++ 3 files changed, 351 insertions(+) diff --git a/tests/cmocka/basic.c b/tests/cmocka/basic.c index 7e60205a..31389f52 100644 --- a/tests/cmocka/basic.c +++ b/tests/cmocka/basic.c @@ -2008,6 +2008,19 @@ int main(void) { cmocka_unit_test (test_vami_set_dynamic_ipv4_static_address_gw), cmocka_unit_test (test_vami_set_static_ipv6_static_address_gw), cmocka_unit_test (test_vami_set_static_ipv4_ipv6_static_address_gw), + /* test cases with set-ipv4 and set-ipv6 */ + cmocka_unit_test (test_dhcp_ipv4_none_ipv6_dhcp_dns), + cmocka_unit_test (test_dhcp_ipv4_none_ipv6_none_dns), + cmocka_unit_test (test_dhcp_ipv4_dhcp_ipv6_dhcp_dns), + cmocka_unit_test (test_dhcp_ipv4_auto_ipv6_dhcp_dns), + cmocka_unit_test (test_dhcp_ipv4_static_ipv6_static_dns), + cmocka_unit_test (test_static_ipv4_none_ipv6_static_dns), + cmocka_unit_test (test_static_ipv4_dhcp_ipv6_static_dns), + cmocka_unit_test (test_static_ipv4_auto_ipv6_static_dns), + cmocka_unit_test (test_static_ipv4_static_ipv6_static_dns), + cmocka_unit_test (test_none_ipv4_dhcp_ipv6_dhcp_dns), + cmocka_unit_test (test_none_ipv4_auto_ipv6_dhcp_dns), + cmocka_unit_test (test_none_ipv4_static_ipv6_static_dns), }; int count_fail_tests = cmocka_run_group_tests (tests, setup, teardown); diff --git a/tests/cmocka/set-network.c b/tests/cmocka/set-network.c index 48d56408..ee39ffb4 100644 --- a/tests/cmocka/set-network.c +++ b/tests/cmocka/set-network.c @@ -526,3 +526,327 @@ void test_set_network_dhcp_ipv4_ipv4_ra_dhcp4_client_identifier_dhcp_iaid_static unlink("/etc/systemd/network/10-test99.network"); } + +/* DHCPv4 + DHCP-DNS */ +void test_dhcp_ipv4_none_ipv6_dhcp_dns(void **state) { + _cleanup_(key_file_freep) KeyFile *key_file = NULL; + int r; + + assert_true(system("nmctl set-ipv4 dev test99 dhcp yes lla ipv4 send-release no use-domains yes cid mac domains eng.vmware.com,vmware.com") >= 0); + + r = parse_key_file("/etc/systemd/network/10-test99.network", &key_file); + assert_true(r >= 0); + + display_key_file(key_file); + assert_true(key_file_config_exists(key_file, "Match", "Name", "test99")); + + assert_true(key_file_config_exists(key_file, "Network", "DHCP", "ipv4")); + assert_true(key_file_config_exists(key_file, "Network", "LinkLocalAddressing", "ipv4")); + assert_true(key_file_config_exists(key_file, "Network", "Domains", "eng.vmware.com vmware.com")); + + assert_true(key_file_config_exists(key_file, "DHCPv4", "SendRelease", "no")); + assert_true(key_file_config_exists(key_file, "DHCPv4", "UseDomains", "yes")); + assert_true(key_file_config_exists(key_file, "DHCPv4", "ClientIdentifier", "mac")); + + unlink("/etc/systemd/network/10-test99.network"); +} + +/* DHCPv4 */ +void test_dhcp_ipv4_none_ipv6_none_dns(void **state) { + _cleanup_(key_file_freep) KeyFile *key_file = NULL; + int r; + + /* Default value of UseDNS=true */ + assert_true(system("nmctl set-ipv4 dev test99 dhcp yes lla ipv4 send-release no use-dns no domains eng.vmware.com,vmware.com") >= 0); + + r = parse_key_file("/etc/systemd/network/10-test99.network", &key_file); + assert_true(r >= 0); + + display_key_file(key_file); + assert_true(key_file_config_exists(key_file, "Match", "Name", "test99")); + + assert_true(key_file_config_exists(key_file, "Network", "DHCP", "ipv4")); + assert_true(key_file_config_exists(key_file, "Network", "LinkLocalAddressing", "ipv4")); + assert_true(key_file_config_exists(key_file, "Network", "Domains", "eng.vmware.com vmware.com")); + + assert_true(key_file_config_exists(key_file, "DHCPv4", "SendRelease", "no")); + assert_true(key_file_config_exists(key_file, "DHCPv4", "UseDNS", "no")); + + unlink("/etc/systemd/network/10-test99.network"); +} + +/* DHCPv4 + DHCPv6 + DHCP-DNS */ +void test_dhcp_ipv4_dhcp_ipv6_dhcp_dns(void **state) { + _cleanup_(key_file_freep) KeyFile *key_file = NULL; + int r; + + assert_true(system("nmctl set-ipv4 dev test99 dhcp yes lla yes send-release no use-domains yes cid mac") >= 0); + assert_true(system("nmctl set-ipv6 dev test99 dhcp yes use-domains yes send-release no") >= 0); + + r = parse_key_file("/etc/systemd/network/10-test99.network", &key_file); + assert_true(r >= 0); + + display_key_file(key_file); + assert_true(key_file_config_exists(key_file, "Match", "Name", "test99")); + + assert_true(key_file_config_exists(key_file, "Network", "DHCP", "yes")); + assert_true(key_file_config_exists(key_file, "Network", "LinkLocalAddressing", "yes")); + assert_true(key_file_config_exists(key_file, "Network", "IPv6AcceptRA", "yes")); + + assert_true(key_file_config_exists(key_file, "DHCPv4", "ClientIdentifier", "mac")); + assert_true(key_file_config_exists(key_file, "DHCPv4", "UseDomains", "yes")); + assert_true(key_file_config_exists(key_file, "DHCPv4", "SendRelease", "no")); + + assert_true(key_file_config_exists(key_file, "DHCPv6", "SendRelease", "no")); + assert_true(key_file_config_exists(key_file, "DHCPv6", "UseDomains", "yes")); + + unlink("/etc/systemd/network/10-test99.network"); +} + +/* DHCPv4 + AUTOv6 + DHCP-DNS */ +void test_dhcp_ipv4_auto_ipv6_dhcp_dns(void **state) { + _cleanup_(key_file_freep) KeyFile *key_file = NULL; + int r; + + assert_true(system("nmctl set-ipv4 dev test99 dhcp yes lla yes send-release no use-domains yes cid mac") >= 0); + assert_true(system("nmctl set-ipv6 dev test99 accept-ra yes use-domains yes") >= 0); + + r = parse_key_file("/etc/systemd/network/10-test99.network", &key_file); + assert_true(r >= 0); + + display_key_file(key_file); + assert_true(key_file_config_exists(key_file, "Match", "Name", "test99")); + + assert_true(key_file_config_exists(key_file, "Network", "DHCP", "ipv4")); + assert_true(key_file_config_exists(key_file, "Network", "LinkLocalAddressing", "yes")); + assert_true(key_file_config_exists(key_file, "Network", "IPv6AcceptRA", "yes")); + + assert_true(key_file_config_exists(key_file, "DHCPv4", "ClientIdentifier", "mac")); + assert_true(key_file_config_exists(key_file, "DHCPv4", "UseDomains", "yes")); + assert_true(key_file_config_exists(key_file, "DHCPv4", "SendRelease", "no")); + + assert_true(key_file_config_exists(key_file, "DHCPv6", "UseDomains", "yes")); + + unlink("/etc/systemd/network/10-test99.network"); +} + +/* DHCPv4 + STATICv6 + STATIC-DNS */ +void test_dhcp_ipv4_static_ipv6_static_dns(void **state) { + _cleanup_(key_file_freep) KeyFile *key_file = NULL; + int r; + + assert_true(system("nmctl set-ipv4 dev test99 dhcp yes lla ipv4 send-release no use-dns no use-domains yes cid mac dns 192.168.1.10,192.168.1.20") >= 0); + assert_true(system("nmctl set-ipv6 dev test99 use-dns no use-domains yes accept-ra no addr fe80::10 gw fe80::1 dns fe80::4,fe80::5") >= 0); + + r = parse_key_file("/etc/systemd/network/10-test99.network", &key_file); + assert_true(r >= 0); + + display_key_file(key_file); + assert_true(key_file_config_exists(key_file, "Match", "Name", "test99")); + + assert_true(key_file_config_exists(key_file, "Network", "DHCP", "ipv4")); + assert_true(key_file_config_exists(key_file, "Network", "LinkLocalAddressing", "ipv4")); + assert_true(key_file_config_exists(key_file, "Network", "DNS", "fe80::4 fe80::5 192.168.1.10 192.168.1.20")); + assert_true(key_file_config_exists(key_file, "Network", "IPv6AcceptRA", "no")); + + assert_true(key_file_config_exists(key_file, "DHCPv4", "ClientIdentifier", "mac")); + assert_true(key_file_config_exists(key_file, "DHCPv4", "UseDomains", "yes")); + assert_true(key_file_config_exists(key_file, "DHCPv4", "UseDNS", "no")); + assert_true(key_file_config_exists(key_file, "DHCPv4", "SendRelease", "no")); + + assert_true(key_file_config_exists(key_file, "DHCPv6", "UseDomains", "yes")); + assert_true(key_file_config_exists(key_file, "DHCPv6", "UseDNS", "no")); + + assert_true(key_file_config_exists(key_file, "Address", "Address", "fe80::10")); + assert_true(key_file_config_exists(key_file, "Route", "Gateway", "fe80::1")); + + unlink("/etc/systemd/network/10-test99.network"); +} + +/* STATICv4 + STATIC-DNS */ +void test_static_ipv4_none_ipv6_static_dns(void **state) { + _cleanup_(key_file_freep) KeyFile *key_file = NULL; + int r; + + assert_true(system("nmctl set-ipv4 dev test99 lla no use-dns no send-release no addr 192.168.1.101 gw 192.168.1.2 dns 192.168.1.10,192.168.1.20") >= 0); + + r = parse_key_file("/etc/systemd/network/10-test99.network", &key_file); + assert_true(r >= 0); + + display_key_file(key_file); + assert_true(key_file_config_exists(key_file, "Match", "Name", "test99")); + + assert_true(key_file_config_exists(key_file, "Network", "LinkLocalAddressing", "no")); + assert_true(key_file_config_exists(key_file, "Network", "DNS", "192.168.1.10 192.168.1.20")); + + assert_true(key_file_config_exists(key_file, "DHCPv4", "UseDNS", "no")); + assert_true(key_file_config_exists(key_file, "DHCPv4", "SendRelease", "no")); + + assert_true(key_file_config_exists(key_file, "Address", "Address", "192.168.1.101")); + assert_true(key_file_config_exists(key_file, "Route", "Gateway", "192.168.1.2")); + + unlink("/etc/systemd/network/10-test99.network"); + +} + +/* STATICv4 + DHCPv6 + STATIC-DNS */ +void test_static_ipv4_dhcp_ipv6_static_dns(void **state) { + _cleanup_(key_file_freep) KeyFile *key_file = NULL; + int r; + + assert_true(system("nmctl set-ipv4 dev test99 use-dns no use-domains yes send-release no cid mac addr 192.168.1.101 gw 192.168.1.2 dns 192.168.1.10,192.168.1.20") >= 0); + assert_true(system("nmctl set-ipv6 dev test99 dhcp yes use-dns no use-domains yes send-release no dns fe80::4,fe80::5") >= 0); + + r = parse_key_file("/etc/systemd/network/10-test99.network", &key_file); + assert_true(r >= 0); + + display_key_file(key_file); + assert_true(key_file_config_exists(key_file, "Match", "Name", "test99")); + + assert_true(key_file_config_exists(key_file, "Network", "DHCP", "ipv6")); + assert_true(key_file_config_exists(key_file, "Network", "IPv6AcceptRA", "yes")); + assert_true(key_file_config_exists(key_file, "Network", "LinkLocalAddressing", "ipv6")); + assert_true(key_file_config_exists(key_file, "Network", "DNS", "fe80::4 fe80::5 192.168.1.10 192.168.1.20")); + + assert_true(key_file_config_exists(key_file, "DHCPv4", "UseDNS", "no")); + assert_true(key_file_config_exists(key_file, "DHCPv4", "UseDomains", "yes")); + assert_true(key_file_config_exists(key_file, "DHCPv4", "SendRelease", "no")); + assert_true(key_file_config_exists(key_file, "DHCPv4", "ClientIdentifier", "mac")); + + assert_true(key_file_config_exists(key_file, "DHCPv6", "UseDNS", "no")); + assert_true(key_file_config_exists(key_file, "DHCPv4", "UseDomains", "yes")); + assert_true(key_file_config_exists(key_file, "DHCPv6", "SendRelease", "no")); + + assert_true(key_file_config_exists(key_file, "Address", "Address", "192.168.1.101")); + assert_true(key_file_config_exists(key_file, "Route", "Gateway", "192.168.1.2")); + + unlink("/etc/systemd/network/10-test99.network"); +} + +/* STATICv4 + AUTOv6 + STATIC-DNS */ +void test_static_ipv4_auto_ipv6_static_dns(void **state) { + _cleanup_(key_file_freep) KeyFile *key_file = NULL; + int r; + + assert_true(system("nmctl set-ipv4 dev test99 use-dns no send-release no addr 192.168.1.101 gw 192.168.1.2 dns 192.168.1.10,192.168.1.20") >= 0); + assert_true(system("nmctl set-ipv6 dev test99 accept-ra yes use-dns no dns fe80::4,fe80::5") >= 0); + + r = parse_key_file("/etc/systemd/network/10-test99.network", &key_file); + assert_true(r >= 0); + + display_key_file(key_file); + assert_true(key_file_config_exists(key_file, "Match", "Name", "test99")); + + assert_true(key_file_config_exists(key_file, "Network", "IPv6AcceptRA", "yes")); + assert_true(key_file_config_exists(key_file, "Network", "LinkLocalAddressing", "ipv6")); + assert_true(key_file_config_exists(key_file, "Network", "DNS", "fe80::4 fe80::5 192.168.1.10 192.168.1.20")); + + assert_true(key_file_config_exists(key_file, "DHCPv4", "UseDNS", "no")); + assert_true(key_file_config_exists(key_file, "DHCPv4", "SendRelease", "no")); + + assert_true(key_file_config_exists(key_file, "DHCPv6", "UseDNS", "no")); + + assert_true(key_file_config_exists(key_file, "Address", "Address", "192.168.1.101")); + assert_true(key_file_config_exists(key_file, "Route", "Gateway", "192.168.1.2")); + + unlink("/etc/systemd/network/10-test99.network"); +} + +/* STATICv4 + STATICv6 + STATIC-DNS */ +void test_static_ipv4_static_ipv6_static_dns(void **state) { + _cleanup_(key_file_freep) KeyFile *key_file = NULL; + int r; + + assert_true(system("nmctl set-ipv4 dev test99 use-dns no send-release no addr 192.168.1.101 gw 192.168.1.2 dns 192.168.1.10,192.168.1.20") >= 0); + assert_true(system("nmctl set-ipv6 dev test99 use-dns no accept-ra no addr fe80::10 gw fe80::1 dns fe80::4,fe80::5") >= 0); + + r = parse_key_file("/etc/systemd/network/10-test99.network", &key_file); + assert_true(r >= 0); + + display_key_file(key_file); + assert_true(key_file_config_exists(key_file, "Match", "Name", "test99")); + + assert_true(key_file_config_exists(key_file, "Network", "IPv6AcceptRA", "no")); + assert_true(key_file_config_exists(key_file, "Network", "DNS", "fe80::4 fe80::5 192.168.1.10 192.168.1.20")); + + assert_true(key_file_config_exists(key_file, "DHCPv4", "UseDNS", "no")); + assert_true(key_file_config_exists(key_file, "DHCPv4", "SendRelease", "no")); + + assert_true(key_file_config_exists(key_file, "DHCPv6", "UseDNS", "no")); + + assert_true(key_file_config_exists(key_file, "Address", "Address", "192.168.1.101")); + assert_true(key_file_config_exists(key_file, "Route", "Gateway", "192.168.1.2")); + + assert_true(key_file_config_exists(key_file, "Address", "Address", "fe80::10")); + assert_true(key_file_config_exists(key_file, "Route", "Gateway", "fe80::1")); + + unlink("/etc/systemd/network/10-test99.network"); +} + +/* DHCPv6 + DHCP-DNS */ +void test_none_ipv4_dhcp_ipv6_dhcp_dns(void **state) { + _cleanup_(key_file_freep) KeyFile *key_file = NULL; + int r; + + assert_true(system("nmctl set-ipv6 dev test99 dhcp yes send-release no use-domains yes") >= 0); + + r = parse_key_file("/etc/systemd/network/10-test99.network", &key_file); + assert_true(r >= 0); + + display_key_file(key_file); + assert_true(key_file_config_exists(key_file, "Match", "Name", "test99")); + + assert_true(key_file_config_exists(key_file, "Network", "DHCP", "ipv6")); + assert_true(key_file_config_exists(key_file, "Network", "IPv6AcceptRA", "yes")); + assert_true(key_file_config_exists(key_file, "Network", "LinkLocalAddressing", "ipv6")); + + assert_true(key_file_config_exists(key_file, "DHCPv6", "UseDomains", "yes")); + assert_true(key_file_config_exists(key_file, "DHCPv6", "SendRelease", "no")); + + unlink("/etc/systemd/network/10-test99.network"); +} + +/* AUTOv6 + DHCP-DNS */ +void test_none_ipv4_auto_ipv6_dhcp_dns(void **state) { + _cleanup_(key_file_freep) KeyFile *key_file = NULL; + int r; + + assert_true(system("nmctl set-ipv6 dev test99 dhcp yes accept-ra yes") >= 0); + + r = parse_key_file("/etc/systemd/network/10-test99.network", &key_file); + assert_true(r >= 0); + + display_key_file(key_file); + + assert_true(key_file_config_exists(key_file, "Match", "Name", "test99")); + + assert_true(key_file_config_exists(key_file, "Network", "DHCP", "ipv6")); + assert_true(key_file_config_exists(key_file, "Network", "IPv6AcceptRA", "yes")); + assert_true(key_file_config_exists(key_file, "Network", "LinkLocalAddressing", "ipv6")); + + unlink("/etc/systemd/network/10-test99.network"); +} + +/* STATICv6 + STATIC-DNS */ +void test_none_ipv4_static_ipv6_static_dns(void **state) { + _cleanup_(key_file_freep) KeyFile *key_file = NULL; + int r; + + assert_true(system("nmctl set-ipv6 dev test99 use-dns no accept-ra no addr fe80::10 gw fe80::1 dns fe80::4,fe80::5") >= 0); + + r = parse_key_file("/etc/systemd/network/10-test99.network", &key_file); + assert_true(r >= 0); + + display_key_file(key_file); + assert_true(key_file_config_exists(key_file, "Match", "Name", "test99")); + + assert_true(key_file_config_exists(key_file, "Network", "IPv6AcceptRA", "no")); + assert_true(key_file_config_exists(key_file, "Network", "DNS", "fe80::4 fe80::5")); + + assert_true(key_file_config_exists(key_file, "DHCPv6", "UseDNS", "no")); + + assert_true(key_file_config_exists(key_file, "Address", "Address", "fe80::10")); + assert_true(key_file_config_exists(key_file, "Route", "Gateway", "fe80::1")); + + unlink("/etc/systemd/network/10-test99.network"); +} diff --git a/tests/cmocka/set-network.h b/tests/cmocka/set-network.h index 7f6ade4f..d900b33b 100644 --- a/tests/cmocka/set-network.h +++ b/tests/cmocka/set-network.h @@ -50,3 +50,17 @@ void test_vami_set_dynamic_dhcpv4_and_dhcpv6(void **state); void test_vami_set_dynamic_ipv4_static_address_gw(void **state); void test_vami_set_static_ipv6_static_address_gw(void **state); void test_vami_set_static_ipv4_ipv6_static_address_gw(void **state); + +/* with set-ipv4 and set-ipv6 */ +void test_dhcp_ipv4_none_ipv6_dhcp_dns(void **state) ; +void test_dhcp_ipv4_none_ipv6_none_dns(void **state) ; +void test_dhcp_ipv4_dhcp_ipv6_dhcp_dns(void **state) ; +void test_dhcp_ipv4_auto_ipv6_dhcp_dns(void **state) ; +void test_dhcp_ipv4_static_ipv6_static_dns(void **state) ; +void test_static_ipv4_none_ipv6_static_dns(void **state) ; +void test_static_ipv4_dhcp_ipv6_static_dns(void **state) ; +void test_static_ipv4_auto_ipv6_static_dns(void **state) ; +void test_static_ipv4_static_ipv6_static_dns(void **state) ; +void test_none_ipv4_dhcp_ipv6_dhcp_dns(void **state) ; +void test_none_ipv4_auto_ipv6_dhcp_dns(void **state) ; +void test_none_ipv4_static_ipv6_static_dns(void **state) ; From 66a6dfc5607a00acec19e825dc6576f8127d297c Mon Sep 17 00:00:00 2001 From: Nitesh Kumar Date: Fri, 9 Aug 2024 12:32:22 +0530 Subject: [PATCH 8/9] Revert "test: Adding multiple test for set-ipv4 and set-ipv6 command." This reverts commit 87a7bc68b16b15f80648119c25c7bcdedbf2342f. --- tests/cmocka/basic.c | 13 -- tests/cmocka/set-network.c | 324 ------------------------------------- tests/cmocka/set-network.h | 14 -- 3 files changed, 351 deletions(-) diff --git a/tests/cmocka/basic.c b/tests/cmocka/basic.c index 31389f52..7e60205a 100644 --- a/tests/cmocka/basic.c +++ b/tests/cmocka/basic.c @@ -2008,19 +2008,6 @@ int main(void) { cmocka_unit_test (test_vami_set_dynamic_ipv4_static_address_gw), cmocka_unit_test (test_vami_set_static_ipv6_static_address_gw), cmocka_unit_test (test_vami_set_static_ipv4_ipv6_static_address_gw), - /* test cases with set-ipv4 and set-ipv6 */ - cmocka_unit_test (test_dhcp_ipv4_none_ipv6_dhcp_dns), - cmocka_unit_test (test_dhcp_ipv4_none_ipv6_none_dns), - cmocka_unit_test (test_dhcp_ipv4_dhcp_ipv6_dhcp_dns), - cmocka_unit_test (test_dhcp_ipv4_auto_ipv6_dhcp_dns), - cmocka_unit_test (test_dhcp_ipv4_static_ipv6_static_dns), - cmocka_unit_test (test_static_ipv4_none_ipv6_static_dns), - cmocka_unit_test (test_static_ipv4_dhcp_ipv6_static_dns), - cmocka_unit_test (test_static_ipv4_auto_ipv6_static_dns), - cmocka_unit_test (test_static_ipv4_static_ipv6_static_dns), - cmocka_unit_test (test_none_ipv4_dhcp_ipv6_dhcp_dns), - cmocka_unit_test (test_none_ipv4_auto_ipv6_dhcp_dns), - cmocka_unit_test (test_none_ipv4_static_ipv6_static_dns), }; int count_fail_tests = cmocka_run_group_tests (tests, setup, teardown); diff --git a/tests/cmocka/set-network.c b/tests/cmocka/set-network.c index ee39ffb4..48d56408 100644 --- a/tests/cmocka/set-network.c +++ b/tests/cmocka/set-network.c @@ -526,327 +526,3 @@ void test_set_network_dhcp_ipv4_ipv4_ra_dhcp4_client_identifier_dhcp_iaid_static unlink("/etc/systemd/network/10-test99.network"); } - -/* DHCPv4 + DHCP-DNS */ -void test_dhcp_ipv4_none_ipv6_dhcp_dns(void **state) { - _cleanup_(key_file_freep) KeyFile *key_file = NULL; - int r; - - assert_true(system("nmctl set-ipv4 dev test99 dhcp yes lla ipv4 send-release no use-domains yes cid mac domains eng.vmware.com,vmware.com") >= 0); - - r = parse_key_file("/etc/systemd/network/10-test99.network", &key_file); - assert_true(r >= 0); - - display_key_file(key_file); - assert_true(key_file_config_exists(key_file, "Match", "Name", "test99")); - - assert_true(key_file_config_exists(key_file, "Network", "DHCP", "ipv4")); - assert_true(key_file_config_exists(key_file, "Network", "LinkLocalAddressing", "ipv4")); - assert_true(key_file_config_exists(key_file, "Network", "Domains", "eng.vmware.com vmware.com")); - - assert_true(key_file_config_exists(key_file, "DHCPv4", "SendRelease", "no")); - assert_true(key_file_config_exists(key_file, "DHCPv4", "UseDomains", "yes")); - assert_true(key_file_config_exists(key_file, "DHCPv4", "ClientIdentifier", "mac")); - - unlink("/etc/systemd/network/10-test99.network"); -} - -/* DHCPv4 */ -void test_dhcp_ipv4_none_ipv6_none_dns(void **state) { - _cleanup_(key_file_freep) KeyFile *key_file = NULL; - int r; - - /* Default value of UseDNS=true */ - assert_true(system("nmctl set-ipv4 dev test99 dhcp yes lla ipv4 send-release no use-dns no domains eng.vmware.com,vmware.com") >= 0); - - r = parse_key_file("/etc/systemd/network/10-test99.network", &key_file); - assert_true(r >= 0); - - display_key_file(key_file); - assert_true(key_file_config_exists(key_file, "Match", "Name", "test99")); - - assert_true(key_file_config_exists(key_file, "Network", "DHCP", "ipv4")); - assert_true(key_file_config_exists(key_file, "Network", "LinkLocalAddressing", "ipv4")); - assert_true(key_file_config_exists(key_file, "Network", "Domains", "eng.vmware.com vmware.com")); - - assert_true(key_file_config_exists(key_file, "DHCPv4", "SendRelease", "no")); - assert_true(key_file_config_exists(key_file, "DHCPv4", "UseDNS", "no")); - - unlink("/etc/systemd/network/10-test99.network"); -} - -/* DHCPv4 + DHCPv6 + DHCP-DNS */ -void test_dhcp_ipv4_dhcp_ipv6_dhcp_dns(void **state) { - _cleanup_(key_file_freep) KeyFile *key_file = NULL; - int r; - - assert_true(system("nmctl set-ipv4 dev test99 dhcp yes lla yes send-release no use-domains yes cid mac") >= 0); - assert_true(system("nmctl set-ipv6 dev test99 dhcp yes use-domains yes send-release no") >= 0); - - r = parse_key_file("/etc/systemd/network/10-test99.network", &key_file); - assert_true(r >= 0); - - display_key_file(key_file); - assert_true(key_file_config_exists(key_file, "Match", "Name", "test99")); - - assert_true(key_file_config_exists(key_file, "Network", "DHCP", "yes")); - assert_true(key_file_config_exists(key_file, "Network", "LinkLocalAddressing", "yes")); - assert_true(key_file_config_exists(key_file, "Network", "IPv6AcceptRA", "yes")); - - assert_true(key_file_config_exists(key_file, "DHCPv4", "ClientIdentifier", "mac")); - assert_true(key_file_config_exists(key_file, "DHCPv4", "UseDomains", "yes")); - assert_true(key_file_config_exists(key_file, "DHCPv4", "SendRelease", "no")); - - assert_true(key_file_config_exists(key_file, "DHCPv6", "SendRelease", "no")); - assert_true(key_file_config_exists(key_file, "DHCPv6", "UseDomains", "yes")); - - unlink("/etc/systemd/network/10-test99.network"); -} - -/* DHCPv4 + AUTOv6 + DHCP-DNS */ -void test_dhcp_ipv4_auto_ipv6_dhcp_dns(void **state) { - _cleanup_(key_file_freep) KeyFile *key_file = NULL; - int r; - - assert_true(system("nmctl set-ipv4 dev test99 dhcp yes lla yes send-release no use-domains yes cid mac") >= 0); - assert_true(system("nmctl set-ipv6 dev test99 accept-ra yes use-domains yes") >= 0); - - r = parse_key_file("/etc/systemd/network/10-test99.network", &key_file); - assert_true(r >= 0); - - display_key_file(key_file); - assert_true(key_file_config_exists(key_file, "Match", "Name", "test99")); - - assert_true(key_file_config_exists(key_file, "Network", "DHCP", "ipv4")); - assert_true(key_file_config_exists(key_file, "Network", "LinkLocalAddressing", "yes")); - assert_true(key_file_config_exists(key_file, "Network", "IPv6AcceptRA", "yes")); - - assert_true(key_file_config_exists(key_file, "DHCPv4", "ClientIdentifier", "mac")); - assert_true(key_file_config_exists(key_file, "DHCPv4", "UseDomains", "yes")); - assert_true(key_file_config_exists(key_file, "DHCPv4", "SendRelease", "no")); - - assert_true(key_file_config_exists(key_file, "DHCPv6", "UseDomains", "yes")); - - unlink("/etc/systemd/network/10-test99.network"); -} - -/* DHCPv4 + STATICv6 + STATIC-DNS */ -void test_dhcp_ipv4_static_ipv6_static_dns(void **state) { - _cleanup_(key_file_freep) KeyFile *key_file = NULL; - int r; - - assert_true(system("nmctl set-ipv4 dev test99 dhcp yes lla ipv4 send-release no use-dns no use-domains yes cid mac dns 192.168.1.10,192.168.1.20") >= 0); - assert_true(system("nmctl set-ipv6 dev test99 use-dns no use-domains yes accept-ra no addr fe80::10 gw fe80::1 dns fe80::4,fe80::5") >= 0); - - r = parse_key_file("/etc/systemd/network/10-test99.network", &key_file); - assert_true(r >= 0); - - display_key_file(key_file); - assert_true(key_file_config_exists(key_file, "Match", "Name", "test99")); - - assert_true(key_file_config_exists(key_file, "Network", "DHCP", "ipv4")); - assert_true(key_file_config_exists(key_file, "Network", "LinkLocalAddressing", "ipv4")); - assert_true(key_file_config_exists(key_file, "Network", "DNS", "fe80::4 fe80::5 192.168.1.10 192.168.1.20")); - assert_true(key_file_config_exists(key_file, "Network", "IPv6AcceptRA", "no")); - - assert_true(key_file_config_exists(key_file, "DHCPv4", "ClientIdentifier", "mac")); - assert_true(key_file_config_exists(key_file, "DHCPv4", "UseDomains", "yes")); - assert_true(key_file_config_exists(key_file, "DHCPv4", "UseDNS", "no")); - assert_true(key_file_config_exists(key_file, "DHCPv4", "SendRelease", "no")); - - assert_true(key_file_config_exists(key_file, "DHCPv6", "UseDomains", "yes")); - assert_true(key_file_config_exists(key_file, "DHCPv6", "UseDNS", "no")); - - assert_true(key_file_config_exists(key_file, "Address", "Address", "fe80::10")); - assert_true(key_file_config_exists(key_file, "Route", "Gateway", "fe80::1")); - - unlink("/etc/systemd/network/10-test99.network"); -} - -/* STATICv4 + STATIC-DNS */ -void test_static_ipv4_none_ipv6_static_dns(void **state) { - _cleanup_(key_file_freep) KeyFile *key_file = NULL; - int r; - - assert_true(system("nmctl set-ipv4 dev test99 lla no use-dns no send-release no addr 192.168.1.101 gw 192.168.1.2 dns 192.168.1.10,192.168.1.20") >= 0); - - r = parse_key_file("/etc/systemd/network/10-test99.network", &key_file); - assert_true(r >= 0); - - display_key_file(key_file); - assert_true(key_file_config_exists(key_file, "Match", "Name", "test99")); - - assert_true(key_file_config_exists(key_file, "Network", "LinkLocalAddressing", "no")); - assert_true(key_file_config_exists(key_file, "Network", "DNS", "192.168.1.10 192.168.1.20")); - - assert_true(key_file_config_exists(key_file, "DHCPv4", "UseDNS", "no")); - assert_true(key_file_config_exists(key_file, "DHCPv4", "SendRelease", "no")); - - assert_true(key_file_config_exists(key_file, "Address", "Address", "192.168.1.101")); - assert_true(key_file_config_exists(key_file, "Route", "Gateway", "192.168.1.2")); - - unlink("/etc/systemd/network/10-test99.network"); - -} - -/* STATICv4 + DHCPv6 + STATIC-DNS */ -void test_static_ipv4_dhcp_ipv6_static_dns(void **state) { - _cleanup_(key_file_freep) KeyFile *key_file = NULL; - int r; - - assert_true(system("nmctl set-ipv4 dev test99 use-dns no use-domains yes send-release no cid mac addr 192.168.1.101 gw 192.168.1.2 dns 192.168.1.10,192.168.1.20") >= 0); - assert_true(system("nmctl set-ipv6 dev test99 dhcp yes use-dns no use-domains yes send-release no dns fe80::4,fe80::5") >= 0); - - r = parse_key_file("/etc/systemd/network/10-test99.network", &key_file); - assert_true(r >= 0); - - display_key_file(key_file); - assert_true(key_file_config_exists(key_file, "Match", "Name", "test99")); - - assert_true(key_file_config_exists(key_file, "Network", "DHCP", "ipv6")); - assert_true(key_file_config_exists(key_file, "Network", "IPv6AcceptRA", "yes")); - assert_true(key_file_config_exists(key_file, "Network", "LinkLocalAddressing", "ipv6")); - assert_true(key_file_config_exists(key_file, "Network", "DNS", "fe80::4 fe80::5 192.168.1.10 192.168.1.20")); - - assert_true(key_file_config_exists(key_file, "DHCPv4", "UseDNS", "no")); - assert_true(key_file_config_exists(key_file, "DHCPv4", "UseDomains", "yes")); - assert_true(key_file_config_exists(key_file, "DHCPv4", "SendRelease", "no")); - assert_true(key_file_config_exists(key_file, "DHCPv4", "ClientIdentifier", "mac")); - - assert_true(key_file_config_exists(key_file, "DHCPv6", "UseDNS", "no")); - assert_true(key_file_config_exists(key_file, "DHCPv4", "UseDomains", "yes")); - assert_true(key_file_config_exists(key_file, "DHCPv6", "SendRelease", "no")); - - assert_true(key_file_config_exists(key_file, "Address", "Address", "192.168.1.101")); - assert_true(key_file_config_exists(key_file, "Route", "Gateway", "192.168.1.2")); - - unlink("/etc/systemd/network/10-test99.network"); -} - -/* STATICv4 + AUTOv6 + STATIC-DNS */ -void test_static_ipv4_auto_ipv6_static_dns(void **state) { - _cleanup_(key_file_freep) KeyFile *key_file = NULL; - int r; - - assert_true(system("nmctl set-ipv4 dev test99 use-dns no send-release no addr 192.168.1.101 gw 192.168.1.2 dns 192.168.1.10,192.168.1.20") >= 0); - assert_true(system("nmctl set-ipv6 dev test99 accept-ra yes use-dns no dns fe80::4,fe80::5") >= 0); - - r = parse_key_file("/etc/systemd/network/10-test99.network", &key_file); - assert_true(r >= 0); - - display_key_file(key_file); - assert_true(key_file_config_exists(key_file, "Match", "Name", "test99")); - - assert_true(key_file_config_exists(key_file, "Network", "IPv6AcceptRA", "yes")); - assert_true(key_file_config_exists(key_file, "Network", "LinkLocalAddressing", "ipv6")); - assert_true(key_file_config_exists(key_file, "Network", "DNS", "fe80::4 fe80::5 192.168.1.10 192.168.1.20")); - - assert_true(key_file_config_exists(key_file, "DHCPv4", "UseDNS", "no")); - assert_true(key_file_config_exists(key_file, "DHCPv4", "SendRelease", "no")); - - assert_true(key_file_config_exists(key_file, "DHCPv6", "UseDNS", "no")); - - assert_true(key_file_config_exists(key_file, "Address", "Address", "192.168.1.101")); - assert_true(key_file_config_exists(key_file, "Route", "Gateway", "192.168.1.2")); - - unlink("/etc/systemd/network/10-test99.network"); -} - -/* STATICv4 + STATICv6 + STATIC-DNS */ -void test_static_ipv4_static_ipv6_static_dns(void **state) { - _cleanup_(key_file_freep) KeyFile *key_file = NULL; - int r; - - assert_true(system("nmctl set-ipv4 dev test99 use-dns no send-release no addr 192.168.1.101 gw 192.168.1.2 dns 192.168.1.10,192.168.1.20") >= 0); - assert_true(system("nmctl set-ipv6 dev test99 use-dns no accept-ra no addr fe80::10 gw fe80::1 dns fe80::4,fe80::5") >= 0); - - r = parse_key_file("/etc/systemd/network/10-test99.network", &key_file); - assert_true(r >= 0); - - display_key_file(key_file); - assert_true(key_file_config_exists(key_file, "Match", "Name", "test99")); - - assert_true(key_file_config_exists(key_file, "Network", "IPv6AcceptRA", "no")); - assert_true(key_file_config_exists(key_file, "Network", "DNS", "fe80::4 fe80::5 192.168.1.10 192.168.1.20")); - - assert_true(key_file_config_exists(key_file, "DHCPv4", "UseDNS", "no")); - assert_true(key_file_config_exists(key_file, "DHCPv4", "SendRelease", "no")); - - assert_true(key_file_config_exists(key_file, "DHCPv6", "UseDNS", "no")); - - assert_true(key_file_config_exists(key_file, "Address", "Address", "192.168.1.101")); - assert_true(key_file_config_exists(key_file, "Route", "Gateway", "192.168.1.2")); - - assert_true(key_file_config_exists(key_file, "Address", "Address", "fe80::10")); - assert_true(key_file_config_exists(key_file, "Route", "Gateway", "fe80::1")); - - unlink("/etc/systemd/network/10-test99.network"); -} - -/* DHCPv6 + DHCP-DNS */ -void test_none_ipv4_dhcp_ipv6_dhcp_dns(void **state) { - _cleanup_(key_file_freep) KeyFile *key_file = NULL; - int r; - - assert_true(system("nmctl set-ipv6 dev test99 dhcp yes send-release no use-domains yes") >= 0); - - r = parse_key_file("/etc/systemd/network/10-test99.network", &key_file); - assert_true(r >= 0); - - display_key_file(key_file); - assert_true(key_file_config_exists(key_file, "Match", "Name", "test99")); - - assert_true(key_file_config_exists(key_file, "Network", "DHCP", "ipv6")); - assert_true(key_file_config_exists(key_file, "Network", "IPv6AcceptRA", "yes")); - assert_true(key_file_config_exists(key_file, "Network", "LinkLocalAddressing", "ipv6")); - - assert_true(key_file_config_exists(key_file, "DHCPv6", "UseDomains", "yes")); - assert_true(key_file_config_exists(key_file, "DHCPv6", "SendRelease", "no")); - - unlink("/etc/systemd/network/10-test99.network"); -} - -/* AUTOv6 + DHCP-DNS */ -void test_none_ipv4_auto_ipv6_dhcp_dns(void **state) { - _cleanup_(key_file_freep) KeyFile *key_file = NULL; - int r; - - assert_true(system("nmctl set-ipv6 dev test99 dhcp yes accept-ra yes") >= 0); - - r = parse_key_file("/etc/systemd/network/10-test99.network", &key_file); - assert_true(r >= 0); - - display_key_file(key_file); - - assert_true(key_file_config_exists(key_file, "Match", "Name", "test99")); - - assert_true(key_file_config_exists(key_file, "Network", "DHCP", "ipv6")); - assert_true(key_file_config_exists(key_file, "Network", "IPv6AcceptRA", "yes")); - assert_true(key_file_config_exists(key_file, "Network", "LinkLocalAddressing", "ipv6")); - - unlink("/etc/systemd/network/10-test99.network"); -} - -/* STATICv6 + STATIC-DNS */ -void test_none_ipv4_static_ipv6_static_dns(void **state) { - _cleanup_(key_file_freep) KeyFile *key_file = NULL; - int r; - - assert_true(system("nmctl set-ipv6 dev test99 use-dns no accept-ra no addr fe80::10 gw fe80::1 dns fe80::4,fe80::5") >= 0); - - r = parse_key_file("/etc/systemd/network/10-test99.network", &key_file); - assert_true(r >= 0); - - display_key_file(key_file); - assert_true(key_file_config_exists(key_file, "Match", "Name", "test99")); - - assert_true(key_file_config_exists(key_file, "Network", "IPv6AcceptRA", "no")); - assert_true(key_file_config_exists(key_file, "Network", "DNS", "fe80::4 fe80::5")); - - assert_true(key_file_config_exists(key_file, "DHCPv6", "UseDNS", "no")); - - assert_true(key_file_config_exists(key_file, "Address", "Address", "fe80::10")); - assert_true(key_file_config_exists(key_file, "Route", "Gateway", "fe80::1")); - - unlink("/etc/systemd/network/10-test99.network"); -} diff --git a/tests/cmocka/set-network.h b/tests/cmocka/set-network.h index d900b33b..7f6ade4f 100644 --- a/tests/cmocka/set-network.h +++ b/tests/cmocka/set-network.h @@ -50,17 +50,3 @@ void test_vami_set_dynamic_dhcpv4_and_dhcpv6(void **state); void test_vami_set_dynamic_ipv4_static_address_gw(void **state); void test_vami_set_static_ipv6_static_address_gw(void **state); void test_vami_set_static_ipv4_ipv6_static_address_gw(void **state); - -/* with set-ipv4 and set-ipv6 */ -void test_dhcp_ipv4_none_ipv6_dhcp_dns(void **state) ; -void test_dhcp_ipv4_none_ipv6_none_dns(void **state) ; -void test_dhcp_ipv4_dhcp_ipv6_dhcp_dns(void **state) ; -void test_dhcp_ipv4_auto_ipv6_dhcp_dns(void **state) ; -void test_dhcp_ipv4_static_ipv6_static_dns(void **state) ; -void test_static_ipv4_none_ipv6_static_dns(void **state) ; -void test_static_ipv4_dhcp_ipv6_static_dns(void **state) ; -void test_static_ipv4_auto_ipv6_static_dns(void **state) ; -void test_static_ipv4_static_ipv6_static_dns(void **state) ; -void test_none_ipv4_dhcp_ipv6_dhcp_dns(void **state) ; -void test_none_ipv4_auto_ipv6_dhcp_dns(void **state) ; -void test_none_ipv4_static_ipv6_static_dns(void **state) ; From 47f221f502305c512840d3053757ae1da8608422 Mon Sep 17 00:00:00 2001 From: Nitesh Kumar Date: Fri, 2 Aug 2024 22:55:45 +0530 Subject: [PATCH 9/9] network-config-manager: This commit has following changes in set-ipv4 and set-ipv6 command. 1. LinkLocalAddressing overrides while setting ipv6 over ipv4 and vice versa. 2. DNS settings got overrides while setting ipv6 DNS over ipv4 DNS and vice versa. 3. Domains option added in both set-ipv4 and set-ipv6 command to set multiple domain names. 4. UseDomains option added in both set-ipv4 and set-ipv6 command to set UseDomains. 5. ClientIdentifier option added in set-ipv4 command to set ClientIdentifier. 6. Adding multiple test for set-ipv4 and set-ipv6 command. The test is a combination of IPv4, IPv6, DNS, Domains, UseDns, UseDomains, SendRelease, LinkLocalAddressing, ClientIdentifier etc. --- tests/cmocka/basic.c | 72 ++++++++- tests/cmocka/set-network.c | 324 +++++++++++++++++++++++++++++++++++++ tests/cmocka/set-network.h | 14 ++ 3 files changed, 406 insertions(+), 4 deletions(-) diff --git a/tests/cmocka/basic.c b/tests/cmocka/basic.c index 7e60205a..c6bf75d0 100644 --- a/tests/cmocka/basic.c +++ b/tests/cmocka/basic.c @@ -479,6 +479,8 @@ static void test_set_dhcp6_duid(void **state) { assert_true(key_file_config_exists(key_file, "DHCPv6", "DUIDType", "vendor")); assert_true(key_file_config_exists(key_file, "DHCPv6", "DUIDRawData", "00:00:ab:11:f9:2a:c2:77:29:f9:5c:00")); + + unlink("/etc/systemd/network/10-test99.network"); } static void test_set_dhcp4_duid(void **state) { @@ -495,6 +497,8 @@ static void test_set_dhcp4_duid(void **state) { assert_true(key_file_config_exists(key_file, "DHCPv4", "DUIDType", "vendor")); assert_true(key_file_config_exists(key_file, "DHCPv4", "DUIDRawData", "00:00:ab:11:f9:2a:c2:77:29:f9:5c:00")); + + unlink("/etc/systemd/network/10-test99.network"); } static void test_set_dns(void **state) { @@ -510,6 +514,8 @@ static void test_set_dns(void **state) { assert_true(key_file_config_exists(key_file, "Match", "Name", "test99")); assert_true(key_file_config_exists(key_file, "Network", "DNS", "192.168.1.5 192.168.1.4")); + + unlink("/etc/systemd/network/10-test99.network"); } static void test_revert_dns(void **state) { @@ -533,6 +539,8 @@ static void test_revert_dns(void **state) { display_key_file(key_file2); assert_true(!key_file_config_exists(key_file2, "Network", "DNS", "192.168.1.5 192.168.1.4")); + + unlink("/etc/systemd/network/10-test99.network"); } static void test_revert_dns_with_parametre(void **state) { @@ -556,6 +564,8 @@ static void test_revert_dns_with_parametre(void **state) { display_key_file(key_file2); assert_true(!key_file_config_exists(key_file2, "Network", "DNS", "192.168.1.5 192.168.1.4")); + + unlink("/etc/systemd/network/10-test99.network"); } static void test_add_remove_many_address(void **state) { @@ -573,6 +583,8 @@ static void test_add_remove_many_address(void **state) { assert_false(key_file_config_exists(key_file, "Address", "Address", "192.168.1.6/24")); assert_false(key_file_config_exists(key_file, "Address", "Address", "192.168.1.7/24")); assert_false(key_file_config_exists(key_file, "Address", "Address", "192.168.1.8/24")); + + unlink("/etc/systemd/network/10-test99.network"); } static void test_add_many_address(void **state) { @@ -591,6 +603,8 @@ static void test_add_many_address(void **state) { assert_true(key_file_config_exists(key_file, "Address", "Address", "192.168.1.6/24")); assert_true(key_file_config_exists(key_file, "Address", "Address", "192.168.1.7/24")); assert_true(key_file_config_exists(key_file, "Address", "Address", "192.168.1.8/24")); + + unlink("/etc/systemd/network/10-test99.network"); } static void test_add_many_address_ipv6(void **state) { @@ -610,6 +624,8 @@ static void test_add_many_address_ipv6(void **state) { assert_true(key_file_config_exists(key_file, "Address", "Address", "fe80::12/64")); assert_true(key_file_config_exists(key_file, "Address", "Address", "fe80::13/64")); assert_true(key_file_config_exists(key_file, "Address", "Address", "fe80::14/64")); + + unlink("/etc/systemd/network/10-test99.network"); } static void test_cli_set_ipv6_with_static_address(void **state) { @@ -649,6 +665,8 @@ static void test_cli_set_ipv6_with_static_address(void **state) { assert_false(key_file_config_exists(key_file, "Address", "Address", "fe80::15/64")); assert_false(key_file_config_exists(key_file, "Route", "Gateway", "::1")); + + unlink("/etc/systemd/network/10-test99.network"); } static void test_cli_set_ipv6_with_send_release(void **state) { @@ -684,6 +702,7 @@ static void test_cli_set_ipv6_with_send_release(void **state) { assert_false(key_file_config_exists(key_file, "Address", "Address", "fe80::15/64")); assert_false(key_file_config_exists(key_file, "Route", "Gateway", "::1")); + unlink("/etc/systemd/network/10-test99.network"); } static void test_cli_set_ipv6_with_static_address_and_dns(void **state) { @@ -719,6 +738,8 @@ static void test_cli_set_ipv6_with_static_address_and_dns(void **state) { assert_false(key_file_config_exists(key_file, "Address", "Address", "fe80::15/64")); assert_false(key_file_config_exists(key_file, "Route", "Gateway", "::1")); + + unlink("/etc/systemd/network/10-test99.network"); } static void test_cli_set_ipv6_with_static_dynamic_and_dns(void **state) { @@ -760,6 +781,8 @@ static void test_cli_set_ipv6_with_static_dynamic_and_dns(void **state) { assert_false(key_file_config_exists(key_file, "Address", "Address", "fe80::15/64")); assert_false(key_file_config_exists(key_file, "Route", "Gateway", "::1")); + + unlink("/etc/systemd/network/10-test99.network"); } static void test_cli_set_ipv4_with_static_address(void **state) { @@ -786,7 +809,7 @@ static void test_cli_set_ipv4_with_static_address(void **state) { display_key_file(key_file); assert_true(key_file_config_exists(key_file, "Match", "Name", "test99")); - assert_true(key_file_config_exists(key_file, "Network", "DHCP", "ipv6")); + assert_true(key_file_config_exists(key_file, "Network", "DHCP", "no")); assert_true(key_file_config_exists(key_file, "Address", "Address", "192.168.1.101")); assert_true(key_file_config_exists(key_file, "Address", "Address", "192.168.1.102")); @@ -795,6 +818,8 @@ static void test_cli_set_ipv4_with_static_address(void **state) { assert_false(key_file_config_exists(key_file, "Address", "Address", "192.168.1.100")); assert_false(key_file_config_exists(key_file, "Route", "Gateway", "192.168.1.1")); + + unlink("/etc/systemd/network/10-test99.network"); } static void test_cli_set_ipv4_with_send_release(void **state) { @@ -821,13 +846,15 @@ static void test_cli_set_ipv4_with_send_release(void **state) { display_key_file(key_file); assert_true(key_file_config_exists(key_file, "Match", "Name", "test99")); - assert_true(key_file_config_exists(key_file, "Network", "DHCP", "yes")); + assert_true(key_file_config_exists(key_file, "Network", "DHCP", "ipv4")); assert_true(key_file_config_exists(key_file, "Network", "LinkLocalAddressing", "ipv4")); assert_true(key_file_config_exists(key_file, "DHCPv4", "SendRelease", "no")); assert_false(key_file_config_exists(key_file, "Address", "Address", "192.168.1.100")); assert_false(key_file_config_exists(key_file, "Route", "Gateway", "192.168.1.1")); + + unlink("/etc/systemd/network/10-test99.network"); } static void test_cli_set_ipv4_with_static_address_and_dns(void **state) { @@ -854,7 +881,7 @@ static void test_cli_set_ipv4_with_static_address_and_dns(void **state) { display_key_file(key_file); assert_true(key_file_config_exists(key_file, "Match", "Name", "test99")); - assert_true(key_file_config_exists(key_file, "Network", "DHCP", "ipv6")); + assert_true(key_file_config_exists(key_file, "Network", "DHCP", "no")); assert_true(key_file_config_exists(key_file, "Network", "DNS", "192.168.1.10 192.168.1.20")); assert_true(key_file_config_exists(key_file, "Address", "Address", "192.168.1.101")); @@ -863,6 +890,8 @@ static void test_cli_set_ipv4_with_static_address_and_dns(void **state) { assert_false(key_file_config_exists(key_file, "Address", "Address", "192.168.1.100")); assert_false(key_file_config_exists(key_file, "Route", "Gateway", "192.168.1.1")); + + unlink("/etc/systemd/network/10-test99.network"); } static void test_cli_set_ipv4_with_static_dynamic_and_dns(void **state) { @@ -889,7 +918,7 @@ static void test_cli_set_ipv4_with_static_dynamic_and_dns(void **state) { display_key_file(key_file); assert_true(key_file_config_exists(key_file, "Match", "Name", "test99")); - assert_true(key_file_config_exists(key_file, "Network", "DHCP", "yes")); + assert_true(key_file_config_exists(key_file, "Network", "DHCP", "ipv4")); assert_true(key_file_config_exists(key_file, "Network", "LinkLocalAddressing", "ipv4")); assert_true(key_file_config_exists(key_file, "Network", "DNS", "192.168.1.10 192.168.1.20")); @@ -903,6 +932,8 @@ static void test_cli_set_ipv4_with_static_dynamic_and_dns(void **state) { assert_false(key_file_config_exists(key_file, "Address", "Address", "192.168.1.100")); assert_false(key_file_config_exists(key_file, "Route", "Gateway", "192.168.1.1")); + + unlink("/etc/systemd/network/10-test99.network"); } static void test_add_many_address_space_separated(void **state) { @@ -936,6 +967,8 @@ static void test_add_one_address(void **state) { assert_true(key_file_config_exists(key_file, "Match", "Name", "test99")); assert_true(key_file_config_exists(key_file, "Address", "Address", "192.168.1.5/24")); + + unlink("/etc/systemd/network/10-test99.network"); } static void test_add_remove_address(void **state) { @@ -961,6 +994,8 @@ static void test_add_remove_address(void **state) { display_key_file(key_file2); printf("--------------------------------------\n"); assert_false(key_file_config_exists(key_file2, "Address", "Address", "192.168.1.5/24")); + + unlink("/etc/systemd/network/10-test99.network"); } static void test_add_remove_many_address_family_ipv6(void **state) { @@ -981,6 +1016,8 @@ static void test_add_remove_many_address_family_ipv6(void **state) { assert_true(!key_file_config_exists(key_file, "Address", "Address", "fe80::12/64")); assert_true(!key_file_config_exists(key_file, "Address", "Address", "fe80::13/64")); assert_true(!key_file_config_exists(key_file, "Address", "Address", "fe80::14/64")); + + unlink("/etc/systemd/network/10-test99.network"); } static void test_add_remove_many_address_family(void **state) { @@ -1005,6 +1042,8 @@ static void test_add_remove_many_address_family(void **state) { assert_true(!key_file_config_exists(key_file, "Address", "Address", "192.168.1.6/24")); assert_true(!key_file_config_exists(key_file, "Address", "Address", "192.168.1.7/24")); assert_true(!key_file_config_exists(key_file, "Address", "Address", "192.168.1.8/24")); + + unlink("/etc/systemd/network/10-test99.network"); } static void test_add_remove_many_address_family_ipv4(void **state) { @@ -1024,6 +1063,8 @@ static void test_add_remove_many_address_family_ipv4(void **state) { assert_true(!key_file_config_exists(key_file, "Address", "Address", "192.168.1.6/24")); assert_true(!key_file_config_exists(key_file, "Address", "Address", "192.168.1.7/24")); assert_true(!key_file_config_exists(key_file, "Address", "Address", "192.168.1.8/24")); + + unlink("/etc/systemd/network/10-test99.network"); } static void test_replace_many_address_ipv6(void **state) { @@ -1064,6 +1105,8 @@ static void test_replace_many_address_ipv6(void **state) { assert_false(key_file_config_exists(key_file, "Address", "Address", "fe80::12/64")); assert_false(key_file_config_exists(key_file, "Address", "Address", "fe80::13/64")); assert_false(key_file_config_exists(key_file, "Address", "Address", "fe80::14/64")); + + unlink("/etc/systemd/network/10-test99.network"); } static void test_replace_many_address_ipv4(void **state) { @@ -1106,6 +1149,8 @@ static void test_replace_many_address_ipv4(void **state) { assert_false(key_file_config_exists(key_file, "Address", "Address", "192.168.1.5/24")); assert_false(key_file_config_exists(key_file, "Address", "Address", "192.168.1.6/24")); + + unlink("/etc/systemd/network/10-test99.network"); } static void test_set_gw_keep(void **state) { @@ -1123,6 +1168,8 @@ static void test_set_gw_keep(void **state) { assert_true(key_file_config_exists(key_file, "Match", "Name", "test99")); assert_true(key_file_config_exists(key_file, "Route", "Gateway", "192.168.1.1")); assert_true(key_file_config_exists(key_file, "Route", "Gateway", "192.168.1.2")); + + unlink("/etc/systemd/network/10-test99.network"); } static void test_set_gw_family(void **state) { @@ -1155,6 +1202,8 @@ static void test_remove_gw_family(void **state) { assert_true(key_file_config_exists(key_file, "Match", "Name", "test99")); assert_true(!key_file_config_exists(key_file, "Route", "Gateway", "192.168.1.1")); assert_true(!key_file_config_exists(key_file, "Route", "Gateway", "::1")); + + unlink("/etc/systemd/network/10-test99.network"); } static void test_additional_gw_source_routing(void **state) { @@ -1183,6 +1232,8 @@ static void test_additional_gw_source_routing(void **state) { assert_true(key_file_config_exists(key_file, "RoutingPolicyRule", "To", "192.168.10.5/24")); assert_true(key_file_config_exists(key_file, "RoutingPolicyRule", "Table", "100")); + + unlink("/etc/systemd/network/10-test99.network"); } static void test_add_dhcp4_server_static_address(void **state) { @@ -2008,6 +2059,19 @@ int main(void) { cmocka_unit_test (test_vami_set_dynamic_ipv4_static_address_gw), cmocka_unit_test (test_vami_set_static_ipv6_static_address_gw), cmocka_unit_test (test_vami_set_static_ipv4_ipv6_static_address_gw), + /* test cases with set-ipv4 and set-ipv6 */ + cmocka_unit_test (test_dhcp_ipv4_none_ipv6_dhcp_dns), + cmocka_unit_test (test_dhcp_ipv4_none_ipv6_none_dns), + cmocka_unit_test (test_dhcp_ipv4_dhcp_ipv6_dhcp_dns), + cmocka_unit_test (test_dhcp_ipv4_auto_ipv6_dhcp_dns), + cmocka_unit_test (test_dhcp_ipv4_static_ipv6_static_dns), + cmocka_unit_test (test_static_ipv4_none_ipv6_static_dns), + cmocka_unit_test (test_static_ipv4_dhcp_ipv6_static_dns), + cmocka_unit_test (test_static_ipv4_auto_ipv6_static_dns), + cmocka_unit_test (test_static_ipv4_static_ipv6_static_dns), + cmocka_unit_test (test_none_ipv4_dhcp_ipv6_dhcp_dns), + cmocka_unit_test (test_none_ipv4_auto_ipv6_dhcp_dns), + cmocka_unit_test (test_none_ipv4_static_ipv6_static_dns), }; int count_fail_tests = cmocka_run_group_tests (tests, setup, teardown); diff --git a/tests/cmocka/set-network.c b/tests/cmocka/set-network.c index 48d56408..ee39ffb4 100644 --- a/tests/cmocka/set-network.c +++ b/tests/cmocka/set-network.c @@ -526,3 +526,327 @@ void test_set_network_dhcp_ipv4_ipv4_ra_dhcp4_client_identifier_dhcp_iaid_static unlink("/etc/systemd/network/10-test99.network"); } + +/* DHCPv4 + DHCP-DNS */ +void test_dhcp_ipv4_none_ipv6_dhcp_dns(void **state) { + _cleanup_(key_file_freep) KeyFile *key_file = NULL; + int r; + + assert_true(system("nmctl set-ipv4 dev test99 dhcp yes lla ipv4 send-release no use-domains yes cid mac domains eng.vmware.com,vmware.com") >= 0); + + r = parse_key_file("/etc/systemd/network/10-test99.network", &key_file); + assert_true(r >= 0); + + display_key_file(key_file); + assert_true(key_file_config_exists(key_file, "Match", "Name", "test99")); + + assert_true(key_file_config_exists(key_file, "Network", "DHCP", "ipv4")); + assert_true(key_file_config_exists(key_file, "Network", "LinkLocalAddressing", "ipv4")); + assert_true(key_file_config_exists(key_file, "Network", "Domains", "eng.vmware.com vmware.com")); + + assert_true(key_file_config_exists(key_file, "DHCPv4", "SendRelease", "no")); + assert_true(key_file_config_exists(key_file, "DHCPv4", "UseDomains", "yes")); + assert_true(key_file_config_exists(key_file, "DHCPv4", "ClientIdentifier", "mac")); + + unlink("/etc/systemd/network/10-test99.network"); +} + +/* DHCPv4 */ +void test_dhcp_ipv4_none_ipv6_none_dns(void **state) { + _cleanup_(key_file_freep) KeyFile *key_file = NULL; + int r; + + /* Default value of UseDNS=true */ + assert_true(system("nmctl set-ipv4 dev test99 dhcp yes lla ipv4 send-release no use-dns no domains eng.vmware.com,vmware.com") >= 0); + + r = parse_key_file("/etc/systemd/network/10-test99.network", &key_file); + assert_true(r >= 0); + + display_key_file(key_file); + assert_true(key_file_config_exists(key_file, "Match", "Name", "test99")); + + assert_true(key_file_config_exists(key_file, "Network", "DHCP", "ipv4")); + assert_true(key_file_config_exists(key_file, "Network", "LinkLocalAddressing", "ipv4")); + assert_true(key_file_config_exists(key_file, "Network", "Domains", "eng.vmware.com vmware.com")); + + assert_true(key_file_config_exists(key_file, "DHCPv4", "SendRelease", "no")); + assert_true(key_file_config_exists(key_file, "DHCPv4", "UseDNS", "no")); + + unlink("/etc/systemd/network/10-test99.network"); +} + +/* DHCPv4 + DHCPv6 + DHCP-DNS */ +void test_dhcp_ipv4_dhcp_ipv6_dhcp_dns(void **state) { + _cleanup_(key_file_freep) KeyFile *key_file = NULL; + int r; + + assert_true(system("nmctl set-ipv4 dev test99 dhcp yes lla yes send-release no use-domains yes cid mac") >= 0); + assert_true(system("nmctl set-ipv6 dev test99 dhcp yes use-domains yes send-release no") >= 0); + + r = parse_key_file("/etc/systemd/network/10-test99.network", &key_file); + assert_true(r >= 0); + + display_key_file(key_file); + assert_true(key_file_config_exists(key_file, "Match", "Name", "test99")); + + assert_true(key_file_config_exists(key_file, "Network", "DHCP", "yes")); + assert_true(key_file_config_exists(key_file, "Network", "LinkLocalAddressing", "yes")); + assert_true(key_file_config_exists(key_file, "Network", "IPv6AcceptRA", "yes")); + + assert_true(key_file_config_exists(key_file, "DHCPv4", "ClientIdentifier", "mac")); + assert_true(key_file_config_exists(key_file, "DHCPv4", "UseDomains", "yes")); + assert_true(key_file_config_exists(key_file, "DHCPv4", "SendRelease", "no")); + + assert_true(key_file_config_exists(key_file, "DHCPv6", "SendRelease", "no")); + assert_true(key_file_config_exists(key_file, "DHCPv6", "UseDomains", "yes")); + + unlink("/etc/systemd/network/10-test99.network"); +} + +/* DHCPv4 + AUTOv6 + DHCP-DNS */ +void test_dhcp_ipv4_auto_ipv6_dhcp_dns(void **state) { + _cleanup_(key_file_freep) KeyFile *key_file = NULL; + int r; + + assert_true(system("nmctl set-ipv4 dev test99 dhcp yes lla yes send-release no use-domains yes cid mac") >= 0); + assert_true(system("nmctl set-ipv6 dev test99 accept-ra yes use-domains yes") >= 0); + + r = parse_key_file("/etc/systemd/network/10-test99.network", &key_file); + assert_true(r >= 0); + + display_key_file(key_file); + assert_true(key_file_config_exists(key_file, "Match", "Name", "test99")); + + assert_true(key_file_config_exists(key_file, "Network", "DHCP", "ipv4")); + assert_true(key_file_config_exists(key_file, "Network", "LinkLocalAddressing", "yes")); + assert_true(key_file_config_exists(key_file, "Network", "IPv6AcceptRA", "yes")); + + assert_true(key_file_config_exists(key_file, "DHCPv4", "ClientIdentifier", "mac")); + assert_true(key_file_config_exists(key_file, "DHCPv4", "UseDomains", "yes")); + assert_true(key_file_config_exists(key_file, "DHCPv4", "SendRelease", "no")); + + assert_true(key_file_config_exists(key_file, "DHCPv6", "UseDomains", "yes")); + + unlink("/etc/systemd/network/10-test99.network"); +} + +/* DHCPv4 + STATICv6 + STATIC-DNS */ +void test_dhcp_ipv4_static_ipv6_static_dns(void **state) { + _cleanup_(key_file_freep) KeyFile *key_file = NULL; + int r; + + assert_true(system("nmctl set-ipv4 dev test99 dhcp yes lla ipv4 send-release no use-dns no use-domains yes cid mac dns 192.168.1.10,192.168.1.20") >= 0); + assert_true(system("nmctl set-ipv6 dev test99 use-dns no use-domains yes accept-ra no addr fe80::10 gw fe80::1 dns fe80::4,fe80::5") >= 0); + + r = parse_key_file("/etc/systemd/network/10-test99.network", &key_file); + assert_true(r >= 0); + + display_key_file(key_file); + assert_true(key_file_config_exists(key_file, "Match", "Name", "test99")); + + assert_true(key_file_config_exists(key_file, "Network", "DHCP", "ipv4")); + assert_true(key_file_config_exists(key_file, "Network", "LinkLocalAddressing", "ipv4")); + assert_true(key_file_config_exists(key_file, "Network", "DNS", "fe80::4 fe80::5 192.168.1.10 192.168.1.20")); + assert_true(key_file_config_exists(key_file, "Network", "IPv6AcceptRA", "no")); + + assert_true(key_file_config_exists(key_file, "DHCPv4", "ClientIdentifier", "mac")); + assert_true(key_file_config_exists(key_file, "DHCPv4", "UseDomains", "yes")); + assert_true(key_file_config_exists(key_file, "DHCPv4", "UseDNS", "no")); + assert_true(key_file_config_exists(key_file, "DHCPv4", "SendRelease", "no")); + + assert_true(key_file_config_exists(key_file, "DHCPv6", "UseDomains", "yes")); + assert_true(key_file_config_exists(key_file, "DHCPv6", "UseDNS", "no")); + + assert_true(key_file_config_exists(key_file, "Address", "Address", "fe80::10")); + assert_true(key_file_config_exists(key_file, "Route", "Gateway", "fe80::1")); + + unlink("/etc/systemd/network/10-test99.network"); +} + +/* STATICv4 + STATIC-DNS */ +void test_static_ipv4_none_ipv6_static_dns(void **state) { + _cleanup_(key_file_freep) KeyFile *key_file = NULL; + int r; + + assert_true(system("nmctl set-ipv4 dev test99 lla no use-dns no send-release no addr 192.168.1.101 gw 192.168.1.2 dns 192.168.1.10,192.168.1.20") >= 0); + + r = parse_key_file("/etc/systemd/network/10-test99.network", &key_file); + assert_true(r >= 0); + + display_key_file(key_file); + assert_true(key_file_config_exists(key_file, "Match", "Name", "test99")); + + assert_true(key_file_config_exists(key_file, "Network", "LinkLocalAddressing", "no")); + assert_true(key_file_config_exists(key_file, "Network", "DNS", "192.168.1.10 192.168.1.20")); + + assert_true(key_file_config_exists(key_file, "DHCPv4", "UseDNS", "no")); + assert_true(key_file_config_exists(key_file, "DHCPv4", "SendRelease", "no")); + + assert_true(key_file_config_exists(key_file, "Address", "Address", "192.168.1.101")); + assert_true(key_file_config_exists(key_file, "Route", "Gateway", "192.168.1.2")); + + unlink("/etc/systemd/network/10-test99.network"); + +} + +/* STATICv4 + DHCPv6 + STATIC-DNS */ +void test_static_ipv4_dhcp_ipv6_static_dns(void **state) { + _cleanup_(key_file_freep) KeyFile *key_file = NULL; + int r; + + assert_true(system("nmctl set-ipv4 dev test99 use-dns no use-domains yes send-release no cid mac addr 192.168.1.101 gw 192.168.1.2 dns 192.168.1.10,192.168.1.20") >= 0); + assert_true(system("nmctl set-ipv6 dev test99 dhcp yes use-dns no use-domains yes send-release no dns fe80::4,fe80::5") >= 0); + + r = parse_key_file("/etc/systemd/network/10-test99.network", &key_file); + assert_true(r >= 0); + + display_key_file(key_file); + assert_true(key_file_config_exists(key_file, "Match", "Name", "test99")); + + assert_true(key_file_config_exists(key_file, "Network", "DHCP", "ipv6")); + assert_true(key_file_config_exists(key_file, "Network", "IPv6AcceptRA", "yes")); + assert_true(key_file_config_exists(key_file, "Network", "LinkLocalAddressing", "ipv6")); + assert_true(key_file_config_exists(key_file, "Network", "DNS", "fe80::4 fe80::5 192.168.1.10 192.168.1.20")); + + assert_true(key_file_config_exists(key_file, "DHCPv4", "UseDNS", "no")); + assert_true(key_file_config_exists(key_file, "DHCPv4", "UseDomains", "yes")); + assert_true(key_file_config_exists(key_file, "DHCPv4", "SendRelease", "no")); + assert_true(key_file_config_exists(key_file, "DHCPv4", "ClientIdentifier", "mac")); + + assert_true(key_file_config_exists(key_file, "DHCPv6", "UseDNS", "no")); + assert_true(key_file_config_exists(key_file, "DHCPv4", "UseDomains", "yes")); + assert_true(key_file_config_exists(key_file, "DHCPv6", "SendRelease", "no")); + + assert_true(key_file_config_exists(key_file, "Address", "Address", "192.168.1.101")); + assert_true(key_file_config_exists(key_file, "Route", "Gateway", "192.168.1.2")); + + unlink("/etc/systemd/network/10-test99.network"); +} + +/* STATICv4 + AUTOv6 + STATIC-DNS */ +void test_static_ipv4_auto_ipv6_static_dns(void **state) { + _cleanup_(key_file_freep) KeyFile *key_file = NULL; + int r; + + assert_true(system("nmctl set-ipv4 dev test99 use-dns no send-release no addr 192.168.1.101 gw 192.168.1.2 dns 192.168.1.10,192.168.1.20") >= 0); + assert_true(system("nmctl set-ipv6 dev test99 accept-ra yes use-dns no dns fe80::4,fe80::5") >= 0); + + r = parse_key_file("/etc/systemd/network/10-test99.network", &key_file); + assert_true(r >= 0); + + display_key_file(key_file); + assert_true(key_file_config_exists(key_file, "Match", "Name", "test99")); + + assert_true(key_file_config_exists(key_file, "Network", "IPv6AcceptRA", "yes")); + assert_true(key_file_config_exists(key_file, "Network", "LinkLocalAddressing", "ipv6")); + assert_true(key_file_config_exists(key_file, "Network", "DNS", "fe80::4 fe80::5 192.168.1.10 192.168.1.20")); + + assert_true(key_file_config_exists(key_file, "DHCPv4", "UseDNS", "no")); + assert_true(key_file_config_exists(key_file, "DHCPv4", "SendRelease", "no")); + + assert_true(key_file_config_exists(key_file, "DHCPv6", "UseDNS", "no")); + + assert_true(key_file_config_exists(key_file, "Address", "Address", "192.168.1.101")); + assert_true(key_file_config_exists(key_file, "Route", "Gateway", "192.168.1.2")); + + unlink("/etc/systemd/network/10-test99.network"); +} + +/* STATICv4 + STATICv6 + STATIC-DNS */ +void test_static_ipv4_static_ipv6_static_dns(void **state) { + _cleanup_(key_file_freep) KeyFile *key_file = NULL; + int r; + + assert_true(system("nmctl set-ipv4 dev test99 use-dns no send-release no addr 192.168.1.101 gw 192.168.1.2 dns 192.168.1.10,192.168.1.20") >= 0); + assert_true(system("nmctl set-ipv6 dev test99 use-dns no accept-ra no addr fe80::10 gw fe80::1 dns fe80::4,fe80::5") >= 0); + + r = parse_key_file("/etc/systemd/network/10-test99.network", &key_file); + assert_true(r >= 0); + + display_key_file(key_file); + assert_true(key_file_config_exists(key_file, "Match", "Name", "test99")); + + assert_true(key_file_config_exists(key_file, "Network", "IPv6AcceptRA", "no")); + assert_true(key_file_config_exists(key_file, "Network", "DNS", "fe80::4 fe80::5 192.168.1.10 192.168.1.20")); + + assert_true(key_file_config_exists(key_file, "DHCPv4", "UseDNS", "no")); + assert_true(key_file_config_exists(key_file, "DHCPv4", "SendRelease", "no")); + + assert_true(key_file_config_exists(key_file, "DHCPv6", "UseDNS", "no")); + + assert_true(key_file_config_exists(key_file, "Address", "Address", "192.168.1.101")); + assert_true(key_file_config_exists(key_file, "Route", "Gateway", "192.168.1.2")); + + assert_true(key_file_config_exists(key_file, "Address", "Address", "fe80::10")); + assert_true(key_file_config_exists(key_file, "Route", "Gateway", "fe80::1")); + + unlink("/etc/systemd/network/10-test99.network"); +} + +/* DHCPv6 + DHCP-DNS */ +void test_none_ipv4_dhcp_ipv6_dhcp_dns(void **state) { + _cleanup_(key_file_freep) KeyFile *key_file = NULL; + int r; + + assert_true(system("nmctl set-ipv6 dev test99 dhcp yes send-release no use-domains yes") >= 0); + + r = parse_key_file("/etc/systemd/network/10-test99.network", &key_file); + assert_true(r >= 0); + + display_key_file(key_file); + assert_true(key_file_config_exists(key_file, "Match", "Name", "test99")); + + assert_true(key_file_config_exists(key_file, "Network", "DHCP", "ipv6")); + assert_true(key_file_config_exists(key_file, "Network", "IPv6AcceptRA", "yes")); + assert_true(key_file_config_exists(key_file, "Network", "LinkLocalAddressing", "ipv6")); + + assert_true(key_file_config_exists(key_file, "DHCPv6", "UseDomains", "yes")); + assert_true(key_file_config_exists(key_file, "DHCPv6", "SendRelease", "no")); + + unlink("/etc/systemd/network/10-test99.network"); +} + +/* AUTOv6 + DHCP-DNS */ +void test_none_ipv4_auto_ipv6_dhcp_dns(void **state) { + _cleanup_(key_file_freep) KeyFile *key_file = NULL; + int r; + + assert_true(system("nmctl set-ipv6 dev test99 dhcp yes accept-ra yes") >= 0); + + r = parse_key_file("/etc/systemd/network/10-test99.network", &key_file); + assert_true(r >= 0); + + display_key_file(key_file); + + assert_true(key_file_config_exists(key_file, "Match", "Name", "test99")); + + assert_true(key_file_config_exists(key_file, "Network", "DHCP", "ipv6")); + assert_true(key_file_config_exists(key_file, "Network", "IPv6AcceptRA", "yes")); + assert_true(key_file_config_exists(key_file, "Network", "LinkLocalAddressing", "ipv6")); + + unlink("/etc/systemd/network/10-test99.network"); +} + +/* STATICv6 + STATIC-DNS */ +void test_none_ipv4_static_ipv6_static_dns(void **state) { + _cleanup_(key_file_freep) KeyFile *key_file = NULL; + int r; + + assert_true(system("nmctl set-ipv6 dev test99 use-dns no accept-ra no addr fe80::10 gw fe80::1 dns fe80::4,fe80::5") >= 0); + + r = parse_key_file("/etc/systemd/network/10-test99.network", &key_file); + assert_true(r >= 0); + + display_key_file(key_file); + assert_true(key_file_config_exists(key_file, "Match", "Name", "test99")); + + assert_true(key_file_config_exists(key_file, "Network", "IPv6AcceptRA", "no")); + assert_true(key_file_config_exists(key_file, "Network", "DNS", "fe80::4 fe80::5")); + + assert_true(key_file_config_exists(key_file, "DHCPv6", "UseDNS", "no")); + + assert_true(key_file_config_exists(key_file, "Address", "Address", "fe80::10")); + assert_true(key_file_config_exists(key_file, "Route", "Gateway", "fe80::1")); + + unlink("/etc/systemd/network/10-test99.network"); +} diff --git a/tests/cmocka/set-network.h b/tests/cmocka/set-network.h index 7f6ade4f..d900b33b 100644 --- a/tests/cmocka/set-network.h +++ b/tests/cmocka/set-network.h @@ -50,3 +50,17 @@ void test_vami_set_dynamic_dhcpv4_and_dhcpv6(void **state); void test_vami_set_dynamic_ipv4_static_address_gw(void **state); void test_vami_set_static_ipv6_static_address_gw(void **state); void test_vami_set_static_ipv4_ipv6_static_address_gw(void **state); + +/* with set-ipv4 and set-ipv6 */ +void test_dhcp_ipv4_none_ipv6_dhcp_dns(void **state) ; +void test_dhcp_ipv4_none_ipv6_none_dns(void **state) ; +void test_dhcp_ipv4_dhcp_ipv6_dhcp_dns(void **state) ; +void test_dhcp_ipv4_auto_ipv6_dhcp_dns(void **state) ; +void test_dhcp_ipv4_static_ipv6_static_dns(void **state) ; +void test_static_ipv4_none_ipv6_static_dns(void **state) ; +void test_static_ipv4_dhcp_ipv6_static_dns(void **state) ; +void test_static_ipv4_auto_ipv6_static_dns(void **state) ; +void test_static_ipv4_static_ipv6_static_dns(void **state) ; +void test_none_ipv4_dhcp_ipv6_dhcp_dns(void **state) ; +void test_none_ipv4_auto_ipv6_dhcp_dns(void **state) ; +void test_none_ipv4_static_ipv6_static_dns(void **state) ;