mirror of
https://git.proxmox.com/git/mirror_frr
synced 2025-04-30 00:56:38 +00:00
Merge pull request #12670 from louis-6wind/fix-bfd-zclient
lib: do not reopen a zclient socket for bfd
This commit is contained in:
commit
21188a567a
95
lib/bfd.c
95
lib/bfd.c
@ -129,8 +129,6 @@ struct bfd_sessions_global {
|
|||||||
struct thread_master *tm;
|
struct thread_master *tm;
|
||||||
/** Pointer to zebra client data structure. */
|
/** Pointer to zebra client data structure. */
|
||||||
struct zclient *zc;
|
struct zclient *zc;
|
||||||
/** Zebra next hop tracking (NHT) client. */
|
|
||||||
struct zclient *nht_zclient;
|
|
||||||
|
|
||||||
/** Debugging state. */
|
/** Debugging state. */
|
||||||
bool debugging;
|
bool debugging;
|
||||||
@ -147,31 +145,10 @@ static const struct in6_addr i6a_zero;
|
|||||||
/*
|
/*
|
||||||
* Prototypes
|
* Prototypes
|
||||||
*/
|
*/
|
||||||
static void bfd_nht_zclient_connect(struct thread *thread);
|
|
||||||
|
|
||||||
static void bfd_nht_zclient_connected(struct zclient *zclient);
|
|
||||||
static int bfd_nht_update(ZAPI_CALLBACK_ARGS);
|
|
||||||
|
|
||||||
static void bfd_source_cache_get(struct bfd_session_params *session);
|
static void bfd_source_cache_get(struct bfd_session_params *session);
|
||||||
static void bfd_source_cache_put(struct bfd_session_params *session);
|
static void bfd_source_cache_put(struct bfd_session_params *session);
|
||||||
|
|
||||||
static inline void
|
|
||||||
bfd_source_cache_register(const struct bfd_source_cache *source)
|
|
||||||
{
|
|
||||||
zclient_send_rnh(bsglobal.nht_zclient, ZEBRA_NEXTHOP_REGISTER,
|
|
||||||
&source->address, SAFI_UNICAST, false, false,
|
|
||||||
source->vrf_id);
|
|
||||||
}
|
|
||||||
|
|
||||||
static inline void
|
|
||||||
bfd_source_cache_unregister(const struct bfd_source_cache *source)
|
|
||||||
{
|
|
||||||
zclient_send_rnh(bsglobal.nht_zclient, ZEBRA_NEXTHOP_UNREGISTER,
|
|
||||||
&source->address, SAFI_UNICAST, false, false,
|
|
||||||
source->vrf_id);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* bfd_get_peer_info - Extract the Peer information for which the BFD session
|
* bfd_get_peer_info - Extract the Peer information for which the BFD session
|
||||||
* went down from the message sent from Zebra to clients.
|
* went down from the message sent from Zebra to clients.
|
||||||
@ -1074,20 +1051,11 @@ static int bfd_protocol_integration_finish(void)
|
|||||||
if (!SLIST_EMPTY(&bsglobal.source_list))
|
if (!SLIST_EMPTY(&bsglobal.source_list))
|
||||||
zlog_warn("BFD integration source cache not empty");
|
zlog_warn("BFD integration source cache not empty");
|
||||||
|
|
||||||
zclient_stop(bsglobal.nht_zclient);
|
|
||||||
zclient_free(bsglobal.nht_zclient);
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static zclient_handler *const bfd_nht_handlers[] = {
|
|
||||||
[ZEBRA_NEXTHOP_UPDATE] = bfd_nht_update,
|
|
||||||
};
|
|
||||||
|
|
||||||
void bfd_protocol_integration_init(struct zclient *zc, struct thread_master *tm)
|
void bfd_protocol_integration_init(struct zclient *zc, struct thread_master *tm)
|
||||||
{
|
{
|
||||||
struct zclient_options bfd_nht_options = zclient_options_default;
|
|
||||||
|
|
||||||
/* Initialize data structure. */
|
/* Initialize data structure. */
|
||||||
TAILQ_INIT(&bsglobal.bsplist);
|
TAILQ_INIT(&bsglobal.bsplist);
|
||||||
SLIST_INIT(&bsglobal.source_list);
|
SLIST_INIT(&bsglobal.source_list);
|
||||||
@ -1102,16 +1070,6 @@ void bfd_protocol_integration_init(struct zclient *zc, struct thread_master *tm)
|
|||||||
/* Send the client registration */
|
/* Send the client registration */
|
||||||
bfd_client_sendmsg(zc, ZEBRA_BFD_CLIENT_REGISTER, VRF_DEFAULT);
|
bfd_client_sendmsg(zc, ZEBRA_BFD_CLIENT_REGISTER, VRF_DEFAULT);
|
||||||
|
|
||||||
/* Start NHT client (for automatic source decisions). */
|
|
||||||
bsglobal.nht_zclient =
|
|
||||||
zclient_new(tm, &bfd_nht_options, bfd_nht_handlers,
|
|
||||||
array_size(bfd_nht_handlers));
|
|
||||||
bsglobal.nht_zclient->sock = -1;
|
|
||||||
bsglobal.nht_zclient->privs = zc->privs;
|
|
||||||
bsglobal.nht_zclient->zebra_connected = bfd_nht_zclient_connected;
|
|
||||||
thread_add_timer(tm, bfd_nht_zclient_connect, bsglobal.nht_zclient, 1,
|
|
||||||
&bsglobal.nht_zclient->t_connect);
|
|
||||||
|
|
||||||
hook_register(frr_fini, bfd_protocol_integration_finish);
|
hook_register(frr_fini, bfd_protocol_integration_finish);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1252,8 +1210,6 @@ static void bfd_source_cache_get(struct bfd_session_params *session)
|
|||||||
session->source_cache = source;
|
session->source_cache = source;
|
||||||
source->refcount = 1;
|
source->refcount = 1;
|
||||||
|
|
||||||
bfd_source_cache_register(source);
|
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1268,7 +1224,6 @@ static void bfd_source_cache_put(struct bfd_session_params *session)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
bfd_source_cache_unregister(session->source_cache);
|
|
||||||
SLIST_REMOVE(&bsglobal.source_list, session->source_cache,
|
SLIST_REMOVE(&bsglobal.source_list, session->source_cache,
|
||||||
bfd_source_cache, entry);
|
bfd_source_cache, entry);
|
||||||
XFREE(MTYPE_BFD_SOURCE, session->source_cache);
|
XFREE(MTYPE_BFD_SOURCE, session->source_cache);
|
||||||
@ -1378,59 +1333,19 @@ static bool bfd_source_cache_update(struct bfd_source_cache *source,
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void bfd_nht_zclient_connect(struct thread *thread)
|
int bfd_nht_update(const struct prefix *match, const struct zapi_route *route)
|
||||||
{
|
|
||||||
struct zclient *zclient = THREAD_ARG(thread);
|
|
||||||
|
|
||||||
if (bsglobal.debugging)
|
|
||||||
zlog_debug("BFD NHT zclient connection attempt");
|
|
||||||
|
|
||||||
if (zclient_start(zclient) == -1) {
|
|
||||||
if (bsglobal.debugging)
|
|
||||||
zlog_debug("BFD NHT zclient connection failed");
|
|
||||||
|
|
||||||
thread_add_timer(bsglobal.tm, bfd_nht_zclient_connect, zclient,
|
|
||||||
3, &zclient->t_connect);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (bsglobal.debugging)
|
|
||||||
zlog_debug("BFD NHT zclient connection succeeded");
|
|
||||||
}
|
|
||||||
|
|
||||||
static void bfd_nht_zclient_connected(struct zclient *zclient)
|
|
||||||
{
|
{
|
||||||
struct bfd_source_cache *source;
|
struct bfd_source_cache *source;
|
||||||
|
|
||||||
if (bsglobal.debugging)
|
if (bsglobal.debugging)
|
||||||
zlog_debug("BFD NHT zclient connected");
|
zlog_debug("BFD NHT update for %pFX", &route->prefix);
|
||||||
|
|
||||||
SLIST_FOREACH (source, &bsglobal.source_list, entry)
|
|
||||||
bfd_source_cache_register(source);
|
|
||||||
}
|
|
||||||
|
|
||||||
static int bfd_nht_update(ZAPI_CALLBACK_ARGS)
|
|
||||||
{
|
|
||||||
struct bfd_source_cache *source;
|
|
||||||
struct zapi_route route;
|
|
||||||
struct prefix match;
|
|
||||||
|
|
||||||
if (!zapi_nexthop_update_decode(zclient->ibuf, &match, &route)) {
|
|
||||||
zlog_warn("BFD NHT update decode failure");
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
if (cmd != ZEBRA_NEXTHOP_UPDATE)
|
|
||||||
return 0;
|
|
||||||
|
|
||||||
if (bsglobal.debugging)
|
|
||||||
zlog_debug("BFD NHT update for %pFX", &route.prefix);
|
|
||||||
|
|
||||||
SLIST_FOREACH (source, &bsglobal.source_list, entry) {
|
SLIST_FOREACH (source, &bsglobal.source_list, entry) {
|
||||||
if (source->vrf_id != route.vrf_id)
|
if (source->vrf_id != route->vrf_id)
|
||||||
continue;
|
continue;
|
||||||
if (!prefix_same(&match, &source->address))
|
if (!prefix_same(match, &source->address))
|
||||||
continue;
|
continue;
|
||||||
if (bfd_source_cache_update(source, &route))
|
if (bfd_source_cache_update(source, route))
|
||||||
bfd_source_cache_update_sessions(source);
|
bfd_source_cache_update_sessions(source);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -473,6 +473,13 @@ extern bool bfd_protocol_integration_debug(void);
|
|||||||
*/
|
*/
|
||||||
extern bool bfd_protocol_integration_shutting_down(void);
|
extern bool bfd_protocol_integration_shutting_down(void);
|
||||||
|
|
||||||
|
/* Update nexthop-tracking (nht) information for BFD auto source selection.
|
||||||
|
* The function must be called from the daemon callback function
|
||||||
|
* that deals with the ZEBRA_NEXTHOP_UPDATE zclient command
|
||||||
|
*/
|
||||||
|
extern int bfd_nht_update(const struct prefix *match,
|
||||||
|
const struct zapi_route *route);
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
@ -211,6 +211,9 @@ static int static_zebra_nexthop_update(ZAPI_CALLBACK_ARGS)
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (zclient->bfd_integration)
|
||||||
|
bfd_nht_update(&matched, &nhr);
|
||||||
|
|
||||||
if (matched.family == AF_INET6)
|
if (matched.family == AF_INET6)
|
||||||
afi = AFI_IP6;
|
afi = AFI_IP6;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user