From 14d91bb3be84d8a30da72f1b94b885b271396a80 Mon Sep 17 00:00:00 2001 From: Igor Ryzhov Date: Fri, 14 May 2021 02:11:43 +0300 Subject: [PATCH] Revert "bgpd: convert addr-family clis to transactional clis" This reverts commit 37a87b8f9865fe17a235b9a76a0dc47f03aae3df. Signed-off-by: Igor Ryzhov --- bgpd/bgp_nb.c | 137 ---- bgpd/bgp_nb.h | 61 -- bgpd/bgp_nb_config.c | 1648 +++++++----------------------------------- bgpd/bgp_route.c | 965 +++++++++++-------------- bgpd/bgp_route.h | 27 - bgpd/bgp_vty.c | 1628 +++++++++++++++++++---------------------- bgpd/bgp_vty.h | 9 +- 7 files changed, 1453 insertions(+), 3022 deletions(-) diff --git a/bgpd/bgp_nb.c b/bgpd/bgp_nb.c index 5991ba4283..c4623e5284 100644 --- a/bgpd/bgp_nb.c +++ b/bgpd/bgp_nb.c @@ -467,8 +467,6 @@ const struct frr_yang_module_info frr_bgp_info = { .cbs = { .create = bgp_global_afi_safis_afi_safi_create, .destroy = bgp_global_afi_safis_afi_safi_destroy, - .cli_show = cli_show_bgp_global_afi_safi_header, - .cli_show_end = cli_show_bgp_global_afi_safi_header_end, } }, { @@ -1287,10 +1285,8 @@ const struct frr_yang_module_info frr_bgp_info = { { .xpath = "/frr-routing:routing/control-plane-protocols/control-plane-protocol/frr-bgp:bgp/global/afi-safis/afi-safi/ipv4-unicast/network-config", .cbs = { - .apply_finish = bgp_global_afi_safis_afi_safi_network_config_apply_finish, .create = bgp_global_afi_safis_afi_safi_ipv4_unicast_network_config_create, .destroy = bgp_global_afi_safis_afi_safi_ipv4_unicast_network_config_destroy, - .cli_show = cli_show_bgp_global_afi_safi_network_config, } }, { @@ -1316,10 +1312,8 @@ const struct frr_yang_module_info frr_bgp_info = { { .xpath = "/frr-routing:routing/control-plane-protocols/control-plane-protocol/frr-bgp:bgp/global/afi-safis/afi-safi/ipv4-unicast/aggregate-route", .cbs = { - .apply_finish = bgp_global_afi_safi_aggregate_route_apply_finish, .create = bgp_global_afi_safis_afi_safi_ipv4_unicast_aggregate_route_create, .destroy = bgp_global_afi_safis_afi_safi_ipv4_unicast_aggregate_route_destroy, - .cli_show = cli_show_bgp_global_afi_safi_unicast_aggregate_route, } }, { @@ -1350,10 +1344,8 @@ const struct frr_yang_module_info frr_bgp_info = { { .xpath = "/frr-routing:routing/control-plane-protocols/control-plane-protocol/frr-bgp:bgp/global/afi-safis/afi-safi/ipv4-unicast/admin-distance-route", .cbs = { - .apply_finish = bgp_global_afi_safi_admin_distance_route_apply_finish, .create = bgp_global_afi_safis_afi_safi_ipv4_unicast_admin_distance_route_create, .destroy = bgp_global_afi_safis_afi_safi_ipv4_unicast_admin_distance_route_destroy, - .cli_show = cli_show_bgp_global_afi_safi_unicast_admin_distance_route, } }, { @@ -1369,13 +1361,6 @@ const struct frr_yang_module_info frr_bgp_info = { .destroy = bgp_global_afi_safis_afi_safi_ipv4_unicast_admin_distance_route_access_list_policy_export_destroy, } }, - { - .xpath = "/frr-routing:routing/control-plane-protocols/control-plane-protocol/frr-bgp:bgp/global/afi-safis/afi-safi/ipv4-unicast/route-flap-dampening", - .cbs = { - .apply_finish = bgp_global_afi_safis_afi_safi_route_flap_dampening_apply_finish, - .cli_show = cli_show_bgp_global_afi_safi_route_flap_dampening, - } - }, { .xpath = "/frr-routing:routing/control-plane-protocols/control-plane-protocol/frr-bgp:bgp/global/afi-safis/afi-safi/ipv4-unicast/route-flap-dampening/enable", .cbs = { @@ -1414,14 +1399,6 @@ const struct frr_yang_module_info frr_bgp_info = { .xpath = "/frr-routing:routing/control-plane-protocols/control-plane-protocol/frr-bgp:bgp/global/afi-safis/afi-safi/ipv4-unicast/use-multiple-paths/ebgp/maximum-paths", .cbs = { .modify = bgp_global_afi_safis_afi_safi_ipv4_unicast_use_multiple_paths_ebgp_maximum_paths_modify, - .cli_show = cli_show_bgp_global_afi_safi_unicast_use_multiple_paths_ebgp_maximum_paths, - } - }, - { - .xpath = "/frr-routing:routing/control-plane-protocols/control-plane-protocol/frr-bgp:bgp/global/afi-safis/afi-safi/ipv4-unicast/use-multiple-paths/ibgp", - .cbs = { - .apply_finish = bgp_global_afi_safi_ip_unicast_use_multiple_paths_ibgp_maximum_paths_apply_finish, - .cli_show = cli_show_bgp_global_afi_safi_ip_unicast_use_multiple_paths_ibgp_maximum_paths, } }, { @@ -1440,10 +1417,8 @@ const struct frr_yang_module_info frr_bgp_info = { { .xpath = "/frr-routing:routing/control-plane-protocols/control-plane-protocol/frr-bgp:bgp/global/afi-safis/afi-safi/ipv4-unicast/redistribution-list", .cbs = { - .apply_finish = bgp_global_afi_safi_ip_unicast_redistribution_list_apply_finish, .create = bgp_global_afi_safis_afi_safi_ipv4_unicast_redistribution_list_create, .destroy = bgp_global_afi_safis_afi_safi_ipv4_unicast_redistribution_list_destroy, - .cli_show = cli_show_bgp_global_afi_safi_ip_unicast_redistribution_list, } }, { @@ -1460,13 +1435,6 @@ const struct frr_yang_module_info frr_bgp_info = { .destroy = bgp_global_afi_safis_afi_safi_ipv4_unicast_redistribution_list_rmap_policy_import_destroy, } }, - { - .xpath = "/frr-routing:routing/control-plane-protocols/control-plane-protocol/frr-bgp:bgp/global/afi-safis/afi-safi/ipv4-unicast/admin-distance", - .cbs = { - .apply_finish = bgp_global_afi_safis_afi_safi_ipv4_unicast_admin_distance_apply_finish, - .cli_show = cli_show_bgp_global_afi_safi_admin_distance_config, - } - }, { .xpath = "/frr-routing:routing/control-plane-protocols/control-plane-protocol/frr-bgp:bgp/global/afi-safis/afi-safi/ipv4-unicast/admin-distance/external", .cbs = { @@ -1497,7 +1465,6 @@ const struct frr_yang_module_info frr_bgp_info = { .cbs = { .modify = bgp_global_afi_safis_afi_safi_ipv4_unicast_vpn_config_rd_modify, .destroy = bgp_global_afi_safis_afi_safi_ipv4_unicast_vpn_config_rd_destroy, - .cli_show = cli_show_bgp_global_afi_safi_ip_unicast_vpn_config_rd, } }, { @@ -1519,21 +1486,18 @@ const struct frr_yang_module_info frr_bgp_info = { .cbs = { .modify = bgp_global_afi_safis_afi_safi_ipv4_unicast_vpn_config_nexthop_modify, .destroy = bgp_global_afi_safis_afi_safi_ipv4_unicast_vpn_config_nexthop_destroy, - .cli_show = cli_show_bgp_global_afi_safi_ip_unicast_vpn_config_nexthop, } }, { .xpath = "/frr-routing:routing/control-plane-protocols/control-plane-protocol/frr-bgp:bgp/global/afi-safis/afi-safi/ipv4-unicast/vpn-config/import-vpn", .cbs = { .modify = bgp_global_afi_safis_afi_safi_ipv4_unicast_vpn_config_import_vpn_modify, - .cli_show = cli_show_bgp_global_afi_safi_ip_unicast_vpn_config_import_vpn, } }, { .xpath = "/frr-routing:routing/control-plane-protocols/control-plane-protocol/frr-bgp:bgp/global/afi-safis/afi-safi/ipv4-unicast/vpn-config/export-vpn", .cbs = { .modify = bgp_global_afi_safis_afi_safi_ipv4_unicast_vpn_config_export_vpn_modify, - .cli_show = cli_show_bgp_global_afi_safi_ip_unicast_vpn_config_export_vpn, } }, { @@ -1541,7 +1505,6 @@ const struct frr_yang_module_info frr_bgp_info = { .cbs = { .create = bgp_global_afi_safis_afi_safi_ipv4_unicast_vpn_config_import_vrf_list_create, .destroy = bgp_global_afi_safis_afi_safi_ipv4_unicast_vpn_config_import_vrf_list_destroy, - .cli_show = cli_show_bgp_global_afi_safi_ip_unicast_vpn_config_import_vrfs, } }, { @@ -1549,7 +1512,6 @@ const struct frr_yang_module_info frr_bgp_info = { .cbs = { .modify = bgp_global_afi_safis_afi_safi_ipv4_unicast_vpn_config_rmap_import_modify, .destroy = bgp_global_afi_safis_afi_safi_ipv4_unicast_vpn_config_rmap_import_destroy, - .cli_show = cli_show_bgp_global_afi_safi_ip_unicast_vpn_config_rmap_import, } }, { @@ -1557,7 +1519,6 @@ const struct frr_yang_module_info frr_bgp_info = { .cbs = { .modify = bgp_global_afi_safis_afi_safi_ipv4_unicast_vpn_config_rmap_export_modify, .destroy = bgp_global_afi_safis_afi_safi_ipv4_unicast_vpn_config_rmap_export_destroy, - .cli_show = cli_show_bgp_global_afi_safi_ip_unicast_vpn_config_rmap_export, } }, { @@ -1591,10 +1552,8 @@ const struct frr_yang_module_info frr_bgp_info = { { .xpath = "/frr-routing:routing/control-plane-protocols/control-plane-protocol/frr-bgp:bgp/global/afi-safis/afi-safi/ipv6-unicast/network-config", .cbs = { - .apply_finish = bgp_global_afi_safis_afi_safi_network_config_apply_finish, .create = bgp_global_afi_safis_afi_safi_ipv6_unicast_network_config_create, .destroy = bgp_global_afi_safis_afi_safi_ipv6_unicast_network_config_destroy, - .cli_show = cli_show_bgp_global_afi_safi_network_config, } }, { @@ -1620,10 +1579,8 @@ const struct frr_yang_module_info frr_bgp_info = { { .xpath = "/frr-routing:routing/control-plane-protocols/control-plane-protocol/frr-bgp:bgp/global/afi-safis/afi-safi/ipv6-unicast/aggregate-route", .cbs = { - .apply_finish = bgp_global_afi_safi_aggregate_route_apply_finish, .create = bgp_global_afi_safis_afi_safi_ipv6_unicast_aggregate_route_create, .destroy = bgp_global_afi_safis_afi_safi_ipv6_unicast_aggregate_route_destroy, - .cli_show = cli_show_bgp_global_afi_safi_unicast_aggregate_route, } }, { @@ -1654,10 +1611,8 @@ const struct frr_yang_module_info frr_bgp_info = { { .xpath = "/frr-routing:routing/control-plane-protocols/control-plane-protocol/frr-bgp:bgp/global/afi-safis/afi-safi/ipv6-unicast/admin-distance-route", .cbs = { - .apply_finish = bgp_global_afi_safi_admin_distance_route_apply_finish, .create = bgp_global_afi_safis_afi_safi_ipv6_unicast_admin_distance_route_create, .destroy = bgp_global_afi_safis_afi_safi_ipv6_unicast_admin_distance_route_destroy, - .cli_show = cli_show_bgp_global_afi_safi_unicast_admin_distance_route, } }, { @@ -1673,13 +1628,6 @@ const struct frr_yang_module_info frr_bgp_info = { .destroy = bgp_global_afi_safis_afi_safi_ipv6_unicast_admin_distance_route_access_list_policy_export_destroy, } }, - { - .xpath = "/frr-routing:routing/control-plane-protocols/control-plane-protocol/frr-bgp:bgp/global/afi-safis/afi-safi/ipv6-unicast/route-flap-dampening", - .cbs = { - .apply_finish = bgp_global_afi_safis_afi_safi_route_flap_dampening_apply_finish, - .cli_show = cli_show_bgp_global_afi_safi_route_flap_dampening, - } - }, { .xpath = "/frr-routing:routing/control-plane-protocols/control-plane-protocol/frr-bgp:bgp/global/afi-safis/afi-safi/ipv6-unicast/route-flap-dampening/enable", .cbs = { @@ -1718,14 +1666,6 @@ const struct frr_yang_module_info frr_bgp_info = { .xpath = "/frr-routing:routing/control-plane-protocols/control-plane-protocol/frr-bgp:bgp/global/afi-safis/afi-safi/ipv6-unicast/use-multiple-paths/ebgp/maximum-paths", .cbs = { .modify = bgp_global_afi_safis_afi_safi_ipv6_unicast_use_multiple_paths_ebgp_maximum_paths_modify, - .cli_show = cli_show_bgp_global_afi_safi_unicast_use_multiple_paths_ebgp_maximum_paths, - } - }, - { - .xpath = "/frr-routing:routing/control-plane-protocols/control-plane-protocol/frr-bgp:bgp/global/afi-safis/afi-safi/ipv6-unicast/use-multiple-paths/ibgp", - .cbs = { - .apply_finish = bgp_global_afi_safi_ip_unicast_use_multiple_paths_ibgp_maximum_paths_apply_finish, - .cli_show = cli_show_bgp_global_afi_safi_ip_unicast_use_multiple_paths_ibgp_maximum_paths, } }, { @@ -1744,10 +1684,8 @@ const struct frr_yang_module_info frr_bgp_info = { { .xpath = "/frr-routing:routing/control-plane-protocols/control-plane-protocol/frr-bgp:bgp/global/afi-safis/afi-safi/ipv6-unicast/redistribution-list", .cbs = { - .apply_finish = bgp_global_afi_safi_ip_unicast_redistribution_list_apply_finish, .create = bgp_global_afi_safis_afi_safi_ipv6_unicast_redistribution_list_create, .destroy = bgp_global_afi_safis_afi_safi_ipv6_unicast_redistribution_list_destroy, - .cli_show = cli_show_bgp_global_afi_safi_ip_unicast_redistribution_list, } }, { @@ -1764,13 +1702,6 @@ const struct frr_yang_module_info frr_bgp_info = { .destroy = bgp_global_afi_safis_afi_safi_ipv6_unicast_redistribution_list_rmap_policy_import_destroy, } }, - { - .xpath = "/frr-routing:routing/control-plane-protocols/control-plane-protocol/frr-bgp:bgp/global/afi-safis/afi-safi/ipv6-unicast/admin-distance", - .cbs = { - .apply_finish = bgp_global_afi_safis_afi_safi_ipv6_unicast_admin_distance_apply_finish, - .cli_show = cli_show_bgp_global_afi_safi_admin_distance_config, - } - }, { .xpath = "/frr-routing:routing/control-plane-protocols/control-plane-protocol/frr-bgp:bgp/global/afi-safis/afi-safi/ipv6-unicast/admin-distance/external", .cbs = { @@ -1848,7 +1779,6 @@ const struct frr_yang_module_info frr_bgp_info = { .cbs = { .modify = bgp_global_afi_safis_afi_safi_ipv6_unicast_vpn_config_rmap_import_modify, .destroy = bgp_global_afi_safis_afi_safi_ipv6_unicast_vpn_config_rmap_import_destroy, - .cli_show = cli_show_bgp_global_afi_safi_ip_unicast_vpn_config_rmap_import, } }, { @@ -1856,7 +1786,6 @@ const struct frr_yang_module_info frr_bgp_info = { .cbs = { .modify = bgp_global_afi_safis_afi_safi_ipv6_unicast_vpn_config_rmap_export_modify, .destroy = bgp_global_afi_safis_afi_safi_ipv6_unicast_vpn_config_rmap_export_destroy, - .cli_show = cli_show_bgp_global_afi_safi_ip_unicast_vpn_config_rmap_export, } }, { @@ -1891,14 +1820,6 @@ const struct frr_yang_module_info frr_bgp_info = { .xpath = "/frr-routing:routing/control-plane-protocols/control-plane-protocol/frr-bgp:bgp/global/afi-safis/afi-safi/ipv4-labeled-unicast/use-multiple-paths/ebgp/maximum-paths", .cbs = { .modify = bgp_global_afi_safis_afi_safi_ipv4_labeled_unicast_use_multiple_paths_ebgp_maximum_paths_modify, - .cli_show = cli_show_bgp_global_afi_safi_unicast_use_multiple_paths_ebgp_maximum_paths, - } - }, - { - .xpath = "/frr-routing:routing/control-plane-protocols/control-plane-protocol/frr-bgp:bgp/global/afi-safis/afi-safi/ipv4-labeled-unicast/use-multiple-paths/ibgp", - .cbs = { - .apply_finish = bgp_global_afi_safi_ip_unicast_use_multiple_paths_ibgp_maximum_paths_apply_finish, - .cli_show = cli_show_bgp_global_afi_safi_ip_unicast_use_multiple_paths_ibgp_maximum_paths, } }, { @@ -1914,13 +1835,6 @@ const struct frr_yang_module_info frr_bgp_info = { .destroy = bgp_global_afi_safis_afi_safi_ipv4_labeled_unicast_use_multiple_paths_ibgp_cluster_length_list_destroy, } }, - { - .xpath = "/frr-routing:routing/control-plane-protocols/control-plane-protocol/frr-bgp:bgp/global/afi-safis/afi-safi/ipv4-labeled-unicast/route-flap-dampening", - .cbs = { - .apply_finish = bgp_global_afi_safis_afi_safi_route_flap_dampening_apply_finish, - .cli_show = cli_show_bgp_global_afi_safi_route_flap_dampening, - } - }, { .xpath = "/frr-routing:routing/control-plane-protocols/control-plane-protocol/frr-bgp:bgp/global/afi-safis/afi-safi/ipv4-labeled-unicast/route-flap-dampening/enable", .cbs = { @@ -1959,14 +1873,6 @@ const struct frr_yang_module_info frr_bgp_info = { .xpath = "/frr-routing:routing/control-plane-protocols/control-plane-protocol/frr-bgp:bgp/global/afi-safis/afi-safi/ipv6-labeled-unicast/use-multiple-paths/ebgp/maximum-paths", .cbs = { .modify = bgp_global_afi_safis_afi_safi_ipv6_labeled_unicast_use_multiple_paths_ebgp_maximum_paths_modify, - .cli_show = cli_show_bgp_global_afi_safi_unicast_use_multiple_paths_ebgp_maximum_paths, - } - }, - { - .xpath = "/frr-routing:routing/control-plane-protocols/control-plane-protocol/frr-bgp:bgp/global/afi-safis/afi-safi/ipv6-labeled-unicast/use-multiple-paths/ibgp", - .cbs = { - .apply_finish = bgp_global_afi_safi_ip_unicast_use_multiple_paths_ibgp_maximum_paths_apply_finish, - .cli_show = cli_show_bgp_global_afi_safi_ip_unicast_use_multiple_paths_ibgp_maximum_paths, } }, { @@ -1982,13 +1888,6 @@ const struct frr_yang_module_info frr_bgp_info = { .destroy = bgp_global_afi_safis_afi_safi_ipv6_labeled_unicast_use_multiple_paths_ibgp_cluster_length_list_destroy, } }, - { - .xpath = "/frr-routing:routing/control-plane-protocols/control-plane-protocol/frr-bgp:bgp/global/afi-safis/afi-safi/ipv6-labeled-unicast/route-flap-dampening", - .cbs = { - .apply_finish = bgp_global_afi_safis_afi_safi_route_flap_dampening_apply_finish, - .cli_show = cli_show_bgp_global_afi_safi_route_flap_dampening, - } - }, { .xpath = "/frr-routing:routing/control-plane-protocols/control-plane-protocol/frr-bgp:bgp/global/afi-safis/afi-safi/ipv6-labeled-unicast/route-flap-dampening/enable", .cbs = { @@ -2026,10 +1925,8 @@ const struct frr_yang_module_info frr_bgp_info = { { .xpath = "/frr-routing:routing/control-plane-protocols/control-plane-protocol/frr-bgp:bgp/global/afi-safis/afi-safi/ipv4-multicast/network-config", .cbs = { - .apply_finish = bgp_global_afi_safis_afi_safi_network_config_apply_finish, .create = bgp_global_afi_safis_afi_safi_ipv4_multicast_network_config_create, .destroy = bgp_global_afi_safis_afi_safi_ipv4_multicast_network_config_destroy, - .cli_show = cli_show_bgp_global_afi_safi_network_config, } }, { @@ -2087,10 +1984,8 @@ const struct frr_yang_module_info frr_bgp_info = { { .xpath = "/frr-routing:routing/control-plane-protocols/control-plane-protocol/frr-bgp:bgp/global/afi-safis/afi-safi/ipv4-multicast/admin-distance-route", .cbs = { - .apply_finish = bgp_global_afi_safi_admin_distance_route_apply_finish, .create = bgp_global_afi_safis_afi_safi_ipv4_multicast_admin_distance_route_create, .destroy = bgp_global_afi_safis_afi_safi_ipv4_multicast_admin_distance_route_destroy, - .cli_show = cli_show_bgp_global_afi_safi_unicast_admin_distance_route, } }, { @@ -2106,12 +2001,6 @@ const struct frr_yang_module_info frr_bgp_info = { .destroy = bgp_global_afi_safis_afi_safi_ipv4_multicast_admin_distance_route_access_list_policy_export_destroy, } }, - { - .xpath = "/frr-routing:routing/control-plane-protocols/control-plane-protocol/frr-bgp:bgp/global/afi-safis/afi-safi/ipv4-multicast/admin-distance", - .cbs = { - .apply_finish = bgp_global_afi_safis_afi_safi_ipv4_multicast_admin_distance_apply_finish, - } - }, { .xpath = "/frr-routing:routing/control-plane-protocols/control-plane-protocol/frr-bgp:bgp/global/afi-safis/afi-safi/ipv4-multicast/admin-distance/external", .cbs = { @@ -2130,13 +2019,6 @@ const struct frr_yang_module_info frr_bgp_info = { .modify = bgp_global_afi_safis_afi_safi_ipv4_multicast_admin_distance_local_modify, } }, - { - .xpath = "/frr-routing:routing/control-plane-protocols/control-plane-protocol/frr-bgp:bgp/global/afi-safis/afi-safi/ipv4-multicast/route-flap-dampening", - .cbs = { - .apply_finish = bgp_global_afi_safis_afi_safi_route_flap_dampening_apply_finish, - .cli_show = cli_show_bgp_global_afi_safi_route_flap_dampening, - } - }, { .xpath = "/frr-routing:routing/control-plane-protocols/control-plane-protocol/frr-bgp:bgp/global/afi-safis/afi-safi/ipv4-multicast/route-flap-dampening/enable", .cbs = { @@ -2181,10 +2063,8 @@ const struct frr_yang_module_info frr_bgp_info = { { .xpath = "/frr-routing:routing/control-plane-protocols/control-plane-protocol/frr-bgp:bgp/global/afi-safis/afi-safi/ipv6-multicast/network-config", .cbs = { - .apply_finish = bgp_global_afi_safis_afi_safi_network_config_apply_finish, .create = bgp_global_afi_safis_afi_safi_ipv6_multicast_network_config_create, .destroy = bgp_global_afi_safis_afi_safi_ipv6_multicast_network_config_destroy, - .cli_show = cli_show_bgp_global_afi_safi_network_config, } }, { @@ -2242,10 +2122,8 @@ const struct frr_yang_module_info frr_bgp_info = { { .xpath = "/frr-routing:routing/control-plane-protocols/control-plane-protocol/frr-bgp:bgp/global/afi-safis/afi-safi/ipv6-multicast/admin-distance-route", .cbs = { - .apply_finish = bgp_global_afi_safi_admin_distance_route_apply_finish, .create = bgp_global_afi_safis_afi_safi_ipv6_multicast_admin_distance_route_create, .destroy = bgp_global_afi_safis_afi_safi_ipv6_multicast_admin_distance_route_destroy, - .cli_show = cli_show_bgp_global_afi_safi_unicast_admin_distance_route, } }, { @@ -2261,13 +2139,6 @@ const struct frr_yang_module_info frr_bgp_info = { .destroy = bgp_global_afi_safis_afi_safi_ipv6_multicast_admin_distance_route_access_list_policy_export_destroy, } }, - { - .xpath = "/frr-routing:routing/control-plane-protocols/control-plane-protocol/frr-bgp:bgp/global/afi-safis/afi-safi/ipv6-multicast/route-flap-dampening", - .cbs = { - .apply_finish = bgp_global_afi_safis_afi_safi_route_flap_dampening_apply_finish, - .cli_show = cli_show_bgp_global_afi_safi_route_flap_dampening, - } - }, { .xpath = "/frr-routing:routing/control-plane-protocols/control-plane-protocol/frr-bgp:bgp/global/afi-safis/afi-safi/ipv6-multicast/route-flap-dampening/enable", .cbs = { @@ -2302,12 +2173,6 @@ const struct frr_yang_module_info frr_bgp_info = { .destroy = bgp_global_afi_safis_afi_safi_ipv6_multicast_route_flap_dampening_unreach_decay_destroy, } }, - { - .xpath = "/frr-routing:routing/control-plane-protocols/control-plane-protocol/frr-bgp:bgp/global/afi-safis/afi-safi/ipv6-multicast/admin-distance", - .cbs = { - .apply_finish = bgp_global_afi_safis_afi_safi_ipv6_multicast_admin_distance_apply_finish, - } - }, { .xpath = "/frr-routing:routing/control-plane-protocols/control-plane-protocol/frr-bgp:bgp/global/afi-safis/afi-safi/ipv6-multicast/admin-distance/external", .cbs = { @@ -2336,10 +2201,8 @@ const struct frr_yang_module_info frr_bgp_info = { { .xpath = "/frr-routing:routing/control-plane-protocols/control-plane-protocol/frr-bgp:bgp/global/afi-safis/afi-safi/l3vpn-ipv4-unicast/network-config", .cbs = { - .apply_finish = bgp_global_afi_safis_afi_safi_network_config_apply_finish, .create = bgp_global_afi_safis_afi_safi_l3vpn_ipv4_unicast_network_config_create, .destroy = bgp_global_afi_safis_afi_safi_l3vpn_ipv4_unicast_network_config_destroy, - .cli_show = cli_show_bgp_global_afi_safi_network_config, } }, { diff --git a/bgpd/bgp_nb.h b/bgpd/bgp_nb.h index 6ae6be02e6..af6ed9cea9 100644 --- a/bgpd/bgp_nb.h +++ b/bgpd/bgp_nb.h @@ -3489,68 +3489,10 @@ void cli_show_router_bgp_graceful_shutdown(struct vty *vty, bool show_defaults); void cli_show_router_bgp_med_config(struct vty *vty, struct lyd_node *dnode, bool show_defaults); -void cli_show_bgp_global_afi_safi_header(struct vty *vty, - struct lyd_node *dnode, - bool show_defaults); -void cli_show_bgp_global_afi_safi_header_end(struct vty *vty, - struct lyd_node *dnode); -void cli_show_bgp_global_afi_safi_network_config(struct vty *vty, - struct lyd_node *dnode, - bool show_defaults); -void cli_show_bgp_global_afi_safi_unicast_aggregate_route( - struct vty *vty, struct lyd_node *dnode, bool show_defaults); -void cli_show_bgp_global_afi_safi_admin_distance_config(struct vty *vty, - struct lyd_node *dnode, - bool show_defaults); -void cli_show_bgp_global_afi_safi_route_flap_dampening(struct vty *vty, - struct lyd_node *dnode, - bool show_defaults); -void cli_show_bgp_global_afi_safi_unicast_admin_distance_route( - struct vty *vty, struct lyd_node *dnode, bool show_defaults); -void cli_show_bgp_global_afi_safi_unicast_use_multiple_paths_ebgp_maximum_paths( - struct vty *vty, struct lyd_node *dnode, bool show_defaults); -void cli_show_bgp_global_afi_safi_ip_unicast_use_multiple_paths_ibgp_maximum_paths( - struct vty *vty, struct lyd_node *dnode, bool show_defaults); -void cli_show_bgp_global_afi_safi_ip_unicast_redistribution_list( - struct vty *vty, struct lyd_node *dnode, bool show_defaults); -void cli_show_bgp_global_afi_safi_ip_unicast_vpn_config_nexthop( - struct vty *vty, struct lyd_node *dnode, bool show_defaults); -void cli_show_bgp_global_afi_safi_ip_unicast_vpn_config_rd( - struct vty *vty, struct lyd_node *dnode, bool show_defaults); -void cli_show_bgp_global_afi_safi_ip_unicast_vpn_config_import_vpn( - struct vty *vty, struct lyd_node *dnode, bool show_defaults); -void cli_show_bgp_global_afi_safi_ip_unicast_vpn_config_export_vpn( - struct vty *vty, struct lyd_node *dnode, bool show_defaults); -void cli_show_bgp_global_afi_safi_ip_unicast_vpn_config_import_vrfs( - struct vty *vty, struct lyd_node *dnode, bool show_defaults); -void cli_show_bgp_global_afi_safi_ip_unicast_vpn_config_rmap_import( - struct vty *vty, struct lyd_node *dnode, bool show_defaults); -void cli_show_bgp_global_afi_safi_ip_unicast_vpn_config_rmap_export( - struct vty *vty, struct lyd_node *dnode, bool show_defaults); void bgp_global_route_selection_options_apply_finish( struct nb_cb_apply_finish_args *args); void bgp_global_med_config_apply_finish(struct nb_cb_apply_finish_args *args); -void bgp_global_afi_safis_afi_safi_network_config_apply_finish( - struct nb_cb_apply_finish_args *args); -void bgp_global_afi_safi_aggregate_route_apply_finish( - struct nb_cb_apply_finish_args *args); -void bgp_global_afi_safis_afi_safi_ipv4_unicast_admin_distance_apply_finish( - struct nb_cb_apply_finish_args *args); -void bgp_global_afi_safis_afi_safi_ipv6_unicast_admin_distance_apply_finish( - struct nb_cb_apply_finish_args *args); -void bgp_global_afi_safis_afi_safi_ipv4_multicast_admin_distance_apply_finish( - struct nb_cb_apply_finish_args *args); -void bgp_global_afi_safis_afi_safi_ipv6_multicast_admin_distance_apply_finish( - struct nb_cb_apply_finish_args *args); -void bgp_global_afi_safi_admin_distance_route_apply_finish( - struct nb_cb_apply_finish_args *args); -void bgp_global_afi_safi_ip_unicast_use_multiple_paths_ibgp_maximum_paths_apply_finish( - struct nb_cb_apply_finish_args *args); -void bgp_global_afi_safi_ip_unicast_redistribution_list_apply_finish( - struct nb_cb_apply_finish_args *args); -void bgp_global_afi_safis_afi_safi_route_flap_dampening_apply_finish( - struct nb_cb_apply_finish_args *args); /* xpath macros */ /* route-list */ @@ -3563,8 +3505,5 @@ void bgp_global_afi_safis_afi_safi_route_flap_dampening_apply_finish( "/frr-routing:routing/control-plane-protocols/" \ "control-plane-protocol[type='%s'][name='%s'][vrf='%s']/" \ "frr-bgp:bgp/local-as" -#define FRR_BGP_AFI_SAFI_REDIST_XPATH \ - "./global/afi-safis/afi-safi[afi-safi-name='%s']/%s/" \ - "redistribution-list[route-type='%s'][route-instance='%s']" #endif diff --git a/bgpd/bgp_nb_config.c b/bgpd/bgp_nb_config.c index 23685e1208..421e03dd19 100644 --- a/bgpd/bgp_nb_config.c +++ b/bgpd/bgp_nb_config.c @@ -32,7 +32,6 @@ #include "bgpd/bgp_addpath.h" #include "bgpd/bgp_updgrp.h" #include "bgpd/bgp_io.h" -#include "bgpd/bgp_damp.h" DEFINE_HOOK(bgp_snmp_init_stats, (struct bgp *bgp), (bgp)); @@ -248,6 +247,7 @@ int bgp_global_local_as_modify(struct nb_cb_modify_args *args) bgp->as); return NB_ERR_INCONSISTENCY; } + break; } @@ -2061,30 +2061,8 @@ int bgp_global_bmp_config_mirror_buffer_limit_destroy( */ int bgp_global_afi_safis_afi_safi_create(struct nb_cb_create_args *args) { - const struct lyd_node *vrf_dnode; - const char *vrf_name; - const char *af_name; - afi_t afi; - safi_t safi; - switch (args->event) { case NB_EV_VALIDATE: - vrf_dnode = yang_dnode_get_parent(args->dnode, - "control-plane-protocol"); - vrf_name = yang_dnode_get_string(vrf_dnode, "./vrf"); - af_name = yang_dnode_get_string(args->dnode, "./afi-safi-name"); - yang_afi_safi_identity2value(af_name, &afi, &safi); - - if ((!strmatch(vrf_name, VRF_DEFAULT_NAME)) - && safi != SAFI_UNICAST && safi != SAFI_MULTICAST - && safi != SAFI_EVPN) { - snprintf( - args->errmsg, args->errmsg_len, - "Only Unicast/Multicast/EVPN SAFIs supported in non-core instances."); - return NB_ERR_VALIDATION; - } - - break; case NB_EV_PREPARE: case NB_EV_ABORT: case NB_EV_APPLY: @@ -5479,81 +5457,6 @@ int bgp_peer_groups_peer_group_afi_safis_afi_safi_enabled_modify( return NB_OK; } -void bgp_global_afi_safis_afi_safi_network_config_apply_finish( - struct nb_cb_apply_finish_args *args) -{ - const struct lyd_node *af_dnode; - struct bgp *bgp; - const char *af_name; - struct prefix prefix; - bool is_backdoor = false; - uint32_t label_index = BGP_INVALID_LABEL_INDEX; - const char *rmap_name = NULL; - afi_t afi; - safi_t safi; - - af_dnode = yang_dnode_get_parent(args->dnode, "afi-safi"); - af_name = yang_dnode_get_string(af_dnode, "./afi-safi-name"); - yang_afi_safi_identity2value(af_name, &afi, &safi); - bgp = nb_running_get_entry(af_dnode, NULL, true); - - yang_dnode_get_prefix(&prefix, args->dnode, "./prefix"); - - is_backdoor = yang_dnode_get_bool(args->dnode, "./backdoor"); - - if (yang_dnode_exists(args->dnode, "./label-index")) - label_index = - yang_dnode_get_uint32(args->dnode, "./label-index"); - - if (yang_dnode_exists(args->dnode, "./rmap-policy-export")) - rmap_name = yang_dnode_get_string(args->dnode, - "./rmap-policy-export"); - - bgp_static_set(bgp, NULL, &prefix, afi, safi, rmap_name, is_backdoor, - label_index, args->errmsg, args->errmsg_len); -} - -static int bgp_global_afi_safis_afi_safi_network_config_destroy( - struct nb_cb_destroy_args *args) -{ - const struct lyd_node *af_dnode; - struct bgp *bgp; - const char *af_name; - struct prefix prefix; - uint32_t label_index = BGP_INVALID_LABEL_INDEX; - const char *rmap_name = NULL; - bool is_backdoor = false; - afi_t afi; - safi_t safi; - int ret; - - af_dnode = yang_dnode_get_parent(args->dnode, "afi-safi"); - af_name = yang_dnode_get_string(af_dnode, "./afi-safi-name"); - yang_afi_safi_identity2value(af_name, &afi, &safi); - bgp = nb_running_get_entry(af_dnode, NULL, true); - - yang_dnode_get_prefix(&prefix, args->dnode, "./prefix"); - - if (yang_dnode_exists(args->dnode, "./rmap-policy-export")) - rmap_name = yang_dnode_get_string(args->dnode, - "./rmap-policy-export"); - - if (yang_dnode_exists(args->dnode, "./label-index")) - label_index = - yang_dnode_get_uint32(args->dnode, "./label-index"); - - if (yang_dnode_exists(args->dnode, "./backdoor")) - is_backdoor = yang_dnode_get_bool(args->dnode, "./backdoor"); - - ret = bgp_static_set(bgp, "no", &prefix, afi, safi, rmap_name, - is_backdoor, label_index, args->errmsg, - args->errmsg_len); - if (ret < 0) - return NB_ERR_INCONSISTENCY; - - return NB_OK; -} - /* * XPath: * /frr-routing:routing/control-plane-protocols/control-plane-protocol/frr-bgp:bgp/global/afi-safis/afi-safi/ipv4-unicast/network-config @@ -5561,7 +5464,14 @@ static int bgp_global_afi_safis_afi_safi_network_config_destroy( int bgp_global_afi_safis_afi_safi_ipv4_unicast_network_config_create( struct nb_cb_create_args *args) { - /* Handled in network_config_apply_finish callback */ + switch (args->event) { + case NB_EV_VALIDATE: + case NB_EV_PREPARE: + case NB_EV_ABORT: + case NB_EV_APPLY: + /* TODO: implement me. */ + break; + } return NB_OK; } @@ -5573,11 +5483,8 @@ int bgp_global_afi_safis_afi_safi_ipv4_unicast_network_config_destroy( case NB_EV_VALIDATE: case NB_EV_PREPARE: case NB_EV_ABORT: - return NB_OK; case NB_EV_APPLY: - return bgp_global_afi_safis_afi_safi_network_config_destroy( - args); - + /* TODO: implement me. */ break; } @@ -5591,7 +5498,14 @@ int bgp_global_afi_safis_afi_safi_ipv4_unicast_network_config_destroy( int bgp_global_afi_safis_afi_safi_ipv4_unicast_network_config_backdoor_modify( struct nb_cb_modify_args *args) { - /* Handled in unicast_network_config_apply_finish callback */ + switch (args->event) { + case NB_EV_VALIDATE: + case NB_EV_PREPARE: + case NB_EV_ABORT: + case NB_EV_APPLY: + /* TODO: implement me. */ + break; + } return NB_OK; } @@ -5603,46 +5517,12 @@ int bgp_global_afi_safis_afi_safi_ipv4_unicast_network_config_backdoor_modify( int bgp_global_afi_safis_afi_safi_ipv4_unicast_network_config_label_index_modify( struct nb_cb_modify_args *args) { - const struct lyd_node *af_dnode; - struct bgp *bgp; - const char *af_name; - struct prefix prefix; - uint32_t label_index; - afi_t afi; - safi_t safi; - struct bgp_dest *dest; - struct bgp_static *bgp_static; - switch (args->event) { case NB_EV_VALIDATE: - bgp = nb_running_get_entry(args->dnode, NULL, false); - if (!bgp) - return NB_OK; - - af_dnode = yang_dnode_get_parent(args->dnode, "afi-safi"); - af_name = yang_dnode_get_string(af_dnode, "./afi-safi-name"); - yang_afi_safi_identity2value(af_name, &afi, &safi); - yang_dnode_get_prefix(&prefix, args->dnode, "../prefix"); - apply_mask(&prefix); - - label_index = yang_dnode_get_uint32(args->dnode, NULL); - - dest = bgp_node_get(bgp->route[afi][safi], &prefix); - bgp_static = bgp_dest_get_bgp_static_info(dest); - if (bgp_static) { - if (bgp_static->label_index != label_index) { - snprintf( - args->errmsg, args->errmsg_len, - "Cannot change label-index: curr %u input %u\n", - bgp_static->label_index, label_index); - return NB_ERR_VALIDATION; - } - } - - break; case NB_EV_PREPARE: case NB_EV_ABORT: case NB_EV_APPLY: + /* TODO: implement me. */ break; } @@ -5652,7 +5532,14 @@ int bgp_global_afi_safis_afi_safi_ipv4_unicast_network_config_label_index_modify int bgp_global_afi_safis_afi_safi_ipv4_unicast_network_config_label_index_destroy( struct nb_cb_destroy_args *args) { - /* Handled in unicast_network_config_apply_finish callback */ + switch (args->event) { + case NB_EV_VALIDATE: + case NB_EV_PREPARE: + case NB_EV_ABORT: + case NB_EV_APPLY: + /* TODO: implement me. */ + break; + } return NB_OK; } @@ -5664,7 +5551,14 @@ int bgp_global_afi_safis_afi_safi_ipv4_unicast_network_config_label_index_destro int bgp_global_afi_safis_afi_safi_ipv4_unicast_network_config_rmap_policy_export_modify( struct nb_cb_modify_args *args) { - /* Handled in unicast_network_config_apply_finish callback */ + switch (args->event) { + case NB_EV_VALIDATE: + case NB_EV_PREPARE: + case NB_EV_ABORT: + case NB_EV_APPLY: + /* TODO: implement me. */ + break; + } return NB_OK; } @@ -5672,9 +5566,6 @@ int bgp_global_afi_safis_afi_safi_ipv4_unicast_network_config_rmap_policy_export int bgp_global_afi_safis_afi_safi_ipv4_unicast_network_config_rmap_policy_export_destroy( struct nb_cb_destroy_args *args) { - /* rmap destory alone is not supported by backend, the entire network - * config needs to be destroyed. - */ switch (args->event) { case NB_EV_VALIDATE: case NB_EV_PREPARE: @@ -5687,72 +5578,6 @@ int bgp_global_afi_safis_afi_safi_ipv4_unicast_network_config_rmap_policy_export return NB_OK; } -void bgp_global_afi_safi_aggregate_route_apply_finish( - struct nb_cb_apply_finish_args *args) -{ - const struct lyd_node *af_dnode; - struct bgp *bgp; - const char *af_name; - struct prefix prefix; - const char *rmap_name = NULL; - afi_t afi; - safi_t safi; - uint8_t as_set = 0; - int summary_only = 0; - uint8_t origin = BGP_ORIGIN_UNSPECIFIED; - bool match_med = false; - const char *suppress_map = NULL; - - af_dnode = yang_dnode_get_parent(args->dnode, "afi-safi"); - af_name = yang_dnode_get_string(af_dnode, "./afi-safi-name"); - yang_afi_safi_identity2value(af_name, &afi, &safi); - bgp = nb_running_get_entry(af_dnode, NULL, true); - - yang_dnode_get_prefix(&prefix, args->dnode, "./prefix"); - - if (yang_dnode_exists(args->dnode, "./as-set")) - as_set = yang_dnode_get_bool(args->dnode, "./as-set"); - - summary_only = yang_dnode_get_bool(args->dnode, "./summary-only"); - - if (yang_dnode_exists(args->dnode, "./rmap-policy-export")) - rmap_name = yang_dnode_get_string(args->dnode, - "./rmap-policy-export"); - - origin = yang_dnode_get_enum(args->dnode, "./origin"); - - bgp_aggregate_set(bgp, &prefix, afi, safi, rmap_name, summary_only, - as_set, origin, match_med, suppress_map, args->errmsg, - args->errmsg_len); -} - -static int -bgp_global_afi_safi_aggregate_route_destroy(struct nb_cb_destroy_args *args) -{ - const struct lyd_node *af_dnode; - struct bgp *bgp; - const char *af_name; - struct prefix prefix; - afi_t afi; - safi_t safi; - int ret; - - af_dnode = yang_dnode_get_parent(args->dnode, "afi-safi"); - af_name = yang_dnode_get_string(af_dnode, "./afi-safi-name"); - yang_afi_safi_identity2value(af_name, &afi, &safi); - bgp = nb_running_get_entry(af_dnode, NULL, true); - - yang_dnode_get_prefix(&prefix, args->dnode, "./prefix"); - - ret = bgp_aggregate_unset(bgp, &prefix, afi, safi, args->errmsg, - args->errmsg_len); - - if (ret < 0) - return NB_ERR_INCONSISTENCY; - - return NB_OK; -} - /* * XPath: * /frr-routing:routing/control-plane-protocols/control-plane-protocol/frr-bgp:bgp/global/afi-safis/afi-safi/ipv4-unicast/aggregate-route @@ -5779,9 +5604,9 @@ int bgp_global_afi_safis_afi_safi_ipv4_unicast_aggregate_route_destroy( case NB_EV_VALIDATE: case NB_EV_PREPARE: case NB_EV_ABORT: - return NB_OK; case NB_EV_APPLY: - return bgp_global_afi_safi_aggregate_route_destroy(args); + /* TODO: implement me. */ + break; } return NB_OK; @@ -5878,60 +5703,6 @@ int bgp_global_afi_safis_afi_safi_ipv4_unicast_aggregate_route_origin_modify( return NB_OK; } -void bgp_global_afi_safi_admin_distance_route_apply_finish( - struct nb_cb_apply_finish_args *args) -{ - const struct lyd_node *af_dnode; - const char *af_name; - const char *prefix_str = NULL; - const char *access_list_str = NULL; - uint8_t distance; - afi_t afi; - safi_t safi; - - af_dnode = yang_dnode_get_parent(args->dnode, "afi-safi"); - af_name = yang_dnode_get_string(af_dnode, "./afi-safi-name"); - yang_afi_safi_identity2value(af_name, &afi, &safi); - - prefix_str = yang_dnode_get_string(args->dnode, "./prefix"); - distance = yang_dnode_get_uint8(args->dnode, "./distance"); - if (yang_dnode_exists(args->dnode, "./access-list-policy-export")) - access_list_str = yang_dnode_get_string( - args->dnode, "./access-list-policy-export"); - - bgp_distance_set(distance, prefix_str, access_list_str, afi, safi, - args->errmsg, args->errmsg_len); -} - -static int bgp_global_afi_safi_admin_distance_route_destroy( - struct nb_cb_destroy_args *args) -{ - const struct lyd_node *af_dnode; - const char *af_name; - const char *prefix_str = NULL; - const char *access_list_str = NULL; - uint8_t distance; - afi_t afi; - safi_t safi; - - af_dnode = yang_dnode_get_parent(args->dnode, "afi-safi"); - af_name = yang_dnode_get_string(af_dnode, "./afi-safi-name"); - yang_afi_safi_identity2value(af_name, &afi, &safi); - - prefix_str = yang_dnode_get_string(args->dnode, "./prefix"); - distance = yang_dnode_get_uint8(args->dnode, "./distance"); - if (yang_dnode_exists(args->dnode, "./access-list-policy-export")) - access_list_str = yang_dnode_get_string( - args->dnode, "./access-list-policy-export"); - - if (bgp_distance_unset(distance, prefix_str, access_list_str, afi, safi, - args->errmsg, args->errmsg_len) - != CMD_SUCCESS) - return NB_ERR_INCONSISTENCY; - - return NB_OK; -} - /* * XPath: * /frr-routing:routing/control-plane-protocols/control-plane-protocol/frr-bgp:bgp/global/afi-safis/afi-safi/ipv4-unicast/admin-distance-route @@ -5958,9 +5729,9 @@ int bgp_global_afi_safis_afi_safi_ipv4_unicast_admin_distance_route_destroy( case NB_EV_VALIDATE: case NB_EV_PREPARE: case NB_EV_ABORT: - return NB_OK; case NB_EV_APPLY: - return bgp_global_afi_safi_admin_distance_route_destroy(args); + /* TODO: implement me. */ + break; } return NB_OK; @@ -6019,68 +5790,6 @@ int bgp_global_afi_safis_afi_safi_ipv4_unicast_admin_distance_route_access_list_ return NB_OK; } -void bgp_global_afi_safis_afi_safi_route_flap_dampening_apply_finish( - struct nb_cb_apply_finish_args *args) -{ - const struct lyd_node *af_dnode; - struct bgp *bgp; - const char *af_name; - afi_t afi; - safi_t safi; - int half = DEFAULT_HALF_LIFE * 60; - int reuse = DEFAULT_REUSE; - int suppress = DEFAULT_SUPPRESS; - int max; - char ab_xpath[XPATH_MAXLEN]; - - af_dnode = yang_dnode_get_parent(args->dnode, "afi-safi"); - af_name = yang_dnode_get_string(af_dnode, "./afi-safi-name"); - yang_afi_safi_identity2value(af_name, &afi, &safi); - bgp = nb_running_get_entry(af_dnode, NULL, true); - - if (!yang_dnode_get_bool(args->dnode, "./enable")) { - bgp_damp_disable(bgp, afi, safi); - } else { - half = yang_dnode_get_uint8(args->dnode, "./reach-decay"); - half *= 60; - reuse = yang_dnode_get_uint16(args->dnode, "./reuse-above"); - - suppress = - yang_dnode_get_uint16(args->dnode, "./suppress-above"); - - max = yang_dnode_get_uint8(args->dnode, "./unreach-decay"); - yang_dnode_get_path(args->dnode, ab_xpath, sizeof(ab_xpath)); - strlcat(ab_xpath, "/unreach-decay", sizeof(ab_xpath)); - if (yang_get_default_uint8(ab_xpath) == max) - max = half * 4; - else - max *= 60; - - bgp_damp_enable(bgp, afi, safi, half, reuse, suppress, max); - } -} - -static int -bgp_global_afi_safi_route_flap_validation(struct nb_cb_modify_args *args) -{ - int reuse; - int suppress; - - if (yang_dnode_exists(args->dnode, "../suppress-above") - && yang_dnode_exists(args->dnode, "../reuse-above")) { - suppress = - yang_dnode_get_uint16(args->dnode, "../suppress-above"); - reuse = yang_dnode_get_uint16(args->dnode, "../reuse-above"); - if (suppress < reuse) { - snprintf( - args->errmsg, args->errmsg_len, - "Suppress value cannot be less than reuse value \n"); - return NB_ERR_VALIDATION; - } - } - return NB_OK; -} - /* * XPath: * /frr-routing:routing/control-plane-protocols/control-plane-protocol/frr-bgp:bgp/global/afi-safis/afi-safi/ipv4-unicast/route-flap-dampening/enable @@ -6090,10 +5799,10 @@ int bgp_global_afi_safis_afi_safi_ipv4_unicast_route_flap_dampening_enable_modif { switch (args->event) { case NB_EV_VALIDATE: - return bgp_global_afi_safi_route_flap_validation(args); case NB_EV_PREPARE: case NB_EV_ABORT: case NB_EV_APPLY: + /* TODO: implement me. */ break; } @@ -6141,22 +5850,8 @@ int bgp_global_afi_safis_afi_safi_ipv4_unicast_route_flap_dampening_reach_decay_ int bgp_global_afi_safis_afi_safi_ipv4_unicast_route_flap_dampening_reuse_above_modify( struct nb_cb_modify_args *args) { - int reuse = DEFAULT_REUSE; - int suppress = DEFAULT_SUPPRESS; - switch (args->event) { case NB_EV_VALIDATE: - if (yang_dnode_exists(args->dnode, "../suppress-above")) - suppress = yang_dnode_get_uint16(args->dnode, - "../suppress-above"); - reuse = yang_dnode_get_uint16(args->dnode, "../reuse-above"); - if (suppress < reuse) { - snprintf( - args->errmsg, args->errmsg_len, - "Suppress value cannot be less than reuse value \n"); - return NB_ERR_VALIDATION; - } - break; case NB_EV_PREPARE: case NB_EV_ABORT: case NB_EV_APPLY: @@ -6250,45 +5945,6 @@ int bgp_global_afi_safis_afi_safi_ipv4_unicast_route_flap_dampening_unreach_deca return NB_OK; } -static int -bgp_global_afi_safi_ip_unicast_use_multiple_paths_ebgp_maximum_paths_modify( - struct nb_cb_modify_args *args) -{ - const struct lyd_node *af_dnode; - struct bgp *bgp; - const char *af_name; - afi_t afi; - safi_t safi; - uint16_t maxpaths, default_maxpaths; - int ret; - char xpath[XPATH_MAXLEN]; - char afi_xpath[XPATH_MAXLEN]; - - af_dnode = yang_dnode_get_parent(args->dnode, "afi-safi"); - af_name = yang_dnode_get_string(af_dnode, "./afi-safi-name"); - yang_afi_safi_identity2value(af_name, &afi, &safi); - bgp = nb_running_get_entry(af_dnode, NULL, true); - maxpaths = yang_dnode_get_uint16(args->dnode, NULL); - - snprintf(xpath, sizeof(xpath), FRR_BGP_GLOBAL_XPATH, "frr-bgp:bgp", - "bgp", bgp->name ? bgp->name : VRF_DEFAULT_NAME); - snprintf( - afi_xpath, sizeof(afi_xpath), - "/global/afi-safis/afi-safi[afi-safi-name='%s']/%s/use-multiple-paths/ebgp/maximum-paths", - yang_afi_safi_value2identity(afi, safi), - bgp_afi_safi_get_container_str(afi, safi)); - strlcat(xpath, afi_xpath, sizeof(xpath)); - default_maxpaths = yang_get_default_uint16(xpath); - - ret = bgp_maxpaths_config_vty(bgp, afi, safi, BGP_PEER_EBGP, maxpaths, - 0, maxpaths != default_maxpaths ? 1 : 0, - args->errmsg, args->errmsg_len); - if (ret != CMD_SUCCESS) - return NB_ERR_INCONSISTENCY; - - return NB_OK; -} - /* * XPath: * /frr-routing:routing/control-plane-protocols/control-plane-protocol/frr-bgp:bgp/global/afi-safis/afi-safi/ipv4-unicast/use-multiple-paths/ebgp/maximum-paths @@ -6296,70 +5952,18 @@ bgp_global_afi_safi_ip_unicast_use_multiple_paths_ebgp_maximum_paths_modify( int bgp_global_afi_safis_afi_safi_ipv4_unicast_use_multiple_paths_ebgp_maximum_paths_modify( struct nb_cb_modify_args *args) { - uint16_t maxpaths; - switch (args->event) { case NB_EV_VALIDATE: - maxpaths = yang_dnode_get_uint16(args->dnode, NULL); - if (maxpaths > MULTIPATH_NUM) { - snprintf(args->errmsg, args->errmsg_len, - "maxpaths %u is out of range %u", maxpaths, - MULTIPATH_NUM); - return NB_ERR_VALIDATION; - } - break; case NB_EV_PREPARE: case NB_EV_ABORT: - return NB_OK; case NB_EV_APPLY: - return bgp_global_afi_safi_ip_unicast_use_multiple_paths_ebgp_maximum_paths_modify( - args); + /* TODO: implement me. */ + break; } return NB_OK; } -/* - * XPath: - * /frr-routing:routing/control-plane-protocols/control-plane-protocol/frr-bgp:bgp/global/afi-safis/afi-safi/ipv4-unicast/use-multiple-paths/ibgp - */ -void bgp_global_afi_safi_ip_unicast_use_multiple_paths_ibgp_maximum_paths_apply_finish( - struct nb_cb_apply_finish_args *args) -{ - const struct lyd_node *af_dnode; - struct bgp *bgp; - const char *af_name; - afi_t afi; - safi_t safi; - uint16_t maxpaths, default_maxpaths; - char xpath[XPATH_MAXLEN]; - char afi_xpath[XPATH_MAXLEN]; - uint16_t options = 0; - - af_dnode = yang_dnode_get_parent(args->dnode, "afi-safi"); - af_name = yang_dnode_get_string(af_dnode, "./afi-safi-name"); - yang_afi_safi_identity2value(af_name, &afi, &safi); - bgp = nb_running_get_entry(af_dnode, NULL, true); - - maxpaths = yang_dnode_get_uint16(args->dnode, "./maximum-paths"); - if (yang_dnode_get_bool(args->dnode, "./cluster-length-list")) - options = BGP_FLAG_IBGP_MULTIPATH_SAME_CLUSTERLEN; - - snprintf(xpath, sizeof(xpath), FRR_BGP_GLOBAL_XPATH, "frr-bgp:bgp", - "bgp", bgp->name ? bgp->name : VRF_DEFAULT_NAME); - snprintf( - afi_xpath, sizeof(afi_xpath), - "/global/afi-safis/afi-safi[afi-safi-name='%s']/%s/use-multiple-paths/ibgp/maximum-paths", - yang_afi_safi_value2identity(afi, safi), - bgp_afi_safi_get_container_str(afi, safi)); - strlcat(xpath, afi_xpath, sizeof(xpath)); - default_maxpaths = yang_get_default_uint16(xpath); - - bgp_maxpaths_config_vty(bgp, afi, safi, BGP_PEER_IBGP, maxpaths, - options, maxpaths != default_maxpaths ? 1 : 0, - args->errmsg, args->errmsg_len); -} - /* * XPath: * /frr-routing:routing/control-plane-protocols/control-plane-protocol/frr-bgp:bgp/global/afi-safis/afi-safi/ipv4-unicast/use-multiple-paths/ibgp/maximum-paths @@ -6367,22 +5971,12 @@ void bgp_global_afi_safi_ip_unicast_use_multiple_paths_ibgp_maximum_paths_apply_ int bgp_global_afi_safis_afi_safi_ipv4_unicast_use_multiple_paths_ibgp_maximum_paths_modify( struct nb_cb_modify_args *args) { - uint16_t maxpaths; - switch (args->event) { case NB_EV_VALIDATE: - maxpaths = yang_dnode_get_uint16(args->dnode, NULL); - if (maxpaths > MULTIPATH_NUM) { - snprintf(args->errmsg, args->errmsg_len, - "maxpaths %u is out of range %u", maxpaths, - MULTIPATH_NUM); - return NB_ERR_VALIDATION; - } - break; case NB_EV_PREPARE: case NB_EV_ABORT: - return NB_OK; case NB_EV_APPLY: + /* TODO: implement me. */ break; } @@ -6423,49 +6017,6 @@ int bgp_global_afi_safis_afi_safi_ipv4_unicast_use_multiple_paths_ibgp_cluster_l return NB_OK; } -void bgp_global_afi_safi_ip_unicast_redistribution_list_apply_finish( - struct nb_cb_apply_finish_args *args) -{ - const struct lyd_node *af_dnode; - struct bgp *bgp; - const char *af_name; - afi_t afi; - safi_t safi; - int route_type; - int route_instance; - struct bgp_redist *red; - bool changed = false; - struct route_map *route_map = NULL; - const char *rmap_name = NULL; - uint32_t metric = 0; - - af_dnode = yang_dnode_get_parent(args->dnode, "afi-safi"); - af_name = yang_dnode_get_string(af_dnode, "./afi-safi-name"); - yang_afi_safi_identity2value(af_name, &afi, &safi); - bgp = nb_running_get_entry(af_dnode, NULL, true); - - route_type = yang_dnode_get_enum(args->dnode, "./route-type"); - route_instance = yang_dnode_get_uint16(args->dnode, "./route-instance"); - - red = bgp_redist_add(bgp, afi, route_type, route_instance); - - if (yang_dnode_exists(args->dnode, "./rmap-policy-import")) { - rmap_name = yang_dnode_get_string(args->dnode, - "./rmap-policy-import"); - route_map = route_map_lookup_by_name(rmap_name); - - changed = bgp_redistribute_rmap_set(red, rmap_name, route_map); - } - - if (yang_dnode_exists(args->dnode, "./metric")) { - metric = yang_dnode_get_uint32(args->dnode, "./metric"); - changed |= bgp_redistribute_metric_set(bgp, red, afi, - route_type, metric); - } - - bgp_redistribute_set(bgp, afi, route_type, route_instance, changed); -} - /* * XPath: * /frr-routing:routing/control-plane-protocols/control-plane-protocol/frr-bgp:bgp/global/afi-safis/afi-safi/ipv4-unicast/redistribution-list @@ -6488,31 +6039,12 @@ int bgp_global_afi_safis_afi_safi_ipv4_unicast_redistribution_list_create( int bgp_global_afi_safis_afi_safi_ipv4_unicast_redistribution_list_destroy( struct nb_cb_destroy_args *args) { - const struct lyd_node *af_dnode; - struct bgp *bgp; - const char *af_name; - afi_t afi; - safi_t safi; - int route_type; - int route_instance; - switch (args->event) { case NB_EV_VALIDATE: case NB_EV_PREPARE: case NB_EV_ABORT: - return NB_OK; case NB_EV_APPLY: - af_dnode = yang_dnode_get_parent(args->dnode, "afi-safi"); - af_name = yang_dnode_get_string(af_dnode, "./afi-safi-name"); - yang_afi_safi_identity2value(af_name, &afi, &safi); - bgp = nb_running_get_entry(af_dnode, NULL, true); - - route_type = yang_dnode_get_enum(args->dnode, "./route-type"); - route_instance = - yang_dnode_get_uint16(args->dnode, "./route-instance"); - - bgp_redistribute_unset(bgp, afi, route_type, route_instance); - + /* TODO: implement me. */ break; } @@ -6587,52 +6119,21 @@ int bgp_global_afi_safis_afi_safi_ipv4_unicast_redistribution_list_rmap_policy_i return NB_OK; } -static int -bgp_global_afi_safis_admin_distance_modify(struct nb_cb_apply_finish_args *args) +/* + * XPath: + * /frr-routing:routing/control-plane-protocols/control-plane-protocol/frr-bgp:bgp/global/afi-safis/afi-safi/ipv4-unicast/admin-distance/external + */ +int bgp_global_afi_safis_afi_safi_ipv4_unicast_admin_distance_external_modify( + struct nb_cb_modify_args *args) { - struct bgp *bgp; - const struct lyd_node *af_dnode; - const char *af_name; - afi_t afi; - safi_t safi; - uint8_t distance_ebgp, distance_ibgp, distance_local; - - af_dnode = yang_dnode_get_parent(args->dnode, "afi-safi"); - af_name = yang_dnode_get_string(af_dnode, "./afi-safi-name"); - yang_afi_safi_identity2value(af_name, &afi, &safi); - bgp = nb_running_get_entry(af_dnode, NULL, true); - - distance_ebgp = yang_dnode_get_uint8(args->dnode, "./external"); - distance_ibgp = yang_dnode_get_uint8(args->dnode, "./internal"); - distance_local = yang_dnode_get_uint8(args->dnode, "./local"); - - bgp->distance_ebgp[afi][safi] = distance_ebgp; - bgp->distance_ibgp[afi][safi] = distance_ibgp; - bgp->distance_local[afi][safi] = distance_local; - - bgp_announce_routes_distance_update(bgp, afi, safi); - - return NB_OK; -} - -/* - * XPath: - * /frr-routing:routing/control-plane-protocols/control-plane-protocol/frr-bgp:bgp/global/afi-safis/afi-safi/ipv4-unicast/admin-distance - */ -void bgp_global_afi_safis_afi_safi_ipv4_unicast_admin_distance_apply_finish( - struct nb_cb_apply_finish_args *args) -{ - bgp_global_afi_safis_admin_distance_modify(args); -} - -/* - * XPath: - * /frr-routing:routing/control-plane-protocols/control-plane-protocol/frr-bgp:bgp/global/afi-safis/afi-safi/ipv4-unicast/admin-distance/external - */ -int bgp_global_afi_safis_afi_safi_ipv4_unicast_admin_distance_external_modify( - struct nb_cb_modify_args *args) -{ - /* Handled in admin_distance_apply_finish callback */ + switch (args->event) { + case NB_EV_VALIDATE: + case NB_EV_PREPARE: + case NB_EV_ABORT: + case NB_EV_APPLY: + /* TODO: implement me. */ + break; + } return NB_OK; } @@ -6644,7 +6145,14 @@ int bgp_global_afi_safis_afi_safi_ipv4_unicast_admin_distance_external_modify( int bgp_global_afi_safis_afi_safi_ipv4_unicast_admin_distance_internal_modify( struct nb_cb_modify_args *args) { - /* Handled in admin_distance_apply_finish callback */ + switch (args->event) { + case NB_EV_VALIDATE: + case NB_EV_PREPARE: + case NB_EV_ABORT: + case NB_EV_APPLY: + /* TODO: implement me. */ + break; + } return NB_OK; } @@ -6656,7 +6164,14 @@ int bgp_global_afi_safis_afi_safi_ipv4_unicast_admin_distance_internal_modify( int bgp_global_afi_safis_afi_safi_ipv4_unicast_admin_distance_local_modify( struct nb_cb_modify_args *args) { - /* Handled in admin_distance_apply_finish callback */ + switch (args->event) { + case NB_EV_VALIDATE: + case NB_EV_PREPARE: + case NB_EV_ABORT: + case NB_EV_APPLY: + /* TODO: implement me. */ + break; + } return NB_OK; } @@ -6695,83 +6210,6 @@ int bgp_global_afi_safis_afi_safi_ipv4_unicast_filter_config_rmap_export_destroy return NB_OK; } -static int bgp_global_afi_safi_ip_unicast_vpn_config_rd_modify( - struct nb_cb_modify_args *args) -{ - struct bgp *bgp; - const struct lyd_node *af_dnode; - const char *af_name; - afi_t afi; - safi_t safi; - const char *rd_str = NULL; - struct prefix_rd prd; - - bgp = nb_running_get_entry(args->dnode, NULL, true); - - af_dnode = yang_dnode_get_parent(args->dnode, "afi-safi"); - af_name = yang_dnode_get_string(af_dnode, "./afi-safi-name"); - yang_afi_safi_identity2value(af_name, &afi, &safi); - - rd_str = yang_dnode_get_string(args->dnode, NULL); - if (!str2prefix_rd(rd_str, &prd)) { - snprintf(args->errmsg, args->errmsg_len, "Malformed rd %s\n", - rd_str); - return NB_ERR_INCONSISTENCY; - } - - /* - * pre-change: un-export vpn routes (vpn->vrf routes unaffected) - */ - vpn_leak_prechange(BGP_VPN_POLICY_DIR_TOVPN, afi, bgp_get_default(), - bgp); - - bgp->vpn_policy[afi].tovpn_rd = prd; - SET_FLAG(bgp->vpn_policy[afi].flags, BGP_VPN_POLICY_TOVPN_RD_SET); - - /* post-change: re-export vpn routes */ - vpn_leak_postchange(BGP_VPN_POLICY_DIR_TOVPN, afi, bgp_get_default(), - bgp); - - return NB_OK; -} - -static int bgp_global_afi_safi_ip_unicast_vpn_config_rd_destroy( - struct nb_cb_destroy_args *args) -{ - struct bgp *bgp; - const struct lyd_node *af_dnode; - const char *af_name; - afi_t afi; - safi_t safi; - const char *rd_str = NULL; - struct prefix_rd prd; - - af_dnode = yang_dnode_get_parent(args->dnode, "afi-safi"); - af_name = yang_dnode_get_string(af_dnode, "./afi-safi-name"); - yang_afi_safi_identity2value(af_name, &afi, &safi); - bgp = nb_running_get_entry(af_dnode, NULL, true); - - rd_str = yang_dnode_get_string(args->dnode, NULL); - if (str2prefix_rd(rd_str, &prd)) { - snprintf(args->errmsg, args->errmsg_len, "Malformed rd %s \n", - rd_str); - return NB_ERR_INCONSISTENCY; - } - - /* - * pre-change: un-export vpn routes (vpn->vrf routes unaffected) - */ - vpn_leak_prechange(BGP_VPN_POLICY_DIR_TOVPN, afi, bgp_get_default(), - bgp); - - UNSET_FLAG(bgp->vpn_policy[afi].flags, BGP_VPN_POLICY_TOVPN_RD_SET); - - /* post-change: re-export vpn routes */ - vpn_leak_postchange(BGP_VPN_POLICY_DIR_TOVPN, afi, bgp_get_default(), - bgp); - return NB_OK; -} - /* * XPath: * /frr-routing:routing/control-plane-protocols/control-plane-protocol/frr-bgp:bgp/global/afi-safis/afi-safi/ipv4-unicast/vpn-config/rd @@ -6779,34 +6217,12 @@ static int bgp_global_afi_safi_ip_unicast_vpn_config_rd_destroy( int bgp_global_afi_safis_afi_safi_ipv4_unicast_vpn_config_rd_modify( struct nb_cb_modify_args *args) { - struct bgp *bgp; - const struct lyd_node *af_dnode; - const char *af_name; - afi_t afi; - safi_t safi; - switch (args->event) { case NB_EV_VALIDATE: - bgp = nb_running_get_entry(args->dnode, NULL, false); - if (!bgp) - return NB_OK; - - af_dnode = yang_dnode_get_parent(args->dnode, "afi-safi"); - af_name = yang_dnode_get_string(af_dnode, "./afi-safi-name"); - yang_afi_safi_identity2value(af_name, &afi, &safi); - - if (!vpn_policy_check_import(bgp, afi, safi, false, - args->errmsg, args->errmsg_len)) - return NB_ERR_VALIDATION; - break; case NB_EV_PREPARE: case NB_EV_ABORT: - return NB_OK; case NB_EV_APPLY: - - return bgp_global_afi_safi_ip_unicast_vpn_config_rd_modify( - args); - + /* TODO: implement me. */ break; } @@ -6820,10 +6236,9 @@ int bgp_global_afi_safis_afi_safi_ipv4_unicast_vpn_config_rd_destroy( case NB_EV_VALIDATE: case NB_EV_PREPARE: case NB_EV_ABORT: - return NB_OK; case NB_EV_APPLY: - return bgp_global_afi_safi_ip_unicast_vpn_config_rd_destroy( - args); + /* TODO: implement me. */ + break; } return NB_OK; @@ -6897,69 +6312,6 @@ int bgp_global_afi_safis_afi_safi_ipv4_unicast_vpn_config_label_auto_destroy( return NB_OK; } -static int bgp_global_afi_safi_ip_unicast_vpn_config_nexthop_modify( - struct nb_cb_modify_args *args) -{ - struct bgp *bgp; - const struct lyd_node *af_dnode; - const char *af_name; - afi_t afi; - safi_t safi; - struct prefix p; - - af_dnode = yang_dnode_get_parent(args->dnode, "afi-safi"); - af_name = yang_dnode_get_string(af_dnode, "./afi-safi-name"); - yang_afi_safi_identity2value(af_name, &afi, &safi); - bgp = nb_running_get_entry(af_dnode, NULL, true); - - yang_dnode_get_prefix(&p, args->dnode, NULL); - - /* - * pre-change: un-export vpn routes (vpn->vrf routes unaffected) - */ - vpn_leak_prechange(BGP_VPN_POLICY_DIR_TOVPN, afi, bgp_get_default(), - bgp); - - bgp->vpn_policy[afi].tovpn_nexthop = p; - SET_FLAG(bgp->vpn_policy[afi].flags, BGP_VPN_POLICY_TOVPN_NEXTHOP_SET); - - /* post-change: re-export vpn routes */ - vpn_leak_postchange(BGP_VPN_POLICY_DIR_TOVPN, afi, bgp_get_default(), - bgp); - - return NB_OK; -} - -static int bgp_global_afi_safi_ip_unicast_vpn_config_nexthop_destroy( - struct nb_cb_destroy_args *args) -{ - struct bgp *bgp; - const struct lyd_node *af_dnode; - const char *af_name; - afi_t afi; - safi_t safi; - struct prefix p; - - af_dnode = yang_dnode_get_parent(args->dnode, "afi-safi"); - af_name = yang_dnode_get_string(af_dnode, "./afi-safi-name"); - yang_afi_safi_identity2value(af_name, &afi, &safi); - bgp = nb_running_get_entry(af_dnode, NULL, true); - - yang_dnode_get_prefix(&p, args->dnode, NULL); - - /* - * pre-change: un-export vpn routes (vpn->vrf routes unaffected) - */ - vpn_leak_prechange(BGP_VPN_POLICY_DIR_TOVPN, afi, bgp_get_default(), - bgp); - UNSET_FLAG(bgp->vpn_policy[afi].flags, - BGP_VPN_POLICY_TOVPN_NEXTHOP_SET); - /* post-change: re-export vpn routes */ - vpn_leak_postchange(BGP_VPN_POLICY_DIR_TOVPN, afi, bgp_get_default(), - bgp); - return NB_OK; -} - /* * XPath: * /frr-routing:routing/control-plane-protocols/control-plane-protocol/frr-bgp:bgp/global/afi-safis/afi-safi/ipv4-unicast/vpn-config/nexthop @@ -6967,32 +6319,13 @@ static int bgp_global_afi_safi_ip_unicast_vpn_config_nexthop_destroy( int bgp_global_afi_safis_afi_safi_ipv4_unicast_vpn_config_nexthop_modify( struct nb_cb_modify_args *args) { - struct bgp *bgp; - const struct lyd_node *af_dnode; - const char *af_name; - afi_t afi; - safi_t safi; - switch (args->event) { case NB_EV_VALIDATE: - bgp = nb_running_get_entry(args->dnode, NULL, false); - if (!bgp) - return NB_OK; - af_dnode = yang_dnode_get_parent(args->dnode, "afi-safi"); - af_name = yang_dnode_get_string(af_dnode, "./afi-safi-name"); - yang_afi_safi_identity2value(af_name, &afi, &safi); - - if (!vpn_policy_check_import(bgp, afi, safi, false, - args->errmsg, args->errmsg_len)) - return NB_ERR_VALIDATION; - - break; case NB_EV_PREPARE: case NB_EV_ABORT: - return NB_OK; case NB_EV_APPLY: - return bgp_global_afi_safi_ip_unicast_vpn_config_nexthop_modify( - args); + /* TODO: implement me. */ + break; } return NB_OK; @@ -7005,59 +6338,9 @@ int bgp_global_afi_safis_afi_safi_ipv4_unicast_vpn_config_nexthop_destroy( case NB_EV_VALIDATE: case NB_EV_PREPARE: case NB_EV_ABORT: - return NB_OK; case NB_EV_APPLY: - return bgp_global_afi_safi_ip_unicast_vpn_config_nexthop_destroy( - args); - } - - return NB_OK; -} - -static int bgp_global_afi_safi_ip_unicast_vpn_config_import_export_vpn_modify( - struct nb_cb_modify_args *args, const char *direction_str, - bool is_enable) -{ - struct bgp *bgp; - const struct lyd_node *af_dnode; - const char *af_name; - afi_t afi; - safi_t safi; - int previous_state; - int flag; - vpn_policy_direction_t dir; - - af_dnode = yang_dnode_get_parent(args->dnode, "afi-safi"); - af_name = yang_dnode_get_string(af_dnode, "./afi-safi-name"); - yang_afi_safi_identity2value(af_name, &afi, &safi); - bgp = nb_running_get_entry(af_dnode, NULL, true); - - if (!strcmp(direction_str, "import")) { - flag = BGP_CONFIG_MPLSVPN_TO_VRF_IMPORT; - dir = BGP_VPN_POLICY_DIR_FROMVPN; - } else if (!strcmp(direction_str, "export")) { - flag = BGP_CONFIG_VRF_TO_MPLSVPN_EXPORT; - dir = BGP_VPN_POLICY_DIR_TOVPN; - } else { - snprintf(args->errmsg, args->errmsg_len, - "unknown direction %s\n", direction_str); - return NB_ERR_INCONSISTENCY; - } - - previous_state = CHECK_FLAG(bgp->af_flags[afi][safi], flag); - - if (is_enable) { - SET_FLAG(bgp->af_flags[afi][safi], flag); - if (!previous_state) { - /* trigger export current vrf */ - vpn_leak_postchange(dir, afi, bgp_get_default(), bgp); - } - } else { - if (previous_state) { - /* trigger un-export current vrf */ - vpn_leak_prechange(dir, afi, bgp_get_default(), bgp); - } - UNSET_FLAG(bgp->af_flags[afi][safi], flag); + /* TODO: implement me. */ + break; } hook_call(bgp_snmp_init_stats, bgp); @@ -7071,33 +6354,13 @@ static int bgp_global_afi_safi_ip_unicast_vpn_config_import_export_vpn_modify( int bgp_global_afi_safis_afi_safi_ipv4_unicast_vpn_config_import_vpn_modify( struct nb_cb_modify_args *args) { - bool is_enable = false; - struct bgp *bgp; - switch (args->event) { case NB_EV_VALIDATE: - bgp = nb_running_get_entry(args->dnode, NULL, false); - if (!bgp) - return NB_OK; - - if (BGP_INSTANCE_TYPE_VRF != bgp->inst_type - && BGP_INSTANCE_TYPE_DEFAULT != bgp->inst_type) { - snprintf( - args->errmsg, args->errmsg_len, - "import|export vpn valid only for bgp vrf or default instance"); - return NB_ERR_VALIDATION; - } - - break; case NB_EV_PREPARE: case NB_EV_ABORT: - return NB_OK; case NB_EV_APPLY: - if (yang_dnode_get_bool(args->dnode, NULL)) - is_enable = true; - - return bgp_global_afi_safi_ip_unicast_vpn_config_import_export_vpn_modify( - args, "import", is_enable); + /* TODO: implement me. */ + break; } return NB_OK; @@ -7110,184 +6373,18 @@ int bgp_global_afi_safis_afi_safi_ipv4_unicast_vpn_config_import_vpn_modify( int bgp_global_afi_safis_afi_safi_ipv4_unicast_vpn_config_export_vpn_modify( struct nb_cb_modify_args *args) { - bool is_enable = false; - struct bgp *bgp; - switch (args->event) { case NB_EV_VALIDATE: - bgp = nb_running_get_entry(args->dnode, NULL, false); - if (!bgp) - return NB_OK; - - if (BGP_INSTANCE_TYPE_VRF != bgp->inst_type - && BGP_INSTANCE_TYPE_DEFAULT != bgp->inst_type) { - snprintf( - args->errmsg, args->errmsg_len, - "import|export vpn valid only for bgp vrf or default instance"); - return NB_ERR_VALIDATION; - } - break; case NB_EV_PREPARE: case NB_EV_ABORT: - return NB_OK; case NB_EV_APPLY: - if (yang_dnode_get_bool(args->dnode, NULL)) - is_enable = true; - - return bgp_global_afi_safi_ip_unicast_vpn_config_import_export_vpn_modify( - args, "export", is_enable); - } - - return NB_OK; -} - - -static int bgp_global_afi_safi_ip_unicast_vpn_config_import_vrfs_create( - struct nb_cb_create_args *args) -{ - struct bgp *bgp; - const struct lyd_node *af_dnode; - const char *af_name; - afi_t afi; - safi_t safi; - int ret = 0; - as_t as; - struct bgp *vrf_bgp, *bgp_default; - const char *import_name; - char *vname; - enum bgp_instance_type bgp_type = BGP_INSTANCE_TYPE_VRF; - struct listnode *node; - - af_dnode = yang_dnode_get_parent(args->dnode, "afi-safi"); - af_name = yang_dnode_get_string(af_dnode, "./afi-safi-name"); - yang_afi_safi_identity2value(af_name, &afi, &safi); - bgp = nb_running_get_entry(af_dnode, NULL, true); - - as = bgp->as; - import_name = yang_dnode_get_string(args->dnode, "./vrf"); - - if (((BGP_INSTANCE_TYPE_DEFAULT == bgp->inst_type) - && (strcmp(import_name, VRF_DEFAULT_NAME) == 0)) - || (bgp->name && (strcmp(import_name, bgp->name) == 0))) { - snprintf(args->errmsg, args->errmsg_len, - "Cannot %s vrf %s into itself\n", "import", - import_name); - return NB_ERR_INCONSISTENCY; - } - - bgp_default = bgp_get_default(); - if (!bgp_default) { - /* Auto-create assuming the same AS */ - ret = bgp_get_vty(&bgp_default, &as, NULL, - BGP_INSTANCE_TYPE_DEFAULT); - - if (ret) { - snprintf( - args->errmsg, args->errmsg_len, - "VRF default is not configured as a bgp instance"); - return NB_ERR_INCONSISTENCY; - } - } - - vrf_bgp = bgp_lookup_by_name(import_name); - if (!vrf_bgp) { - if (strcmp(import_name, VRF_DEFAULT_NAME) == 0) - vrf_bgp = bgp_default; - else - /* Auto-create assuming the same AS */ - ret = bgp_get_vty(&vrf_bgp, &as, import_name, bgp_type); - - if (ret) { - snprintf(args->errmsg, args->errmsg_len, - "VRF %s is not configured as a bgp instance\n", - import_name); - return NB_ERR_INCONSISTENCY; - } - } - - /* Already importing from "import_vrf"? */ - for (ALL_LIST_ELEMENTS_RO(bgp->vpn_policy[afi].import_vrf, node, - vname)) { - if (strcmp(vname, import_name) == 0) { - snprintf(args->errmsg, args->errmsg_len, - "already importing from vrf %s", import_name); - return NB_ERR_INCONSISTENCY; - } - } - - vrf_import_from_vrf(bgp, vrf_bgp, afi, safi); - - return NB_OK; -} - - -static int bgp_global_afi_safi_ip_unicast_vpn_config_import_vrf_list_destroy( - struct nb_cb_destroy_args *args) -{ - struct bgp *bgp; - const struct lyd_node *af_dnode; - const char *af_name; - afi_t afi; - safi_t safi; - int ret = 0; - as_t as; - struct bgp *vrf_bgp, *bgp_default; - const char *import_name; - enum bgp_instance_type bgp_type = BGP_INSTANCE_TYPE_VRF; - - af_dnode = yang_dnode_get_parent(args->dnode, "afi-safi"); - af_name = yang_dnode_get_string(af_dnode, "./afi-safi-name"); - yang_afi_safi_identity2value(af_name, &afi, &safi); - bgp = nb_running_get_entry(af_dnode, NULL, true); - - as = bgp->as; - import_name = yang_dnode_get_string(args->dnode, "./vrf"); - - if (((BGP_INSTANCE_TYPE_DEFAULT == bgp->inst_type) - && (strcmp(import_name, VRF_DEFAULT_NAME) == 0)) - || (bgp->name && (strcmp(import_name, bgp->name) == 0))) { - snprintf(args->errmsg, args->errmsg_len, - "Cannot %s vrf %s into itself\n", "unimport", - import_name); - return NB_ERR_INCONSISTENCY; - } - - bgp_default = bgp_get_default(); - if (!bgp_default) { - /* Auto-create assuming the same AS */ - ret = bgp_get_vty(&bgp_default, &as, NULL, - BGP_INSTANCE_TYPE_DEFAULT); - - if (ret) { - snprintf( - args->errmsg, args->errmsg_len, "%s", - "VRF default is not configured as a bgp instance"); - return NB_ERR_INCONSISTENCY; - } - } - - vrf_bgp = bgp_lookup_by_name(import_name); - if (!vrf_bgp) { - if (strcmp(import_name, VRF_DEFAULT_NAME) == 0) - vrf_bgp = bgp_default; - else - /* Auto-create assuming the same AS */ - ret = bgp_get_vty(&vrf_bgp, &as, import_name, bgp_type); - - if (ret) { - snprintf(args->errmsg, args->errmsg_len, - "VRF %s is not configured as a bgp instance\n", - import_name); - return NB_ERR_INCONSISTENCY; - } + /* TODO: implement me. */ + break; } - vrf_unimport_from_vrf(bgp, vrf_bgp, afi, safi); - return NB_OK; } - /* * XPath: * /frr-routing:routing/control-plane-protocols/control-plane-protocol/frr-bgp:bgp/global/afi-safis/afi-safi/ipv4-unicast/vpn-config/import-vrf-list @@ -7295,32 +6392,13 @@ static int bgp_global_afi_safi_ip_unicast_vpn_config_import_vrf_list_destroy( int bgp_global_afi_safis_afi_safi_ipv4_unicast_vpn_config_import_vrf_list_create( struct nb_cb_create_args *args) { - struct bgp *bgp; - const struct lyd_node *af_dnode; - const char *af_name; - afi_t afi; - safi_t safi; - switch (args->event) { case NB_EV_VALIDATE: - bgp = nb_running_get_entry(args->dnode, NULL, false); - if (!bgp) - return NB_OK; - af_dnode = yang_dnode_get_parent(args->dnode, "afi-safi"); - af_name = yang_dnode_get_string(af_dnode, "./afi-safi-name"); - yang_afi_safi_identity2value(af_name, &afi, &safi); - - if (!vpn_policy_check_import(bgp, afi, safi, true, args->errmsg, - args->errmsg_len)) - return NB_ERR_VALIDATION; - - break; case NB_EV_PREPARE: case NB_EV_ABORT: - return NB_OK; case NB_EV_APPLY: - return bgp_global_afi_safi_ip_unicast_vpn_config_import_vrfs_create( - args); + /* TODO: implement me. */ + break; } return NB_OK; @@ -7333,104 +6411,9 @@ int bgp_global_afi_safis_afi_safi_ipv4_unicast_vpn_config_import_vrf_list_destro case NB_EV_VALIDATE: case NB_EV_PREPARE: case NB_EV_ABORT: - return NB_OK; case NB_EV_APPLY: - return bgp_global_afi_safi_ip_unicast_vpn_config_import_vrf_list_destroy( - args); - } - - return NB_OK; -} - -static int bgp_global_afi_safi_ip_unicast_vpn_config_rmap_import_modify( - struct nb_cb_modify_args *args, const char *dstr) -{ - struct bgp *bgp; - const struct lyd_node *af_dnode; - const char *af_name; - afi_t afi; - safi_t safi; - const char *rmap_str = NULL; - int dodir[BGP_VPN_POLICY_DIR_MAX] = {0}; - vpn_policy_direction_t dir; - - af_dnode = yang_dnode_get_parent(args->dnode, "afi-safi"); - af_name = yang_dnode_get_string(af_dnode, "./afi-safi-name"); - yang_afi_safi_identity2value(af_name, &afi, &safi); - bgp = nb_running_get_entry(af_dnode, NULL, true); - - if (!strcmp(dstr, "import")) { - rmap_str = yang_dnode_get_string(args->dnode, NULL); - dodir[BGP_VPN_POLICY_DIR_FROMVPN] = 1; - } else if (!strcmp(dstr, "export")) { - rmap_str = yang_dnode_get_string(args->dnode, NULL); - dodir[BGP_VPN_POLICY_DIR_TOVPN] = 1; - } else if (!strcmp(dstr, "both")) { - dodir[BGP_VPN_POLICY_DIR_FROMVPN] = 1; - dodir[BGP_VPN_POLICY_DIR_TOVPN] = 1; - } - - for (dir = 0; dir < BGP_VPN_POLICY_DIR_MAX; ++dir) { - if (!dodir[dir]) - continue; - - vpn_leak_prechange(dir, afi, bgp_get_default(), bgp); - - if (bgp->vpn_policy[afi].rmap_name[dir]) - XFREE(MTYPE_ROUTE_MAP_NAME, - bgp->vpn_policy[afi].rmap_name[dir]); - bgp->vpn_policy[afi].rmap_name[dir] = - XSTRDUP(MTYPE_ROUTE_MAP_NAME, rmap_str); - bgp->vpn_policy[afi].rmap[dir] = - route_map_lookup_by_name(rmap_str); - if (!bgp->vpn_policy[afi].rmap[dir]) - return NB_OK; - - - vpn_leak_postchange(dir, afi, bgp_get_default(), bgp); - } - - return NB_OK; -} - -static int bgp_global_afi_safi_ip_unicast_vpn_config_rmap_import_destroy( - struct nb_cb_destroy_args *args, const char *dstr) -{ - struct bgp *bgp; - const struct lyd_node *af_dnode; - const char *af_name; - afi_t afi; - safi_t safi; - int dodir[BGP_VPN_POLICY_DIR_MAX] = {0}; - vpn_policy_direction_t dir; - - af_dnode = yang_dnode_get_parent(args->dnode, "afi-safi"); - af_name = yang_dnode_get_string(af_dnode, "./afi-safi-name"); - yang_afi_safi_identity2value(af_name, &afi, &safi); - bgp = nb_running_get_entry(af_dnode, NULL, true); - - if (!strcmp(dstr, "import")) { - dodir[BGP_VPN_POLICY_DIR_FROMVPN] = 1; - } else if (!strcmp(dstr, "export")) { - dodir[BGP_VPN_POLICY_DIR_TOVPN] = 1; - } else if (!strcmp(dstr, "both")) { - dodir[BGP_VPN_POLICY_DIR_FROMVPN] = 1; - dodir[BGP_VPN_POLICY_DIR_TOVPN] = 1; - } - - for (dir = 0; dir < BGP_VPN_POLICY_DIR_MAX; ++dir) { - if (!dodir[dir]) - continue; - - vpn_leak_prechange(dir, afi, bgp_get_default(), bgp); - - if (bgp->vpn_policy[afi].rmap_name[dir]) - XFREE(MTYPE_ROUTE_MAP_NAME, - bgp->vpn_policy[afi].rmap_name[dir]); - bgp->vpn_policy[afi].rmap_name[dir] = NULL; - bgp->vpn_policy[afi].rmap[dir] = NULL; - - vpn_leak_postchange(dir, afi, bgp_get_default(), bgp); + /* TODO: implement me. */ + break; } return NB_OK; @@ -7443,31 +6426,13 @@ static int bgp_global_afi_safi_ip_unicast_vpn_config_rmap_import_destroy( int bgp_global_afi_safis_afi_safi_ipv4_unicast_vpn_config_rmap_import_modify( struct nb_cb_modify_args *args) { - struct bgp *bgp; - const struct lyd_node *af_dnode; - const char *af_name; - afi_t afi; - safi_t safi; - switch (args->event) { case NB_EV_VALIDATE: - bgp = nb_running_get_entry(args->dnode, NULL, false); - if (!bgp) - return NB_OK; - af_dnode = yang_dnode_get_parent(args->dnode, "afi-safi"); - af_name = yang_dnode_get_string(af_dnode, "./afi-safi-name"); - yang_afi_safi_identity2value(af_name, &afi, &safi); - - if (!vpn_policy_check_import(bgp, afi, safi, false, - args->errmsg, args->errmsg_len)) - return NB_ERR_VALIDATION; - break; case NB_EV_PREPARE: case NB_EV_ABORT: - return NB_OK; case NB_EV_APPLY: - return bgp_global_afi_safi_ip_unicast_vpn_config_rmap_import_modify( - args, "import"); + /* TODO: implement me. */ + break; } return NB_OK; @@ -7476,31 +6441,13 @@ int bgp_global_afi_safis_afi_safi_ipv4_unicast_vpn_config_rmap_import_modify( int bgp_global_afi_safis_afi_safi_ipv4_unicast_vpn_config_rmap_import_destroy( struct nb_cb_destroy_args *args) { - struct bgp *bgp; - const struct lyd_node *af_dnode; - const char *af_name; - afi_t afi; - safi_t safi; - switch (args->event) { case NB_EV_VALIDATE: - bgp = nb_running_get_entry(args->dnode, NULL, false); - if (!bgp) - return NB_OK; - af_dnode = yang_dnode_get_parent(args->dnode, "afi-safi"); - af_name = yang_dnode_get_string(af_dnode, "./afi-safi-name"); - yang_afi_safi_identity2value(af_name, &afi, &safi); - - if (!vpn_policy_check_import(bgp, afi, safi, false, - args->errmsg, args->errmsg_len)) - return NB_ERR_VALIDATION; - break; case NB_EV_PREPARE: case NB_EV_ABORT: - return NB_OK; case NB_EV_APPLY: - return bgp_global_afi_safi_ip_unicast_vpn_config_rmap_import_destroy( - args, "import"); + /* TODO: implement me. */ + break; } return NB_OK; @@ -7517,10 +6464,9 @@ int bgp_global_afi_safis_afi_safi_ipv4_unicast_vpn_config_rmap_export_modify( case NB_EV_VALIDATE: case NB_EV_PREPARE: case NB_EV_ABORT: - return NB_OK; case NB_EV_APPLY: - return bgp_global_afi_safi_ip_unicast_vpn_config_rmap_import_modify( - args, "export"); + /* TODO: implement me. */ + break; } return NB_OK; @@ -7533,10 +6479,8 @@ int bgp_global_afi_safis_afi_safi_ipv4_unicast_vpn_config_rmap_export_destroy( case NB_EV_VALIDATE: case NB_EV_PREPARE: case NB_EV_ABORT: - return NB_OK; case NB_EV_APPLY: - return bgp_global_afi_safi_ip_unicast_vpn_config_rmap_import_destroy( - args, "export"); + /* TODO: implement me. */ break; } @@ -7686,7 +6630,14 @@ int bgp_global_afi_safis_afi_safi_ipv4_unicast_vpn_config_rt_list_destroy( int bgp_global_afi_safis_afi_safi_ipv6_unicast_network_config_create( struct nb_cb_create_args *args) { - /* Handled in network_config_apply_finish callback */ + switch (args->event) { + case NB_EV_VALIDATE: + case NB_EV_PREPARE: + case NB_EV_ABORT: + case NB_EV_APPLY: + /* TODO: implement me. */ + break; + } return NB_OK; } @@ -7698,10 +6649,8 @@ int bgp_global_afi_safis_afi_safi_ipv6_unicast_network_config_destroy( case NB_EV_VALIDATE: case NB_EV_PREPARE: case NB_EV_ABORT: - return NB_OK; case NB_EV_APPLY: - return bgp_global_afi_safis_afi_safi_network_config_destroy( - args); + /* TODO: implement me. */ break; } @@ -7715,7 +6664,14 @@ int bgp_global_afi_safis_afi_safi_ipv6_unicast_network_config_destroy( int bgp_global_afi_safis_afi_safi_ipv6_unicast_network_config_backdoor_modify( struct nb_cb_modify_args *args) { - /* Handled in unicast_network_config_apply_finish callback */ + switch (args->event) { + case NB_EV_VALIDATE: + case NB_EV_PREPARE: + case NB_EV_ABORT: + case NB_EV_APPLY: + /* TODO: implement me. */ + break; + } return NB_OK; } @@ -7727,7 +6683,14 @@ int bgp_global_afi_safis_afi_safi_ipv6_unicast_network_config_backdoor_modify( int bgp_global_afi_safis_afi_safi_ipv6_unicast_network_config_label_index_modify( struct nb_cb_modify_args *args) { - /* Handled in unicast_network_config_apply_finish callback */ + switch (args->event) { + case NB_EV_VALIDATE: + case NB_EV_PREPARE: + case NB_EV_ABORT: + case NB_EV_APPLY: + /* TODO: implement me. */ + break; + } return NB_OK; } @@ -7754,7 +6717,14 @@ int bgp_global_afi_safis_afi_safi_ipv6_unicast_network_config_label_index_destro int bgp_global_afi_safis_afi_safi_ipv6_unicast_network_config_rmap_policy_export_modify( struct nb_cb_modify_args *args) { - /* Handled in unicast_network_config_apply_finish callback */ + switch (args->event) { + case NB_EV_VALIDATE: + case NB_EV_PREPARE: + case NB_EV_ABORT: + case NB_EV_APPLY: + /* TODO: implement me. */ + break; + } return NB_OK; } @@ -7800,9 +6770,9 @@ int bgp_global_afi_safis_afi_safi_ipv6_unicast_aggregate_route_destroy( case NB_EV_VALIDATE: case NB_EV_PREPARE: case NB_EV_ABORT: - return NB_OK; case NB_EV_APPLY: - return bgp_global_afi_safi_aggregate_route_destroy(args); + /* TODO: implement me. */ + break; } return NB_OK; @@ -7925,9 +6895,9 @@ int bgp_global_afi_safis_afi_safi_ipv6_unicast_admin_distance_route_destroy( case NB_EV_VALIDATE: case NB_EV_PREPARE: case NB_EV_ABORT: - return NB_OK; case NB_EV_APPLY: - return bgp_global_afi_safi_admin_distance_route_destroy(args); + /* TODO: implement me. */ + break; } return NB_OK; @@ -7995,10 +6965,10 @@ int bgp_global_afi_safis_afi_safi_ipv6_unicast_route_flap_dampening_enable_modif { switch (args->event) { case NB_EV_VALIDATE: - return bgp_global_afi_safi_route_flap_validation(args); case NB_EV_PREPARE: case NB_EV_ABORT: case NB_EV_APPLY: + /* TODO: implement me. */ break; } @@ -8046,22 +7016,8 @@ int bgp_global_afi_safis_afi_safi_ipv6_unicast_route_flap_dampening_reach_decay_ int bgp_global_afi_safis_afi_safi_ipv6_unicast_route_flap_dampening_reuse_above_modify( struct nb_cb_modify_args *args) { - int reuse = DEFAULT_REUSE; - int suppress = DEFAULT_SUPPRESS; - switch (args->event) { case NB_EV_VALIDATE: - if (yang_dnode_exists(args->dnode, "../suppress-above")) - suppress = yang_dnode_get_uint16(args->dnode, - "../suppress-above"); - reuse = yang_dnode_get_uint16(args->dnode, "../reuse-above"); - if (suppress < reuse) { - snprintf( - args->errmsg, args->errmsg_len, - "Suppress value cannot be less than reuse value \n"); - return NB_ERR_VALIDATION; - } - break; case NB_EV_PREPARE: case NB_EV_ABORT: case NB_EV_APPLY: @@ -8162,24 +7118,13 @@ int bgp_global_afi_safis_afi_safi_ipv6_unicast_route_flap_dampening_unreach_deca int bgp_global_afi_safis_afi_safi_ipv6_unicast_use_multiple_paths_ebgp_maximum_paths_modify( struct nb_cb_modify_args *args) { - uint16_t maxpaths; - switch (args->event) { case NB_EV_VALIDATE: - maxpaths = yang_dnode_get_uint16(args->dnode, NULL); - if (maxpaths > MULTIPATH_NUM) { - snprintf(args->errmsg, args->errmsg_len, - "maxpaths %u is out of range %u", maxpaths, - MULTIPATH_NUM); - return NB_ERR_VALIDATION; - } - break; case NB_EV_PREPARE: case NB_EV_ABORT: - return NB_OK; case NB_EV_APPLY: - return bgp_global_afi_safi_ip_unicast_use_multiple_paths_ebgp_maximum_paths_modify( - args); + /* TODO: implement me. */ + break; } return NB_OK; @@ -8260,31 +7205,12 @@ int bgp_global_afi_safis_afi_safi_ipv6_unicast_redistribution_list_create( int bgp_global_afi_safis_afi_safi_ipv6_unicast_redistribution_list_destroy( struct nb_cb_destroy_args *args) { - const struct lyd_node *af_dnode; - struct bgp *bgp; - const char *af_name; - afi_t afi; - safi_t safi; - int route_type; - int route_instance; - switch (args->event) { case NB_EV_VALIDATE: case NB_EV_PREPARE: case NB_EV_ABORT: - return NB_OK; case NB_EV_APPLY: - af_dnode = yang_dnode_get_parent(args->dnode, "afi-safi"); - af_name = yang_dnode_get_string(af_dnode, "./afi-safi-name"); - yang_afi_safi_identity2value(af_name, &afi, &safi); - bgp = nb_running_get_entry(af_dnode, NULL, true); - - route_type = yang_dnode_get_enum(args->dnode, "./route-type"); - route_instance = - yang_dnode_get_uint16(args->dnode, "./route-instance"); - - bgp_redistribute_unset(bgp, afi, route_type, route_instance); - + /* TODO: implement me. */ break; } @@ -8359,16 +7285,6 @@ int bgp_global_afi_safis_afi_safi_ipv6_unicast_redistribution_list_rmap_policy_i return NB_OK; } -/* - * XPath: - * /frr-routing:routing/control-plane-protocols/control-plane-protocol/frr-bgp:bgp/global/afi-safis/afi-safi/ipv6-unicast/admin-distance - */ -void bgp_global_afi_safis_afi_safi_ipv6_unicast_admin_distance_apply_finish( - struct nb_cb_apply_finish_args *args) -{ - bgp_global_afi_safis_admin_distance_modify(args); -} - /* * XPath: * /frr-routing:routing/control-plane-protocols/control-plane-protocol/frr-bgp:bgp/global/afi-safis/afi-safi/ipv6-unicast/admin-distance/external @@ -8376,7 +7292,14 @@ void bgp_global_afi_safis_afi_safi_ipv6_unicast_admin_distance_apply_finish( int bgp_global_afi_safis_afi_safi_ipv6_unicast_admin_distance_external_modify( struct nb_cb_modify_args *args) { - /* Handled in admin_distance_apply_finish callback */ + switch (args->event) { + case NB_EV_VALIDATE: + case NB_EV_PREPARE: + case NB_EV_ABORT: + case NB_EV_APPLY: + /* TODO: implement me. */ + break; + } return NB_OK; } @@ -8388,7 +7311,14 @@ int bgp_global_afi_safis_afi_safi_ipv6_unicast_admin_distance_external_modify( int bgp_global_afi_safis_afi_safi_ipv6_unicast_admin_distance_internal_modify( struct nb_cb_modify_args *args) { - /* Handled in admin_distance_apply_finish callback */ + switch (args->event) { + case NB_EV_VALIDATE: + case NB_EV_PREPARE: + case NB_EV_ABORT: + case NB_EV_APPLY: + /* TODO: implement me. */ + break; + } return NB_OK; } @@ -8400,7 +7330,14 @@ int bgp_global_afi_safis_afi_safi_ipv6_unicast_admin_distance_internal_modify( int bgp_global_afi_safis_afi_safi_ipv6_unicast_admin_distance_local_modify( struct nb_cb_modify_args *args) { - /* Handled in admin_distance_apply_finish callback */ + switch (args->event) { + case NB_EV_VALIDATE: + case NB_EV_PREPARE: + case NB_EV_ABORT: + case NB_EV_APPLY: + /* TODO: implement me. */ + break; + } return NB_OK; } @@ -8446,33 +7383,13 @@ int bgp_global_afi_safis_afi_safi_ipv6_unicast_filter_config_rmap_export_destroy int bgp_global_afi_safis_afi_safi_ipv6_unicast_vpn_config_rd_modify( struct nb_cb_modify_args *args) { - struct bgp *bgp; - const struct lyd_node *af_dnode; - const char *af_name; - afi_t afi; - safi_t safi; - switch (args->event) { case NB_EV_VALIDATE: - bgp = nb_running_get_entry(args->dnode, NULL, false); - if (!bgp) - return NB_OK; - - af_dnode = yang_dnode_get_parent(args->dnode, "afi-safi"); - af_name = yang_dnode_get_string(af_dnode, "./afi-safi-name"); - yang_afi_safi_identity2value(af_name, &afi, &safi); - - if (!vpn_policy_check_import(bgp, afi, safi, false, - args->errmsg, args->errmsg_len)) - return NB_ERR_VALIDATION; - - break; case NB_EV_PREPARE: case NB_EV_ABORT: - return NB_OK; case NB_EV_APPLY: - return bgp_global_afi_safi_ip_unicast_vpn_config_rd_modify( - args); + /* TODO: implement me. */ + break; } return NB_OK; @@ -8485,10 +7402,9 @@ int bgp_global_afi_safis_afi_safi_ipv6_unicast_vpn_config_rd_destroy( case NB_EV_VALIDATE: case NB_EV_PREPARE: case NB_EV_ABORT: - return NB_OK; case NB_EV_APPLY: - return bgp_global_afi_safi_ip_unicast_vpn_config_rd_destroy( - args); + /* TODO: implement me. */ + break; } return NB_OK; @@ -8569,33 +7485,13 @@ int bgp_global_afi_safis_afi_safi_ipv6_unicast_vpn_config_label_auto_destroy( int bgp_global_afi_safis_afi_safi_ipv6_unicast_vpn_config_nexthop_modify( struct nb_cb_modify_args *args) { - struct bgp *bgp; - const struct lyd_node *af_dnode; - const char *af_name; - afi_t afi; - safi_t safi; - switch (args->event) { case NB_EV_VALIDATE: - bgp = nb_running_get_entry(args->dnode, NULL, false); - if (!bgp) - return NB_OK; - - af_dnode = yang_dnode_get_parent(args->dnode, "afi-safi"); - af_name = yang_dnode_get_string(af_dnode, "./afi-safi-name"); - yang_afi_safi_identity2value(af_name, &afi, &safi); - - if (!vpn_policy_check_import(bgp, afi, safi, false, - args->errmsg, args->errmsg_len)) - return NB_ERR_VALIDATION; - - break; case NB_EV_PREPARE: case NB_EV_ABORT: - return NB_OK; case NB_EV_APPLY: - return bgp_global_afi_safi_ip_unicast_vpn_config_nexthop_modify( - args); + /* TODO: implement me. */ + break; } return NB_OK; @@ -8608,10 +7504,9 @@ int bgp_global_afi_safis_afi_safi_ipv6_unicast_vpn_config_nexthop_destroy( case NB_EV_VALIDATE: case NB_EV_PREPARE: case NB_EV_ABORT: - return NB_OK; case NB_EV_APPLY: - return bgp_global_afi_safi_ip_unicast_vpn_config_nexthop_destroy( - args); + /* TODO: implement me. */ + break; } return NB_OK; @@ -8662,32 +7557,13 @@ int bgp_global_afi_safis_afi_safi_ipv6_unicast_vpn_config_export_vpn_modify( int bgp_global_afi_safis_afi_safi_ipv6_unicast_vpn_config_import_vrf_list_create( struct nb_cb_create_args *args) { - struct bgp *bgp; - const struct lyd_node *af_dnode; - const char *af_name; - afi_t afi; - safi_t safi; - switch (args->event) { case NB_EV_VALIDATE: - bgp = nb_running_get_entry(args->dnode, NULL, false); - if (!bgp) - return NB_OK; - af_dnode = yang_dnode_get_parent(args->dnode, "afi-safi"); - af_name = yang_dnode_get_string(af_dnode, "./afi-safi-name"); - yang_afi_safi_identity2value(af_name, &afi, &safi); - - if (!vpn_policy_check_import(bgp, afi, safi, true, args->errmsg, - args->errmsg_len)) - return NB_ERR_VALIDATION; - - break; case NB_EV_PREPARE: case NB_EV_ABORT: - return NB_OK; case NB_EV_APPLY: - return bgp_global_afi_safi_ip_unicast_vpn_config_import_vrfs_create( - args); + /* TODO: implement me. */ + break; } return NB_OK; @@ -8700,10 +7576,9 @@ int bgp_global_afi_safis_afi_safi_ipv6_unicast_vpn_config_import_vrf_list_destro case NB_EV_VALIDATE: case NB_EV_PREPARE: case NB_EV_ABORT: - return NB_OK; case NB_EV_APPLY: - return bgp_global_afi_safi_ip_unicast_vpn_config_import_vrf_list_destroy( - args); + /* TODO: implement me. */ + break; } return NB_OK; @@ -8720,10 +7595,9 @@ int bgp_global_afi_safis_afi_safi_ipv6_unicast_vpn_config_rmap_import_modify( case NB_EV_VALIDATE: case NB_EV_PREPARE: case NB_EV_ABORT: - return NB_OK; case NB_EV_APPLY: - return bgp_global_afi_safi_ip_unicast_vpn_config_rmap_import_modify( - args, "import"); + /* TODO: implement me. */ + break; } return NB_OK; @@ -8736,10 +7610,9 @@ int bgp_global_afi_safis_afi_safi_ipv6_unicast_vpn_config_rmap_import_destroy( case NB_EV_VALIDATE: case NB_EV_PREPARE: case NB_EV_ABORT: - return NB_OK; case NB_EV_APPLY: - return bgp_global_afi_safi_ip_unicast_vpn_config_rmap_import_destroy( - args, "import"); + /* TODO: implement me. */ + break; } return NB_OK; @@ -8756,10 +7629,9 @@ int bgp_global_afi_safis_afi_safi_ipv6_unicast_vpn_config_rmap_export_modify( case NB_EV_VALIDATE: case NB_EV_PREPARE: case NB_EV_ABORT: - return NB_OK; case NB_EV_APPLY: - return bgp_global_afi_safi_ip_unicast_vpn_config_rmap_import_modify( - args, "export"); + /* TODO: implement me. */ + break; } return NB_OK; @@ -8772,10 +7644,9 @@ int bgp_global_afi_safis_afi_safi_ipv6_unicast_vpn_config_rmap_export_destroy( case NB_EV_VALIDATE: case NB_EV_PREPARE: case NB_EV_ABORT: - return NB_OK; case NB_EV_APPLY: - return bgp_global_afi_safi_ip_unicast_vpn_config_rmap_import_destroy( - args, "export"); + /* TODO: implement me. */ + break; } return NB_OK; @@ -8924,24 +7795,13 @@ int bgp_global_afi_safis_afi_safi_ipv6_unicast_vpn_config_rt_list_destroy( int bgp_global_afi_safis_afi_safi_ipv4_labeled_unicast_use_multiple_paths_ebgp_maximum_paths_modify( struct nb_cb_modify_args *args) { - uint16_t maxpaths; - switch (args->event) { case NB_EV_VALIDATE: - maxpaths = yang_dnode_get_uint16(args->dnode, NULL); - if (maxpaths > MULTIPATH_NUM) { - snprintf(args->errmsg, args->errmsg_len, - "maxpaths %u is out of range %u", maxpaths, - MULTIPATH_NUM); - return NB_ERR_VALIDATION; - } - break; case NB_EV_PREPARE: case NB_EV_ABORT: - return NB_OK; case NB_EV_APPLY: - return bgp_global_afi_safi_ip_unicast_use_multiple_paths_ebgp_maximum_paths_modify( - args); + /* TODO: implement me. */ + break; } return NB_OK; @@ -9009,10 +7869,10 @@ int bgp_global_afi_safis_afi_safi_ipv4_labeled_unicast_route_flap_dampening_enab { switch (args->event) { case NB_EV_VALIDATE: - return bgp_global_afi_safi_route_flap_validation(args); case NB_EV_PREPARE: case NB_EV_ABORT: case NB_EV_APPLY: + /* TODO: implement me. */ break; } @@ -9162,24 +8022,13 @@ int bgp_global_afi_safis_afi_safi_ipv4_labeled_unicast_route_flap_dampening_unre int bgp_global_afi_safis_afi_safi_ipv6_labeled_unicast_use_multiple_paths_ebgp_maximum_paths_modify( struct nb_cb_modify_args *args) { - uint16_t maxpaths; - switch (args->event) { case NB_EV_VALIDATE: - maxpaths = yang_dnode_get_uint16(args->dnode, NULL); - if (maxpaths > MULTIPATH_NUM) { - snprintf(args->errmsg, args->errmsg_len, - "maxpaths %u is out of range %u", maxpaths, - MULTIPATH_NUM); - return NB_ERR_VALIDATION; - } - break; case NB_EV_PREPARE: case NB_EV_ABORT: - return NB_OK; case NB_EV_APPLY: - return bgp_global_afi_safi_ip_unicast_use_multiple_paths_ebgp_maximum_paths_modify( - args); + /* TODO: implement me. */ + break; } return NB_OK; @@ -9192,18 +8041,8 @@ int bgp_global_afi_safis_afi_safi_ipv6_labeled_unicast_use_multiple_paths_ebgp_m int bgp_global_afi_safis_afi_safi_ipv6_labeled_unicast_use_multiple_paths_ibgp_maximum_paths_modify( struct nb_cb_modify_args *args) { - uint16_t maxpaths; - switch (args->event) { case NB_EV_VALIDATE: - maxpaths = yang_dnode_get_uint16(args->dnode, NULL); - if (maxpaths > MULTIPATH_NUM) { - snprintf(args->errmsg, args->errmsg_len, - "maxpaths %u is out of range %u", maxpaths, - MULTIPATH_NUM); - return NB_ERR_VALIDATION; - } - break; case NB_EV_PREPARE: case NB_EV_ABORT: case NB_EV_APPLY: @@ -9257,10 +8096,10 @@ int bgp_global_afi_safis_afi_safi_ipv6_labeled_unicast_route_flap_dampening_enab { switch (args->event) { case NB_EV_VALIDATE: - return bgp_global_afi_safi_route_flap_validation(args); case NB_EV_PREPARE: case NB_EV_ABORT: case NB_EV_APPLY: + /* TODO: implement me. */ break; } @@ -9410,7 +8249,14 @@ int bgp_global_afi_safis_afi_safi_ipv6_labeled_unicast_route_flap_dampening_unre int bgp_global_afi_safis_afi_safi_ipv4_multicast_network_config_create( struct nb_cb_create_args *args) { - /* Handled in network_config_apply_finish callback */ + switch (args->event) { + case NB_EV_VALIDATE: + case NB_EV_PREPARE: + case NB_EV_ABORT: + case NB_EV_APPLY: + /* TODO: implement me. */ + break; + } return NB_OK; } @@ -9422,10 +8268,8 @@ int bgp_global_afi_safis_afi_safi_ipv4_multicast_network_config_destroy( case NB_EV_VALIDATE: case NB_EV_PREPARE: case NB_EV_ABORT: - return NB_OK; case NB_EV_APPLY: - return bgp_global_afi_safis_afi_safi_network_config_destroy( - args); + /* TODO: implement me. */ break; } @@ -9670,9 +8514,9 @@ int bgp_global_afi_safis_afi_safi_ipv4_multicast_admin_distance_route_destroy( case NB_EV_VALIDATE: case NB_EV_PREPARE: case NB_EV_ABORT: - return NB_OK; case NB_EV_APPLY: - return bgp_global_afi_safi_admin_distance_route_destroy(args); + /* TODO: implement me. */ + break; } return NB_OK; @@ -9793,10 +8637,10 @@ int bgp_global_afi_safis_afi_safi_ipv6_multicast_route_flap_dampening_enable_mod { switch (args->event) { case NB_EV_VALIDATE: - return bgp_global_afi_safi_route_flap_validation(args); case NB_EV_PREPARE: case NB_EV_ABORT: case NB_EV_APPLY: + /* TODO: implement me. */ break; } @@ -9939,16 +8783,6 @@ int bgp_global_afi_safis_afi_safi_ipv6_multicast_route_flap_dampening_unreach_de return NB_OK; } -/* - * XPath: - * /frr-routing:routing/control-plane-protocols/control-plane-protocol/frr-bgp:bgp/global/afi-safis/afi-safi/ipv4-multicast/admin-distance - */ -void bgp_global_afi_safis_afi_safi_ipv4_multicast_admin_distance_apply_finish( - struct nb_cb_apply_finish_args *args) -{ - bgp_global_afi_safis_admin_distance_modify(args); -} - /* * XPath: * /frr-routing:routing/control-plane-protocols/control-plane-protocol/frr-bgp:bgp/global/afi-safis/afi-safi/ipv4-multicast/admin-distance/external @@ -9956,7 +8790,14 @@ void bgp_global_afi_safis_afi_safi_ipv4_multicast_admin_distance_apply_finish( int bgp_global_afi_safis_afi_safi_ipv4_multicast_admin_distance_external_modify( struct nb_cb_modify_args *args) { - /* Handled in admin_distance_apply_finish callback */ + switch (args->event) { + case NB_EV_VALIDATE: + case NB_EV_PREPARE: + case NB_EV_ABORT: + case NB_EV_APPLY: + /* TODO: implement me. */ + break; + } return NB_OK; } @@ -9968,7 +8809,14 @@ int bgp_global_afi_safis_afi_safi_ipv4_multicast_admin_distance_external_modify( int bgp_global_afi_safis_afi_safi_ipv4_multicast_admin_distance_internal_modify( struct nb_cb_modify_args *args) { - /* Handled in admin_distance_apply_finish callback */ + switch (args->event) { + case NB_EV_VALIDATE: + case NB_EV_PREPARE: + case NB_EV_ABORT: + case NB_EV_APPLY: + /* TODO: implement me. */ + break; + } return NB_OK; } @@ -9980,7 +8828,14 @@ int bgp_global_afi_safis_afi_safi_ipv4_multicast_admin_distance_internal_modify( int bgp_global_afi_safis_afi_safi_ipv4_multicast_admin_distance_local_modify( struct nb_cb_modify_args *args) { - /* Handled in admin_distance_apply_finish callback */ + switch (args->event) { + case NB_EV_VALIDATE: + case NB_EV_PREPARE: + case NB_EV_ABORT: + case NB_EV_APPLY: + /* TODO: implement me. */ + break; + } return NB_OK; } @@ -9994,10 +8849,10 @@ int bgp_global_afi_safis_afi_safi_ipv4_multicast_route_flap_dampening_enable_mod { switch (args->event) { case NB_EV_VALIDATE: - return bgp_global_afi_safi_route_flap_validation(args); case NB_EV_PREPARE: case NB_EV_ABORT: case NB_EV_APPLY: + /* TODO: implement me. */ break; } @@ -10181,7 +9036,14 @@ int bgp_global_afi_safis_afi_safi_ipv4_multicast_filter_config_rmap_export_destr int bgp_global_afi_safis_afi_safi_ipv6_multicast_network_config_create( struct nb_cb_create_args *args) { - /* Handled in network_config_apply_finish callback */ + switch (args->event) { + case NB_EV_VALIDATE: + case NB_EV_PREPARE: + case NB_EV_ABORT: + case NB_EV_APPLY: + /* TODO: implement me. */ + break; + } return NB_OK; } @@ -10193,11 +9055,8 @@ int bgp_global_afi_safis_afi_safi_ipv6_multicast_network_config_destroy( case NB_EV_VALIDATE: case NB_EV_PREPARE: case NB_EV_ABORT: - return NB_OK; case NB_EV_APPLY: - return bgp_global_afi_safis_afi_safi_network_config_destroy( - args); - + /* TODO: implement me. */ break; } @@ -10442,24 +9301,14 @@ int bgp_global_afi_safis_afi_safi_ipv6_multicast_admin_distance_route_destroy( case NB_EV_VALIDATE: case NB_EV_PREPARE: case NB_EV_ABORT: - return NB_OK; case NB_EV_APPLY: - return bgp_global_afi_safi_admin_distance_route_destroy(args); + /* TODO: implement me. */ + break; } return NB_OK; } -/* - * XPath: - * /frr-routing:routing/control-plane-protocols/control-plane-protocol/frr-bgp:bgp/global/afi-safis/afi-safi/ipv4-multicast/admin-distance - */ -void bgp_global_afi_safis_afi_safi_ipv6_multicast_admin_distance_apply_finish( - struct nb_cb_apply_finish_args *args) -{ - bgp_global_afi_safis_admin_distance_modify(args); -} - /* * XPath: * /frr-routing:routing/control-plane-protocols/control-plane-protocol/frr-bgp:bgp/global/afi-safis/afi-safi/ipv6-multicast/admin-distance/external @@ -10467,7 +9316,14 @@ void bgp_global_afi_safis_afi_safi_ipv6_multicast_admin_distance_apply_finish( int bgp_global_afi_safis_afi_safi_ipv6_multicast_admin_distance_external_modify( struct nb_cb_modify_args *args) { - /* Handled in admin_distance_apply_finish callback */ + switch (args->event) { + case NB_EV_VALIDATE: + case NB_EV_PREPARE: + case NB_EV_ABORT: + case NB_EV_APPLY: + /* TODO: implement me. */ + break; + } return NB_OK; } @@ -10479,7 +9335,14 @@ int bgp_global_afi_safis_afi_safi_ipv6_multicast_admin_distance_external_modify( int bgp_global_afi_safis_afi_safi_ipv6_multicast_admin_distance_internal_modify( struct nb_cb_modify_args *args) { - /* Handled in admin_distance_apply_finish callback */ + switch (args->event) { + case NB_EV_VALIDATE: + case NB_EV_PREPARE: + case NB_EV_ABORT: + case NB_EV_APPLY: + /* TODO: implement me. */ + break; + } return NB_OK; } @@ -10491,7 +9354,14 @@ int bgp_global_afi_safis_afi_safi_ipv6_multicast_admin_distance_internal_modify( int bgp_global_afi_safis_afi_safi_ipv6_multicast_admin_distance_local_modify( struct nb_cb_modify_args *args) { - /* Handled in admin_distance_apply_finish callback */ + switch (args->event) { + case NB_EV_VALIDATE: + case NB_EV_PREPARE: + case NB_EV_ABORT: + case NB_EV_APPLY: + /* TODO: implement me. */ + break; + } return NB_OK; } diff --git a/bgpd/bgp_route.c b/bgpd/bgp_route.c index ee4dd8281f..e9731e0507 100644 --- a/bgpd/bgp_route.c +++ b/bgpd/bgp_route.c @@ -87,9 +87,6 @@ #include "bgpd/bgp_flowspec.h" #include "bgpd/bgp_flowspec_util.h" #include "bgpd/bgp_pbr.h" -#include "northbound.h" -#include "northbound_cli.h" -#include "bgpd/bgp_nb.h" #ifndef VTYSH_EXTRACT_PL #include "bgpd/bgp_route_clippy.c" @@ -5830,16 +5827,28 @@ static void bgp_static_update_safi(struct bgp *bgp, const struct prefix *p, /* Configure static BGP network. When user don't run zebra, static route should be installed as valid. */ -int bgp_static_set(struct bgp *bgp, const char *negate, struct prefix *pfx, - afi_t afi, safi_t safi, const char *rmap, int backdoor, - uint32_t label_index, char *errmsg, size_t errmsg_len) +static int bgp_static_set(struct vty *vty, const char *negate, + const char *ip_str, afi_t afi, safi_t safi, + const char *rmap, int backdoor, uint32_t label_index) { + VTY_DECLVAR_CONTEXT(bgp, bgp); + int ret; struct prefix p; struct bgp_static *bgp_static; struct bgp_dest *dest; uint8_t need_update = 0; - prefix_copy(&p, pfx); + /* Convert IP prefix string to struct prefix. */ + ret = str2prefix(ip_str, &p); + if (!ret) { + vty_out(vty, "%% Malformed prefix\n"); + return CMD_WARNING_CONFIG_FAILED; + } + if (afi == AFI_IP6 && IN6_IS_ADDR_LINKLOCAL(&p.u.prefix6)) { + vty_out(vty, "%% Malformed prefix (link-local address)\n"); + return CMD_WARNING_CONFIG_FAILED; + } + apply_mask(&p); if (negate) { @@ -5848,25 +5857,24 @@ int bgp_static_set(struct bgp *bgp, const char *negate, struct prefix *pfx, dest = bgp_node_lookup(bgp->route[afi][safi], &p); if (!dest) { - snprintf(errmsg, errmsg_len, - "Can't find static route specified\n"); - return -1; + vty_out(vty, "%% Can't find static route specified\n"); + return CMD_WARNING_CONFIG_FAILED; } bgp_static = bgp_dest_get_bgp_static_info(dest); if ((label_index != BGP_INVALID_LABEL_INDEX) && (label_index != bgp_static->label_index)) { - snprintf(errmsg, errmsg_len, - "label-index doesn't match static route\n"); - return -1; + vty_out(vty, + "%% label-index doesn't match static route\n"); + return CMD_WARNING_CONFIG_FAILED; } if ((rmap && bgp_static->rmap.name) && strcmp(rmap, bgp_static->rmap.name)) { - snprintf(errmsg, errmsg_len, - "route-map name doesn't match static route\n"); - return -1; + vty_out(vty, + "%% route-map name doesn't match static route\n"); + return CMD_WARNING_CONFIG_FAILED; } /* Update BGP RIB. */ @@ -5887,9 +5895,8 @@ int bgp_static_set(struct bgp *bgp, const char *negate, struct prefix *pfx, /* Configuration change. */ /* Label index cannot be changed. */ if (bgp_static->label_index != label_index) { - snprintf(errmsg, errmsg_len, - "cannot change label-index\n"); - return -1; + vty_out(vty, "%% cannot change label-index\n"); + return CMD_WARNING_CONFIG_FAILED; } /* Check previous routes are installed into BGP. */ @@ -5951,7 +5958,7 @@ int bgp_static_set(struct bgp *bgp, const char *negate, struct prefix *pfx, bgp_static_update(bgp, &p, bgp_static, afi, safi); } - return 0; + return CMD_SUCCESS; } void bgp_static_add(struct bgp *bgp) @@ -6401,27 +6408,25 @@ DEFUN (no_bgp_table_map, argv[idx_word]->arg); } -DEFPY_YANG (bgp_network, bgp_network_cmd, - "[no] network \ - \ - [{route-map WORD$map_name|label-index (0-1048560)$label_index| \ - backdoor$backdoor}]", - NO_STR - "Specify a network to announce via BGP\n" - "IPv4 prefix\n" - "Network number\n" - "Network mask\n" - "Network mask\n" - "Route-map to modify the attributes\n" - "Name of the route map\n" - "Label index to associate with the prefix\n" - "Label index value\n" - "Specify a BGP backdoor route\n") -{ - char addr_prefix_str[PREFIX_STRLEN]; - char base_xpath[XPATH_MAXLEN]; - afi_t afi; - safi_t safi; +DEFPY(bgp_network, + bgp_network_cmd, + "[no] network \ + \ + [{route-map WORD$map_name|label-index (0-1048560)$label_index| \ + backdoor$backdoor}]", + NO_STR + "Specify a network to announce via BGP\n" + "IPv4 prefix\n" + "Network number\n" + "Network mask\n" + "Network mask\n" + "Route-map to modify the attributes\n" + "Name of the route map\n" + "Label index to associate with the prefix\n" + "Label index value\n" + "Specify a BGP backdoor route\n") +{ + char addr_prefix_str[BUFSIZ]; if (address_str) { int ret; @@ -6435,102 +6440,27 @@ DEFPY_YANG (bgp_network, bgp_network_cmd, } } - afi = bgp_node_afi(vty); - safi = bgp_node_safi(vty); - - if (no) { - nb_cli_enqueue_change(vty, ".", NB_OP_DESTROY, NULL); - } else { - nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL); - - if (map_name) - nb_cli_enqueue_change(vty, "./rmap-policy-export", - NB_OP_CREATE, map_name); - else - nb_cli_enqueue_change(vty, "./rmap-policy-export", - NB_OP_DESTROY, NULL); - - if (label_index_str) - nb_cli_enqueue_change(vty, "./label-index", - NB_OP_MODIFY, label_index_str); - - nb_cli_enqueue_change(vty, "./backdoor", NB_OP_MODIFY, - backdoor ? "true" : "false"); - } - - snprintf( - base_xpath, sizeof(base_xpath), - "./global/afi-safis/afi-safi[afi-safi-name='%s']/%s/network-config[prefix='%s']", - yang_afi_safi_value2identity(afi, safi), - bgp_afi_safi_get_container_str(afi, safi), - address_str ? addr_prefix_str : prefix_str); - - return nb_cli_apply_changes(vty, base_xpath); + return bgp_static_set( + vty, no, address_str ? addr_prefix_str : prefix_str, AFI_IP, + bgp_node_safi(vty), map_name, backdoor ? 1 : 0, + label_index ? (uint32_t)label_index : BGP_INVALID_LABEL_INDEX); } -DEFPY_YANG (ipv6_bgp_network, - ipv6_bgp_network_cmd, - "[no] network X:X::X:X/M$prefix \ - [{route-map WORD$map_name|label-index (0-1048560)$label_index}]", - NO_STR - "Specify a network to announce via BGP\n" - "IPv6 prefix\n" - "Route-map to modify the attributes\n" - "Name of the route map\n" - "Label index to associate with the prefix\n" - "Label index value\n") +DEFPY(ipv6_bgp_network, + ipv6_bgp_network_cmd, + "[no] network X:X::X:X/M$prefix \ + [{route-map WORD$map_name|label-index (0-1048560)$label_index}]", + NO_STR + "Specify a network to announce via BGP\n" + "IPv6 prefix\n" + "Route-map to modify the attributes\n" + "Name of the route map\n" + "Label index to associate with the prefix\n" + "Label index value\n") { - char base_xpath[XPATH_MAXLEN]; - afi_t afi; - safi_t safi; - - afi = bgp_node_afi(vty); - safi = bgp_node_safi(vty); - - if (no) { - nb_cli_enqueue_change(vty, ".", NB_OP_DESTROY, NULL); - } else { - nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL); - - if (map_name) - nb_cli_enqueue_change(vty, "./rmap-policy-export", - NB_OP_MODIFY, map_name); - else - nb_cli_enqueue_change(vty, "./rmap-policy-export", - NB_OP_DESTROY, NULL); - - if (label_index_str) - nb_cli_enqueue_change(vty, "./label-index", - NB_OP_MODIFY, label_index_str); - } - - snprintf( - base_xpath, sizeof(base_xpath), - "./global/afi-safis/afi-safi[afi-safi-name='%s']/%s/network-config[prefix='%s']", - yang_afi_safi_value2identity(afi, safi), - bgp_afi_safi_get_container_str(afi, safi), prefix_str); - - return nb_cli_apply_changes(vty, base_xpath); -} - -void cli_show_bgp_global_afi_safi_network_config(struct vty *vty, - struct lyd_node *dnode, - bool show_defaults) -{ - vty_out(vty, " network %s", yang_dnode_get_string(dnode, "./prefix")); - - if (yang_dnode_exists(dnode, "./label-index")) - vty_out(vty, " label-index %s", - yang_dnode_get_string(dnode, "./label-index")); - - if (yang_dnode_exists(dnode, "./rmap-policy-export")) - vty_out(vty, " route-map %s", - yang_dnode_get_string(dnode, "./rmap-policy-export")); - - if (yang_dnode_get_bool(dnode, "./backdoor")) - vty_out(vty, " backdoor"); - - vty_out(vty, "\n"); + return bgp_static_set( + vty, no, prefix_str, AFI_IP6, bgp_node_safi(vty), map_name, 0, + label_index ? (uint32_t)label_index : BGP_INVALID_LABEL_INDEX); } static struct bgp_aggregate *bgp_aggregate_new(void) @@ -7606,32 +7536,35 @@ static const char *bgp_rpki_validation2str(enum rpki_states v_state) return "ERROR"; } -int bgp_aggregate_unset(struct bgp *bgp, struct prefix *prefix, afi_t afi, - safi_t safi, char *errmsg, size_t errmsg_len) +static int bgp_aggregate_unset(struct vty *vty, const char *prefix_str, + afi_t afi, safi_t safi) { + VTY_DECLVAR_CONTEXT(bgp, bgp); + int ret; + struct prefix p; struct bgp_dest *dest; struct bgp_aggregate *aggregate; - /* If the bgp instance is being deleted or self peer is deleted - * then do not create aggregate route - */ - if (CHECK_FLAG(bgp->flags, BGP_FLAG_DELETE_IN_PROGRESS) - || (bgp->peer_self == NULL)) - return 0; + /* Convert string to prefix structure. */ + ret = str2prefix(prefix_str, &p); + if (!ret) { + vty_out(vty, "Malformed prefix\n"); + return CMD_WARNING_CONFIG_FAILED; + } + apply_mask(&p); - apply_mask(prefix); /* Old configuration check. */ - dest = bgp_node_lookup(bgp->aggregate[afi][safi], prefix); + dest = bgp_node_lookup(bgp->aggregate[afi][safi], &p); if (!dest) { - snprintf(errmsg, errmsg_len, - "There is no aggregate-address configuration.\n"); - return -1; + vty_out(vty, + "%% There is no aggregate-address configuration.\n"); + return CMD_WARNING_CONFIG_FAILED; } aggregate = bgp_dest_get_bgp_aggregate_info(dest); - bgp_aggregate_delete(bgp, prefix, afi, safi, aggregate); - bgp_aggregate_install(bgp, afi, safi, prefix, 0, NULL, NULL, NULL, NULL, - 0, aggregate); + bgp_aggregate_delete(bgp, &p, afi, safi, aggregate); + bgp_aggregate_install(bgp, afi, safi, &p, 0, NULL, NULL, + NULL, NULL, 0, aggregate); /* Unlock aggregate address configuration. */ bgp_dest_set_bgp_aggregate_info(dest, NULL); @@ -7692,53 +7625,55 @@ int bgp_aggregate_unset(struct bgp *bgp, struct prefix *prefix, afi_t afi, bgp_dest_unlock_node(dest); bgp_dest_unlock_node(dest); - return 0; + return CMD_SUCCESS; } -int bgp_aggregate_set(struct bgp *bgp, struct prefix *prefix, afi_t afi, - safi_t safi, const char *rmap, uint8_t summary_only, - uint8_t as_set, uint8_t origin, bool match_med, - const char *suppress_map, - char *errmsg, size_t errmsg_len) +static int bgp_aggregate_set(struct vty *vty, const char *prefix_str, afi_t afi, + safi_t safi, const char *rmap, + uint8_t summary_only, uint8_t as_set, + uint8_t origin, bool match_med, + const char *suppress_map) { + VTY_DECLVAR_CONTEXT(bgp, bgp); int ret; + struct prefix p; struct bgp_dest *dest; struct bgp_aggregate *aggregate; uint8_t as_set_new = as_set; - char buf[PREFIX2STR_BUFFER]; if (suppress_map && summary_only) { - snprintf(errmsg, errmsg_len, + vty_out(vty, "'summary-only' and 'suppress-map' can't be used at the same time\n"); - return -1; + return CMD_WARNING_CONFIG_FAILED; } - apply_mask(prefix); + /* Convert string to prefix structure. */ + ret = str2prefix(prefix_str, &p); + if (!ret) { + vty_out(vty, "Malformed prefix\n"); + return CMD_WARNING_CONFIG_FAILED; + } + apply_mask(&p); - if ((afi == AFI_IP && prefix->prefixlen == IPV4_MAX_BITLEN) - || (afi == AFI_IP6 && prefix->prefixlen == IPV6_MAX_BITLEN)) { - snprintf( - errmsg, errmsg_len, - "Specified prefix: %s will not result in any useful aggregation, disallowing\n", - prefix2str(prefix, buf, PREFIX_STRLEN)); - return -1; + if ((afi == AFI_IP && p.prefixlen == IPV4_MAX_BITLEN) || + (afi == AFI_IP6 && p.prefixlen == IPV6_MAX_BITLEN)) { + vty_out(vty, "Specified prefix: %s will not result in any useful aggregation, disallowing\n", + prefix_str); + return CMD_WARNING_CONFIG_FAILED; } /* Old configuration check. */ - dest = bgp_node_get(bgp->aggregate[afi][safi], prefix); + dest = bgp_node_get(bgp->aggregate[afi][safi], &p); aggregate = bgp_dest_get_bgp_aggregate_info(dest); if (aggregate) { - snprintf(errmsg, errmsg_len, - "There is already same aggregate network.\n"); + vty_out(vty, "There is already same aggregate network.\n"); /* try to remove the old entry */ - ret = bgp_aggregate_unset(bgp, prefix, afi, safi, errmsg, - errmsg_len); + ret = bgp_aggregate_unset(vty, prefix_str, afi, safi); if (ret) { - snprintf(errmsg, errmsg_len, - "Error deleting aggregate.\n"); + vty_out(vty, "Error deleting aggregate.\n"); bgp_dest_unlock_node(dest); - return -1; + return CMD_WARNING_CONFIG_FAILED; } } @@ -7761,8 +7696,7 @@ int bgp_aggregate_set(struct bgp *bgp, struct prefix *prefix, afi_t afi, zlog_warn( "%s: Ignoring as-set because `bgp reject-as-sets` is enabled.", __func__); - snprintf( - errmsg, errmsg_len, + vty_out(vty, "Ignoring as-set because `bgp reject-as-sets` is enabled.\n"); } } @@ -7799,39 +7733,39 @@ int bgp_aggregate_set(struct bgp *bgp, struct prefix *prefix, afi_t afi, bgp_dest_set_bgp_aggregate_info(dest, aggregate); /* Aggregate address insert into BGP routing table. */ - bgp_aggregate_route(bgp, prefix, afi, safi, aggregate); + bgp_aggregate_route(bgp, &p, afi, safi, aggregate); - return 0; + return CMD_SUCCESS; } -DEFPY_YANG( - aggregate_addressv4, aggregate_addressv4_cmd, - "[no] aggregate-address {" - "as-set$as_set_s" - "|summary-only$summary_only" - "|route-map WORD$rmap_name" - "|origin $origin_s" - "|matching-MED-only$match_med" - "}", - NO_STR - "Configure BGP aggregate entries\n" - "Aggregate prefix\n" - "Aggregate address\n" - "Aggregate mask\n" - "Generate AS set path information\n" - "Filter more specific routes from updates\n" - "Apply route map to aggregate network\n" - "Route map name\n" - "BGP origin code\n" - "Remote EGP\n" - "Local IGP\n" - "Unknown heritage\n" - "Only aggregate routes with matching MED\n" - "Suppress the selected more specific routes\n" - "Route map with the route selectors\n") -{ - char base_xpath[XPATH_MAXLEN]; +DEFPY(aggregate_addressv4, aggregate_addressv4_cmd, + "[no] aggregate-address {" + "as-set$as_set_s" + "|summary-only$summary_only" + "|route-map WORD$rmap_name" + "|origin $origin_s" + "|matching-MED-only$match_med" + "|suppress-map WORD$suppress_map" + "}", + NO_STR + "Configure BGP aggregate entries\n" + "Aggregate prefix\n" "Aggregate address\n" "Aggregate mask\n" + "Generate AS set path information\n" + "Filter more specific routes from updates\n" + "Apply route map to aggregate network\n" + "Route map name\n" + "BGP origin code\n" + "Remote EGP\n" + "Local IGP\n" + "Unknown heritage\n" + "Only aggregate routes with matching MED\n" + "Suppress the selected more specific routes\n" + "Route map with the route selectors\n") +{ + const char *prefix_s = NULL; safi_t safi = bgp_node_safi(vty); + uint8_t origin = BGP_ORIGIN_UNSPECIFIED; + int as_set = AGGREGATE_AS_UNSET; char prefix_buf[PREFIX2STR_BUFFER]; if (addr_str) { @@ -7841,128 +7775,78 @@ DEFPY_YANG( vty_out(vty, "%% Inconsistent address and mask\n"); return CMD_WARNING_CONFIG_FAILED; } - } else { - strlcpy(prefix_buf, prefix_str, sizeof(prefix_buf)); - } - - if (!no && origin_s) - nb_cli_enqueue_change(vty, "./origin", NB_OP_MODIFY, origin_s); - - if (!no && as_set_s) - nb_cli_enqueue_change(vty, "./as-set", NB_OP_MODIFY, "true"); - else - nb_cli_enqueue_change(vty, "./as-set", NB_OP_MODIFY, "false"); - - if (!no && summary_only) - nb_cli_enqueue_change(vty, "./summary-only", NB_OP_MODIFY, - "true"); - else - nb_cli_enqueue_change(vty, "./summary-only", NB_OP_MODIFY, - "false"); + prefix_s = prefix_buf; + } else + prefix_s = prefix_str; - if (rmap_name) - nb_cli_enqueue_change(vty, "./rmap-policy-export", NB_OP_MODIFY, - rmap_name); - else - nb_cli_enqueue_change(vty, "./rmap-policy-export", - NB_OP_DESTROY, NULL); + if (origin_s) { + if (strcmp(origin_s, "egp") == 0) + origin = BGP_ORIGIN_EGP; + else if (strcmp(origin_s, "igp") == 0) + origin = BGP_ORIGIN_IGP; + else if (strcmp(origin_s, "incomplete") == 0) + origin = BGP_ORIGIN_INCOMPLETE; + } - snprintf( - base_xpath, sizeof(base_xpath), - "./global/afi-safis/afi-safi[afi-safi-name='%s']/%s/aggregate-route[prefix='%s']", - yang_afi_safi_value2identity(AFI_IP, safi), - bgp_afi_safi_get_container_str(AFI_IP, safi), prefix_buf); + if (as_set_s) + as_set = AGGREGATE_AS_SET; + /* Handle configuration removal, otherwise installation. */ if (no) - nb_cli_enqueue_change(vty, ".", NB_OP_DESTROY, NULL); - else - nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL); - - return nb_cli_apply_changes(vty, base_xpath); -} - -DEFPY_YANG(aggregate_addressv6, aggregate_addressv6_cmd, - "[no] aggregate-address X:X::X:X/M$prefix {" - "as-set$as_set_s" - "|summary-only$summary_only" - "|route-map WORD$rmap_name" - "|origin $origin_s" - "|matching-MED-only$match_med" - "}", - NO_STR - "Configure BGP aggregate entries\n" - "Aggregate prefix\n" - "Generate AS set path information\n" - "Filter more specific routes from updates\n" - "Apply route map to aggregate network\n" - "Route map name\n" - "BGP origin code\n" - "Remote EGP\n" - "Local IGP\n" - "Unknown heritage\n" - "Only aggregate routes with matching MED\n" - "Suppress the selected more specific routes\n" - "Route map with the route selectors\n") -{ - char base_xpath[XPATH_MAXLEN]; - safi_t safi = bgp_node_safi(vty); - - if (!no && origin_s) - nb_cli_enqueue_change(vty, "./origin", NB_OP_MODIFY, origin_s); - - if (!no && as_set_s) - nb_cli_enqueue_change(vty, "./as-set", NB_OP_MODIFY, "true"); - else - nb_cli_enqueue_change(vty, "./as-set", NB_OP_MODIFY, "false"); - - if (!no && summary_only) - nb_cli_enqueue_change(vty, "./summary-only", NB_OP_MODIFY, - "true"); - else - nb_cli_enqueue_change(vty, "./summary-only", NB_OP_MODIFY, - "false"); - - if (rmap_name) - nb_cli_enqueue_change(vty, "./rmap-policy-export", NB_OP_MODIFY, - rmap_name); - - snprintf( - base_xpath, sizeof(base_xpath), - "./global/afi-safis/afi-safi[afi-safi-name='%s']/%s/aggregate-route[prefix='%s']", - yang_afi_safi_value2identity(AFI_IP6, safi), - bgp_afi_safi_get_container_str(AFI_IP6, safi), prefix_str); - + return bgp_aggregate_unset(vty, prefix_s, AFI_IP, safi); + + return bgp_aggregate_set(vty, prefix_s, AFI_IP, safi, rmap_name, + summary_only != NULL, as_set, origin, + match_med != NULL, suppress_map); +} + +DEFPY(aggregate_addressv6, aggregate_addressv6_cmd, + "[no] aggregate-address X:X::X:X/M$prefix {" + "as-set$as_set_s" + "|summary-only$summary_only" + "|route-map WORD$rmap_name" + "|origin $origin_s" + "|matching-MED-only$match_med" + "|suppress-map WORD$suppress_map" + "}", + NO_STR + "Configure BGP aggregate entries\n" + "Aggregate prefix\n" + "Generate AS set path information\n" + "Filter more specific routes from updates\n" + "Apply route map to aggregate network\n" + "Route map name\n" + "BGP origin code\n" + "Remote EGP\n" + "Local IGP\n" + "Unknown heritage\n" + "Only aggregate routes with matching MED\n" + "Suppress the selected more specific routes\n" + "Route map with the route selectors\n") +{ + uint8_t origin = BGP_ORIGIN_UNSPECIFIED; + int as_set = AGGREGATE_AS_UNSET; + + if (origin_s) { + if (strcmp(origin_s, "egp") == 0) + origin = BGP_ORIGIN_EGP; + else if (strcmp(origin_s, "igp") == 0) + origin = BGP_ORIGIN_IGP; + else if (strcmp(origin_s, "incomplete") == 0) + origin = BGP_ORIGIN_INCOMPLETE; + } + + if (as_set_s) + as_set = AGGREGATE_AS_SET; + + /* Handle configuration removal, otherwise installation. */ if (no) - nb_cli_enqueue_change(vty, ".", NB_OP_DESTROY, NULL); - else - nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL); + return bgp_aggregate_unset(vty, prefix_str, AFI_IP6, + SAFI_UNICAST); - return nb_cli_apply_changes(vty, base_xpath); -} - -void cli_show_bgp_global_afi_safi_unicast_aggregate_route( - struct vty *vty, struct lyd_node *dnode, bool show_defaults) -{ - uint8_t origin; - - vty_out(vty, " aggregate-address %s", - yang_dnode_get_string(dnode, "./prefix")); - - if (yang_dnode_get_bool(dnode, "./as-set")) - vty_out(vty, " as-set"); - - if (yang_dnode_get_bool(dnode, "./summary-only")) - vty_out(vty, " summary-only"); - - if (yang_dnode_exists(dnode, "./rmap-policy-export")) - vty_out(vty, " route-map %s", - yang_dnode_get_string(dnode, "./rmap-policy-export")); - - origin = yang_dnode_get_enum(dnode, "./origin"); - if (origin != BGP_ORIGIN_UNSPECIFIED) - vty_out(vty, " origin %s", bgp_origin2str(origin)); - - vty_out(vty, "\n"); + return bgp_aggregate_set(vty, prefix_str, AFI_IP6, SAFI_UNICAST, + rmap_name, summary_only != NULL, as_set, + origin, match_med != NULL, suppress_map); } /* Redistribute route treatment. */ @@ -14011,21 +13895,28 @@ static void bgp_distance_free(struct bgp_distance *bdistance) XFREE(MTYPE_BGP_DISTANCE, bdistance); } -int bgp_distance_set(uint8_t distance, const char *ip_str, - const char *access_list_str, afi_t afi, safi_t safi, - char *errmsg, size_t errmsg_len) +static int bgp_distance_set(struct vty *vty, const char *distance_str, + const char *ip_str, const char *access_list_str) { int ret; + afi_t afi; + safi_t safi; struct prefix p; + uint8_t distance; struct bgp_dest *dest; struct bgp_distance *bdistance; + afi = bgp_node_afi(vty); + safi = bgp_node_safi(vty); + ret = str2prefix(ip_str, &p); if (ret == 0) { - snprintf(errmsg, errmsg_len, "Malformed prefix\n"); + vty_out(vty, "Malformed prefix\n"); return CMD_WARNING_CONFIG_FAILED; } + distance = atoi(distance_str); + /* Get BGP distance node. */ dest = bgp_node_get(bgp_distance_table[afi][safi], &p); bdistance = bgp_dest_get_bgp_distance_info(dest); @@ -14048,32 +13939,37 @@ int bgp_distance_set(uint8_t distance, const char *ip_str, return CMD_SUCCESS; } -int bgp_distance_unset(uint8_t distance, const char *ip_str, - const char *access_list_str, afi_t afi, safi_t safi, - char *errmsg, size_t errmsg_len) +static int bgp_distance_unset(struct vty *vty, const char *distance_str, + const char *ip_str, const char *access_list_str) { int ret; + afi_t afi; + safi_t safi; struct prefix p; + int distance; struct bgp_dest *dest; struct bgp_distance *bdistance; + afi = bgp_node_afi(vty); + safi = bgp_node_safi(vty); + ret = str2prefix(ip_str, &p); if (ret == 0) { - snprintf(errmsg, errmsg_len, "Malformed prefix\n"); + vty_out(vty, "Malformed prefix\n"); return CMD_WARNING_CONFIG_FAILED; } dest = bgp_node_lookup(bgp_distance_table[afi][safi], &p); if (!dest) { - snprintf(errmsg, errmsg_len, "Can't find specified prefix\n"); + vty_out(vty, "Can't find specified prefix\n"); return CMD_WARNING_CONFIG_FAILED; } bdistance = bgp_dest_get_bgp_distance_info(dest); + distance = atoi(distance_str); if (bdistance->distance != distance) { - snprintf(errmsg, errmsg_len, - "Distance does not match configured\n"); + vty_out(vty, "Distance does not match configured\n"); return CMD_WARNING_CONFIG_FAILED; } @@ -14160,8 +14056,9 @@ uint8_t bgp_distance_apply(const struct prefix *p, struct bgp_path_info *pinfo, * we should tell ZEBRA update the routes for a specific * AFI/SAFI to reflect changes in RIB. */ -void bgp_announce_routes_distance_update(struct bgp *bgp, afi_t update_afi, - safi_t update_safi) +static void bgp_announce_routes_distance_update(struct bgp *bgp, + afi_t update_afi, + safi_t update_safi) { afi_t afi; safi_t safi; @@ -14181,228 +14078,237 @@ void bgp_announce_routes_distance_update(struct bgp *bgp, afi_t update_afi, } } -DEFUN_YANG(bgp_distance, bgp_distance_cmd, - "distance bgp (1-255) (1-255) (1-255)", - "Define an administrative distance\n" - "BGP distance\n" - "Distance for routes external to the AS\n" - "Distance for routes internal to the AS\n" - "Distance for local routes\n") +DEFUN (bgp_distance, + bgp_distance_cmd, + "distance bgp (1-255) (1-255) (1-255)", + "Define an administrative distance\n" + "BGP distance\n" + "Distance for routes external to the AS\n" + "Distance for routes internal to the AS\n" + "Distance for local routes\n") { + VTY_DECLVAR_CONTEXT(bgp, bgp); int idx_number = 2; int idx_number_2 = 3; int idx_number_3 = 4; + int distance_ebgp = atoi(argv[idx_number]->arg); + int distance_ibgp = atoi(argv[idx_number_2]->arg); + int distance_local = atoi(argv[idx_number_3]->arg); afi_t afi; safi_t safi; - char xpath[XPATH_MAXLEN]; afi = bgp_node_afi(vty); safi = bgp_node_safi(vty); - snprintf( - xpath, sizeof(xpath), - "./global/afi-safis/afi-safi[afi-safi-name='%s']/%s/admin-distance/external", - yang_afi_safi_value2identity(afi, safi), - bgp_afi_safi_get_container_str(afi, safi)); - nb_cli_enqueue_change(vty, xpath, NB_OP_MODIFY, argv[idx_number]->arg); - snprintf( - xpath, sizeof(xpath), - "./global/afi-safis/afi-safi[afi-safi-name='%s']/%s/admin-distance/internal", - yang_afi_safi_value2identity(afi, safi), - bgp_afi_safi_get_container_str(afi, safi)); - nb_cli_enqueue_change(vty, xpath, NB_OP_MODIFY, - argv[idx_number_2]->arg); - snprintf( - xpath, sizeof(xpath), - "./global/afi-safis/afi-safi[afi-safi-name='%s']/%s/admin-distance/local", - yang_afi_safi_value2identity(afi, safi), - bgp_afi_safi_get_container_str(afi, safi)); - - nb_cli_enqueue_change(vty, xpath, NB_OP_MODIFY, - argv[idx_number_3]->arg); - - return nb_cli_apply_changes(vty, NULL); -} - -DEFUN_YANG(no_bgp_distance, no_bgp_distance_cmd, - "no distance bgp [(1-255) (1-255) (1-255)]", - NO_STR - "Define an administrative distance\n" - "BGP distance\n" - "Distance for routes external to the AS\n" - "Distance for routes internal to the AS\n" - "Distance for local routes\n") -{ - afi_t afi; - safi_t safi; - char xpath[XPATH_MAXLEN]; - - afi = bgp_node_afi(vty); - safi = bgp_node_safi(vty); + if (bgp->distance_ebgp[afi][safi] != distance_ebgp + || bgp->distance_ibgp[afi][safi] != distance_ibgp + || bgp->distance_local[afi][safi] != distance_local) { + bgp->distance_ebgp[afi][safi] = distance_ebgp; + bgp->distance_ibgp[afi][safi] = distance_ibgp; + bgp->distance_local[afi][safi] = distance_local; + bgp_announce_routes_distance_update(bgp, afi, safi); + } + return CMD_SUCCESS; +} - snprintf( - xpath, sizeof(xpath), - "./global/afi-safis/afi-safi[afi-safi-name='%s']/%s/admin-distance/external", - yang_afi_safi_value2identity(afi, safi), - bgp_afi_safi_get_container_str(afi, safi)); - nb_cli_enqueue_change(vty, xpath, NB_OP_MODIFY, NULL); - snprintf( - xpath, sizeof(xpath), - "./global/afi-safis/afi-safi[afi-safi-name='%s']/%s/admin-distance/internal", - yang_afi_safi_value2identity(afi, safi), - bgp_afi_safi_get_container_str(afi, safi)); - nb_cli_enqueue_change(vty, xpath, NB_OP_MODIFY, NULL); - snprintf( - xpath, sizeof(xpath), - "./global/afi-safis/afi-safi[afi-safi-name='%s']/%s/admin-distance/local", - yang_afi_safi_value2identity(afi, safi), - bgp_afi_safi_get_container_str(afi, safi)); - - nb_cli_enqueue_change(vty, xpath, NB_OP_MODIFY, NULL); - - return nb_cli_apply_changes(vty, NULL); -} - -void cli_show_bgp_global_afi_safi_admin_distance_config(struct vty *vty, - struct lyd_node *dnode, - bool show_defaults) -{ - uint8_t distance_ebgp, distance_ibgp, distance_local; - - distance_ebgp = yang_dnode_get_uint8(dnode, "./external"); - distance_ibgp = yang_dnode_get_uint8(dnode, "./internal"); - distance_local = yang_dnode_get_uint8(dnode, "./local"); - - vty_out(vty, " distance bgp %d %d %d\n", distance_ebgp, distance_ibgp, - distance_local); -} - -DEFPY_YANG(bgp_distance_source, - bgp_distance_source_cmd, - "[no] distance (1-255) $prefix [WORD$acl]", - NO_STR - "Define an administrative distance\n" - "Distance value\n" - "IPv4 source prefix\n" - "IPv6 source prefix\n" - "Access list name\n") +DEFUN (no_bgp_distance, + no_bgp_distance_cmd, + "no distance bgp [(1-255) (1-255) (1-255)]", + NO_STR + "Define an administrative distance\n" + "BGP distance\n" + "Distance for routes external to the AS\n" + "Distance for routes internal to the AS\n" + "Distance for local routes\n") { + VTY_DECLVAR_CONTEXT(bgp, bgp); afi_t afi; safi_t safi; - char xpath[XPATH_MAXLEN]; afi = bgp_node_afi(vty); safi = bgp_node_safi(vty); - if (!no) { - nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL); - nb_cli_enqueue_change(vty, "./distance", NB_OP_MODIFY, - distance_str); - if (acl) - nb_cli_enqueue_change(vty, - "./access-list-policy-export", - NB_OP_CREATE, acl); - else - nb_cli_enqueue_change(vty, - "./access-list-policy-export", - NB_OP_DESTROY, NULL); - } else { - nb_cli_enqueue_change(vty, ".", NB_OP_DESTROY, NULL); + if (bgp->distance_ebgp[afi][safi] != 0 + || bgp->distance_ibgp[afi][safi] != 0 + || bgp->distance_local[afi][safi] != 0) { + bgp->distance_ebgp[afi][safi] = 0; + bgp->distance_ibgp[afi][safi] = 0; + bgp->distance_local[afi][safi] = 0; + bgp_announce_routes_distance_update(bgp, afi, safi); } + return CMD_SUCCESS; +} - snprintf( - xpath, sizeof(xpath), - "./global/afi-safis/afi-safi[afi-safi-name='%s']/%s/admin-distance-route[prefix='%s']", - yang_afi_safi_value2identity(afi, safi), - bgp_afi_safi_get_container_str(afi, safi), prefix_str); - return nb_cli_apply_changes(vty, xpath); +DEFUN (bgp_distance_source, + bgp_distance_source_cmd, + "distance (1-255) A.B.C.D/M", + "Define an administrative distance\n" + "Administrative distance\n" + "IP source prefix\n") +{ + int idx_number = 1; + int idx_ipv4_prefixlen = 2; + bgp_distance_set(vty, argv[idx_number]->arg, + argv[idx_ipv4_prefixlen]->arg, NULL); + return CMD_SUCCESS; } -void cli_show_bgp_global_afi_safi_unicast_admin_distance_route( - struct vty *vty, struct lyd_node *dnode, bool show_defaults) +DEFUN (no_bgp_distance_source, + no_bgp_distance_source_cmd, + "no distance (1-255) A.B.C.D/M", + NO_STR + "Define an administrative distance\n" + "Administrative distance\n" + "IP source prefix\n") { - vty_out(vty, " distance %d %s %s\n", - yang_dnode_get_uint8(dnode, "./distance"), - yang_dnode_get_string(dnode, "./prefix"), - (yang_dnode_exists(dnode, "./access-list-policy-export")) - ? yang_dnode_get_string(dnode, - "./access-list-policy-export") - : ""); + int idx_number = 2; + int idx_ipv4_prefixlen = 3; + bgp_distance_unset(vty, argv[idx_number]->arg, + argv[idx_ipv4_prefixlen]->arg, NULL); + return CMD_SUCCESS; } -DEFPY_YANG( - bgp_dampening, bgp_dampening_cmd, - "[no] bgp dampening [(1-45)$halflife [(1-20000)$reuse (1-20000)$suppress (1-255)$max_suppress]]", - NO_STR - "BGP Specific commands\n" - "Enable route-flap dampening\n" - "Half-life time for the penalty\n" - "Value to start reusing a route\n" - "Value to start suppressing a route\n" - "Maximum duration to suppress a stable route\n") +DEFUN (bgp_distance_source_access_list, + bgp_distance_source_access_list_cmd, + "distance (1-255) A.B.C.D/M WORD", + "Define an administrative distance\n" + "Administrative distance\n" + "IP source prefix\n" + "Access list name\n") { - afi_t afi; - safi_t safi; - char xpath[XPATH_MAXLEN]; + int idx_number = 1; + int idx_ipv4_prefixlen = 2; + int idx_word = 3; + bgp_distance_set(vty, argv[idx_number]->arg, + argv[idx_ipv4_prefixlen]->arg, argv[idx_word]->arg); + return CMD_SUCCESS; +} - afi = bgp_node_afi(vty); - safi = bgp_node_safi(vty); +DEFUN (no_bgp_distance_source_access_list, + no_bgp_distance_source_access_list_cmd, + "no distance (1-255) A.B.C.D/M WORD", + NO_STR + "Define an administrative distance\n" + "Administrative distance\n" + "IP source prefix\n" + "Access list name\n") +{ + int idx_number = 2; + int idx_ipv4_prefixlen = 3; + int idx_word = 4; + bgp_distance_unset(vty, argv[idx_number]->arg, + argv[idx_ipv4_prefixlen]->arg, argv[idx_word]->arg); + return CMD_SUCCESS; +} - if (!no) { - nb_cli_enqueue_change(vty, "./enable", NB_OP_MODIFY, "true"); - if (argc == 6) { - nb_cli_enqueue_change(vty, "./reach-decay", - NB_OP_MODIFY, halflife_str); - nb_cli_enqueue_change(vty, "./reuse-above", - NB_OP_MODIFY, reuse_str); - nb_cli_enqueue_change(vty, "./suppress-above", - NB_OP_MODIFY, suppress_str); - nb_cli_enqueue_change(vty, "./unreach-decay", - NB_OP_MODIFY, max_suppress_str); - } if (argc == 3) { - nb_cli_enqueue_change(vty, "./reach-decay", - NB_OP_MODIFY, halflife_str); - } - } else { - nb_cli_enqueue_change(vty, "./enable", NB_OP_MODIFY, "false"); - } +DEFUN (ipv6_bgp_distance_source, + ipv6_bgp_distance_source_cmd, + "distance (1-255) X:X::X:X/M", + "Define an administrative distance\n" + "Administrative distance\n" + "IP source prefix\n") +{ + bgp_distance_set(vty, argv[1]->arg, argv[2]->arg, NULL); + return CMD_SUCCESS; +} - snprintf( - xpath, sizeof(xpath), - "./global/afi-safis/afi-safi[afi-safi-name='%s']/%s/route-flap-dampening", - yang_afi_safi_value2identity(afi, safi), - bgp_afi_safi_get_container_str(afi, safi)); +DEFUN (no_ipv6_bgp_distance_source, + no_ipv6_bgp_distance_source_cmd, + "no distance (1-255) X:X::X:X/M", + NO_STR + "Define an administrative distance\n" + "Administrative distance\n" + "IP source prefix\n") +{ + bgp_distance_unset(vty, argv[2]->arg, argv[3]->arg, NULL); + return CMD_SUCCESS; +} - return nb_cli_apply_changes(vty, xpath); +DEFUN (ipv6_bgp_distance_source_access_list, + ipv6_bgp_distance_source_access_list_cmd, + "distance (1-255) X:X::X:X/M WORD", + "Define an administrative distance\n" + "Administrative distance\n" + "IP source prefix\n" + "Access list name\n") +{ + bgp_distance_set(vty, argv[1]->arg, argv[2]->arg, argv[3]->arg); + return CMD_SUCCESS; } -void cli_show_bgp_global_afi_safi_route_flap_dampening(struct vty *vty, - struct lyd_node *dnode, - bool show_defaults) +DEFUN (no_ipv6_bgp_distance_source_access_list, + no_ipv6_bgp_distance_source_access_list_cmd, + "no distance (1-255) X:X::X:X/M WORD", + NO_STR + "Define an administrative distance\n" + "Administrative distance\n" + "IP source prefix\n" + "Access list name\n") { - if (!yang_dnode_get_bool(dnode, "./enable")) - return; + bgp_distance_unset(vty, argv[2]->arg, argv[3]->arg, argv[4]->arg); + return CMD_SUCCESS; +} +DEFUN (bgp_damp_set, + bgp_damp_set_cmd, + "bgp dampening [(1-45) [(1-20000) (1-20000) (1-255)]]", + "BGP Specific commands\n" + "Enable route-flap dampening\n" + "Half-life time for the penalty\n" + "Value to start reusing a route\n" + "Value to start suppressing a route\n" + "Maximum duration to suppress a stable route\n") +{ + VTY_DECLVAR_CONTEXT(bgp, bgp); + int idx_half_life = 2; + int idx_reuse = 3; + int idx_suppress = 4; + int idx_max_suppress = 5; int half = DEFAULT_HALF_LIFE * 60; int reuse = DEFAULT_REUSE; int suppress = DEFAULT_SUPPRESS; - int max; - - half = yang_dnode_get_uint8(dnode, "../reach-decay"); - reuse = yang_dnode_get_uint16(dnode, "../reuse-above"); - suppress = yang_dnode_get_uint16(dnode, "../suppress-above"); - max = yang_dnode_get_uint8(dnode, "../unreach-decay"); - - if (half == DEFAULT_HALF_LIFE * 60 && reuse == DEFAULT_REUSE - && suppress == DEFAULT_SUPPRESS && max == half * 4) - vty_out(vty, " bgp dampening\n"); - else if (half != DEFAULT_HALF_LIFE * 60 && reuse == DEFAULT_REUSE - && suppress == DEFAULT_SUPPRESS && max == half * 4) - vty_out(vty, " bgp dampening %u\n", half); - else - vty_out(vty, " bgp dampening %u %d %d %d\n", half, reuse, - suppress, max); + int max = 4 * half; + + if (argc == 6) { + half = atoi(argv[idx_half_life]->arg) * 60; + reuse = atoi(argv[idx_reuse]->arg); + suppress = atoi(argv[idx_suppress]->arg); + max = atoi(argv[idx_max_suppress]->arg) * 60; + } else if (argc == 3) { + half = atoi(argv[idx_half_life]->arg) * 60; + max = 4 * half; + } + + /* + * These can't be 0 but our SA doesn't understand the + * way our cli is constructed + */ + assert(reuse); + assert(half); + if (suppress < reuse) { + vty_out(vty, + "Suppress value cannot be less than reuse value \n"); + return 0; + } + + return bgp_damp_enable(bgp, bgp_node_afi(vty), bgp_node_safi(vty), half, + reuse, suppress, max); +} + +DEFUN (bgp_damp_unset, + bgp_damp_unset_cmd, + "no bgp dampening [(1-45) [(1-20000) (1-20000) (1-255)]]", + NO_STR + "BGP Specific commands\n" + "Enable route-flap dampening\n" + "Half-life time for the penalty\n" + "Value to start reusing a route\n" + "Value to start suppressing a route\n" + "Maximum duration to suppress a stable route\n") +{ + VTY_DECLVAR_CONTEXT(bgp, bgp); + return bgp_damp_disable(bgp, bgp_node_afi(vty), bgp_node_safi(vty)); } /* Display specified route of BGP table. */ @@ -14965,13 +14871,20 @@ void bgp_route_init(void) install_element(BGP_IPV6M_NODE, &bgp_distance_source_cmd); /* BGP dampening */ - install_element(BGP_NODE, &bgp_dampening_cmd); - install_element(BGP_IPV4_NODE, &bgp_dampening_cmd); - install_element(BGP_IPV4M_NODE, &bgp_dampening_cmd); - install_element(BGP_IPV4L_NODE, &bgp_dampening_cmd); - install_element(BGP_IPV6_NODE, &bgp_dampening_cmd); - install_element(BGP_IPV6M_NODE, &bgp_dampening_cmd); - install_element(BGP_IPV6L_NODE, &bgp_dampening_cmd); + install_element(BGP_NODE, &bgp_damp_set_cmd); + install_element(BGP_NODE, &bgp_damp_unset_cmd); + install_element(BGP_IPV4_NODE, &bgp_damp_set_cmd); + install_element(BGP_IPV4_NODE, &bgp_damp_unset_cmd); + install_element(BGP_IPV4M_NODE, &bgp_damp_set_cmd); + install_element(BGP_IPV4M_NODE, &bgp_damp_unset_cmd); + install_element(BGP_IPV4L_NODE, &bgp_damp_set_cmd); + install_element(BGP_IPV4L_NODE, &bgp_damp_unset_cmd); + install_element(BGP_IPV6_NODE, &bgp_damp_set_cmd); + install_element(BGP_IPV6_NODE, &bgp_damp_unset_cmd); + install_element(BGP_IPV6M_NODE, &bgp_damp_set_cmd); + install_element(BGP_IPV6M_NODE, &bgp_damp_unset_cmd); + install_element(BGP_IPV6L_NODE, &bgp_damp_set_cmd); + install_element(BGP_IPV6L_NODE, &bgp_damp_unset_cmd); /* Large Communities */ install_element(VIEW_NODE, &show_ip_bgp_large_community_list_cmd); diff --git a/bgpd/bgp_route.h b/bgpd/bgp_route.h index e58213a688..65ef268509 100644 --- a/bgpd/bgp_route.h +++ b/bgpd/bgp_route.h @@ -787,32 +787,5 @@ extern void bgp_aggregate_toggle_suppressed(struct bgp_aggregate *aggregate, struct bgp *bgp, const struct prefix *p, afi_t afi, safi_t safi, bool suppress); -extern int bgp_static_set(struct bgp *bgp, const char *negate, - struct prefix *pfx, afi_t afi, safi_t safi, - const char *rmap, int backdoor, uint32_t label_index, - char *errmsg, size_t errmsg_len); - -extern int bgp_aggregate_set(struct bgp *bgp, struct prefix *prefix, afi_t afi, - safi_t safi, const char *rmap, - uint8_t summary_only, uint8_t as_set, - uint8_t origin, bool match_med, - const char *suppress_map, char *errmsg, - size_t errmsg_len); - -extern int bgp_aggregate_unset(struct bgp *bgp, struct prefix *prefix, - afi_t afi, safi_t safi, char *errmsg, - size_t errmsg_len); - -extern void bgp_announce_routes_distance_update(struct bgp *bgp, - afi_t update_afi, - safi_t update_safi); - -extern int bgp_distance_set(uint8_t distance, const char *ip_str, - const char *access_list_str, afi_t afi, safi_t safi, - char *errmsg, size_t errmsg_len); - -extern int bgp_distance_unset(uint8_t distance, const char *ip_str, - const char *access_list_str, afi_t afi, - safi_t safi, char *errmsg, size_t errmsg_len); extern void subgroup_announce_reset_nhop(uint8_t family, struct attr *attr); #endif /* _QUAGGA_BGP_ROUTE_H */ diff --git a/bgpd/bgp_vty.c b/bgpd/bgp_vty.c index 1ce1454826..d987c8327a 100644 --- a/bgpd/bgp_vty.c +++ b/bgpd/bgp_vty.c @@ -285,41 +285,6 @@ static const char *get_afi_safi_json_str(afi_t afi, safi_t safi) return "Unknown"; } -/* return string maps to afi-safi specific container names - * defined in bgp yang file. - */ -const char *bgp_afi_safi_get_container_str(afi_t afi, safi_t safi) -{ - if (afi == AFI_IP) { - if (safi == SAFI_UNICAST) - return "ipv4-unicast"; - if (safi == SAFI_MULTICAST) - return "ipv4-multicast"; - if (safi == SAFI_LABELED_UNICAST) - return "ipv4-labeled-unicast"; - if (safi == SAFI_MPLS_VPN) - return "l3vpn-ipv4-unicast"; - if (safi == SAFI_FLOWSPEC) - return "ipv4-flowspec"; - } else if (afi == AFI_IP6) { - if (safi == SAFI_UNICAST) - return "ipv6-unicast"; - if (safi == SAFI_MULTICAST) - return "ipv6-multicast"; - if (safi == SAFI_LABELED_UNICAST) - return "ipv6-labeled-unicast"; - if (safi == SAFI_MPLS_VPN) - return "l3vpn-ipv6-unicast"; - if (safi == SAFI_FLOWSPEC) - return "ipv6-flowspec"; - } else if (afi == AFI_L2VPN) { - if (safi == SAFI_EVPN) - return "l2vpn-evpn"; - } - - return "Unknown"; -} - /* Utility function to get address family from current node. */ afi_t bgp_node_afi(struct vty *vty) { @@ -1763,16 +1728,23 @@ void cli_show_router_bgp_confederation_member_as(struct vty *vty, * @peer_type: BGP_PEER_EBGP or BGP_PEER_IBGP * @set: 1 for setting values, 0 for removing the max-paths config. */ -int bgp_maxpaths_config_vty(struct bgp *bgp, afi_t afi, safi_t safi, - int peer_type, uint16_t maxpaths, uint16_t options, - int set, char *errmsg, size_t errmsg_len) +static int bgp_maxpaths_config_vty(struct vty *vty, int peer_type, + const char *mpaths, uint16_t options, + int set) { + VTY_DECLVAR_CONTEXT(bgp, bgp); + uint16_t maxpaths = 0; int ret; + afi_t afi; + safi_t safi; + + afi = bgp_node_afi(vty); + safi = bgp_node_safi(vty); if (set) { + maxpaths = strtol(mpaths, NULL, 10); if (maxpaths > multipath_num) { - snprintf( - errmsg, errmsg_len, + vty_out(vty, "%% Maxpaths Specified: %d is > than multipath num specified on bgp command line %d", maxpaths, multipath_num); return CMD_WARNING_CONFIG_FAILED; @@ -1783,8 +1755,7 @@ int bgp_maxpaths_config_vty(struct bgp *bgp, afi_t afi, safi_t safi, ret = bgp_maximum_paths_unset(bgp, afi, safi, peer_type); if (ret < 0) { - snprintf( - errmsg, errmsg_len, + vty_out(vty, "%% Failed to %sset maximum-paths %s %u for afi %u, safi %u\n", (set == 1) ? "" : "un", (peer_type == BGP_PEER_EBGP) ? "ebgp" : "ibgp", @@ -1875,14 +1846,14 @@ DEFUN_YANG(no_bgp_maxmed_admin, return nb_cli_apply_changes(vty, NULL); } -DEFUN_YANG (bgp_maxmed_onstartup, - bgp_maxmed_onstartup_cmd, - "bgp max-med on-startup (5-86400) [(0-4294967295)]", - BGP_STR - "Advertise routes with max-med\n" - "Effective on a startup\n" - "Time (seconds) period for max-med\n" - "Max MED value to be used\n") +DEFUN_YANG(bgp_maxmed_onstartup, + bgp_maxmed_onstartup_cmd, + "bgp max-med on-startup (5-86400) [(0-4294967295)]", + BGP_STR + "Advertise routes with max-med\n" + "Effective on a startup\n" + "Time (seconds) period for max-med\n" + "Max MED value to be used\n") { int idx = 0; @@ -1903,14 +1874,14 @@ DEFUN_YANG (bgp_maxmed_onstartup, return nb_cli_apply_changes(vty, NULL); } -DEFUN_YANG (no_bgp_maxmed_onstartup, - no_bgp_maxmed_onstartup_cmd, - "no bgp max-med on-startup [(5-86400) [(0-4294967295)]]", - NO_STR BGP_STR - "Advertise routes with max-med\n" - "Effective on a startup\n" - "Time (seconds) period for max-med\n" - "Max MED value to be used\n") +DEFUN_YANG(no_bgp_maxmed_onstartup, + no_bgp_maxmed_onstartup_cmd, + "no bgp max-med on-startup [(5-86400) [(0-4294967295)]]", + NO_STR BGP_STR + "Advertise routes with max-med\n" + "Effective on a startup\n" + "Time (seconds) period for max-med\n" + "Max MED value to be used\n") { nb_cli_enqueue_change(vty, "./global/med-config/max-med-onstart-up-time", @@ -2144,12 +2115,12 @@ void bgp_config_write_rpkt_quanta(struct vty *vty, struct bgp *bgp) * Furthermore, the maximums used here should correspond to * BGP_WRITE_PACKET_MAX and BGP_READ_PACKET_MAX. */ -DEFPY_YANG (bgp_wpkt_quanta, - bgp_wpkt_quanta_cmd, - "[no] write-quanta (1-64)$quanta", - NO_STR - "How many packets to write to peer socket per run\n" - "Number of packets\n") +DEFPY_YANG(bgp_wpkt_quanta, + bgp_wpkt_quanta_cmd, + "[no] write-quanta (1-64)$quanta", + NO_STR + "How many packets to write to peer socket per run\n" + "Number of packets\n") { if (!no) nb_cli_enqueue_change( @@ -2165,12 +2136,12 @@ DEFPY_YANG (bgp_wpkt_quanta, return nb_cli_apply_changes(vty, NULL); } -DEFPY_YANG (bgp_rpkt_quanta, - bgp_rpkt_quanta_cmd, - "[no] read-quanta (1-10)$quanta", - NO_STR - "How many packets to read from peer socket per I/O cycle\n" - "Number of packets\n") +DEFPY_YANG(bgp_rpkt_quanta, + bgp_rpkt_quanta_cmd, + "[no] read-quanta (1-10)$quanta", + NO_STR + "How many packets to read from peer socket per I/O cycle\n" + "Number of packets\n") { if (!no) nb_cli_enqueue_change( @@ -2199,11 +2170,11 @@ void cli_show_router_global_update_group_config_coalesce_time( } -DEFUN_YANG (bgp_coalesce_time, - bgp_coalesce_time_cmd, - "coalesce-time (0-4294967295)", - "Subgroup coalesce timer\n" - "Subgroup coalesce timer value (in ms)\n") +DEFUN_YANG(bgp_coalesce_time, + bgp_coalesce_time_cmd, + "coalesce-time (0-4294967295)", + "Subgroup coalesce timer\n" + "Subgroup coalesce timer value (in ms)\n") { int idx = 0; @@ -2230,37 +2201,15 @@ DEFUN_YANG(no_bgp_coalesce_time, } /* Maximum-paths configuration */ -DEFUN_YANG (bgp_maxpaths, - bgp_maxpaths_cmd, - "maximum-paths " CMD_RANGE_STR(1, MULTIPATH_NUM), - "Forward packets over multiple paths\n" - "Number of paths\n") +DEFUN (bgp_maxpaths, + bgp_maxpaths_cmd, + "maximum-paths " CMD_RANGE_STR(1, MULTIPATH_NUM), + "Forward packets over multiple paths\n" + "Number of paths\n") { int idx_number = 1; - char base_xpath[XPATH_MAXLEN]; - afi_t afi; - safi_t safi; - - afi = bgp_node_afi(vty); - safi = bgp_node_safi(vty); - - snprintf( - base_xpath, sizeof(base_xpath), - "./global/afi-safis/afi-safi[afi-safi-name='%s']/%s/use-multiple-paths/ebgp/maximum-paths", - yang_afi_safi_value2identity(afi, safi), - bgp_afi_safi_get_container_str(afi, safi)); - - nb_cli_enqueue_change(vty, base_xpath, NB_OP_MODIFY, - argv[idx_number]->arg); - - return nb_cli_apply_changes(vty, NULL); -} - -void cli_show_bgp_global_afi_safi_unicast_use_multiple_paths_ebgp_maximum_paths( - struct vty *vty, struct lyd_node *dnode, bool show_defaults) -{ - vty_out(vty, " maximum-paths %d\n", - yang_dnode_get_uint16(dnode, NULL)); + return bgp_maxpaths_config_vty(vty, BGP_PEER_EBGP, + argv[idx_number]->arg, 0, 1); } ALIAS_HIDDEN(bgp_maxpaths, bgp_maxpaths_hidden_cmd, @@ -2268,31 +2217,16 @@ ALIAS_HIDDEN(bgp_maxpaths, bgp_maxpaths_hidden_cmd, "Forward packets over multiple paths\n" "Number of paths\n") -DEFUN_YANG (bgp_maxpaths_ibgp, - bgp_maxpaths_ibgp_cmd, - "maximum-paths ibgp " CMD_RANGE_STR(1, MULTIPATH_NUM), - "Forward packets over multiple paths\n" - "iBGP-multipath\n" - "Number of paths\n") +DEFUN (bgp_maxpaths_ibgp, + bgp_maxpaths_ibgp_cmd, + "maximum-paths ibgp " CMD_RANGE_STR(1, MULTIPATH_NUM), + "Forward packets over multiple paths\n" + "iBGP-multipath\n" + "Number of paths\n") { int idx_number = 2; - char base_xpath[XPATH_MAXLEN]; - afi_t afi; - safi_t safi; - - afi = bgp_node_afi(vty); - safi = bgp_node_safi(vty); - - snprintf( - base_xpath, sizeof(base_xpath), - "./global/afi-safis/afi-safi[afi-safi-name='%s']/%s/use-multiple-paths/ibgp/maximum-paths", - yang_afi_safi_value2identity(afi, safi), - bgp_afi_safi_get_container_str(afi, safi)); - - nb_cli_enqueue_change(vty, base_xpath, NB_OP_MODIFY, - argv[idx_number]->arg); - - return nb_cli_apply_changes(vty, NULL); + return bgp_maxpaths_config_vty(vty, BGP_PEER_IBGP, + argv[idx_number]->arg, 0, 1); } ALIAS_HIDDEN(bgp_maxpaths_ibgp, bgp_maxpaths_ibgp_hidden_cmd, @@ -2301,50 +2235,18 @@ ALIAS_HIDDEN(bgp_maxpaths_ibgp, bgp_maxpaths_ibgp_hidden_cmd, "iBGP-multipath\n" "Number of paths\n") -DEFUN_YANG (bgp_maxpaths_ibgp_cluster, - bgp_maxpaths_ibgp_cluster_cmd, - "maximum-paths ibgp " CMD_RANGE_STR(1, MULTIPATH_NUM) " equal-cluster-length", - "Forward packets over multiple paths\n" - "iBGP-multipath\n" - "Number of paths\n" - "Match the cluster length\n") +DEFUN (bgp_maxpaths_ibgp_cluster, + bgp_maxpaths_ibgp_cluster_cmd, + "maximum-paths ibgp " CMD_RANGE_STR(1, MULTIPATH_NUM) " equal-cluster-length", + "Forward packets over multiple paths\n" + "iBGP-multipath\n" + "Number of paths\n" + "Match the cluster length\n") { int idx_number = 2; - char base_xpath[XPATH_MAXLEN]; - afi_t afi; - safi_t safi; - - afi = bgp_node_afi(vty); - safi = bgp_node_safi(vty); - - snprintf( - base_xpath, sizeof(base_xpath), - "./global/afi-safis/afi-safi[afi-safi-name='%s']/%s/use-multiple-paths/ibgp/maximum-paths", - yang_afi_safi_value2identity(afi, safi), - bgp_afi_safi_get_container_str(afi, safi)); - - nb_cli_enqueue_change(vty, base_xpath, NB_OP_MODIFY, - argv[idx_number]->arg); - - snprintf( - base_xpath, sizeof(base_xpath), - "./global/afi-safis/afi-safi[afi-safi-name='%s']/%s/use-multiple-paths/ibgp/cluster-length-list", - yang_afi_safi_value2identity(afi, safi), - bgp_afi_safi_get_container_str(afi, safi)); - - nb_cli_enqueue_change(vty, base_xpath, NB_OP_MODIFY, "true"); - - return nb_cli_apply_changes(vty, NULL); -} - -void cli_show_bgp_global_afi_safi_ip_unicast_use_multiple_paths_ibgp_maximum_paths( - struct vty *vty, struct lyd_node *dnode, bool show_defaults) -{ - vty_out(vty, " maximum-paths ibgp %d", - yang_dnode_get_uint16(dnode, "./maximum-paths")); - if (yang_dnode_get_bool(dnode, "./cluster-length-list")) - vty_out(vty, " equal-cluster-length"); - vty_out(vty, "\n"); + return bgp_maxpaths_config_vty( + vty, BGP_PEER_IBGP, argv[idx_number]->arg, + BGP_FLAG_IBGP_MULTIPATH_SAME_CLUSTERLEN, 1); } ALIAS_HIDDEN(bgp_maxpaths_ibgp_cluster, bgp_maxpaths_ibgp_cluster_hidden_cmd, @@ -2355,29 +2257,14 @@ ALIAS_HIDDEN(bgp_maxpaths_ibgp_cluster, bgp_maxpaths_ibgp_cluster_hidden_cmd, "Number of paths\n" "Match the cluster length\n") -DEFUN_YANG (no_bgp_maxpaths, - no_bgp_maxpaths_cmd, - "no maximum-paths [" CMD_RANGE_STR(1, MULTIPATH_NUM) "]", - NO_STR - "Forward packets over multiple paths\n" - "Number of paths\n") +DEFUN (no_bgp_maxpaths, + no_bgp_maxpaths_cmd, + "no maximum-paths [" CMD_RANGE_STR(1, MULTIPATH_NUM) "]", + NO_STR + "Forward packets over multiple paths\n" + "Number of paths\n") { - char base_xpath[XPATH_MAXLEN]; - afi_t afi; - safi_t safi; - - afi = bgp_node_afi(vty); - safi = bgp_node_safi(vty); - - snprintf( - base_xpath, sizeof(base_xpath), - "./global/afi-safis/afi-safi[afi-safi-name='%s']/%s/use-multiple-paths/ebgp/maximum-paths", - yang_afi_safi_value2identity(afi, safi), - bgp_afi_safi_get_container_str(afi, safi)); - - nb_cli_enqueue_change(vty, base_xpath, NB_OP_MODIFY, NULL); - - return nb_cli_apply_changes(vty, NULL); + return bgp_maxpaths_config_vty(vty, BGP_PEER_EBGP, NULL, 0, 0); } ALIAS_HIDDEN(no_bgp_maxpaths, no_bgp_maxpaths_hidden_cmd, @@ -2385,39 +2272,16 @@ ALIAS_HIDDEN(no_bgp_maxpaths, no_bgp_maxpaths_hidden_cmd, "Forward packets over multiple paths\n" "Number of paths\n") -DEFUN_YANG (no_bgp_maxpaths_ibgp, - no_bgp_maxpaths_ibgp_cmd, - "no maximum-paths ibgp [" CMD_RANGE_STR(1, MULTIPATH_NUM) " [equal-cluster-length]]", - NO_STR - "Forward packets over multiple paths\n" - "iBGP-multipath\n" - "Number of paths\n" - "Match the cluster length\n") +DEFUN (no_bgp_maxpaths_ibgp, + no_bgp_maxpaths_ibgp_cmd, + "no maximum-paths ibgp [" CMD_RANGE_STR(1, MULTIPATH_NUM) " [equal-cluster-length]]", + NO_STR + "Forward packets over multiple paths\n" + "iBGP-multipath\n" + "Number of paths\n" + "Match the cluster length\n") { - char base_xpath[XPATH_MAXLEN]; - afi_t afi; - safi_t safi; - - afi = bgp_node_afi(vty); - safi = bgp_node_safi(vty); - - snprintf( - base_xpath, sizeof(base_xpath), - "./global/afi-safis/afi-safi[afi-safi-name='%s']/%s/use-multiple-paths/ibgp/maximum-paths", - yang_afi_safi_value2identity(afi, safi), - bgp_afi_safi_get_container_str(afi, safi)); - - nb_cli_enqueue_change(vty, base_xpath, NB_OP_MODIFY, NULL); - - snprintf( - base_xpath, sizeof(base_xpath), - "./global/afi-safis/afi-safi[afi-safi-name='%s']/%s/use-multiple-paths/ibgp/cluster-length-list", - yang_afi_safi_value2identity(afi, safi), - bgp_afi_safi_get_container_str(afi, safi)); - - nb_cli_enqueue_change(vty, base_xpath, NB_OP_MODIFY, "false"); - - return nb_cli_apply_changes(vty, NULL); + return bgp_maxpaths_config_vty(vty, BGP_PEER_IBGP, NULL, 0, 0); } ALIAS_HIDDEN(no_bgp_maxpaths_ibgp, no_bgp_maxpaths_ibgp_hidden_cmd, @@ -2449,13 +2313,13 @@ static void bgp_config_write_maxpaths(struct vty *vty, struct bgp *bgp, /* BGP timers. */ -DEFUN_YANG (bgp_timers, - bgp_timers_cmd, - "timers bgp (0-65535) (0-65535)", - "Adjust routing timers\n" - "BGP timers\n" - "Keepalive interval\n" - "Holdtime\n") +DEFUN_YANG(bgp_timers, + bgp_timers_cmd, + "timers bgp (0-65535) (0-65535)", + "Adjust routing timers\n" + "BGP timers\n" + "Keepalive interval\n" + "Holdtime\n") { int idx_number = 2; int idx_number_2 = 3; @@ -2468,14 +2332,14 @@ DEFUN_YANG (bgp_timers, return nb_cli_apply_changes(vty, NULL); } -DEFUN_YANG (no_bgp_timers, - no_bgp_timers_cmd, - "no timers bgp [(0-65535) (0-65535)]", - NO_STR - "Adjust routing timers\n" - "BGP timers\n" - "Keepalive interval\n" - "Holdtime\n") +DEFUN_YANG(no_bgp_timers, + no_bgp_timers_cmd, + "no timers bgp [(0-65535) (0-65535)]", + NO_STR + "Adjust routing timers\n" + "BGP timers\n" + "Keepalive interval\n" + "Holdtime\n") { nb_cli_enqueue_change(vty, "./global/global-config-timers/keepalive", NB_OP_DESTROY, NULL); @@ -8438,33 +8302,6 @@ static int set_ecom_list(struct vty *vty, int argc, struct cmd_token **argv, return CMD_SUCCESS; } -bool vpn_policy_check_import(struct bgp *bgp, afi_t afi, safi_t safi, - bool v2vimport, char *errmsg, size_t errmsg_len) -{ - if (!v2vimport) { - if (CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST], - BGP_CONFIG_VRF_TO_VRF_IMPORT) - || CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST], - BGP_CONFIG_VRF_TO_VRF_EXPORT)) { - snprintf( - errmsg, errmsg_len, "%s", - "%% error: Please unconfigure import vrf commands before using vpn commands"); - return false; - } - } else { - if (CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST], - BGP_CONFIG_VRF_TO_MPLSVPN_EXPORT) - || CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST], - BGP_CONFIG_MPLSVPN_TO_VRF_IMPORT)) { - snprintf( - errmsg, errmsg_len, "%s", - "%% error: Please unconfigure vpn to vrf commands before using import vrf commands"); - return false; - } - } - return true; -} - /* * v2vimport is true if we are handling a `import vrf ...` command */ @@ -8507,45 +8344,57 @@ static afi_t vpn_policy_getafi(struct vty *vty, struct bgp *bgp, bool v2vimport) return afi; } -DEFPY_YANG( - af_rd_vpn_export, - af_rd_vpn_export_cmd, - "[no] rd vpn export ASN:NN_OR_IP-ADDRESS:NN$rd_str", - NO_STR - "Specify route distinguisher\n" - "Between current address-family and vpn\n" - "For routes leaked from current address-family to vpn\n" - "Route Distinguisher (: | :)\n") +DEFPY (af_rd_vpn_export, + af_rd_vpn_export_cmd, + "[no] rd vpn export ASN:NN_OR_IP-ADDRESS:NN$rd_str", + NO_STR + "Specify route distinguisher\n" + "Between current address-family and vpn\n" + "For routes leaked from current address-family to vpn\n" + "Route Distinguisher (: | :)\n") { - char base_xpath[XPATH_MAXLEN]; + VTY_DECLVAR_CONTEXT(bgp, bgp); + struct prefix_rd prd; + int ret; afi_t afi; - safi_t safi; int idx = 0; + bool yes = true; - afi = bgp_node_afi(vty); - safi = bgp_node_safi(vty); + if (argv_find(argv, argc, "no", &idx)) + yes = false; - snprintf( - base_xpath, sizeof(base_xpath), - "./global/afi-safis/afi-safi[afi-safi-name='%s']/%s/vpn-config", - yang_afi_safi_value2identity(afi, safi), - bgp_afi_safi_get_container_str(afi, safi)); + if (yes) { + ret = str2prefix_rd(rd_str, &prd); + if (!ret) { + vty_out(vty, "%% Malformed rd\n"); + return CMD_WARNING_CONFIG_FAILED; + } + } - if (argv_find(argv, argc, "no", &idx)) - nb_cli_enqueue_change(vty, "./rd", NB_OP_DESTROY, NULL); - else - nb_cli_enqueue_change(vty, "./rd", NB_OP_MODIFY, rd_str); + afi = vpn_policy_getafi(vty, bgp, false); + if (afi == AFI_MAX) + return CMD_WARNING_CONFIG_FAILED; - return nb_cli_apply_changes(vty, base_xpath); -} + /* + * pre-change: un-export vpn routes (vpn->vrf routes unaffected) + */ + vpn_leak_prechange(BGP_VPN_POLICY_DIR_TOVPN, afi, + bgp_get_default(), bgp); -void cli_show_bgp_global_afi_safi_ip_unicast_vpn_config_rd( - struct vty *vty, struct lyd_node *dnode, bool show_defaults) -{ - int indent = 2; + if (yes) { + bgp->vpn_policy[afi].tovpn_rd = prd; + SET_FLAG(bgp->vpn_policy[afi].flags, + BGP_VPN_POLICY_TOVPN_RD_SET); + } else { + UNSET_FLAG(bgp->vpn_policy[afi].flags, + BGP_VPN_POLICY_TOVPN_RD_SET); + } + + /* post-change: re-export vpn routes */ + vpn_leak_postchange(BGP_VPN_POLICY_DIR_TOVPN, afi, + bgp_get_default(), bgp); - vty_out(vty, "%*srd vpn export %s\n", indent, "", - yang_dnode_get_string(dnode, NULL)); + return CMD_SUCCESS; } ALIAS (af_rd_vpn_export, @@ -8647,7 +8496,7 @@ ALIAS (af_label_vpn_export, "Between current address-family and vpn\n" "For routes leaked from current address-family to vpn\n") -DEFPY_YANG (af_nexthop_vpn_export, +DEFPY (af_nexthop_vpn_export, af_nexthop_vpn_export_cmd, "[no] nexthop vpn export [$nexthop_su]", NO_STR @@ -8657,10 +8506,8 @@ DEFPY_YANG (af_nexthop_vpn_export, "IPv4 prefix\n" "IPv6 prefix\n") { - char base_xpath[XPATH_MAXLEN]; + VTY_DECLVAR_CONTEXT(bgp, bgp); afi_t afi; - safi_t safi; - int idx = 0; struct prefix p; if (!no) { @@ -8672,31 +8519,30 @@ DEFPY_YANG (af_nexthop_vpn_export, return CMD_WARNING_CONFIG_FAILED; } - afi = bgp_node_afi(vty); - safi = bgp_node_safi(vty); - - snprintf( - base_xpath, sizeof(base_xpath), - "./global/afi-safis/afi-safi[afi-safi-name='%s']/%s/vpn-config", - yang_afi_safi_value2identity(afi, safi), - bgp_afi_safi_get_container_str(afi, safi)); + afi = vpn_policy_getafi(vty, bgp, false); + if (afi == AFI_MAX) + return CMD_WARNING_CONFIG_FAILED; - if (argv_find(argv, argc, "no", &idx)) - nb_cli_enqueue_change(vty, "./nexthop", NB_OP_DESTROY, NULL); - else - nb_cli_enqueue_change(vty, "./nexthop", NB_OP_MODIFY, - nexthop_su_str); + /* + * pre-change: un-export vpn routes (vpn->vrf routes unaffected) + */ + vpn_leak_prechange(BGP_VPN_POLICY_DIR_TOVPN, afi, + bgp_get_default(), bgp); - return nb_cli_apply_changes(vty, base_xpath); -} + if (!no) { + bgp->vpn_policy[afi].tovpn_nexthop = p; + SET_FLAG(bgp->vpn_policy[afi].flags, + BGP_VPN_POLICY_TOVPN_NEXTHOP_SET); + } else { + UNSET_FLAG(bgp->vpn_policy[afi].flags, + BGP_VPN_POLICY_TOVPN_NEXTHOP_SET); + } -void cli_show_bgp_global_afi_safi_ip_unicast_vpn_config_nexthop( - struct vty *vty, struct lyd_node *dnode, bool show_defaults) -{ - int indent = 2; + /* post-change: re-export vpn routes */ + vpn_leak_postchange(BGP_VPN_POLICY_DIR_TOVPN, afi, + bgp_get_default(), bgp); - vty_out(vty, "%*snexthop vpn export %s\n", indent, "", - yang_dnode_get_string(dnode, NULL)); + return CMD_SUCCESS; } static int vpn_policy_getdirs(struct vty *vty, const char *dstr, int *dodir) @@ -8797,7 +8643,7 @@ ALIAS (af_rt_vpn_imexport, "For routes leaked from current address-family to vpn\n" "both import and export\n") -DEFPY_YANG (af_route_map_vpn_imexport, +DEFPY (af_route_map_vpn_imexport, af_route_map_vpn_imexport_cmd, /* future: "route-map RMAP" */ "[no] route-map vpn $direction_str RMAP$rmap_str", @@ -8808,54 +8654,53 @@ DEFPY_YANG (af_route_map_vpn_imexport, "For routes leaked from current address-family to vpn\n" "name of route-map\n") { - char base_xpath[XPATH_MAXLEN]; + VTY_DECLVAR_CONTEXT(bgp, bgp); + int ret; + int dodir[BGP_VPN_POLICY_DIR_MAX] = {0}; + vpn_policy_direction_t dir; afi_t afi; - safi_t safi; int idx = 0; + bool yes = true; - afi = bgp_node_afi(vty); - safi = bgp_node_safi(vty); + if (argv_find(argv, argc, "no", &idx)) + yes = false; - snprintf( - base_xpath, sizeof(base_xpath), - "./global/afi-safis/afi-safi[afi-safi-name='%s']/%s/vpn-config", - yang_afi_safi_value2identity(afi, safi), - bgp_afi_safi_get_container_str(afi, safi)); - - if (argv_find(argv, argc, "no", &idx)) { - if (!strcmp(direction_str, "import")) - nb_cli_enqueue_change(vty, "./rmap-import", - NB_OP_DESTROY, NULL); - else if (!strcmp(direction_str, "export")) - nb_cli_enqueue_change(vty, "./rmap-export", - NB_OP_DESTROY, NULL); - } else { - if (!strcmp(direction_str, "import")) - nb_cli_enqueue_change(vty, "./rmap-import", - NB_OP_MODIFY, rmap_str); - if (!strcmp(direction_str, "export")) - nb_cli_enqueue_change(vty, "./rmap-export", - NB_OP_MODIFY, rmap_str); - } - return nb_cli_apply_changes(vty, base_xpath); -} + afi = vpn_policy_getafi(vty, bgp, false); + if (afi == AFI_MAX) + return CMD_WARNING_CONFIG_FAILED; -void cli_show_bgp_global_afi_safi_ip_unicast_vpn_config_rmap_import( - struct vty *vty, struct lyd_node *dnode, bool show_defaults) -{ - int indent = 2; + ret = vpn_policy_getdirs(vty, direction_str, dodir); + if (ret != CMD_SUCCESS) + return ret; - vty_out(vty, "%*sroute-map vpn import %s\n", indent, "", - yang_dnode_get_string(dnode, NULL)); -} + for (dir = 0; dir < BGP_VPN_POLICY_DIR_MAX; ++dir) { + if (!dodir[dir]) + continue; -void cli_show_bgp_global_afi_safi_ip_unicast_vpn_config_rmap_export( - struct vty *vty, struct lyd_node *dnode, bool show_defaults) -{ - int indent = 2; + vpn_leak_prechange(dir, afi, bgp_get_default(), bgp); + + if (yes) { + if (bgp->vpn_policy[afi].rmap_name[dir]) + XFREE(MTYPE_ROUTE_MAP_NAME, + bgp->vpn_policy[afi].rmap_name[dir]); + bgp->vpn_policy[afi].rmap_name[dir] = XSTRDUP( + MTYPE_ROUTE_MAP_NAME, rmap_str); + bgp->vpn_policy[afi].rmap[dir] = + route_map_lookup_warn_noexist(vty, rmap_str); + if (!bgp->vpn_policy[afi].rmap[dir]) + return CMD_SUCCESS; + } else { + if (bgp->vpn_policy[afi].rmap_name[dir]) + XFREE(MTYPE_ROUTE_MAP_NAME, + bgp->vpn_policy[afi].rmap_name[dir]); + bgp->vpn_policy[afi].rmap_name[dir] = NULL; + bgp->vpn_policy[afi].rmap[dir] = NULL; + } + + vpn_leak_postchange(dir, afi, bgp_get_default(), bgp); + } - vty_out(vty, "%*sroute-map vpn import %s\n", indent, "", - yang_dnode_get_string(dnode, NULL)); + return CMD_SUCCESS; } ALIAS (af_route_map_vpn_imexport, @@ -8952,18 +8797,24 @@ DEFPY(af_no_import_vrf_route_map, af_no_import_vrf_route_map_cmd, return CMD_SUCCESS; } -DEFPY_YANG(bgp_imexport_vrf, - bgp_imexport_vrf_cmd, - "[no] import vrf VIEWVRFNAME$import_name", - NO_STR - "Import routes from another VRF\n" - "VRF to import from\n" - "The name of the VRF\n") +DEFPY(bgp_imexport_vrf, bgp_imexport_vrf_cmd, + "[no] import vrf VIEWVRFNAME$import_name", + NO_STR + "Import routes from another VRF\n" + "VRF to import from\n" + "The name of the VRF\n") { - char base_xpath[XPATH_MAXLEN]; + VTY_DECLVAR_CONTEXT(bgp, bgp); + struct listnode *node; + struct bgp *vrf_bgp, *bgp_default; + int32_t ret = 0; + as_t as = bgp->as; + bool remove = false; + int32_t idx = 0; + char *vname; + enum bgp_instance_type bgp_type = BGP_INSTANCE_TYPE_VRF; safi_t safi; afi_t afi; - int32_t idx = 0; if (import_name == NULL) { vty_out(vty, "%% Missing import name\n"); @@ -8975,32 +8826,70 @@ DEFPY_YANG(bgp_imexport_vrf, return CMD_WARNING; } - afi = bgp_node_afi(vty); - safi = bgp_node_safi(vty); + if (argv_find(argv, argc, "no", &idx)) + remove = true; - snprintf( - base_xpath, sizeof(base_xpath), - "./global/afi-safis/afi-safi[afi-safi-name='%s']/%s/vpn-config/import-vrf-list[vrf='%s']", - yang_afi_safi_value2identity(afi, safi), - bgp_afi_safi_get_container_str(afi, safi), import_name); + afi = vpn_policy_getafi(vty, bgp, true); + if (afi == AFI_MAX) + return CMD_WARNING_CONFIG_FAILED; - if (argv_find(argv, argc, "no", &idx)) - nb_cli_enqueue_change(vty, ".", NB_OP_DESTROY, NULL); - else - nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL); + safi = bgp_node_safi(vty); - return nb_cli_apply_changes(vty, base_xpath); -} + if (((BGP_INSTANCE_TYPE_DEFAULT == bgp->inst_type) + && (strcmp(import_name, VRF_DEFAULT_NAME) == 0)) + || (bgp->name && (strcmp(import_name, bgp->name) == 0))) { + vty_out(vty, "%% Cannot %s vrf %s into itself\n", + remove ? "unimport" : "import", import_name); + return CMD_WARNING; + } -void cli_show_bgp_global_afi_safi_ip_unicast_vpn_config_import_vrfs( - struct vty *vty, struct lyd_node *dnode, bool show_defaults) -{ - vty_out(vty, " import vrf %s\n", - yang_dnode_get_string(dnode, "./vrf")); + bgp_default = bgp_get_default(); + if (!bgp_default) { + /* Auto-create assuming the same AS */ + ret = bgp_get_vty(&bgp_default, &as, NULL, + BGP_INSTANCE_TYPE_DEFAULT); + + if (ret) { + vty_out(vty, + "VRF default is not configured as a bgp instance\n"); + return CMD_WARNING; + } + } + + vrf_bgp = bgp_lookup_by_name(import_name); + if (!vrf_bgp) { + if (strcmp(import_name, VRF_DEFAULT_NAME) == 0) + vrf_bgp = bgp_default; + else + /* Auto-create assuming the same AS */ + ret = bgp_get_vty(&vrf_bgp, &as, import_name, bgp_type); + + if (ret) { + vty_out(vty, + "VRF %s is not configured as a bgp instance\n", + import_name); + return CMD_WARNING; + } + } + + if (remove) { + vrf_unimport_from_vrf(bgp, vrf_bgp, afi, safi); + } else { + /* Already importing from "import_vrf"? */ + for (ALL_LIST_ELEMENTS_RO(bgp->vpn_policy[afi].import_vrf, node, + vname)) { + if (strcmp(vname, import_name) == 0) + return CMD_WARNING; + } + + vrf_import_from_vrf(bgp, vrf_bgp, afi, safi); + } + + return CMD_SUCCESS; } /* This command is valid only in a bgp vrf instance or the default instance */ -DEFPY_YANG (bgp_imexport_vpn, +DEFPY (bgp_imexport_vpn, bgp_imexport_vpn_cmd, "[no] $direction_str vpn", NO_STR @@ -9008,51 +8897,60 @@ DEFPY_YANG (bgp_imexport_vpn, "Export routes from this address-family\n" "to/from default instance VPN RIB\n") { - char base_xpath[XPATH_MAXLEN]; - safi_t safi; + VTY_DECLVAR_CONTEXT(bgp, bgp); + int previous_state; afi_t afi; - int32_t idx = 0; + safi_t safi; + int idx = 0; + bool yes = true; + int flag; + vpn_policy_direction_t dir; + + if (argv_find(argv, argc, "no", &idx)) + yes = false; + + if (BGP_INSTANCE_TYPE_VRF != bgp->inst_type && + BGP_INSTANCE_TYPE_DEFAULT != bgp->inst_type) { + + vty_out(vty, "%% import|export vpn valid only for bgp vrf or default instance\n"); + return CMD_WARNING_CONFIG_FAILED; + } afi = bgp_node_afi(vty); safi = bgp_node_safi(vty); + if ((SAFI_UNICAST != safi) || ((AFI_IP != afi) && (AFI_IP6 != afi))) { + vty_out(vty, "%% import|export vpn valid only for unicast ipv4|ipv6\n"); + return CMD_WARNING_CONFIG_FAILED; + } if (!strcmp(direction_str, "import")) { - snprintf( - base_xpath, sizeof(base_xpath), - "./global/afi-safis/afi-safi[afi-safi-name='%s']/%s/vpn-config/import-vpn", - yang_afi_safi_value2identity(afi, safi), - bgp_afi_safi_get_container_str(afi, safi)); + flag = BGP_CONFIG_MPLSVPN_TO_VRF_IMPORT; + dir = BGP_VPN_POLICY_DIR_FROMVPN; } else if (!strcmp(direction_str, "export")) { - snprintf( - base_xpath, sizeof(base_xpath), - "./global/afi-safis/afi-safi[afi-safi-name='%s']/%s/vpn-config/export-vpn", - yang_afi_safi_value2identity(afi, safi), - bgp_afi_safi_get_container_str(afi, safi)); + flag = BGP_CONFIG_VRF_TO_MPLSVPN_EXPORT; + dir = BGP_VPN_POLICY_DIR_TOVPN; } else { vty_out(vty, "%% unknown direction %s\n", direction_str); return CMD_WARNING_CONFIG_FAILED; } - if (argv_find(argv, argc, "no", &idx)) - nb_cli_enqueue_change(vty, ".", NB_OP_DESTROY, NULL); - else - nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, "true"); + previous_state = CHECK_FLAG(bgp->af_flags[afi][safi], flag); - return nb_cli_apply_changes(vty, base_xpath); -} - -void cli_show_bgp_global_afi_safi_ip_unicast_vpn_config_import_vpn( - struct vty *vty, struct lyd_node *dnode, bool show_defaults) -{ - if (yang_dnode_get_bool(dnode, NULL)) - vty_out(vty, " import vpn\n"); -} + if (yes) { + SET_FLAG(bgp->af_flags[afi][safi], flag); + if (!previous_state) { + /* trigger export current vrf */ + vpn_leak_postchange(dir, afi, bgp_get_default(), bgp); + } + } else { + if (previous_state) { + /* trigger un-export current vrf */ + vpn_leak_prechange(dir, afi, bgp_get_default(), bgp); + } + UNSET_FLAG(bgp->af_flags[afi][safi], flag); + } -void cli_show_bgp_global_afi_safi_ip_unicast_vpn_config_export_vpn( - struct vty *vty, struct lyd_node *dnode, bool show_defaults) -{ - if (yang_dnode_get_bool(dnode, NULL)) - vty_out(vty, " export vpn\n"); + return CMD_SUCCESS; } DEFPY (af_routetarget_import, @@ -9118,51 +9016,6 @@ DEFPY (af_routetarget_import, return CMD_SUCCESS; } -void cli_show_bgp_global_afi_safi_header(struct vty *vty, - struct lyd_node *dnode, - bool show_defaults) -{ - const char *af_name; - afi_t afi; - safi_t safi; - - af_name = yang_dnode_get_string(dnode, "./afi-safi-name"); - yang_afi_safi_identity2value(af_name, &afi, &safi); - - vty_out(vty, " !\n address-family "); - if (afi == AFI_IP) { - if (safi == SAFI_UNICAST) - vty_out(vty, "ipv4 unicast"); - else if (safi == SAFI_LABELED_UNICAST) - vty_out(vty, "ipv4 labeled-unicast"); - else if (safi == SAFI_MULTICAST) - vty_out(vty, "ipv4 multicast"); - else if (safi == SAFI_MPLS_VPN) - vty_out(vty, "ipv4 vpn"); - else if (safi == SAFI_ENCAP) - vty_out(vty, "ipv4 encap"); - else if (safi == SAFI_FLOWSPEC) - vty_out(vty, "ipv4 flowspec"); - } else if (afi == AFI_IP6) { - if (safi == SAFI_UNICAST) - vty_out(vty, "ipv6 unicast"); - else if (safi == SAFI_LABELED_UNICAST) - vty_out(vty, "ipv6 labeled-unicast"); - else if (safi == SAFI_MULTICAST) - vty_out(vty, "ipv6 multicast"); - else if (safi == SAFI_MPLS_VPN) - vty_out(vty, "ipv6 vpn"); - else if (safi == SAFI_ENCAP) - vty_out(vty, "ipv6 encap"); - else if (safi == SAFI_FLOWSPEC) - vty_out(vty, "ipv6 flowspec"); - } else if (afi == AFI_L2VPN) { - if (safi == SAFI_EVPN) - vty_out(vty, "l2vpn evpn"); - } - vty_out(vty, "\n"); -} - DEFUN_NOSH (address_family_ipv4_safi, address_family_ipv4_safi_cmd, "address-family ipv4 []", @@ -9171,28 +9024,19 @@ DEFUN_NOSH (address_family_ipv4_safi, BGP_SAFI_WITH_LABEL_HELP_STR) { - safi_t safi = SAFI_UNICAST; - const struct lyd_node *vrf_dnode, *bgp_glb_dnode; - const char *vrf_name = NULL; - if (argc == 3) { - safi = bgp_vty_safi_from_str(argv[2]->text); - - bgp_glb_dnode = yang_dnode_get(vty->candidate_config->dnode, - VTY_CURR_XPATH); - vrf_dnode = yang_dnode_get_parent(bgp_glb_dnode, - "control-plane-protocol"); - vrf_name = yang_dnode_get_string(vrf_dnode, "./vrf"); - - if (!strmatch(vrf_name, VRF_DEFAULT_NAME) + VTY_DECLVAR_CONTEXT(bgp, bgp); + safi_t safi = bgp_vty_safi_from_str(argv[2]->text); + if (bgp->inst_type != BGP_INSTANCE_TYPE_DEFAULT && safi != SAFI_UNICAST && safi != SAFI_MULTICAST && safi != SAFI_EVPN) { vty_out(vty, "Only Unicast/Multicast/EVPN SAFIs supported in non-core instances.\n"); return CMD_WARNING_CONFIG_FAILED; } - } - vty->node = bgp_node_type(AFI_IP, safi); + vty->node = bgp_node_type(AFI_IP, safi); + } else + vty->node = BGP_IPV4_NODE; return CMD_SUCCESS; } @@ -9204,27 +9048,19 @@ DEFUN_NOSH (address_family_ipv6_safi, "Address Family\n" BGP_SAFI_WITH_LABEL_HELP_STR) { - safi_t safi = SAFI_UNICAST; - const struct lyd_node *vrf_dnode, *bgp_glb_dnode; - const char *vrf_name = NULL; - if (argc == 3) { - safi = bgp_vty_safi_from_str(argv[2]->text); - bgp_glb_dnode = yang_dnode_get(vty->candidate_config->dnode, - VTY_CURR_XPATH); - vrf_dnode = yang_dnode_get_parent(bgp_glb_dnode, - "control-plane-protocol"); - vrf_name = yang_dnode_get_string(vrf_dnode, "./vrf"); - - if (!strmatch(vrf_name, VRF_DEFAULT_NAME) + VTY_DECLVAR_CONTEXT(bgp, bgp); + safi_t safi = bgp_vty_safi_from_str(argv[2]->text); + if (bgp->inst_type != BGP_INSTANCE_TYPE_DEFAULT && safi != SAFI_UNICAST && safi != SAFI_MULTICAST && safi != SAFI_EVPN) { vty_out(vty, "Only Unicast/Multicast/EVPN SAFIs supported in non-core instances.\n"); return CMD_WARNING_CONFIG_FAILED; } - } - vty->node = bgp_node_type(AFI_IP6, safi); + vty->node = bgp_node_type(AFI_IP6, safi); + } else + vty->node = BGP_IPV6_NODE; return CMD_SUCCESS; } @@ -9281,13 +9117,6 @@ DEFUN_NOSH (exit_address_family, return CMD_SUCCESS; } -void cli_show_bgp_global_afi_safi_header_end(struct vty *vty, - struct lyd_node *dnode - __attribute__((__unused__))) -{ - vty_out(vty, " exit-address-family\n"); -} - /* Recalculate bestpath and re-advertise a prefix */ static int bgp_clear_prefix(struct vty *vty, const char *view_name, const char *ip_str, afi_t afi, safi_t safi, @@ -15224,23 +15053,24 @@ DEFUN(show_ip_bgp_peer_groups, show_ip_bgp_peer_groups_cmd, /* Redistribute VTY commands. */ -DEFUN_YANG (bgp_redistribute_ipv4, - bgp_redistribute_ipv4_cmd, - "redistribute " FRR_IP_REDIST_STR_BGPD, - "Redistribute information from another routing protocol\n" - FRR_IP_REDIST_HELP_STR_BGPD) +DEFUN (bgp_redistribute_ipv4, + bgp_redistribute_ipv4_cmd, + "redistribute " FRR_IP_REDIST_STR_BGPD, + "Redistribute information from another routing protocol\n" + FRR_IP_REDIST_HELP_STR_BGPD) { + VTY_DECLVAR_CONTEXT(bgp, bgp); int idx_protocol = 1; - char base_xpath[XPATH_MAXLEN]; + int type; - snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_AFI_SAFI_REDIST_XPATH, - yang_afi_safi_value2identity(AFI_IP, SAFI_UNICAST), - bgp_afi_safi_get_container_str(AFI_IP, SAFI_UNICAST), - argv[idx_protocol]->text, "0"); - - nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL); + type = proto_redistnum(AFI_IP, argv[idx_protocol]->text); + if (type < 0) { + vty_out(vty, "%% Invalid route type\n"); + return CMD_WARNING_CONFIG_FAILED; + } - return nb_cli_apply_changes(vty, base_xpath); + bgp_redist_add(bgp, AFI_IP, type, 0); + return bgp_redistribute_set(bgp, AFI_IP, type, 0, false); } ALIAS_HIDDEN( @@ -15248,28 +15078,33 @@ ALIAS_HIDDEN( "redistribute " FRR_IP_REDIST_STR_BGPD, "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD) -DEFUN_YANG (bgp_redistribute_ipv4_rmap, - bgp_redistribute_ipv4_rmap_cmd, - "redistribute " FRR_IP_REDIST_STR_BGPD " route-map WORD", - "Redistribute information from another routing protocol\n" - FRR_IP_REDIST_HELP_STR_BGPD - "Route map reference\n" - "Pointer to route-map entries\n") +DEFUN (bgp_redistribute_ipv4_rmap, + bgp_redistribute_ipv4_rmap_cmd, + "redistribute " FRR_IP_REDIST_STR_BGPD " route-map WORD", + "Redistribute information from another routing protocol\n" + FRR_IP_REDIST_HELP_STR_BGPD + "Route map reference\n" + "Pointer to route-map entries\n") { + VTY_DECLVAR_CONTEXT(bgp, bgp); int idx_protocol = 1; int idx_word = 3; - char base_xpath[XPATH_MAXLEN]; - - snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_AFI_SAFI_REDIST_XPATH, - yang_afi_safi_value2identity(AFI_IP, SAFI_UNICAST), - bgp_afi_safi_get_container_str(AFI_IP, SAFI_UNICAST), - argv[idx_protocol]->text, "0"); - - nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL); - nb_cli_enqueue_change(vty, "./rmap-policy-import", NB_OP_CREATE, - argv[idx_word]->arg); + int type; + struct bgp_redist *red; + bool changed; + struct route_map *route_map = route_map_lookup_warn_noexist( + vty, argv[idx_word]->arg); + + type = proto_redistnum(AFI_IP, argv[idx_protocol]->text); + if (type < 0) { + vty_out(vty, "%% Invalid route type\n"); + return CMD_WARNING_CONFIG_FAILED; + } - return nb_cli_apply_changes(vty, base_xpath); + red = bgp_redist_add(bgp, AFI_IP, type, 0); + changed = + bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map); + return bgp_redistribute_set(bgp, AFI_IP, type, 0, changed); } ALIAS_HIDDEN( @@ -15279,28 +15114,32 @@ ALIAS_HIDDEN( "Route map reference\n" "Pointer to route-map entries\n") -DEFUN_YANG (bgp_redistribute_ipv4_metric, - bgp_redistribute_ipv4_metric_cmd, - "redistribute " FRR_IP_REDIST_STR_BGPD " metric (0-4294967295)", - "Redistribute information from another routing protocol\n" - FRR_IP_REDIST_HELP_STR_BGPD - "Metric for redistributed routes\n" - "Default metric\n") +DEFUN (bgp_redistribute_ipv4_metric, + bgp_redistribute_ipv4_metric_cmd, + "redistribute " FRR_IP_REDIST_STR_BGPD " metric (0-4294967295)", + "Redistribute information from another routing protocol\n" + FRR_IP_REDIST_HELP_STR_BGPD + "Metric for redistributed routes\n" + "Default metric\n") { + VTY_DECLVAR_CONTEXT(bgp, bgp); int idx_protocol = 1; int idx_number = 3; - char base_xpath[XPATH_MAXLEN]; - - snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_AFI_SAFI_REDIST_XPATH, - yang_afi_safi_value2identity(AFI_IP, SAFI_UNICAST), - bgp_afi_safi_get_container_str(AFI_IP, SAFI_UNICAST), - argv[idx_protocol]->text, "0"); - - nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL); - nb_cli_enqueue_change(vty, "./metric", NB_OP_CREATE, - argv[idx_number]->arg); + int type; + uint32_t metric; + struct bgp_redist *red; + bool changed; + + type = proto_redistnum(AFI_IP, argv[idx_protocol]->text); + if (type < 0) { + vty_out(vty, "%% Invalid route type\n"); + return CMD_WARNING_CONFIG_FAILED; + } + metric = strtoul(argv[idx_number]->arg, NULL, 10); - return nb_cli_apply_changes(vty, base_xpath); + red = bgp_redist_add(bgp, AFI_IP, type, 0); + changed = bgp_redistribute_metric_set(bgp, red, AFI_IP, type, metric); + return bgp_redistribute_set(bgp, AFI_IP, type, 0, changed); } ALIAS_HIDDEN( @@ -15310,34 +15149,39 @@ ALIAS_HIDDEN( "Metric for redistributed routes\n" "Default metric\n") -DEFUN_YANG( - bgp_redistribute_ipv4_rmap_metric, - bgp_redistribute_ipv4_rmap_metric_cmd, - "redistribute " FRR_IP_REDIST_STR_BGPD - " route-map WORD metric (0-4294967295)", - "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD - "Route map reference\n" - "Pointer to route-map entries\n" - "Metric for redistributed routes\n" - "Default metric\n") +DEFUN (bgp_redistribute_ipv4_rmap_metric, + bgp_redistribute_ipv4_rmap_metric_cmd, + "redistribute " FRR_IP_REDIST_STR_BGPD " route-map WORD metric (0-4294967295)", + "Redistribute information from another routing protocol\n" + FRR_IP_REDIST_HELP_STR_BGPD + "Route map reference\n" + "Pointer to route-map entries\n" + "Metric for redistributed routes\n" + "Default metric\n") { + VTY_DECLVAR_CONTEXT(bgp, bgp); int idx_protocol = 1; int idx_word = 3; int idx_number = 5; - char base_xpath[XPATH_MAXLEN]; - - snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_AFI_SAFI_REDIST_XPATH, - yang_afi_safi_value2identity(AFI_IP, SAFI_UNICAST), - bgp_afi_safi_get_container_str(AFI_IP, SAFI_UNICAST), - argv[idx_protocol]->text, "0"); - - nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL); - nb_cli_enqueue_change(vty, "./rmap-policy-import", NB_OP_CREATE, - argv[idx_word]->arg); - nb_cli_enqueue_change(vty, "./metric", NB_OP_CREATE, - argv[idx_number]->arg); + int type; + uint32_t metric; + struct bgp_redist *red; + bool changed; + struct route_map *route_map = + route_map_lookup_warn_noexist(vty, argv[idx_word]->arg); + + type = proto_redistnum(AFI_IP, argv[idx_protocol]->text); + if (type < 0) { + vty_out(vty, "%% Invalid route type\n"); + return CMD_WARNING_CONFIG_FAILED; + } + metric = strtoul(argv[idx_number]->arg, NULL, 10); - return nb_cli_apply_changes(vty, base_xpath); + red = bgp_redist_add(bgp, AFI_IP, type, 0); + changed = + bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map); + changed |= bgp_redistribute_metric_set(bgp, red, AFI_IP, type, metric); + return bgp_redistribute_set(bgp, AFI_IP, type, 0, changed); } ALIAS_HIDDEN( @@ -15351,34 +15195,39 @@ ALIAS_HIDDEN( "Metric for redistributed routes\n" "Default metric\n") -DEFUN_YANG( - bgp_redistribute_ipv4_metric_rmap, - bgp_redistribute_ipv4_metric_rmap_cmd, - "redistribute " FRR_IP_REDIST_STR_BGPD - " metric (0-4294967295) route-map WORD", - "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD - "Metric for redistributed routes\n" - "Default metric\n" - "Route map reference\n" - "Pointer to route-map entries\n") +DEFUN (bgp_redistribute_ipv4_metric_rmap, + bgp_redistribute_ipv4_metric_rmap_cmd, + "redistribute " FRR_IP_REDIST_STR_BGPD " metric (0-4294967295) route-map WORD", + "Redistribute information from another routing protocol\n" + FRR_IP_REDIST_HELP_STR_BGPD + "Metric for redistributed routes\n" + "Default metric\n" + "Route map reference\n" + "Pointer to route-map entries\n") { + VTY_DECLVAR_CONTEXT(bgp, bgp); int idx_protocol = 1; - int idx_word = 5; int idx_number = 3; - char base_xpath[XPATH_MAXLEN]; - - snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_AFI_SAFI_REDIST_XPATH, - yang_afi_safi_value2identity(AFI_IP, SAFI_UNICAST), - bgp_afi_safi_get_container_str(AFI_IP, SAFI_UNICAST), - argv[idx_protocol]->text, "0"); - - nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL); - nb_cli_enqueue_change(vty, "./metric", NB_OP_CREATE, - argv[idx_number]->arg); - nb_cli_enqueue_change(vty, "./rmap-policy-import", NB_OP_CREATE, - argv[idx_word]->arg); + int idx_word = 5; + int type; + uint32_t metric; + struct bgp_redist *red; + bool changed; + struct route_map *route_map = + route_map_lookup_warn_noexist(vty, argv[idx_word]->arg); + + type = proto_redistnum(AFI_IP, argv[idx_protocol]->text); + if (type < 0) { + vty_out(vty, "%% Invalid route type\n"); + return CMD_WARNING_CONFIG_FAILED; + } + metric = strtoul(argv[idx_number]->arg, NULL, 10); - return nb_cli_apply_changes(vty, base_xpath); + red = bgp_redist_add(bgp, AFI_IP, type, 0); + changed = bgp_redistribute_metric_set(bgp, red, AFI_IP, type, metric); + changed |= + bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map); + return bgp_redistribute_set(bgp, AFI_IP, type, 0, changed); } ALIAS_HIDDEN( @@ -15392,26 +15241,29 @@ ALIAS_HIDDEN( "Route map reference\n" "Pointer to route-map entries\n") -DEFUN_YANG (bgp_redistribute_ipv4_ospf, - bgp_redistribute_ipv4_ospf_cmd, - "redistribute (1-65535)", - "Redistribute information from another routing protocol\n" - "Open Shortest Path First (OSPFv2)\n" - "Non-main Kernel Routing Table\n" - "Instance ID/Table ID\n") +DEFUN (bgp_redistribute_ipv4_ospf, + bgp_redistribute_ipv4_ospf_cmd, + "redistribute (1-65535)", + "Redistribute information from another routing protocol\n" + "Open Shortest Path First (OSPFv2)\n" + "Non-main Kernel Routing Table\n" + "Instance ID/Table ID\n") { - int idx_protocol = 1; + VTY_DECLVAR_CONTEXT(bgp, bgp); + int idx_ospf_table = 1; int idx_number = 2; - char base_xpath[XPATH_MAXLEN]; + unsigned short instance; + unsigned short protocol; - snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_AFI_SAFI_REDIST_XPATH, - yang_afi_safi_value2identity(AFI_IP, SAFI_UNICAST), - bgp_afi_safi_get_container_str(AFI_IP, SAFI_UNICAST), - argv[idx_protocol]->text, argv[idx_number]->arg); + instance = strtoul(argv[idx_number]->arg, NULL, 10); - nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL); + if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0) + protocol = ZEBRA_ROUTE_OSPF; + else + protocol = ZEBRA_ROUTE_TABLE; - return nb_cli_apply_changes(vty, base_xpath); + bgp_redist_add(bgp, AFI_IP, protocol, instance); + return bgp_redistribute_set(bgp, AFI_IP, protocol, instance, false); } ALIAS_HIDDEN(bgp_redistribute_ipv4_ospf, bgp_redistribute_ipv4_ospf_hidden_cmd, @@ -15421,32 +15273,37 @@ ALIAS_HIDDEN(bgp_redistribute_ipv4_ospf, bgp_redistribute_ipv4_ospf_hidden_cmd, "Non-main Kernel Routing Table\n" "Instance ID/Table ID\n") -DEFUN_YANG (bgp_redistribute_ipv4_ospf_rmap, - bgp_redistribute_ipv4_ospf_rmap_cmd, - "redistribute (1-65535) route-map WORD", - "Redistribute information from another routing protocol\n" - "Open Shortest Path First (OSPFv2)\n" - "Non-main Kernel Routing Table\n" - "Instance ID/Table ID\n" - "Route map reference\n" - "Pointer to route-map entries\n") +DEFUN (bgp_redistribute_ipv4_ospf_rmap, + bgp_redistribute_ipv4_ospf_rmap_cmd, + "redistribute (1-65535) route-map WORD", + "Redistribute information from another routing protocol\n" + "Open Shortest Path First (OSPFv2)\n" + "Non-main Kernel Routing Table\n" + "Instance ID/Table ID\n" + "Route map reference\n" + "Pointer to route-map entries\n") { - int idx_protocol = 1; + VTY_DECLVAR_CONTEXT(bgp, bgp); + int idx_ospf_table = 1; int idx_number = 2; int idx_word = 4; - char base_xpath[XPATH_MAXLEN]; - - snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_AFI_SAFI_REDIST_XPATH, - yang_afi_safi_value2identity(AFI_IP, SAFI_UNICAST), - bgp_afi_safi_get_container_str(AFI_IP, SAFI_UNICAST), - argv[idx_protocol]->text, argv[idx_number]->arg); - - nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL); - - nb_cli_enqueue_change(vty, "./rmap-policy-import", NB_OP_CREATE, - argv[idx_word]->arg); + struct bgp_redist *red; + unsigned short instance; + int protocol; + bool changed; + struct route_map *route_map = + route_map_lookup_warn_noexist(vty, argv[idx_word]->arg); + + if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0) + protocol = ZEBRA_ROUTE_OSPF; + else + protocol = ZEBRA_ROUTE_TABLE; - return nb_cli_apply_changes(vty, base_xpath); + instance = strtoul(argv[idx_number]->arg, NULL, 10); + red = bgp_redist_add(bgp, AFI_IP, protocol, instance); + changed = + bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map); + return bgp_redistribute_set(bgp, AFI_IP, protocol, instance, changed); } ALIAS_HIDDEN(bgp_redistribute_ipv4_ospf_rmap, @@ -15459,32 +15316,38 @@ ALIAS_HIDDEN(bgp_redistribute_ipv4_ospf_rmap, "Route map reference\n" "Pointer to route-map entries\n") -DEFUN_YANG(bgp_redistribute_ipv4_ospf_metric, - bgp_redistribute_ipv4_ospf_metric_cmd, - "redistribute (1-65535) metric (0-4294967295)", - "Redistribute information from another routing protocol\n" - "Open Shortest Path First (OSPFv2)\n" - "Non-main Kernel Routing Table\n" - "Instance ID/Table ID\n" - "Metric for redistributed routes\n" - "Default metric\n") +DEFUN (bgp_redistribute_ipv4_ospf_metric, + bgp_redistribute_ipv4_ospf_metric_cmd, + "redistribute (1-65535) metric (0-4294967295)", + "Redistribute information from another routing protocol\n" + "Open Shortest Path First (OSPFv2)\n" + "Non-main Kernel Routing Table\n" + "Instance ID/Table ID\n" + "Metric for redistributed routes\n" + "Default metric\n") { - int idx_protocol = 1; + VTY_DECLVAR_CONTEXT(bgp, bgp); + int idx_ospf_table = 1; int idx_number = 2; int idx_number_2 = 4; - char base_xpath[XPATH_MAXLEN]; - - snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_AFI_SAFI_REDIST_XPATH, - yang_afi_safi_value2identity(AFI_IP, SAFI_UNICAST), - bgp_afi_safi_get_container_str(AFI_IP, SAFI_UNICAST), - argv[idx_protocol]->text, argv[idx_number]->arg); - - nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL); + uint32_t metric; + struct bgp_redist *red; + unsigned short instance; + int protocol; + bool changed; + + if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0) + protocol = ZEBRA_ROUTE_OSPF; + else + protocol = ZEBRA_ROUTE_TABLE; - nb_cli_enqueue_change(vty, "./metric", NB_OP_CREATE, - argv[idx_number_2]->arg); + instance = strtoul(argv[idx_number]->arg, NULL, 10); + metric = strtoul(argv[idx_number_2]->arg, NULL, 10); - return nb_cli_apply_changes(vty, base_xpath); + red = bgp_redist_add(bgp, AFI_IP, protocol, instance); + changed = bgp_redistribute_metric_set(bgp, red, AFI_IP, protocol, + metric); + return bgp_redistribute_set(bgp, AFI_IP, protocol, instance, changed); } ALIAS_HIDDEN(bgp_redistribute_ipv4_ospf_metric, @@ -15497,38 +15360,45 @@ ALIAS_HIDDEN(bgp_redistribute_ipv4_ospf_metric, "Metric for redistributed routes\n" "Default metric\n") -DEFUN_YANG( - bgp_redistribute_ipv4_ospf_rmap_metric, - bgp_redistribute_ipv4_ospf_rmap_metric_cmd, - "redistribute (1-65535) route-map WORD metric (0-4294967295)", - "Redistribute information from another routing protocol\n" - "Open Shortest Path First (OSPFv2)\n" - "Non-main Kernel Routing Table\n" - "Instance ID/Table ID\n" - "Route map reference\n" - "Pointer to route-map entries\n" - "Metric for redistributed routes\n" - "Default metric\n") +DEFUN (bgp_redistribute_ipv4_ospf_rmap_metric, + bgp_redistribute_ipv4_ospf_rmap_metric_cmd, + "redistribute (1-65535) route-map WORD metric (0-4294967295)", + "Redistribute information from another routing protocol\n" + "Open Shortest Path First (OSPFv2)\n" + "Non-main Kernel Routing Table\n" + "Instance ID/Table ID\n" + "Route map reference\n" + "Pointer to route-map entries\n" + "Metric for redistributed routes\n" + "Default metric\n") { - int idx_protocol = 1; + VTY_DECLVAR_CONTEXT(bgp, bgp); + int idx_ospf_table = 1; int idx_number = 2; int idx_word = 4; int idx_number_2 = 6; - char base_xpath[XPATH_MAXLEN]; - - snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_AFI_SAFI_REDIST_XPATH, - yang_afi_safi_value2identity(AFI_IP, SAFI_UNICAST), - bgp_afi_safi_get_container_str(AFI_IP, SAFI_UNICAST), - argv[idx_protocol]->text, argv[idx_number]->arg); - - nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL); + uint32_t metric; + struct bgp_redist *red; + unsigned short instance; + int protocol; + bool changed; + struct route_map *route_map = + route_map_lookup_warn_noexist(vty, argv[idx_word]->arg); + + if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0) + protocol = ZEBRA_ROUTE_OSPF; + else + protocol = ZEBRA_ROUTE_TABLE; - nb_cli_enqueue_change(vty, "./rmap-policy-import", NB_OP_CREATE, - argv[idx_word]->arg); - nb_cli_enqueue_change(vty, "./metric", NB_OP_CREATE, - argv[idx_number_2]->arg); + instance = strtoul(argv[idx_number]->arg, NULL, 10); + metric = strtoul(argv[idx_number_2]->arg, NULL, 10); - return nb_cli_apply_changes(vty, base_xpath); + red = bgp_redist_add(bgp, AFI_IP, protocol, instance); + changed = + bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map); + changed |= bgp_redistribute_metric_set(bgp, red, AFI_IP, protocol, + metric); + return bgp_redistribute_set(bgp, AFI_IP, protocol, instance, changed); } ALIAS_HIDDEN( @@ -15544,38 +15414,45 @@ ALIAS_HIDDEN( "Metric for redistributed routes\n" "Default metric\n") -DEFUN_YANG( - bgp_redistribute_ipv4_ospf_metric_rmap, - bgp_redistribute_ipv4_ospf_metric_rmap_cmd, - "redistribute (1-65535) metric (0-4294967295) route-map WORD", - "Redistribute information from another routing protocol\n" - "Open Shortest Path First (OSPFv2)\n" - "Non-main Kernel Routing Table\n" - "Instance ID/Table ID\n" - "Metric for redistributed routes\n" - "Default metric\n" - "Route map reference\n" - "Pointer to route-map entries\n") +DEFUN (bgp_redistribute_ipv4_ospf_metric_rmap, + bgp_redistribute_ipv4_ospf_metric_rmap_cmd, + "redistribute (1-65535) metric (0-4294967295) route-map WORD", + "Redistribute information from another routing protocol\n" + "Open Shortest Path First (OSPFv2)\n" + "Non-main Kernel Routing Table\n" + "Instance ID/Table ID\n" + "Metric for redistributed routes\n" + "Default metric\n" + "Route map reference\n" + "Pointer to route-map entries\n") { - int idx_protocol = 1; + VTY_DECLVAR_CONTEXT(bgp, bgp); + int idx_ospf_table = 1; int idx_number = 2; int idx_number_2 = 4; int idx_word = 6; - char base_xpath[XPATH_MAXLEN]; - - snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_AFI_SAFI_REDIST_XPATH, - yang_afi_safi_value2identity(AFI_IP, SAFI_UNICAST), - bgp_afi_safi_get_container_str(AFI_IP, SAFI_UNICAST), - argv[idx_protocol]->text, argv[idx_number]->arg); - - nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL); + uint32_t metric; + struct bgp_redist *red; + unsigned short instance; + int protocol; + bool changed; + struct route_map *route_map = + route_map_lookup_warn_noexist(vty, argv[idx_word]->arg); + + if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0) + protocol = ZEBRA_ROUTE_OSPF; + else + protocol = ZEBRA_ROUTE_TABLE; - nb_cli_enqueue_change(vty, "./metric", NB_OP_CREATE, - argv[idx_number_2]->arg); - nb_cli_enqueue_change(vty, "./rmap-policy-import", NB_OP_CREATE, - argv[idx_word]->arg); + instance = strtoul(argv[idx_number]->arg, NULL, 10); + metric = strtoul(argv[idx_number_2]->arg, NULL, 10); - return nb_cli_apply_changes(vty, base_xpath); + red = bgp_redist_add(bgp, AFI_IP, protocol, instance); + changed = bgp_redistribute_metric_set(bgp, red, AFI_IP, protocol, + metric); + changed |= + bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map); + return bgp_redistribute_set(bgp, AFI_IP, protocol, instance, changed); } ALIAS_HIDDEN( @@ -15591,31 +15468,32 @@ ALIAS_HIDDEN( "Route map reference\n" "Pointer to route-map entries\n") -DEFUN_YANG (no_bgp_redistribute_ipv4_ospf, - no_bgp_redistribute_ipv4_ospf_cmd, - "no redistribute (1-65535) [{metric (0-4294967295)|route-map WORD}]", - NO_STR - "Redistribute information from another routing protocol\n" - "Open Shortest Path First (OSPFv2)\n" - "Non-main Kernel Routing Table\n" - "Instance ID/Table ID\n" - "Metric for redistributed routes\n" - "Default metric\n" - "Route map reference\n" - "Pointer to route-map entries\n") +DEFUN (no_bgp_redistribute_ipv4_ospf, + no_bgp_redistribute_ipv4_ospf_cmd, + "no redistribute (1-65535) [{metric (0-4294967295)|route-map WORD}]", + NO_STR + "Redistribute information from another routing protocol\n" + "Open Shortest Path First (OSPFv2)\n" + "Non-main Kernel Routing Table\n" + "Instance ID/Table ID\n" + "Metric for redistributed routes\n" + "Default metric\n" + "Route map reference\n" + "Pointer to route-map entries\n") { - int idx_protocol = 2; + VTY_DECLVAR_CONTEXT(bgp, bgp); + int idx_ospf_table = 2; int idx_number = 3; - char base_xpath[XPATH_MAXLEN]; + unsigned short instance; + int protocol; - snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_AFI_SAFI_REDIST_XPATH, - yang_afi_safi_value2identity(AFI_IP, SAFI_UNICAST), - bgp_afi_safi_get_container_str(AFI_IP, SAFI_UNICAST), - argv[idx_protocol]->text, argv[idx_number]->arg); - - nb_cli_enqueue_change(vty, ".", NB_OP_DESTROY, NULL); + if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0) + protocol = ZEBRA_ROUTE_OSPF; + else + protocol = ZEBRA_ROUTE_TABLE; - return nb_cli_apply_changes(vty, base_xpath); + instance = strtoul(argv[idx_number]->arg, NULL, 10); + return bgp_redistribute_unset(bgp, AFI_IP, protocol, instance); } ALIAS_HIDDEN( @@ -15631,28 +15509,27 @@ ALIAS_HIDDEN( "Route map reference\n" "Pointer to route-map entries\n") -DEFUN_YANG (no_bgp_redistribute_ipv4, - no_bgp_redistribute_ipv4_cmd, - "no redistribute " FRR_IP_REDIST_STR_BGPD " [{metric (0-4294967295)|route-map WORD}]", - NO_STR - "Redistribute information from another routing protocol\n" - FRR_IP_REDIST_HELP_STR_BGPD - "Metric for redistributed routes\n" - "Default metric\n" - "Route map reference\n" - "Pointer to route-map entries\n") +DEFUN (no_bgp_redistribute_ipv4, + no_bgp_redistribute_ipv4_cmd, + "no redistribute " FRR_IP_REDIST_STR_BGPD " [{metric (0-4294967295)|route-map WORD}]", + NO_STR + "Redistribute information from another routing protocol\n" + FRR_IP_REDIST_HELP_STR_BGPD + "Metric for redistributed routes\n" + "Default metric\n" + "Route map reference\n" + "Pointer to route-map entries\n") { + VTY_DECLVAR_CONTEXT(bgp, bgp); int idx_protocol = 2; - char base_xpath[XPATH_MAXLEN]; - - snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_AFI_SAFI_REDIST_XPATH, - yang_afi_safi_value2identity(AFI_IP, SAFI_UNICAST), - bgp_afi_safi_get_container_str(AFI_IP, SAFI_UNICAST), - argv[idx_protocol]->text, "0"); - - nb_cli_enqueue_change(vty, ".", NB_OP_DESTROY, NULL); + int type; - return nb_cli_apply_changes(vty, base_xpath); + type = proto_redistnum(AFI_IP, argv[idx_protocol]->text); + if (type < 0) { + vty_out(vty, "%% Invalid route type\n"); + return CMD_WARNING_CONFIG_FAILED; + } + return bgp_redistribute_unset(bgp, AFI_IP, type, 0); } ALIAS_HIDDEN( @@ -15666,50 +15543,56 @@ ALIAS_HIDDEN( "Route map reference\n" "Pointer to route-map entries\n") -DEFUN_YANG (bgp_redistribute_ipv6, - bgp_redistribute_ipv6_cmd, - "redistribute " FRR_IP6_REDIST_STR_BGPD, - "Redistribute information from another routing protocol\n" - FRR_IP6_REDIST_HELP_STR_BGPD) +DEFUN (bgp_redistribute_ipv6, + bgp_redistribute_ipv6_cmd, + "redistribute " FRR_IP6_REDIST_STR_BGPD, + "Redistribute information from another routing protocol\n" + FRR_IP6_REDIST_HELP_STR_BGPD) { + VTY_DECLVAR_CONTEXT(bgp, bgp); int idx_protocol = 1; - char base_xpath[XPATH_MAXLEN]; - - snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_AFI_SAFI_REDIST_XPATH, - yang_afi_safi_value2identity(AFI_IP6, SAFI_UNICAST), - bgp_afi_safi_get_container_str(AFI_IP6, SAFI_UNICAST), - argv[idx_protocol]->text, "0"); + int type; - nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL); + type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text); + if (type < 0) { + vty_out(vty, "%% Invalid route type\n"); + return CMD_WARNING_CONFIG_FAILED; + } - return nb_cli_apply_changes(vty, base_xpath); + bgp_redist_add(bgp, AFI_IP6, type, 0); + return bgp_redistribute_set(bgp, AFI_IP6, type, 0, false); } -DEFUN_YANG (bgp_redistribute_ipv6_rmap, - bgp_redistribute_ipv6_rmap_cmd, - "redistribute " FRR_IP6_REDIST_STR_BGPD " route-map WORD", - "Redistribute information from another routing protocol\n" - FRR_IP6_REDIST_HELP_STR_BGPD - "Route map reference\n" - "Pointer to route-map entries\n") +DEFUN (bgp_redistribute_ipv6_rmap, + bgp_redistribute_ipv6_rmap_cmd, + "redistribute " FRR_IP6_REDIST_STR_BGPD " route-map WORD", + "Redistribute information from another routing protocol\n" + FRR_IP6_REDIST_HELP_STR_BGPD + "Route map reference\n" + "Pointer to route-map entries\n") { + VTY_DECLVAR_CONTEXT(bgp, bgp); int idx_protocol = 1; int idx_word = 3; - char base_xpath[XPATH_MAXLEN]; - - snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_AFI_SAFI_REDIST_XPATH, - yang_afi_safi_value2identity(AFI_IP6, SAFI_UNICAST), - bgp_afi_safi_get_container_str(AFI_IP6, SAFI_UNICAST), - argv[idx_protocol]->text, "0"); - - nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL); - nb_cli_enqueue_change(vty, "./rmap-policy-import", NB_OP_CREATE, - argv[idx_word]->arg); + int type; + struct bgp_redist *red; + bool changed; + struct route_map *route_map = + route_map_lookup_warn_noexist(vty, argv[idx_word]->arg); + + type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text); + if (type < 0) { + vty_out(vty, "%% Invalid route type\n"); + return CMD_WARNING_CONFIG_FAILED; + } - return nb_cli_apply_changes(vty, base_xpath); + red = bgp_redist_add(bgp, AFI_IP6, type, 0); + changed = + bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map); + return bgp_redistribute_set(bgp, AFI_IP6, type, 0, changed); } -DEFUN_YANG (bgp_redistribute_ipv6_metric, +DEFUN (bgp_redistribute_ipv6_metric, bgp_redistribute_ipv6_metric_cmd, "redistribute " FRR_IP6_REDIST_STR_BGPD " metric (0-4294967295)", "Redistribute information from another routing protocol\n" @@ -15717,123 +15600,120 @@ DEFUN_YANG (bgp_redistribute_ipv6_metric, "Metric for redistributed routes\n" "Default metric\n") { + VTY_DECLVAR_CONTEXT(bgp, bgp); int idx_protocol = 1; int idx_number = 3; - char base_xpath[XPATH_MAXLEN]; - - snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_AFI_SAFI_REDIST_XPATH, - yang_afi_safi_value2identity(AFI_IP6, SAFI_UNICAST), - bgp_afi_safi_get_container_str(AFI_IP6, SAFI_UNICAST), - argv[idx_protocol]->text, "0"); - - nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL); - nb_cli_enqueue_change(vty, "./metric", NB_OP_CREATE, - argv[idx_number]->arg); + int type; + uint32_t metric; + struct bgp_redist *red; + bool changed; + + type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text); + if (type < 0) { + vty_out(vty, "%% Invalid route type\n"); + return CMD_WARNING_CONFIG_FAILED; + } + metric = strtoul(argv[idx_number]->arg, NULL, 10); - return nb_cli_apply_changes(vty, base_xpath); + red = bgp_redist_add(bgp, AFI_IP6, type, 0); + changed = bgp_redistribute_metric_set(bgp, red, AFI_IP6, type, metric); + return bgp_redistribute_set(bgp, AFI_IP6, type, 0, changed); } -DEFUN_YANG( - bgp_redistribute_ipv6_rmap_metric, - bgp_redistribute_ipv6_rmap_metric_cmd, - "redistribute " FRR_IP6_REDIST_STR_BGPD - " route-map WORD metric (0-4294967295)", - "Redistribute information from another routing protocol\n" FRR_IP6_REDIST_HELP_STR_BGPD - "Route map reference\n" - "Pointer to route-map entries\n" - "Metric for redistributed routes\n" - "Default metric\n") +DEFUN (bgp_redistribute_ipv6_rmap_metric, + bgp_redistribute_ipv6_rmap_metric_cmd, + "redistribute " FRR_IP6_REDIST_STR_BGPD " route-map WORD metric (0-4294967295)", + "Redistribute information from another routing protocol\n" + FRR_IP6_REDIST_HELP_STR_BGPD + "Route map reference\n" + "Pointer to route-map entries\n" + "Metric for redistributed routes\n" + "Default metric\n") { + VTY_DECLVAR_CONTEXT(bgp, bgp); int idx_protocol = 1; int idx_word = 3; int idx_number = 5; - char base_xpath[XPATH_MAXLEN]; - - snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_AFI_SAFI_REDIST_XPATH, - yang_afi_safi_value2identity(AFI_IP6, SAFI_UNICAST), - bgp_afi_safi_get_container_str(AFI_IP6, SAFI_UNICAST), - argv[idx_protocol]->text, "0"); - - nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL); - nb_cli_enqueue_change(vty, "./rmap-policy-import", NB_OP_CREATE, - argv[idx_word]->arg); - nb_cli_enqueue_change(vty, "./metric", NB_OP_CREATE, - argv[idx_number]->arg); + int type; + uint32_t metric; + struct bgp_redist *red; + bool changed; + struct route_map *route_map = + route_map_lookup_warn_noexist(vty, argv[idx_word]->arg); + + type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text); + if (type < 0) { + vty_out(vty, "%% Invalid route type\n"); + return CMD_WARNING_CONFIG_FAILED; + } + metric = strtoul(argv[idx_number]->arg, NULL, 10); - return nb_cli_apply_changes(vty, base_xpath); + red = bgp_redist_add(bgp, AFI_IP6, type, 0); + changed = + bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map); + changed |= bgp_redistribute_metric_set(bgp, red, AFI_IP6, type, + metric); + return bgp_redistribute_set(bgp, AFI_IP6, type, 0, changed); } -DEFUN_YANG( - bgp_redistribute_ipv6_metric_rmap, - bgp_redistribute_ipv6_metric_rmap_cmd, - "redistribute " FRR_IP6_REDIST_STR_BGPD - " metric (0-4294967295) route-map WORD", - "Redistribute information from another routing protocol\n" FRR_IP6_REDIST_HELP_STR_BGPD - "Metric for redistributed routes\n" - "Default metric\n" - "Route map reference\n" - "Pointer to route-map entries\n") +DEFUN (bgp_redistribute_ipv6_metric_rmap, + bgp_redistribute_ipv6_metric_rmap_cmd, + "redistribute " FRR_IP6_REDIST_STR_BGPD " metric (0-4294967295) route-map WORD", + "Redistribute information from another routing protocol\n" + FRR_IP6_REDIST_HELP_STR_BGPD + "Metric for redistributed routes\n" + "Default metric\n" + "Route map reference\n" + "Pointer to route-map entries\n") { + VTY_DECLVAR_CONTEXT(bgp, bgp); int idx_protocol = 1; - int idx_word = 5; int idx_number = 3; - char base_xpath[XPATH_MAXLEN]; - - snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_AFI_SAFI_REDIST_XPATH, - yang_afi_safi_value2identity(AFI_IP6, SAFI_UNICAST), - bgp_afi_safi_get_container_str(AFI_IP6, SAFI_UNICAST), - argv[idx_protocol]->text, "0"); - - nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL); - nb_cli_enqueue_change(vty, "./metric", NB_OP_CREATE, - argv[idx_number]->arg); - nb_cli_enqueue_change(vty, "./rmap-policy-import", NB_OP_CREATE, - argv[idx_word]->arg); + int idx_word = 5; + int type; + uint32_t metric; + struct bgp_redist *red; + bool changed; + struct route_map *route_map = + route_map_lookup_warn_noexist(vty, argv[idx_word]->arg); + + type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text); + if (type < 0) { + vty_out(vty, "%% Invalid route type\n"); + return CMD_WARNING_CONFIG_FAILED; + } + metric = strtoul(argv[idx_number]->arg, NULL, 10); - return nb_cli_apply_changes(vty, base_xpath); + red = bgp_redist_add(bgp, AFI_IP6, type, 0); + changed = bgp_redistribute_metric_set(bgp, red, AFI_IP6, SAFI_UNICAST, + metric); + changed |= + bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map); + return bgp_redistribute_set(bgp, AFI_IP6, type, 0, changed); } -DEFUN_YANG( - no_bgp_redistribute_ipv6, - no_bgp_redistribute_ipv6_cmd, - "no redistribute " FRR_IP6_REDIST_STR_BGPD - " [{metric (0-4294967295)|route-map WORD}]", - NO_STR - "Redistribute information from another routing protocol\n" FRR_IP6_REDIST_HELP_STR_BGPD - "Metric for redistributed routes\n" - "Default metric\n" - "Route map reference\n" - "Pointer to route-map entries\n") +DEFUN (no_bgp_redistribute_ipv6, + no_bgp_redistribute_ipv6_cmd, + "no redistribute " FRR_IP6_REDIST_STR_BGPD " [{metric (0-4294967295)|route-map WORD}]", + NO_STR + "Redistribute information from another routing protocol\n" + FRR_IP6_REDIST_HELP_STR_BGPD + "Metric for redistributed routes\n" + "Default metric\n" + "Route map reference\n" + "Pointer to route-map entries\n") { + VTY_DECLVAR_CONTEXT(bgp, bgp); int idx_protocol = 2; - char base_xpath[XPATH_MAXLEN]; - - snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_AFI_SAFI_REDIST_XPATH, - yang_afi_safi_value2identity(AFI_IP6, SAFI_UNICAST), - bgp_afi_safi_get_container_str(AFI_IP6, SAFI_UNICAST), - argv[idx_protocol]->text, "0"); - - nb_cli_enqueue_change(vty, ".", NB_OP_DESTROY, NULL); + int type; - return nb_cli_apply_changes(vty, base_xpath); -} + type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text); + if (type < 0) { + vty_out(vty, "%% Invalid route type\n"); + return CMD_WARNING_CONFIG_FAILED; + } -void cli_show_bgp_global_afi_safi_ip_unicast_redistribution_list( - struct vty *vty, struct lyd_node *dnode, bool show_defaults) -{ - uint32_t instance = 0; - - vty_out(vty, " redistribute %s", - yang_dnode_get_string(dnode, "./route-type")); - if ((instance = yang_dnode_get_uint16(dnode, "./route-instance"))) - vty_out(vty, " %d", instance); - if (yang_dnode_exists(dnode, "./metric")) - vty_out(vty, " metric %u", - yang_dnode_get_uint32(dnode, "./metric")); - if (yang_dnode_exists(dnode, "./rmap-policy-import")) - vty_out(vty, " route-map %s", - yang_dnode_get_string(dnode, "./rmap-policy-import")); - vty_out(vty, "\n"); + return bgp_redistribute_unset(bgp, AFI_IP6, type, 0); } /* Neighbor update tcp-mss. */ diff --git a/bgpd/bgp_vty.h b/bgpd/bgp_vty.h index 0f079415f9..97050a5acd 100644 --- a/bgpd/bgp_vty.h +++ b/bgpd/bgp_vty.h @@ -192,13 +192,6 @@ extern int bgp_clear_star_soft_out(const char *name, char *errmsg, size_t errmsg_len); int bgp_wpkt_quanta_config_vty(struct bgp *bgp, uint32_t quanta, bool set); int bgp_rpkt_quanta_config_vty(struct bgp *bgp, uint32_t quanta, bool set); -extern int bgp_maxpaths_config_vty(struct bgp *bgp, afi_t afi, safi_t safi, - int peer_type, uint16_t maxpaths, - uint16_t options, int set, char *errmsg, - size_t errmsg_len); -extern const char *bgp_afi_safi_get_container_str(afi_t afi, safi_t safi); -extern bool vpn_policy_check_import(struct bgp *bgp, afi_t afi, safi_t safi, - bool v2vimport, char *errmsg, - size_t errmsg_len); + #endif /* _QUAGGA_BGP_VTY_H */ -- 2.39.5