cli: merge IPv4 and IPv6 versions of ip/dhcp config print

This commit is contained in:
Thomas Haller 2018-04-26 20:09:53 +02:00
parent bddf482fa1
commit 940979a5a6
4 changed files with 40 additions and 48 deletions

View file

@ -336,49 +336,29 @@ const NmcMetaGenericInfo *const metagen_dhcp_config[_NMC_GENERIC_INFO_TYPE_DHCP_
/*****************************************************************************/
gboolean
print_ip4_config (NMIPConfig *cfg4,
const NmcConfig *nmc_config,
const char *one_field)
print_ip_config (NMIPConfig *cfg,
int addr_family,
const NmcConfig *nmc_config,
const char *one_field)
{
gs_free_error GError *error = NULL;
gs_free char *field_str = NULL;
if (cfg4 == NULL)
if (!cfg)
return FALSE;
if (one_field)
field_str = g_strdup_printf ("IP4.%s", one_field);
if (!nmc_print (nmc_config,
(gpointer[]) { cfg4, NULL },
NULL,
NMC_META_GENERIC_GROUP ("IP4", metagen_ip4_config, N_("GROUP")),
field_str,
&error)) {
return FALSE;
if (one_field) {
field_str = g_strdup_printf ("IP%c.%s",
nm_utils_addr_family_to_char (addr_family),
one_field);
}
return TRUE;
}
gboolean
print_ip6_config (NMIPConfig *cfg6,
const NmcConfig *nmc_config,
const char *group_prefix,
const char *one_field)
{
gs_free_error GError *error = NULL;
gs_free char *field_str = NULL;
if (cfg6 == NULL)
return FALSE;
if (one_field)
field_str = g_strdup_printf ("IP6.%s", one_field);
if (!nmc_print (nmc_config,
(gpointer[]) { cfg6, NULL },
(gpointer[]) { cfg, NULL },
NULL,
NMC_META_GENERIC_GROUP ("IP6", metagen_ip6_config, N_("GROUP")),
addr_family == AF_INET
? NMC_META_GENERIC_GROUP ("IP4", metagen_ip4_config, N_("GROUP"))
: NMC_META_GENERIC_GROUP ("IP6", metagen_ip6_config, N_("GROUP")),
field_str,
&error)) {
return FALSE;
@ -388,8 +368,8 @@ print_ip6_config (NMIPConfig *cfg6,
gboolean
print_dhcp_config (NMDhcpConfig *dhcp,
int addr_family,
const NmcConfig *nmc_config,
const char *group_prefix,
const char *one_field)
{
gs_free_error GError *error = NULL;
@ -398,13 +378,18 @@ print_dhcp_config (NMDhcpConfig *dhcp,
if (!dhcp)
return FALSE;
if (one_field)
field_str = g_strdup_printf ("%s.%s", group_prefix, one_field);
if (one_field) {
field_str = g_strdup_printf ("DHCP%c.%s",
nm_utils_addr_family_to_char (addr_family),
one_field);
}
if (!nmc_print (nmc_config,
(gpointer[]) { dhcp, NULL },
NULL,
NMC_META_GENERIC_GROUP (group_prefix, metagen_dhcp_config, N_("GROUP")),
addr_family == AF_INET
? NMC_META_GENERIC_GROUP ("DHCP4", metagen_dhcp_config, N_("GROUP"))
: NMC_META_GENERIC_GROUP ("DHCP6", metagen_dhcp_config, N_("GROUP")),
field_str,
&error)) {
return FALSE;

View file

@ -25,9 +25,16 @@
#include "nmcli.h"
#include "nm-secret-agent-simple.h"
gboolean print_ip4_config (NMIPConfig *cfg4, const NmcConfig *nmc_config, const char *one_field);
gboolean print_ip6_config (NMIPConfig *cfg6, const NmcConfig *nmc_config, const char *group_prefix, const char *one_field);
gboolean print_dhcp_config (NMDhcpConfig *dhcp, const NmcConfig *nmc_config, const char *group_prefix, const char *one_field);
gboolean print_ip_config (NMIPConfig *cfg,
int addr_family,
const NmcConfig *nmc_config,
const char *one_field);
gboolean print_dhcp_config (NMDhcpConfig *dhcp,
int addr_family,
const NmcConfig *nmc_config,
const char *one_field);
NMConnection *nmc_find_connection (const GPtrArray *connections,
const char *filter_type,

View file

@ -1392,7 +1392,7 @@ nmc_active_connection_details (NMActiveConnection *acon, NmCli *nmc)
gboolean b1 = FALSE;
NMIPConfig *cfg4 = nm_active_connection_get_ip4_config (acon);
b1 = print_ip4_config (cfg4, &nmc->nmc_config, group_fld);
b1 = print_ip_config (cfg4, AF_INET, &nmc->nmc_config, group_fld);
was_output = was_output || b1;
}
@ -1401,7 +1401,7 @@ nmc_active_connection_details (NMActiveConnection *acon, NmCli *nmc)
gboolean b1 = FALSE;
NMDhcpConfig *dhcp4 = nm_active_connection_get_dhcp4_config (acon);
b1 = print_dhcp_config (dhcp4, &nmc->nmc_config, "DHCP4", group_fld);
b1 = print_dhcp_config (dhcp4, AF_INET, &nmc->nmc_config, group_fld);
was_output = was_output || b1;
}
@ -1410,7 +1410,7 @@ nmc_active_connection_details (NMActiveConnection *acon, NmCli *nmc)
gboolean b1 = FALSE;
NMIPConfig *cfg6 = nm_active_connection_get_ip6_config (acon);
b1 = print_ip6_config (cfg6, &nmc->nmc_config, "IP6", group_fld);
b1 = print_ip_config (cfg6, AF_INET6, &nmc->nmc_config, group_fld);
was_output = was_output || b1;
}
@ -1419,7 +1419,7 @@ nmc_active_connection_details (NMActiveConnection *acon, NmCli *nmc)
gboolean b1 = FALSE;
NMDhcpConfig *dhcp6 = nm_active_connection_get_dhcp6_config (acon);
b1 = print_dhcp_config (dhcp6, &nmc->nmc_config, "DHCP6", group_fld);
b1 = print_dhcp_config (dhcp6, AF_INET6, &nmc->nmc_config, group_fld);
was_output = was_output || b1;
}

View file

@ -1319,19 +1319,19 @@ show_device_info (NMDevice *device, NmCli *nmc)
/* IP4 */
if (cfg4 && !strcasecmp (nmc_fields_dev_show_sections[section_idx]->name, nmc_fields_dev_show_sections[7]->name))
was_output = print_ip4_config (cfg4, &nmc->nmc_config, section_fld);
was_output = print_ip_config (cfg4, AF_INET, &nmc->nmc_config, section_fld);
/* DHCP4 */
if (dhcp4 && !strcasecmp (nmc_fields_dev_show_sections[section_idx]->name, nmc_fields_dev_show_sections[8]->name))
was_output = print_dhcp_config (dhcp4, &nmc->nmc_config, nmc_fields_dev_show_sections[8]->name, section_fld);
was_output = print_dhcp_config (dhcp4, AF_INET, &nmc->nmc_config, section_fld);
/* IP6 */
if (cfg6 && !strcasecmp (nmc_fields_dev_show_sections[section_idx]->name, nmc_fields_dev_show_sections[9]->name))
was_output = print_ip6_config (cfg6, &nmc->nmc_config, nmc_fields_dev_show_sections[9]->name, section_fld);
was_output = print_ip_config (cfg6, AF_INET6, &nmc->nmc_config, section_fld);
/* DHCP6 */
if (dhcp6 && !strcasecmp (nmc_fields_dev_show_sections[section_idx]->name, nmc_fields_dev_show_sections[10]->name))
was_output = print_dhcp_config (dhcp6, &nmc->nmc_config, nmc_fields_dev_show_sections[10]->name, section_fld);
was_output = print_dhcp_config (dhcp6, AF_INET6, &nmc->nmc_config, section_fld);
/* Bond specific information */
if (NM_IS_DEVICE_BOND (device)) {