From 849d8f2bbdcf1ad31ce4c068db602723db17abee Mon Sep 17 00:00:00 2001 From: sri-mohan1 Date: Fri, 5 May 2023 23:41:01 +0530 Subject: [PATCH] ldpd: changes for code maintainability these changes are for improving the code maintainability and readability Signed-off-by: sri-mohan1 --- ldpd/lde_lib.c | 70 ++++++++++++++++++++++---------------------------- 1 file changed, 30 insertions(+), 40 deletions(-) diff --git a/ldpd/lde_lib.c b/ldpd/lde_lib.c index 470580ff5e..cb6b8986b8 100644 --- a/ldpd/lde_lib.c +++ b/ldpd/lde_lib.c @@ -47,11 +47,9 @@ fec_compare(const struct fec *a, const struct fec *b) switch (a->type) { case FEC_TYPE_IPV4: - if (ntohl(a->u.ipv4.prefix.s_addr) < - ntohl(b->u.ipv4.prefix.s_addr)) + if (ntohl(a->u.ipv4.prefix.s_addr) < ntohl(b->u.ipv4.prefix.s_addr)) return (-1); - if (ntohl(a->u.ipv4.prefix.s_addr) > - ntohl(b->u.ipv4.prefix.s_addr)) + if (ntohl(a->u.ipv4.prefix.s_addr) > ntohl(b->u.ipv4.prefix.s_addr)) return (1); if (a->u.ipv4.prefixlen < b->u.ipv4.prefixlen) return (-1); @@ -79,11 +77,9 @@ fec_compare(const struct fec *a, const struct fec *b) return (-1); if (a->u.pwid.pwid > b->u.pwid.pwid) return (1); - if (ntohl(a->u.pwid.lsr_id.s_addr) < - ntohl(b->u.pwid.lsr_id.s_addr)) + if (ntohl(a->u.pwid.lsr_id.s_addr) < ntohl(b->u.pwid.lsr_id.s_addr)) return (-1); - if (ntohl(a->u.pwid.lsr_id.s_addr) > - ntohl(b->u.pwid.lsr_id.s_addr)) + if (ntohl(a->u.pwid.lsr_id.s_addr) > ntohl(b->u.pwid.lsr_id.s_addr)) return (1); return (0); } @@ -261,8 +257,7 @@ fec_add(struct fec *fec) fn->pw_remote_status = PW_FORWARDING; if (fec_insert(&ft, &fn->fec)) - log_warnx("failed to add %s to ft tree", - log_fec(&fn->fec)); + log_warnx("failed to add %s to ft tree", log_fec(&fn->fec)); return (fn); } @@ -338,14 +333,14 @@ lde_kernel_insert(struct fec *fec, int af, union ldpd_addr *nexthop, * installing in kernel and sending to peer */ iface = if_lookup(ldeconf, ifindex); - if ((ldeconf->flags & F_LDPD_ORDERED_CONTROL) && + if (CHECK_FLAG(ldeconf->flags, F_LDPD_ORDERED_CONTROL) && !connected && iface != NULL && fec->type != FEC_TYPE_PWID) - fnh->flags |= F_FEC_NH_DEFER; + SET_FLAG(fnh->flags, F_FEC_NH_DEFER); } - fnh->flags |= F_FEC_NH_NEW; + SET_FLAG(fnh->flags, F_FEC_NH_NEW); if (connected) - fnh->flags |= F_FEC_NH_CONNECTED; + SET_FLAG(fnh->flags, F_FEC_NH_CONNECTED); } void @@ -388,22 +383,22 @@ lde_kernel_update(struct fec *fec) return; LIST_FOREACH_SAFE(fnh, &fn->nexthops, entry, safe) { - if (fnh->flags & F_FEC_NH_NEW) { - fnh->flags &= ~F_FEC_NH_NEW; + if (CHECK_FLAG(fnh->flags, F_FEC_NH_NEW)) { + UNSET_FLAG(fnh->flags, F_FEC_NH_NEW); /* * if LDP configured on interface or a static route * clear flag else treat fec as a connected route */ - if (ldeconf->flags & F_LDPD_ENABLED) { + if (CHECK_FLAG(ldeconf->flags, F_LDPD_ENABLED)) { iface = if_lookup(ldeconf,fnh->ifindex); - if (fnh->flags & F_FEC_NH_CONNECTED || + if (CHECK_FLAG(fnh->flags, F_FEC_NH_CONNECTED) || iface || fnh->route_type == ZEBRA_ROUTE_STATIC) - fnh->flags &=~F_FEC_NH_NO_LDP; + UNSET_FLAG(fnh->flags, F_FEC_NH_NO_LDP); else - fnh->flags |= F_FEC_NH_NO_LDP; + SET_FLAG(fnh->flags, F_FEC_NH_NO_LDP); } else - fnh->flags |= F_FEC_NH_NO_LDP; + SET_FLAG(fnh->flags, F_FEC_NH_NO_LDP); } else { lde_send_delete_klabel(fn, fnh); fec_nh_del(fnh); @@ -510,7 +505,7 @@ lde_check_mapping(struct map *map, struct lde_nbr *ln, int rcvd_label_mapping) /* RFC 4447 control word and status tlv negotiation */ if (map->type == MAP_TYPE_PWID && l2vpn_pw_negotiate(ln, fn, map)) { - if (rcvd_label_mapping && map->flags & F_MAP_PW_STATUS) + if (rcvd_label_mapping && CHECK_FLAG(map->flags, F_MAP_PW_STATUS)) fn->pw_remote_status = map->pw_status; return; @@ -534,8 +529,7 @@ lde_check_mapping(struct map *map, struct lde_nbr *ln, int rcvd_label_mapping) * the possibility of multipath. */ LIST_FOREACH(fnh, &fn->nexthops, entry) { - if (lde_address_find(ln, fnh->af, - &fnh->nexthop) == NULL) + if (lde_address_find(ln, fnh->af, &fnh->nexthop) == NULL) continue; lde_send_delete_klabel(fn, fnh); @@ -561,9 +555,9 @@ lde_check_mapping(struct map *map, struct lde_nbr *ln, int rcvd_label_mapping) * NH so clear flag and send labelmap msg to * peer */ - if (ldeconf->flags & F_LDPD_ORDERED_CONTROL) { + if (CHECK_FLAG(ldeconf->flags, F_LDPD_ORDERED_CONTROL)) { send_map = true; - fnh->flags &= ~F_FEC_NH_DEFER; + UNSET_FLAG(fnh->flags, F_FEC_NH_DEFER); } fnh->remote_label = map->label; if (fn->local_label != NO_LABEL) @@ -575,9 +569,9 @@ lde_check_mapping(struct map *map, struct lde_nbr *ln, int rcvd_label_mapping) continue; pw->remote_group = map->fec.pwid.group_id; - if (map->flags & F_MAP_PW_IFMTU) + if (CHECK_FLAG(map->flags, F_MAP_PW_IFMTU)) pw->remote_mtu = map->fec.pwid.ifmtu; - if (rcvd_label_mapping && map->flags & F_MAP_PW_STATUS) { + if (rcvd_label_mapping && CHECK_FLAG(map->flags, F_MAP_PW_STATUS)) { pw->remote_status = map->pw_status; fn->pw_remote_status = map->pw_status; } @@ -726,7 +720,7 @@ lde_check_release(struct map *map, struct lde_nbr *ln) /* wildcard label release */ if (map->type == MAP_TYPE_WILDCARD || map->type == MAP_TYPE_TYPED_WCARD || - (map->type == MAP_TYPE_PWID && !(map->flags & F_MAP_PW_ID))) { + (map->type == MAP_TYPE_PWID && !CHECK_FLAG(map->flags, F_MAP_PW_ID))) { lde_check_release_wcard(map, ln); return; } @@ -818,7 +812,7 @@ lde_check_withdraw(struct map *map, struct lde_nbr *ln) /* wildcard label withdraw */ if (map->type == MAP_TYPE_WILDCARD || map->type == MAP_TYPE_TYPED_WCARD || - (map->type == MAP_TYPE_PWID && !(map->flags & F_MAP_PW_ID))) { + (map->type == MAP_TYPE_PWID && !CHECK_FLAG(map->flags, F_MAP_PW_ID))) { lde_check_withdraw_wcard(map, ln); return; } @@ -868,7 +862,7 @@ lde_check_withdraw(struct map *map, struct lde_nbr *ln) return; /* Ordered Control: additional withdraw steps */ - if (ldeconf->flags & F_LDPD_ORDERED_CONTROL) { + if (CHECK_FLAG(ldeconf->flags, F_LDPD_ORDERED_CONTROL)) { /* LWd.8: for each neighbor other that src of withdraw msg */ RB_FOREACH(lnbr, nbr_tree, &lde_nbrs) { if (ln->peerid == lnbr->peerid) @@ -929,8 +923,7 @@ lde_check_withdraw_wcard(struct map *map, struct lde_nbr *ln) default: break; } - if (map->label != NO_LABEL && map->label != - fnh->remote_label) + if (map->label != NO_LABEL && map->label != fnh->remote_label) continue; lde_send_delete_klabel(fn, fnh); @@ -941,8 +934,7 @@ lde_check_withdraw_wcard(struct map *map, struct lde_nbr *ln) lde_rlfa_update_clients(f, ln, MPLS_INVALID_LABEL); /* LWd.3: check previously received label mapping */ - if (me && (map->label == NO_LABEL || - map->label == me->map.label)) + if (me && (map->label == NO_LABEL || map->label == me->map.label)) /* * LWd.4: remove record of previously received * label mapping @@ -953,7 +945,7 @@ lde_check_withdraw_wcard(struct map *map, struct lde_nbr *ln) continue; /* Ordered Control: additional withdraw steps */ - if (ldeconf->flags & F_LDPD_ORDERED_CONTROL) { + if (CHECK_FLAG(ldeconf->flags, F_LDPD_ORDERED_CONTROL)) { /* * LWd.8: for each neighbor other that src of * withdraw msg @@ -965,16 +957,14 @@ lde_check_withdraw_wcard(struct map *map, struct lde_nbr *ln) /* LWd.9: check if previously sent a label * mapping */ - me = (struct lde_map *)fec_find( - &lnbr->sent_map, &fn->fec); + me = (struct lde_map *)fec_find(&lnbr->sent_map, &fn->fec); /* * LWd.10: does label sent to peer "map" to * withdraw label */ if (me && lde_nbr_is_nexthop(fn, lnbr)) /* LWd.11: send label withdraw */ - lde_send_labelwithdraw(lnbr, fn, NULL, - NULL); + lde_send_labelwithdraw(lnbr, fn, NULL, NULL); } } } -- 2.39.5