Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ldpd: changes for code maintainability #13451

Merged
merged 1 commit into from
May 6, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
70 changes: 30 additions & 40 deletions ldpd/lde_lib.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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;
Expand All @@ -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);
Expand All @@ -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)
Expand All @@ -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;
}
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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);
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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);
}
}
}
Expand Down