]> git.proxmox.com Git - mirror_frr.git/blobdiff - lib/routemap_northbound.c
Merge pull request #7063 from idryzhov/yang-leafref
[mirror_frr.git] / lib / routemap_northbound.c
index f500a6c408dab6d288fd7d05bc1ca8f932e14583..597a6b1ecfdbfb940dde0907ef62330f78675eb7 100644 (file)
@@ -515,77 +515,6 @@ static int lib_route_map_entry_match_condition_interface_destroy(
        return lib_route_map_entry_match_destroy(args);
 }
 
-/*
- * XPath: /frr-route-map:lib/route-map/entry/match-condition/access-list-num
- */
-static int lib_route_map_entry_match_condition_access_list_num_modify(
-       struct nb_cb_modify_args *args)
-{
-       struct routemap_hook_context *rhc;
-       const char *acl;
-       int condition, rv;
-
-       if (args->event != NB_EV_APPLY)
-               return NB_OK;
-
-       /* Check for hook function. */
-       rv = CMD_SUCCESS;
-       acl = yang_dnode_get_string(args->dnode, NULL);
-       rhc = nb_running_get_entry(args->dnode, NULL, true);
-       condition = yang_dnode_get_enum(args->dnode, "../condition");
-       switch (condition) {
-       case 1: /* ipv4-address-list */
-               if (rmap_match_set_hook.match_ip_address == NULL)
-                       break;
-               rhc->rhc_mhook = rmap_match_set_hook.no_match_ip_address;
-               rhc->rhc_rule = "ip address";
-               rhc->rhc_event = RMAP_EVENT_FILTER_DELETED;
-               rv = rmap_match_set_hook.match_ip_address(
-                       NULL, rhc->rhc_rmi, "ip address", acl,
-                       RMAP_EVENT_FILTER_ADDED);
-               break;
-       case 3: /* ipv4-next-hop-list */
-               if (rmap_match_set_hook.match_ip_next_hop == NULL)
-                       break;
-               rhc->rhc_mhook = rmap_match_set_hook.no_match_ip_next_hop;
-               rhc->rhc_rule = "ip next-hop";
-               rhc->rhc_event = RMAP_EVENT_FILTER_DELETED;
-               rv = rmap_match_set_hook.match_ip_next_hop(
-                       NULL, rhc->rhc_rmi, "ip next-hop", acl,
-                       RMAP_EVENT_FILTER_ADDED);
-               break;
-       }
-       if (rv != CMD_SUCCESS) {
-               rhc->rhc_mhook = NULL;
-               return NB_ERR_INCONSISTENCY;
-       }
-
-       return NB_OK;
-}
-
-static int lib_route_map_entry_match_condition_access_list_num_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/access-list-num-extended
- */
-static int lib_route_map_entry_match_condition_access_list_num_extended_modify(
-       struct nb_cb_modify_args *args)
-{
-       return lib_route_map_entry_match_condition_access_list_num_modify(args);
-}
-
-static int lib_route_map_entry_match_condition_access_list_num_extended_destroy(
-       struct nb_cb_destroy_args *args)
-{
-       return lib_route_map_entry_match_condition_access_list_num_destroy(
-               args);
-}
-
 /*
  * XPath: /frr-route-map:lib/route-map/entry/match-condition/list-name
  */
@@ -1054,8 +983,19 @@ lib_route_map_entry_set_action_value_destroy(struct nb_cb_destroy_args *args)
 static int
 lib_route_map_entry_set_action_add_metric_modify(struct nb_cb_modify_args *args)
 {
+       char metric_str[16];
+
+       if (args->event == NB_EV_VALIDATE
+           && yang_dnode_get_uint32(args->dnode, NULL) == 0) {
+               snprintf(args->errmsg, args->errmsg_len,
+                        "Can't add zero to metric");
+               return NB_ERR_VALIDATION;
+       }
+
+       snprintf(metric_str, sizeof(metric_str), "+%s",
+                yang_dnode_get_string(args->dnode, NULL));
        return set_action_modify(args->event, args->dnode, args->resource,
-                                "+metric");
+                                metric_str);
 }
 
 static int lib_route_map_entry_set_action_add_metric_destroy(
@@ -1070,8 +1010,19 @@ static int lib_route_map_entry_set_action_add_metric_destroy(
 static int lib_route_map_entry_set_action_subtract_metric_modify(
        struct nb_cb_modify_args *args)
 {
+       char metric_str[16];
+
+       if (args->event == NB_EV_VALIDATE
+           && yang_dnode_get_uint32(args->dnode, NULL) == 0) {
+               snprintf(args->errmsg, args->errmsg_len,
+                        "Can't subtract zero from metric");
+               return NB_ERR_VALIDATION;
+       }
+
+       snprintf(metric_str, sizeof(metric_str), "-%s",
+                yang_dnode_get_string(args->dnode, NULL));
        return set_action_modify(args->event, args->dnode, args->resource,
-                                "-metric");
+                                metric_str);
 }
 
 static int lib_route_map_entry_set_action_subtract_metric_destroy(
@@ -1244,20 +1195,6 @@ const struct frr_yang_module_info frr_route_map_info = {
                                .destroy = lib_route_map_entry_match_condition_interface_destroy,
                        }
                },
-               {
-                       .xpath = "/frr-route-map:lib/route-map/entry/match-condition/access-list-num",
-                       .cbs = {
-                               .modify = lib_route_map_entry_match_condition_access_list_num_modify,
-                               .destroy = lib_route_map_entry_match_condition_access_list_num_destroy,
-                       }
-               },
-               {
-                       .xpath = "/frr-route-map:lib/route-map/entry/match-condition/access-list-num-extended",
-                       .cbs = {
-                               .modify = lib_route_map_entry_match_condition_access_list_num_extended_modify,
-                               .destroy = lib_route_map_entry_match_condition_access_list_num_extended_destroy,
-                       }
-               },
                {
                        .xpath = "/frr-route-map:lib/route-map/entry/match-condition/list-name",
                        .cbs = {