From b38fbb3bf621a45c8a00beb290ae0c29fb226ba3 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Wed, 21 Oct 2020 12:14:08 +0200 Subject: [PATCH] l3cfg: add nm_l3_acd_addr_info_find_track_info() helper --- src/nm-l3cfg.h | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/src/nm-l3cfg.h b/src/nm-l3cfg.h index d89e2fa280..0bbe692408 100644 --- a/src/nm-l3cfg.h +++ b/src/nm-l3cfg.h @@ -55,6 +55,33 @@ typedef struct { const NML3AcdAddrTrackInfo *track_infos; } NML3AcdAddrInfo; +static inline const NML3AcdAddrTrackInfo * +nm_l3_acd_addr_info_find_track_info(const NML3AcdAddrInfo *addr_info, + gconstpointer tag, + const NML3ConfigData * l3cd, + const NMPObject * obj) +{ + guint i; + const NML3AcdAddrTrackInfo *ti; + + nm_assert(addr_info); + + /* we always expect that the number n_track_infos is reasonably small. Hence, + * a naive linear search is simplest and fastest (e.g. we don't have a hash table). */ + + for (i = 0, ti = addr_info->track_infos; i < addr_info->n_track_infos; i++, ti++) { + if (l3cd && ti->l3cd != l3cd) + continue; + if (tag && ti->tag != tag) + continue; + if (obj && ti->obj != obj) + continue; + return ti; + } + + return NULL; +} + typedef enum { NM_L3_CONFIG_NOTIFY_TYPE_ROUTES_TEMPORARY_NOT_AVAILABLE_EXPIRED,