mirror of
https://gitlab.freedesktop.org/NetworkManager/NetworkManager.git
synced 2025-12-27 16:20:09 +01:00
l3cfg: accept NULL NML3ConfigData for several getters
We often want to be pedantic about not accepting %NULL for getters (or ref,
unref, etc). Often that is also inconvenient, so we would need to write:
if (l3cd)
strv = nm_l3_config_data_get_nameservers(l3cd, addr_family, &len);
else
len = 0;
(and, make sure that strv does not trigger a maybe-uninitialized warning).
Being pedanic here is more cumbersome than helpful. Accept NULL to return
the sensible default.
Also add nm_l3_config_data_get_dns_priority_or_default() helper which maps
NULL or a missing value to zero. This is also only for convenience for certain
callers.
This commit is contained in:
parent
e60843e245
commit
5efd3134e4
2 changed files with 42 additions and 5 deletions
|
|
@ -1394,10 +1394,15 @@ _check_and_add_domain(GPtrArray **p_arr, const char *domain)
|
|||
gconstpointer
|
||||
nm_l3_config_data_get_nameservers(const NML3ConfigData *self, int addr_family, guint *out_len)
|
||||
{
|
||||
nm_assert(_NM_IS_L3_CONFIG_DATA(self, TRUE));
|
||||
nm_assert(!self || _NM_IS_L3_CONFIG_DATA(self, TRUE));
|
||||
nm_assert_addr_family(addr_family);
|
||||
nm_assert(out_len);
|
||||
|
||||
if (!self) {
|
||||
*out_len = 0;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return _garray_inaddr_get(self->nameservers_x[NM_IS_IPv4(addr_family)], out_len);
|
||||
}
|
||||
|
||||
|
|
@ -1430,7 +1435,13 @@ nm_l3_config_data_clear_nameservers(NML3ConfigData *self, int addr_family)
|
|||
const in_addr_t *
|
||||
nm_l3_config_data_get_wins(const NML3ConfigData *self, guint *out_len)
|
||||
{
|
||||
nm_assert(_NM_IS_L3_CONFIG_DATA(self, TRUE));
|
||||
nm_assert(!self || _NM_IS_L3_CONFIG_DATA(self, TRUE));
|
||||
nm_assert(out_len);
|
||||
|
||||
if (!self) {
|
||||
*out_len = 0;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return _garray_inaddr_get(self->wins, out_len);
|
||||
}
|
||||
|
|
@ -1478,10 +1489,15 @@ nm_l3_config_data_set_nis_domain(NML3ConfigData *self, const char *nis_domain)
|
|||
const char *const *
|
||||
nm_l3_config_data_get_domains(const NML3ConfigData *self, int addr_family, guint *out_len)
|
||||
{
|
||||
nm_assert(_NM_IS_L3_CONFIG_DATA(self, TRUE));
|
||||
nm_assert(!self || _NM_IS_L3_CONFIG_DATA(self, TRUE));
|
||||
nm_assert_addr_family(addr_family);
|
||||
nm_assert(out_len);
|
||||
|
||||
if (!self) {
|
||||
*out_len = 0;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return nm_strv_ptrarray_get_unsafe(self->domains_x[NM_IS_IPv4(addr_family)], out_len);
|
||||
}
|
||||
|
||||
|
|
@ -1497,10 +1513,15 @@ nm_l3_config_data_add_domain(NML3ConfigData *self, int addr_family, const char *
|
|||
const char *const *
|
||||
nm_l3_config_data_get_searches(const NML3ConfigData *self, int addr_family, guint *out_len)
|
||||
{
|
||||
nm_assert(_NM_IS_L3_CONFIG_DATA(self, TRUE));
|
||||
nm_assert(!self || _NM_IS_L3_CONFIG_DATA(self, TRUE));
|
||||
nm_assert_addr_family(addr_family);
|
||||
nm_assert(out_len);
|
||||
|
||||
if (!self) {
|
||||
*out_len = 0;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return nm_strv_ptrarray_get_unsafe(self->searches_x[NM_IS_IPv4(addr_family)], out_len);
|
||||
}
|
||||
|
||||
|
|
@ -1550,10 +1571,15 @@ nm_l3_config_data_add_dns_option(NML3ConfigData *self, int addr_family, const ch
|
|||
const char *const *
|
||||
nm_l3_config_data_get_dns_options(const NML3ConfigData *self, int addr_family, guint *out_len)
|
||||
{
|
||||
nm_assert(_NM_IS_L3_CONFIG_DATA(self, TRUE));
|
||||
nm_assert(!self || _NM_IS_L3_CONFIG_DATA(self, TRUE));
|
||||
nm_assert_addr_family(addr_family);
|
||||
nm_assert(out_len);
|
||||
|
||||
if (!self) {
|
||||
*out_len = 0;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return nm_strv_ptrarray_get_unsafe(self->dns_options_x[NM_IS_IPv4(addr_family)], out_len);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -512,6 +512,17 @@ nm_l3_config_data_get_dns_options(const NML3ConfigData *self, int addr_family, g
|
|||
gboolean
|
||||
nm_l3_config_data_get_dns_priority(const NML3ConfigData *self, int addr_family, int *out_prio);
|
||||
|
||||
static inline int
|
||||
nm_l3_config_data_get_dns_priority_or_default(const NML3ConfigData *self, int addr_family)
|
||||
{
|
||||
int v;
|
||||
|
||||
nm_assert_addr_family(addr_family);
|
||||
if (!self || !nm_l3_config_data_get_dns_priority(self, addr_family, &v))
|
||||
return 0;
|
||||
return v;
|
||||
}
|
||||
|
||||
gboolean
|
||||
nm_l3_config_data_set_dns_priority(NML3ConfigData *self, int addr_family, int dns_priority);
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue