diff --git a/.clang-format b/.clang-format index 3971384a3659..5f21a3f32453 100644 --- a/.clang-format +++ b/.clang-format @@ -103,6 +103,7 @@ ForEachMacros: - 'FOREACH_AFI_SAFI' - 'FOREACH_AFI_SAFI_NSF' - 'FOREACH_BE_APPLY_BATCH_IN_LIST' + - 'FOREACH_BE_CLIENT_BITS' - 'FOREACH_BE_TXN_BATCH_IN_LIST' - 'FOREACH_BE_TXN_IN_LIST' - 'FOREACH_CMT_REC' diff --git a/lib/mgmt_be_client.h b/lib/mgmt_be_client.h index 560f65fae74c..c692b9c963f1 100644 --- a/lib/mgmt_be_client.h +++ b/lib/mgmt_be_client.h @@ -37,6 +37,12 @@ enum mgmt_be_client_id { for ((id) = MGMTD_BE_CLIENT_ID_MIN; \ (id) < MGMTD_BE_CLIENT_ID_MAX; (id)++) +#define FOREACH_BE_CLIENT_BITS(id, bits) \ + FOREACH_MGMTD_BE_CLIENT_ID (id) \ + if (IS_IDBIT_UNSET((bits), (id))) \ + continue; \ + else + #define IS_IDBIT_UNSET(v, id) (!((v) & (1ull << (id)))) #define IS_IDBIT_SET(v, id) (!IS_IDBIT_UNSET(v, id)) diff --git a/mgmtd/mgmt_be_adapter.c b/mgmtd/mgmt_be_adapter.c index c3f0e9f81aef..1f0eb4766360 100644 --- a/mgmtd/mgmt_be_adapter.c +++ b/mgmtd/mgmt_be_adapter.c @@ -708,11 +708,9 @@ uint64_t mgmt_be_interested_clients(const char *xpath, bool config) clients |= map->clients; if (DEBUG_MODE_CHECK(&mgmt_debug_be, DEBUG_MODE_ALL)) { - FOREACH_MGMTD_BE_CLIENT_ID (id) { - if (IS_IDBIT_SET(clients, id)) - MGMTD_BE_ADAPTER_DBG("Cient: %s: subscribed", - mgmt_be_client_id2name(id)); - } + FOREACH_BE_CLIENT_BITS (id, clients) + MGMTD_BE_ADAPTER_DBG("Cient: %s: subscribed", + mgmt_be_client_id2name(id)); } return clients; } @@ -786,9 +784,7 @@ static void be_show_xpath_register(struct vty *vty, const char *astr; vty_out(vty, " - xpath: '%s'\n", map->xpath_regexp); - FOREACH_MGMTD_BE_CLIENT_ID (id) { - if (IS_IDBIT_UNSET(map->clients, id)) - continue; + FOREACH_BE_CLIENT_BITS (id, map->clients) { astr = mgmt_be_get_adapter_by_id(id) ? "active" : "inactive"; vty_out(vty, " -- %s-client: '%s'\n", astr, mgmt_be_client_id2name(id)); @@ -820,9 +816,7 @@ void mgmt_be_show_xpath_registries(struct vty *vty, const char *xpath) combined = cclients | oclients; vty_out(vty, "XPath: '%s'\n", xpath); - FOREACH_MGMTD_BE_CLIENT_ID (id) { - if (IS_IDBIT_UNSET(combined, id)) - continue; + FOREACH_BE_CLIENT_BITS (id, combined) { vty_out(vty, " -- Client: '%s'\tconfig:%d oper:%d\n", mgmt_be_client_id2name(id), IS_IDBIT_SET(cclients, id), IS_IDBIT_SET(oclients, id)); diff --git a/mgmtd/mgmt_txn.c b/mgmtd/mgmt_txn.c index 027423637791..996431be8b8e 100644 --- a/mgmtd/mgmt_txn.c +++ b/mgmtd/mgmt_txn.c @@ -1042,10 +1042,7 @@ static int mgmt_txn_create_config_batches(struct mgmt_txn_req *txn_req, xpath_len = strlen(xpath) + 1; value_len = strlen(value) + 1; - FOREACH_MGMTD_BE_CLIENT_ID (id) { - if (IS_IDBIT_UNSET(clients, id)) - continue; - + FOREACH_BE_CLIENT_BITS (id, clients) { adapter = mgmt_be_get_adapter_by_id(id); if (!adapter) continue; diff --git a/tools/checkpatch.pl b/tools/checkpatch.pl index d007c1d32580..3e8a6b392a3e 100755 --- a/tools/checkpatch.pl +++ b/tools/checkpatch.pl @@ -563,6 +563,7 @@ sub hash_show_words { SUBGRP_FOREACH_PEER|SUBGRP_FOREACH_PEER_SAFE| SUBGRP_FOREACH_ADJ|SUBGRP_FOREACH_ADJ_SAFE| AF_FOREACH|FOREACH_AFI_SAFI|FOREACH_SAFI| + FOREACH_BE_CLIENT_BITS|FOREACH_MGMTD_BE_CLIENT_ID| LSDB_LOOP }x;