]> git.proxmox.com Git - mirror_frr.git/blobdiff - bgpd/bgp_table.c
Merge pull request #12798 from donaldsharp/rib_match_multicast
[mirror_frr.git] / bgpd / bgp_table.c
index 7e3aa2a48a50bc4c9fa3861f5e517a32868370e3..cb658c03086679b6122bbc0b7256b9715891e69f 100644 (file)
@@ -1,21 +1,6 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
 /* BGP routing table
  * Copyright (C) 1998, 2001 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>
@@ -31,6 +16,7 @@
 #include "bgpd/bgpd.h"
 #include "bgpd/bgp_table.h"
 #include "bgp_addpath.h"
+#include "bgp_trace.h"
 
 void bgp_table_lock(struct bgp_table *rt)
 {
@@ -60,6 +46,42 @@ void bgp_table_finish(struct bgp_table **rt)
        }
 }
 
+/*
+ * bgp_dest_unlock_node
+ */
+void bgp_dest_unlock_node(struct bgp_dest *dest)
+{
+       frrtrace(1, frr_bgp, bgp_dest_unlock, dest);
+       bgp_delete_listnode(dest);
+       route_unlock_node(bgp_dest_to_rnode(dest));
+}
+
+/*
+ * bgp_dest_lock_node
+ */
+struct bgp_dest *bgp_dest_lock_node(struct bgp_dest *dest)
+{
+       frrtrace(1, frr_bgp, bgp_dest_lock, dest);
+       struct route_node *rn = route_lock_node(bgp_dest_to_rnode(dest));
+
+       return bgp_dest_from_rnode(rn);
+}
+
+/*
+ * bgp_dest_get_prefix_str
+ */
+const char *bgp_dest_get_prefix_str(struct bgp_dest *dest)
+{
+       const struct prefix *p = NULL;
+       static char str[PREFIX_STRLEN] = {0};
+
+       p = bgp_dest_get_prefix(dest);
+       if (p)
+               return prefix2str(p, str, sizeof(str));
+
+       return NULL;
+}
+
 /*
  * bgp_node_create
  */
@@ -200,19 +222,18 @@ struct bgp_node *bgp_table_subtree_lookup(const struct bgp_table *table,
        return matched;
 }
 
-printfrr_ext_autoreg_p("BD", printfrr_bd)
-static ssize_t printfrr_bd(char *buf, size_t bsz, const char *fmt,
-                          int prec, const void *ptr)
+printfrr_ext_autoreg_p("BD", printfrr_bd);
+static ssize_t printfrr_bd(struct fbuf *buf, struct printfrr_eargs *ea,
+                          const void *ptr)
 {
        const struct bgp_dest *dest = ptr;
-       const struct prefix *p;
+       const struct prefix *p = bgp_dest_get_prefix(dest);
+       char cbuf[PREFIX_STRLEN];
 
-       if (dest) {
-               p = bgp_dest_get_prefix(dest);
-               prefix2str(p, buf, bsz);
-       } else {
-               strlcpy(buf, "NULL", bsz);
-       }
+       if (!dest)
+               return bputs(buf, "(null)");
 
-       return 2;
+       /* need to get the real length even if buffer too small */
+       prefix2str(p, cbuf, sizeof(cbuf));
+       return bputs(buf, cbuf);
 }