Skip to content

Commit

Permalink
zebra: changes for code maintainability
Browse files Browse the repository at this point in the history
these changes are for improving the code maintainability and readability

Signed-off-by: sri-mohan1 <[email protected]>
  • Loading branch information
sri-mohan1 committed Mar 14, 2024
1 parent 19a0211 commit 6592131
Showing 1 changed file with 17 additions and 29 deletions.
46 changes: 17 additions & 29 deletions zebra/zebra_mpls.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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. */
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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 = "";
}

Expand Down Expand Up @@ -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 */
Expand Down Expand Up @@ -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;
}

Expand All @@ -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;
}
}
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 6592131

Please sign in to comment.