diff options
Diffstat (limited to 'zebra/zebra_evpn_mh.c')
| -rw-r--r-- | zebra/zebra_evpn_mh.c | 137 |
1 files changed, 92 insertions, 45 deletions
diff --git a/zebra/zebra_evpn_mh.c b/zebra/zebra_evpn_mh.c index d6ae92a03d..c0cc57fc69 100644 --- a/zebra/zebra_evpn_mh.c +++ b/zebra/zebra_evpn_mh.c @@ -1747,7 +1747,7 @@ static int zebra_es_rb_cmp(const struct zebra_evpn_es *es1, RB_GENERATE(zebra_es_rb_head, zebra_evpn_es, rb_node, zebra_es_rb_cmp); /* Lookup ES */ -struct zebra_evpn_es *zebra_evpn_es_find(esi_t *esi) +struct zebra_evpn_es *zebra_evpn_es_find(const esi_t *esi) { struct zebra_evpn_es tmp; @@ -1758,7 +1758,7 @@ struct zebra_evpn_es *zebra_evpn_es_find(esi_t *esi) /* A new local es is created when a local-es-id and sysmac is configured * against an interface. */ -static struct zebra_evpn_es *zebra_evpn_es_new(esi_t *esi) +static struct zebra_evpn_es *zebra_evpn_es_new(const esi_t *esi) { struct zebra_evpn_es *es; @@ -2392,7 +2392,7 @@ static int zebra_evpn_type3_esi_update(struct zebra_if *zif, uint32_t lid, return zebra_evpn_local_es_update(zif, &esi); } -static int zebra_evpn_remote_es_del(esi_t *esi, struct in_addr vtep_ip) +int zebra_evpn_remote_es_del(const esi_t *esi, struct in_addr vtep_ip) { char buf[ESI_STR_LEN]; struct zebra_evpn_es *es; @@ -2432,9 +2432,8 @@ static void zebra_evpn_remote_es_flush(struct zebra_evpn_es **esp) zebra_evpn_es_remote_info_re_eval(esp); } -static int zebra_evpn_remote_es_add(esi_t *esi, struct in_addr vtep_ip, - bool esr_rxed, uint8_t df_alg, - uint16_t df_pref) +int zebra_evpn_remote_es_add(const esi_t *esi, struct in_addr vtep_ip, + bool esr_rxed, uint8_t df_alg, uint16_t df_pref) { char buf[ESI_STR_LEN]; struct zebra_evpn_es *es; @@ -2498,10 +2497,10 @@ void zebra_evpn_proc_remote_es(ZAPI_HANDLER_ARGS) : false; STREAM_GETC(s, df_alg); STREAM_GETW(s, df_pref); - zebra_evpn_remote_es_add(&esi, vtep_ip, esr_rxed, df_alg, - df_pref); + zebra_rib_queue_evpn_rem_es_add(&esi, &vtep_ip, esr_rxed, + df_alg, df_pref); } else { - zebra_evpn_remote_es_del(&esi, vtep_ip); + zebra_rib_queue_evpn_rem_es_del(&esi, &vtep_ip); } stream_failure: @@ -2542,7 +2541,7 @@ bool zebra_evpn_es_mac_ref_entry(zebra_mac_t *mac, struct zebra_evpn_es *es) return true; } -bool zebra_evpn_es_mac_ref(zebra_mac_t *mac, esi_t *esi) +bool zebra_evpn_es_mac_ref(zebra_mac_t *mac, const esi_t *esi) { struct zebra_evpn_es *es; @@ -2782,41 +2781,76 @@ bool zebra_evpn_is_if_es_capable(struct zebra_if *zif) return false; } -void zebra_evpn_if_es_print(struct vty *vty, struct zebra_if *zif) +void zebra_evpn_if_es_print(struct vty *vty, json_object *json, + struct zebra_if *zif) { char buf[ETHER_ADDR_STRLEN]; - char mh_buf[80]; - bool vty_print = false; char esi_buf[ESI_STR_LEN]; - mh_buf[0] = '\0'; - strlcat(mh_buf, " EVPN-MH:", sizeof(mh_buf)); - if (zif->es_info.lid || !is_zero_mac(&zif->es_info.sysmac)) { - vty_print = true; - snprintf( - mh_buf + strlen(mh_buf), - sizeof(mh_buf) - strlen(mh_buf), - " ES id %u ES sysmac %s", zif->es_info.lid, - prefix_mac2str(&zif->es_info.sysmac, buf, sizeof(buf))); - } else if (memcmp(&zif->es_info.esi, zero_esi, sizeof(*zero_esi))) { - vty_print = true; - snprintf(mh_buf + strnlen(mh_buf, sizeof(mh_buf)), - sizeof(mh_buf) - strnlen(mh_buf, sizeof(mh_buf)), - " ES id %s", - esi_to_str(&zif->es_info.esi, esi_buf, - sizeof(esi_buf))); - } - - if (zif->flags & ZIF_FLAG_EVPN_MH_UPLINK) { - vty_print = true; - if (zif->flags & ZIF_FLAG_EVPN_MH_UPLINK_OPER_UP) - strlcat(mh_buf, " uplink (up)", sizeof(mh_buf)); - else - strlcat(mh_buf, " uplink (down)", sizeof(mh_buf)); - } + if (json) { + json_object *json_evpn; + + json_evpn = json_object_new_object(); + json_object_object_add(json, "evpnMh", json_evpn); + + if (zif->es_info.lid || !is_zero_mac(&zif->es_info.sysmac)) { + json_object_int_add(json_evpn, "esId", + zif->es_info.lid); + json_object_string_add( + json_evpn, "esSysmac", + prefix_mac2str(&zif->es_info.sysmac, buf, + sizeof(buf))); + } else if (memcmp(&zif->es_info.esi, zero_esi, + sizeof(*zero_esi))) { + json_object_string_add(json_evpn, "esId", + esi_to_str(&zif->es_info.esi, + esi_buf, + sizeof(esi_buf))); + } + + if (zif->flags & ZIF_FLAG_EVPN_MH_UPLINK) + json_object_string_add( + json_evpn, "uplink", + CHECK_FLAG(zif->flags, + ZIF_FLAG_EVPN_MH_UPLINK_OPER_UP) + ? "up" + : "down"); + } else { + char mh_buf[80]; + bool vty_print = false; + + mh_buf[0] = '\0'; + strlcat(mh_buf, " EVPN-MH:", sizeof(mh_buf)); + if (zif->es_info.lid || !is_zero_mac(&zif->es_info.sysmac)) { + vty_print = true; + snprintf(mh_buf + strlen(mh_buf), + sizeof(mh_buf) - strlen(mh_buf), + " ES id %u ES sysmac %s", zif->es_info.lid, + prefix_mac2str(&zif->es_info.sysmac, buf, + sizeof(buf))); + } else if (memcmp(&zif->es_info.esi, zero_esi, + sizeof(*zero_esi))) { + vty_print = true; + snprintf(mh_buf + strnlen(mh_buf, sizeof(mh_buf)), + sizeof(mh_buf) + - strnlen(mh_buf, sizeof(mh_buf)), + " ES id %s", + esi_to_str(&zif->es_info.esi, esi_buf, + sizeof(esi_buf))); + } - if (vty_print) - vty_out(vty, "%s\n", mh_buf); + if (zif->flags & ZIF_FLAG_EVPN_MH_UPLINK) { + vty_print = true; + if (zif->flags & ZIF_FLAG_EVPN_MH_UPLINK_OPER_UP) + strlcat(mh_buf, " uplink (up)", sizeof(mh_buf)); + else + strlcat(mh_buf, " uplink (down)", + sizeof(mh_buf)); + } + + if (vty_print) + vty_out(vty, "%s\n", mh_buf); + } } static void zebra_evpn_local_mac_oper_state_change(struct zebra_evpn_es *es) @@ -3886,8 +3920,18 @@ void zebra_evpn_proc_remote_nh(ZAPI_HANDLER_ARGS) struct ipaddr nh; struct ethaddr rmac; struct prefix_evpn dummy_prefix; + size_t min_len = 4 + sizeof(nh); s = msg; + + /* + * Ensure that the stream sent to us is long enough + */ + if (hdr->command == ZEBRA_EVPN_REMOTE_NH_ADD) + min_len += sizeof(rmac); + if (hdr->length < min_len) + return; + vrf_id = stream_getl(s); stream_get(&nh, s, sizeof(nh)); @@ -3895,18 +3939,21 @@ void zebra_evpn_proc_remote_nh(ZAPI_HANDLER_ARGS) dummy_prefix.family = AF_EVPN; dummy_prefix.prefixlen = (sizeof(struct evpn_addr) * 8); dummy_prefix.prefix.route_type = 1; /* XXX - fixup to type-1 def */ + dummy_prefix.prefix.ead_addr.ip.ipa_type = nh.ipa_type; if (hdr->command == ZEBRA_EVPN_REMOTE_NH_ADD) { stream_get(&rmac, s, sizeof(rmac)); if (IS_ZEBRA_DEBUG_EVPN_MH_ES) - zlog_debug("evpn remote nh %d %pIA rmac %pEA add", - vrf_id, &nh, &rmac); - zebra_vxlan_evpn_vrf_route_add(vrf_id, &rmac, &nh, + zlog_debug( + "evpn remote nh %d %pIA rmac %pEA add pfx %pFX", + vrf_id, &nh, &rmac, &dummy_prefix); + zebra_rib_queue_evpn_route_add(vrf_id, &rmac, &nh, (struct prefix *)&dummy_prefix); } else { if (IS_ZEBRA_DEBUG_EVPN_MH_ES) - zlog_debug("evpn remote nh %d %pIA del", vrf_id, &nh); - zebra_vxlan_evpn_vrf_route_del(vrf_id, &nh, + zlog_debug("evpn remote nh %d %pIA del pfx %pFX", + vrf_id, &nh, &dummy_prefix); + zebra_rib_queue_evpn_route_del(vrf_id, &nh, (struct prefix *)&dummy_prefix); } } |
