From: Igor Ryzhov Date: Fri, 19 Jan 2024 23:02:37 +0000 (+0200) Subject: zebra: convert interface link-params neighbor command to NB X-Git-Tag: base_10.0~66^2~43 X-Git-Url: https://git.puffer.fish/?a=commitdiff_plain;h=217b65e5bf75f46534af49e0d4034cac9be28923;p=matthieu%2Ffrr.git zebra: convert interface link-params neighbor command to NB Signed-off-by: Igor Ryzhov --- diff --git a/yang/frr-zebra.yang b/yang/frr-zebra.yang index 8e22c334e7..4593aeeeec 100644 --- a/yang/frr-zebra.yang +++ b/yang/frr-zebra.yang @@ -2149,6 +2149,22 @@ module frr-zebra { } } } + container neighbor { + description "Remote ASBR information (RFC 5316 & RFC 5392)"; + presence "Activates neighbor information on this interface."; + leaf remote-as { + type inet:as-number; + mandatory true; + description + "Remote AS Number (RFC 5316 & RFC 5392)"; + } + leaf ipv4-remote-id { + type inet:ipv4-address; + mandatory true; + description + "IPv4 Remote ASBR ID (RFC 5316 & RFC 5392)"; + } + } // TODO -- other link-params options // for (experimental/partial TE use in IGP extensions) } diff --git a/zebra/interface.c b/zebra/interface.c index b47ca6a5ca..005bb53ee5 100644 --- a/zebra/interface.c +++ b/zebra/interface.c @@ -4131,70 +4131,26 @@ DEFPY_YANG(no_link_params_admin_grp, no_link_params_admin_grp_cmd, } /* RFC5392 & RFC5316: INTER-AS */ -DEFUN (link_params_inter_as, +DEFPY_YANG (link_params_inter_as, link_params_inter_as_cmd, - "neighbor A.B.C.D as (1-4294967295)", + "[no] neighbor ![A.B.C.D$ip as (1-4294967295)$as]", + NO_STR "Configure remote ASBR information (Neighbor IP address and AS number)\n" "Remote IP address in dot decimal A.B.C.D\n" "Remote AS number\n" "AS number in the range <1-4294967295>\n") { - int idx_ipv4 = 1; - int idx_number = 3; - - VTY_DECLVAR_CONTEXT(interface, ifp); - struct if_link_params *iflp = if_link_params_get(ifp); - struct in_addr addr; - uint32_t as; - - if (!inet_aton(argv[idx_ipv4]->arg, &addr)) { - vty_out(vty, "Please specify Router-Addr by A.B.C.D\n"); - return CMD_WARNING_CONFIG_FAILED; - } - - if (!iflp) - iflp = if_link_params_enable(ifp); - - as = strtoul(argv[idx_number]->arg, NULL, 10); - - /* Update Remote IP and Remote AS fields if needed */ - if (IS_PARAM_UNSET(iflp, LP_RMT_AS) || iflp->rmt_as != as - || iflp->rmt_ip.s_addr != addr.s_addr) { - - iflp->rmt_as = as; - iflp->rmt_ip.s_addr = addr.s_addr; - SET_PARAM(iflp, LP_RMT_AS); - - /* force protocols to update LINK STATE due to parameters change - */ - if (if_is_operative(ifp)) - zebra_interface_parameters_update(ifp); + if (!no) { + nb_cli_enqueue_change(vty, "./neighbor", NB_OP_CREATE, NULL); + nb_cli_enqueue_change(vty, "./neighbor/remote-as", NB_OP_MODIFY, + as_str); + nb_cli_enqueue_change(vty, "./neighbor/ipv4-remote-id", + NB_OP_MODIFY, ip_str); + } else { + nb_cli_enqueue_change(vty, "./neighbor", NB_OP_DESTROY, NULL); } - return CMD_SUCCESS; -} - -DEFUN (no_link_params_inter_as, - no_link_params_inter_as_cmd, - "no neighbor", - NO_STR - "Remove Neighbor IP address and AS number for Inter-AS TE\n") -{ - VTY_DECLVAR_CONTEXT(interface, ifp); - struct if_link_params *iflp = if_link_params_get(ifp); - - if (!iflp) - return CMD_SUCCESS; - - /* Reset Remote IP and AS neighbor */ - iflp->rmt_as = 0; - iflp->rmt_ip.s_addr = 0; - UNSET_PARAM(iflp, LP_RMT_AS); - /* force protocols to update LINK STATE due to parameters change */ - if (if_is_operative(ifp)) - zebra_interface_parameters_update(ifp); - - return CMD_SUCCESS; + return nb_cli_apply_changes(vty, NULL); } /* RFC7471: OSPF Traffic Engineering (TE) Metric extensions & @@ -5044,7 +5000,6 @@ void zebra_if_init(void) install_element(LINK_PARAMS_NODE, &link_params_admin_grp_cmd); install_element(LINK_PARAMS_NODE, &no_link_params_admin_grp_cmd); install_element(LINK_PARAMS_NODE, &link_params_inter_as_cmd); - install_element(LINK_PARAMS_NODE, &no_link_params_inter_as_cmd); install_element(LINK_PARAMS_NODE, &link_params_delay_cmd); install_element(LINK_PARAMS_NODE, &no_link_params_delay_cmd); install_element(LINK_PARAMS_NODE, &link_params_delay_var_cmd); diff --git a/zebra/zebra_nb.c b/zebra/zebra_nb.c index 314c142d4e..8119dea891 100644 --- a/zebra/zebra_nb.c +++ b/zebra/zebra_nb.c @@ -448,6 +448,25 @@ const struct frr_yang_module_info frr_zebra_info = { .cli_show = cli_show_affinity_mode, }, }, + { + .xpath = "/frr-interface:lib/interface/frr-zebra:zebra/link-params/neighbor", + .cbs = { + .create = lib_interface_zebra_link_params_neighbor_create, + .destroy = lib_interface_zebra_link_params_neighbor_destroy, + } + }, + { + .xpath = "/frr-interface:lib/interface/frr-zebra:zebra/link-params/neighbor/remote-as", + .cbs = { + .modify = lib_interface_zebra_link_params_neighbor_remote_as_modify, + } + }, + { + .xpath = "/frr-interface:lib/interface/frr-zebra:zebra/link-params/neighbor/ipv4-remote-id", + .cbs = { + .modify = lib_interface_zebra_link_params_neighbor_ipv4_remote_id_modify, + } + }, { .xpath = "/frr-interface:lib/interface/frr-zebra:zebra/state/up-count", .cbs = { diff --git a/zebra/zebra_nb.h b/zebra/zebra_nb.h index 52e2590d02..85dfca1c82 100644 --- a/zebra/zebra_nb.h +++ b/zebra/zebra_nb.h @@ -139,6 +139,14 @@ int lib_interface_zebra_legacy_admin_group_destroy( int lib_interface_zebra_affinity_create(struct nb_cb_create_args *args); int lib_interface_zebra_affinity_destroy(struct nb_cb_destroy_args *args); int lib_interface_zebra_affinity_mode_modify(struct nb_cb_modify_args *args); +int lib_interface_zebra_link_params_neighbor_create( + struct nb_cb_create_args *args); +int lib_interface_zebra_link_params_neighbor_destroy( + struct nb_cb_destroy_args *args); +int lib_interface_zebra_link_params_neighbor_remote_as_modify( + struct nb_cb_modify_args *args); +int lib_interface_zebra_link_params_neighbor_ipv4_remote_id_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 c155ae6a2e..6a4e278434 100644 --- a/zebra/zebra_nb_config.c +++ b/zebra/zebra_nb_config.c @@ -1876,6 +1876,109 @@ int lib_interface_zebra_affinity_mode_modify(struct nb_cb_modify_args *args) return NB_OK; } +/* + * XPath: /frr-interface:lib/interface/frr-zebra:zebra/link-params/neighbor + */ +int lib_interface_zebra_link_params_neighbor_create(struct nb_cb_create_args *args) +{ + struct interface *ifp; + struct if_link_params *iflp; + struct in_addr ip; + uint32_t as; + + if (args->event != NB_EV_APPLY) + return NB_OK; + + as = yang_dnode_get_uint32(args->dnode, "remote-as"); + yang_dnode_get_ipv4(&ip, args->dnode, "ipv4-remote-id"); + + ifp = nb_running_get_entry(args->dnode, NULL, true); + iflp = if_link_params_get(ifp); + + iflp->rmt_as = as; + iflp->rmt_ip = ip; + SET_PARAM(iflp, LP_RMT_AS); + + if (if_is_operative(ifp)) + zebra_interface_parameters_update(ifp); + + return NB_OK; +} + +int lib_interface_zebra_link_params_neighbor_destroy( + struct nb_cb_destroy_args *args) +{ + struct interface *ifp; + struct if_link_params *iflp; + + if (args->event != NB_EV_APPLY) + return NB_OK; + + ifp = nb_running_get_entry(args->dnode, NULL, true); + iflp = if_link_params_get(ifp); + + iflp->rmt_as = 0; + iflp->rmt_ip.s_addr = 0; + UNSET_PARAM(iflp, LP_RMT_AS); + + if (if_is_operative(ifp)) + zebra_interface_parameters_update(ifp); + + return NB_OK; +} + +/* + * XPath: /frr-interface:lib/interface/frr-zebra:zebra/link-params/neighbor/remote-as + */ +int lib_interface_zebra_link_params_neighbor_remote_as_modify( + struct nb_cb_modify_args *args) +{ + struct interface *ifp; + struct if_link_params *iflp; + uint32_t as; + + if (args->event != NB_EV_APPLY) + return NB_OK; + + as = yang_dnode_get_uint32(args->dnode, NULL); + + ifp = nb_running_get_entry(args->dnode, NULL, true); + iflp = if_link_params_get(ifp); + + iflp->rmt_as = as; + + if (if_is_operative(ifp)) + zebra_interface_parameters_update(ifp); + + return NB_OK; +} + +/* + * XPath: /frr-interface:lib/interface/frr-zebra:zebra/link-params/neighbor/ipv4-remote-id + */ +int lib_interface_zebra_link_params_neighbor_ipv4_remote_id_modify( + struct nb_cb_modify_args *args) +{ + struct interface *ifp; + struct if_link_params *iflp; + struct in_addr ip; + + if (args->event != NB_EV_APPLY) + return NB_OK; + + yang_dnode_get_ipv4(&ip, args->dnode, NULL); + + ifp = nb_running_get_entry(args->dnode, NULL, true); + iflp = if_link_params_get(ifp); + + iflp->rmt_ip = ip; + + if (if_is_operative(ifp)) + zebra_interface_parameters_update(ifp); + + return NB_OK; +} + /* * XPath: /frr-vrf:lib/vrf/frr-zebra:zebra/l3vni-id */