]> git.puffer.fish Git - mirror/frr.git/commitdiff
zebra: convert interface link-params neighbor command to NB
authorIgor Ryzhov <iryzhov@nfware.com>
Fri, 19 Jan 2024 23:02:37 +0000 (01:02 +0200)
committerIgor Ryzhov <iryzhov@nfware.com>
Sun, 28 Jan 2024 21:28:39 +0000 (23:28 +0200)
Signed-off-by: Igor Ryzhov <iryzhov@nfware.com>
yang/frr-zebra.yang
zebra/interface.c
zebra/zebra_nb.c
zebra/zebra_nb.h
zebra/zebra_nb_config.c

index 8e22c334e72c63643584901fd70328808c9f95a0..4593aeeeece9965a8ce42abc90b574ca9406deb3 100644 (file)
@@ -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)
       }
index b47ca6a5ca661269881e4946f73fa4b729eb4b20..005bb53ee5ab808bc07a6b2490447b2893604467 100644 (file)
@@ -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);
index 314c142d4e2f0608d7ef24029ff5791aed130663..8119dea89190ec7a67ebbb75c55f3169552000df 100644 (file)
@@ -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 = {
index 52e2590d027c43ba64bcd181e068e1fe02dc02b3..85dfca1c82c3efe8af922505e929d69e47226a74 100644 (file)
@@ -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 *
index c155ae6a2e1a92f774062f5b1d21677061a71b1c..6a4e2784341f1ad607208f2aae2ea01d3d219966 100644 (file)
@@ -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
  */