]> git.puffer.fish Git - mirror/frr.git/commitdiff
zebra: North-bound implementation for zebra rmaps
authorSarita Patra <saritap@vmware.com>
Fri, 30 Oct 2020 07:41:19 +0000 (00:41 -0700)
committerIgor Ryzhov <iryzhov@nfware.com>
Tue, 30 Mar 2021 19:58:42 +0000 (22:58 +0300)
This commit introduces the implementation for the north-bound
callbacks for the zebra-specific route-map match and set clauses.

Signed-off-by: NaveenThanikachalam <nthanikachal@vmware.com>
Signed-off-by: Sarita Patra <saritap@vmware.com>
zebra/main.c
zebra/subdir.am
zebra/zebra_nb.c
zebra/zebra_nb.h
zebra/zebra_nb_config.c
zebra/zebra_routemap.c
zebra/zebra_routemap.h
zebra/zebra_routemap_nb.c [new file with mode: 0644]
zebra/zebra_routemap_nb.h [new file with mode: 0644]
zebra/zebra_routemap_nb_config.c [new file with mode: 0644]

index 09350f72c18fbaadaf6ef36b0436482f5ce4d3b2..3f75b222bac1fe15f5c4df0935b5b17be8c952da 100644 (file)
@@ -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(
index b5c26d720fe77ed923db7a1a9243b23c3a04f1cb..6a582f69015b501a18ec2af225b74cf709463235 100644 (file)
@@ -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
index bdeb84486d58d61bc1f5924ed5883f34d584578c..90d4ee7ced3420ac3b1df900d27faf514c667373 100644 (file)
@@ -643,48 +643,6 @@ const struct frr_yang_module_info frr_zebra_info = {
                                .modify = lib_vrf_zebra_prefix_only_modify,
                        }
                },
-               {
-                       .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,
                },
index 79632dc83e3eadd0eb7cc12a575e4edcc7e85a55..95907059a8511e7ab95318c436e0899af8cd06b7 100644 (file)
@@ -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 *
index ba9f96b7dee8d84065f78b21ab509f2d0e5f5c18..e23a515168dba199f5499ee851f1409d11359b98 100644 (file)
@@ -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);
-}
index c9660c7309a067a3079529be35524191ab97fd3a..6a42c682ad4e1e45db35ecd6655eb2de065b1e00 100644 (file)
@@ -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
index c016d958750e4f9f9de1458523acba70b99d6353..3f58e14e10e1e0de69bad5a6f68a092033449882 100644 (file)
@@ -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 (file)
index 0000000..c82c34d
--- /dev/null
@@ -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 (file)
index 0000000..a43f2b2
--- /dev/null
@@ -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 (file)
index 0000000..8f56606
--- /dev/null
@@ -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;
+}