From: Donatas Abraitis Date: Wed, 1 Jun 2022 12:19:33 +0000 (+0300) Subject: bgpd: Drop label_ntop/label_pton functions X-Git-Tag: base_8.4~376^2 X-Git-Url: https://git.puffer.fish/?a=commitdiff_plain;h=67f67ba481f39b3049eadabe2c73e4d9a2797d28;p=matthieu%2Ffrr.git bgpd: Drop label_ntop/label_pton functions Start using mpls_lse_encode/mpls_lse_decode, that is endian-aware, because we always use host-byte order, should use network-byte. Signed-off-by: Donatas Abraitis --- diff --git a/bgpd/bgp_label.c b/bgpd/bgp_label.c index a9c4b4c678..38f34a8927 100644 --- a/bgpd/bgp_label.c +++ b/bgpd/bgp_label.c @@ -85,7 +85,7 @@ int bgp_parse_fec_update(void) if (label == MPLS_INVALID_LABEL) bgp_unset_valid_label(&dest->local_label); else { - label_ntop(label, 1, &dest->local_label); + dest->local_label = mpls_lse_encode(label, 0, 0, 1); bgp_set_valid_label(&dest->local_label); } SET_FLAG(dest->flags, BGP_NODE_LABEL_CHANGED); @@ -129,9 +129,16 @@ static void bgp_send_fec_register_label_msg(struct bgp_dest *dest, bool reg, uint16_t flags = 0; size_t flags_pos = 0; mpls_label_t *local_label = &(dest->local_label); - bool have_label_to_reg = - bgp_is_valid_label(local_label) - && label_pton(local_label) != MPLS_LABEL_IMPLICIT_NULL; + uint32_t ttl = 0; + uint32_t bos = 0; + uint32_t exp = 0; + mpls_label_t label = MPLS_INVALID_LABEL; + bool have_label_to_reg; + + mpls_lse_decode(*local_label, &label, &ttl, &exp, &bos); + + have_label_to_reg = bgp_is_valid_label(local_label) && + label != MPLS_LABEL_IMPLICIT_NULL; p = bgp_dest_get_prefix(dest); @@ -142,7 +149,7 @@ static void bgp_send_fec_register_label_msg(struct bgp_dest *dest, bool reg, if (BGP_DEBUG(labelpool, LABELPOOL)) zlog_debug("%s: FEC %sregister %pRN label_index=%u label=%u", __func__, reg ? "" : "un", bgp_dest_to_rnode(dest), - label_index, label_pton(local_label)); + label_index, label); /* If the route node has a local_label assigned or the * path node has an MPLS SR label index allowing zebra to * derive the label, proceed with registration. */ @@ -161,7 +168,7 @@ static void bgp_send_fec_register_label_msg(struct bgp_dest *dest, bool reg, stream_putl(s, label_index); } else if (have_label_to_reg) { flags |= ZEBRA_FEC_REGISTER_LABEL; - stream_putl(s, label_pton(local_label)); + stream_putl(s, label); } SET_FLAG(dest->flags, BGP_NODE_REGISTERED_FOR_LABEL); } else @@ -216,13 +223,13 @@ int bgp_reg_for_label_callback(mpls_label_t new_label, void *labelid, */ if (CHECK_FLAG(dest->flags, BGP_NODE_REGISTERED_FOR_LABEL)) { UNSET_FLAG(dest->flags, BGP_NODE_LABEL_REQUESTED); - label_ntop(MPLS_LABEL_IMPLICIT_NULL, 1, - &dest->local_label); + dest->local_label = mpls_lse_encode( + MPLS_LABEL_IMPLICIT_NULL, 0, 0, 1); bgp_set_valid_label(&dest->local_label); } } - label_ntop(new_label, 1, &dest->local_label); + dest->local_label = mpls_lse_encode(new_label, 0, 0, 1); bgp_set_valid_label(&dest->local_label); /* @@ -238,9 +245,16 @@ void bgp_reg_dereg_for_label(struct bgp_dest *dest, struct bgp_path_info *pi, { bool with_label_index = false; const struct prefix *p; - bool have_label_to_reg = - bgp_is_valid_label(&dest->local_label) - && label_pton(&dest->local_label) != MPLS_LABEL_IMPLICIT_NULL; + bool have_label_to_reg; + uint32_t ttl = 0; + uint32_t bos = 0; + uint32_t exp = 0; + mpls_label_t label = MPLS_INVALID_LABEL; + + mpls_lse_decode(dest->local_label, &label, &ttl, &exp, &bos); + + have_label_to_reg = bgp_is_valid_label(&dest->local_label) && + label != MPLS_LABEL_IMPLICIT_NULL; p = bgp_dest_get_prefix(dest); @@ -283,8 +297,7 @@ void bgp_reg_dereg_for_label(struct bgp_dest *dest, struct bgp_path_info *pi, } } else { UNSET_FLAG(dest->flags, BGP_NODE_LABEL_REQUESTED); - bgp_lp_release(LP_TYPE_BGP_LU, dest, - label_pton(&dest->local_label)); + bgp_lp_release(LP_TYPE_BGP_LU, dest, label); } bgp_send_fec_register_label_msg( diff --git a/bgpd/bgp_label.h b/bgpd/bgp_label.h index cafcc8e9c7..4061e8719b 100644 --- a/bgpd/bgp_label.h +++ b/bgpd/bgp_label.h @@ -98,25 +98,6 @@ static inline void bgp_unregister_for_label(struct bgp_dest *dest) bgp_reg_dereg_for_label(dest, NULL, false); } -/* Label stream to value */ -static inline uint32_t label_pton(const mpls_label_t *label) -{ - uint8_t *t = (uint8_t *)label; - return ((((unsigned int)t[0]) << 12) | (((unsigned int)t[1]) << 4) - | ((unsigned int)((t[2] & 0xF0) >> 4))); -} - -/* Encode label values */ -static inline void label_ntop(uint32_t l, int bos, mpls_label_t *label) -{ - uint8_t *t = (uint8_t *)label; - t[0] = ((l & 0x000FF000) >> 12); - t[1] = ((l & 0x00000FF0) >> 4); - t[2] = ((l & 0x0000000F) << 4); - if (bos) - t[2] |= 0x01; -} - /* Return BOS value of label stream */ static inline uint8_t label_bos(mpls_label_t *label) { diff --git a/bgpd/bgp_route.c b/bgpd/bgp_route.c index 5df45aa315..5146862e33 100644 --- a/bgpd/bgp_route.c +++ b/bgpd/bgp_route.c @@ -2958,8 +2958,9 @@ static void bgp_process_main_one(struct bgp *bgp, struct bgp_dest *dest, dest->flags, BGP_NODE_LABEL_REQUESTED)) bgp_unregister_for_label(dest); - label_ntop(MPLS_LABEL_IMPLICIT_NULL, 1, - &dest->local_label); + dest->local_label = mpls_lse_encode( + MPLS_LABEL_IMPLICIT_NULL, 0, 0, + 1); bgp_set_valid_label(&dest->local_label); } else bgp_register_for_label(dest, @@ -9872,6 +9873,10 @@ void route_vty_out_detail(struct vty *vty, struct bgp *bgp, struct bgp_dest *bn, int i; char *nexthop_hostname = bgp_nexthop_hostname(path->peer, path->nexthop); + uint32_t ttl = 0; + uint32_t bos = 0; + uint32_t exp = 0; + mpls_label_t label = MPLS_INVALID_LABEL; if (json_paths) { json_path = json_object_new_object(); @@ -10614,7 +10619,8 @@ void route_vty_out_detail(struct vty *vty, struct bgp *bgp, struct bgp_dest *bn, /* Remote Label */ if (path->extra && bgp_is_valid_label(&path->extra->label[0]) && (safi != SAFI_EVPN && !is_route_parent_evpn(path))) { - mpls_label_t label = label_pton(&path->extra->label[0]); + mpls_lse_decode(path->extra->label[0], &label, &ttl, &exp, + &bos); if (json_paths) json_object_int_add(json_path, "remoteLabel", label); @@ -11433,12 +11439,14 @@ void route_vty_out_detail_header(struct vty *vty, struct bgp *bgp, int has_valid_label = 0; mpls_label_t label = 0; json_object *json_adv_to = NULL; + uint32_t ttl = 0; + uint32_t bos = 0; + uint32_t exp = 0; - p = bgp_dest_get_prefix(dest); - has_valid_label = bgp_is_valid_label(&dest->local_label); + mpls_lse_decode(dest->local_label, &label, &ttl, &exp, &bos); - if (has_valid_label) - label = label_pton(&dest->local_label); + p = bgp_dest_get_prefix(dest); + has_valid_label = bgp_is_valid_label(&label); if (safi == SAFI_EVPN) { diff --git a/bgpd/bgp_zebra.c b/bgpd/bgp_zebra.c index 2c1d561721..c1b388b05d 100644 --- a/bgpd/bgp_zebra.c +++ b/bgpd/bgp_zebra.c @@ -1274,6 +1274,9 @@ void bgp_zebra_announce(struct bgp_dest *dest, const struct prefix *p, uint64_t cum_bw = 0; uint32_t nhg_id = 0; bool is_add; + uint32_t ttl = 0; + uint32_t bos = 0; + uint32_t exp = 0; /* Don't try to install if we're not connected to Zebra or Zebra doesn't * know of this instance. @@ -1465,7 +1468,8 @@ void bgp_zebra_announce(struct bgp_dest *dest, const struct prefix *p, if (mpinfo->extra && bgp_is_valid_label(&mpinfo->extra->label[0]) && !CHECK_FLAG(api.flags, ZEBRA_FLAG_EVPN_ROUTE)) { - label = label_pton(&mpinfo->extra->label[0]); + mpls_lse_decode(mpinfo->extra->label[0], &label, &ttl, + &exp, &bos); SET_FLAG(api_nh->flags, ZAPI_NEXTHOP_FLAG_LABEL); @@ -1493,7 +1497,8 @@ void bgp_zebra_announce(struct bgp_dest *dest, const struct prefix *p, &mpinfo->extra->label[0])) continue; - label = label_pton(&mpinfo->extra->label[0]); + mpls_lse_decode(mpinfo->extra->label[0], &label, + &ttl, &exp, &bos); transpose_sid(&api_nh->seg6_segs, label, sid_info->transposition_offset, sid_info->transposition_len);