diff options
author | Igor Ryzhov <iryzhov@nfware.com> | 2024-01-22 20:52:09 +0100 |
---|---|---|
committer | Igor Ryzhov <iryzhov@nfware.com> | 2024-01-28 22:28:39 +0100 |
commit | 7c6e41ecffe63cb5d17b475c874faf788e4138a3 (patch) | |
tree | 52a3cddb5043a10fcf00193ef8d97d3b98417c94 | |
parent | zebra: convert interface evpn mh es-id commands to NB (diff) | |
download | frr-7c6e41ecffe63cb5d17b475c874faf788e4138a3.tar.xz frr-7c6e41ecffe63cb5d17b475c874faf788e4138a3.zip |
zebra: convert interface evpn mh es-df-pref command to NB
Signed-off-by: Igor Ryzhov <iryzhov@nfware.com>
-rw-r--r-- | yang/frr-zebra.yang | 6 | ||||
-rw-r--r-- | zebra/interface.c | 2 | ||||
-rw-r--r-- | zebra/zebra_evpn_mh.c | 58 | ||||
-rw-r--r-- | zebra/zebra_evpn_mh.h | 4 | ||||
-rw-r--r-- | zebra/zebra_nb.c | 6 | ||||
-rw-r--r-- | zebra/zebra_nb.h | 2 | ||||
-rw-r--r-- | zebra/zebra_nb_config.c | 19 |
7 files changed, 66 insertions, 31 deletions
diff --git a/yang/frr-zebra.yang b/yang/frr-zebra.yang index e12484063..a004aaf2a 100644 --- a/yang/frr-zebra.yang +++ b/yang/frr-zebra.yang @@ -2245,6 +2245,12 @@ module frr-zebra { } } } + leaf df-preference { + type uint16; + default "32767"; + description + "Preference value used for DF election."; + } } container state { config false; diff --git a/zebra/interface.c b/zebra/interface.c index 9c8c9e012..8bbabff92 100644 --- a/zebra/interface.c +++ b/zebra/interface.c @@ -148,6 +148,8 @@ static int if_zebra_new_hook(struct interface *ifp) rtadv_if_init(zebra_if); + zebra_evpn_mh_if_init(zebra_if); + memset(&zebra_if->neigh_mac[0], 0, 6); /* Initialize installed address chains tree. */ diff --git a/zebra/zebra_evpn_mh.c b/zebra/zebra_evpn_mh.c index 24542932f..0d5eb6fc1 100644 --- a/zebra/zebra_evpn_mh.c +++ b/zebra/zebra_evpn_mh.c @@ -2251,8 +2251,7 @@ static void zebra_evpn_es_local_info_set(struct zebra_evpn_es *es, /* attach es to interface */ zif->es_info.es = es; - es->df_pref = zif->es_info.df_pref ? zif->es_info.df_pref - : EVPN_MH_DF_PREF_DEFAULT; + es->df_pref = zif->es_info.df_pref; /* attach interface to es */ es->zif = zif; @@ -2706,10 +2705,9 @@ void zebra_evpn_es_cleanup(void) } } -static void zebra_evpn_es_df_pref_update(struct zebra_if *zif, uint16_t df_pref) +void zebra_evpn_es_df_pref_update(struct zebra_if *zif, uint16_t df_pref) { struct zebra_evpn_es *es; - uint16_t tmp_pref; if (zif->es_info.df_pref == df_pref) return; @@ -2720,13 +2718,10 @@ static void zebra_evpn_es_df_pref_update(struct zebra_if *zif, uint16_t df_pref) if (!es) return; - tmp_pref = zif->es_info.df_pref ? zif->es_info.df_pref - : EVPN_MH_DF_PREF_DEFAULT; - - if (es->df_pref == tmp_pref) + if (es->df_pref == zif->es_info.df_pref) return; - es->df_pref = tmp_pref; + es->df_pref = zif->es_info.df_pref; /* run df election */ zebra_evpn_es_run_df_election(es, __func__); /* notify bgp */ @@ -3330,7 +3325,7 @@ int zebra_evpn_mh_if_write(struct vty *vty, struct interface *ifp) vty_out(vty, " evpn mh es-id %s\n", esi_to_str(&zif->es_info.esi, esi_buf, sizeof(esi_buf))); - if (zif->es_info.df_pref) + if (zif->es_info.df_pref != EVPN_MH_DF_PREF_DEFAULT) vty_out(vty, " evpn mh es-df-pref %u\n", zif->es_info.df_pref); if (zif->flags & ZIF_FLAG_EVPN_MH_UPLINK) @@ -3339,6 +3334,11 @@ int zebra_evpn_mh_if_write(struct vty *vty, struct interface *ifp) return 0; } +void zebra_evpn_mh_if_init(struct zebra_if *zif) +{ + zif->es_info.df_pref = EVPN_MH_DF_PREF_DEFAULT; +} + #include "zebra/zebra_evpn_mh_clippy.c" /* CLI for setting an ES in bypass mode */ DEFPY_HIDDEN(zebra_evpn_es_bypass, zebra_evpn_es_bypass_cmd, @@ -3364,28 +3364,24 @@ DEFPY_HIDDEN(zebra_evpn_es_bypass, zebra_evpn_es_bypass_cmd, } /* CLI for configuring DF preference part for an ES */ -DEFPY(zebra_evpn_es_pref, zebra_evpn_es_pref_cmd, - "[no$no] evpn mh es-df-pref [(1-65535)$df_pref]", - NO_STR "EVPN\n" EVPN_MH_VTY_STR - "preference value used for DF election\n" - "pref\n") +DEFPY_YANG (zebra_evpn_es_pref, + zebra_evpn_es_pref_cmd, + "[no$no] evpn mh es-df-pref ![(1-65535)$df_pref]", + NO_STR + "EVPN\n" + EVPN_MH_VTY_STR + "Preference value used for DF election\n" + "Preference\n") { - VTY_DECLVAR_CONTEXT(interface, ifp); - struct zebra_if *zif; - - zif = ifp->info; - - if (no) { - zebra_evpn_es_df_pref_update(zif, 0); - } else { - if (!zebra_evpn_is_if_es_capable(zif)) { - vty_out(vty, - "%% DF preference cannot be associated with this interface type\n"); - return CMD_WARNING; - } - zebra_evpn_es_df_pref_update(zif, df_pref); - } - return CMD_SUCCESS; + if (!no) + nb_cli_enqueue_change(vty, + "./frr-zebra:zebra/evpn-mh/df-preference", + NB_OP_MODIFY, df_pref_str); + else + nb_cli_enqueue_change(vty, + "./frr-zebra:zebra/evpn-mh/df-preference", + NB_OP_DESTROY, NULL); + return nb_cli_apply_changes(vty, NULL); } /* CLI for setting up sysmac part of ESI on an access port */ diff --git a/zebra/zebra_evpn_mh.h b/zebra/zebra_evpn_mh.h index ebfe66f9d..81a773b87 100644 --- a/zebra/zebra_evpn_mh.h +++ b/zebra/zebra_evpn_mh.h @@ -388,4 +388,8 @@ void zebra_evpn_es_sys_mac_update(struct zebra_if *zif, struct ethaddr *sysmac); void zebra_evpn_es_lid_update(struct zebra_if *zif, uint32_t lid); void zebra_evpn_es_type0_esi_update(struct zebra_if *zif, esi_t *esi); +void zebra_evpn_es_df_pref_update(struct zebra_if *zif, uint16_t df_pref); + +void zebra_evpn_mh_if_init(struct zebra_if *zif); + #endif /* _ZEBRA_EVPN_MH_H */ diff --git a/zebra/zebra_nb.c b/zebra/zebra_nb.c index d5f0450fb..d6a4a41e7 100644 --- a/zebra/zebra_nb.c +++ b/zebra/zebra_nb.c @@ -529,6 +529,12 @@ const struct frr_yang_module_info frr_zebra_info = { } }, { + .xpath = "/frr-interface:lib/interface/frr-zebra:zebra/evpn-mh/df-preference", + .cbs = { + .modify = lib_interface_zebra_evpn_mh_df_preference_modify, + } + }, + { .xpath = "/frr-interface:lib/interface/frr-zebra:zebra/state/up-count", .cbs = { .get_elem = lib_interface_zebra_state_up_count_get_elem, diff --git a/zebra/zebra_nb.h b/zebra/zebra_nb.h index 6494cec9e..93df1a83e 100644 --- a/zebra/zebra_nb.h +++ b/zebra/zebra_nb.h @@ -177,6 +177,8 @@ int lib_interface_zebra_evpn_mh_type_3_local_discriminator_modify( struct nb_cb_modify_args *args); int lib_interface_zebra_evpn_mh_type_3_local_discriminator_destroy( struct nb_cb_destroy_args *args); +int lib_interface_zebra_evpn_mh_df_preference_modify( + struct nb_cb_modify_args *args); struct yang_data * lib_interface_zebra_state_up_count_get_elem(struct nb_cb_get_elem_args *args); struct yang_data * diff --git a/zebra/zebra_nb_config.c b/zebra/zebra_nb_config.c index 535b60f7f..e6eeb60b2 100644 --- a/zebra/zebra_nb_config.c +++ b/zebra/zebra_nb_config.c @@ -2401,6 +2401,25 @@ int lib_interface_zebra_evpn_mh_type_3_local_discriminator_destroy( } /* + * XPath: /frr-interface:lib/interface/frr-zebra:zebra/evpn-mh/df-preference + */ +int lib_interface_zebra_evpn_mh_df_preference_modify( + struct nb_cb_modify_args *args) +{ + struct interface *ifp; + uint16_t df_pref; + + if (args->event != NB_EV_APPLY) + return NB_OK; + + ifp = nb_running_get_entry(args->dnode, NULL, true); + df_pref = yang_dnode_get_uint16(args->dnode, NULL); + zebra_evpn_es_df_pref_update(ifp->info, df_pref); + + return NB_OK; +} + +/* * XPath: /frr-vrf:lib/vrf/frr-zebra:zebra/l3vni-id */ int lib_vrf_zebra_l3vni_id_modify(struct nb_cb_modify_args *args) |