]> git.proxmox.com Git - mirror_frr.git/blobdiff - bgpd/bgp_mplsvpn_snmp.c
Merge pull request #13060 from opensourcerouting/feature/allow_peering_with_127.0.0.1
[mirror_frr.git] / bgpd / bgp_mplsvpn_snmp.c
index 6f75856d543144bfec4438e341914d6dce23823b..20fec6d77be648f0ae6835d03e83a2f8955d4661 100644 (file)
@@ -1,21 +1,6 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
 /* MPLS/BGP L3VPN MIB
  * Copyright (C) 2020 Volta Networks Inc
- *
- * This file is part of FRR.
- *
- * FRRouting 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.
- *
- * FRRouting 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>
 #include "log.h"
 #include "prefix.h"
 #include "command.h"
-#include "thread.h"
+#include "frrevent.h"
 #include "smux.h"
 #include "filter.h"
 #include "hook.h"
 #include "libfrr.h"
-#include "version.h"
+#include "lib/version.h"
 
 #include "bgpd/bgpd.h"
 #include "bgpd/bgp_route.h"
@@ -957,11 +942,13 @@ static uint8_t *mplsL3vpnVrfTable(struct variable *v, oid name[],
                if (CHECK_FLAG(l3vpn_bgp->vpn_policy[AFI_IP].flags,
                               BGP_VPN_POLICY_TOVPN_RD_SET))
                        prefix_rd2str(&l3vpn_bgp->vpn_policy[AFI_IP].tovpn_rd,
-                                     rd_buf, sizeof(rd_buf));
+                                     rd_buf, sizeof(rd_buf),
+                                     bgp_get_asnotation(l3vpn_bgp));
                else if (CHECK_FLAG(l3vpn_bgp->vpn_policy[AFI_IP6].flags,
                                    BGP_VPN_POLICY_TOVPN_RD_SET))
                        prefix_rd2str(&l3vpn_bgp->vpn_policy[AFI_IP6].tovpn_rd,
-                                     rd_buf, sizeof(rd_buf));
+                                     rd_buf, sizeof(rd_buf),
+                                     bgp_get_asnotation(l3vpn_bgp));
 
                *var_len = strnlen(rd_buf, RD_ADDRSTRLEN);
                return (uint8_t *)rd_buf;
@@ -1137,7 +1124,8 @@ static uint8_t *mplsL3vpnVrfRtTable(struct variable *v, oid name[],
        struct bgp *l3vpn_bgp;
        uint32_t rt_index = 0;
        uint8_t rt_type = 0;
-       char *rt_b;
+       char *rt_b = NULL;
+       static char rt_b_str[BUFSIZ] = {};
 
        if (smux_header_table(v, name, length, exact, var_len, write_method)
            == MATCH_FAILED)
@@ -1169,14 +1157,16 @@ static uint8_t *mplsL3vpnVrfRtTable(struct variable *v, oid name[],
                                ECOMMUNITY_ROUTE_TARGET);
                        break;
                default:
-                       rt_b = NULL;
                        break;
                }
-               if (rt_b)
+               if (rt_b) {
                        *var_len = strnlen(rt_b, ECOMMUNITY_STRLEN);
-               else
+                       strlcpy(rt_b_str, rt_b, sizeof(rt_b_str));
+                       XFREE(MTYPE_ECOMMUNITY_STR, rt_b);
+               } else {
                        *var_len = 0;
-               return (uint8_t *)rt_b;
+               }
+               return (uint8_t *)rt_b_str;
        case MPLSL3VPNVRFRTDESCR:
                /* since we dont have a description generate one */
                memset(rt_description, 0, VRF_NAMSIZ + RT_PREAMBLE_SIZE);
@@ -1264,7 +1254,7 @@ bgp_lookup_route(struct bgp *l3vpn_bgp, struct bgp_dest **dest,
                            == 0)
                                return pi;
                        break;
-               default:
+               case IPADDR_NONE:
                        return pi;
                }
        }
@@ -1529,7 +1519,7 @@ static uint8_t *mplsL3vpnRteTable(struct variable *v, oid name[],
        char vrf_name[VRF_NAMSIZ];
        struct bgp *l3vpn_bgp;
        struct bgp_dest *dest;
-       struct bgp_path_info *pi;
+       struct bgp_path_info *pi, *bpi_ultimate;
        const struct prefix *p;
        uint16_t policy = 0;
 
@@ -1545,6 +1535,8 @@ static uint8_t *mplsL3vpnRteTable(struct variable *v, oid name[],
        if (!pi)
                return NULL;
 
+       bpi_ultimate = bgp_get_imported_bpi_ultimate(pi);
+
        p = bgp_dest_get_prefix(dest);
 
        if (!p)
@@ -1625,13 +1617,13 @@ static uint8_t *mplsL3vpnRteTable(struct variable *v, oid name[],
                                case BLACKHOLE_REJECT:
                                        return SNMP_INTEGER(
                                                MPLSL3VPNVRFRTECIDRTYPEREJECT);
-                               default:
+                               case BLACKHOLE_UNSPEC:
+                               case BLACKHOLE_NULL:
+                               case BLACKHOLE_ADMINPROHIB:
                                        return SNMP_INTEGER(
                                                MPLSL3VPNVRFRTECIDRTYPEBLACKHOLE);
                                }
-                       default:
-                               return SNMP_INTEGER(
-                                       MPLSL3VPNVRFRTECIDRTYPEOTHER);
+                               break;
                        }
                } else
                        return SNMP_INTEGER(MPLSL3VPNVRFRTECIDRTYPEOTHER);
@@ -1661,8 +1653,8 @@ static uint8_t *mplsL3vpnRteTable(struct variable *v, oid name[],
        case MPLSL3VPNVRFRTEINETCIDRNEXTHOPAS:
                return SNMP_INTEGER(pi->peer ? pi->peer->as : 0);
        case MPLSL3VPNVRFRTEINETCIDRMETRIC1:
-               if (pi->extra)
-                       return SNMP_INTEGER(pi->extra->igpmetric);
+               if (bpi_ultimate->extra)
+                       return SNMP_INTEGER(bpi_ultimate->extra->igpmetric);
                else
                        return SNMP_INTEGER(0);
        case MPLSL3VPNVRFRTEINETCIDRMETRIC2: