platform: expose index lookup for objects in public API

This commit is contained in:
Thomas Haller 2017-06-29 14:46:32 +02:00
parent c5af191dbf
commit 16aefdd865
3 changed files with 86 additions and 2 deletions

View file

@ -2651,6 +2651,14 @@ nm_platform_ethtool_get_link_settings (NMPlatform *self, int ifindex, gboolean *
/*****************************************************************************/
const NMDedupMultiHeadEntry *
nm_platform_lookup (NMPlatform *platform,
const NMPLookup *lookup)
{
return nmp_cache_lookup (nm_platform_get_cache (platform),
lookup);
}
void
nm_platform_ip4_address_set_addr (NMPlatformIP4Address *addr, in_addr_t address, guint8 plen)
{

View file

@ -777,6 +777,11 @@ gboolean nm_platform_link_delete (NMPlatform *self, int ifindex);
gboolean nm_platform_link_set_netns (NMPlatform *self, int ifindex, int netns_fd);
struct _NMDedupMultiHeadEntry;
struct _NMPLookup;
const struct _NMDedupMultiHeadEntry *nm_platform_lookup (NMPlatform *platform,
const struct _NMPLookup *lookup);
/* convienience methods to lookup the link and access fields of NMPlatformLink. */
int nm_platform_link_get_ifindex (NMPlatform *self, const char *name);
const char *nm_platform_link_get_name (NMPlatform *self, int ifindex);

View file

@ -386,10 +386,12 @@ const NMDedupMultiEntry *nmp_cache_lookup_entry_link (const NMPCache *cache, int
const NMPObject *nmp_cache_lookup_obj (const NMPCache *cache, const NMPObject *obj);
const NMPObject *nmp_cache_lookup_link (const NMPCache *cache, int ifindex);
typedef struct {
typedef struct _NMPLookup NMPLookup;
struct _NMPLookup {
NMPCacheIdType cache_id_type;
NMPObject selector_obj;
} NMPLookup;
};
const NMDedupMultiHeadEntry *nmp_cache_lookup_all (const NMPCache *cache,
NMPCacheIdType cache_id_type,
@ -549,4 +551,73 @@ ASSERT_nmp_cache_ops (const NMPCache *cache,
#endif
}
static inline const NMDedupMultiHeadEntry *
nm_platform_lookup_obj_type (NMPlatform *platform,
NMPObjectType obj_type,
gboolean visible_only)
{
NMPLookup lookup;
nmp_lookup_init_obj_type (&lookup, obj_type, visible_only);
return nm_platform_lookup (platform, &lookup);
}
static inline const NMDedupMultiHeadEntry *
nm_platform_lookup_link (NMPlatform *platform,
gboolean visible_only)
{
NMPLookup lookup;
nmp_lookup_init_link (&lookup, visible_only);
return nm_platform_lookup (platform, &lookup);
}
static inline const NMDedupMultiHeadEntry *
nm_platform_lookup_link_by_ifname (NMPlatform *platform,
const char *ifname)
{
NMPLookup lookup;
nmp_lookup_init_link_by_ifname (&lookup, ifname);
return nm_platform_lookup (platform, &lookup);
}
static inline const NMDedupMultiHeadEntry *
nm_platform_lookup_addrroute (NMPlatform *platform,
NMPObjectType obj_type,
int ifindex,
gboolean visible_only)
{
NMPLookup lookup;
nmp_lookup_init_addrroute (&lookup, obj_type, ifindex, visible_only);
return nm_platform_lookup (platform, &lookup);
}
static inline const NMDedupMultiHeadEntry *
nm_platform_lookup_route_visible (NMPlatform *platform,
NMPObjectType obj_type,
int ifindex,
gboolean with_default,
gboolean with_non_default)
{
NMPLookup lookup;
nmp_lookup_init_route_visible (&lookup, obj_type, ifindex, with_default, with_non_default);
return nm_platform_lookup (platform, &lookup);
}
static inline const NMDedupMultiHeadEntry *
nm_platform_lookup_route_by_dest (NMPlatform *platform,
int addr_family,
gconstpointer network,
guint plen,
guint32 metric)
{
NMPLookup lookup;
nmp_lookup_init_route_by_dest (&lookup, addr_family, network, plen, metric);
return nm_platform_lookup (platform, &lookup);
}
#endif /* __NMP_OBJECT_H__ */