]> git.proxmox.com Git - mirror_frr.git/blobdiff - bgpd/bgp_routemap.c
Merge pull request #12798 from donaldsharp/rib_match_multicast
[mirror_frr.git] / bgpd / bgp_routemap.c
index 5aa3ec4fd168b53b298cde1433ec59f6b9fe86af..8fd46d00af771347c1648d61f29588c3d78d0a5d 100644 (file)
@@ -1,21 +1,6 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
 /* Route map function of bgpd.
  * Copyright (C) 1998, 1999 Kunihiro Ishiguro
- *
- * 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>
@@ -228,7 +213,7 @@ static void *route_aspath_compile(const char *arg)
 {
        struct aspath *aspath;
 
-       aspath = aspath_str2aspath(arg);
+       aspath = aspath_str2aspath(arg, bgp_get_asnotation(NULL));
        if (!aspath)
                return NULL;
        return aspath;
@@ -1403,10 +1388,6 @@ static void *route_match_local_pref_compile(const char *arg)
        char *endptr = NULL;
        unsigned long tmpval;
 
-       /* Locpref value shoud be integer. */
-       if (!all_digit(arg))
-               return NULL;
-
        errno = 0;
        tmpval = strtoul(arg, &endptr, 10);
        if (*endptr != '\0' || errno || tmpval > UINT32_MAX)
@@ -3043,11 +3024,11 @@ static void *route_set_origin_compile(const char *arg)
        origin = XMALLOC(MTYPE_ROUTE_MAP_COMPILED, sizeof(uint8_t));
 
        if (strcmp(arg, "igp") == 0)
-               *origin = 0;
+               *origin = BGP_ORIGIN_IGP;
        else if (strcmp(arg, "egp") == 0)
-               *origin = 1;
+               *origin = BGP_ORIGIN_EGP;
        else
-               *origin = 2;
+               *origin = BGP_ORIGIN_INCOMPLETE;
 
        return origin;
 }
