From 757443d0c5ee9ca878f7c68280dff38652d79f53 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Fri, 20 Nov 2020 22:33:15 +0100 Subject: [PATCH] core: add nm_ip_config_iter_ip_address_for_each() macro --- .clang-format | 2 ++ src/nm-ip4-config.h | 30 ++++++++++++++++++++++++++++++ 2 files changed, 32 insertions(+) diff --git a/.clang-format b/.clang-format index 33a0c6399..13c9899c6 100644 --- a/.clang-format +++ b/.clang-format @@ -101,6 +101,8 @@ ForEachMacros: ['c_list_for_each', 'nm_ip_config_iter_ip4_route_for_each', 'nm_ip_config_iter_ip6_address_for_each', 'nm_ip_config_iter_ip6_route_for_each', + 'nm_ip_config_iter_ip_address_for_each', + 'nm_ip_config_iter_ip_route_for_each', 'nm_json_array_foreach', 'nm_json_object_foreach', 'nm_l3_config_data_iter_ip4_address_for_each', diff --git a/src/nm-ip4-config.h b/src/nm-ip4-config.h index e1f231e52..36f8b5dd8 100644 --- a/src/nm-ip4-config.h +++ b/src/nm-ip4-config.h @@ -375,6 +375,36 @@ nm_ip_config_get_first_address(NMIPConfig *self) _NM_IP_CONFIG_DISPATCH(self, nm_ip4_config_get_first_address, nm_ip6_config_get_first_address); } +static inline void +nm_ip_config_iter_ip_address_init(NMDedupMultiIter *iter, const NMIPConfig *self) +{ + if (NM_IS_IP4_CONFIG(self)) + nm_ip_config_iter_ip4_address_init(iter, (const NMIP4Config *) self); + else { + nm_assert(NM_IS_IP6_CONFIG(self)); + nm_ip_config_iter_ip6_address_init(iter, (const NMIP6Config *) self); + } +} + +#define nm_ip_config_iter_ip_address_for_each(iter, self, address) \ + for (nm_ip_config_iter_ip_address_init((iter), (self)); \ + nm_platform_dedup_multi_iter_next_ip_address((iter), (address));) + +static inline void +nm_ip_config_iter_ip_route_init(NMDedupMultiIter *iter, const NMIPConfig *self) +{ + if (NM_IS_IP4_CONFIG(self)) + nm_ip_config_iter_ip4_route_init(iter, (const NMIP4Config *) self); + else { + nm_assert(NM_IS_IP6_CONFIG(self)); + nm_ip_config_iter_ip6_route_init(iter, (const NMIP6Config *) self); + } +} + +#define nm_ip_config_iter_ip_route_for_each(iter, self, route) \ + for (nm_ip_config_iter_ip_route_init((iter), (self)); \ + nm_platform_dedup_multi_iter_next_ip_route((iter), (route));) + static inline void nm_ip_config_add_address(NMIPConfig *self, const NMPlatformIPAddress *address) {