]> git.proxmox.com Git - mirror_frr.git/blobdiff - ospfd/ospf_routemap.c
Merge pull request #12798 from donaldsharp/rib_match_multicast
[mirror_frr.git] / ospfd / ospf_routemap.c
index bdc65d23bf64ccffdb930c28e8c39ddfd1c14761..3087008819275c7a97fa0040d083fc9c56a7dc4f 100644 (file)
@@ -1,24 +1,9 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
 /*
  * Route map function of ospfd.
  * Copyright (C) 2000 IP Infusion Inc.
  *
  * Written by Toshiaki Takada.
- *
- * This file is part of GNU Zebra.
- *
- * GNU Zebra 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, or (at your option) any
- * later version.
- *
- * GNU Zebra 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 <zebra.h>
@@ -33,6 +18,7 @@
 #include "plist.h"
 #include "vrf.h"
 #include "frrstr.h"
+#include "northbound_cli.h"
 
 #include "ospfd/ospfd.h"
 #include "ospfd/ospf_asbr.h"
@@ -70,19 +56,14 @@ static void ospf_route_map_update(const char *name)
                                        /* Keep old route-map. */
                                        struct route_map *old = ROUTEMAP(red);
 
-                                       if (!old) {
-                                               /* Route-map creation */
-                                               /* Update route-map. */
-                                               ROUTEMAP(red) =
-                                                       route_map_lookup_by_name(
-                                                               ROUTEMAP_NAME(red));
-
-                                                       route_map_counter_increment(
-                                                               ROUTEMAP(red));
-                                       } else {
-                                               /* Route-map deletion */
-                                               ROUTEMAP(red) = NULL;
-                                       }
+                                       ROUTEMAP(red) =
+                                               route_map_lookup_by_name(
+                                                       ROUTEMAP_NAME(red));
+
+                                       if (!old)
+                                               route_map_counter_increment(
+                                                       ROUTEMAP(red));
+
                                        /* No update for this distribute type.
                                         */
                                        if (old == NULL
@@ -138,8 +119,13 @@ route_match_ip_nexthop(void *rule, const struct prefix *prefix, void *object)
        p.prefixlen = IPV4_MAX_BITLEN;
 
        alist = access_list_lookup(AFI_IP, (char *)rule);
-       if (alist == NULL)
+       if (alist == NULL) {
+               if (CHECK_FLAG(rmap_debug, DEBUG_ROUTEMAP_DETAIL))
+                       zlog_debug(
+                               "%s: Access-List Specified: %s does not exist defaulting to NO_MATCH",
+                               __func__, (char *)rule);
                return RMAP_NOMATCH;
+       }
 
        return (access_list_apply(alist, &p) == FILTER_DENY ? RMAP_NOMATCH
                                                            : RMAP_MATCH);
@@ -181,8 +167,13 @@ route_match_ip_next_hop_prefix_list(void *rule, const struct prefix *prefix,
        p.prefixlen = IPV4_MAX_BITLEN;
 
        plist = prefix_list_lookup(AFI_IP, (char *)rule);
-       if (plist == NULL)
+       if (plist == NULL) {
+               if (CHECK_FLAG(rmap_debug, DEBUG_ROUTEMAP_DETAIL))
+                       zlog_debug(
+                               "%s: Prefix List %s specified does not exist defaulting to NO_MATCH",
+                               __func__, (char *)rule);
                return RMAP_NOMATCH;
+       }
 
        return (prefix_list_apply(plist, &p) == PREFIX_DENY ? RMAP_NOMATCH
                                                            : RMAP_MATCH);
@@ -253,8 +244,13 @@ route_match_ip_address(void *rule, const struct prefix *prefix, void *object)
        /* struct prefix_ipv4 match; */
 
        alist = access_list_lookup(AFI_IP, (char *)rule);
-       if (alist == NULL)
+       if (alist == NULL) {
+               if (CHECK_FLAG(rmap_debug, DEBUG_ROUTEMAP_DETAIL))
+                       zlog_debug(
+                               "%s: Access-List Specified: %s does not exist defaulting to NO_MATCH",
+                               __func__, (char *)rule);
                return RMAP_NOMATCH;
+       }
 
        return (access_list_apply(alist, prefix) == FILTER_DENY ? RMAP_NOMATCH
                                                                : RMAP_MATCH);
@@ -289,8 +285,14 @@ route_match_ip_address_prefix_list(void *rule, const struct prefix *prefix,
        struct prefix_list *plist;
 
        plist = prefix_list_lookup(AFI_IP, (char *)rule);
-       if (plist == NULL)
+       if (plist == NULL) {
+               if (CHECK_FLAG(rmap_debug, DEBUG_ROUTEMAP_DETAIL))
+                       zlog_debug(
+                               "%s: Prefix List %s specified does not exist defaulting to NO_MATCH",
+                               __func__, (char *)rule);
+
                return RMAP_NOMATCH;
+       }
 
        return (prefix_list_apply(plist, prefix) == PREFIX_DENY ? RMAP_NOMATCH
                                                                : RMAP_MATCH);
@@ -324,7 +326,7 @@ route_match_interface(void *rule, const struct prefix *prefix, void *object)
        struct external_info *ei;
 
        ei = object;
-       ifp = if_lookup_by_name_all_vrf((char *)rule);
+       ifp = if_lookup_by_name((char *)rule, ei->ospf->vrf_id);
 
        if (ifp == NULL || ifp->ifindex != ei->ifindex)
                return RMAP_NOMATCH;
@@ -534,7 +536,7 @@ static const struct route_map_rule_cmd route_set_tag_cmd = {
        route_map_rule_tag_free,
 };
 
-DEFUN (set_metric_type,
+DEFUN_YANG (set_metric_type,
        set_metric_type_cmd,
        "set metric-type <type-1|type-2>",
        SET_STR
@@ -543,11 +545,19 @@ DEFUN (set_metric_type,
        "OSPF[6] external type 2 metric\n")
 {
        char *ext = argv[2]->text;
-       return generic_set_add(vty, VTY_GET_CONTEXT(route_map_index),
-                              "metric-type", ext);
+
+       const char *xpath =
+               "./set-action[action='frr-ospf-route-map:metric-type']";
+       char xpath_value[XPATH_MAXLEN];
+
+       nb_cli_enqueue_change(vty, xpath, NB_OP_CREATE, NULL);
+       snprintf(xpath_value, sizeof(xpath_value),
+                "%s/rmap-set-action/frr-ospf-route-map:metric-type", xpath);
+       nb_cli_enqueue_change(vty, xpath_value, NB_OP_MODIFY, ext);
+       return nb_cli_apply_changes(vty, NULL);
 }
 
-DEFUN (no_set_metric_type,
+DEFUN_YANG (no_set_metric_type,
        no_set_metric_type_cmd,
        "no set metric-type [<type-1|type-2>]",
        NO_STR
@@ -556,9 +566,11 @@ DEFUN (no_set_metric_type,
        "OSPF[6] external type 1 metric\n"
        "OSPF[6] external type 2 metric\n")
 {
-       char *ext = (argc == 4) ? argv[3]->text : NULL;
-       return generic_set_delete(vty, VTY_GET_CONTEXT(route_map_index),
-                                 "metric-type", ext);
+       const char *xpath =
+               "./set-action[action='frr-ospf-route-map:metric-type']";
+
+       nb_cli_enqueue_change(vty, xpath, NB_OP_DESTROY, NULL);
+       return nb_cli_apply_changes(vty, NULL);
 }
 
 /* Route-map init */