@@ -3650,17 +3631,29 @@ route_set_ipv6_nexthop_local(void *rule, const struct prefix *p, void *object)
 {
        struct in6_addr *address;
        struct bgp_path_info *path;
+       struct bgp_dest *dest;
+       struct bgp_table *table = NULL;
 
        /* Fetch routemap's rule information. */
        address = rule;
        path = object;
+       dest = path->net;
+
+       if (!dest)
+               return RMAP_OKAY;
+
+       table = bgp_dest_table(dest);
+       if (!table)
+               return RMAP_OKAY;
 
        /* Set next hop value. */
        path->attr->mp_nexthop_local = *address;
 
        /* Set nexthop length. */
-       if (path->attr->mp_nexthop_len != BGP_ATTR_NHLEN_IPV6_GLOBAL_AND_LL &&
-           path->attr->mp_nexthop_len != BGP_ATTR_NHLEN_VPNV6_GLOBAL_AND_LL)
+       if (table->safi == SAFI_MPLS_VPN || table->safi == SAFI_ENCAP ||
+           table->safi == SAFI_EVPN)
+               path->attr->mp_nexthop_len = BGP_ATTR_NHLEN_VPNV6_GLOBAL_AND_LL;
+       else
                path->attr->mp_nexthop_len = BGP_ATTR_NHLEN_IPV6_GLOBAL_AND_LL;
 
        SET_FLAG(path->attr->rmap_change_flags,
@@ -5682,15 +5675,16 @@ DEFUN_YANG (no_set_label_index,
 
 DEFUN_YANG (set_aspath_prepend_asn,
            set_aspath_prepend_asn_cmd,
-           "set as-path prepend (1-4294967295)...",
+           "set as-path prepend ASNUM...",
            SET_STR
            "Transform BGP AS_PATH attribute\n"
            "Prepend to the as-path\n"
-           "AS number\n")
+           AS_STR)
 {
        int idx_asn = 3;
        int ret;
        char *str;
+       struct aspath *aspath;
 
        str = argv_concat(argv, argc, idx_asn);
 
@@ -5698,6 +5692,12 @@ DEFUN_YANG (set_aspath_prepend_asn,
                "./set-action[action='frr-bgp-route-map:as-path-prepend']";
        char xpath_value[XPATH_MAXLEN];
 
+       aspath = route_aspath_compile(str);
+       if (!aspath) {
+               vty_out(vty, "%% Invalid AS path value %s\n", str);
+               return CMD_WARNING_CONFIG_FAILED;
+       }
+       route_aspath_free(aspath);
        nb_cli_enqueue_change(vty, xpath, NB_OP_CREATE, NULL);
        snprintf(xpath_value, sizeof(xpath_value),
                 "%s/rmap-set-action/frr-bgp-route-map:prepend-as-path", xpath);
@@ -5732,16 +5732,22 @@ DEFUN_YANG (set_aspath_prepend_lastas,
 
 DEFPY_YANG (set_aspath_replace_asn,
            set_aspath_replace_asn_cmd,
-           "set as-path replace <any|(1-4294967295)>$replace",
+           "set as-path replace <any|ASNUM>$replace",
            SET_STR
            "Transform BGP AS_PATH attribute\n"
            "Replace AS number to local AS number\n"
            "Replace any AS number to local AS number\n"
-           "Replace a specific AS number to local AS number\n")
+           "Replace a specific AS number in plain or dotted format to local AS number\n")
 {
        const char *xpath =
                "./set-action[action='frr-bgp-route-map:as-path-replace']";
        char xpath_value[XPATH_MAXLEN];
+       as_t as_value;
+
+       if (!strmatch(replace, "any") && !asn_str2asn(replace, &as_value)) {
+               vty_out(vty, "%% Invalid AS value %s\n", replace);
+               return CMD_WARNING_CONFIG_FAILED;
+       }
 
        nb_cli_enqueue_change(vty, xpath, NB_OP_CREATE, NULL);
        snprintf(xpath_value, sizeof(xpath_value),
@@ -5752,13 +5758,13 @@ DEFPY_YANG (set_aspath_replace_asn,
 
 DEFPY_YANG (no_set_aspath_replace_asn,
            no_set_aspath_replace_asn_cmd,
-           "no set as-path replace [<any|(1-4294967295)>]",
+           "no set as-path replace [<any|ASNUM>]",
            NO_STR
            SET_STR
            "Transform BGP AS_PATH attribute\n"
            "Replace AS number to local AS number\n"
            "Replace any AS number to local AS number\n"
-           "Replace a specific AS number to local AS number\n")
+           "Replace a specific AS number in plain or dotted format to local AS number\n")
 {
        const char *xpath =
                "./set-action[action='frr-bgp-route-map:as-path-replace']";
@@ -5769,12 +5775,12 @@ DEFPY_YANG (no_set_aspath_replace_asn,
 
 DEFUN_YANG (no_set_aspath_prepend,
            no_set_aspath_prepend_cmd,
-           "no set as-path prepend [(1-4294967295)]",
+           "no set as-path prepend [ASNUM]",
            NO_STR
            SET_STR
            "Transform BGP AS_PATH attribute\n"
            "Prepend to the as-path\n"
-           "AS number\n")
+           AS_STR)
 {
        const char *xpath =
                "./set-action[action='frr-bgp-route-map:as-path-prepend']";
@@ -5802,15 +5808,16 @@ DEFUN_YANG (no_set_aspath_prepend_lastas,
 
 DEFUN_YANG (set_aspath_exclude,
            set_aspath_exclude_cmd,
-           "set as-path exclude (1-4294967295)...",
+           "set as-path exclude ASNUM...",
            SET_STR
            "Transform BGP AS-path attribute\n"
            "Exclude from the as-path\n"
-           "AS number\n")
+           AS_STR)
 {
        int idx_asn = 3;
        int ret;
        char *str;
+       struct aspath *aspath;
 
        str = argv_concat(argv, argc, idx_asn);
 
@@ -5818,6 +5825,12 @@ DEFUN_YANG (set_aspath_exclude,
                "./set-action[action='frr-bgp-route-map:as-path-exclude']";
        char xpath_value[XPATH_MAXLEN];
 
+       aspath = route_aspath_compile(str);
+       if (!aspath) {
+               vty_out(vty, "%% Invalid AS path value %s\n", str);
+               return CMD_WARNING_CONFIG_FAILED;
+       }
+       route_aspath_free(aspath);
        nb_cli_enqueue_change(vty, xpath, NB_OP_CREATE, NULL);
        snprintf(xpath_value, sizeof(xpath_value),
                 "%s/rmap-set-action/frr-bgp-route-map:exclude-as-path", xpath);
@@ -5829,7 +5842,7 @@ DEFUN_YANG (set_aspath_exclude,
 
 DEFUN_YANG (no_set_aspath_exclude,
            no_set_aspath_exclude_cmd,
-           "no set as-path exclude (1-4294967295)...",
+           "no set as-path exclude ASNUM...",
            NO_STR
            SET_STR
            "Transform BGP AS_PATH attribute\n"
@@ -5889,9 +5902,14 @@ DEFUN_YANG (set_community,
                else
                        first = 1;
 
+#if CONFDATE > 20230801
+CPP_NOTICE("Deprecate COMMUNITY_INTERNET BGP community")
+#endif
                if (strncmp(argv[i]->arg, "internet", strlen(argv[i]->arg))
                    == 0) {
                        buffer_putstr(b, "internet");
+                       vty_out(vty, "%% `internet` community is deprecated\n");
+                       zlog_warn("`internet` community is deprecated");
                        continue;
                }
                if (strncmp(argv[i]->arg, "local-AS", strlen(argv[i]->arg))
@@ -6515,11 +6533,11 @@ DEFPY_YANG (no_set_aigp_metric,
 
 DEFUN_YANG (set_aggregator_as,
            set_aggregator_as_cmd,
-           "set aggregator as (1-4294967295) A.B.C.D",
+           "set aggregator as ASNUM A.B.C.D",
            SET_STR
            "BGP aggregator attribute\n"
            "AS number of aggregator\n"
-           "AS number\n"
+           AS_STR
            "IP address of aggregator\n")
 {
        int idx_number = 3;
@@ -6528,6 +6546,12 @@ DEFUN_YANG (set_aggregator_as,
        char xpath_addr[XPATH_MAXLEN];
        const char *xpath =
                "./set-action[action='frr-bgp-route-map:aggregator']";
+       as_t as_value;
+
+       if (!asn_str2asn(argv[idx_number]->arg, &as_value)) {
+               vty_out(vty, "%% Invalid AS value %s\n", argv[idx_number]->arg);
+               return CMD_WARNING_CONFIG_FAILED;
+       }
 
        nb_cli_enqueue_change(vty, xpath, NB_OP_CREATE, NULL);
 
@@ -6550,12 +6574,12 @@ DEFUN_YANG (set_aggregator_as,
 
 DEFUN_YANG (no_set_aggregator_as,
            no_set_aggregator_as_cmd,
-           "no set aggregator as [(1-4294967295) A.B.C.D]",
+           "no set aggregator as [ASNUM A.B.C.D]",
            NO_STR
            SET_STR
            "BGP aggregator attribute\n"
            "AS number of aggregator\n"
-           "AS number\n"
+           AS_STR
            "IP address of aggregator\n")
 {
        const char *xpath =