bfdd: add bfdname info when notify bfd status to PTM

Signed-off-by: wumu.zsl <wumu.zsl@alibaba-inc.com>
This commit is contained in:
wumu.zsl 2025-01-21 07:59:50 +00:00
parent 3548b3004d
commit 0ef6003167
3 changed files with 42 additions and 21 deletions

View file

@ -65,11 +65,11 @@ static int bp_raw_sbfd_red_send(int sd, uint8_t *data, size_t datalen, uint16_t
struct in6_addr *out_sip, struct in6_addr *sip,
struct in6_addr *dip, uint16_t src_port, uint16_t dst_port,
uint8_t seg_num, struct in6_addr *segment_list);
ssize_t bfd_recv_ipv4_fp(int sd, uint8_t *msgbuf, size_t msgbuflen,
uint8_t *ttl, ifindex_t *ifindex,
struct sockaddr_any *local, struct sockaddr_any *peer);
void bfd_peer_mac_set(int sd, struct bfd_session *bfd,
struct sockaddr_any *peer, struct interface *ifp);
static ssize_t bfd_recv_ipv4_fp(int sd, uint8_t *msgbuf, size_t msgbuflen, uint8_t *ttl,
ifindex_t *ifindex, struct sockaddr_any *local,
struct sockaddr_any *peer);
static void bfd_peer_mac_set(int sd, struct bfd_session *bfd, struct sockaddr_any *peer,
struct interface *ifp);
int bp_udp_send_fp(int sd, uint8_t *data, size_t datalen,
struct bfd_session *bfd);
ssize_t bfd_recv_fp_echo(int sd, uint8_t *msgbuf, size_t msgbuflen,
@ -470,9 +470,9 @@ void ptm_bfd_snd(struct bfd_session *bfd, int fbit)
/*
* receive the ipv4 echo packet that was loopback in the peers forwarding plane
*/
ssize_t bfd_recv_ipv4_fp(int sd, uint8_t *msgbuf, size_t msgbuflen,
uint8_t *ttl, ifindex_t *ifindex,
struct sockaddr_any *local, struct sockaddr_any *peer)
static ssize_t bfd_recv_ipv4_fp(int sd, uint8_t *msgbuf, size_t msgbuflen, uint8_t *ttl,
ifindex_t *ifindex, struct sockaddr_any *local,
struct sockaddr_any *peer)
{
ssize_t mlen;
struct sockaddr_ll msgaddr;
@ -1808,8 +1808,8 @@ int bp_echov6_socket(const struct vrf *vrf)
/* get peer's mac address to be used with Echo packets when they are looped in
* peers forwarding plane
*/
void bfd_peer_mac_set(int sd, struct bfd_session *bfd,
struct sockaddr_any *peer, struct interface *ifp)
static void bfd_peer_mac_set(int sd, struct bfd_session *bfd, struct sockaddr_any *peer,
struct interface *ifp)
{
struct arpreq arpreq_;

View file

@ -70,10 +70,10 @@ static void bfdd_client_deregister(struct stream *msg);
PRINTFRR(2, 3)
static void debug_printbpc(const struct bfd_peer_cfg *bpc, const char *fmt, ...)
{
char timers[3][128] = {};
char timers[3][160] = {};
char minttl_str[32] = {};
char addr[3][128] = {};
char profile[128] = {};
char addr[3][160] = {};
char profile[160] = {};
char cbit_str[32];
char msgbuf[512];
va_list vl;
@ -134,7 +134,9 @@ static void _ptm_bfd_session_del(struct bfd_session *bs, uint8_t diag)
/* Change state and notify peer. */
bs->ses_state = PTM_BFD_DOWN;
bs->local_diag = diag;
ptm_bfd_snd(bs, 0);
if (bs->bfd_mode == BFD_MODE_TYPE_BFD)
ptm_bfd_snd(bs, 0);
/* Session reached refcount == 0, lets delete it. */
if (bs->refcount == 0) {
@ -200,6 +202,8 @@ int ptm_bfd_notify(struct bfd_session *bs, uint8_t notify_state)
* - 16 bytes: ipv6
* - c: prefix length
* - c: cbit
* - c: bfd name len
* - Xbytes: bfd name
*
* Commands: ZEBRA_BFD_DEST_REPLAY
*
@ -238,9 +242,12 @@ int ptm_bfd_notify(struct bfd_session *bs, uint8_t notify_state)
case PTM_BFD_DOWN:
case PTM_BFD_INIT:
stream_putl(msg, BFD_STATUS_DOWN);
break;
if (CHECK_FLAG(bs->flags, BFD_SESS_FLAG_SHUTDOWN))
stream_putl(msg, BFD_STATUS_ADMIN_DOWN);
else
stream_putl(msg, BFD_STATUS_DOWN);
break;
default:
stream_putl(msg, BFD_STATUS_UNKNOWN);
break;
@ -251,6 +258,9 @@ int ptm_bfd_notify(struct bfd_session *bs, uint8_t notify_state)
stream_putc(msg, bs->remote_cbit);
stream_putc(msg, strlen(bs->bfd_name));
stream_put(msg, bs->bfd_name, strlen(bs->bfd_name));
/* Write packet size. */
stream_putw_at(msg, 0, stream_get_endp(msg));

View file

@ -18,6 +18,7 @@
#include "table.h"
#include "vty.h"
#include "bfd.h"
#include "bfdd/bfd.h"
DEFINE_MTYPE_STATIC(LIB, BFD_INFO, "BFD info");
DEFINE_MTYPE_STATIC(LIB, BFD_SOURCE, "BFD source cache");
@ -140,14 +141,15 @@ static void bfd_source_cache_put(struct bfd_session_params *session);
* bfd_get_peer_info - Extract the Peer information for which the BFD session
* went down from the message sent from Zebra to clients.
*/
static struct interface *bfd_get_peer_info(struct stream *s, struct prefix *dp,
struct prefix *sp, int *status,
int *remote_cbit, vrf_id_t vrf_id)
static struct interface *bfd_get_peer_info(struct stream *s, struct prefix *dp, struct prefix *sp,
int *status, int *remote_cbit, vrf_id_t vrf_id,
char *bfd_name)
{
unsigned int ifindex;
struct interface *ifp = NULL;
int plen;
int local_remote_cbit;
uint8_t bfd_name_len = 0;
/*
* If the ifindex lookup fails the
@ -194,6 +196,13 @@ static struct interface *bfd_get_peer_info(struct stream *s, struct prefix *dp,
STREAM_GETC(s, local_remote_cbit);
if (remote_cbit)
*remote_cbit = local_remote_cbit;
STREAM_GETC(s, bfd_name_len);
if (bfd_name_len) {
STREAM_GET(bfd_name, s, bfd_name_len);
*(bfd_name + bfd_name_len) = 0;
}
return ifp;
stream_failure:
@ -365,6 +374,7 @@ int zclient_bfd_command(struct zclient *zc, struct bfd_session_arg *args)
stream_putc(s, args->profilelen);
if (args->profilelen)
stream_put(s, args->profile, args->profilelen);
#else /* PTM BFD */
/* Encode timers if this is a registration message. */
if (args->command != ZEBRA_BFD_DEST_DEREGISTER) {
@ -742,6 +752,7 @@ void bfd_sess_install(struct bfd_session_params *bsp)
event_add_event(bsglobal.tm, _bfd_sess_send, bsp, 0, &bsp->installev);
}
void bfd_sess_uninstall(struct bfd_session_params *bsp)
{
bsp->lastev = BSE_UNINSTALL;
@ -918,6 +929,7 @@ int zclient_bfd_session_update(ZAPI_CALLBACK_ARGS)
struct prefix dp;
struct prefix sp;
char ifstr[128], cbitstr[32];
char bfd_name[BFD_NAME_SIZE + 1] = { 0 };
if (!zclient->bfd_integration)
return 0;
@ -926,8 +938,7 @@ int zclient_bfd_session_update(ZAPI_CALLBACK_ARGS)
if (bsglobal.shutting_down)
return 0;
ifp = bfd_get_peer_info(zclient->ibuf, &dp, &sp, &state, &remote_cbit,
vrf_id);
ifp = bfd_get_peer_info(zclient->ibuf, &dp, &sp, &state, &remote_cbit, vrf_id, bfd_name);
/*
* When interface lookup fails or an invalid stream is read, we must
* not proceed otherwise it will trigger an assertion while checking