From 65921313b0b21d0a65cb96e931f0535feacb3c71 Mon Sep 17 00:00:00 2001 From: sri-mohan1 Date: Thu, 14 Mar 2024 14:34:31 +0530 Subject: [PATCH] zebra: changes for code maintainability these changes are for improving the code maintainability and readability Signed-off-by: sri-mohan1 --- zebra/zebra_mpls.c | 46 +++++++++++++++++----------------------------- 1 file changed, 17 insertions(+), 29 deletions(-) diff --git a/zebra/zebra_mpls.c b/zebra/zebra_mpls.c index 15e36acda8c3..f8435bf7f95e 100644 --- a/zebra/zebra_mpls.c +++ b/zebra/zebra_mpls.c @@ -329,7 +329,7 @@ static void fec_evaluate(struct zebra_vrf *zvrf) /* Skip configured FECs and those without a label index. */ - if (fec->flags & FEC_FLAG_CONFIGURED + if (CHECK_FLAG(fec->flags, FEC_FLAG_CONFIGURED) || fec->label_index == MPLS_INVALID_LABEL_INDEX) continue; @@ -2415,12 +2415,10 @@ static int zebra_mpls_cleanup_fecs_for_client(struct zserv *client) if (!fec || list_isempty(fec->client_list)) continue; - for (ALL_LIST_ELEMENTS_RO(fec->client_list, node, - fec_client)) { + for (ALL_LIST_ELEMENTS_RO(fec->client_list, node, fec_client)) { if (fec_client == client) { - listnode_delete(fec->client_list, - fec_client); - if (!(fec->flags & FEC_FLAG_CONFIGURED) + listnode_delete(fec->client_list, fec_client); + if (!CHECK_FLAG(fec->flags, FEC_FLAG_CONFIGURED) && list_isempty(fec->client_list)) fec_del(fec); break; @@ -2455,8 +2453,7 @@ static int zebra_mpls_cleanup_zclient_labels(struct zserv *client) /* Cleanup LSPs. */ args.lsp_table = zvrf->lsp_table; args.type = lsp_type_from_re_type(client->proto); - hash_iterate(zvrf->lsp_table, mpls_lsp_uninstall_all_type, - &args); + hash_iterate(zvrf->lsp_table, mpls_lsp_uninstall_all_type, &args); /* Cleanup FTNs. */ mpls_ftn_uninstall_all(zvrf, AFI_IP, @@ -2538,7 +2535,7 @@ int zebra_mpls_static_fec_add(struct zebra_vrf *zvrf, struct prefix *p, if (IS_ZEBRA_DEBUG_MPLS) zlog_debug("Add fec %pFX label %u", p, in_label); } else { - fec->flags |= FEC_FLAG_CONFIGURED; + SET_FLAG(fec->flags, FEC_FLAG_CONFIGURED); if (fec->label == in_label) /* Duplicate config */ return 0; @@ -2587,7 +2584,7 @@ int zebra_mpls_static_fec_del(struct zebra_vrf *zvrf, struct prefix *p) } old_label = fec->label; - fec->flags &= ~FEC_FLAG_CONFIGURED; + UNSET_FLAG(fec->flags, FEC_FLAG_CONFIGURED); fec->label = MPLS_INVALID_LABEL; /* If no client exists, just delete the FEC. */ @@ -2630,7 +2627,7 @@ int zebra_mpls_write_fec_config(struct vty *vty, struct zebra_vrf *zvrf) char lstr[BUFSIZ]; fec = rn->info; - if (!(fec->flags & FEC_FLAG_CONFIGURED)) + if (!CHECK_FLAG(fec->flags, FEC_FLAG_CONFIGURED)) continue; write = 1; @@ -2785,8 +2782,7 @@ static bool ftn_update_znh(bool add_p, enum lsp_types_t type, if (znh->type != NEXTHOP_TYPE_IPV4 && znh->type != NEXTHOP_TYPE_IPV4_IFINDEX) continue; - if (!IPV4_ADDR_SAME(&nexthop->gate.ipv4, - &znh->gate.ipv4)) + if (!IPV4_ADDR_SAME(&nexthop->gate.ipv4, &znh->gate.ipv4)) continue; if (nexthop->type == NEXTHOP_TYPE_IPV4_IFINDEX && nexthop->ifindex != znh->ifindex) @@ -2804,8 +2800,7 @@ static bool ftn_update_znh(bool add_p, enum lsp_types_t type, if (znh->type != NEXTHOP_TYPE_IPV6 && znh->type != NEXTHOP_TYPE_IPV6_IFINDEX) continue; - if (!IPV6_ADDR_SAME(&nexthop->gate.ipv6, - &znh->gate.ipv6)) + if (!IPV6_ADDR_SAME(&nexthop->gate.ipv6, &znh->gate.ipv6)) continue; if (nexthop->type == NEXTHOP_TYPE_IPV6_IFINDEX && nexthop->ifindex != znh->ifindex) @@ -2952,8 +2947,7 @@ void zebra_mpls_zapi_labels_process(bool add_p, struct zebra_vrf *zvrf, continue; /* Search the route's nexthops for a match, and update it. */ - found = ftn_update_znh(add_p, zl->type, new_nhe->nhg.nexthop, - znh); + found = ftn_update_znh(add_p, zl->type, new_nhe->nhg.nexthop, znh); if (found) { counter++; } else if (IS_ZEBRA_DEBUG_RECV | IS_ZEBRA_DEBUG_MPLS) { @@ -3055,8 +3049,7 @@ lsp_add_nhlfe(struct zebra_lsp *lsp, enum lsp_types_t type, gate, ifindex); backup_str = "backup "; } else { - nhlfe = nhlfe_find(&lsp->nhlfe_list, type, gtype, gate, - ifindex); + nhlfe = nhlfe_find(&lsp->nhlfe_list, type, gtype, gate, ifindex); backup_str = ""; } @@ -3101,8 +3094,7 @@ lsp_add_nhlfe(struct zebra_lsp *lsp, enum lsp_types_t type, sizeof(mpls_label_t) * num_out_labels); else { nexthop_del_labels(nh); - nexthop_add_labels(nh, type, num_out_labels, - out_labels); + nexthop_add_labels(nh, type, num_out_labels, out_labels); } } else { /* Add LSP entry to this nexthop */ @@ -3392,8 +3384,7 @@ static void mpls_ftn_uninstall_all(struct zebra_vrf *zvrf, nexthop_del_labels(nexthop); SET_FLAG(re->status, ROUTE_ENTRY_CHANGED); - SET_FLAG(re->status, - ROUTE_ENTRY_LABELS_CHANGED); + SET_FLAG(re->status, ROUTE_ENTRY_LABELS_CHANGED); update = true; } @@ -3406,10 +3397,8 @@ static void mpls_ftn_uninstall_all(struct zebra_vrf *zvrf, continue; nexthop_del_labels(nexthop); - SET_FLAG(re->status, - ROUTE_ENTRY_CHANGED); - SET_FLAG(re->status, - ROUTE_ENTRY_LABELS_CHANGED); + SET_FLAG(re->status, ROUTE_ENTRY_CHANGED); + SET_FLAG(re->status, ROUTE_ENTRY_LABELS_CHANGED); update = true; } } @@ -3481,8 +3470,7 @@ int zebra_mpls_lsp_label_consistent(struct zebra_vrf *zvrf, if (nh == NULL || nh->nh_label == NULL) return 0; - cur_op = (nh->nh_label->label[0] == - MPLS_LABEL_IMPLICIT_NULL); + cur_op = (nh->nh_label->label[0] == MPLS_LABEL_IMPLICIT_NULL); new_op = (out_label == MPLS_LABEL_IMPLICIT_NULL); if (cur_op != new_op) return 0;