summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--zebra/main.c1
-rw-r--r--zebra/subdir.am4
-rw-r--r--zebra/zebra_nb.c42
-rw-r--r--zebra/zebra_nb.h24
-rw-r--r--zebra/zebra_nb_config.c320
-rw-r--r--zebra/zebra_routemap.c74
-rw-r--r--zebra/zebra_routemap.h2
-rw-r--r--zebra/zebra_routemap_nb.c74
-rw-r--r--zebra/zebra_routemap_nb.h45
-rw-r--r--zebra/zebra_routemap_nb_config.c396
10 files changed, 570 insertions, 412 deletions
diff --git a/zebra/main.c b/zebra/main.c
index 09350f72c..3f75b222b 100644
--- a/zebra/main.c
+++ b/zebra/main.c
@@ -260,6 +260,7 @@ static const struct frr_yang_module_info *const zebra_yang_modules[] = {
&frr_zebra_info,
&frr_vrf_info,
&frr_routing_info,
+ &frr_zebra_route_map_info,
};
FRR_DAEMON_INFO(
diff --git a/zebra/subdir.am b/zebra/subdir.am
index b5c26d720..6a582f690 100644
--- a/zebra/subdir.am
+++ b/zebra/subdir.am
@@ -111,6 +111,8 @@ zebra_zebra_SOURCES = \
zebra/zebra_router.c \
zebra/zebra_rnh.c \
zebra/zebra_routemap.c \
+ zebra/zebra_routemap_nb.c \
+ zebra/zebra_routemap_nb_config.c \
zebra/zebra_srte.c \
zebra/zebra_vrf.c \
zebra/zebra_vty.c \
@@ -174,6 +176,7 @@ noinst_HEADERS += \
zebra/zebra_pw.h \
zebra/zebra_rnh.h \
zebra/zebra_routemap.h \
+ zebra/zebra_routemap_nb.h \
zebra/zebra_router.h \
zebra/zebra_srte.h \
zebra/zebra_vrf.h \
@@ -217,6 +220,7 @@ endif
nodist_zebra_zebra_SOURCES = \
yang/frr-zebra.yang.c \
+ yang/frr-zebra-route-map.yang.c \
# end
zebra_zebra_cumulus_mlag_la_SOURCES = zebra/zebra_mlag_private.c
diff --git a/zebra/zebra_nb.c b/zebra/zebra_nb.c
index bdeb84486..90d4ee7ce 100644
--- a/zebra/zebra_nb.c
+++ b/zebra/zebra_nb.c
@@ -644,48 +644,6 @@ const struct frr_yang_module_info frr_zebra_info = {
}
},
{
- .xpath = "/frr-route-map:lib/route-map/entry/match-condition/frr-zebra:ipv4-prefix-length",
- .cbs = {
- .modify = lib_route_map_entry_match_condition_ipv4_prefix_length_modify,
- .destroy = lib_route_map_entry_match_condition_ipv4_prefix_length_destroy,
- }
- },
- {
- .xpath = "/frr-route-map:lib/route-map/entry/match-condition/frr-zebra:ipv6-prefix-length",
- .cbs = {
- .modify = lib_route_map_entry_match_condition_ipv6_prefix_length_modify,
- .destroy = lib_route_map_entry_match_condition_ipv6_prefix_length_destroy,
- }
- },
- {
- .xpath = "/frr-route-map:lib/route-map/entry/match-condition/frr-zebra:source-protocol",
- .cbs = {
- .modify = lib_route_map_entry_match_condition_source_protocol_modify,
- .destroy = lib_route_map_entry_match_condition_source_protocol_destroy,
- }
- },
- {
- .xpath = "/frr-route-map:lib/route-map/entry/match-condition/frr-zebra:source-instance",
- .cbs = {
- .modify = lib_route_map_entry_match_condition_source_instance_modify,
- .destroy = lib_route_map_entry_match_condition_source_instance_destroy,
- }
- },
- {
- .xpath = "/frr-route-map:lib/route-map/entry/set-action/frr-zebra:source-v4",
- .cbs = {
- .modify = lib_route_map_entry_set_action_source_v4_modify,
- .destroy = lib_route_map_entry_set_action_source_v4_destroy,
- }
- },
- {
- .xpath = "/frr-route-map:lib/route-map/entry/set-action/frr-zebra:source-v6",
- .cbs = {
- .modify = lib_route_map_entry_set_action_source_v6_modify,
- .destroy = lib_route_map_entry_set_action_source_v6_destroy,
- }
- },
- {
.xpath = NULL,
},
}
diff --git a/zebra/zebra_nb.h b/zebra/zebra_nb.h
index 79632dc83..95907059a 100644
--- a/zebra/zebra_nb.h
+++ b/zebra/zebra_nb.h
@@ -109,30 +109,6 @@ int lib_interface_zebra_shutdown_modify(struct nb_cb_modify_args *args);
int lib_interface_zebra_shutdown_destroy(struct nb_cb_destroy_args *args);
int lib_interface_zebra_bandwidth_modify(struct nb_cb_modify_args *args);
int lib_interface_zebra_bandwidth_destroy(struct nb_cb_destroy_args *args);
-int lib_route_map_entry_match_condition_ipv4_prefix_length_modify(
- struct nb_cb_modify_args *args);
-int lib_route_map_entry_match_condition_ipv4_prefix_length_destroy(
- struct nb_cb_destroy_args *args);
-int lib_route_map_entry_match_condition_ipv6_prefix_length_modify(
- struct nb_cb_modify_args *args);
-int lib_route_map_entry_match_condition_ipv6_prefix_length_destroy(
- struct nb_cb_destroy_args *args);
-int lib_route_map_entry_match_condition_source_protocol_modify(
- struct nb_cb_modify_args *args);
-int lib_route_map_entry_match_condition_source_protocol_destroy(
- struct nb_cb_destroy_args *args);
-int lib_route_map_entry_match_condition_source_instance_modify(
- struct nb_cb_modify_args *args);
-int lib_route_map_entry_match_condition_source_instance_destroy(
- struct nb_cb_destroy_args *args);
-int lib_route_map_entry_set_action_source_v4_modify(
- struct nb_cb_modify_args *args);
-int lib_route_map_entry_set_action_source_v4_destroy(
- struct nb_cb_destroy_args *args);
-int lib_route_map_entry_set_action_source_v6_modify(
- struct nb_cb_modify_args *args);
-int lib_route_map_entry_set_action_source_v6_destroy(
- struct nb_cb_destroy_args *args);
struct yang_data *
lib_interface_zebra_state_up_count_get_elem(struct nb_cb_get_elem_args *args);
struct yang_data *
diff --git a/zebra/zebra_nb_config.c b/zebra/zebra_nb_config.c
index ba9f96b7d..e23a51516 100644
--- a/zebra/zebra_nb_config.c
+++ b/zebra/zebra_nb_config.c
@@ -1294,323 +1294,3 @@ int lib_vrf_zebra_prefix_only_modify(struct nb_cb_modify_args *args)
return NB_OK;
}
-
-/*
- * XPath:
- * /frr-route-map:lib/route-map/entry/match-condition/frr-zebra:ipv4-prefix-length
- */
-int lib_route_map_entry_match_condition_ipv4_prefix_length_modify(
- struct nb_cb_modify_args *args)
-{
- struct routemap_hook_context *rhc;
- const char *length;
- int condition, rv;
-
- if (args->event != NB_EV_APPLY)
- return NB_OK;
-
- /* Add configuration. */
- rhc = nb_running_get_entry(args->dnode, NULL, true);
- length = yang_dnode_get_string(args->dnode, NULL);
- condition =
- yang_dnode_get_enum(args->dnode, "../frr-route-map:condition");
-
- /* Set destroy information. */
- switch (condition) {
- case 100: /* ipv4-prefix-length */
- rhc->rhc_rule = "ip address prefix-len";
- break;
-
- case 102: /* ipv4-next-hop-prefix-length */
- rhc->rhc_rule = "ip next-hop prefix-len";
- break;
- }
- rhc->rhc_mhook = generic_match_delete;
- rhc->rhc_event = RMAP_EVENT_MATCH_DELETED;
-
- rv = generic_match_add(NULL, rhc->rhc_rmi, rhc->rhc_rule, length,
- RMAP_EVENT_MATCH_ADDED);
- if (rv != CMD_SUCCESS) {
- rhc->rhc_mhook = NULL;
- return NB_ERR_INCONSISTENCY;
- }
-
- return NB_OK;
-}
-
-int lib_route_map_entry_match_condition_ipv4_prefix_length_destroy(
- struct nb_cb_destroy_args *args)
-{
- return lib_route_map_entry_match_destroy(args);
-}
-
-/*
- * XPath:
- * /frr-route-map:lib/route-map/entry/match-condition/frr-zebra:ipv6-prefix-length
- */
-int lib_route_map_entry_match_condition_ipv6_prefix_length_modify(
- struct nb_cb_modify_args *args)
-{
- struct routemap_hook_context *rhc;
- const char *length;
- int rv;
-
- if (args->event != NB_EV_APPLY)
- return NB_OK;
-
- /* Add configuration. */
- rhc = nb_running_get_entry(args->dnode, NULL, true);
- length = yang_dnode_get_string(args->dnode, NULL);
-
- /* Set destroy information. */
- rhc->rhc_mhook = generic_match_delete;
- rhc->rhc_rule = "ipv6 address prefix-len";
- rhc->rhc_event = RMAP_EVENT_MATCH_DELETED;
-
- rv = generic_match_add(NULL, rhc->rhc_rmi, "ipv6 address prefix-len",
- length, RMAP_EVENT_MATCH_ADDED);
- if (rv != CMD_SUCCESS) {
- rhc->rhc_mhook = NULL;
- return NB_ERR_INCONSISTENCY;
- }
-
- return NB_OK;
-}
-
-int lib_route_map_entry_match_condition_ipv6_prefix_length_destroy(
- struct nb_cb_destroy_args *args)
-{
- return lib_route_map_entry_match_destroy(args);
-}
-
-/*
- * XPath:
- * /frr-route-map:lib/route-map/entry/match-condition/frr-zebra:source-protocol
- */
-int lib_route_map_entry_match_condition_source_protocol_modify(
- struct nb_cb_modify_args *args)
-{
- struct routemap_hook_context *rhc;
- const char *type;
- int rv;
-
- switch (args->event) {
- case NB_EV_VALIDATE:
- type = yang_dnode_get_string(args->dnode, NULL);
- if (proto_name2num(type) == -1) {
- snprintf(args->errmsg, args->errmsg_len,
- "invalid protocol: %s", type);
- return NB_ERR_VALIDATION;
- }
- return NB_OK;
- case NB_EV_PREPARE:
- case NB_EV_ABORT:
- return NB_OK;
- case NB_EV_APPLY:
- /* NOTHING */
- break;
- }
-
- /* Add configuration. */
- rhc = nb_running_get_entry(args->dnode, NULL, true);
- type = yang_dnode_get_string(args->dnode, NULL);
-
- /* Set destroy information. */
- rhc->rhc_mhook = generic_match_delete;
- rhc->rhc_rule = "source-protocol";
- rhc->rhc_event = RMAP_EVENT_MATCH_DELETED;
-
- rv = generic_match_add(NULL, rhc->rhc_rmi, "source-protocol", type,
- RMAP_EVENT_MATCH_ADDED);
- if (rv != CMD_SUCCESS) {
- rhc->rhc_mhook = NULL;
- return NB_ERR_INCONSISTENCY;
- }
-
- return NB_OK;
-}
-
-int lib_route_map_entry_match_condition_source_protocol_destroy(
- struct nb_cb_destroy_args *args)
-{
- return lib_route_map_entry_match_destroy(args);
-}
-
-/*
- * XPath:
- * /frr-route-map:lib/route-map/entry/match-condition/frr-zebra:source-instance
- */
-int lib_route_map_entry_match_condition_source_instance_modify(
- struct nb_cb_modify_args *args)
-{
- struct routemap_hook_context *rhc;
- const char *type;
- int rv;
-
- if (args->event != NB_EV_APPLY)
- return NB_OK;
-
- /* Add configuration. */
- rhc = nb_running_get_entry(args->dnode, NULL, true);
- type = yang_dnode_get_string(args->dnode, NULL);
-
- /* Set destroy information. */
- rhc->rhc_mhook = generic_match_delete;
- rhc->rhc_rule = "source-instance";
- rhc->rhc_event = RMAP_EVENT_MATCH_DELETED;
-
- rv = generic_match_add(NULL, rhc->rhc_rmi, "source-instance", type,
- RMAP_EVENT_MATCH_ADDED);
- if (rv != CMD_SUCCESS) {
- rhc->rhc_mhook = NULL;
- return NB_ERR_INCONSISTENCY;
- }
-
- return NB_OK;
-}
-
-int lib_route_map_entry_match_condition_source_instance_destroy(
- struct nb_cb_destroy_args *args)
-{
- return lib_route_map_entry_match_destroy(args);
-}
-
-/*
- * XPath: /frr-route-map:lib/route-map/entry/set-action/frr-zebra:source-v4
- */
-int lib_route_map_entry_set_action_source_v4_modify(
- struct nb_cb_modify_args *args)
-{
- struct routemap_hook_context *rhc;
- struct interface *pif = NULL;
- const char *source;
- struct vrf *vrf;
- struct prefix p;
- int rv;
-
- switch (args->event) {
- case NB_EV_VALIDATE:
- memset(&p, 0, sizeof(p));
- yang_dnode_get_ipv4p(&p, args->dnode, NULL);
- if (zebra_check_addr(&p) == 0) {
- snprintf(args->errmsg, args->errmsg_len,
- "invalid IPv4 address: %s",
- yang_dnode_get_string(args->dnode, NULL));
- return NB_ERR_VALIDATION;
- }
-
- RB_FOREACH (vrf, vrf_id_head, &vrfs_by_id) {
- pif = if_lookup_exact_address(&p.u.prefix4, AF_INET,
- vrf->vrf_id);
- if (pif != NULL)
- break;
- }
- /*
- * On startup the local address *may* not have come up
- * yet. We need to allow startup configuration of
- * set src or we are fudged. Log it for future fun
- */
- if (pif == NULL)
- zlog_warn("set src %pI4 is not a local address",
- &p.u.prefix4);
- return NB_OK;
- case NB_EV_PREPARE:
- case NB_EV_ABORT:
- return NB_OK;
- case NB_EV_APPLY:
- /* NOTHING */
- break;
- }
-
- /* Add configuration. */
- rhc = nb_running_get_entry(args->dnode, NULL, true);
- source = yang_dnode_get_string(args->dnode, NULL);
-
- /* Set destroy information. */
- rhc->rhc_shook = generic_set_delete;
- rhc->rhc_rule = "src";
-
- rv = generic_set_add(NULL, rhc->rhc_rmi, "src", source);
- if (rv != CMD_SUCCESS) {
- rhc->rhc_shook = NULL;
- return NB_ERR_INCONSISTENCY;
- }
-
- return NB_OK;
-}
-
-int lib_route_map_entry_set_action_source_v4_destroy(
- struct nb_cb_destroy_args *args)
-{
- return lib_route_map_entry_set_destroy(args);
-}
-
-/*
- * XPath: /frr-route-map:lib/route-map/entry/set-action/frr-zebra:source-v6
- */
-int lib_route_map_entry_set_action_source_v6_modify(
- struct nb_cb_modify_args *args)
-{
- struct routemap_hook_context *rhc;
- struct interface *pif = NULL;
- const char *source;
- struct vrf *vrf;
- struct prefix p;
- int rv;
-
- switch (args->event) {
- case NB_EV_VALIDATE:
- memset(&p, 0, sizeof(p));
- yang_dnode_get_ipv6p(&p, args->dnode, NULL);
- if (zebra_check_addr(&p) == 0) {
- snprintf(args->errmsg, args->errmsg_len,
- "invalid IPv6 address: %s",
- yang_dnode_get_string(args->dnode, NULL));
- return NB_ERR_VALIDATION;
- }
-
- RB_FOREACH (vrf, vrf_id_head, &vrfs_by_id) {
- pif = if_lookup_exact_address(&p.u.prefix6, AF_INET6,
- vrf->vrf_id);
- if (pif != NULL)
- break;
- }
- /*
- * On startup the local address *may* not have come up
- * yet. We need to allow startup configuration of
- * set src or we are fudged. Log it for future fun
- */
- if (pif == NULL)
- zlog_warn("set src %pI6 is not a local address",
- &p.u.prefix6);
- return NB_OK;
- case NB_EV_PREPARE:
- case NB_EV_ABORT:
- return NB_OK;
- case NB_EV_APPLY:
- /* NOTHING */
- break;
- }
-
- /* Add configuration. */
- rhc = nb_running_get_entry(args->dnode, NULL, true);
- source = yang_dnode_get_string(args->dnode, NULL);
-
- /* Set destroy information. */
- rhc->rhc_shook = generic_set_delete;
- rhc->rhc_rule = "src";
-
- rv = generic_set_add(NULL, rhc->rhc_rmi, "src", source);
- if (rv != CMD_SUCCESS) {
- rhc->rhc_shook = NULL;
- return NB_ERR_INCONSISTENCY;
- }
-
- return NB_OK;
-}
-
-int lib_route_map_entry_set_action_source_v6_destroy(
- struct nb_cb_destroy_args *args)
-{
- return lib_route_map_entry_set_destroy(args);
-}
diff --git a/zebra/zebra_routemap.c b/zebra/zebra_routemap.c
index c9660c730..6a42c682a 100644
--- a/zebra/zebra_routemap.c
+++ b/zebra/zebra_routemap.c
@@ -357,12 +357,15 @@ DEFPY_YANG(
"Match prefix length of IP address\n"
"Prefix length\n")
{
- const char *xpath = "./match-condition[condition='ipv4-prefix-length']";
+ const char *xpath =
+ "./match-condition[condition='frr-zebra-route-map:ipv4-prefix-length']";
char xpath_value[XPATH_MAXLEN];
nb_cli_enqueue_change(vty, xpath, NB_OP_CREATE, NULL);
- snprintf(xpath_value, sizeof(xpath_value),
- "%s/frr-zebra:ipv4-prefix-length", xpath);
+ snprintf(
+ xpath_value, sizeof(xpath_value),
+ "%s/rmap-match-condition/frr-zebra-route-map:ipv4-prefix-length",
+ xpath);
nb_cli_enqueue_change(vty, xpath_value, NB_OP_MODIFY, length_str);
return nb_cli_apply_changes(vty, NULL);
@@ -378,7 +381,8 @@ DEFPY_YANG(
"Match prefix length of IP address\n"
"Prefix length\n")
{
- const char *xpath = "./match-condition[condition='ipv4-prefix-length']";
+ const char *xpath =
+ "./match-condition[condition='frr-zebra-route-map:ipv4-prefix-length']";
nb_cli_enqueue_change(vty, xpath, NB_OP_DESTROY, NULL);
@@ -394,12 +398,15 @@ DEFPY_YANG(
"Match prefix length of IPv6 address\n"
"Prefix length\n")
{
- const char *xpath = "./match-condition[condition='ipv6-prefix-length']";
+ const char *xpath =
+ "./match-condition[condition='frr-zebra-route-map:ipv6-prefix-length']";
char xpath_value[XPATH_MAXLEN];
nb_cli_enqueue_change(vty, xpath, NB_OP_CREATE, NULL);
- snprintf(xpath_value, sizeof(xpath_value),
- "%s/frr-zebra:ipv6-prefix-length", xpath);
+ snprintf(
+ xpath_value, sizeof(xpath_value),
+ "%s/rmap-match-condition/frr-zebra-route-map:ipv6-prefix-length",
+ xpath);
nb_cli_enqueue_change(vty, xpath_value, NB_OP_MODIFY, length_str);
return nb_cli_apply_changes(vty, NULL);
@@ -415,7 +422,8 @@ DEFPY_YANG(
"Match prefix length of IPv6 address\n"
"Prefix length\n")
{
- const char *xpath = "./match-condition[condition='ipv6-prefix-length']";
+ const char *xpath =
+ "./match-condition[condition='frr-zebra-route-map:ipv6-prefix-length']";
nb_cli_enqueue_change(vty, xpath, NB_OP_DESTROY, NULL);
@@ -432,12 +440,14 @@ DEFPY_YANG(
"Prefix length\n")
{
const char *xpath =
- "./match-condition[condition='ipv4-next-hop-prefix-length']";
+ "./match-condition[condition='frr-zebra-route-map:ipv4-next-hop-prefix-length']";
char xpath_value[XPATH_MAXLEN];
nb_cli_enqueue_change(vty, xpath, NB_OP_CREATE, NULL);
- snprintf(xpath_value, sizeof(xpath_value),
- "%s/frr-zebra:ipv4-prefix-length", xpath);
+ snprintf(
+ xpath_value, sizeof(xpath_value),
+ "%s/rmap-match-condition/frr-zebra-route-map:ipv4-prefix-length",
+ xpath);
nb_cli_enqueue_change(vty, xpath_value, NB_OP_MODIFY, length_str);
return nb_cli_apply_changes(vty, NULL);
@@ -454,7 +464,7 @@ DEFPY_YANG(
"Prefix length\n")
{
const char *xpath =
- "./match-condition[condition='ipv4-next-hop-prefix-length']";
+ "./match-condition[condition='frr-zebra-route-map:ipv4-next-hop-prefix-length']";
nb_cli_enqueue_change(vty, xpath, NB_OP_DESTROY, NULL);
@@ -468,12 +478,14 @@ DEFPY_YANG(
"Match protocol via which the route was learnt\n"
FRR_REDIST_HELP_STR_ZEBRA)
{
- const char *xpath = "./match-condition[condition='source-protocol']";
+ const char *xpath =
+ "./match-condition[condition='frr-zebra-route-map:source-protocol']";
char xpath_value[XPATH_MAXLEN];
nb_cli_enqueue_change(vty, xpath, NB_OP_CREATE, NULL);
snprintf(xpath_value, sizeof(xpath_value),
- "%s/frr-zebra:source-protocol", xpath);
+ "%s/rmap-match-condition/frr-zebra-route-map:source-protocol",
+ xpath);
nb_cli_enqueue_change(vty, xpath_value, NB_OP_MODIFY, proto);
return nb_cli_apply_changes(vty, NULL);
@@ -487,7 +499,8 @@ DEFPY_YANG(
"Match protocol via which the route was learnt\n"
FRR_REDIST_HELP_STR_ZEBRA)
{
- const char *xpath = "./match-condition[condition='source-protocol']";
+ const char *xpath =
+ "./match-condition[condition='frr-zebra-route-map:source-protocol']";
nb_cli_enqueue_change(vty, xpath, NB_OP_DESTROY, NULL);
@@ -501,12 +514,14 @@ DEFPY_YANG(
"Match the protocol's instance number\n"
"The instance number\n")
{
- const char *xpath = "./match-condition[condition='source-instance']";
+ const char *xpath =
+ "./match-condition[condition='frr-zebra-route-map:source-instance']";
char xpath_value[XPATH_MAXLEN];
nb_cli_enqueue_change(vty, xpath, NB_OP_CREATE, NULL);
snprintf(xpath_value, sizeof(xpath_value),
- "%s/frr-zebra:source-instance", xpath);
+ "%s/rmap-match-condition/frr-zebra-route-map:source-instance",
+ xpath);
nb_cli_enqueue_change(vty, xpath_value, NB_OP_MODIFY, instance_str);
return nb_cli_apply_changes(vty, NULL);
@@ -519,7 +534,8 @@ DEFPY_YANG(
"Match the protocol's instance number\n"
"The instance number\n")
{
- const char *xpath = "./match-condition[condition='source-instance']";
+ const char *xpath =
+ "./match-condition[condition='frr-zebra-route-map:source-instance']";
nb_cli_enqueue_change(vty, xpath, NB_OP_DESTROY, NULL);
@@ -536,18 +552,23 @@ DEFPY_YANG(
"IPv4 src address\n"
"IPv6 src address\n")
{
- const char *xpath = "./set-action[action='source']";
+ const char *xpath =
+ "./set-action[action='frr-zebra-route-map:src-address']";
char xpath_value[XPATH_MAXLEN];
nb_cli_enqueue_change(vty, xpath, NB_OP_CREATE, NULL);
if (addrv4_str) {
- snprintf(xpath_value, sizeof(xpath_value),
- "%s/frr-zebra:source-v4", xpath);
+ snprintf(
+ xpath_value, sizeof(xpath_value),
+ "%s/rmap-set-action/frr-zebra-route-map:ipv4-src-address",
+ xpath);
nb_cli_enqueue_change(vty, xpath_value, NB_OP_MODIFY,
addrv4_str);
} else {
- snprintf(xpath_value, sizeof(xpath_value),
- "%s/frr-zebra:source-v6", xpath);
+ snprintf(
+ xpath_value, sizeof(xpath_value),
+ "%s/rmap-set-action/frr-zebra-route-map:ipv6-src-address",
+ xpath);
nb_cli_enqueue_change(vty, xpath_value, NB_OP_MODIFY,
addrv6_str);
}
@@ -564,14 +585,15 @@ DEFPY_YANG(
"IPv4 address\n"
"IPv6 address\n")
{
- const char *xpath = "./set-action[action='source']";
+ const char *xpath =
+ "./set-action[action='frr-zebra-route-map:src-address']";
nb_cli_enqueue_change(vty, xpath, NB_OP_DESTROY, NULL);
return nb_cli_apply_changes(vty, NULL);
}
-DEFUN (zebra_route_map_timer,
+DEFUN_YANG (zebra_route_map_timer,
zebra_route_map_timer_cmd,
"zebra route-map delay-timer (0-600)",
ZEBRA_STR
@@ -588,7 +610,7 @@ DEFUN (zebra_route_map_timer,
return (CMD_SUCCESS);
}
-DEFUN (no_zebra_route_map_timer,
+DEFUN_YANG (no_zebra_route_map_timer,
no_zebra_route_map_timer_cmd,
"no zebra route-map delay-timer [(0-600)]",
NO_STR
diff --git a/zebra/zebra_routemap.h b/zebra/zebra_routemap.h
index c016d9587..3f58e14e1 100644
--- a/zebra/zebra_routemap.h
+++ b/zebra/zebra_routemap.h
@@ -55,4 +55,6 @@ zebra_nht_route_map_check(afi_t afi, int client_proto, const struct prefix *p,
#endif
extern void zebra_routemap_finish(void);
+
+extern const struct frr_yang_module_info frr_zebra_route_map_info;
#endif
diff --git a/zebra/zebra_routemap_nb.c b/zebra/zebra_routemap_nb.c
new file mode 100644
index 000000000..c82c34dd5
--- /dev/null
+++ b/zebra/zebra_routemap_nb.c
@@ -0,0 +1,74 @@
+/*
+ * Copyright (C) 2020 Vmware
+ * Sarita Patra
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the Free
+ * Software Foundation; either version 2 of the License, or (at your option)
+ * any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
+ * more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; see the file COPYING; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#include "northbound.h"
+#include "libfrr.h"
+#include "zebra_routemap_nb.h"
+
+/* clang-format off */
+const struct frr_yang_module_info frr_zebra_route_map_info = {
+ .name = "frr-zebra-route-map",
+ .nodes = {
+ {
+ .xpath = "/frr-route-map:lib/route-map/entry/match-condition/rmap-match-condition/frr-zebra-route-map:ipv4-prefix-length",
+ .cbs = {
+ .modify = lib_route_map_entry_match_condition_rmap_match_condition_ipv4_prefix_length_modify,
+ .destroy = lib_route_map_entry_match_condition_rmap_match_condition_ipv4_prefix_length_destroy,
+ }
+ },
+ {
+ .xpath = "/frr-route-map:lib/route-map/entry/match-condition/rmap-match-condition/frr-zebra-route-map:ipv6-prefix-length",
+ .cbs = {
+ .modify = lib_route_map_entry_match_condition_rmap_match_condition_ipv6_prefix_length_modify,
+ .destroy = lib_route_map_entry_match_condition_rmap_match_condition_ipv6_prefix_length_destroy,
+ }
+ },
+ {
+ .xpath = "/frr-route-map:lib/route-map/entry/match-condition/rmap-match-condition/frr-zebra-route-map:source-instance",
+ .cbs = {
+ .modify = lib_route_map_entry_match_condition_rmap_match_condition_source_instance_modify,
+ .destroy = lib_route_map_entry_match_condition_rmap_match_condition_source_instance_destroy,
+ }
+ },
+ {
+ .xpath = "/frr-route-map:lib/route-map/entry/match-condition/rmap-match-condition/frr-zebra-route-map:source-protocol",
+ .cbs = {
+ .modify = lib_route_map_entry_match_condition_rmap_match_condition_source_protocol_modify,
+ .destroy = lib_route_map_entry_match_condition_rmap_match_condition_source_protocol_destroy,
+ }
+ },
+ {
+ .xpath = "/frr-route-map:lib/route-map/entry/set-action/rmap-set-action/frr-zebra-route-map:ipv4-src-address",
+ .cbs = {
+ .modify = lib_route_map_entry_set_action_rmap_set_action_ipv4_src_address_modify,
+ .destroy = lib_route_map_entry_set_action_rmap_set_action_ipv4_src_address_destroy,
+ }
+ },
+ {
+ .xpath = "/frr-route-map:lib/route-map/entry/set-action/rmap-set-action/frr-zebra-route-map:ipv6-src-address",
+ .cbs = {
+ .modify = lib_route_map_entry_set_action_rmap_set_action_ipv6_src_address_modify,
+ .destroy = lib_route_map_entry_set_action_rmap_set_action_ipv6_src_address_destroy,
+ }
+ },
+ {
+ .xpath = NULL,
+ },
+ }
+};
diff --git a/zebra/zebra_routemap_nb.h b/zebra/zebra_routemap_nb.h
new file mode 100644
index 000000000..a43f2b2ae
--- /dev/null
+++ b/zebra/zebra_routemap_nb.h
@@ -0,0 +1,45 @@
+/*
+ * Copyright (C) 2020 Vmware
+ * Sarita Patra
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the Free
+ * Software Foundation; either version 2 of the License, or (at your option)
+ * any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
+ * more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; see the file COPYING; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#ifndef _FRR_ZEBRA_ROUTEMAP_NB_H_
+#define _FRR_ZEBRA_ROUTEMAP_NB_H_
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/* prototypes */
+int lib_route_map_entry_match_condition_rmap_match_condition_ipv4_prefix_length_modify(struct nb_cb_modify_args *args);
+int lib_route_map_entry_match_condition_rmap_match_condition_ipv4_prefix_length_destroy(struct nb_cb_destroy_args *args);
+int lib_route_map_entry_match_condition_rmap_match_condition_ipv6_prefix_length_modify(struct nb_cb_modify_args *args);
+int lib_route_map_entry_match_condition_rmap_match_condition_ipv6_prefix_length_destroy(struct nb_cb_destroy_args *args);
+int lib_route_map_entry_match_condition_rmap_match_condition_source_instance_modify(struct nb_cb_modify_args *args);
+int lib_route_map_entry_match_condition_rmap_match_condition_source_instance_destroy(struct nb_cb_destroy_args *args);
+int lib_route_map_entry_match_condition_rmap_match_condition_source_protocol_modify(struct nb_cb_modify_args *args);
+int lib_route_map_entry_match_condition_rmap_match_condition_source_protocol_destroy(struct nb_cb_destroy_args *args);
+int lib_route_map_entry_set_action_rmap_set_action_ipv4_src_address_modify(struct nb_cb_modify_args *args);
+int lib_route_map_entry_set_action_rmap_set_action_ipv4_src_address_destroy(struct nb_cb_destroy_args *args);
+int lib_route_map_entry_set_action_rmap_set_action_ipv6_src_address_modify(struct nb_cb_modify_args *args);
+int lib_route_map_entry_set_action_rmap_set_action_ipv6_src_address_destroy(struct nb_cb_destroy_args *args);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/zebra/zebra_routemap_nb_config.c b/zebra/zebra_routemap_nb_config.c
new file mode 100644
index 000000000..8f5660610
--- /dev/null
+++ b/zebra/zebra_routemap_nb_config.c
@@ -0,0 +1,396 @@
+#include <zebra.h>
+
+#include "lib/command.h"
+#include "lib/log.h"
+#include "lib/northbound.h"
+#include "lib/routemap.h"
+#include "zebra/rib.h"
+#include "zebra/zebra_routemap_nb.h"
+
+/*
+ * XPath: /frr-route-map:lib/route-map/entry/match-condition/rmap-match-condition/frr-zebra-route-map:ipv4-prefix-length
+ */
+int
+lib_route_map_entry_match_condition_rmap_match_condition_ipv4_prefix_length_modify(
+ struct nb_cb_modify_args *args)
+{
+ struct routemap_hook_context *rhc;
+ const char *length;
+ int rv;
+ const char *condition;
+
+ switch (args->event) {
+ case NB_EV_VALIDATE:
+ case NB_EV_PREPARE:
+ case NB_EV_ABORT:
+ return NB_OK;
+ case NB_EV_APPLY:
+ /* Add configuration. */
+ rhc = nb_running_get_entry(args->dnode, NULL, true);
+ length = yang_dnode_get_string(args->dnode, NULL);
+ condition = yang_dnode_get_string(args->dnode,
+ "../../frr-route-map:condition");
+
+ if (IS_MATCH_IPv4_PREFIX_LEN(condition))
+ rhc->rhc_rule = "ip address prefix-len";
+ else if (IS_MATCH_IPv4_NH_PREFIX_LEN(condition))
+ rhc->rhc_rule = "ip next-hop prefix-len";
+
+ rhc->rhc_mhook = generic_match_delete;
+ rhc->rhc_event = RMAP_EVENT_MATCH_DELETED;
+
+ rv = generic_match_add(rhc->rhc_rmi, rhc->rhc_rule,
+ length, RMAP_EVENT_MATCH_ADDED,
+ args->errmsg, args->errmsg_len);
+ if (rv != CMD_SUCCESS) {
+ rhc->rhc_mhook = NULL;
+ return NB_ERR_INCONSISTENCY;
+ }
+ }
+
+ return NB_OK;
+}
+
+int
+lib_route_map_entry_match_condition_rmap_match_condition_ipv4_prefix_length_destroy(
+ struct nb_cb_destroy_args *args)
+{
+ switch (args->event) {
+ case NB_EV_VALIDATE:
+ case NB_EV_PREPARE:
+ case NB_EV_ABORT:
+ break;
+ case NB_EV_APPLY:
+ return lib_route_map_entry_match_destroy(args);
+ }
+
+ return NB_OK;
+}
+
+/*
+ * XPath: /frr-route-map:lib/route-map/entry/match-condition/rmap-match-condition/frr-zebra-route-map:ipv6-prefix-length
+ */
+int
+lib_route_map_entry_match_condition_rmap_match_condition_ipv6_prefix_length_modify(
+ struct nb_cb_modify_args *args)
+{
+ struct routemap_hook_context *rhc;
+ const char *length;
+ int rv;
+
+ switch (args->event) {
+ case NB_EV_VALIDATE:
+ case NB_EV_PREPARE:
+ case NB_EV_ABORT:
+ return NB_OK;
+ case NB_EV_APPLY:
+ /* Add configuration. */
+ rhc = nb_running_get_entry(args->dnode, NULL, true);
+ length = yang_dnode_get_string(args->dnode, NULL);
+
+ /* Set destroy information. */
+ rhc->rhc_mhook = generic_match_delete;
+ rhc->rhc_rule = "ipv6 address prefix-len";
+ rhc->rhc_event = RMAP_EVENT_MATCH_DELETED;
+
+ rv = generic_match_add(rhc->rhc_rmi, "ipv6 address prefix-len",
+ length, RMAP_EVENT_MATCH_ADDED,
+ args->errmsg, args->errmsg_len);
+ if (rv != CMD_SUCCESS) {
+ rhc->rhc_mhook = NULL;
+ return NB_ERR_INCONSISTENCY;
+ }
+ }
+
+ return NB_OK;
+}
+
+int
+lib_route_map_entry_match_condition_rmap_match_condition_ipv6_prefix_length_destroy(
+ struct nb_cb_destroy_args *args)
+{
+ switch (args->event) {
+ case NB_EV_VALIDATE:
+ case NB_EV_PREPARE:
+ case NB_EV_ABORT:
+ break;
+ case NB_EV_APPLY:
+ return lib_route_map_entry_match_destroy(args);
+ }
+
+ return NB_OK;
+
+}
+
+/*
+ * XPath: /frr-route-map:lib/route-map/entry/match-condition/rmap-match-condition/frr-zebra-route-map:source-instance
+ */
+int
+lib_route_map_entry_match_condition_rmap_match_condition_source_instance_modify(
+ struct nb_cb_modify_args *args)
+{
+ struct routemap_hook_context *rhc;
+ const char *type;
+ int rv;
+
+ switch (args->event) {
+ case NB_EV_VALIDATE:
+ case NB_EV_PREPARE:
+ case NB_EV_ABORT:
+ break;
+ case NB_EV_APPLY:
+ /* Add configuration. */
+ rhc = nb_running_get_entry(args->dnode, NULL, true);
+ type = yang_dnode_get_string(args->dnode, NULL);
+
+ /* Set destroy information. */
+ rhc->rhc_mhook = generic_match_delete;
+ rhc->rhc_rule = "source-instance";
+ rhc->rhc_event = RMAP_EVENT_MATCH_DELETED;
+
+ rv = generic_match_add(rhc->rhc_rmi, "source-instance",
+ type, RMAP_EVENT_MATCH_ADDED,
+ args->errmsg, args->errmsg_len);
+ if (rv != CMD_SUCCESS) {
+ rhc->rhc_mhook = NULL;
+ return NB_ERR_INCONSISTENCY;
+ }
+ }
+
+ return NB_OK;
+}
+
+int
+lib_route_map_entry_match_condition_rmap_match_condition_source_instance_destroy(
+ struct nb_cb_destroy_args *args)
+{
+ switch (args->event) {
+ case NB_EV_VALIDATE:
+ case NB_EV_PREPARE:
+ case NB_EV_ABORT:
+ break;
+ case NB_EV_APPLY:
+ return lib_route_map_entry_match_destroy(args);
+ }
+
+ return NB_OK;
+}
+
+/*
+ * XPath: /frr-route-map:lib/route-map/entry/match-condition/rmap-match-condition/frr-zebra-route-map:source-protocol
+ */
+int
+lib_route_map_entry_match_condition_rmap_match_condition_source_protocol_modify(
+ struct nb_cb_modify_args *args)
+{
+ struct routemap_hook_context *rhc;
+ const char *type;
+ int rv;
+
+ switch (args->event) {
+ case NB_EV_VALIDATE:
+ type = yang_dnode_get_string(args->dnode, NULL);
+ if (proto_name2num(type) == -1) {
+ zlog_warn("%s: invalid protocol: %s", __func__, type);
+ return NB_ERR_VALIDATION;
+ }
+ return NB_OK;
+ case NB_EV_PREPARE:
+ case NB_EV_ABORT:
+ return NB_OK;
+ case NB_EV_APPLY:
+ /* NOTHING */
+ break;
+ }
+
+ /* Add configuration. */
+ rhc = nb_running_get_entry(args->dnode, NULL, true);
+ type = yang_dnode_get_string(args->dnode, NULL);
+
+ /* Set destroy information. */
+ rhc->rhc_mhook = generic_match_delete;
+ rhc->rhc_rule = "source-protocol";
+ rhc->rhc_event = RMAP_EVENT_MATCH_DELETED;
+
+ rv = generic_match_add(rhc->rhc_rmi, "source-protocol", type,
+ RMAP_EVENT_MATCH_ADDED,
+ args->errmsg, args->errmsg_len);
+ if (rv != CMD_SUCCESS) {
+ rhc->rhc_mhook = NULL;
+ return NB_ERR_INCONSISTENCY;
+ }
+
+ return NB_OK;
+}
+
+int
+lib_route_map_entry_match_condition_rmap_match_condition_source_protocol_destroy(
+ struct nb_cb_destroy_args *args)
+{
+ switch (args->event) {
+ case NB_EV_VALIDATE:
+ case NB_EV_PREPARE:
+ case NB_EV_ABORT:
+ break;
+ case NB_EV_APPLY:
+ return lib_route_map_entry_match_destroy(args);
+ }
+
+ return NB_OK;
+}
+
+/*
+ * XPath: /frr-route-map:lib/route-map/entry/set-action/rmap-set-action/frr-zebra-route-map:ipv4-src-address
+ */
+int
+lib_route_map_entry_set_action_rmap_set_action_ipv4_src_address_modify(
+ struct nb_cb_modify_args *args)
+{
+ struct routemap_hook_context *rhc;
+ struct interface *pif = NULL;
+ const char *source;
+ struct vrf *vrf;
+ struct prefix p;
+ int rv;
+
+ switch (args->event) {
+ case NB_EV_VALIDATE:
+ memset(&p, 0, sizeof(p));
+ yang_dnode_get_ipv4p(&p, args->dnode, NULL);
+ if (zebra_check_addr(&p) == 0) {
+ zlog_warn("%s: invalid IPv4 address: %s", __func__,
+ yang_dnode_get_string(args->dnode, NULL));
+ return NB_ERR_VALIDATION;
+ }
+
+ RB_FOREACH(vrf, vrf_id_head, &vrfs_by_id) {
+ pif = if_lookup_exact_address(&p.u.prefix4, AF_INET,
+ vrf->vrf_id);
+ if (pif != NULL)
+ break;
+ }
+ if (pif == NULL) {
+ zlog_warn("%s: is not a local address: %s", __func__,
+ yang_dnode_get_string(args->dnode, NULL));
+ return NB_ERR_VALIDATION;
+ }
+ return NB_OK;
+ case NB_EV_PREPARE:
+ case NB_EV_ABORT:
+ return NB_OK;
+ case NB_EV_APPLY:
+ /* NOTHING */
+ break;
+ }
+
+ /* Add configuration. */
+ rhc = nb_running_get_entry(args->dnode, NULL, true);
+ source = yang_dnode_get_string(args->dnode, NULL);
+
+ /* Set destroy information. */
+ rhc->rhc_shook = generic_set_delete;
+ rhc->rhc_rule = "src";
+
+ rv = generic_set_add(rhc->rhc_rmi, "src", source,
+ args->errmsg, args->errmsg_len);
+ if (rv != CMD_SUCCESS) {
+ rhc->rhc_shook = NULL;
+ return NB_ERR_INCONSISTENCY;
+ }
+
+ return NB_OK;
+}
+
+int
+lib_route_map_entry_set_action_rmap_set_action_ipv4_src_address_destroy(
+ struct nb_cb_destroy_args *args)
+{
+ switch (args->event) {
+ case NB_EV_VALIDATE:
+ case NB_EV_PREPARE:
+ case NB_EV_ABORT:
+ break;
+ case NB_EV_APPLY:
+ return lib_route_map_entry_set_destroy(args);
+ }
+
+ return NB_OK;
+}
+
+/*
+ * XPath: /frr-route-map:lib/route-map/entry/set-action/rmap-set-action/frr-zebra-route-map:ipv6-src-address
+ */
+int
+lib_route_map_entry_set_action_rmap_set_action_ipv6_src_address_modify(
+ struct nb_cb_modify_args *args)
+{
+ struct routemap_hook_context *rhc;
+ struct interface *pif = NULL;
+ const char *source;
+ struct vrf *vrf;
+ struct prefix p;
+ int rv;
+
+ switch (args->event) {
+ case NB_EV_VALIDATE:
+ memset(&p, 0, sizeof(p));
+ yang_dnode_get_ipv6p(&p, args->dnode, NULL);
+ if (zebra_check_addr(&p) == 0) {
+ zlog_warn("%s: invalid IPv6 address: %s", __func__,
+ yang_dnode_get_string(args->dnode, NULL));
+ return NB_ERR_VALIDATION;
+ }
+
+ RB_FOREACH(vrf, vrf_id_head, &vrfs_by_id) {
+ pif = if_lookup_exact_address(&p.u.prefix6, AF_INET6,
+ vrf->vrf_id);
+ if (pif != NULL)
+ break;
+ }
+ if (pif == NULL) {
+ zlog_warn("%s: is not a local address: %s", __func__,
+ yang_dnode_get_string(args->dnode, NULL));
+ return NB_ERR_VALIDATION;
+ }
+ return NB_OK;
+ case NB_EV_PREPARE:
+ case NB_EV_ABORT:
+ return NB_OK;
+ case NB_EV_APPLY:
+ /* NOTHING */
+ break;
+ }
+
+ /* Add configuration. */
+ rhc = nb_running_get_entry(args->dnode, NULL, true);
+ source = yang_dnode_get_string(args->dnode, NULL);
+
+ /* Set destroy information. */
+ rhc->rhc_shook = generic_set_delete;
+ rhc->rhc_rule = "src";
+
+ rv = generic_set_add(rhc->rhc_rmi, "src", source,
+ args->errmsg, args->errmsg_len);
+ if (rv != CMD_SUCCESS) {
+ rhc->rhc_shook = NULL;
+ return NB_ERR_INCONSISTENCY;
+ }
+
+ return NB_OK;
+}
+
+int
+lib_route_map_entry_set_action_rmap_set_action_ipv6_src_address_destroy(
+ struct nb_cb_destroy_args *args)
+{
+ switch (args->event) {
+ case NB_EV_VALIDATE:
+ case NB_EV_PREPARE:
+ case NB_EV_ABORT:
+ break;
+ case NB_EV_APPLY:
+ return lib_route_map_entry_set_destroy(args);
+ }
+
+ return NB_OK;
+}