diff options
author | Donald Sharp <donaldsharp72@gmail.com> | 2023-02-22 18:14:23 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-02-22 18:14:23 +0100 |
commit | 941778e854975305928d06df5ea7dc908aeda258 (patch) | |
tree | 0fb917fcde67bd6ea9408972fb6434784ab94bf4 /ldpd | |
parent | Merge pull request #12839 from taspelund/evpn_prefix (diff) | |
parent | ldpd: changes for code maintainability (diff) | |
download | frr-941778e854975305928d06df5ea7dc908aeda258.tar.xz frr-941778e854975305928d06df5ea7dc908aeda258.zip |
Merge pull request #12863 from sri-mohan1/sri-mohan-ldp
ldpd: changes for code maintainability
Diffstat (limited to 'ldpd')
-rw-r--r-- | ldpd/lde.c | 230 |
1 files changed, 103 insertions, 127 deletions
diff --git a/ldpd/lde.c b/ldpd/lde.c index edd13fed3..325b33d05 100644 --- a/ldpd/lde.c +++ b/ldpd/lde.c @@ -261,8 +261,7 @@ static void lde_dispatch_imsg(struct thread *thread) case IMSG_LABEL_MAPPING_FULL: ln = lde_nbr_find(imsg.hdr.peerid); if (ln == NULL) { - log_debug("%s: cannot find lde neighbor", - __func__); + log_debug("%s: cannot find lde neighbor", __func__); break; } @@ -273,15 +272,13 @@ static void lde_dispatch_imsg(struct thread *thread) case IMSG_LABEL_RELEASE: case IMSG_LABEL_WITHDRAW: case IMSG_LABEL_ABORT: - if (imsg.hdr.len - IMSG_HEADER_SIZE != - sizeof(struct map)) + if (imsg.hdr.len - IMSG_HEADER_SIZE != sizeof(struct map)) fatalx("lde_dispatch_imsg: wrong imsg len"); map = imsg.data; ln = lde_nbr_find(imsg.hdr.peerid); if (ln == NULL) { - log_debug("%s: cannot find lde neighbor", - __func__); + log_debug("%s: cannot find lde neighbor", __func__); break; } @@ -304,49 +301,45 @@ static void lde_dispatch_imsg(struct thread *thread) } break; case IMSG_ADDRESS_ADD: - if (imsg.hdr.len - IMSG_HEADER_SIZE != - sizeof(struct lde_addr)) + if (imsg.hdr.len - IMSG_HEADER_SIZE != sizeof(struct lde_addr)) fatalx("lde_dispatch_imsg: wrong imsg len"); lde_addr = imsg.data; ln = lde_nbr_find(imsg.hdr.peerid); if (ln == NULL) { - log_debug("%s: cannot find lde neighbor", - __func__); + log_debug("%s: cannot find lde neighbor", __func__); break; } + if (lde_address_add(ln, lde_addr) < 0) { log_debug("%s: cannot add address %s, it already exists", __func__, log_addr(lde_addr->af, &lde_addr->addr)); } break; case IMSG_ADDRESS_DEL: - if (imsg.hdr.len - IMSG_HEADER_SIZE != - sizeof(struct lde_addr)) + if (imsg.hdr.len - IMSG_HEADER_SIZE != sizeof(struct lde_addr)) fatalx("lde_dispatch_imsg: wrong imsg len"); lde_addr = imsg.data; ln = lde_nbr_find(imsg.hdr.peerid); if (ln == NULL) { - log_debug("%s: cannot find lde neighbor", - __func__); + log_debug("%s: cannot find lde neighbor", __func__); break; } + if (lde_address_del(ln, lde_addr) < 0) { log_debug("%s: cannot delete address %s, it does not exist", __func__, log_addr(lde_addr->af, &lde_addr->addr)); } break; case IMSG_NOTIFICATION: - if (imsg.hdr.len - IMSG_HEADER_SIZE != - sizeof(struct notify_msg)) + if (imsg.hdr.len - IMSG_HEADER_SIZE != sizeof(struct notify_msg)) fatalx("lde_dispatch_imsg: wrong imsg len"); nm = imsg.data; ln = lde_nbr_find(imsg.hdr.peerid); if (ln == NULL) { - log_debug("%s: cannot find lde neighbor", - __func__); + log_debug("%s: cannot find lde neighbor", __func__); break; } @@ -366,8 +359,7 @@ static void lde_dispatch_imsg(struct thread *thread) } break; case IMSG_NEIGHBOR_UP: - if (imsg.hdr.len - IMSG_HEADER_SIZE != - sizeof(struct lde_nbr)) + if (imsg.hdr.len - IMSG_HEADER_SIZE != sizeof(struct lde_nbr)) fatalx("lde_dispatch_imsg: wrong imsg len"); if (lde_nbr_find(imsg.hdr.peerid)) @@ -386,18 +378,15 @@ static void lde_dispatch_imsg(struct thread *thread) case IMSG_CTL_SHOW_L2VPN_PW: l2vpn_pw_ctl(imsg.hdr.pid); - lde_imsg_compose_ldpe(IMSG_CTL_END, 0, - imsg.hdr.pid, NULL, 0); + lde_imsg_compose_ldpe(IMSG_CTL_END, 0, imsg.hdr.pid, NULL, 0); break; case IMSG_CTL_SHOW_L2VPN_BINDING: l2vpn_binding_ctl(imsg.hdr.pid); - lde_imsg_compose_ldpe(IMSG_CTL_END, 0, - imsg.hdr.pid, NULL, 0); + lde_imsg_compose_ldpe(IMSG_CTL_END, 0, imsg.hdr.pid, NULL, 0); break; default: - log_debug("%s: unexpected imsg %d", __func__, - imsg.hdr.type); + log_debug("%s: unexpected imsg %d", __func__, imsg.hdr.type); break; } imsg_free(&imsg); @@ -452,8 +441,7 @@ static void lde_dispatch_parent(struct thread *thread) switch (imsg.hdr.type) { case IMSG_IFSTATUS: - if (imsg.hdr.len != IMSG_HEADER_SIZE + - sizeof(struct kif)) + if (imsg.hdr.len != IMSG_HEADER_SIZE + sizeof(struct kif)) fatalx("IFSTATUS imsg with wrong len"); kif = imsg.data; @@ -481,18 +469,15 @@ static void lde_dispatch_parent(struct thread *thread) } break; case IMSG_PW_UPDATE: - if (imsg.hdr.len != IMSG_HEADER_SIZE + - sizeof(struct zapi_pw_status)) + if (imsg.hdr.len != IMSG_HEADER_SIZE + sizeof(struct zapi_pw_status)) fatalx("PW_UPDATE imsg with wrong len"); if (l2vpn_pw_status_update(imsg.data) != 0) - log_warnx("%s: error updating PW status", - __func__); + log_warnx("%s: error updating PW status", __func__); break; case IMSG_NETWORK_ADD: case IMSG_NETWORK_UPDATE: - if (imsg.hdr.len != IMSG_HEADER_SIZE + - sizeof(struct kroute)) { + if (imsg.hdr.len != IMSG_HEADER_SIZE + sizeof(struct kroute)) { log_warnx("%s: wrong imsg len", __func__); break; } @@ -516,9 +501,8 @@ static void lde_dispatch_parent(struct thread *thread) switch (imsg.hdr.type) { case IMSG_NETWORK_ADD: lde_kernel_insert(&fec, kr->af, &kr->nexthop, - kr->ifindex, kr->route_type, - kr->route_instance, - kr->flags & F_CONNECTED, NULL); + kr->ifindex, kr->route_type, kr->route_instance, + CHECK_FLAG(kr->flags, F_CONNECTED), NULL); break; case IMSG_NETWORK_UPDATE: lde_kernel_update(&fec); @@ -556,8 +540,7 @@ static void lde_dispatch_parent(struct thread *thread) ldp_agentx_enabled(); break; case IMSG_RECONF_CONF: - if ((nconf = malloc(sizeof(struct ldpd_conf))) == - NULL) + if ((nconf = malloc(sizeof(struct ldpd_conf))) == NULL) fatal(NULL); memcpy(nconf, imsg.data, sizeof(struct ldpd_conf)); @@ -681,8 +664,7 @@ static void lde_dispatch_parent(struct thread *thread) } break; default: - log_debug("%s: unexpected imsg %d", __func__, - imsg.hdr.type); + log_debug("%s: unexpected imsg %d", __func__, imsg.hdr.type); break; } imsg_free(&imsg); @@ -708,7 +690,7 @@ static bool lde_fec_connected(const struct fec_node *fn) struct fec_nh *fnh; LIST_FOREACH(fnh, &fn->nexthops, entry) - if (fnh->flags & F_FEC_NH_CONNECTED) + if (CHECK_FLAG(fnh->flags, F_FEC_NH_CONNECTED)) return true; return false; @@ -719,7 +701,7 @@ static bool lde_fec_outside_mpls_network(const struct fec_node *fn) struct fec_nh *fnh; LIST_FOREACH(fnh, &fn->nexthops, entry) - if (!(fnh->flags & F_FEC_NH_NO_LDP)) + if (!CHECK_FLAG(fnh->flags, F_FEC_NH_NO_LDP)) return false; return true; @@ -732,18 +714,20 @@ lde_update_label(struct fec_node *fn) /* should we allocate a label for this fec? */ switch (fn->fec.type) { case FEC_TYPE_IPV4: - if ((ldeconf->ipv4.flags & F_LDPD_AF_ALLOCHOSTONLY) + if (CHECK_FLAG(ldeconf->ipv4.flags, F_LDPD_AF_ALLOCHOSTONLY) && fn->fec.u.ipv4.prefixlen != IPV4_MAX_BITLEN) return (NO_LABEL); + if (lde_acl_check(ldeconf->ipv4.acl_label_allocate_for, AF_INET, (union ldpd_addr *)&fn->fec.u.ipv4.prefix, fn->fec.u.ipv4.prefixlen) != FILTER_PERMIT) return (NO_LABEL); break; case FEC_TYPE_IPV6: - if ((ldeconf->ipv6.flags & F_LDPD_AF_ALLOCHOSTONLY) + if (CHECK_FLAG(ldeconf->ipv6.flags, F_LDPD_AF_ALLOCHOSTONLY) && fn->fec.u.ipv6.prefixlen != IPV6_MAX_BITLEN) return (NO_LABEL); + if (lde_acl_check(ldeconf->ipv6.acl_label_allocate_for, AF_INET6, (union ldpd_addr *)&fn->fec.u.ipv6.prefix, fn->fec.u.ipv6.prefixlen) != FILTER_PERMIT) @@ -764,16 +748,18 @@ lde_update_label(struct fec_node *fn) /* choose implicit or explicit-null depending on configuration */ switch (fn->fec.type) { case FEC_TYPE_IPV4: - if (!(ldeconf->ipv4.flags & F_LDPD_AF_EXPNULL)) + if (!CHECK_FLAG(ldeconf->ipv4.flags, F_LDPD_AF_EXPNULL)) return (MPLS_LABEL_IMPLICIT_NULL); + if (lde_acl_check(ldeconf->ipv4.acl_label_expnull_for, AF_INET, (union ldpd_addr *)&fn->fec.u.ipv4.prefix, fn->fec.u.ipv4.prefixlen) != FILTER_PERMIT) return (MPLS_LABEL_IMPLICIT_NULL); return MPLS_LABEL_IPV4_EXPLICIT_NULL; case FEC_TYPE_IPV6: - if (!(ldeconf->ipv6.flags & F_LDPD_AF_EXPNULL)) + if (!CHECK_FLAG(ldeconf->ipv6.flags, F_LDPD_AF_EXPNULL)) return (MPLS_LABEL_IMPLICIT_NULL); + if (lde_acl_check(ldeconf->ipv6.acl_label_expnull_for, AF_INET6, (union ldpd_addr *)&fn->fec.u.ipv6.prefix, fn->fec.u.ipv6.prefixlen) != FILTER_PERMIT) @@ -803,7 +789,7 @@ lde_send_change_klabel(struct fec_node *fn, struct fec_nh *fnh) * Ordered Control: don't program label into HW until a * labelmap msg has been received from upstream router */ - if (fnh->flags & F_FEC_NH_DEFER) + if (CHECK_FLAG(fnh->flags, F_FEC_NH_DEFER)) return; switch (fn->fec.type) { @@ -818,8 +804,7 @@ lde_send_change_klabel(struct fec_node *fn, struct fec_nh *fnh) kr.remote_label = fnh->remote_label; kr.route_type = fnh->route_type; kr.route_instance = fnh->route_instance; - lde_imsg_compose_parent(IMSG_KLABEL_CHANGE, 0, &kr, - sizeof(kr)); + lde_imsg_compose_parent(IMSG_KLABEL_CHANGE, 0, &kr, sizeof(kr)); break; case FEC_TYPE_IPV6: memset(&kr, 0, sizeof(kr)); @@ -833,8 +818,7 @@ lde_send_change_klabel(struct fec_node *fn, struct fec_nh *fnh) kr.route_type = fnh->route_type; kr.route_instance = fnh->route_instance; - lde_imsg_compose_parent(IMSG_KLABEL_CHANGE, 0, &kr, - sizeof(kr)); + lde_imsg_compose_parent(IMSG_KLABEL_CHANGE, 0, &kr, sizeof(kr)); break; case FEC_TYPE_PWID: pw = (struct l2vpn_pw *) fn->data; @@ -871,8 +855,7 @@ lde_send_delete_klabel(struct fec_node *fn, struct fec_nh *fnh) kr.route_type = fnh->route_type; kr.route_instance = fnh->route_instance; - lde_imsg_compose_parent(IMSG_KLABEL_DELETE, 0, &kr, - sizeof(kr)); + lde_imsg_compose_parent(IMSG_KLABEL_DELETE, 0, &kr, sizeof(kr)); break; case FEC_TYPE_IPV6: memset(&kr, 0, sizeof(kr)); @@ -886,8 +869,7 @@ lde_send_delete_klabel(struct fec_node *fn, struct fec_nh *fnh) kr.route_type = fnh->route_type; kr.route_instance = fnh->route_instance; - lde_imsg_compose_parent(IMSG_KLABEL_DELETE, 0, &kr, - sizeof(kr)); + lde_imsg_compose_parent(IMSG_KLABEL_DELETE, 0, &kr, sizeof(kr)); break; case FEC_TYPE_PWID: pw = (struct l2vpn_pw *) fn->data; @@ -967,7 +949,7 @@ lde_fec2map(struct fec *fec, struct map *map) map->type = MAP_TYPE_PWID; map->fec.pwid.type = fec->u.pwid.type; map->fec.pwid.group_id = 0; - map->flags |= F_MAP_PW_ID; + SET_FLAG(map->flags, F_MAP_PW_ID); map->fec.pwid.pwid = fec->u.pwid.pwid; break; } @@ -1021,9 +1003,9 @@ lde_send_labelmapping(struct lde_nbr *ln, struct fec_node *fn, int single) * a labelmap message is received from downstream router * and don't send labelmap back to downstream router */ - if (ldeconf->flags & F_LDPD_ORDERED_CONTROL) { + if (CHECK_FLAG(ldeconf->flags, F_LDPD_ORDERED_CONTROL)) { LIST_FOREACH(fnh, &fn->nexthops, entry) { - if (fnh->flags & F_FEC_NH_DEFER) + if (CHECK_FLAG(fnh->flags, F_FEC_NH_DEFER)) continue; if (lde_address_find(ln, fnh->af, &fnh->nexthop)) @@ -1061,9 +1043,11 @@ lde_send_labelmapping(struct lde_nbr *ln, struct fec_node *fn, int single) case FEC_TYPE_IPV4: if (!ln->v4_enabled) return; + if (lde_acl_check(ldeconf->ipv4.acl_label_advertise_to, AF_INET, (union ldpd_addr *)&ln->id, 32) != FILTER_PERMIT) return; + if (lde_acl_check(ldeconf->ipv4.acl_label_advertise_for, AF_INET, (union ldpd_addr *)&fn->fec.u.ipv4.prefix, fn->fec.u.ipv4.prefixlen) != FILTER_PERMIT) @@ -1072,9 +1056,11 @@ lde_send_labelmapping(struct lde_nbr *ln, struct fec_node *fn, int single) case FEC_TYPE_IPV6: if (!ln->v6_enabled) return; + if (lde_acl_check(ldeconf->ipv6.acl_label_advertise_to, AF_INET, (union ldpd_addr *)&ln->id, 32) != FILTER_PERMIT) return; + if (lde_acl_check(ldeconf->ipv6.acl_label_advertise_for, AF_INET6, (union ldpd_addr *)&fn->fec.u.ipv6.prefix, fn->fec.u.ipv6.prefixlen) != FILTER_PERMIT) @@ -1086,12 +1072,14 @@ lde_send_labelmapping(struct lde_nbr *ln, struct fec_node *fn, int single) /* not the remote end of the pseudowire */ return; - map.flags |= F_MAP_PW_IFMTU; + SET_FLAG(map.flags, F_MAP_PW_IFMTU); map.fec.pwid.ifmtu = pw->l2vpn->mtu; - if (pw->flags & F_PW_CWORD) - map.flags |= F_MAP_PW_CWORD; - if (pw->flags & F_PW_STATUSTLV) { - map.flags |= F_MAP_PW_STATUS; + + if (CHECK_FLAG(pw->flags, F_PW_CWORD)) + SET_FLAG(map.flags, F_MAP_PW_CWORD); + + if (CHECK_FLAG(pw->flags, F_PW_STATUSTLV)) { + SET_FLAG(map.flags, F_MAP_PW_STATUS); map.pw_status = pw->local_status; } break; @@ -1149,8 +1137,8 @@ lde_send_labelwithdraw(struct lde_nbr *ln, struct fec_node *fn, /* not the remote end of the pseudowire */ return; - if (pw->flags & F_PW_CWORD) - map.flags |= F_MAP_PW_CWORD; + if (CHECK_FLAG(pw->flags, F_PW_CWORD)) + SET_FLAG(map.flags, F_MAP_PW_CWORD); break; } map.label = fn->local_label; @@ -1161,7 +1149,7 @@ lde_send_labelwithdraw(struct lde_nbr *ln, struct fec_node *fn, map.st.status_code = st->status_code; map.st.msg_id = st->msg_id; map.st.msg_type = st->msg_type; - map.flags |= F_MAP_STATUS; + SET_FLAG(map.flags, F_MAP_STATUS); } /* SWd.1: send label withdraw. */ @@ -1184,10 +1172,10 @@ lde_send_labelwithdraw(struct lde_nbr *ln, struct fec_node *fn, if (lde_wildcard_apply(wcard, &fn->fec, me) == 0) continue; - lw = (struct lde_wdraw *)fec_find(&ln->sent_wdraw, - &fn->fec); + lw = (struct lde_wdraw *)fec_find(&ln->sent_wdraw, &fn->fec); if (lw == NULL) lw = lde_wdraw_add(ln, fn); + lw->label = map.label; } } @@ -1271,8 +1259,8 @@ lde_send_labelrelease(struct lde_nbr *ln, struct fec_node *fn, /* not the remote end of the pseudowire */ return; - if (pw->flags & F_PW_CWORD) - map.flags |= F_MAP_PW_CWORD; + if (CHECK_FLAG(pw->flags, F_PW_CWORD)) + SET_FLAG(map.flags, F_MAP_PW_CWORD); break; } } else @@ -1333,8 +1321,7 @@ lde_send_labelrequest(struct lde_nbr *ln, struct fec_node *fn, lde_imsg_compose_ldpe(IMSG_REQUEST_ADD, ln->peerid, 0, &map, sizeof(map)); if (single) - lde_imsg_compose_ldpe(IMSG_REQUEST_ADD_END, - ln->peerid, 0, NULL, 0); + lde_imsg_compose_ldpe(IMSG_REQUEST_ADD_END, ln->peerid, 0, NULL, 0); /* SLRq.4: record sent request */ RB_FOREACH(f, fec_tree, &ft) { @@ -1386,7 +1373,7 @@ lde_send_notification_eol_prefix(struct lde_nbr *ln, int af) nm.fec.type = MAP_TYPE_TYPED_WCARD; nm.fec.fec.twcard.type = MAP_TYPE_PREFIX; nm.fec.fec.twcard.u.prefix_af = af; - nm.flags |= F_NOTIF_FEC; + SET_FLAG(nm.flags, F_NOTIF_FEC); lde_imsg_compose_ldpe(IMSG_NOTIFICATION_SEND, ln->peerid, 0, &nm, sizeof(nm)); @@ -1402,7 +1389,7 @@ lde_send_notification_eol_pwid(struct lde_nbr *ln, uint16_t pw_type) nm.fec.type = MAP_TYPE_TYPED_WCARD; nm.fec.fec.twcard.type = MAP_TYPE_PWID; nm.fec.fec.twcard.u.pw_type = pw_type; - nm.flags |= F_NOTIF_FEC; + SET_FLAG(nm.flags, F_NOTIF_FEC); lde_imsg_compose_ldpe(IMSG_NOTIFICATION_SEND, ln->peerid, 0, &nm, sizeof(nm)); @@ -1465,8 +1452,7 @@ lde_nbr_del(struct lde_nbr *ln) switch (f->type) { case FEC_TYPE_IPV4: case FEC_TYPE_IPV6: - if (!lde_address_find(ln, fnh->af, - &fnh->nexthop)) + if (!lde_address_find(ln, fnh->af, &fnh->nexthop)) continue; /* @@ -1478,8 +1464,8 @@ lde_nbr_del(struct lde_nbr *ln) * to other neighbors for all fecs from neighbor * going down */ - if (ldeconf->flags & F_LDPD_ORDERED_CONTROL) { - fnh->flags |= F_FEC_NH_DEFER; + if (CHECK_FLAG(ldeconf->flags, F_LDPD_ORDERED_CONTROL)) { + SET_FLAG(fnh->flags, F_FEC_NH_DEFER); RB_FOREACH(lnbr, nbr_tree, &lde_nbrs) { if (ln->peerid == lnbr->peerid) @@ -1594,8 +1580,7 @@ lde_nbr_addr_update(struct lde_nbr *ln, struct lde_addr *lde_addr, int removed) continue; LIST_FOREACH(fnh, &fn->nexthops, entry) { - if (ldp_addrcmp(fnh->af, &fnh->nexthop, - &lde_addr->addr)) + if (ldp_addrcmp(fnh->af, &fnh->nexthop, &lde_addr->addr)) continue; if (removed) { @@ -1658,15 +1643,13 @@ lde_map_add(struct lde_nbr *ln, struct fec_node *fn, int sent) RB_INSERT(lde_map_head, &fn->upstream, me); me->head = &fn->upstream; if (fec_insert(&ln->sent_map, &me->fec)) - log_warnx("failed to add %s to sent map", - log_fec(&me->fec)); + log_warnx("failed to add %s to sent map", log_fec(&me->fec)); /* XXX on failure more cleanup is needed */ } else { RB_INSERT(lde_map_head, &fn->downstream, me); me->head = &fn->downstream; if (fec_insert(&ln->recv_map, &me->fec)) - log_warnx("failed to add %s to recv map", - log_fec(&me->fec)); + log_warnx("failed to add %s to recv map", log_fec(&me->fec)); } return (me); @@ -1703,8 +1686,7 @@ lde_map_pending_add(struct lde_nbr *ln, struct fec_node *fn) *map = fn->fec; if (fec_insert(&ln->sent_map_pending, map)) - log_warnx("failed to add %s to sent map (pending)", - log_fec(map)); + log_warnx("failed to add %s to sent map (pending)", log_fec(map)); return (map); } @@ -1762,8 +1744,7 @@ lde_wdraw_add(struct lde_nbr *ln, struct fec_node *fn) lw->fec = fn->fec; if (fec_insert(&ln->sent_wdraw, &lw->fec)) - log_warnx("failed to add %s to sent wdraw", - log_fec(&lw->fec)); + log_warnx("failed to add %s to sent wdraw", log_fec(&lw->fec)); return (lw); } @@ -1786,13 +1767,9 @@ lde_change_egress_label(int af) RB_FOREACH(ln, nbr_tree, &lde_nbrs) { lde_send_labelwithdraw_wcard(ln, MPLS_LABEL_IMPLICIT_NULL); if (ln->v4_enabled) - lde_send_labelwithdraw_wcard( - ln, - MPLS_LABEL_IPV4_EXPLICIT_NULL); + lde_send_labelwithdraw_wcard(ln, MPLS_LABEL_IPV4_EXPLICIT_NULL); if (ln->v6_enabled) - lde_send_labelwithdraw_wcard( - ln, - MPLS_LABEL_IPV6_EXPLICIT_NULL); + lde_send_labelwithdraw_wcard(ln, MPLS_LABEL_IPV6_EXPLICIT_NULL); } /* update label of connected routes */ @@ -1820,8 +1797,7 @@ lde_change_egress_label(int af) lde_send_labelmapping(ln, fn, 0); } RB_FOREACH(ln, nbr_tree, &lde_nbrs) - lde_imsg_compose_ldpe(IMSG_MAPPING_ADD_END, ln->peerid, 0, - NULL, 0); + lde_imsg_compose_ldpe(IMSG_MAPPING_ADD_END, ln->peerid, 0, NULL, 0); } void @@ -1861,8 +1837,7 @@ lde_change_allocate_filter(int af) if (fn->local_label != new_label) { if (new_label == NO_LABEL) RB_FOREACH(ln, nbr_tree, &lde_nbrs) - lde_send_labelwithdraw(ln, fn, - NULL, NULL); + lde_send_labelwithdraw(ln, fn, NULL, NULL); fn->local_label = new_label; if (fn->local_label != NO_LABEL) @@ -1870,6 +1845,7 @@ lde_change_allocate_filter(int af) lde_send_labelmapping(ln, fn, 0); } } + RB_FOREACH(ln, nbr_tree, &lde_nbrs) lde_imsg_compose_ldpe(IMSG_MAPPING_ADD_END, ln->peerid, 0, NULL, 0); @@ -1915,34 +1891,30 @@ lde_change_advertise_filter(int af) case AF_INET: if (fn->fec.type != FEC_TYPE_IPV4) continue; - prefix = (union ldpd_addr *) - &fn->fec.u.ipv4.prefix; + prefix = (union ldpd_addr *)&fn->fec.u.ipv4.prefix; plen = fn->fec.u.ipv4.prefixlen; break; case FEC_TYPE_IPV6: if (fn->fec.type != FEC_TYPE_IPV6) continue; - prefix = (union ldpd_addr *) - &fn->fec.u.ipv6.prefix; + prefix = (union ldpd_addr *)&fn->fec.u.ipv6.prefix; plen = fn->fec.u.ipv6.prefixlen; break; default: continue; } + if (lde_acl_check(acl_for_filter, af, prefix, plen) != FILTER_PERMIT) { - me = (struct lde_map *)fec_find( - &ln->sent_map, &fn->fec); + me = (struct lde_map *)fec_find(&ln->sent_map, &fn->fec); if (me) /* fec filtered withdraw */ - lde_send_labelwithdraw(ln, fn, - NULL, NULL); + lde_send_labelwithdraw(ln, fn, NULL, NULL); } else /* fec allowed send map */ lde_send_labelmapping(ln, fn, 0); } - lde_imsg_compose_ldpe(IMSG_MAPPING_ADD_END, - ln->peerid, 0, NULL, 0); + lde_imsg_compose_ldpe(IMSG_MAPPING_ADD_END, ln->peerid, 0, NULL, 0); } } } @@ -1988,13 +1960,12 @@ lde_change_accept_filter(int af) RB_FOREACH(f, fec_tree, &ft) { fn = (struct fec_node *)f; if (fn->fec.type == type) { - me = (struct lde_map *)fec_find( - &ln->recv_map, &fn->fec); + me = (struct lde_map *)fec_find(&ln->recv_map, &fn->fec); if (me) lde_map_del(ln, me, 0); } } - } else if (ln->flags & F_NBR_CAP_TWCARD) { + } else if (CHECK_FLAG(ln->flags, F_NBR_CAP_TWCARD)) { /* This neighbor is allowed and supports type * wildcard so send a labelrequest * to get any new labels from neighbor @@ -2007,15 +1978,13 @@ lde_change_accept_filter(int af) case AF_INET: if (fn->fec.type != FEC_TYPE_IPV4) continue; - prefix = (union ldpd_addr *) - &fn->fec.u.ipv4.prefix; + prefix = (union ldpd_addr *)&fn->fec.u.ipv4.prefix; plen = fn->fec.u.ipv4.prefixlen; break; case AF_INET6: if (fn->fec.type != FEC_TYPE_IPV6) continue; - prefix = (union ldpd_addr *) - &fn->fec.u.ipv6.prefix; + prefix = (union ldpd_addr *)&fn->fec.u.ipv6.prefix; plen = fn->fec.u.ipv6.prefixlen; break; default: @@ -2023,8 +1992,7 @@ lde_change_accept_filter(int af) } if (lde_acl_check(acl_for_filter, af, prefix, plen) != FILTER_PERMIT) { - me = (struct lde_map *)fec_find( - &ln->recv_map, &fn->fec); + me = (struct lde_map *)fec_find(&ln->recv_map, &fn->fec); if (me) lde_map_del(ln, me, 0); } @@ -2032,8 +2000,7 @@ lde_change_accept_filter(int af) lde_send_labelrequest_wcard(ln, af); } else /* Type Wildcard is not supported so restart session */ - lde_imsg_compose_ldpe(IMSG_NBR_SHUTDOWN, ln->peerid, 0, - NULL, 0); + lde_imsg_compose_ldpe(IMSG_NBR_SHUTDOWN, ln->peerid, 0, NULL, 0); } } @@ -2299,7 +2266,7 @@ lde_free_label(uint32_t label) for (ALL_LIST_ELEMENTS_RO(label_chunk_list, node, label_chunk)) { if (label <= label_chunk->end && label >= label_chunk->start) { pos = 1ULL << (label - label_chunk->start); - label_chunk->used_mask &= ~pos; + UNSET_FLAG(label_chunk->used_mask, pos); /* if nobody is using this chunk and it's not current_label_chunk, then free it */ if (!label_chunk->used_mask && (current_label_chunk != node)) { if (lde_release_label_chunk(label_chunk->start, label_chunk->end) != 0) @@ -2312,6 +2279,7 @@ lde_free_label(uint32_t label) break; } } + return; } @@ -2332,7 +2300,7 @@ lde_get_next_label(void) size = label_chunk->end - label_chunk->start + 1; for (i = 0, pos = 1; i < size; i++, pos <<= 1) { if (!(pos & label_chunk->used_mask)) { - label_chunk->used_mask |= pos; + SET_FLAG(label_chunk->used_mask, pos); label = label_chunk->start + i; goto end; } @@ -2360,12 +2328,15 @@ lde_check_filter_af(int af, struct ldpd_af_conf *af_conf, { if (strcmp(af_conf->acl_label_allocate_for, filter_name) == 0) lde_change_allocate_filter(af); + if ((strcmp(af_conf->acl_label_advertise_to, filter_name) == 0) || (strcmp(af_conf->acl_label_advertise_for, filter_name) == 0)) lde_change_advertise_filter(af); + if ((strcmp(af_conf->acl_label_accept_for, filter_name) == 0) || (strcmp(af_conf->acl_label_accept_from, filter_name) == 0)) lde_change_accept_filter(af); + if (strcmp(af_conf->acl_label_expnull_for, filter_name) == 0) lde_change_expnull_for_filter(af); } @@ -2379,6 +2350,7 @@ void lde_route_update(struct iface *iface, int af) /* update label of non-connected routes */ log_debug("update labels for interface %s", iface->name); + RB_FOREACH(f, fec_tree, &ft) { fn = (struct fec_node *)f; if (IS_MPLS_UNRESERVED_LABEL(fn->local_label)) @@ -2405,13 +2377,13 @@ void lde_route_update(struct iface *iface, int af) * may need new label. If no LDP configured * treat fec as a connected route */ - if (fnh->flags & F_FEC_NH_CONNECTED) + if (CHECK_FLAG(fnh->flags, F_FEC_NH_CONNECTED)) break; if (fnh->ifindex != iface->ifindex) continue; - fnh->flags &= ~F_FEC_NH_NO_LDP; + UNSET_FLAG(fnh->flags, F_FEC_NH_NO_LDP); if (IS_MPLS_RESERVED_LABEL(fn->local_label)) { fn->local_label = NO_LABEL; fn->local_label = lde_update_label(fn); @@ -2423,6 +2395,7 @@ void lde_route_update(struct iface *iface, int af) break; } } + RB_FOREACH(ln, nbr_tree, &lde_nbrs) lde_imsg_compose_ldpe(IMSG_MAPPING_ADD_END, ln->peerid, 0, NULL, 0); @@ -2438,6 +2411,7 @@ void lde_route_update_release(struct iface *iface, int af) /* update label of interfaces no longer running LDP */ log_debug("release all labels for interface %s af %s", iface->name, af == AF_INET ? "ipv4" : "ipv6"); + RB_FOREACH(f, fec_tree, &ft) { fn = (struct fec_node *)f; @@ -2463,13 +2437,13 @@ void lde_route_update_release(struct iface *iface, int af) * removed from interface may need new label * and would be treated as a connected route */ - if (fnh->flags & F_FEC_NH_CONNECTED) + if (CHECK_FLAG(fnh->flags, F_FEC_NH_CONNECTED)) break; if (fnh->ifindex != iface->ifindex) continue; - fnh->flags |= F_FEC_NH_NO_LDP; + SET_FLAG(fnh->flags, F_FEC_NH_NO_LDP); RB_FOREACH(ln, nbr_tree, &lde_nbrs) lde_send_labelwithdraw(ln, fn, NULL, NULL); lde_free_label(fn->local_label); @@ -2481,6 +2455,7 @@ void lde_route_update_release(struct iface *iface, int af) break; } } + RB_FOREACH(ln, nbr_tree, &lde_nbrs) lde_imsg_compose_ldpe(IMSG_MAPPING_ADD_END, ln->peerid, 0, NULL, 0); @@ -2498,6 +2473,7 @@ void lde_route_update_release_all(int af) */ log_debug("release all labels for address family %s", af == AF_INET ? "ipv4" : "ipv6"); + RB_FOREACH(f, fec_tree, &ft) { fn = (struct fec_node *)f; switch (af) { @@ -2517,7 +2493,7 @@ void lde_route_update_release_all(int af) lde_send_labelwithdraw(ln, fn, NULL, NULL); LIST_FOREACH(fnh, &fn->nexthops, entry) { - fnh->flags |= F_FEC_NH_NO_LDP; + SET_FLAG(fnh->flags, F_FEC_NH_NO_LDP); lde_send_delete_klabel(fn, fnh); } } |