summaryrefslogtreecommitdiff
path: root/bgpd
diff options
context:
space:
mode:
authorPhilippe Guibert <philippe.guibert@6wind.com>2023-12-11 17:23:50 +0100
committerPhilippe Guibert <philippe.guibert@6wind.com>2023-12-11 21:03:33 +0100
commit9cb66bdceb524fbe58614caab27fd6bdbc060c29 (patch)
tree219fc311a7df48ca8c7a03d9b4c0d7dead9b2d0e /bgpd
parent4a2ece949e5ff82d9c3caf7273d31be9a3b3e93c (diff)
bgpd: move l3nhg functions in separate bgp_nhg.[ch] file
This rework separates l3nhg functionality from the nexthop tracking code, by introducing two bgp_nhg.[ch] files. The calling functions are renamed from bgp_l3nhg* to bgp_nhg*. Signed-off-by: Philippe Guibert <philippe.guibert@6wind.com>
Diffstat (limited to 'bgpd')
-rw-r--r--bgpd/bgp_evpn_mh.c10
-rw-r--r--bgpd/bgp_main.c4
-rw-r--r--bgpd/bgp_nhg.c99
-rw-r--r--bgpd/bgp_nhg.h18
-rw-r--r--bgpd/bgp_nht.c87
-rw-r--r--bgpd/bgp_nht.h6
-rw-r--r--bgpd/bgpd.c3
-rw-r--r--bgpd/subdir.am2
8 files changed, 128 insertions, 101 deletions
diff --git a/bgpd/bgp_evpn_mh.c b/bgpd/bgp_evpn_mh.c
index a712310905..c7d8551b5e 100644
--- a/bgpd/bgp_evpn_mh.c
+++ b/bgpd/bgp_evpn_mh.c
@@ -37,7 +37,7 @@
#include "bgpd/bgp_zebra.h"
#include "bgpd/bgp_addpath.h"
#include "bgpd/bgp_label.h"
-#include "bgpd/bgp_nht.h"
+#include "bgpd/bgp_nhg.h"
#include "bgpd/bgp_mpath.h"
#include "bgpd/bgp_trace.h"
@@ -3005,8 +3005,8 @@ static struct bgp_evpn_es_vrf *bgp_evpn_es_vrf_create(struct bgp_evpn_es *es,
listnode_add(es->es_vrf_list, &es_vrf->es_listnode);
/* setup the L3 NHG id for the ES */
- es_vrf->nhg_id = bgp_l3nhg_id_alloc();
- es_vrf->v6_nhg_id = bgp_l3nhg_id_alloc();
+ es_vrf->nhg_id = bgp_nhg_id_alloc();
+ es_vrf->v6_nhg_id = bgp_nhg_id_alloc();
if (BGP_DEBUG(evpn_mh, EVPN_MH_ES))
zlog_debug("es %s vrf %u nhg %u v6_nhg %d create", es->esi_str,
@@ -3034,10 +3034,10 @@ static void bgp_evpn_es_vrf_delete(struct bgp_evpn_es_vrf *es_vrf)
/* Remove the NHG resources */
bgp_evpn_l3nhg_deactivate(es_vrf);
if (es_vrf->nhg_id)
- bgp_l3nhg_id_free(es_vrf->nhg_id);
+ bgp_nhg_id_free(es_vrf->nhg_id);
es_vrf->nhg_id = 0;
if (es_vrf->v6_nhg_id)
- bgp_l3nhg_id_free(es_vrf->v6_nhg_id);
+ bgp_nhg_id_free(es_vrf->v6_nhg_id);
es_vrf->v6_nhg_id = 0;
/* remove from the ES's VRF list */
diff --git a/bgpd/bgp_main.c b/bgpd/bgp_main.c
index 11917c6c4a..e8d5a0307a 100644
--- a/bgpd/bgp_main.c
+++ b/bgpd/bgp_main.c
@@ -47,7 +47,7 @@
#include "bgpd/bgp_errors.h"
#include "bgpd/bgp_script.h"
#include "bgpd/bgp_evpn_mh.h"
-#include "bgpd/bgp_nht.h"
+#include "bgpd/bgp_nhg.h"
#include "bgpd/bgp_routemap_nb.h"
#include "bgpd/bgp_community_alias.h"
@@ -199,7 +199,7 @@ static __attribute__((__noreturn__)) void bgp_exit(int status)
bgp_delete(bgp_default);
bgp_evpn_mh_finish();
- bgp_l3nhg_finish();
+ bgp_nhg_finish();
/* reverse bgp_dump_init */
bgp_dump_finish();
diff --git a/bgpd/bgp_nhg.c b/bgpd/bgp_nhg.c
new file mode 100644
index 0000000000..bf0ba77444
--- /dev/null
+++ b/bgpd/bgp_nhg.c
@@ -0,0 +1,99 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/* BGP Nexthop Group Support
+ * Copyright (C) 2023 NVIDIA Corporation
+ * Copyright (C) 2023 6WIND
+ */
+
+#include <zebra.h>
+
+#include <bgpd/bgpd.h>
+#include <bgpd/bgp_debug.h>
+#include <bgpd/bgp_nhg.h>
+
+
+/****************************************************************************
+ * L3 NHGs are used for fast failover of nexthops in the dplane. These are
+ * the APIs for allocating L3 NHG ids. Management of the L3 NHG itself is
+ * left to the application using it.
+ * PS: Currently EVPN host routes is the only app using L3 NHG for fast
+ * failover of remote ES links.
+ ***************************************************************************/
+static bitfield_t bgp_nh_id_bitmap;
+static uint32_t bgp_nhg_start;
+
+/* XXX - currently we do nothing on the callbacks */
+static void bgp_nhg_add_cb(const char *name)
+{
+}
+
+static void bgp_nhg_modify_cb(const struct nexthop_group_cmd *nhgc)
+{
+}
+
+static void bgp_nhg_add_nexthop_cb(const struct nexthop_group_cmd *nhgc,
+ const struct nexthop *nhop)
+{
+}
+
+static void bgp_nhg_del_nexthop_cb(const struct nexthop_group_cmd *nhgc,
+ const struct nexthop *nhop)
+{
+}
+
+static void bgp_nhg_del_cb(const char *name)
+{
+}
+
+static void bgp_nhg_zebra_init(void)
+{
+ static bool bgp_nhg_zebra_inited;
+
+ if (bgp_nhg_zebra_inited)
+ return;
+
+ bgp_nhg_zebra_inited = true;
+ bgp_nhg_start = zclient_get_nhg_start(ZEBRA_ROUTE_BGP);
+ nexthop_group_init(bgp_nhg_add_cb, bgp_nhg_modify_cb,
+ bgp_nhg_add_nexthop_cb, bgp_nhg_del_nexthop_cb,
+ bgp_nhg_del_cb);
+}
+
+void bgp_nhg_init(void)
+{
+ uint32_t id_max;
+
+ id_max = MIN(ZEBRA_NHG_PROTO_SPACING - 1, 16 * 1024);
+ bf_init(bgp_nh_id_bitmap, id_max);
+ bf_assign_zero_index(bgp_nh_id_bitmap);
+
+ if (BGP_DEBUG(nht, NHT) || BGP_DEBUG(evpn_mh, EVPN_MH_ES))
+ zlog_debug("bgp nhg range %u - %u", bgp_nhg_start + 1,
+ bgp_nhg_start + id_max);
+}
+
+void bgp_nhg_finish(void)
+{
+ bf_free(bgp_nh_id_bitmap);
+}
+
+uint32_t bgp_nhg_id_alloc(void)
+{
+ uint32_t nhg_id = 0;
+
+ bgp_nhg_zebra_init();
+ bf_assign_index(bgp_nh_id_bitmap, nhg_id);
+ if (nhg_id)
+ nhg_id += bgp_nhg_start;
+
+ return nhg_id;
+}
+
+void bgp_nhg_id_free(uint32_t nhg_id)
+{
+ if (!nhg_id || (nhg_id <= bgp_nhg_start))
+ return;
+
+ nhg_id -= bgp_nhg_start;
+
+ bf_release_index(bgp_nh_id_bitmap, nhg_id);
+}
diff --git a/bgpd/bgp_nhg.h b/bgpd/bgp_nhg.h
new file mode 100644
index 0000000000..370e8ab091
--- /dev/null
+++ b/bgpd/bgp_nhg.h
@@ -0,0 +1,18 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/* BGP Nexthop Group Support
+ * Copyright (C) 2023 NVIDIA Corporation
+ * Copyright (C) 2023 6WIND
+ */
+
+#ifndef _BGP_NHG_H
+#define _BGP_NHG_H
+
+#include "nexthop_group.h"
+
+/* APIs for setting up and allocating L3 nexthop group ids */
+extern uint32_t bgp_nhg_id_alloc(void);
+extern void bgp_nhg_id_free(uint32_t nhg_id);
+extern void bgp_nhg_init(void);
+void bgp_nhg_finish(void);
+
+#endif /* _BGP_NHG_H */
diff --git a/bgpd/bgp_nht.c b/bgpd/bgp_nht.c
index 10c0382f6f..05fd0dc4e7 100644
--- a/bgpd/bgp_nht.c
+++ b/bgpd/bgp_nht.c
@@ -1569,90 +1569,3 @@ void bgp_nht_dereg_enhe_cap_intfs(struct peer *peer)
0);
}
}
-
-/****************************************************************************
- * L3 NHGs are used for fast failover of nexthops in the dplane. These are
- * the APIs for allocating L3 NHG ids. Management of the L3 NHG itself is
- * left to the application using it.
- * PS: Currently EVPN host routes is the only app using L3 NHG for fast
- * failover of remote ES links.
- ***************************************************************************/
-static bitfield_t bgp_nh_id_bitmap;
-static uint32_t bgp_l3nhg_start;
-
-/* XXX - currently we do nothing on the callbacks */
-static void bgp_l3nhg_add_cb(const char *name)
-{
-}
-
-static void bgp_l3nhg_modify_cb(const struct nexthop_group_cmd *nhgc)
-{
-}
-
-static void bgp_l3nhg_add_nexthop_cb(const struct nexthop_group_cmd *nhgc,
- const struct nexthop *nhop)
-{
-}
-
-static void bgp_l3nhg_del_nexthop_cb(const struct nexthop_group_cmd *nhgc,
- const struct nexthop *nhop)
-{
-}
-
-static void bgp_l3nhg_del_cb(const char *name)
-{
-}
-
-static void bgp_l3nhg_zebra_init(void)
-{
- static bool bgp_l3nhg_zebra_inited;
- if (bgp_l3nhg_zebra_inited)
- return;
-
- bgp_l3nhg_zebra_inited = true;
- bgp_l3nhg_start = zclient_get_nhg_start(ZEBRA_ROUTE_BGP);
- nexthop_group_init(bgp_l3nhg_add_cb, bgp_l3nhg_modify_cb,
- bgp_l3nhg_add_nexthop_cb, bgp_l3nhg_del_nexthop_cb,
- bgp_l3nhg_del_cb);
-}
-
-
-void bgp_l3nhg_init(void)
-{
- uint32_t id_max;
-
- id_max = MIN(ZEBRA_NHG_PROTO_SPACING - 1, 16 * 1024);
- bf_init(bgp_nh_id_bitmap, id_max);
- bf_assign_zero_index(bgp_nh_id_bitmap);
-
- if (BGP_DEBUG(nht, NHT) || BGP_DEBUG(evpn_mh, EVPN_MH_ES))
- zlog_debug("bgp l3_nhg range %u - %u", bgp_l3nhg_start + 1,
- bgp_l3nhg_start + id_max);
-}
-
-void bgp_l3nhg_finish(void)
-{
- bf_free(bgp_nh_id_bitmap);
-}
-
-uint32_t bgp_l3nhg_id_alloc(void)
-{
- uint32_t nhg_id = 0;
-
- bgp_l3nhg_zebra_init();
- bf_assign_index(bgp_nh_id_bitmap, nhg_id);
- if (nhg_id)
- nhg_id += bgp_l3nhg_start;
-
- return nhg_id;
-}
-
-void bgp_l3nhg_id_free(uint32_t nhg_id)
-{
- if (!nhg_id || (nhg_id <= bgp_l3nhg_start))
- return;
-
- nhg_id -= bgp_l3nhg_start;
-
- bf_release_index(bgp_nh_id_bitmap, nhg_id);
-}
diff --git a/bgpd/bgp_nht.h b/bgpd/bgp_nht.h
index b9f0f6d469..e7c6fdc281 100644
--- a/bgpd/bgp_nht.h
+++ b/bgpd/bgp_nht.h
@@ -79,12 +79,6 @@ extern void bgp_nht_reg_enhe_cap_intfs(struct peer *peer);
extern void bgp_nht_dereg_enhe_cap_intfs(struct peer *peer);
extern void evaluate_paths(struct bgp_nexthop_cache *bnc);
-/* APIs for setting up and allocating L3 nexthop group ids */
-extern uint32_t bgp_l3nhg_id_alloc(void);
-extern void bgp_l3nhg_id_free(uint32_t nhg_id);
-extern void bgp_l3nhg_init(void);
-void bgp_l3nhg_finish(void);
-
extern void bgp_nht_ifp_up(struct interface *ifp);
extern void bgp_nht_ifp_down(struct interface *ifp);
diff --git a/bgpd/bgpd.c b/bgpd/bgpd.c
index 4fa021ab93..0023855a9f 100644
--- a/bgpd/bgpd.c
+++ b/bgpd/bgpd.c
@@ -63,6 +63,7 @@
#include "bgpd/bgp_vty.h"
#include "bgpd/bgp_mpath.h"
#include "bgpd/bgp_nht.h"
+#include "bgpd/bgp_nhg.h"
#include "bgpd/bgp_updgrp.h"
#include "bgpd/bgp_bfd.h"
#include "bgpd/bgp_memory.h"
@@ -8264,7 +8265,7 @@ void bgp_master_init(struct event_loop *master, const int buffer_size,
/* mpls label dynamic allocation pool */
bgp_lp_init(bm->master, &bm->labelpool);
- bgp_l3nhg_init();
+ bgp_nhg_init();
bgp_evpn_mh_init();
QOBJ_REG(bm, bgp_master);
}
diff --git a/bgpd/subdir.am b/bgpd/subdir.am
index 7de6e7a9f1..6d6fad0074 100644
--- a/bgpd/subdir.am
+++ b/bgpd/subdir.am
@@ -77,6 +77,7 @@ bgpd_libbgp_a_SOURCES = \
bgpd/bgp_zebra.c \
bgpd/bgpd.c \
bgpd/bgp_trace.c \
+ bgpd/bgp_nhg.c \
# end
if ENABLE_BGP_VNC
@@ -160,6 +161,7 @@ noinst_HEADERS += \
bgpd/bgp_zebra.h \
bgpd/bgpd.h \
bgpd/bgp_trace.h \
+ bgpd/bgp_nhg.h \
\
bgpd/rfapi/bgp_rfapi_cfg.h \
bgpd/rfapi/rfapi_import.h \