From 95d90814e7503ebd755420ddf6082c5e71cfd0cb Mon Sep 17 00:00:00 2001 From: "wumu.zsl" Date: Tue, 7 Jan 2025 03:22:02 +0000 Subject: [PATCH] bfdd: format code style Signed-off-by: wumu.zsl --- bfdd/bfd.c | 211 +++++----- bfdd/bfd.h | 49 ++- bfdd/bfd_packet.c | 895 ++++++++++++++++++------------------------ bfdd/bfdd.c | 22 +- bfdd/bfdd_cli.c | 280 ++++++------- bfdd/bfdd_nb.c | 28 +- bfdd/bfdd_nb.h | 18 +- bfdd/bfdd_nb_config.c | 221 +++++------ bfdd/bfdd_nb_state.c | 14 +- bfdd/bfdd_vty.c | 194 ++++----- bfdd/event.c | 33 +- bfdd/ptm_adapter.c | 34 +- lib/bfd.c | 27 +- lib/bfd.h | 7 +- zebra/zebra_ptm.h | 11 +- 15 files changed, 889 insertions(+), 1155 deletions(-) diff --git a/bfdd/bfd.c b/bfdd/bfd.c index 51cdd01da18a..6662f5f7f36d 100644 --- a/bfdd/bfd.c +++ b/bfdd/bfd.c @@ -197,8 +197,7 @@ void bfd_session_apply(struct bfd_session *bs) } /* Toggle 'passive-mode' if default value. */ - if (bs->bfd_mode == BFD_MODE_TYPE_BFD) - { + if (bs->bfd_mode == BFD_MODE_TYPE_BFD) { if (bs->peer_profile.passive == false) bfd_set_passive_mode(bs, bp->passive); else @@ -230,9 +229,8 @@ void bfd_profile_remove(struct bfd_session *bs) bfd_session_apply(bs); } -void gen_bfd_key(struct bfd_key *key, struct sockaddr_any *peer, - struct sockaddr_any *local, bool mhop, const char *ifname, - const char *vrfname, const char *bfdname) +void gen_bfd_key(struct bfd_key *key, struct sockaddr_any *peer, struct sockaddr_any *local, + bool mhop, const char *ifname, const char *vrfname, const char *bfdname) { struct vrf *vrf = NULL; memset(key, 0, sizeof(*key)); @@ -257,25 +255,18 @@ void gen_bfd_key(struct bfd_key *key, struct sockaddr_any *peer, key->mhop = mhop; if (ifname && ifname[0]) strlcpy(key->ifname, ifname, sizeof(key->ifname)); - if (vrfname && vrfname[0] && strcmp(vrfname, VRF_DEFAULT_NAME) != 0) - { + if (vrfname && vrfname[0] && strcmp(vrfname, VRF_DEFAULT_NAME) != 0) { vrf = vrf_lookup_by_name(vrfname); - if (vrf) - { + if (vrf) { strlcpy(key->vrfname, vrf->name, sizeof(key->vrfname)); + } else { + strlcpy(key->vrfname, vrfname, sizeof(key->vrfname)); } - else - { - strlcpy(key->vrfname, vrfname, sizeof(key->vrfname)); - } - } - else - { + } else { strlcpy(key->vrfname, VRF_DEFAULT_NAME, sizeof(key->vrfname)); } - if (bfdname && bfdname[0]) - { + if (bfdname && bfdname[0]) { strlcpy(key->bfdname, bfdname, sizeof(key->bfdname)); } } @@ -285,8 +276,8 @@ struct bfd_session *bs_peer_find(struct bfd_peer_cfg *bpc) struct bfd_key key; /* Otherwise fallback to peer/local hash lookup. */ - gen_bfd_key(&key, &bpc->bpc_peer, &bpc->bpc_local, bpc->bpc_mhop, - bpc->bpc_localif, bpc->bpc_vrfname, bpc->bfd_name); + gen_bfd_key(&key, &bpc->bpc_peer, &bpc->bpc_local, bpc->bpc_mhop, bpc->bpc_localif, + bpc->bpc_vrfname, bpc->bfd_name); return bfd_key_lookup(key); } @@ -359,27 +350,21 @@ int bfd_session_enable(struct bfd_session *bs) * could use the destination port (3784) for the source * port we wouldn't need a socket per session. */ - if (bs->bfd_mode == BFD_MODE_TYPE_SBFD_ECHO - || bs->bfd_mode == BFD_MODE_TYPE_SBFD_INIT) - { + if (bs->bfd_mode == BFD_MODE_TYPE_SBFD_ECHO || bs->bfd_mode == BFD_MODE_TYPE_SBFD_INIT) { psock = bp_peer_srh_socketv6(bs); - if (psock <= 0){ + if (psock <= 0) { zlog_err("bp_peer_srh_socketv6 error"); return 0; } - } - else if (CHECK_FLAG(bs->flags, BFD_SESS_FLAG_IPV6) == 0) - { + } else if (CHECK_FLAG(bs->flags, BFD_SESS_FLAG_IPV6) == 0) { psock = bp_peer_socket(bs); - if (psock == -1){ + if (psock == -1) { zlog_err("bp_peer_socket error"); return 0; } - } - else - { + } else { psock = bp_peer_socketv6(bs); - if (psock == -1){ + if (psock == -1) { zlog_err("bp_peer_socketv6 error"); return 0; } @@ -393,17 +378,14 @@ int bfd_session_enable(struct bfd_session *bs) /* Only start timers if we are using active mode. */ if (CHECK_FLAG(bs->flags, BFD_SESS_FLAG_PASSIVE) == 0) { - if (bs->bfd_mode == BFD_MODE_TYPE_SBFD_ECHO) - { + if (bs->bfd_mode == BFD_MODE_TYPE_SBFD_ECHO) { /*enable receive echo response*/ bfd_set_echo(bs, true); bs->echo_detect_TO = (bs->remote_detect_mult * bs->echo_xmt_TO); sbfd_echo_recvtimer_update(bs); ptm_bfd_start_xmt_timer(bs, true); - } - else - { + } else { bfd_recvtimer_update(bs); ptm_bfd_start_xmt_timer(bs, false); } @@ -477,19 +459,17 @@ void ptm_bfd_start_xmt_timer(struct bfd_session *bfd, bool is_echo) jitter = (xmt_TO * (75 + (frr_weak_random() % maxpercent))) / 100; /* XXX remove that division above */ - if (bfd->bfd_mode == BFD_MODE_TYPE_SBFD_ECHO || bfd->bfd_mode == BFD_MODE_TYPE_SBFD_INIT) - { - if(is_echo) - sbfd_echo_xmttimer_update(bfd, jitter); + if (bfd->bfd_mode == BFD_MODE_TYPE_SBFD_ECHO || bfd->bfd_mode == BFD_MODE_TYPE_SBFD_INIT) { + if (is_echo) + sbfd_echo_xmttimer_update(bfd, jitter); else - sbfd_init_xmttimer_update(bfd, jitter); + sbfd_init_xmttimer_update(bfd, jitter); - }else{ - if(is_echo) + } else { + if (is_echo) bfd_echo_xmttimer_update(bfd, jitter); else bfd_xmttimer_update(bfd, jitter); - } } @@ -522,16 +502,16 @@ void ptm_bfd_xmt_TO(struct bfd_session *bfd, int fbit) } static void ptm_sbfd_echo_xmt_TO(struct bfd_session *bfd) -{ +{ /* Send the scheduled sbfd-echo packet */ ptm_sbfd_echo_snd(bfd); - + /* Restart the timer for next time */ ptm_bfd_start_xmt_timer(bfd, true); } void ptm_sbfd_init_xmt_TO(struct bfd_session *bfd, int fbit) -{ +{ /* Send the scheduled control packet */ ptm_sbfd_initiator_snd(bfd, fbit); @@ -577,7 +557,7 @@ void ptm_bfd_sess_up(struct bfd_session *bfd) bfd->local_diag = 0; bfd->ses_state = PTM_BFD_UP; - UNSET_FLAG(bfd->flags, BFD_SESS_FLAG_REM_ADMIN_DOWN); + UNSET_FLAG(bfd->flags, BFD_SESS_FLAG_REM_ADMIN_DOWN); monotime(&bfd->uptime); /* Connection is up, lets negotiate timers. */ @@ -647,7 +627,7 @@ void ptm_bfd_sess_dn(struct bfd_session *bfd, uint8_t diag) UNSET_FLAG(bfd->flags, BFD_SESS_FLAG_MAC_SET); memset(bfd->peer_hw_addr, 0, sizeof(bfd->peer_hw_addr)); /* reset local address ,it might has been be changed after bfd is up*/ - if(bfd->bfd_mode == BFD_MODE_TYPE_BFD) + if (bfd->bfd_mode == BFD_MODE_TYPE_BFD) memset(&bfd->local_address, 0, sizeof(bfd->local_address)); /* reset RTT */ @@ -660,18 +640,17 @@ void ptm_sbfd_sess_up(struct bfd_session *bfd) bfd->local_diag = 0; bfd->ses_state = PTM_BFD_UP; - UNSET_FLAG(bfd->flags, BFD_SESS_FLAG_REM_ADMIN_DOWN); + UNSET_FLAG(bfd->flags, BFD_SESS_FLAG_REM_ADMIN_DOWN); monotime(&bfd->uptime); - + /*notify session up*/ ptm_bfd_notify(bfd, bfd->ses_state); if (old_state != bfd->ses_state) { bfd->stats.session_up++; if (bglobal.debug_peer_event) - zlog_info("state-change: [%s] %s -> %s", - bs_to_string(bfd), state_list[old_state].str, - state_list[bfd->ses_state].str); + zlog_info("state-change: [%s] %s -> %s", bs_to_string(bfd), + state_list[old_state].str, state_list[bfd->ses_state].str); } } @@ -711,9 +690,8 @@ void ptm_sbfd_init_sess_dn(struct bfd_session *bfd, uint8_t diag) if (old_state != bfd->ses_state) { bfd->stats.session_down++; if (bglobal.debug_peer_event) - zlog_debug("state-change: [%s] %s -> %s reason:%s", - bs_to_string(bfd), state_list[old_state].str, - state_list[bfd->ses_state].str, + zlog_debug("state-change: [%s] %s -> %s reason:%s", bs_to_string(bfd), + state_list[old_state].str, state_list[bfd->ses_state].str, get_diag_str(bfd->local_diag)); } /* reset local address ,it might has been be changed after bfd is up*/ @@ -740,10 +718,9 @@ void ptm_sbfd_echo_sess_dn(struct bfd_session *bfd, uint8_t diag) if (old_state != bfd->ses_state) { bfd->stats.session_down++; if (bglobal.debug_peer_event) - zlog_warn("state-change: [%s] %s -> %s reason:%s", - bs_to_string(bfd), state_list[old_state].str, - state_list[bfd->ses_state].str, - get_diag_str(bfd->local_diag)); + zlog_warn("state-change: [%s] %s -> %s reason:%s", bs_to_string(bfd), + state_list[old_state].str, state_list[bfd->ses_state].str, + get_diag_str(bfd->local_diag)); } } static struct bfd_session *bfd_find_disc(struct sockaddr_any *sa, @@ -842,9 +819,9 @@ void bfd_echo_recvtimer_cb(struct event *t) { struct bfd_session *bs = EVENT_ARG(t); - if (bglobal.debug_peer_event){ - zlog_debug("%s: time-out bfd: [%s] bfd'state is %s", - __func__, bs_to_string(bs), state_list[bs->ses_state].str); + if (bglobal.debug_peer_event) { + zlog_debug("%s: time-out bfd: [%s] bfd'state is %s", __func__, bs_to_string(bs), + state_list[bs->ses_state].str); } switch (bs->ses_state) { @@ -875,15 +852,15 @@ void sbfd_echo_recvtimer_cb(struct event *t) { struct bfd_session *bs = EVENT_ARG(t); - if (bglobal.debug_peer_event){ - zlog_debug("%s: time-out bfd: [%s] bfd'state is %s", - __func__, bs_to_string(bs), state_list[bs->ses_state].str); + if (bglobal.debug_peer_event) { + zlog_debug("%s: time-out bfd: [%s] bfd'state is %s", __func__, bs_to_string(bs), + state_list[bs->ses_state].str); } switch (bs->ses_state) { case PTM_BFD_INIT: case PTM_BFD_UP: - ptm_sbfd_echo_sess_dn(bs, BD_SBFD_DETECT_FAILED); + ptm_sbfd_echo_sess_dn(bs, BD_SBFD_DETECT_FAILED); break; case PTM_BFD_DOWN: break; @@ -895,7 +872,8 @@ struct bfd_session *bfd_session_new(enum bfd_mode_type mode, uint8_t segnum) struct bfd_session *bs; //"sizeof(struct in6_addr)*segnum" increase extra mem for sbfd segments - bs = XCALLOC(MTYPE_BFDD_CONFIG, sizeof(struct bfd_session) + sizeof(struct in6_addr)*segnum); + bs = XCALLOC(MTYPE_BFDD_CONFIG, + sizeof(struct bfd_session) + sizeof(struct in6_addr) * segnum); bs->segnum = segnum; bs->bfd_mode = mode; @@ -1236,8 +1214,7 @@ static void sbfd_down_handler(struct bfd_session *bs, int nstate) default: if (bglobal.debug_peer_event) - zlog_err("state-change: unhandled sbfd state: %d", - nstate); + zlog_err("state-change: unhandled sbfd state: %d", nstate); break; } } @@ -1298,13 +1275,11 @@ static void sbfd_up_handler(struct bfd_session *bs, int nstate) switch (nstate) { case PTM_BFD_ADM_DOWN: case PTM_BFD_DOWN: - if (bs->bfd_mode == BFD_MODE_TYPE_SBFD_ECHO) - { + if (bs->bfd_mode == BFD_MODE_TYPE_SBFD_ECHO) { ptm_sbfd_echo_sess_dn(bs, BD_ECHO_FAILED); - } - else - ptm_sbfd_init_sess_dn(bs, BD_ECHO_FAILED); - + } else + ptm_sbfd_init_sess_dn(bs, BD_ECHO_FAILED); + break; case PTM_BFD_UP: @@ -1313,8 +1288,7 @@ static void sbfd_up_handler(struct bfd_session *bs, int nstate) default: if (bglobal.debug_peer_event) - zlog_debug("state-change: unhandled neighbor state: %d", - nstate); + zlog_debug("state-change: unhandled neighbor state: %d", nstate); break; } } @@ -1345,10 +1319,10 @@ void bs_state_handler(struct bfd_session *bs, int nstate) void sbfd_echo_state_handler(struct bfd_session *bs, int nstate) { - if (bglobal.debug_peer_event) - zlog_debug("%s: bfd(%u) state: %s , notify state: %s", - __func__, bs->discrs.my_discr, - state_list[bs->ses_state].str, state_list[nstate].str); + if (bglobal.debug_peer_event) + zlog_debug("%s: bfd(%u) state: %s , notify state: %s", __func__, + bs->discrs.my_discr, state_list[bs->ses_state].str, + state_list[nstate].str); switch (bs->ses_state) { case PTM_BFD_ADM_DOWN: @@ -1363,18 +1337,18 @@ void sbfd_echo_state_handler(struct bfd_session *bs, int nstate) default: if (bglobal.debug_peer_event) - zlog_debug("state-change: [%s] is in invalid state: %d", - bs_to_string(bs), nstate); + zlog_debug("state-change: [%s] is in invalid state: %d", bs_to_string(bs), + nstate); break; } } void sbfd_initiator_state_handler(struct bfd_session *bs, int nstate) { - if (bglobal.debug_peer_event) - zlog_debug("%s: sbfd(%u) state: %s , notify state: %s", - __func__, bs->discrs.my_discr, - state_list[bs->ses_state].str, state_list[nstate].str); + if (bglobal.debug_peer_event) + zlog_debug("%s: sbfd(%u) state: %s , notify state: %s", __func__, + bs->discrs.my_discr, state_list[bs->ses_state].str, + state_list[nstate].str); switch (bs->ses_state) { case PTM_BFD_ADM_DOWN: @@ -1389,8 +1363,8 @@ void sbfd_initiator_state_handler(struct bfd_session *bs, int nstate) default: if (bglobal.debug_peer_event) - zlog_debug("state-change: [%s] is in invalid state: %d", - bs_to_string(bs), nstate); + zlog_debug("state-change: [%s] is in invalid state: %d", bs_to_string(bs), + nstate); break; } } @@ -1499,7 +1473,7 @@ void bs_set_slow_timers(struct bfd_session *bs) bs->xmt_TO = BFD_DEF_SLOWTX; /* add for sbfd-echo slow connection */ - if (BFD_MODE_TYPE_SBFD_ECHO == bs->bfd_mode){ + if (BFD_MODE_TYPE_SBFD_ECHO == bs->bfd_mode) { bs->echo_xmt_TO = SBFD_ECHO_DEF_SLOWTX; bs->timers.desired_min_echo_tx = BFD_DEFDESIREDMINTX; bs->timers.required_min_echo_rx = BFD_DEFDESIREDMINTX; @@ -1798,8 +1772,7 @@ const char *bs_to_string(const struct bfd_session *bs) pos += snprintf(buf + pos, sizeof(buf) - pos, " ifname:%s", bs->key.ifname); if (bs->bfd_name[0]) - pos += snprintf(buf + pos, sizeof(buf) - pos, " bfd_name:%s", - bs->bfd_name); + pos += snprintf(buf + pos, sizeof(buf) - pos, " bfd_name:%s", bs->bfd_name); (void)pos; @@ -1933,8 +1906,7 @@ static bool bfd_key_hash_cmp(const void *n1, const void *n2) if (memcmp(bs1->key.vrfname, bs2->key.vrfname, sizeof(bs1->key.vrfname))) return false; - if (memcmp(bs1->key.bfdname, bs2->key.bfdname, - sizeof(bs1->key.bfdname))) + if (memcmp(bs1->key.bfdname, bs2->key.bfdname, sizeof(bs1->key.bfdname))) return false; /* @@ -2002,7 +1974,7 @@ struct sbfd_reflector *sbfd_discr_lookup(uint32_t discr) { struct sbfd_reflector sr; - sr.discr= discr; + sr.discr = discr; return hash_lookup(sbfd_rflt_hash, &sr); } @@ -2094,7 +2066,7 @@ void bfd_initialize(void) bfd_key_hash = hash_create(bfd_key_hash_do, bfd_key_hash_cmp, "BFD session hash"); sbfd_rflt_hash = hash_create(sbfd_discr_hash_do, sbfd_discr_hash_cmp, - "SBFD reflector discriminator hash"); + "SBFD reflector discriminator hash"); TAILQ_INIT(&bplist); } @@ -2106,11 +2078,10 @@ static void _bfd_free(struct hash_bucket *hb, bfd_session_free(bs); } -static void _sbfd_reflector_free(struct hash_bucket *hb, - void *arg __attribute__((__unused__))) +static void _sbfd_reflector_free(struct hash_bucket *hb, void *arg __attribute__((__unused__))) { struct sbfd_reflector *sr = hb->data; - + sbfd_reflector_free(sr->discr); } @@ -2169,7 +2140,8 @@ static int _bfd_session_next(struct hash_bucket *hb, void *arg) bsi->bsi_stop = 1; /* Set entry to NULL to signal end of list. */ bsi->bsi_bs = NULL; - } else if (bsi->bsi_bs == NULL && bsi->bsi_mhop == bs->key.mhop && bsi->bsi_bfdmode == bs->bfd_mode) { + } else if (bsi->bsi_bs == NULL && bsi->bsi_mhop == bs->key.mhop && + bsi->bsi_bfdmode == bs->bfd_mode) { /* We want the first list item. */ bsi->bsi_stop = 1; bsi->bsi_bs = hb->data; @@ -2184,8 +2156,8 @@ static int _bfd_session_next(struct hash_bucket *hb, void *arg) * * `bs` might point to NULL to get the first item of the data structure. */ -const struct bfd_session *bfd_session_next(const struct bfd_session *bs, - bool mhop, uint32_t bfd_mode) +const struct bfd_session *bfd_session_next(const struct bfd_session *bs, bool mhop, + uint32_t bfd_mode) { struct bfd_session_iterator bsi; @@ -2408,8 +2380,7 @@ static int bfd_vrf_enable(struct vrf *vrf) event_add_read(master, bfd_recv_cb, bvrf, bvrf->bg_mhop6, &bvrf->bg_ev[3]); if (bvrf->bg_ev[6] == NULL && bvrf->bg_initv6 != -1) - event_add_read(master, bfd_recv_cb, bvrf, bvrf->bg_initv6, - &bvrf->bg_ev[6]); + event_add_read(master, bfd_recv_cb, bvrf, bvrf->bg_initv6, &bvrf->bg_ev[6]); /* Toggle echo if VRF was disabled. */ bfd_vrf_toggle_echo(bvrf); @@ -2496,18 +2467,17 @@ struct sbfd_reflector *sbfd_reflector_new(const uint32_t discr, struct in6_addr { struct sbfd_reflector *sr; - sr = sbfd_discr_lookup(discr); + sr = sbfd_discr_lookup(discr); if (sr) - return sr; + return sr; sr = XCALLOC(MTYPE_SBFD_REFLECTOR, sizeof(*sr)); - sr->discr = discr; + sr->discr = discr; memcpy(&sr->local, sip, sizeof(struct in6_addr)); sbfd_discr_insert(sr); - return sr; } @@ -2515,12 +2485,12 @@ void sbfd_reflector_free(const uint32_t discr) { struct sbfd_reflector *sr; - sr = sbfd_discr_lookup(discr); + sr = sbfd_discr_lookup(discr); if (!sr) - return; + return; - sbfd_discr_delete(discr); - XFREE(MTYPE_SBFD_REFLECTOR, sr); + sbfd_discr_delete(discr); + XFREE(MTYPE_SBFD_REFLECTOR, sr); return; } @@ -2541,8 +2511,7 @@ static int _bfd_session_name_cmp(struct hash_bucket *hb, void *arg) struct bfd_session *bs = hb->data; struct bfd_session_name_match_unique *match = (struct bfd_session_name_match_unique *)arg; - if (strlen(bs->bfd_name) != strlen(match->bfd_name)) - { + if (strlen(bs->bfd_name) != strlen(match->bfd_name)) { return HASHWALK_CONTINUE; } @@ -2550,18 +2519,18 @@ static int _bfd_session_name_cmp(struct hash_bucket *hb, void *arg) match->bfd_found = bs; return HASHWALK_ABORT; } - return HASHWALK_CONTINUE; + return HASHWALK_CONTINUE; } -struct bfd_session * bfd_session_get_by_name(const char * name) +struct bfd_session *bfd_session_get_by_name(const char *name) { if (!name || name[0] == '\0') return NULL; - struct bfd_session_name_match_unique match; + struct bfd_session_name_match_unique match; match.bfd_name = name; match.bfd_found = NULL; - + hash_walk(bfd_key_hash, _bfd_session_name_cmp, &match); return match.bfd_found; diff --git a/bfdd/bfd.h b/bfdd/bfd.h index d2abddc9d963..2e23e3e847f6 100644 --- a/bfdd/bfd.h +++ b/bfdd/bfd.h @@ -90,9 +90,9 @@ struct bfd_peer_cfg { bool bpc_has_profile; char bpc_profile[64]; - vrf_id_t vrf_id; - char bfd_name[BFD_NAME_SIZE +1]; - uint8_t bfd_name_len; + vrf_id_t vrf_id; + char bfd_name[BFD_NAME_SIZE + 1]; + uint8_t bfd_name_len; }; /* bfd Authentication Type. */ @@ -154,7 +154,7 @@ struct bfd_echo_pkt { uint64_t time_sent_usec; }; -#define BFD_XMTDEL_DELAY_TIMER 5 +#define BFD_XMTDEL_DELAY_TIMER 5 /* Macros for manipulating control packets */ #define BFD_VERMASK 0x07 @@ -202,8 +202,8 @@ struct bfd_echo_pkt { #define BFD_ECHO_VERSION 1 #define BFD_ECHO_PKT_LEN sizeof(struct bfd_echo_pkt) -#define RTH_BASE_HEADER_LEN 8 -#define GET_RTH_HDR_LEN(size) (((size)>>3) - 1) +#define RTH_BASE_HEADER_LEN 8 +#define GET_RTH_HDR_LEN(size) (((size) >> 3) - 1) enum bfd_diagnosticis { BD_OK = 0, /* Control Detection Time Expired. */ @@ -230,21 +230,21 @@ enum bfd_diagnosticis { /* BFD session flags */ enum bfd_session_flags { BFD_SESS_FLAG_NONE = 0, - BFD_SESS_FLAG_ECHO = 1 << 0, /* BFD Echo functionality */ - BFD_SESS_FLAG_ECHO_ACTIVE = 1 << 1, /* BFD Echo Packets are being sent + BFD_SESS_FLAG_ECHO = 1 << 0, /* BFD Echo functionality */ + BFD_SESS_FLAG_ECHO_ACTIVE = 1 << 1, /* BFD Echo Packets are being sent * actively */ - BFD_SESS_FLAG_MH = 1 << 2, /* BFD Multi-hop session */ - BFD_SESS_FLAG_IPV6 = 1 << 4, /* BFD IPv6 session */ + BFD_SESS_FLAG_MH = 1 << 2, /* BFD Multi-hop session */ + BFD_SESS_FLAG_IPV6 = 1 << 4, /* BFD IPv6 session */ BFD_SESS_FLAG_SEND_EVT_ACTIVE = 1 << 5, /* send event timer active */ BFD_SESS_FLAG_SEND_EVT_IGNORE = 1 << 6, /* ignore send event when timer * expires */ BFD_SESS_FLAG_SHUTDOWN = 1 << 7, /* disable BGP peer function */ - BFD_SESS_FLAG_CONFIG = 1 << 8, /* Session configured with bfd NB API */ - BFD_SESS_FLAG_CBIT = 1 << 9, /* CBIT is set */ - BFD_SESS_FLAG_PASSIVE = 1 << 10, /* Passive mode */ - BFD_SESS_FLAG_MAC_SET = 1 << 11, /* MAC of peer known */ + BFD_SESS_FLAG_CONFIG = 1 << 8, /* Session configured with bfd NB API */ + BFD_SESS_FLAG_CBIT = 1 << 9, /* CBIT is set */ + BFD_SESS_FLAG_PASSIVE = 1 << 10, /* Passive mode */ + BFD_SESS_FLAG_MAC_SET = 1 << 11, /* MAC of peer known */ BFD_SESS_FLAG_REM_ADMIN_DOWN = 1 << 13, /* remote notify admindown */ }; @@ -396,7 +396,7 @@ struct bfd_session { uint8_t rtt_valid; /* number of valid samples */ uint8_t rtt_index; /* last index added */ uint64_t rtt[BFD_RTT_SAMPLE]; /* RRT in usec for echo to be looped */ - char bfd_name[BFD_NAME_SIZE +1]; + char bfd_name[BFD_NAME_SIZE + 1]; uint32_t bfd_mode; uint8_t segnum; @@ -424,7 +424,7 @@ struct bfd_session_observer { TAILQ_HEAD(obslist, bfd_session_observer); /*sbfd reflector struct*/ -struct sbfd_reflector{ +struct sbfd_reflector { uint32_t discr; struct in6_addr local; }; @@ -445,7 +445,7 @@ struct sbfd_reflector{ #define BFD_DEF_DES_MIN_ECHO_TX (50 * 1000) /* microseconds. */ #define BFD_DEF_REQ_MIN_ECHO_RX (50 * 1000) /* microseconds. */ #define BFD_DEF_SLOWTX (1000 * 1000) /* microseconds. */ -#define SBFD_ECHO_DEF_SLOWTX (3000 * 1000) /* microseconds. */ +#define SBFD_ECHO_DEF_SLOWTX (3000 * 1000) /* microseconds. */ /** Minimum multi hop TTL. */ #define BFD_DEF_MHOP_TTL 254 #define BFD_PKT_LEN 24 /* Length of control packet */ @@ -462,9 +462,9 @@ struct sbfd_reflector{ #define BFD_DEF_MHOP_DEST_PORT 4784 #define BFD_DEF_SBFD_DEST_PORT 7784 -#define BFD_SBFD_INITIATOR_DEMAND 1 +#define BFD_SBFD_INITIATOR_DEMAND 1 #define BFD_IPV6_UDP_DISABLE_CHECKSUM 1 -#define UDP_NO_CHECK6_RX 102 +#define UDP_NO_CHECK6_RX 102 /* * bfdd.c @@ -655,16 +655,15 @@ void bs_observer_del(struct bfd_session_observer *bso); void bs_to_bpc(struct bfd_session *bs, struct bfd_peer_cfg *bpc); -void gen_bfd_key(struct bfd_key *key, struct sockaddr_any *peer, - struct sockaddr_any *local, bool mhop, const char *ifname, - const char *vrfname, const char *bfdname); +void gen_bfd_key(struct bfd_key *key, struct sockaddr_any *peer, struct sockaddr_any *local, + bool mhop, const char *ifname, const char *vrfname, const char *bfdname); struct bfd_session *bfd_session_new(enum bfd_mode_type mode, uint8_t segnum); struct bfd_session *bs_registrate(struct bfd_session *bs); void bfd_session_free(struct bfd_session *bs); -const struct bfd_session *bfd_session_next(const struct bfd_session *bs, - bool mhop, uint32_t bfd_mode); +const struct bfd_session *bfd_session_next(const struct bfd_session *bs, bool mhop, + uint32_t bfd_mode); void bfd_sessions_remove_manual(void); void bfd_profiles_remove(void); void bs_sbfd_echo_timer_handler(struct bfd_session *bs); @@ -890,5 +889,5 @@ void ptm_sbfd_sess_up(struct bfd_session *bfd); void sbfd_echo_state_handler(struct bfd_session *bs, int nstate); void sbfd_initiator_state_handler(struct bfd_session *bs, int nstate); -struct bfd_session * bfd_session_get_by_name(const char * name); +struct bfd_session *bfd_session_get_by_name(const char *name); #endif /* _BFD_H_ */ diff --git a/bfdd/bfd_packet.c b/bfdd/bfd_packet.c index 1373cb8c96d4..02f4c9d95c92 100644 --- a/bfdd/bfd_packet.c +++ b/bfdd/bfd_packet.c @@ -33,7 +33,7 @@ #include "lib/network.h" #include "bfd.h" -#define BUF_SIZ 1024 +#define BUF_SIZ 1024 #define SOCK_OPT_PRIO_HIGH 6 /* * Prototypes @@ -55,22 +55,19 @@ int bp_bfd_echo_in(struct bfd_vrf_global *bvrf, int sd, uint8_t *ttl, uint32_t *my_discr, uint64_t *my_rtt); static int ptm_bfd_reflector_process_init_packet(struct bfd_vrf_global *bvrf, int s); -int _ptm_sbfd_init_send(struct bfd_session *bs, const void *data, size_t datalen); -int _ptm_sbfd_echo_send(struct bfd_session *bfd, const void *data, size_t datalen); -int bp_raw_sbfd_send(int sd, uint8_t *data, size_t datalen, 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); -int bp_raw_sbfd_red_send(int sd, uint8_t *data, size_t datalen, - uint16_t family, 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); - +int _ptm_sbfd_init_send(struct bfd_session *bs, const void *data, size_t datalen); + +static int bp_raw_sbfd_red_send(int sd, uint8_t *data, size_t datalen, uint16_t family, + 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); + #ifdef BFD_LINUX 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 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, @@ -391,11 +388,10 @@ static int ptm_bfd_process_echo_pkt(struct bfd_vrf_global *bvrf, int s) bfd->echo_detect_TO = bfd->remote_detect_mult * bfd->echo_xmt_TO; /* Update sbfd-echo session state */ - if (bfd->bfd_mode == BFD_MODE_TYPE_SBFD_ECHO){ + if (bfd->bfd_mode == BFD_MODE_TYPE_SBFD_ECHO) { sbfd_echo_state_handler(bfd, PTM_BFD_UP); - if(bfd->echo_xmt_TO != bfd->timers.desired_min_echo_tx) - { + if (bfd->echo_xmt_TO != bfd->timers.desired_min_echo_tx) { bfd->echo_xmt_TO = bfd->timers.desired_min_echo_tx; //reset xmt timer TO after UP ptm_bfd_start_xmt_timer(bfd, true); @@ -763,11 +759,9 @@ static void bfd_sd_reschedule(struct bfd_vrf_global *bvrf, int sd) EVENT_OFF(bvrf->bg_ev[5]); event_add_read(master, bfd_recv_cb, bvrf, bvrf->bg_echov6, &bvrf->bg_ev[5]); - } - else if (sd == bvrf->bg_initv6) { + } else if (sd == bvrf->bg_initv6) { EVENT_OFF(bvrf->bg_ev[6]); - event_add_read(master, bfd_recv_cb, bvrf, bvrf->bg_initv6, - &bvrf->bg_ev[6]); + event_add_read(master, bfd_recv_cb, bvrf, bvrf->bg_initv6, &bvrf->bg_ev[6]); } } @@ -862,7 +856,7 @@ void bfd_recv_cb(struct event *t) bfd_sd_reschedule(bvrf, sd); /* The reflector handle SBFD init packets. */ - if(sd == bvrf->bg_initv6){ + if (sd == bvrf->bg_initv6) { ptm_bfd_reflector_process_init_packet(bvrf, sd); return; } @@ -1041,10 +1035,9 @@ void bfd_recv_cb(struct event *t) bfd->remote_cbit = 0; /* The initiator handle SBFD reflect packet. */ - if (bfd->bfd_mode == BFD_MODE_TYPE_SBFD_INIT){ + if (bfd->bfd_mode == BFD_MODE_TYPE_SBFD_INIT) { sbfd_initiator_state_handler(bfd, PTM_BFD_UP); - if(bfd->xmt_TO != bfd->timers.desired_min_tx) - { + if (bfd->xmt_TO != bfd->timers.desired_min_tx) { bfd->xmt_TO = bfd->timers.desired_min_tx; //reset xmt timer TO after UP ptm_bfd_start_xmt_timer(bfd, false); @@ -1061,7 +1054,7 @@ void bfd_recv_cb(struct event *t) bfd->cur_timers.required_min_rx = bfd->timers.required_min_rx; } - return ; + return; } /* State switch from section 6.2. */ @@ -1424,9 +1417,8 @@ void bp_set_prio(int sd, int value) { int priority = value; - if (setsockopt(sd, SOL_SOCKET, SO_PRIORITY, &priority, sizeof(priority)) < 0) { + if (setsockopt(sd, SOL_SOCKET, SO_PRIORITY, &priority, sizeof(priority)) < 0) zlog_warn("set_prio: setsockopt(SO_PRIORITY, %d): %s", value, strerror(errno)); - } } int bp_udp_shop(const struct vrf *vrf) @@ -1814,8 +1806,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_; @@ -1858,40 +1850,45 @@ int _ptm_sbfd_init_send(struct bfd_session *bfd, const void *data, size_t datale struct bfd_vrf_global *bvrf = bfd_vrf_look_by_session(bfd); int seg_num; - struct in6_addr* segment_list = NULL; + struct in6_addr *segment_list = NULL; struct in6_addr peer; struct in6_addr local; if (!bvrf) return -1; - seg_num = bfd->segnum; + seg_num = bfd->segnum; if (seg_num > 0) - segment_list = bfd->seg_list; + segment_list = bfd->seg_list; sd = bfd->sock; local = bfd->key.local; - peer = bfd->key.peer; - - /*SBFD Control pkt dst port should be 7784, src port can be any but NOT 7784 according to RFC7781 */ - if (bp_raw_sbfd_red_send(sd, (uint8_t *)data, datalen, bfd->key.family, &bfd->out_sip6, &local, &peer, - BFD_DEF_MHOP_DEST_PORT, BFD_DEF_SBFD_DEST_PORT, seg_num, segment_list) < 0) - { - if(bfd->stats.tx_fail_pkt <= 1){ - char dst[INET6_ADDRSTRLEN] = {0}; - inet_ntop(AF_INET6, seg_num > 0?segment_list: (&bfd->key.peer), dst, sizeof(dst)); - zlog_err("sbfd initiator send failed, dst:%s, errno:%s", dst, safe_strerror(errno)); + peer = bfd->key.peer; + + /*SBFD Control pkt dst port should be 7784, src port can be any but NOT 7784 according to RFC7781 */ + if (bp_raw_sbfd_red_send(sd, (uint8_t *)data, datalen, bfd->key.family, &bfd->out_sip6, + &local, &peer, BFD_DEF_MHOP_DEST_PORT, BFD_DEF_SBFD_DEST_PORT, + seg_num, segment_list) < 0) { + if (bfd->stats.tx_fail_pkt <= 1) { + char dst[INET6_ADDRSTRLEN] = { 0 }; + + inet_ntop(AF_INET6, seg_num > 0 ? segment_list : (&bfd->key.peer), dst, + sizeof(dst)); + zlog_err("sbfd initiator send failed, dst:%s, errno:%s", dst, + safe_strerror(errno)); } bfd->stats.tx_fail_pkt++; - return -1; + return -1; } - if(bfd->stats.tx_fail_pkt > 0){ - char dst[INET6_ADDRSTRLEN] = {0}; - inet_ntop(AF_INET6, seg_num > 0?segment_list: (&bfd->key.peer), dst, sizeof(dst)); - zlog_warn("sbfd initiator send success, dst:%s, previous tx_fail_pkt:%d", dst, (int)bfd->stats.tx_fail_pkt); + if (bfd->stats.tx_fail_pkt > 0) { + char dst[INET6_ADDRSTRLEN] = { 0 }; + + inet_ntop(AF_INET6, seg_num > 0 ? segment_list : (&bfd->key.peer), dst, sizeof(dst)); + zlog_warn("sbfd initiator send success, dst:%s, previous tx_fail_pkt:%d", dst, + (int)bfd->stats.tx_fail_pkt); } bfd->stats.tx_fail_pkt = 0; @@ -1899,45 +1896,50 @@ int _ptm_sbfd_init_send(struct bfd_session *bfd, const void *data, size_t datale return 0; } -int _ptm_sbfd_echo_send(struct bfd_session *bfd, const void *data, size_t datalen) +static int _ptm_sbfd_echo_send(struct bfd_session *bfd, const void *data, size_t datalen) { int sd = -1; struct bfd_vrf_global *bvrf = bfd_vrf_look_by_session(bfd); int seg_num; - struct in6_addr* segment_list = NULL; + struct in6_addr *segment_list = NULL; struct in6_addr peer; struct in6_addr local; if (!bvrf) return -1; - seg_num = bfd->segnum; + seg_num = bfd->segnum; if (seg_num > 0) - segment_list = bfd->seg_list; + segment_list = bfd->seg_list; sd = bfd->sock; - local = bfd->key.local; - peer = bfd->key.peer; + local = bfd->key.local; + peer = bfd->key.peer; /*SBFD echo pkt dst port should use BFD Echo port 3785, src port can be any according to RFC7781*/ - if (bp_raw_sbfd_red_send(sd, (uint8_t *)data, datalen, bfd->key.family, &bfd->out_sip6, &local , &peer, - BFD_DEF_ECHO_PORT, BFD_DEF_ECHO_PORT, seg_num, segment_list) < 0) - { - if(bfd->stats.tx_fail_pkt <= 1){ - char dst[INET6_ADDRSTRLEN] = {0}; - inet_ntop(AF_INET6, seg_num > 0?segment_list: (&bfd->key.peer), dst, sizeof(dst)); - zlog_err("sbfd echo send failed, bfd_name:%s, dst:%s, errno:%s", bfd->bfd_name, dst, safe_strerror(errno)); + if (bp_raw_sbfd_red_send(sd, (uint8_t *)data, datalen, bfd->key.family, &bfd->out_sip6, + &local, &peer, BFD_DEF_ECHO_PORT, BFD_DEF_ECHO_PORT, seg_num, + segment_list) < 0) { + if (bfd->stats.tx_fail_pkt <= 1) { + char dst[INET6_ADDRSTRLEN] = { 0 }; + + inet_ntop(AF_INET6, seg_num > 0 ? segment_list : (&bfd->key.peer), dst, + sizeof(dst)); + zlog_err("sbfd echo send failed, bfd_name:%s, dst:%s, errno:%s", + bfd->bfd_name, dst, safe_strerror(errno)); } bfd->stats.tx_fail_pkt++; - return -1; + return -1; } - if(bfd->stats.tx_fail_pkt > 0){ - char dst[INET6_ADDRSTRLEN] = {0}; - inet_ntop(AF_INET6, seg_num > 0?segment_list: (&bfd->key.peer), dst, sizeof(dst)); - zlog_warn("sbfd echo send success, bfd_name:%s, dst:%s, previous tx_fail_pkt:%d", bfd->bfd_name, dst, (int)bfd->stats.tx_fail_pkt); + if (bfd->stats.tx_fail_pkt > 0) { + char dst[INET6_ADDRSTRLEN] = { 0 }; + + inet_ntop(AF_INET6, seg_num > 0 ? segment_list : (&bfd->key.peer), dst, sizeof(dst)); + zlog_warn("sbfd echo send success, bfd_name:%s, dst:%s, previous tx_fail_pkt:%d", + bfd->bfd_name, dst, (int)bfd->stats.tx_fail_pkt); } bfd->stats.tx_fail_pkt = 0; @@ -1974,8 +1976,7 @@ void ptm_sbfd_initiator_snd(struct bfd_session *bfd, int fbit) cp.discrs.my_discr = htonl(bfd->discrs.my_discr); cp.discrs.remote_discr = htonl(bfd->discrs.remote_discr); if (bfd->polling) { - cp.timers.desired_min_tx = - htonl(bfd->timers.desired_min_tx); + cp.timers.desired_min_tx = htonl(bfd->timers.desired_min_tx); } else { /* * We can only announce current setting on poll, this @@ -1983,8 +1984,7 @@ void ptm_sbfd_initiator_snd(struct bfd_session *bfd, int fbit) * the oportunity to learn. See `bs_final_handler` for * more information. */ - cp.timers.desired_min_tx = - htonl(bfd->cur_timers.desired_min_tx); + cp.timers.desired_min_tx = htonl(bfd->cur_timers.desired_min_tx); } cp.timers.required_min_rx = 0; cp.timers.required_min_echo = 0; @@ -1997,14 +1997,14 @@ void ptm_sbfd_initiator_snd(struct bfd_session *bfd, int fbit) void ptm_sbfd_echo_snd(struct bfd_session *bfd) { struct bfd_echo_pkt bep; - + memset(&bep, 0, sizeof(bep)); BFD_SETVER(bep.ver, BFD_ECHO_VERSION); bep.len = BFD_ECHO_PKT_LEN; bep.my_discr = htonl(bfd->discrs.my_discr); - if (_ptm_sbfd_echo_send(bfd, &bep, BFD_ECHO_PKT_LEN) != 0) - return; + if (_ptm_sbfd_echo_send(bfd, &bep, BFD_ECHO_PKT_LEN) != 0) + return; if (!CHECK_FLAG(bfd->flags, BFD_SESS_FLAG_ECHO_ACTIVE)) SET_FLAG(bfd->flags, BFD_SESS_FLAG_ECHO_ACTIVE); @@ -2025,46 +2025,39 @@ static int ptm_bfd_reflector_process_init_packet(struct bfd_vrf_global *bvrf, in //vrf_id_t vrfid = VRF_DEFAULT; uint8_t msgbuf[1516]; - rlen = bfd_recv_ipv6(sd, msgbuf, sizeof(msgbuf), &ttl, &ifindex, - &local, &peer); + rlen = bfd_recv_ipv6(sd, msgbuf, sizeof(msgbuf), &ttl, &ifindex, &local, &peer); /* Short packet, better not risk reading it. */ - if (rlen < (ssize_t)sizeof(*cp)) - { + if (rlen < (ssize_t)sizeof(*cp)) { zlog_debug("small bfd packet"); return 0; } cp = (struct bfd_pkt *)(msgbuf); - if(!CHECK_FLAG(cp->flags, BFD_DEMANDBIT)){ + if (!CHECK_FLAG(cp->flags, BFD_DEMANDBIT)) { /*Control Packet from SBFDInitiator should have Demand bit set to 1 according to RFC7880*/ return 0; } sr = sbfd_discr_lookup(ntohl(cp->discrs.remote_discr)); - if(sr) - { + if (sr) { uint32_t temp = cp->discrs.my_discr; + cp->discrs.my_discr = cp->discrs.remote_discr; cp->discrs.remote_discr = temp; UNSET_FLAG(cp->flags, BFD_DEMANDBIT); BFD_SETSTATE(cp->flags, PTM_BFD_UP); - if(CHECK_FLAG(cp->flags, BFD_PBIT)) - { + if (CHECK_FLAG(cp->flags, BFD_PBIT)) { UNSET_FLAG(cp->flags, BFD_PBIT); SET_FLAG(cp->flags, BFD_FBIT); } sa = (struct sockaddr *)&peer.sa_sin6; - if (sendto(sd, msgbuf, rlen, 0, sa, sizeof(peer.sa_sin6)) <= 0) - { - zlog_debug("packet-send: send failure: %s", - strerror(errno)); + if (sendto(sd, msgbuf, rlen, 0, sa, sizeof(peer.sa_sin6)) <= 0) { + zlog_debug("packet-send: send failure: %s", strerror(errno)); return -1; } - } - else - { - zlog_debug("no reflector found in %u",cp->discrs.remote_discr); + } else { + zlog_debug("no reflector found in %u", cp->discrs.remote_discr); } return 0; } @@ -2077,25 +2070,21 @@ int bp_peer_srh_socketv6(struct bfd_session *bs) const char *device_to_bind = NULL; int on = 1; - if (bs->key.ifname[0]){ + if (bs->key.ifname[0]) { device_to_bind = (const char *)bs->key.ifname; zlog_debug("device_to_bind to ifname:%s", device_to_bind); - } - else if (CHECK_FLAG(bs->flags, BFD_SESS_FLAG_MH) - && bs->key.vrfname[0]){ + } else if (CHECK_FLAG(bs->flags, BFD_SESS_FLAG_MH) && bs->key.vrfname[0]) { device_to_bind = (const char *)bs->key.vrfname; zlog_debug("device_to_bind to vrf:%s", device_to_bind); - }else{ - zlog_debug("device_to_bind to NULL"); + } else { + zlog_debug("device_to_bind to NULL"); } - frr_with_privs(&bglobal.bfdd_privs) { - sd = vrf_socket(AF_INET6, SOCK_RAW, IPPROTO_RAW, - bs->vrf->vrf_id, device_to_bind); + frr_with_privs (&bglobal.bfdd_privs) { + sd = vrf_socket(AF_INET6, SOCK_RAW, IPPROTO_RAW, bs->vrf->vrf_id, device_to_bind); } if (sd == -1) { - zlog_err("ipv6-new: failed to create socket: %s", - strerror(errno)); + zlog_err("ipv6-new: failed to create socket: %s", strerror(errno)); return -1; } @@ -2111,9 +2100,9 @@ int bp_peer_srh_socketv6(struct bfd_session *bs) return -1; } - /*manage the IP6 header all on own onwn*/ - if (setsockopt(sd, IPPROTO_IPV6, IPV6_HDRINCL, &on, sizeof(on))){ - zlog_err("setsockopt IPV6_HDRINCL error: %s", strerror(errno)); + /*manage the IP6 header all on own onwn*/ + if (setsockopt(sd, IPPROTO_IPV6, IPV6_HDRINCL, &on, sizeof(on))) { + zlog_err("setsockopt IPV6_HDRINCL error: %s", strerror(errno)); close(sd); return -1; } @@ -2124,13 +2113,13 @@ int bp_peer_srh_socketv6(struct bfd_session *bs) int bp_initv6_socket(const struct vrf *vrf) { int sd; - frr_with_privs(&bglobal.bfdd_privs) { + + frr_with_privs (&bglobal.bfdd_privs) { sd = vrf_socket(AF_INET6, SOCK_DGRAM, 0, vrf->vrf_id, vrf->name); } if (sd == -1) { if (errno != EAFNOSUPPORT) - zlog_fatal("echov6-socket: socket: %s", - strerror(errno)); + zlog_fatal("echov6-socket: socket: %s", strerror(errno)); else zlog_warn("echov6-socket: V6 is not supported, continuing"); @@ -2143,185 +2132,191 @@ int bp_initv6_socket(const struct vrf *vrf) return sd; } -static uint16_t -checksum (uint16_t *addr, int len) { +static uint16_t checksum(uint16_t *addr, int len) +{ + int count = len; + uint16_t answer = 0; - int count = len; - register uint32_t sum = 0; - uint16_t answer = 0; + register uint32_t sum = 0; - // Sum up 2-byte values until none or only one byte left. - while (count > 1) { - sum += *(addr++); - count -= 2; - } + // Sum up 2-byte values until none or only one byte left. + while (count > 1) { + sum += *(addr++); + count -= 2; + } - // Add left-over byte, if any. - if (count > 0) { - sum += *(uint8_t *) addr; - } + // Add left-over byte, if any. + if (count > 0) + sum += *(uint8_t *)addr; - // Fold 32-bit sum into 16 bits; we lose information by doing this, - // increasing the chances of a collision. - // sum = (lower 16 bits) + (upper 16 bits shifted right 16 bits) - while (sum >> 16) { - sum = (sum & 0xffff) + (sum >> 16); - } + // Fold 32-bit sum into 16 bits; we lose information by doing this, + // increasing the chances of a collision. + // sum = (lower 16 bits) + (upper 16 bits shifted right 16 bits) + while (sum >> 16) + sum = (sum & 0xffff) + (sum >> 16); - // Checksum is one's compliment of sum. - answer = ~sum; + // Checksum is one's compliment of sum. + answer = ~sum; - return (answer); + return answer; } -static uint16_t -udp6_checksum (struct ip6_hdr iphdr, struct udphdr udphdr, uint8_t *payload, int payloadlen) { - - char buf[IP_MAXPACKET]; - char *ptr; - int chksumlen = 0; - int i; - - ptr = &buf[0]; // ptr points to beginning of buffer buf - - // Copy source IP address into buf (128 bits) - memcpy (ptr, &iphdr.ip6_src.s6_addr, sizeof (iphdr.ip6_src.s6_addr)); - ptr += sizeof (iphdr.ip6_src.s6_addr); - chksumlen += sizeof (iphdr.ip6_src.s6_addr); - - // Copy destination IP address into buf (128 bits) - memcpy (ptr, &iphdr.ip6_dst.s6_addr, sizeof (iphdr.ip6_dst.s6_addr)); - ptr += sizeof (iphdr.ip6_dst.s6_addr); - chksumlen += sizeof (iphdr.ip6_dst.s6_addr); - - // Copy UDP length into buf (32 bits) - memcpy (ptr, &udphdr.len, sizeof (udphdr.len)); - ptr += sizeof (udphdr.len); - chksumlen += sizeof (udphdr.len); - - // Copy zero field to buf (24 bits) - *ptr = 0; ptr++; - *ptr = 0; ptr++; - *ptr = 0; ptr++; - chksumlen += 3; - - // Copy next header field to buf (8 bits) - memcpy (ptr, &iphdr.ip6_nxt, sizeof (iphdr.ip6_nxt)); - ptr += sizeof (iphdr.ip6_nxt); - chksumlen += sizeof (iphdr.ip6_nxt); - - // Copy UDP source port to buf (16 bits) - memcpy (ptr, &udphdr.source, sizeof (udphdr.source)); - ptr += sizeof (udphdr.source); - chksumlen += sizeof (udphdr.source); - - // Copy UDP destination port to buf (16 bits) - memcpy (ptr, &udphdr.dest, sizeof (udphdr.dest)); - ptr += sizeof (udphdr.dest); - chksumlen += sizeof (udphdr.dest); - - // Copy UDP length again to buf (16 bits) - memcpy (ptr, &udphdr.len, sizeof (udphdr.len)); - ptr += sizeof (udphdr.len); - chksumlen += sizeof (udphdr.len); - - // Copy UDP checksum to buf (16 bits) - // Zero, since we don't know it yet - *ptr = 0; ptr++; - *ptr = 0; ptr++; - chksumlen += 2; - - // Copy payload to buf - memcpy (ptr, payload, payloadlen * sizeof (uint8_t)); - ptr += payloadlen; - chksumlen += payloadlen; - - // Pad to the next 16-bit boundary - for (i=0; ivrf_id, vrf->name); } if (s == -1) { @@ -2338,321 +2333,216 @@ int bp_sbfd_socket(const struct vrf *vrf) return s; } -static void bp_sbfd_encap_srh_ip6h(struct ip6_hdr* srh_ip6h, - struct in6_addr* sip , struct in6_addr* dip ,uint8_t seg_num, size_t datalen) +static void bp_sbfd_encap_srh_ip6h(struct ip6_hdr *srh_ip6h, struct in6_addr *sip, + struct in6_addr *dip, uint8_t seg_num, size_t datalen) { - /* SRH IPv6 Header */ - srh_ip6h->ip6_flow = 0; - srh_ip6h->ip6_vfc = 6 << 4; - srh_ip6h->ip6_plen = htons(sizeof(struct ip6_hdr) - + sizeof(struct udphdr) - + sizeof(struct ipv6_sr_hdr) - + sizeof(struct in6_addr) * seg_num - + datalen); - srh_ip6h->ip6_nxt = IPPROTO_ROUTING; - srh_ip6h->ip6_hlim = BFD_TTL_VAL; - - memcpy(&(srh_ip6h->ip6_src), sip, sizeof(struct in6_addr)); + /* SRH IPv6 Header */ + srh_ip6h->ip6_flow = 0; + srh_ip6h->ip6_vfc = 6 << 4; + srh_ip6h->ip6_plen = htons(sizeof(struct ip6_hdr) + sizeof(struct udphdr) + + sizeof(struct ipv6_sr_hdr) + sizeof(struct in6_addr) * seg_num + + datalen); + srh_ip6h->ip6_nxt = IPPROTO_ROUTING; + srh_ip6h->ip6_hlim = BFD_TTL_VAL; + + memcpy(&(srh_ip6h->ip6_src), sip, sizeof(struct in6_addr)); memcpy(&(srh_ip6h->ip6_dst), dip, sizeof(struct in6_addr)); } -static void bp_sbfd_encap_srh_ip6h_red(struct ip6_hdr* srh_ip6h, - struct in6_addr* sip , struct in6_addr* dip ,uint8_t seg_num, size_t datalen, uint16_t family) +static void bp_sbfd_encap_srh_ip6h_red(struct ip6_hdr *srh_ip6h, struct in6_addr *sip, + struct in6_addr *dip, uint8_t seg_num, size_t datalen, + uint16_t family) { - /* SRH IPv6 Header */ + /* SRH IPv6 Header */ srh_ip6h->ip6_flow = (BFD_TOS_VAL << 20); srh_ip6h->ip6_vfc = 6 << 4; - if (seg_num == 1) - { - if (family == AF_INET6) - { - srh_ip6h->ip6_plen = htons(sizeof(struct ip6_hdr) - + sizeof(struct udphdr) - + datalen); + if (seg_num == 1) { + if (family == AF_INET6) { + srh_ip6h->ip6_plen = + htons(sizeof(struct ip6_hdr) + sizeof(struct udphdr) + datalen); srh_ip6h->ip6_nxt = IPPROTO_IPV6; - } - else - { - srh_ip6h->ip6_plen = htons(sizeof(struct ip) - + sizeof(struct udphdr) - + datalen); + } else { + srh_ip6h->ip6_plen = + htons(sizeof(struct ip) + sizeof(struct udphdr) + datalen); srh_ip6h->ip6_nxt = IPPROTO_IPIP; } + } else { + srh_ip6h->ip6_plen = htons(sizeof(struct ip6_hdr) + sizeof(struct udphdr) + + sizeof(struct ipv6_sr_hdr) + + sizeof(struct in6_addr) * (seg_num - 1) + datalen); + srh_ip6h->ip6_nxt = IPPROTO_ROUTING; } - else - { - srh_ip6h->ip6_plen = htons(sizeof(struct ip6_hdr) - + sizeof(struct udphdr) - + sizeof(struct ipv6_sr_hdr) - + sizeof(struct in6_addr) * (seg_num - 1) - + datalen); - srh_ip6h->ip6_nxt = IPPROTO_ROUTING; - } - srh_ip6h->ip6_hlim = BFD_TTL_VAL; + srh_ip6h->ip6_hlim = BFD_TTL_VAL; - memcpy(&(srh_ip6h->ip6_src), sip, sizeof(struct in6_addr)); + memcpy(&(srh_ip6h->ip6_src), sip, sizeof(struct in6_addr)); memcpy(&(srh_ip6h->ip6_dst), dip, sizeof(struct in6_addr)); } -static void bp_sbfd_encap_srh_rth(struct ipv6_sr_hdr *srv6h, - struct in6_addr* segment_list ,uint8_t seg_num) +static void bp_sbfd_encap_srh_rth(struct ipv6_sr_hdr *srv6h, struct in6_addr *segment_list, + uint8_t seg_num) { - srv6h->nexthdr = IPPROTO_IPV6; - srv6h->hdrlen = GET_RTH_HDR_LEN(RTH_BASE_HEADER_LEN + sizeof(struct in6_addr)*seg_num); - srv6h->type = 4; // IPV6_SRCRT_TYPE_4 - srv6h->segments_left = seg_num-1; //if encap reduce mode , seg_num-1 - srv6h->first_segment = seg_num-1; //if encap reduce mode , seg_num-2 - srv6h->flags = 0; - srv6h->tag = 0; - - int i; - for(i = 0;i < seg_num;i++) - { - memcpy(&srv6h->segments[i], &segment_list[seg_num-1-i], sizeof(struct in6_addr)); - } + srv6h->nexthdr = IPPROTO_IPV6; + srv6h->hdrlen = GET_RTH_HDR_LEN(RTH_BASE_HEADER_LEN + sizeof(struct in6_addr) * seg_num); + srv6h->type = 4; // IPV6_SRCRT_TYPE_4 + srv6h->segments_left = seg_num - 1; //if encap reduce mode , seg_num-1 + srv6h->first_segment = seg_num - 1; //if encap reduce mode , seg_num-2 + srv6h->flags = 0; + srv6h->tag = 0; + + for (int i = 0; i < seg_num; i++) + memcpy(&srv6h->segments[i], &segment_list[seg_num - 1 - i], sizeof(struct in6_addr)); } -static void bp_sbfd_encap_srh_rth_red(struct ipv6_sr_hdr *srv6h, - struct in6_addr* segment_list ,uint8_t seg_num) +static void bp_sbfd_encap_srh_rth_red(struct ipv6_sr_hdr *srv6h, struct in6_addr *segment_list, + uint8_t seg_num) { //caller should make sure: seg_num > 1 - srv6h->nexthdr = IPPROTO_IPV6; - srv6h->hdrlen = GET_RTH_HDR_LEN(RTH_BASE_HEADER_LEN + sizeof(struct in6_addr)*(seg_num - 1)); - srv6h->type = 4; // IPV6_SRCRT_TYPE_4 - srv6h->segments_left = seg_num - 1; //if encap reduce mode , seg_num-1 - srv6h->first_segment = seg_num - 2; //if encap reduce mode , seg_num-2 - srv6h->flags = 0; - srv6h->tag = 0; - - int i; - for(i = 0; i < seg_num - 1; i++) - { - //todo: double check here - memcpy(&srv6h->segments[i], &segment_list[seg_num-1-i], sizeof(struct in6_addr)); - } + srv6h->nexthdr = IPPROTO_IPV6; + srv6h->hdrlen = + GET_RTH_HDR_LEN(RTH_BASE_HEADER_LEN + sizeof(struct in6_addr) * (seg_num - 1)); + srv6h->type = 4; // IPV6_SRCRT_TYPE_4 + srv6h->segments_left = seg_num - 1; //if encap reduce mode , seg_num-1 + srv6h->first_segment = seg_num - 2; //if encap reduce mode , seg_num-2 + srv6h->flags = 0; + srv6h->tag = 0; + + for (int i = 0; i < seg_num - 1; i++) + memcpy(&srv6h->segments[i], &segment_list[seg_num - 1 - i], sizeof(struct in6_addr)); } -static void bp_sbfd_encap_inner_ip6h(struct ip6_hdr* ip6h, struct in6_addr* sip , struct in6_addr* dip, size_t datalen) +static void bp_sbfd_encap_inner_ip6h(struct ip6_hdr *ip6h, struct in6_addr *sip, + struct in6_addr *dip, size_t datalen) { - /* IPv6 Header */ - ip6h->ip6_flow = (BFD_TOS_VAL << 20); - ip6h->ip6_vfc = 6 << 4; - ip6h->ip6_plen = htons(sizeof(struct udphdr) + datalen); - ip6h->ip6_nxt = IPPROTO_UDP; - ip6h->ip6_hlim = BFD_TTL_VAL; - - memcpy(&(ip6h->ip6_src), sip, sizeof(struct in6_addr)); + /* IPv6 Header */ + ip6h->ip6_flow = (BFD_TOS_VAL << 20); + ip6h->ip6_vfc = 6 << 4; + ip6h->ip6_plen = htons(sizeof(struct udphdr) + datalen); + ip6h->ip6_nxt = IPPROTO_UDP; + ip6h->ip6_hlim = BFD_TTL_VAL; + + memcpy(&(ip6h->ip6_src), sip, sizeof(struct in6_addr)); memcpy(&(ip6h->ip6_dst), dip, sizeof(struct in6_addr)); } -static void bp_sbfd_encap_inner_iph(struct ip* iph, struct in6_addr* sip , struct in6_addr* dip, size_t datalen) +static void bp_sbfd_encap_inner_iph(struct ip *iph, struct in6_addr *sip, struct in6_addr *dip, + size_t datalen) { - /* IPv4 Header */ - iph->ip_v = 4; - iph->ip_hl = 5; - iph->ip_tos = BFD_TOS_VAL; - iph->ip_len = htons(sizeof(struct ip) + sizeof(struct udphdr) + datalen); - iph->ip_id = (uint16_t)frr_weak_random(); - iph->ip_ttl = BFD_TTL_VAL; - iph->ip_p = IPPROTO_UDP; - iph->ip_sum = 0; + /* IPv4 Header */ + iph->ip_v = 4; + iph->ip_hl = 5; + iph->ip_tos = BFD_TOS_VAL; + iph->ip_len = htons(sizeof(struct ip) + sizeof(struct udphdr) + datalen); + iph->ip_id = (uint16_t)frr_weak_random(); + iph->ip_ttl = BFD_TTL_VAL; + iph->ip_p = IPPROTO_UDP; + iph->ip_sum = 0; memcpy(&iph->ip_src, sip, sizeof(iph->ip_src)); memcpy(&iph->ip_dst, dip, sizeof(iph->ip_dst)); } -static void bp_sbfd_encap_udp6(struct udphdr* udph, struct ip6_hdr* ip6h, uint16_t src_port, uint16_t dst_port , uint8_t *payload, int payloadlen) +static void bp_sbfd_encap_udp6(struct udphdr *udph, struct ip6_hdr *ip6h, uint16_t src_port, + uint16_t dst_port, uint8_t *payload, int payloadlen) { - udph->uh_sport = htons(src_port); - udph->uh_dport = htons(dst_port); - udph->uh_ulen = htons(sizeof(struct udphdr) + payloadlen); - udph->uh_sum = udp6_checksum (*ip6h, *udph, payload, payloadlen); + udph->uh_sport = htons(src_port); + udph->uh_dport = htons(dst_port); + udph->uh_ulen = htons(sizeof(struct udphdr) + payloadlen); + udph->uh_sum = udp6_checksum(*ip6h, *udph, payload, payloadlen); } -static void bp_sbfd_encap_udp4(struct udphdr* udph, struct ip* iph, uint16_t src_port, uint16_t dst_port , uint8_t *payload, int payloadlen) +static void bp_sbfd_encap_udp4(struct udphdr *udph, struct ip *iph, uint16_t src_port, + uint16_t dst_port, uint8_t *payload, int payloadlen) { - udph->uh_sport = htons(src_port); - udph->uh_dport = htons(dst_port); - udph->uh_ulen = htons(sizeof(struct udphdr) + payloadlen); - udph->uh_sum = udp4_checksum (*iph, *udph, payload, payloadlen); -} - -/** - * @brief encap srv6 to send raw socker - * - * @param sd sokcet - * @param data actual data, e.g. bfd packet or bfd echo packet - * @param datalen actual data length - * @param sip source ip address of outer ipv6 header and inner ipv6 header - * @param dip destination ip address of inner ipv6 header - * @param src_port source port of udp - * @param dst_port destination port of udp - * @param seg_num segment number of srh header - * @param segment_list segment list of srh header and the last one segment is destination ip address of outer ipv6 header - * @return int - */ -int bp_raw_sbfd_send(int sd, uint8_t *data, size_t datalen, 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) -{ - struct sockaddr_in6 sin6; - struct msghdr msg; - struct iovec iov[5]; - int flags = 0; - int ret = 0; - - /*raw sbfd layer header*/ - struct ip6_hdr srh_ip6h; // srh ipv6 - struct ipv6_sr_hdr *psrv6h; // srh Routing header - struct ip6_hdr ip6h; // inner ipv6 - struct udphdr udp; - - if (!segment_list || seg_num == 0) - { - zlog_err( - "sbfd segment_list is invalid , seg_num = %d .", seg_num); - return -1; - } - - memset(&sin6,0,sizeof(sin6)); - sin6.sin6_family = AF_INET6; - memcpy(&sin6.sin6_addr, &segment_list[0], sizeof(sin6.sin6_addr)); - - sin6.sin6_port = 0; - - /* SRH IPv6 Header */ - bp_sbfd_encap_srh_ip6h(&srh_ip6h, sip , &segment_list[0], seg_num, datalen); - - /* SRH Routing Header */ - psrv6h = (struct ipv6_sr_hdr*)malloc(sizeof(struct ipv6_sr_hdr) + sizeof(struct in6_addr) * seg_num); - if(psrv6h == NULL) - return -1; - - bp_sbfd_encap_srh_rth(psrv6h, segment_list, seg_num); - - /* Inner IPv6 Header */ - bp_sbfd_encap_inner_ip6h(&ip6h, sip , dip, datalen); - - /* UDP Header */ - bp_sbfd_encap_udp6(&udp, &ip6h, src_port, dst_port, data, datalen); - - memset(&msg, 0, sizeof(msg)); - msg.msg_name = &sin6; - msg.msg_namelen = sizeof(sin6); - msg.msg_iov = iov; - msg.msg_iovlen = 5; - iov[0].iov_base = (char *)&srh_ip6h; - iov[0].iov_len = sizeof(struct ip6_hdr); - iov[1].iov_base = (char *) psrv6h; - iov[1].iov_len = sizeof(struct ipv6_sr_hdr) + sizeof(struct in6_addr) * seg_num; - iov[2].iov_base = (char *)&ip6h; - iov[2].iov_len = sizeof(struct ip6_hdr); - iov[3].iov_base = (char *)&udp; - iov[3].iov_len = sizeof(struct udphdr); - iov[4].iov_base = data; - iov[4].iov_len = datalen; - - ret = sendmsg(sd, &msg, flags); - if (ret < 0) - { - zlog_err( - "sbfd echo send failed , ret : %d .", ret); - } - - free(psrv6h); - - return ret; - + udph->uh_sport = htons(src_port); + udph->uh_dport = htons(dst_port); + udph->uh_ulen = htons(sizeof(struct udphdr) + payloadlen); + udph->uh_sum = udp4_checksum(*iph, *udph, payload, payloadlen); } /** * @brief encap srv6 to send raw socker red mode, just support ecore 2.5 case - * + * * @param sd sokcet * @param data actual data, e.g. bfd packet or bfd echo packet * @param datalen actual data length - * @param sip source ip address of outer ipv6 header and inner ipv6 header - * @param dip destination ip address of inner ipv6 header - * @param src_port source port of udp - * @param dst_port destination port of udp + * @param sip source ip address of outer ipv6 header and inner ipv6 header + * @param dip destination ip address of inner ipv6 header + * @param src_port source port of udp + * @param dst_port destination port of udp * @param seg_num segment number of srh header - * @param segment_list segment list of srh header and the last one segment is destination ip address of outer ipv6 header + * @param segment_list segment list of srh header and the last one segment is destination ip address of outer ipv6 header * @param ifname out interface name * @param vrfname vrf name * @param nhp specified nexthop - * @return int + * @return int */ -int bp_raw_sbfd_red_send(int sd, uint8_t *data, size_t datalen, - uint16_t family, 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) +static int bp_raw_sbfd_red_send(int sd, uint8_t *data, size_t datalen, uint16_t family, + 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) { static uint8_t sendbuf[BUF_SIZ]; - struct msghdr msg = {0}; + struct msghdr msg = { 0 }; struct iovec iov; int flags = 0; int ret = 0; struct ip6_hdr *srh_ip6h; - struct ipv6_sr_hdr *psrv6h; // srh Routing header - struct ip6_hdr *ip6h; + struct ipv6_sr_hdr *psrv6h; // srh Routing header + struct ip6_hdr *ip6h; struct ip *iph; struct udphdr *udp; uint8_t *payload; - struct ipaddr out_sip_addr = {0}; - struct sockaddr_in6 dst_sin6 = {0}; - char buf_addr[INET6_ADDRSTRLEN] = {0}; + struct ipaddr out_sip_addr = { 0 }; + struct sockaddr_in6 dst_sin6 = { 0 }; + char buf_addr[INET6_ADDRSTRLEN] = { 0 }; memset(sendbuf, 0, sizeof(sendbuf)); int total_len = 0; - /* SRH IPv6 Header */ - if (seg_num > 0) - { + /* SRH IPv6 Header */ + if (seg_num > 0) { memcpy(&out_sip_addr.ipaddr_v6, out_sip, sizeof(struct in6_addr)); srh_ip6h = (struct ip6_hdr *)(sendbuf + total_len); - bp_sbfd_encap_srh_ip6h_red(srh_ip6h, &out_sip_addr.ipaddr_v6 , &segment_list[0], seg_num, datalen, family); + bp_sbfd_encap_srh_ip6h_red(srh_ip6h, &out_sip_addr.ipaddr_v6, &segment_list[0], + seg_num, datalen, family); total_len += sizeof(struct ip6_hdr); memcpy(&dst_sin6.sin6_addr, &segment_list[0], sizeof(struct in6_addr)); } //case with srh header - if(seg_num > 1){ - psrv6h = (struct ipv6_sr_hdr*)(sendbuf + total_len); + if (seg_num > 1) { + psrv6h = (struct ipv6_sr_hdr *)(sendbuf + total_len); bp_sbfd_encap_srh_rth_red(psrv6h, segment_list, seg_num); total_len += sizeof(struct ipv6_sr_hdr) + sizeof(struct in6_addr) * (seg_num - 1); } - if (family == AF_INET6) - { - if(seg_num == 0){ - memcpy(&dst_sin6.sin6_addr, dip, sizeof(struct in6_addr)); - } + if (family == AF_INET6) { + if (seg_num == 0) + memcpy(&dst_sin6.sin6_addr, dip, sizeof(struct in6_addr)); /* Inner IPv6 Header */ ip6h = (struct ip6_hdr *)(sendbuf + total_len); - bp_sbfd_encap_inner_ip6h(ip6h, sip , dip, datalen); + bp_sbfd_encap_inner_ip6h(ip6h, sip, dip, datalen); total_len += sizeof(struct ip6_hdr); /* UDP Header */ udp = (struct udphdr *)(sendbuf + total_len); bp_sbfd_encap_udp6(udp, ip6h, src_port, dst_port, data, datalen); total_len += sizeof(struct udphdr); - } - else - { - if(seg_num == 0){ + } else { + if (seg_num == 0) { //should never come to here, just print a error hint - zlog_err("bp_raw_sbfd_red_send error, empty sidlist for ipv4 bfd"); + zlog_err("%s error, empty sidlist for ipv4 bfd", __func__); } /* Inner IPv4 Header */ iph = (struct ip *)(sendbuf + total_len); - bp_sbfd_encap_inner_iph(iph, sip , dip, datalen); + bp_sbfd_encap_inner_iph(iph, sip, dip, datalen); total_len += sizeof(struct ip); /* UDP Header */ @@ -2665,12 +2555,12 @@ int bp_raw_sbfd_red_send(int sd, uint8_t *data, size_t datalen, /* BFD payload*/ payload = (uint8_t *)(sendbuf + total_len); - memcpy(payload, data, datalen); + memcpy(payload, data, datalen); total_len += datalen; - dst_sin6.sin6_family = AF_INET6; - dst_sin6.sin6_port = 0; //we don't use sin6_port in raw, but should set to 0!! - + dst_sin6.sin6_family = AF_INET6; + dst_sin6.sin6_port = 0; //we don't use sin6_port in raw, but should set to 0!! + /* message data. */ iov.iov_base = (uint8_t *)sendbuf; iov.iov_len = total_len; @@ -2681,15 +2571,14 @@ int bp_raw_sbfd_red_send(int sd, uint8_t *data, size_t datalen, msg.msg_iovlen = 1; /* sendmsg */ - ret = sendmsg(sd, &msg, flags); - if (ret < 0) - { + ret = sendmsg(sd, &msg, flags); + if (ret < 0) { inet_ntop(AF_INET6, &dst_sin6.sin6_addr, buf_addr, INET6_ADDRSTRLEN); - zlog_debug( - "sbfd send to:%s failed , ret:%d, errno:%s", buf_addr, ret, safe_strerror(errno)); + zlog_debug("sbfd send to:%s failed , ret:%d, errno:%s", buf_addr, ret, + safe_strerror(errno)); return ret; - } + } - return 0; + return 0; } diff --git a/bfdd/bfdd.c b/bfdd/bfdd.c index 47b51ae94aba..5b486377a82d 100644 --- a/bfdd/bfdd.c +++ b/bfdd/bfdd.c @@ -142,16 +142,16 @@ static const struct option longopts[] = { struct bfd_global bglobal; const struct bfd_diag_str_list diag_list[] = { - {.str = "control-expired", .type = BD_CONTROL_EXPIRED}, - {.str = "echo-failed", .type = BD_ECHO_FAILED}, - {.str = "neighbor-down", .type = BD_NEIGHBOR_DOWN}, - {.str = "forwarding-reset", .type = BD_FORWARDING_RESET}, - {.str = "path-down", .type = BD_PATH_DOWN}, - {.str = "concatenated-path-down", .type = BD_CONCATPATH_DOWN}, - {.str = "administratively-down", .type = BD_ADMIN_DOWN}, - {.str = "reverse-concat-path-down", .type = BD_REVCONCATPATH_DOWN}, - {.str = "sbfd-detect-failed", .type = BD_SBFD_DETECT_FAILED}, - {.str = NULL}, + { .str = "control-expired", .type = BD_CONTROL_EXPIRED }, + { .str = "echo-failed", .type = BD_ECHO_FAILED }, + { .str = "neighbor-down", .type = BD_NEIGHBOR_DOWN }, + { .str = "forwarding-reset", .type = BD_FORWARDING_RESET }, + { .str = "path-down", .type = BD_PATH_DOWN }, + { .str = "concatenated-path-down", .type = BD_CONCATPATH_DOWN }, + { .str = "administratively-down", .type = BD_ADMIN_DOWN }, + { .str = "reverse-concat-path-down", .type = BD_REVCONCATPATH_DOWN }, + { .str = "sbfd-detect-failed", .type = BD_SBFD_DETECT_FAILED }, + { .str = NULL }, }; const struct bfd_state_str_list state_list[] = { @@ -360,7 +360,7 @@ int main(int argc, char *argv[]) bfd_vrf_init(); access_list_init(); - + /* Initialize zebra connection. */ bfdd_zclient_init(&bglobal.bfdd_privs); diff --git a/bfdd/bfdd_cli.c b/bfdd/bfdd_cli.c index 31b58d65979b..4b7e91c5a2a4 100644 --- a/bfdd/bfdd_cli.c +++ b/bfdd/bfdd_cli.c @@ -34,14 +34,14 @@ #define LOCAL_INTF_STR "Configure local interface name to use\n" #define VRF_STR "Configure VRF\n" #define VRF_NAME_STR "Configure VRF name\n" -#define SESSION_NAME_STR "Specify bfd session name\n" -#define SET_SESSION_NAME_STR "bfd session name\n" -#define SESSION_MODE_STR "Specify bfd session mode\n" +#define SESSION_NAME_STR "Specify bfd session name\n" +#define SET_SESSION_NAME_STR "bfd session name\n" +#define SESSION_MODE_STR "Specify bfd session mode\n" #define APPLY_SESSION_MODE_STR "Enable bfd mode\n" #define IPV4_ADDRESS 4 #define IPV6_ADDRESS 6 -#define INVALID_IP 0 +#define INVALID_IP 0 /* * Prototypes. @@ -52,8 +52,7 @@ bfd_cli_is_single_hop(struct vty *vty) return strstr(VTY_CURR_XPATH, "/single-hop") != NULL; } -static bool -bfd_cli_is_sbfd_echo(struct vty *vty) +static bool bfd_cli_is_sbfd_echo(struct vty *vty) { return strstr(VTY_CURR_XPATH, "/srte-sbfd-echo") != NULL; } @@ -65,17 +64,17 @@ bfd_cli_is_profile(struct vty *vty) return strstr(VTY_CURR_XPATH, "/bfd/profile") != NULL; } -static int determine_ip_version(const char *ip) +static int determine_ip_version(const char *ip) { - struct in_addr inaddr4; - struct in6_addr inaddr6; + struct in_addr inaddr4; + struct in6_addr inaddr6; - if (inet_pton(AF_INET, ip, &inaddr4) == 1) + if (inet_pton(AF_INET, ip, &inaddr4) == 1) return IPV4_ADDRESS; - if (inet_pton(AF_INET6, ip, &inaddr6) == 1) + if (inet_pton(AF_INET6, ip, &inaddr6) == 1) return IPV6_ADDRESS; - return INVALID_IP; + return INVALID_IP; } /* * Functions. @@ -270,42 +269,36 @@ DEFPY_YANG_NOSH( VRF_NAME_STR) { int ret, slen; - char value[32]; char xpath[XPATH_MAXLEN], xpath_sl[XPATH_MAXLEN + 32]; - + if (!bfdname) { - vty_out(vty,"%% ERROR: bfd name is required\n"); - return CMD_WARNING_CONFIG_FAILED; + vty_out(vty, "%% ERROR: bfd name is required\n"); + return CMD_WARNING_CONFIG_FAILED; } - if (strcmp(peer_str, local_address_str)) - { - vty_out(vty,"%% ERROR: peer and local-address must be the same in sbfd-echo mode\n"); - return CMD_WARNING_CONFIG_FAILED; + if (strcmp(peer_str, local_address_str)) { + vty_out(vty, + "%% ERROR: peer and local-address must be the same in sbfd-echo mode\n"); + return CMD_WARNING_CONFIG_FAILED; } - + slen = snprintf(xpath, sizeof(xpath), "/frr-bfdd:bfdd/bfd/sessions/srte-sbfd-echo[source-addr='%s'][bfd-name='%s']", - local_address_str, - bfdname); + local_address_str, bfdname); if (vrf) slen += snprintf(xpath + slen, sizeof(xpath) - slen, "[vrf='%s']", vrf); else - slen += snprintf(xpath + slen, sizeof(xpath) - slen, "[vrf='%s']", - VRF_DEFAULT_NAME); + slen += snprintf(xpath + slen, sizeof(xpath) - slen, "[vrf='%s']", VRF_DEFAULT_NAME); nb_cli_enqueue_change(vty, xpath, NB_OP_CREATE, NULL); - if (strcmp(encap_type, "SRv6") == 0) - { + if (strcmp(encap_type, "SRv6") == 0) { snprintf(xpath_sl, sizeof(xpath_sl), "%s/segment-list", xpath); nb_cli_enqueue_change(vty, xpath_sl, NB_OP_MODIFY, encap_data_str); - } - else - { - vty_out(vty,"%% ERROR: encap_type is invalid\n"); - return CMD_WARNING_CONFIG_FAILED; + } else { + vty_out(vty, "%% ERROR: encap_type is invalid\n"); + return CMD_WARNING_CONFIG_FAILED; } snprintf(xpath_sl, sizeof(xpath_sl), "%s/source-ipv6", xpath); nb_cli_enqueue_change(vty, xpath_sl, NB_OP_MODIFY, source_ipv6_str); @@ -351,14 +344,12 @@ DEFPY_YANG( slen = snprintf(xpath, sizeof(xpath), "/frr-bfdd:bfdd/bfd/sessions/srte-sbfd-echo[source-addr='%s'][bfd-name='%s']", - local_address_str, - bfdname); + local_address_str, bfdname); if (vrf) slen += snprintf(xpath + slen, sizeof(xpath) - slen, "[vrf='%s']", vrf); else - slen += snprintf(xpath + slen, sizeof(xpath) - slen, "[vrf='%s']", - VRF_DEFAULT_NAME); + slen += snprintf(xpath + slen, sizeof(xpath) - slen, "[vrf='%s']", VRF_DEFAULT_NAME); nb_cli_enqueue_change(vty, xpath, NB_OP_DESTROY, NULL); @@ -394,55 +385,47 @@ DEFPY_YANG_NOSH( VRF_NAME_STR) { int ret, slen, peer_ver, local_ver; - char value[32]; - char xpath[XPATH_MAXLEN], xpath_sl[XPATH_MAXLEN + 32],xpath_rd[XPATH_MAXLEN + 32]; - + char xpath[XPATH_MAXLEN], xpath_sl[XPATH_MAXLEN + 32], xpath_rd[XPATH_MAXLEN + 32]; + if (!bfdname) { - vty_out(vty,"%% ERROR: bfd name is required\n"); - return CMD_WARNING_CONFIG_FAILED; + vty_out(vty, "%% ERROR: bfd name is required\n"); + return CMD_WARNING_CONFIG_FAILED; } - + peer_ver = determine_ip_version(peer_str); - if (peer_ver == INVALID_IP) - { - vty_out(vty,"%% ERROR: peer is invalid address\n"); + if (peer_ver == INVALID_IP) { + vty_out(vty, "%% ERROR: peer is invalid address\n"); return CMD_WARNING_CONFIG_FAILED; } local_ver = determine_ip_version(local_address_str); - if (local_ver == INVALID_IP) - { - vty_out(vty,"%% ERROR: local_address is invalid address\n"); + if (local_ver == INVALID_IP) { + vty_out(vty, "%% ERROR: local_address is invalid address\n"); return CMD_WARNING_CONFIG_FAILED; } - if (peer_ver != local_ver) - { - vty_out(vty,"%% ERROR: peer and local_address are not the same ip version\n"); - return CMD_WARNING_CONFIG_FAILED; + if (peer_ver != local_ver) { + vty_out(vty, "%% ERROR: peer and local_address are not the same ip version\n"); + return CMD_WARNING_CONFIG_FAILED; } - + slen = snprintf(xpath, sizeof(xpath), "/frr-bfdd:bfdd/bfd/sessions/srte-sbfd-init[source-addr='%s'][dest-addr='%s'][bfd-name='%s']", - local_address_str, - peer_str, - bfdname); + local_address_str, peer_str, bfdname); if (vrf) slen += snprintf(xpath + slen, sizeof(xpath) - slen, "[vrf='%s']", vrf); else - slen += snprintf(xpath + slen, sizeof(xpath) - slen, "[vrf='%s']", - VRF_DEFAULT_NAME); + slen += snprintf(xpath + slen, sizeof(xpath) - slen, "[vrf='%s']", VRF_DEFAULT_NAME); nb_cli_enqueue_change(vty, xpath, NB_OP_CREATE, NULL); - if (encap_type && strcmp(encap_type, "SRv6") == 0) - { + if (encap_type && strcmp(encap_type, "SRv6") == 0) { snprintf(xpath_sl, sizeof(xpath_sl), "%s/segment-list", xpath); nb_cli_enqueue_change(vty, xpath_sl, NB_OP_MODIFY, encap_data_str); snprintf(xpath_sl, sizeof(xpath_sl), "%s/source-ipv6", xpath); - nb_cli_enqueue_change(vty, xpath_sl, NB_OP_MODIFY, source_ipv6_str); + nb_cli_enqueue_change(vty, xpath_sl, NB_OP_MODIFY, source_ipv6_str); } snprintf(xpath_rd, sizeof(xpath_rd), "%s/remote-discr", xpath); @@ -488,15 +471,12 @@ DEFPY_YANG( slen = snprintf(xpath, sizeof(xpath), "/frr-bfdd:bfdd/bfd/sessions/srte-sbfd-init[source-addr='%s'][dest-addr='%s'][bfd-name='%s']", - local_address_str, - peer_str, - bfdname); + local_address_str, peer_str, bfdname); if (vrf) slen += snprintf(xpath + slen, sizeof(xpath) - slen, "[vrf='%s']", vrf); else - slen += snprintf(xpath + slen, sizeof(xpath) - slen, "[vrf='%s']", - VRF_DEFAULT_NAME); + slen += snprintf(xpath + slen, sizeof(xpath) - slen, "[vrf='%s']", VRF_DEFAULT_NAME); nb_cli_enqueue_change(vty, xpath, NB_OP_DESTROY, NULL); @@ -504,28 +484,27 @@ DEFPY_YANG( return nb_cli_apply_changes(vty, NULL); } -static const char *_bfd_cli_bfd_mode_type_to_string(enum bfd_mode_type mode) { - switch (mode) { - case BFD_MODE_TYPE_BFD: - return "bfd"; - case BFD_MODE_TYPE_SBFD_ECHO: - return "sbfd-echo"; - case BFD_MODE_TYPE_SBFD_INIT: - return "sbfd-init"; - default: - return "Unknown"; - } +static const char *_bfd_cli_bfd_mode_type_to_string(enum bfd_mode_type mode) +{ + switch (mode) { + case BFD_MODE_TYPE_BFD: + return "bfd"; + case BFD_MODE_TYPE_SBFD_ECHO: + return "sbfd-echo"; + case BFD_MODE_TYPE_SBFD_INIT: + return "sbfd-init"; + default: + return "Unknown"; + } } static void _bfd_cli_show_peer(struct vty *vty, const struct lyd_node *dnode, - bool show_defaults __attribute__((__unused__)), - bool mhop, uint32_t bfd_mode) + bool show_defaults __attribute__((__unused__)), bool mhop, + uint32_t bfd_mode) { const char *vrf = yang_dnode_get_string(dnode, "vrf"); - vty_out(vty, " peer %s", - yang_dnode_get_string(dnode, "./dest-addr")); - if (bfd_mode == BFD_MODE_TYPE_BFD) - { + vty_out(vty, " peer %s", yang_dnode_get_string(dnode, "./dest-addr")); + if (bfd_mode == BFD_MODE_TYPE_BFD) { if (mhop) vty_out(vty, " multihop"); @@ -537,19 +516,17 @@ static void _bfd_cli_show_peer(struct vty *vty, const struct lyd_node *dnode, vty_out(vty, " vrf %s", vrf); if (!mhop) { - const char *ifname = - yang_dnode_get_string(dnode, "./interface"); + const char *ifname = yang_dnode_get_string(dnode, "./interface"); + if (strcmp(ifname, "*")) vty_out(vty, " interface %s", ifname); } - vty_out(vty, "\n"); - } - else if (bfd_mode == BFD_MODE_TYPE_SBFD_ECHO || bfd_mode == BFD_MODE_TYPE_SBFD_INIT) - { - vty_out(vty, " bfd-mode %s", _bfd_cli_bfd_mode_type_to_string(bfd_mode)); + vty_out(vty, "\n"); + } else if (bfd_mode == BFD_MODE_TYPE_SBFD_ECHO || bfd_mode == BFD_MODE_TYPE_SBFD_INIT) { + vty_out(vty, " bfd-mode %s", _bfd_cli_bfd_mode_type_to_string(bfd_mode)); if (yang_dnode_exists(dnode, "bfd-name")) - vty_out(vty, " bfd-name %s", yang_dnode_get_string(dnode, "bfd-name")); + vty_out(vty, " bfd-name %s", yang_dnode_get_string(dnode, "bfd-name")); if (yang_dnode_exists(dnode, "source-addr")) vty_out(vty, " local-address %s", @@ -560,11 +537,9 @@ static void _bfd_cli_show_peer(struct vty *vty, const struct lyd_node *dnode, yang_dnode_get_string(dnode, "segment-list")); if (yang_dnode_exists(dnode, "source-ipv6")) - vty_out(vty, " source-ipv6 %s", - yang_dnode_get_string(dnode, "source-ipv6")); + vty_out(vty, " source-ipv6 %s", yang_dnode_get_string(dnode, "source-ipv6")); - if (bfd_mode == BFD_MODE_TYPE_SBFD_INIT) - { + if (bfd_mode == BFD_MODE_TYPE_SBFD_INIT) { if (yang_dnode_exists(dnode, "remote-discr")) vty_out(vty, " remote-discr %u", yang_dnode_get_uint32(dnode, "remote-discr")); @@ -574,7 +549,7 @@ static void _bfd_cli_show_peer(struct vty *vty, const struct lyd_node *dnode, vty_out(vty, " vrf %s", vrf); vty_out(vty, "\n"); - } + } } void bfd_cli_show_single_hop_peer(struct vty *vty, const struct lyd_node *dnode, @@ -589,14 +564,12 @@ void bfd_cli_show_multi_hop_peer(struct vty *vty, const struct lyd_node *dnode, _bfd_cli_show_peer(vty, dnode, show_defaults, true, BFD_MODE_TYPE_BFD); } -void bfd_cli_show_sbfd_echo_peer(struct vty *vty, const struct lyd_node *dnode, - bool show_defaults) +void bfd_cli_show_sbfd_echo_peer(struct vty *vty, const struct lyd_node *dnode, bool show_defaults) { _bfd_cli_show_peer(vty, dnode, show_defaults, false, BFD_MODE_TYPE_SBFD_ECHO); } -void bfd_cli_show_sbfd_init_peer(struct vty *vty, const struct lyd_node *dnode, - bool show_defaults) +void bfd_cli_show_sbfd_init_peer(struct vty *vty, const struct lyd_node *dnode, bool show_defaults) { _bfd_cli_show_peer(vty, dnode, show_defaults, true, BFD_MODE_TYPE_SBFD_INIT); } @@ -792,7 +765,8 @@ DEFPY_YANG( char value[32]; if (!bfd_cli_is_profile(vty) && !bfd_cli_is_single_hop(vty) && !bfd_cli_is_sbfd_echo(vty)) { - vty_out(vty, "%% Echo mode is only available for single hop or sbfd echo sessions.\n"); + vty_out(vty, + "%% Echo mode is only available for single hop or sbfd echo sessions.\n"); return CMD_WARNING_CONFIG_FAILED; } @@ -816,7 +790,8 @@ DEFPY_YANG( char value[32]; if (!bfd_cli_is_profile(vty) && !bfd_cli_is_single_hop(vty) && !bfd_cli_is_sbfd_echo(vty)) { - vty_out(vty, "%% Echo mode is only available for single hop or sbfd echo sessions.\n"); + vty_out(vty, + "%% Echo mode is only available for single hop or sbfd echo sessions.\n"); return CMD_WARNING_CONFIG_FAILED; } @@ -847,7 +822,8 @@ DEFPY_YANG( char value[32]; if (!bfd_cli_is_profile(vty) && !bfd_cli_is_single_hop(vty) && !bfd_cli_is_sbfd_echo(vty)) { - vty_out(vty, "%% Echo mode is only available for single hop or sbfd echo sessions.\n"); + vty_out(vty, + "%% Echo mode is only available for single hop or sbfd echo sessions.\n"); return CMD_WARNING_CONFIG_FAILED; } @@ -1021,45 +997,36 @@ DEFPY( uint32_t discr_to = 0; for (i = idx_discr; i < argc; i++) { - /* check validity*/ - char *pstr = argv[i]->arg; - + /* check validity*/ + char *pstr = argv[i]->arg; + /*single discr*/ - if (strspn(pstr, "0123456789")==strlen(pstr)) - { + if (strspn(pstr, "0123456789") == strlen(pstr)) { discr = atol(pstr); sbfd_reflector_new(discr, &srcip); - } + } /*discr segment*/ - else if (strspn(pstr, "0123456789-")==strlen(pstr)) - { - char *token = strtok(argv[i]->arg, "-"); - if(token) - { + else if (strspn(pstr, "0123456789-") == strlen(pstr)) { + char *token = strtok(argv[i]->arg, "-"); + + if (token) discr_from = atol(token); - } - token = strtok(NULL, "-"); - if(token) - { + + token = strtok(NULL, "-"); + if (token) discr_to = atol(token); - } - if (discr_from >= discr_to) - { - vty_out(vty, "input discriminator range %u-%u is illegal\n", discr_from, discr_to); + if (discr_from >= discr_to) { + vty_out(vty, "input discriminator range %u-%u is illegal\n", + discr_from, discr_to); } for (j = discr_from; j <= discr_to; j++) - { - sbfd_reflector_new(j, &srcip); - } - } + sbfd_reflector_new(j, &srcip); + } /*illegal input*/ else - { vty_out(vty, "input discriminator %s is illegal\n", (char *)argv[i]); - } - } return CMD_SUCCESS; @@ -1073,10 +1040,9 @@ DEFPY( "sbfd reflector\n" "all\n") { - sbfd_reflector_flush(); - - if (sbfd_discr_get_count()) - { + sbfd_reflector_flush(); + + if (sbfd_discr_get_count()) { vty_out(vty, "delete all refector discriminator failed.\n"); return CMD_WARNING_CONFIG_FAILED; } @@ -1094,41 +1060,33 @@ DEFPY( "end discriminator\n") { struct sbfd_reflector *sr; - uint32_t i; + int32_t i; - if (end_discr == 0 ) - { - if (start_discr == 0) - { + if (end_discr == 0) { + if (start_discr == 0) { vty_out(vty, "input refector discriminator is illegal.\n"); return CMD_WARNING_CONFIG_FAILED; } - + sr = sbfd_discr_lookup(start_discr); - if (!sr) - { + if (!sr) { vty_out(vty, "input refector discriminator does not exist.\n"); return CMD_WARNING_CONFIG_FAILED; } - + // notify bfdsyncd //bfd_fpm_sbfd_reflector_sendmsg(sr, false); sbfd_reflector_free(start_discr); - } - else - { - if (end_discr <= start_discr) - { + } else { + if (end_discr <= start_discr) { vty_out(vty, "input refector discriminator is illegal.\n"); return CMD_WARNING_CONFIG_FAILED; } - for (i = start_discr; i <= end_discr; i++) - { + for (i = start_discr; i <= end_discr; i++) { sr = sbfd_discr_lookup(i); - if (sr) - { + if (sr) { // notify bfdsyncd //bfd_fpm_sbfd_reflector_sendmsg(sr, false); sbfd_reflector_free(i); @@ -1139,20 +1097,16 @@ DEFPY( return CMD_SUCCESS; } -static void _sbfd_reflector_show(struct hash_bucket *hb, - void *arg) +static void _sbfd_reflector_show(struct hash_bucket *hb, void *arg) { struct sbfd_reflector *sr = hb->data; struct ttable *tt; char buf[INET6_ADDRSTRLEN]; - tt = (struct ttable *) arg; - - ttable_add_row(tt, "%u|%s|%s|%s", - sr->discr, - inet_ntop(AF_INET6, &sr->local, buf, sizeof(buf)), - "Active", - "Software"); + tt = (struct ttable *)arg; + + ttable_add_row(tt, "%u|%s|%s|%s", sr->discr, + inet_ntop(AF_INET6, &sr->local, buf, sizeof(buf)), "Active", "Software"); } DEFPY( @@ -1164,13 +1118,13 @@ DEFPY( { struct ttable *tt; char *out; - + vty_out(vty, "sbfd refector discriminator :\n"); tt = ttable_new(&ttable_styles[TTSTYLE_BLANK]); ttable_add_row(tt, "SBFD-Discr|SourceIP|State|CreateType"); ttable_rowseps(tt, 0, BOTTOM, true, '-'); - sbfd_discr_iterate(_sbfd_reflector_show, tt); + sbfd_discr_iterate(_sbfd_reflector_show, tt); out = ttable_dump(tt, "\n"); vty_out(vty, "%s", out); @@ -1225,7 +1179,7 @@ bfdd_cli_init(void) install_element(BFD_NODE, &sbfd_reflector_cmd); install_element(BFD_NODE, &no_sbfd_reflector_all_cmd); install_element(BFD_NODE, &no_sbfd_reflector_cmd); - install_element(VIEW_NODE, &sbfd_reflector_show_info_cmd); + install_element(VIEW_NODE, &sbfd_reflector_show_info_cmd); install_element(BFD_PEER_NODE, &bfd_peer_shutdown_cmd); install_element(BFD_PEER_NODE, &bfd_peer_mult_cmd); install_element(BFD_PEER_NODE, &bfd_peer_rx_cmd); diff --git a/bfdd/bfdd_nb.c b/bfdd/bfdd_nb.c index fa06db607386..8c915a740a23 100644 --- a/bfdd/bfdd_nb.c +++ b/bfdd/bfdd_nb.c @@ -519,14 +519,14 @@ const struct frr_yang_module_info frr_bfdd_info = { .destroy = bfdd_bfd_sessions_srte_sbfd_source_ipv6_destroy, } }, - { - .xpath = "/frr-bfdd:bfdd/bfd/sessions/srte-sbfd-echo/profile", - .cbs = { - .modify = bfdd_bfd_sessions_single_hop_profile_modify, - .destroy = bfdd_bfd_sessions_single_hop_profile_destroy, + { + .xpath = "/frr-bfdd:bfdd/bfd/sessions/srte-sbfd-echo/profile", + .cbs = { + .modify = bfdd_bfd_sessions_single_hop_profile_modify, + .destroy = bfdd_bfd_sessions_single_hop_profile_destroy, .cli_show = bfd_cli_peer_profile_show, - } - }, + } + }, { .xpath = "/frr-bfdd:bfdd/bfd/sessions/srte-sbfd-echo/detection-multiplier", .cbs = { @@ -757,14 +757,14 @@ const struct frr_yang_module_info frr_bfdd_info = { .destroy = bfdd_bfd_sessions_srte_sbfd_init_remote_discr_destroy, } }, - { - .xpath = "/frr-bfdd:bfdd/bfd/sessions/srte-sbfd-init/profile", - .cbs = { - .modify = bfdd_bfd_sessions_single_hop_profile_modify, - .destroy = bfdd_bfd_sessions_single_hop_profile_destroy, + { + .xpath = "/frr-bfdd:bfdd/bfd/sessions/srte-sbfd-init/profile", + .cbs = { + .modify = bfdd_bfd_sessions_single_hop_profile_modify, + .destroy = bfdd_bfd_sessions_single_hop_profile_destroy, .cli_show = bfd_cli_peer_profile_show, - } - }, + } + }, { .xpath = "/frr-bfdd:bfdd/bfd/sessions/srte-sbfd-init/detection-multiplier", .cbs = { diff --git a/bfdd/bfdd_nb.h b/bfdd/bfdd_nb.h index 4f624c4fd971..cbd867771463 100644 --- a/bfdd/bfdd_nb.h +++ b/bfdd/bfdd_nb.h @@ -124,16 +124,12 @@ int bfdd_bfd_sessions_srte_sbfd_init_remote_discr_destroy(struct nb_cb_destroy_a int bfdd_bfd_sessions_srte_sbfd_init_create(struct nb_cb_create_args *args); int bfdd_bfd_sessions_srte_sbfd_init_destroy(struct nb_cb_destroy_args *args); -const void * -bfdd_bfd_sessions_srte_sbfd_echo_get_next(struct nb_cb_get_next_args *args); +const void *bfdd_bfd_sessions_srte_sbfd_echo_get_next(struct nb_cb_get_next_args *args); int bfdd_bfd_sessions_srte_sbfd_echo_get_keys(struct nb_cb_get_keys_args *args); -const void * -bfdd_bfd_sessions_srte_sbfd_echo_lookup_entry(struct nb_cb_lookup_entry_args *args); -const void * -bfdd_bfd_sessions_srte_sbfd_init_get_next(struct nb_cb_get_next_args *args); +const void *bfdd_bfd_sessions_srte_sbfd_echo_lookup_entry(struct nb_cb_lookup_entry_args *args); +const void *bfdd_bfd_sessions_srte_sbfd_init_get_next(struct nb_cb_get_next_args *args); int bfdd_bfd_sessions_srte_sbfd_init_get_keys(struct nb_cb_get_keys_args *args); -const void * -bfdd_bfd_sessions_srte_sbfd_init_lookup_entry(struct nb_cb_lookup_entry_args *args); +const void *bfdd_bfd_sessions_srte_sbfd_init_lookup_entry(struct nb_cb_lookup_entry_args *args); const void * bfdd_bfd_sessions_multi_hop_get_next(struct nb_cb_get_next_args *args); @@ -208,10 +204,8 @@ void bfd_cli_show_single_hop_peer(struct vty *vty, const struct lyd_node *dnode, bool show_defaults); void bfd_cli_show_multi_hop_peer(struct vty *vty, const struct lyd_node *dnode, bool show_defaults); -void bfd_cli_show_sbfd_echo_peer(struct vty *vty, const struct lyd_node *dnode, - bool show_defaults); -void bfd_cli_show_sbfd_init_peer(struct vty *vty, const struct lyd_node *dnode, - bool show_defaults); +void bfd_cli_show_sbfd_echo_peer(struct vty *vty, const struct lyd_node *dnode, bool show_defaults); +void bfd_cli_show_sbfd_init_peer(struct vty *vty, const struct lyd_node *dnode, bool show_defaults); void bfd_cli_show_peer_end(struct vty *vty, const struct lyd_node *dnode); void bfd_cli_show_mult(struct vty *vty, const struct lyd_node *dnode, bool show_defaults); diff --git a/bfdd/bfdd_nb_config.c b/bfdd/bfdd_nb_config.c index 767f8387abc3..acda4364a418 100644 --- a/bfdd/bfdd_nb_config.c +++ b/bfdd/bfdd_nb_config.c @@ -18,34 +18,35 @@ /* * Helpers. */ -static void get_ip_by_interface(const char *ifname, char *ifip) { - struct ifaddrs *ifaddr, *ifa; - int family; - char intfip[INET6_ADDRSTRLEN]; - - if (getifaddrs(&ifaddr) == -1) { - zlog_err("getifaddrs failed, ifname: %s", ifname); - return; - } - - for (ifa = ifaddr; ifa != NULL; ifa = ifa->ifa_next) { - if (ifa->ifa_addr == NULL) continue; - family = ifa->ifa_addr->sa_family; - - if (family == AF_INET || family == AF_INET6) { - if (strcmp(ifa->ifa_name, ifname) == 0) { - getnameinfo(ifa->ifa_addr, - (family == AF_INET) ? sizeof(struct sockaddr_in) : - sizeof(struct sockaddr_in6), - intfip, sizeof(intfip), - NULL, 0, NI_NUMERICHOST); - strlcpy(ifip,intfip,INET6_ADDRSTRLEN - 1); +static void get_ip_by_interface(const char *ifname, char *ifip) +{ + struct ifaddrs *ifaddr, *ifa; + int family; + char intfip[INET6_ADDRSTRLEN]; + + if (getifaddrs(&ifaddr) == -1) { + zlog_err("getifaddrs failed, ifname: %s", ifname); + return; + } + + for (ifa = ifaddr; ifa != NULL; ifa = ifa->ifa_next) { + if (ifa->ifa_addr == NULL) + continue; + family = ifa->ifa_addr->sa_family; + + if (family == AF_INET || family == AF_INET6) { + if (strcmp(ifa->ifa_name, ifname) == 0) { + getnameinfo(ifa->ifa_addr, + (family == AF_INET) ? sizeof(struct sockaddr_in) + : sizeof(struct sockaddr_in6), + intfip, sizeof(intfip), NULL, 0, NI_NUMERICHOST); + strlcpy(ifip, intfip, INET6_ADDRSTRLEN - 1); break; - } - } - } - - freeifaddrs(ifaddr); + } + } + } + + freeifaddrs(ifaddr); } static void bfd_session_get_key(bool mhop, const struct lyd_node *dnode, @@ -69,9 +70,8 @@ static void bfd_session_get_key(bool mhop, const struct lyd_node *dnode, ifname = yang_dnode_get_string(dnode, "interface"); if (strcmp(ifname, "*") == 0) ifname = NULL; - if (ifname != NULL && !yang_dnode_exists(dnode, "source-addr")) - { - get_ip_by_interface(ifname,ifip); + if (ifname != NULL && !yang_dnode_exists(dnode, "source-addr")) { + get_ip_by_interface(ifname, ifip); strtosa(ifip, &lsa); } } @@ -80,19 +80,18 @@ static void bfd_session_get_key(bool mhop, const struct lyd_node *dnode, gen_bfd_key(bk, &psa, &lsa, mhop, ifname, vrfname, NULL); } -static void sbfd_session_get_key(bool mhop, const struct lyd_node *dnode, - struct bfd_key *bk) +static void sbfd_session_get_key(bool mhop, const struct lyd_node *dnode, struct bfd_key *bk) { const char *ifname = NULL, *vrfname = NULL, *bfdname = NULL; struct sockaddr_any psa, lsa; /* Required source parameter. */ strtosa(yang_dnode_get_string(dnode, "source-addr"), &lsa); - + strtosa(yang_dnode_get_string(dnode, "dest-addr"), &psa); - + if (yang_dnode_exists(dnode, "bfd-name")) - bfdname = yang_dnode_get_string(dnode, "bfd-name"); + bfdname = yang_dnode_get_string(dnode, "bfd-name"); if (yang_dnode_exists(dnode, "vrf")) vrfname = yang_dnode_get_string(dnode, "vrf"); @@ -121,7 +120,7 @@ static int session_iter_cb(const struct lyd_node *dnode, void *arg) return YANG_ITER_CONTINUE; } -static int bfd_session_create(struct nb_cb_create_args *args, bool mhop, uint32_t bfd_mode) +static int bfd_session_create(struct nb_cb_create_args *args, bool mhop, uint32_t bfd_mode) { const struct lyd_node *sess_dnode; struct session_iter iter; @@ -131,17 +130,15 @@ static int bfd_session_create(struct nb_cb_create_args *args, bool mhop, uint32 const char *vrfname; struct bfd_key bk; struct prefix p; - const char * bfd_name = NULL; + const char *bfd_name = NULL; uint8_t segnum = 1; struct sockaddr_any slist, out_sip6; switch (args->event) { case NB_EV_VALIDATE: if ((bfd_mode == BFD_MODE_TYPE_SBFD_ECHO) || (bfd_mode == BFD_MODE_TYPE_SBFD_INIT)) { - if(bfd_session_get_by_name(yang_dnode_get_string(args->dnode, "bfd-name"))) { - snprintf( - args->errmsg, args->errmsg_len, - "bfd name already exist."); + if (bfd_session_get_by_name(yang_dnode_get_string(args->dnode, "bfd-name"))) { + snprintf(args->errmsg, args->errmsg_len, "bfd name already exist."); return NB_ERR_VALIDATION; } return NB_OK; @@ -199,8 +196,7 @@ static int bfd_session_create(struct nb_cb_create_args *args, bool mhop, uint32 break; case NB_EV_PREPARE: - if (bfd_mode == BFD_MODE_TYPE_BFD) - { + if (bfd_mode == BFD_MODE_TYPE_BFD) { bfd_session_get_key(mhop, args->dnode, &bk); bs = bfd_key_lookup(bk); @@ -228,9 +224,8 @@ static int bfd_session_create(struct nb_cb_create_args *args, bool mhop, uint32 args->resource->ptr = bs; break; - } - else if (bfd_mode == BFD_MODE_TYPE_SBFD_ECHO || bfd_mode == BFD_MODE_TYPE_SBFD_INIT) - { + } else if (bfd_mode == BFD_MODE_TYPE_SBFD_ECHO || + bfd_mode == BFD_MODE_TYPE_SBFD_INIT) { sbfd_session_get_key(mhop, args->dnode, &bk); bs = bfd_key_lookup(bk); @@ -244,58 +239,58 @@ static int bfd_session_create(struct nb_cb_create_args *args, bool mhop, uint32 break; } - //todo: set segnum according to segment-list - segnum = yang_dnode_exists(args->dnode, "segment-list")?1: 0; - if (bfd_mode == BFD_MODE_TYPE_SBFD_ECHO && !yang_dnode_exists(args->dnode, "segment-list")){ + //todo: set segnum according to segment-list + segnum = yang_dnode_exists(args->dnode, "segment-list") ? 1 : 0; + if (bfd_mode == BFD_MODE_TYPE_SBFD_ECHO && + !yang_dnode_exists(args->dnode, "segment-list")) { //currenty segment-list should not be null - snprintf( - args->errmsg, args->errmsg_len, - "segment-list should not be null"); + snprintf(args->errmsg, args->errmsg_len, + "segment-list should not be null"); return NB_ERR_RESOURCE; } - if (bfd_mode == BFD_MODE_TYPE_SBFD_ECHO && !yang_dnode_exists(args->dnode, "source-ipv6")){ - snprintf( - args->errmsg, args->errmsg_len, - "source_ipv6 should not be null"); + if (bfd_mode == BFD_MODE_TYPE_SBFD_ECHO && + !yang_dnode_exists(args->dnode, "source-ipv6")) { + snprintf(args->errmsg, args->errmsg_len, + "source_ipv6 should not be null"); return NB_ERR_RESOURCE; } - if (bfd_mode == BFD_MODE_TYPE_SBFD_INIT) - { - if (!yang_dnode_exists(args->dnode, "remote-discr")){ - snprintf( - args->errmsg, args->errmsg_len, - "remote-discr should not be null"); + if (bfd_mode == BFD_MODE_TYPE_SBFD_INIT) { + if (!yang_dnode_exists(args->dnode, "remote-discr")) { + snprintf(args->errmsg, args->errmsg_len, + "remote-discr should not be null"); return NB_ERR_RESOURCE; - } - } + } + } bfd_name = yang_dnode_get_string(args->dnode, "bfd-name"); bs = bfd_session_new(bfd_mode, segnum); if (bs == NULL) { - snprintf( - args->errmsg, args->errmsg_len, - "session-new: allocation failed"); + snprintf(args->errmsg, args->errmsg_len, + "session-new: allocation failed"); return NB_ERR_RESOURCE; } /* Fill the session key. */ sbfd_session_get_key(mhop, args->dnode, &bs->key); strlcpy(bs->bfd_name, bfd_name, BFD_NAME_SIZE); - if(segnum) - { - strtosa(yang_dnode_get_string(args->dnode, "./segment-list"), &slist); - memcpy(&bs->seg_list[0], &slist.sa_sin6.sin6_addr, sizeof(struct in6_addr)); + if (segnum) { + strtosa(yang_dnode_get_string(args->dnode, "./segment-list"), + &slist); + memcpy(&bs->seg_list[0], &slist.sa_sin6.sin6_addr, + sizeof(struct in6_addr)); - strtosa(yang_dnode_get_string(args->dnode, "./source-ipv6"), &out_sip6); - memcpy(&bs->out_sip6, &out_sip6.sa_sin6.sin6_addr, sizeof(struct in6_addr)); + strtosa(yang_dnode_get_string(args->dnode, "./source-ipv6"), + &out_sip6); + memcpy(&bs->out_sip6, &out_sip6.sa_sin6.sin6_addr, + sizeof(struct in6_addr)); } - if (bfd_mode == BFD_MODE_TYPE_SBFD_INIT) - { - bs->discrs.remote_discr = yang_dnode_get_uint32(args->dnode, "./remote-discr"); + if (bfd_mode == BFD_MODE_TYPE_SBFD_INIT) { + bs->discrs.remote_discr = yang_dnode_get_uint32(args->dnode, + "./remote-discr"); } /* Set configuration flags. */ @@ -306,24 +301,19 @@ static int bfd_session_create(struct nb_cb_create_args *args, bool mhop, uint32 if (bs->key.family == AF_INET6) SET_FLAG(bs->flags, BFD_SESS_FLAG_IPV6); - - if (bfd_mode == BFD_MODE_TYPE_SBFD_ECHO) - { + + if (bfd_mode == BFD_MODE_TYPE_SBFD_ECHO) { memcpy(&bs->key.peer, &bs->key.local, sizeof(struct in6_addr)); - } - else - { + } else { bs->xmt_TO = bs->timers.desired_min_tx; - bs->detect_TO = bs->detect_mult * bs->xmt_TO; + bs->detect_TO = bs->detect_mult * bs->xmt_TO; } args->resource->ptr = bs; break; - } - else - { - snprintf(args->errmsg, args->errmsg_len,"bfd mode must be bfd or sbfd."); + } else { + snprintf(args->errmsg, args->errmsg_len, "bfd mode must be bfd or sbfd."); return NB_ERR_VALIDATION; } @@ -347,19 +337,18 @@ static int bfd_session_create(struct nb_cb_create_args *args, bool mhop, uint32 return NB_OK; } -static int bfd_session_destroy(enum nb_event event, - const struct lyd_node *dnode, bool mhop, uint32_t bfd_mode) +static int bfd_session_destroy(enum nb_event event, const struct lyd_node *dnode, bool mhop, + uint32_t bfd_mode) { struct bfd_session *bs; struct bfd_key bk; switch (event) { case NB_EV_VALIDATE: - if(bfd_mode == BFD_MODE_TYPE_BFD){ - bfd_session_get_key(mhop, dnode, &bk); - }else{ + if (bfd_mode == BFD_MODE_TYPE_BFD) + bfd_session_get_key(mhop, dnode, &bk); + else sbfd_session_get_key(mhop, dnode, &bk); - } if (bfd_key_lookup(bk) == NULL) return NB_ERR_INCONSISTENCY; @@ -382,11 +371,10 @@ static int bfd_session_destroy(enum nb_event event, break; if (bglobal.debug_peer_event) - zlog_info("bfd_session_destroy: %s", bs_to_string(bs)); + zlog_info("session destroy: %s", bs_to_string(bs)); - if (bfd_mode == BFD_MODE_TYPE_SBFD_ECHO || bfd_mode == BFD_MODE_TYPE_SBFD_INIT){ + if (bfd_mode == BFD_MODE_TYPE_SBFD_ECHO || bfd_mode == BFD_MODE_TYPE_SBFD_INIT) ptm_bfd_notify(bs, PTM_BFD_DOWN); - } bfd_session_free(bs); break; @@ -957,18 +945,16 @@ int bfdd_bfd_sessions_single_hop_passive_mode_modify( * XPath: /frr-bfdd:bfdd/bfd/sessions/srte-sbfd-init/bfd-mode * /frr-bfdd:bfdd/bfd/sessions/srte-sbfd-echo/bfd-mode */ -int bfdd_bfd_sessions_bfd_mode_modify( - struct nb_cb_modify_args *args) +int bfdd_bfd_sessions_bfd_mode_modify(struct nb_cb_modify_args *args) { - uint32_t bfd_mode; - bfd_mode = yang_dnode_get_uint32(args->dnode, NULL); + uint32_t bfd_mode = yang_dnode_get_uint32(args->dnode, NULL); struct bfd_session *bs; switch (args->event) { case NB_EV_VALIDATE: - if ((bfd_mode != BFD_MODE_TYPE_BFD) && (bfd_mode != BFD_MODE_TYPE_SBFD_ECHO) && (bfd_mode != BFD_MODE_TYPE_SBFD_INIT)) - { - snprintf(args->errmsg, args->errmsg_len,"bfd mode is invalid."); + if ((bfd_mode != BFD_MODE_TYPE_BFD) && (bfd_mode != BFD_MODE_TYPE_SBFD_ECHO) && + (bfd_mode != BFD_MODE_TYPE_SBFD_INIT)) { + snprintf(args->errmsg, args->errmsg_len, "bfd mode is invalid."); return NB_ERR_VALIDATION; } return NB_OK; @@ -989,8 +975,7 @@ int bfdd_bfd_sessions_bfd_mode_modify( return NB_OK; } -int bfdd_bfd_sessions_bfd_mode_destroy( - struct nb_cb_destroy_args *args) +int bfdd_bfd_sessions_bfd_mode_destroy(struct nb_cb_destroy_args *args) { return NB_OK; } @@ -1073,7 +1058,7 @@ int bfdd_bfd_sessions_single_hop_required_echo_receive_interval_modify( switch (args->event) { case NB_EV_VALIDATE: if (echo_interval == 0) - return NB_OK; + return NB_OK; if (echo_interval < 10000 || echo_interval > 60000000) return NB_ERR_VALIDATION; break; @@ -1139,8 +1124,7 @@ int bfdd_bfd_sessions_multi_hop_minimum_ttl_modify( return NB_OK; } -int bfdd_bfd_sessions_multi_hop_minimum_ttl_destroy( - struct nb_cb_destroy_args *args) +int bfdd_bfd_sessions_multi_hop_minimum_ttl_destroy(struct nb_cb_destroy_args *args) { struct bfd_session *bs; @@ -1181,14 +1165,12 @@ int bfdd_bfd_sessions_srte_sbfd_echo_destroy(struct nb_cb_destroy_args *args) * XPath: /frr-bfdd:bfdd/bfd/sessions/srte-sbfd-echo/segment-list * XPath: /frr-bfdd:bfdd/bfd/sessions/srte-sbfd-init/segment-list */ -int bfdd_bfd_sessions_segment_list_modify( - struct nb_cb_modify_args *args) +int bfdd_bfd_sessions_segment_list_modify(struct nb_cb_modify_args *args) { return NB_OK; } -int bfdd_bfd_sessions_segment_list_destroy( - struct nb_cb_destroy_args *args) +int bfdd_bfd_sessions_segment_list_destroy(struct nb_cb_destroy_args *args) { return NB_OK; } @@ -1196,14 +1178,12 @@ int bfdd_bfd_sessions_segment_list_destroy( /* * XPath: /frr-bfdd:bfdd/bfd/sessions/srte-sbfd-echo/dest-addr */ -int bfdd_bfd_sessions_srte_sbfd_echo_dest_addr_modify( - struct nb_cb_modify_args *args) +int bfdd_bfd_sessions_srte_sbfd_echo_dest_addr_modify(struct nb_cb_modify_args *args) { return NB_OK; } -int bfdd_bfd_sessions_srte_sbfd_echo_dest_addr_destroy( - struct nb_cb_destroy_args *args) +int bfdd_bfd_sessions_srte_sbfd_echo_dest_addr_destroy(struct nb_cb_destroy_args *args) { return NB_OK; } @@ -1211,8 +1191,7 @@ int bfdd_bfd_sessions_srte_sbfd_echo_dest_addr_destroy( /* * XPath: /frr-bfdd:bfdd/bfd/sessions/srte-sbfd-echo/echo-mode */ -int bfdd_bfd_sessions_srte_sbfd_echo_mode_modify( - struct nb_cb_modify_args *args) +int bfdd_bfd_sessions_srte_sbfd_echo_mode_modify(struct nb_cb_modify_args *args) { return NB_OK; } @@ -1221,14 +1200,12 @@ int bfdd_bfd_sessions_srte_sbfd_echo_mode_modify( * XPath: /frr-bfdd:bfdd/bfd/sessions/srte-sbfd-echo/source-ipv6 * XPath: /frr-bfdd:bfdd/bfd/sessions/srte-sbfd-init/source-ipv6 */ -int bfdd_bfd_sessions_srte_sbfd_source_ipv6_modify( - struct nb_cb_modify_args *args) +int bfdd_bfd_sessions_srte_sbfd_source_ipv6_modify(struct nb_cb_modify_args *args) { return NB_OK; } -int bfdd_bfd_sessions_srte_sbfd_source_ipv6_destroy( - struct nb_cb_destroy_args *args) +int bfdd_bfd_sessions_srte_sbfd_source_ipv6_destroy(struct nb_cb_destroy_args *args) { return NB_OK; } diff --git a/bfdd/bfdd_nb_state.c b/bfdd/bfdd_nb_state.c index 3d3fc05c4e0d..c4415b90c9df 100644 --- a/bfdd/bfdd_nb_state.c +++ b/bfdd/bfdd_nb_state.c @@ -362,8 +362,7 @@ bfdd_bfd_sessions_multi_hop_lookup_entry(struct nb_cb_lookup_entry_args *args) /* * XPath: /frr-bfdd:bfdd/bfd/sessions/srte-sbfd-echo */ -const void * -bfdd_bfd_sessions_srte_sbfd_echo_get_next(struct nb_cb_get_next_args *args) +const void *bfdd_bfd_sessions_srte_sbfd_echo_get_next(struct nb_cb_get_next_args *args) { return bfd_session_next(args->list_entry, true, BFD_MODE_TYPE_SBFD_ECHO); } @@ -383,8 +382,7 @@ int bfdd_bfd_sessions_srte_sbfd_echo_get_keys(struct nb_cb_get_keys_args *args) return NB_OK; } -const void * -bfdd_bfd_sessions_srte_sbfd_echo_lookup_entry(struct nb_cb_lookup_entry_args *args) +const void *bfdd_bfd_sessions_srte_sbfd_echo_lookup_entry(struct nb_cb_lookup_entry_args *args) { const char *source_addr = args->keys->key[0]; const char *bfdname = args->keys->key[1]; @@ -402,8 +400,7 @@ bfdd_bfd_sessions_srte_sbfd_echo_lookup_entry(struct nb_cb_lookup_entry_args *ar /* * XPath: /frr-bfdd:bfdd/bfd/sessions/srte-sbfd-init */ -const void * -bfdd_bfd_sessions_srte_sbfd_init_get_next(struct nb_cb_get_next_args *args) +const void *bfdd_bfd_sessions_srte_sbfd_init_get_next(struct nb_cb_get_next_args *args) { return bfd_session_next(args->list_entry, true, BFD_MODE_TYPE_SBFD_INIT); } @@ -426,8 +423,7 @@ int bfdd_bfd_sessions_srte_sbfd_init_get_keys(struct nb_cb_get_keys_args *args) return NB_OK; } -const void * -bfdd_bfd_sessions_srte_sbfd_init_lookup_entry(struct nb_cb_lookup_entry_args *args) +const void *bfdd_bfd_sessions_srte_sbfd_init_lookup_entry(struct nb_cb_lookup_entry_args *args) { const char *source_addr = args->keys->key[0]; const char *dest_addr = args->keys->key[1]; @@ -441,4 +437,4 @@ bfdd_bfd_sessions_srte_sbfd_init_lookup_entry(struct nb_cb_lookup_entry_args *ar gen_bfd_key(&bk, &psa, &lsa, true, NULL, vrf, bfdname); return bfd_key_lookup(bk); -} \ No newline at end of file +} diff --git a/bfdd/bfdd_vty.c b/bfdd/bfdd_vty.c index 9b04a2b501b3..80a0619ab2f9 100644 --- a/bfdd/bfdd_vty.c +++ b/bfdd/bfdd_vty.c @@ -60,24 +60,27 @@ _find_peer_or_error(struct vty *vty, int argc, struct cmd_token **argv, const char *vrfname); static void _display_bfd_by_bfdname_json_iter(struct hash_bucket *hb, void *arg); static void _display_bfd_by_bfdname_iter(struct hash_bucket *hb, void *arg); -static void _display_bfd_by_bfdname(struct vty *vty, const char *vrfname, const char *bfdname, bool use_json); +static void _display_bfd_by_bfdname(struct vty *vty, const char *vrfname, const char *bfdname, + bool use_json); static void _display_bfd_counters_by_bfdname_iter(struct hash_bucket *hb, void *arg); static void _display_bfd_counters_json_by_bfdname_iter(struct hash_bucket *hb, void *arg); -static void _display_bfd_counters_by_bfdname(struct vty *vty, const char *vrfname, const char *bfdname, bool use_json); +static void _display_bfd_counters_by_bfdname(struct vty *vty, const char *vrfname, + const char *bfdname, bool use_json); static void _clear_bfd_counters_by_bfdname(const char *vrfname, const char *bfdname); static void _clear_peer_counter(struct bfd_session *bs); -static const char *bfd_mode_type_to_string(enum bfd_mode_type mode) { - switch (mode) { - case BFD_MODE_TYPE_BFD: - return "bfd"; - case BFD_MODE_TYPE_SBFD_ECHO: - return "sbfd-echo"; - case BFD_MODE_TYPE_SBFD_INIT: - return "sbfd-init"; - default: - return "Unknown"; - } +static const char *bfd_mode_type_to_string(enum bfd_mode_type mode) +{ + switch (mode) { + case BFD_MODE_TYPE_BFD: + return "bfd"; + case BFD_MODE_TYPE_SBFD_ECHO: + return "sbfd-echo"; + case BFD_MODE_TYPE_SBFD_INIT: + return "sbfd-init"; + default: + return "Unknown"; + } } @@ -91,43 +94,36 @@ static void _display_peer_header(struct vty *vty, struct bfd_session *bs) vty_out(vty, "\tpeer %s", inet_ntop(bs->key.family, &bs->key.peer, addr_buf, sizeof(addr_buf))); - if (bs->bfd_mode == BFD_MODE_TYPE_BFD){ + if (bs->bfd_mode == BFD_MODE_TYPE_BFD) { if (CHECK_FLAG(bs->flags, BFD_SESS_FLAG_MH)) vty_out(vty, " multihop"); } if (bs->bfd_mode == BFD_MODE_TYPE_SBFD_ECHO || bs->bfd_mode == BFD_MODE_TYPE_SBFD_INIT) vty_out(vty, " bfd-mode %s", bfd_mode_type_to_string(bs->bfd_mode)); - + if (bs->bfd_name[0]) - { vty_out(vty, " bfd-name %s", bs->bfd_name); - } if (memcmp(&bs->key.local, &zero_addr, sizeof(bs->key.local))) vty_out(vty, " local-address %s", inet_ntop(bs->key.family, &bs->key.local, addr_buf, sizeof(addr_buf))); - if (bs->bfd_mode == BFD_MODE_TYPE_SBFD_ECHO || bs->bfd_mode == BFD_MODE_TYPE_SBFD_INIT) - { + if (bs->bfd_mode == BFD_MODE_TYPE_SBFD_ECHO || bs->bfd_mode == BFD_MODE_TYPE_SBFD_INIT) { if (bs->bfd_mode == BFD_MODE_TYPE_SBFD_INIT) - { vty_out(vty, " remote-discr %u", bs->discrs.remote_discr); - } - if (bs->bfd_name[0] && bs->segnum) - { + + if (bs->bfd_name[0] && bs->segnum) { vty_out(vty, " encap-type %s", "SRv6"); vty_out(vty, " encap-data %s", - inet_ntop(AF_INET6, &bs->seg_list[0], addr_buf, - sizeof(addr_buf))); + inet_ntop(AF_INET6, &bs->seg_list[0], addr_buf, sizeof(addr_buf))); vty_out(vty, " source-ipv6 %s", - inet_ntop(AF_INET6, &bs->out_sip6, addr_buf, - sizeof(addr_buf))); + inet_ntop(AF_INET6, &bs->out_sip6, addr_buf, sizeof(addr_buf))); } } - if (bs->key.vrfname[0]) + if (bs->key.vrfname[0]) vty_out(vty, " vrf %s", bs->key.vrfname); if (bs->key.ifname[0]) vty_out(vty, " interface %s", bs->key.ifname); @@ -183,20 +179,15 @@ static void _display_peer(struct vty *vty, struct bfd_session *bs) vty_out(vty, "\t\tDiagnostics: %s\n", diag2str(bs->local_diag)); vty_out(vty, "\t\tRemote diagnostics: %s\n", diag2str(bs->remote_diag)); - if (bs->bfd_mode == BFD_MODE_TYPE_SBFD_INIT) - { + if (bs->bfd_mode == BFD_MODE_TYPE_SBFD_INIT) { vty_out(vty, "\t\tPeer Type: sbfd initiator\n"); - } - else if (bs->bfd_mode == BFD_MODE_TYPE_SBFD_ECHO) - { - vty_out(vty, "\t\tPeer Type: echo\n"); - } - else - { - vty_out(vty, "\t\tPeer Type: %s\n", - CHECK_FLAG(bs->flags, BFD_SESS_FLAG_CONFIG) ? "configured" : "dynamic"); - _display_rtt(&min, &avg, &max, bs); - vty_out(vty, "\t\tRTT min/avg/max: %u/%u/%u usec\n", min, avg, max); + } else if (bs->bfd_mode == BFD_MODE_TYPE_SBFD_ECHO) { + vty_out(vty, "\t\tPeer Type: echo\n"); + } else { + vty_out(vty, "\t\tPeer Type: %s\n", + CHECK_FLAG(bs->flags, BFD_SESS_FLAG_CONFIG) ? "configured" : "dynamic"); + _display_rtt(&min, &avg, &max, bs); + vty_out(vty, "\t\tRTT min/avg/max: %u/%u/%u usec\n", min, avg, max); } vty_out(vty, "\t\tLocal timers:\n"); @@ -211,37 +202,31 @@ static void _display_peer(struct vty *vty, struct bfd_session *bs) bs->timers.required_min_echo_rx / 1000); else vty_out(vty, "\t\t\tEcho receive interval: disabled\n"); - if (CHECK_FLAG(bs->flags, BFD_SESS_FLAG_ECHO) - || bs->bfd_mode == BFD_MODE_TYPE_SBFD_ECHO) + if (CHECK_FLAG(bs->flags, BFD_SESS_FLAG_ECHO) || bs->bfd_mode == BFD_MODE_TYPE_SBFD_ECHO) vty_out(vty, "\t\t\tEcho transmission interval: %ums\n", - bs->timers.desired_min_echo_tx / 1000); + bs->timers.desired_min_echo_tx / 1000); else vty_out(vty, "\t\t\tEcho transmission interval: disabled\n"); - if (bs->bfd_mode == BFD_MODE_TYPE_SBFD_INIT - || bs->bfd_mode == BFD_MODE_TYPE_SBFD_ECHO) - { + if (bs->bfd_mode == BFD_MODE_TYPE_SBFD_INIT || bs->bfd_mode == BFD_MODE_TYPE_SBFD_ECHO) { vty_out(vty, "\t\tRemote timers:\n"); vty_out(vty, "\t\t\tDetect-multiplier: -\n"); vty_out(vty, "\t\t\tReceive interval: -\n"); vty_out(vty, "\t\t\tTransmission interval: -\n"); vty_out(vty, "\t\t\tEcho receive interval: -\n"); - } - else - { - vty_out(vty, "\t\tRemote timers:\n"); - vty_out(vty, "\t\t\tDetect-multiplier: %u\n", - bs->remote_detect_mult); - vty_out(vty, "\t\t\tReceive interval: %ums\n", - bs->remote_timers.required_min_rx / 1000); - vty_out(vty, "\t\t\tTransmission interval: %ums\n", - bs->remote_timers.desired_min_tx / 1000); - if (bs->remote_timers.required_min_echo != 0) - vty_out(vty, "\t\t\tEcho receive interval: %ums\n", - bs->remote_timers.required_min_echo / 1000); - else - vty_out(vty, "\t\t\tEcho receive interval: disabled\n"); + } else { + vty_out(vty, "\t\tRemote timers:\n"); + vty_out(vty, "\t\t\tDetect-multiplier: %u\n", bs->remote_detect_mult); + vty_out(vty, "\t\t\tReceive interval: %ums\n", + bs->remote_timers.required_min_rx / 1000); + vty_out(vty, "\t\t\tTransmission interval: %ums\n", + bs->remote_timers.desired_min_tx / 1000); + if (bs->remote_timers.required_min_echo != 0) + vty_out(vty, "\t\t\tEcho receive interval: %ums\n", + bs->remote_timers.required_min_echo / 1000); + else + vty_out(vty, "\t\t\tEcho receive interval: disabled\n"); } vty_out(vty, "\n"); @@ -329,17 +314,13 @@ static struct json_object *__display_peer_json(struct bfd_session *bs) bs->timers.desired_min_tx / 1000); json_object_int_add(jo, "echo-receive-interval", bs->timers.required_min_echo_rx / 1000); - if (bs->bfd_mode == BFD_MODE_TYPE_SBFD_INIT - || bs->bfd_mode == BFD_MODE_TYPE_SBFD_ECHO) - { + if (bs->bfd_mode == BFD_MODE_TYPE_SBFD_INIT || bs->bfd_mode == BFD_MODE_TYPE_SBFD_ECHO) { json_object_int_add(jo, "configured-echo-transmit-interval", - bs->timers.desired_min_echo_tx / 1000); - json_object_int_add(jo, "current-echo-transmit-interval", - bs->echo_xmt_TO / 1000); + bs->timers.desired_min_echo_tx / 1000); + json_object_int_add(jo, "current-echo-transmit-interval", bs->echo_xmt_TO / 1000); json_object_int_add(jo, "current-detect-echo-receive-interval", - bs->echo_detect_TO / 1000); - } - else if (CHECK_FLAG(bs->flags, BFD_SESS_FLAG_ECHO)) + bs->echo_detect_TO / 1000); + } else if (CHECK_FLAG(bs->flags, BFD_SESS_FLAG_ECHO)) json_object_int_add(jo, "echo-transmit-interval", bs->timers.desired_min_echo_tx / 1000); else @@ -407,13 +388,12 @@ static void _display_bfd_by_bfdname_iter(struct hash_bucket *hb, void *arg) vty = bvt->vty; if (bvt->vrfname) { - if (!bs->key.vrfname[0] || - !strmatch(bs->key.vrfname, bvt->vrfname)) + if (!bs->key.vrfname[0] || !strmatch(bs->key.vrfname, bvt->vrfname)) return; } if (bvt->bfdname) { - if ((!bs->key.bfdname[0] || !strmatch(bs->key.bfdname, bvt->bfdname)) && + if ((!bs->key.bfdname[0] || !strmatch(bs->key.bfdname, bvt->bfdname)) && (!bs->bfd_name[0] || !strmatch(bs->bfd_name, bvt->bfdname))) return; } @@ -457,13 +437,12 @@ static void _display_bfd_by_bfdname_json_iter(struct hash_bucket *hb, void *arg) jo = bvt->jo; if (bvt->vrfname) { - if (!bs->key.vrfname[0] || - !strmatch(bs->key.vrfname, bvt->vrfname)) + if (!bs->key.vrfname[0] || !strmatch(bs->key.vrfname, bvt->vrfname)) return; } if (bvt->bfdname) { - if ((!bs->key.bfdname[0] || !strmatch(bs->key.bfdname, bvt->bfdname)) && + if ((!bs->key.bfdname[0] || !strmatch(bs->key.bfdname, bvt->bfdname)) && (!bs->bfd_name[0] || !strmatch(bs->bfd_name, bvt->bfdname))) return; } @@ -476,10 +455,11 @@ static void _display_bfd_by_bfdname_json_iter(struct hash_bucket *hb, void *arg) json_object_array_add(jo, jon); } -static void _display_bfd_by_bfdname(struct vty *vty, const char *vrfname, const char *bfdname, bool use_json) +static void _display_bfd_by_bfdname(struct vty *vty, const char *vrfname, const char *bfdname, + bool use_json) { struct json_object *jo; - struct bfd_vrf_tuple bvt = {0}; + struct bfd_vrf_tuple bvt = { 0 }; bvt.vrfname = vrfname; bvt.bfdname = bfdname; @@ -542,8 +522,7 @@ static void _display_peer_counter(struct vty *vty, struct bfd_session *bs) bs->stats.session_down); vty_out(vty, "\t\tZebra notifications: %" PRIu64 "\n", bs->stats.znotification); - vty_out(vty, "\t\tTx fail packet: %" PRIu64 "\n", - bs->stats.tx_fail_pkt); + vty_out(vty, "\t\tTx fail packet: %" PRIu64 "\n", bs->stats.tx_fail_pkt); vty_out(vty, "\n"); } @@ -650,14 +629,12 @@ static void _display_bfd_counters_by_bfdname_iter(struct hash_bucket *hb, void * vty = bvt->vty; if (bvt->vrfname) { - if (!bs->key.vrfname[0] || - !strmatch(bs->key.vrfname, bvt->vrfname)) + if (!bs->key.vrfname[0] || !strmatch(bs->key.vrfname, bvt->vrfname)) return; } - if (bvt->bfdname){ - if (!bs->key.bfdname[0] || - !strmatch(bs->key.bfdname, bvt->bfdname)) + if (bvt->bfdname) { + if (!bs->key.bfdname[0] || !strmatch(bs->key.bfdname, bvt->bfdname)) return; } @@ -671,17 +648,15 @@ static void _display_bfd_counters_json_by_bfdname_iter(struct hash_bucket *hb, v if (!bvt) return; - jo = bvt->jo; + jo = bvt->jo; if (bvt->vrfname) { - if (!bs->key.vrfname[0] || - !strmatch(bs->key.vrfname, bvt->vrfname)) + if (!bs->key.vrfname[0] || !strmatch(bs->key.vrfname, bvt->vrfname)) return; } - if (bvt->bfdname){ - if (!bs->key.bfdname[0] || - !strmatch(bs->key.bfdname, bvt->bfdname)) + if (bvt->bfdname) { + if (!bs->key.bfdname[0] || !strmatch(bs->key.bfdname, bvt->bfdname)) return; } @@ -693,10 +668,11 @@ static void _display_bfd_counters_json_by_bfdname_iter(struct hash_bucket *hb, v json_object_array_add(jo, jon); } -static void _display_bfd_counters_by_bfdname(struct vty *vty, const char *vrfname, const char *bfdname, bool use_json) +static void _display_bfd_counters_by_bfdname(struct vty *vty, const char *vrfname, + const char *bfdname, bool use_json) { struct json_object *jo; - struct bfd_vrf_tuple bvt = {0}; + struct bfd_vrf_tuple bvt = { 0 }; bvt.vrfname = vrfname; bvt.bfdname = bfdname; @@ -723,14 +699,12 @@ static void _clear_bfd_counters_by_bfdname_iter(struct hash_bucket *hb, void *ar return; if (bvt->vrfname) { - if (!bs->key.vrfname[0] || - !strmatch(bs->key.vrfname, bvt->vrfname)) + if (!bs->key.vrfname[0] || !strmatch(bs->key.vrfname, bvt->vrfname)) return; } - if (bvt->bfdname){ - if (!bs->key.bfdname[0] || - !strmatch(bs->key.bfdname, bvt->bfdname)) + if (bvt->bfdname) { + if (!bs->key.bfdname[0] || !strmatch(bs->key.bfdname, bvt->bfdname)) return; } @@ -739,13 +713,12 @@ static void _clear_bfd_counters_by_bfdname_iter(struct hash_bucket *hb, void *ar static void _clear_bfd_counters_by_bfdname(const char *vrfname, const char *bfdname) { - struct bfd_vrf_tuple bvt = {0}; + struct bfd_vrf_tuple bvt = { 0 }; bvt.vrfname = vrfname; bvt.bfdname = bfdname; bfd_id_iterate(_clear_bfd_counters_by_bfdname_iter, &bvt); - return; } static void _clear_peer_counter(struct bfd_session *bs) @@ -864,12 +837,11 @@ _find_peer_or_error(struct vty *vty, int argc, struct cmd_token **argv, vty_out(vty, "%% Vrf is not exist: %s\n", vrfname); return NULL; } - tmpName = vrf->name; + tmpName = vrf->name; } - if (bfd_configure_peer(&bpc, mhop, &psa, lsap, ifname, tmpName, - errormsg, sizeof(errormsg)) - != 0) { + if (bfd_configure_peer(&bpc, mhop, &psa, lsap, ifname, tmpName, errormsg, + sizeof(errormsg)) != 0) { vty_out(vty, "%% Invalid peer configuration: %s\n", errormsg); return NULL; @@ -937,7 +909,6 @@ DEFPY(bfd_show_by_bfdname, bfd_show_by_bfdname_cmd, "bfd session name\n" JSON_STR) { - _display_bfd_by_bfdname(vty, vrf_name, bfdname, use_json(argc, argv)); return CMD_SUCCESS; @@ -967,7 +938,7 @@ DEFPY(bfd_clear_counters_by_bfdname, bfd_clear_counters_by_bfdname_cmd, "bfd session name\n" "clear BFD peer counters information\n") { - _clear_bfd_counters_by_bfdname(vrfname, bfdname); + _clear_bfd_counters_by_bfdname(vrfname, bfdname); return CMD_SUCCESS; } @@ -1317,14 +1288,15 @@ static void _sbfd_reflector_write_config(struct hash_bucket *hb, void *arg) struct sbfd_reflector *sr = hb->data; char buf[INET6_ADDRSTRLEN]; struct vty *vty; - vty = (struct vty *) arg; + + vty = (struct vty *)arg; inet_ntop(AF_INET6, &sr->local, buf, sizeof(buf)); vty_out(vty, " sbfd reflector source-address %s discriminator %u\n", buf, sr->discr); } static void sbfd_reflector_write_config(struct vty *vty) { - sbfd_discr_iterate(_sbfd_reflector_write_config, vty); + sbfd_discr_iterate(_sbfd_reflector_write_config, vty); } static int bfdd_write_config(struct vty *vty) @@ -1359,7 +1331,7 @@ static int bfdd_write_config(struct vty *vty) } /*sbfd config*/ - sbfd_reflector_write_config(vty); + sbfd_reflector_write_config(vty); return written; } @@ -1370,7 +1342,7 @@ void bfdd_vty_init(void) install_element(ENABLE_NODE, &bfd_show_peer_counters_cmd); install_element(ENABLE_NODE, &bfd_clear_peer_counters_cmd); install_element(ENABLE_NODE, &bfd_show_peers_cmd); - install_element(ENABLE_NODE, &bfd_show_by_bfdname_cmd); + install_element(ENABLE_NODE, &bfd_show_by_bfdname_cmd); install_element(ENABLE_NODE, &bfd_show_counters_by_bfdname_cmd); install_element(ENABLE_NODE, &bfd_clear_counters_by_bfdname_cmd); install_element(ENABLE_NODE, &bfd_show_peer_cmd); diff --git a/bfdd/event.c b/bfdd/event.c index 8742496b9410..e5f43b6cc698 100644 --- a/bfdd/event.c +++ b/bfdd/event.c @@ -60,53 +60,48 @@ void bfd_echo_recvtimer_update(struct bfd_session *bs) void sbfd_init_recvtimer_update(struct bfd_session *bs) { - struct timeval tv = {.tv_sec = 0, .tv_usec = bs->detect_TO}; + struct timeval tv = { .tv_sec = 0, .tv_usec = bs->detect_TO }; /* Remove previous schedule if any. */ sbfd_init_recvtimer_delete(bs); /* Don't add event if peer is deactivated. */ - if (CHECK_FLAG(bs->flags, BFD_SESS_FLAG_SHUTDOWN) || - bs->sock == -1) + if (CHECK_FLAG(bs->flags, BFD_SESS_FLAG_SHUTDOWN) || bs->sock == -1) return; tv_normalize(&tv); #ifdef BFD_EVENT_DEBUG - log_debug("%s: sec = %ld, usec = %ld", __func__, tv.tv_sec, tv.tv_usec); + log_debug("%s: sec = %ld, usec = %ld", __func__, tv.tv_sec, tv.tv_usec); #endif /* BFD_EVENT_DEBUG */ - event_add_timer_tv(master, sbfd_init_recvtimer_cb, bs, &tv, - &bs->recvtimer_ev); + event_add_timer_tv(master, sbfd_init_recvtimer_cb, bs, &tv, &bs->recvtimer_ev); } void sbfd_echo_recvtimer_update(struct bfd_session *bs) { - struct timeval tv = {.tv_sec = 0, .tv_usec = bs->echo_detect_TO}; + struct timeval tv = { .tv_sec = 0, .tv_usec = bs->echo_detect_TO }; /* Remove previous schedule if any. */ sbfd_echo_recvtimer_delete(bs); /* Don't add event if peer is deactivated. */ - if (CHECK_FLAG(bs->flags, BFD_SESS_FLAG_SHUTDOWN) || - bs->sock == -1) + if (CHECK_FLAG(bs->flags, BFD_SESS_FLAG_SHUTDOWN) || bs->sock == -1) return; tv_normalize(&tv); - event_add_timer_tv(master, sbfd_echo_recvtimer_cb, bs, &tv, - &bs->echo_recvtimer_ev); + event_add_timer_tv(master, sbfd_echo_recvtimer_cb, bs, &tv, &bs->echo_recvtimer_ev); } void sbfd_init_xmttimer_update(struct bfd_session *bs, uint64_t jitter) { - struct timeval tv = {.tv_sec = 0, .tv_usec = jitter}; + struct timeval tv = { .tv_sec = 0, .tv_usec = jitter }; /* Remove previous schedule if any. */ sbfd_init_xmttimer_delete(bs); /* Don't add event if peer is deactivated. */ - if (CHECK_FLAG(bs->flags, BFD_SESS_FLAG_SHUTDOWN) || - bs->sock == -1) + if (CHECK_FLAG(bs->flags, BFD_SESS_FLAG_SHUTDOWN) || bs->sock == -1) return; tv_normalize(&tv); @@ -116,20 +111,18 @@ void sbfd_init_xmttimer_update(struct bfd_session *bs, uint64_t jitter) void sbfd_echo_xmttimer_update(struct bfd_session *bs, uint64_t jitter) { - struct timeval tv = {.tv_sec = 0, .tv_usec = jitter}; + struct timeval tv = { .tv_sec = 0, .tv_usec = jitter }; /* Remove previous schedule if any. */ sbfd_echo_xmttimer_delete(bs); /* Don't add event if peer is deactivated. */ - if (CHECK_FLAG(bs->flags, BFD_SESS_FLAG_SHUTDOWN) || - bs->sock == -1) + if (CHECK_FLAG(bs->flags, BFD_SESS_FLAG_SHUTDOWN) || bs->sock == -1) return; tv_normalize(&tv); - event_add_timer_tv(master, sbfd_echo_xmt_cb, bs, &tv, - &bs->echo_xmttimer_ev); + event_add_timer_tv(master, sbfd_echo_xmt_cb, bs, &tv, &bs->echo_xmttimer_ev); } void bfd_xmttimer_update(struct bfd_session *bs, uint64_t jitter) @@ -205,4 +198,4 @@ void sbfd_init_xmttimer_delete(struct bfd_session *bs) void sbfd_echo_xmttimer_delete(struct bfd_session *bs) { EVENT_OFF(bs->echo_xmttimer_ev); -} \ No newline at end of file +} diff --git a/bfdd/ptm_adapter.c b/bfdd/ptm_adapter.c index 2387a7ab7d8f..8717e4b5bd0c 100644 --- a/bfdd/ptm_adapter.c +++ b/bfdd/ptm_adapter.c @@ -71,10 +71,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; @@ -137,9 +137,7 @@ static void _ptm_bfd_session_del(struct bfd_session *bs, uint8_t diag) bs->local_diag = diag; if (bs->bfd_mode == BFD_MODE_TYPE_BFD) - { - ptm_bfd_snd(bs, 0); - } + ptm_bfd_snd(bs, 0); /* Session reached refcount == 0, lets delete it. */ if (bs->refcount == 0) { @@ -245,14 +243,11 @@ int ptm_bfd_notify(struct bfd_session *bs, uint8_t notify_state) case PTM_BFD_DOWN: case PTM_BFD_INIT: - if (CHECK_FLAG(bs->flags, BFD_SESS_FLAG_SHUTDOWN|BFD_SESS_FLAG_REM_ADMIN_DOWN)) - { - stream_putl(msg, BFD_STATUS_ADMIN_DOWN); - } - else - { - stream_putl(msg, BFD_STATUS_DOWN); - } + if (CHECK_FLAG(bs->flags, BFD_SESS_FLAG_SHUTDOWN | BFD_SESS_FLAG_REM_ADMIN_DOWN)) + stream_putl(msg, BFD_STATUS_ADMIN_DOWN); + else + stream_putl(msg, BFD_STATUS_DOWN); + break; default: stream_putl(msg, BFD_STATUS_UNKNOWN); @@ -493,13 +488,11 @@ static void bfdd_dest_register(struct stream *msg, vrf_id_t vrf_id) debug_printbpc(&bpc, "ptm-add-dest: register peer"); /* sbfd case: pathd register to a sbfd session. */ - if (bpc.bfd_name[0] != 0) - { + if (bpc.bfd_name[0] != 0) { bs = bfd_session_get_by_name((const char *)bpc.bfd_name); if (bs != NULL) - { ptm_bfd_notify(bs, bs->ses_state); - } + return; } @@ -548,8 +541,8 @@ static void bfdd_dest_deregister(struct stream *msg, vrf_id_t vrf_id) debug_printbpc(&bpc, "ptm-del-dest: deregister peer"); /* Find or start new BFD session. */ - if(bpc.bfd_name[0]) - bs = bfd_session_get_by_name((const char *)bpc.bfd_name); + if (bpc.bfd_name[0]) + bs = bfd_session_get_by_name((const char *)bpc.bfd_name); if (bs == NULL) { bs = bs_peer_find(&bpc); if (bs == NULL) { @@ -557,7 +550,6 @@ static void bfdd_dest_deregister(struct stream *msg, vrf_id_t vrf_id) zlog_debug("ptm-del-dest: failed to find BFD session"); return; } - } /* Unregister client peer notification. */ diff --git a/lib/bfd.c b/lib/bfd.c index 7c0ccdae2c02..d9dc00eb545a 100644 --- a/lib/bfd.c +++ b/lib/bfd.c @@ -23,7 +23,7 @@ DEFINE_MTYPE_STATIC(LIB, BFD_INFO, "BFD info"); DEFINE_MTYPE_STATIC(LIB, BFD_SOURCE, "BFD source cache"); -DEFINE_HOOK(sbfd_state_change_hook, (char *bfd_name, int state),(bfd_name, state)); +DEFINE_HOOK(sbfd_state_change_hook, (char *bfd_name, int state), (bfd_name, state)); /** * BFD protocol integration configuration. */ @@ -142,9 +142,9 @@ 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, char *bfd_name) +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; @@ -199,9 +199,9 @@ static struct interface *bfd_get_peer_info(struct stream *s, struct prefix *dp, *remote_cbit = local_remote_cbit; STREAM_GETC(s, bfd_name_len); - if(bfd_name_len) { + if (bfd_name_len) { STREAM_GET(bfd_name, s, bfd_name_len); - *(bfd_name+bfd_name_len) = 0; + *(bfd_name + bfd_name_len) = 0; } return ifp; @@ -229,7 +229,7 @@ const char *bfd_get_status_str(int status) case BFD_STATUS_ADMIN_DOWN: return "Admin Down"; case BFD_STATUS_DEL: - return "Del"; + return "Del"; case BFD_STATUS_UNKNOWN: default: return "Unknown"; @@ -333,8 +333,8 @@ int zclient_bfd_command(struct zclient *zc, struct bfd_session_arg *args) stream_putc(s, args->bfd_name[0] ? strlen(args->bfd_name) : 0); if (args->bfd_name[0]) - stream_put(s, args->bfd_name, strlen(args->bfd_name)); - + stream_put(s, args->bfd_name, strlen(args->bfd_name)); + /* Encode destination address. */ stream_putw(s, args->family); addrlen = (args->family == AF_INET) ? sizeof(struct in_addr) @@ -936,7 +936,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}; + char bfd_name[BFD_NAME_SIZE + 1] = { 0 }; if (!zclient->bfd_integration) return 0; @@ -984,12 +984,11 @@ int zclient_bfd_session_update(ZAPI_CALLBACK_ARGS) /* Cache current time to avoid multiple monotime clock calls. */ now = monotime(NULL); - - if (bfd_name[0]) - { + + if (bfd_name[0]) { hook_call(sbfd_state_change_hook, bfd_name, state); if (bsglobal.debugging) - zlog_debug("%s: sessions updated: %s", __func__, bfd_name); + zlog_debug("%s: sessions updated: %s", __func__, bfd_name); return 0; } diff --git a/lib/bfd.h b/lib/bfd.h index fa8ec2df5f20..5eae07f6347e 100644 --- a/lib/bfd.h +++ b/lib/bfd.h @@ -23,7 +23,7 @@ extern "C" { #define BFD_STATUS_DOWN (1 << 1) /* BFD session status is down */ #define BFD_STATUS_UP (1 << 2) /* BFD session status is up */ #define BFD_STATUS_ADMIN_DOWN (1 << 3) /* BFD session is admin down */ -#define BFD_STATUS_DEL (1 << 4) /* BFD session is deleted, reserved for sbfd*/ +#define BFD_STATUS_DEL (1 << 4) /* BFD session is deleted, reserved for sbfd*/ #define BFD_PROFILE_NAME_LEN 64 @@ -413,7 +413,7 @@ struct bfd_session_arg { /** Detection multiplier. */ uint32_t detection_multiplier; /* bfd session name*/ - char bfd_name[BFD_NAME_SIZE +1]; + char bfd_name[BFD_NAME_SIZE + 1]; }; /** @@ -463,7 +463,8 @@ extern bool bfd_protocol_integration_shutting_down(void); extern int bfd_nht_update(const struct prefix *match, const struct zapi_route *route); -DECLARE_HOOK(sbfd_state_change_hook, (char *bfd_name, int state,int remote_cbit),(bfd_name, state)); +DECLARE_HOOK(sbfd_state_change_hook, (char *bfd_name, int state, int remote_cbit), + (bfd_name, state)); extern bool bfd_session_is_down(const struct bfd_session_params *session); diff --git a/zebra/zebra_ptm.h b/zebra/zebra_ptm.h index af54aff1edd6..46613ba90edc 100644 --- a/zebra/zebra_ptm.h +++ b/zebra/zebra_ptm.h @@ -48,12 +48,11 @@ struct zebra_ptm_cb { #define ZEBRA_IF_PTM_ENABLE_ON 1 #define ZEBRA_IF_PTM_ENABLE_UNSPEC 2 -#define IS_BFD_ENABLED_PROTOCOL(protocol) \ - ((protocol) == ZEBRA_ROUTE_BGP || (protocol) == ZEBRA_ROUTE_OSPF || \ - (protocol) == ZEBRA_ROUTE_OSPF6 || (protocol) == ZEBRA_ROUTE_ISIS || \ - (protocol) == ZEBRA_ROUTE_PIM || \ - (protocol) == ZEBRA_ROUTE_OPENFABRIC || \ - (protocol) == ZEBRA_ROUTE_STATIC || (protocol) == ZEBRA_ROUTE_RIP || \ +#define IS_BFD_ENABLED_PROTOCOL(protocol) \ + ((protocol) == ZEBRA_ROUTE_BGP || (protocol) == ZEBRA_ROUTE_OSPF || \ + (protocol) == ZEBRA_ROUTE_OSPF6 || (protocol) == ZEBRA_ROUTE_ISIS || \ + (protocol) == ZEBRA_ROUTE_PIM || (protocol) == ZEBRA_ROUTE_OPENFABRIC || \ + (protocol) == ZEBRA_ROUTE_STATIC || (protocol) == ZEBRA_ROUTE_RIP || \ (protocol) == ZEBRA_ROUTE_SRTE)