l3cfg: add more API to NML3ConfigData
This commit is contained in:
@@ -219,6 +219,20 @@ _garray_inaddr_find (GArray *arr,
|
||||
return -1;
|
||||
}
|
||||
|
||||
static gconstpointer
|
||||
_garray_inaddr_get (GArray *arr,
|
||||
guint *out_len)
|
||||
{
|
||||
nm_assert (out_len);
|
||||
|
||||
if (!arr) {
|
||||
*out_len = 0;
|
||||
return NULL;
|
||||
}
|
||||
*out_len = arr->len;
|
||||
return arr->data;
|
||||
}
|
||||
|
||||
static gboolean
|
||||
_garray_inaddr_add (GArray **p_arr,
|
||||
int addr_family,
|
||||
@@ -546,8 +560,7 @@ nm_l3_config_data_lookup_index (const NML3ConfigData *self, NMPObjectType obj_ty
|
||||
case NMP_OBJECT_TYPE_IP6_ROUTE:
|
||||
return &self->idx_routes_6.parent;
|
||||
default:
|
||||
nm_assert_not_reached ();
|
||||
return NULL;
|
||||
return nm_assert_unreachable_val (NULL);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -575,6 +588,30 @@ nm_l3_config_data_lookup_obj (const NML3ConfigData *self,
|
||||
obj);
|
||||
}
|
||||
|
||||
const NMPObject *
|
||||
nmtst_l3_config_data_get_obj_at (const NML3ConfigData *self,
|
||||
NMPObjectType obj_type,
|
||||
guint i)
|
||||
{
|
||||
NMDedupMultiIter iter;
|
||||
guint j;
|
||||
|
||||
nm_assert (_NM_IS_L3_CONFIG_DATA (self, TRUE));
|
||||
|
||||
j = 0;
|
||||
nm_dedup_multi_iter_init (&iter,
|
||||
nm_l3_config_data_lookup_objs (self, obj_type));
|
||||
while (nm_dedup_multi_iter_next (&iter)) {
|
||||
nm_assert (iter.current);
|
||||
nm_assert (NMP_OBJECT_GET_TYPE (iter.current->obj) == obj_type);
|
||||
if (i == j)
|
||||
return iter.current->obj;
|
||||
j++;
|
||||
}
|
||||
|
||||
g_return_val_if_reached (NULL);
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
|
||||
NMDedupMultiIndex *
|
||||
@@ -892,6 +929,16 @@ nm_l3_config_data_add_route_full (NML3ConfigData *self,
|
||||
return changed;
|
||||
}
|
||||
|
||||
const NMPObject *
|
||||
nm_l3_config_data_get_best_default_route (const NML3ConfigData *self,
|
||||
int addr_family)
|
||||
{
|
||||
nm_assert (_NM_IS_L3_CONFIG_DATA (self, TRUE));
|
||||
nm_assert_addr_family (addr_family);
|
||||
|
||||
return self->best_default_route_x[NM_IS_IPv4 (addr_family)];
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
|
||||
static gboolean
|
||||
@@ -924,6 +971,18 @@ _check_and_add_domain (GPtrArray **p_arr, const char *domain)
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
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_addr_family (addr_family);
|
||||
nm_assert (out_len);
|
||||
|
||||
return _garray_inaddr_get (self->nameservers_x[NM_IS_IPv4 (addr_family)], out_len);
|
||||
}
|
||||
|
||||
gboolean
|
||||
nm_l3_config_data_add_nameserver (NML3ConfigData *self,
|
||||
int addr_family,
|
||||
@@ -938,6 +997,15 @@ nm_l3_config_data_add_nameserver (NML3ConfigData *self,
|
||||
nameserver);
|
||||
}
|
||||
|
||||
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));
|
||||
|
||||
return _garray_inaddr_get (self->wins, out_len);
|
||||
}
|
||||
|
||||
gboolean
|
||||
nm_l3_config_data_add_wins (NML3ConfigData *self,
|
||||
in_addr_t wins)
|
||||
@@ -980,6 +1048,18 @@ nm_l3_config_data_add_domain (NML3ConfigData *self,
|
||||
return _check_and_add_domain (&self->domains_x[NM_IS_IPv4 (addr_family)], domain);
|
||||
}
|
||||
|
||||
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_addr_family (addr_family);
|
||||
nm_assert (out_len);
|
||||
|
||||
return nm_strv_ptrarray_get_unsafe (self->searches_x[NM_IS_IPv4 (addr_family)], out_len);
|
||||
}
|
||||
|
||||
gboolean
|
||||
nm_l3_config_data_add_search (NML3ConfigData *self,
|
||||
int addr_family,
|
||||
@@ -1089,6 +1169,14 @@ nm_l3_config_data_set_route_table_sync (NML3ConfigData *self,
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
NMTernary
|
||||
nm_l3_config_data_get_metered (const NML3ConfigData *self)
|
||||
{
|
||||
nm_assert (_NM_IS_L3_CONFIG_DATA (self, TRUE));
|
||||
|
||||
return self->metered;
|
||||
}
|
||||
|
||||
gboolean
|
||||
nm_l3_config_data_set_metered (NML3ConfigData *self,
|
||||
NMTernary metered)
|
||||
@@ -1102,18 +1190,24 @@ nm_l3_config_data_set_metered (NML3ConfigData *self,
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
guint32
|
||||
nm_l3_config_data_get_mtu (const NML3ConfigData *self)
|
||||
{
|
||||
nm_assert (_NM_IS_L3_CONFIG_DATA (self, TRUE));
|
||||
|
||||
return self->mtu;
|
||||
}
|
||||
|
||||
gboolean
|
||||
nm_l3_config_data_set_mtu (NML3ConfigData *self,
|
||||
guint32 mtu)
|
||||
{
|
||||
nm_assert (_NM_IS_L3_CONFIG_DATA (self, FALSE));
|
||||
|
||||
if ( self->mtu == mtu
|
||||
&& NM_FLAGS_HAS (self->flags, NM_L3_CONFIG_DAT_FLAGS_HAS_MTU))
|
||||
if (self->mtu == mtu)
|
||||
return FALSE;
|
||||
|
||||
self->mtu = mtu;
|
||||
self->flags |= NM_L3_CONFIG_DAT_FLAGS_HAS_MTU;
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
@@ -1209,8 +1303,7 @@ nm_l3_config_data_cmp (const NML3ConfigData *a, const NML3ConfigData *b)
|
||||
NM_CMP_FIELD_STR0 (a, b, nis_domain);
|
||||
NM_CMP_DIRECT (a->mdns, b->mdns);
|
||||
NM_CMP_DIRECT (a->llmnr, b->llmnr);
|
||||
if (NM_FLAGS_HAS (a->flags, NM_L3_CONFIG_DAT_FLAGS_HAS_MTU))
|
||||
NM_CMP_DIRECT (a->mtu, b->mtu);
|
||||
NM_CMP_DIRECT (a->mtu, b->mtu);
|
||||
NM_CMP_DIRECT_UNSAFE (a->metered, b->metered);
|
||||
|
||||
NM_CMP_FIELD (a, b, source);
|
||||
@@ -1686,15 +1779,17 @@ NML3ConfigData *
|
||||
nm_l3_config_data_new_from_connection (NMDedupMultiIndex *multi_idx,
|
||||
int ifindex,
|
||||
NMConnection *connection,
|
||||
guint32 route_table,
|
||||
guint32 route_metric)
|
||||
guint32 route_table_4,
|
||||
guint32 route_table_6,
|
||||
guint32 route_metric_4,
|
||||
guint32 route_metric_6)
|
||||
{
|
||||
NML3ConfigData *self;
|
||||
|
||||
self = nm_l3_config_data_new (multi_idx, ifindex);
|
||||
|
||||
_init_from_connection_ip (self, AF_INET, connection, route_table, route_metric);
|
||||
_init_from_connection_ip (self, AF_INET6, connection, route_table, route_metric);
|
||||
_init_from_connection_ip (self, AF_INET, connection, route_table_4, route_metric_4);
|
||||
_init_from_connection_ip (self, AF_INET6, connection, route_table_6, route_metric_6);
|
||||
return self;
|
||||
}
|
||||
|
||||
@@ -1927,11 +2022,8 @@ _init_merge (NML3ConfigData *self,
|
||||
if (self->metered == NM_TERNARY_DEFAULT)
|
||||
self->metered = src->metered;
|
||||
|
||||
if ( !NM_FLAGS_HAS (self->flags, NM_L3_CONFIG_DAT_FLAGS_HAS_MTU)
|
||||
&& NM_FLAGS_HAS (src->flags, NM_L3_CONFIG_DAT_FLAGS_HAS_MTU)) {
|
||||
if (self->mtu != 0u)
|
||||
self->mtu = src->mtu;
|
||||
self->flags |= NM_L3_CONFIG_DAT_FLAGS_HAS_MTU;
|
||||
}
|
||||
|
||||
/* self->source does not get merged. */
|
||||
}
|
||||
|
@@ -7,6 +7,7 @@
|
||||
#include "nm-setting-connection.h"
|
||||
#include "nm-setting-ip6-config.h"
|
||||
#include "platform/nm-platform.h"
|
||||
#include "platform/nmp-object.h"
|
||||
|
||||
typedef enum {
|
||||
NM_L3_CONFIG_DAT_FLAGS_NONE = 0,
|
||||
@@ -20,7 +21,6 @@ typedef enum {
|
||||
#define NM_L3_CONFIG_DAT_FLAGS_HAS_DNS_PRIORITY(is_ipv4) ( (is_ipv4) \
|
||||
? NM_L3_CONFIG_DAT_FLAGS_HAS_DNS_PRIORITY_4 \
|
||||
: NM_L3_CONFIG_DAT_FLAGS_HAS_DNS_PRIORITY_6)
|
||||
NM_L3_CONFIG_DAT_FLAGS_HAS_MTU = (1ull << 3),
|
||||
|
||||
} NML3ConfigDatFlags;
|
||||
|
||||
@@ -96,8 +96,10 @@ NML3ConfigData *nm_l3_config_data_new_clone (const NML3ConfigData *src,
|
||||
NML3ConfigData *nm_l3_config_data_new_from_connection (NMDedupMultiIndex *multi_idx,
|
||||
int ifindex,
|
||||
NMConnection *connection,
|
||||
guint32 route_table,
|
||||
guint32 route_metric);
|
||||
guint32 route_table_4,
|
||||
guint32 route_table_6,
|
||||
guint32 route_metric_4,
|
||||
guint32 route_metric_6);
|
||||
|
||||
NML3ConfigData *nm_l3_config_data_new_from_platform (NMDedupMultiIndex *multi_idx,
|
||||
int ifindex,
|
||||
@@ -209,6 +211,73 @@ nm_l3_config_data_lookup_routes (const NML3ConfigData *self, int addr_family)
|
||||
nm_platform_dedup_multi_iter_next_ip6_route (&(iter), &(route)); \
|
||||
)
|
||||
|
||||
static inline guint
|
||||
nm_l3_config_data_get_num_objs (const NML3ConfigData *self, NMPObjectType obj_type)
|
||||
{
|
||||
const NMDedupMultiHeadEntry *head_entry;
|
||||
|
||||
head_entry = nm_l3_config_data_lookup_objs (self, obj_type);
|
||||
return head_entry ? head_entry->len : 0u;
|
||||
}
|
||||
|
||||
static inline guint
|
||||
nm_l3_config_data_get_num_addresses (const NML3ConfigData *self, int addr_family)
|
||||
{
|
||||
return nm_l3_config_data_get_num_objs (self,
|
||||
NM_IS_IPv4 (addr_family)
|
||||
? NMP_OBJECT_TYPE_IP4_ADDRESS
|
||||
: NMP_OBJECT_TYPE_IP6_ADDRESS);
|
||||
}
|
||||
|
||||
static inline guint
|
||||
nm_l3_config_data_get_num_routes (const NML3ConfigData *self, int addr_family)
|
||||
{
|
||||
return nm_l3_config_data_get_num_objs (self,
|
||||
NM_IS_IPv4 (addr_family)
|
||||
? NMP_OBJECT_TYPE_IP4_ROUTE
|
||||
: NMP_OBJECT_TYPE_IP6_ROUTE);
|
||||
}
|
||||
|
||||
const NMPObject *nmtst_l3_config_data_get_obj_at (const NML3ConfigData *self,
|
||||
NMPObjectType obj_type,
|
||||
guint i);
|
||||
|
||||
static inline const NMPlatformIP4Address *
|
||||
nmtst_l3_config_data_get_address_at_4 (const NML3ConfigData *self,
|
||||
guint i)
|
||||
{
|
||||
return NMP_OBJECT_CAST_IP4_ADDRESS (nmtst_l3_config_data_get_obj_at (self,
|
||||
NMP_OBJECT_TYPE_IP4_ADDRESS,
|
||||
i));
|
||||
}
|
||||
|
||||
static inline const NMPlatformIP6Address *
|
||||
nmtst_l3_config_data_get_address_at_6 (const NML3ConfigData *self,
|
||||
guint i)
|
||||
{
|
||||
return NMP_OBJECT_CAST_IP6_ADDRESS (nmtst_l3_config_data_get_obj_at (self,
|
||||
NMP_OBJECT_TYPE_IP6_ADDRESS,
|
||||
i));
|
||||
}
|
||||
|
||||
static inline const NMPlatformIP4Route *
|
||||
nmtst_l3_config_data_get_route_at_4 (const NML3ConfigData *self,
|
||||
guint i)
|
||||
{
|
||||
return NMP_OBJECT_CAST_IP4_ROUTE (nmtst_l3_config_data_get_obj_at (self,
|
||||
NMP_OBJECT_TYPE_IP4_ROUTE,
|
||||
i));
|
||||
}
|
||||
|
||||
static inline const NMPlatformIP6Route *
|
||||
nmtst_l3_config_data_get_route_at_6 (const NML3ConfigData *self,
|
||||
guint i)
|
||||
{
|
||||
return NMP_OBJECT_CAST_IP6_ROUTE (nmtst_l3_config_data_get_obj_at (self,
|
||||
NMP_OBJECT_TYPE_IP6_ROUTE,
|
||||
i));
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
|
||||
NML3ConfigDatFlags nm_l3_config_data_get_flags (const NML3ConfigData *self);
|
||||
@@ -304,6 +373,9 @@ nm_l3_config_data_add_route_6 (NML3ConfigData *self, const NMPlatformIP6Route *r
|
||||
return nm_l3_config_data_add_route (self, AF_INET6, NULL, NM_PLATFORM_IP_ROUTE_CAST (rt));
|
||||
}
|
||||
|
||||
const NMPObject *nm_l3_config_data_get_best_default_route (const NML3ConfigData *self,
|
||||
int addr_family);
|
||||
|
||||
gboolean nm_l3_config_data_set_mdns (NML3ConfigData *self,
|
||||
NMSettingConnectionMdns mdns);
|
||||
|
||||
@@ -317,19 +389,30 @@ gboolean nm_l3_config_data_set_route_table_sync (NML3ConfigData *self,
|
||||
int addr_family,
|
||||
NMIPRouteTableSyncMode route_table_sync);
|
||||
|
||||
NMTernary nm_l3_config_data_get_metered (const NML3ConfigData *self);
|
||||
|
||||
gboolean nm_l3_config_data_set_metered (NML3ConfigData *self,
|
||||
NMTernary metered);
|
||||
|
||||
guint32 nm_l3_config_data_get_mtu (const NML3ConfigData *self);
|
||||
|
||||
gboolean nm_l3_config_data_set_mtu (NML3ConfigData *self,
|
||||
guint32 mtu);
|
||||
|
||||
gboolean nm_l3_config_data_add_nameserver (NML3ConfigData *self,
|
||||
int addr_family,
|
||||
gconstpointer /* (const NMIPAddr *) */ nameserver);
|
||||
const in_addr_t *nm_l3_config_data_get_wins (const NML3ConfigData *self,
|
||||
guint *out_len);
|
||||
|
||||
gboolean nm_l3_config_data_add_wins (NML3ConfigData *self,
|
||||
in_addr_t wins);
|
||||
|
||||
gconstpointer nm_l3_config_data_get_nameservers (const NML3ConfigData *self,
|
||||
int addr_family,
|
||||
guint *out_len);
|
||||
|
||||
gboolean nm_l3_config_data_add_nameserver (NML3ConfigData *self,
|
||||
int addr_family,
|
||||
gconstpointer /* (const NMIPAddr *) */ nameserver);
|
||||
|
||||
gboolean nm_l3_config_data_add_nis_server (NML3ConfigData *self,
|
||||
in_addr_t nis_server);
|
||||
|
||||
@@ -340,6 +423,10 @@ gboolean nm_l3_config_data_add_domain (NML3ConfigData *self,
|
||||
int addr_family,
|
||||
const char *domain);
|
||||
|
||||
const char *const*nm_l3_config_data_get_searches (const NML3ConfigData *self,
|
||||
int addr_family,
|
||||
guint *out_len);
|
||||
|
||||
gboolean nm_l3_config_data_add_search (NML3ConfigData *self,
|
||||
int addr_family,
|
||||
const char *search);
|
||||
@@ -352,4 +439,17 @@ gboolean nm_l3_config_data_set_dns_priority (NML3ConfigData *self,
|
||||
int addr_family,
|
||||
int dns_priority);
|
||||
|
||||
static inline const NMIPAddr *
|
||||
nmtst_l3_config_data_get_best_gateway (const NML3ConfigData *self,
|
||||
int addr_family)
|
||||
{
|
||||
const NMPObject *rt;
|
||||
|
||||
rt = nm_l3_config_data_get_best_default_route (self, addr_family);
|
||||
if (!rt)
|
||||
return NULL;
|
||||
|
||||
return nm_platform_ip_route_get_gateway (addr_family, NMP_OBJECT_CAST_IP_ROUTE (rt));
|
||||
}
|
||||
|
||||
#endif /* __NM_L3_CONFIG_DATA_H__ */
|
||||
|
Reference in New Issue
Block a user