X-Git-Url: https://git.proxmox.com/?a=blobdiff_plain;f=bgpd%2Fbgp_bfd.c;h=663bc4894a842aae8e262a7c4f7e3b5e60902d07;hb=91d227b7e3cb53ad8fdbcd9d4cff7f0a666918e3;hp=1aa2b93a90e442ca36082014e297c767c8bdabf7;hpb=4e671a08d6bc26f5743b2273389a6b6b29a3850b;p=mirror_frr.git diff --git a/bgpd/bgp_bfd.c b/bgpd/bgp_bfd.c index 1aa2b93a9..663bc4894 100644 --- a/bgpd/bgp_bfd.c +++ b/bgpd/bgp_bfd.c @@ -43,112 +43,110 @@ extern struct zclient *zclient; /* - * bgp_bfd_peer_group2peer_copy - Copy the BFD information from peer group template + * bgp_bfd_peer_group2peer_copy - Copy the BFD information from peer group + * template * to peer. */ -void -bgp_bfd_peer_group2peer_copy(struct peer *conf, struct peer *peer) +void bgp_bfd_peer_group2peer_copy(struct peer *conf, struct peer *peer) { - struct bfd_info *bfd_info; - struct bfd_info *conf_bfd_info; + struct bfd_info *bfd_info; + struct bfd_info *conf_bfd_info; - if (!conf->bfd_info) - return; + if (!conf->bfd_info) + return; - conf_bfd_info = (struct bfd_info *)conf->bfd_info; - if (!peer->bfd_info) - peer->bfd_info = bfd_info_create(); + conf_bfd_info = (struct bfd_info *)conf->bfd_info; + if (!peer->bfd_info) + peer->bfd_info = bfd_info_create(); - bfd_info = (struct bfd_info *)peer->bfd_info; + bfd_info = (struct bfd_info *)peer->bfd_info; - /* Copy BFD parameter values */ - bfd_info->required_min_rx = conf_bfd_info->required_min_rx; - bfd_info->desired_min_tx = conf_bfd_info->desired_min_tx; - bfd_info->detect_mult = conf_bfd_info->detect_mult; - bfd_info->type = conf_bfd_info->type; + /* Copy BFD parameter values */ + bfd_info->required_min_rx = conf_bfd_info->required_min_rx; + bfd_info->desired_min_tx = conf_bfd_info->desired_min_tx; + bfd_info->detect_mult = conf_bfd_info->detect_mult; + bfd_info->type = conf_bfd_info->type; } /* - * bgp_bfd_is_peer_multihop - returns whether BFD peer is multi-hop or single hop. + * bgp_bfd_is_peer_multihop - returns whether BFD peer is multi-hop or single + * hop. */ -int -bgp_bfd_is_peer_multihop(struct peer *peer) +int bgp_bfd_is_peer_multihop(struct peer *peer) { - struct bfd_info *bfd_info; + struct bfd_info *bfd_info; - bfd_info = (struct bfd_info *)peer->bfd_info; + bfd_info = (struct bfd_info *)peer->bfd_info; - if (!bfd_info) - return 0; + if (!bfd_info) + return 0; - if((bfd_info->type == BFD_TYPE_MULTIHOP) || - ((peer->sort == BGP_PEER_IBGP) && !peer->shared_network) || - is_ebgp_multihop_configured(peer)) - return 1; - else - return 0; + if ((bfd_info->type == BFD_TYPE_MULTIHOP) + || ((peer->sort == BGP_PEER_IBGP) && !peer->shared_network) + || is_ebgp_multihop_configured(peer)) + return 1; + else + return 0; } /* * bgp_bfd_peer_sendmsg - Format and send a Peer register/Unregister * command to Zebra to be forwarded to BFD */ -static void -bgp_bfd_peer_sendmsg (struct peer *peer, int command) +static void bgp_bfd_peer_sendmsg(struct peer *peer, int command) { - struct bfd_info *bfd_info; - vrf_id_t vrf_id = VRF_DEFAULT; - int multihop; - - bfd_info = (struct bfd_info *)peer->bfd_info; - - if (peer->bgp && (peer->bgp->inst_type == BGP_INSTANCE_TYPE_VRF)) - vrf_id = peer->bgp->vrf_id; - - if (command == ZEBRA_BFD_DEST_DEREGISTER) - { - multihop = CHECK_FLAG(bfd_info->flags, BFD_FLAG_BFD_TYPE_MULTIHOP); - UNSET_FLAG(bfd_info->flags, BFD_FLAG_BFD_TYPE_MULTIHOP); - } - else - { - multihop = bgp_bfd_is_peer_multihop(peer); - if ((command == ZEBRA_BFD_DEST_REGISTER) && multihop) - SET_FLAG(bfd_info->flags, BFD_FLAG_BFD_TYPE_MULTIHOP); - } - - if (peer->su.sa.sa_family == AF_INET) - bfd_peer_sendmsg (zclient, bfd_info, AF_INET, - &peer->su.sin.sin_addr, - (peer->su_local) ? &peer->su_local->sin.sin_addr : NULL, - (peer->nexthop.ifp) ? peer->nexthop.ifp->name : NULL, - peer->ttl, multihop, command, 1, vrf_id); - else if (peer->su.sa.sa_family == AF_INET6) - bfd_peer_sendmsg (zclient, bfd_info, AF_INET6, - &peer->su.sin6.sin6_addr, - (peer->su_local) ? &peer->su_local->sin6.sin6_addr : NULL, - (peer->nexthop.ifp) ? peer->nexthop.ifp->name : NULL, - peer->ttl, multihop, command, 1, vrf_id); + struct bfd_info *bfd_info; + vrf_id_t vrf_id = VRF_DEFAULT; + int multihop; + + bfd_info = (struct bfd_info *)peer->bfd_info; + + if (peer->bgp->inst_type == BGP_INSTANCE_TYPE_VRF) + vrf_id = peer->bgp->vrf_id; + + if (command == ZEBRA_BFD_DEST_DEREGISTER) { + multihop = + CHECK_FLAG(bfd_info->flags, BFD_FLAG_BFD_TYPE_MULTIHOP); + UNSET_FLAG(bfd_info->flags, BFD_FLAG_BFD_TYPE_MULTIHOP); + } else { + multihop = bgp_bfd_is_peer_multihop(peer); + if ((command == ZEBRA_BFD_DEST_REGISTER) && multihop) + SET_FLAG(bfd_info->flags, BFD_FLAG_BFD_TYPE_MULTIHOP); + } + + if (peer->su.sa.sa_family == AF_INET) + bfd_peer_sendmsg( + zclient, bfd_info, AF_INET, &peer->su.sin.sin_addr, + (peer->su_local) ? &peer->su_local->sin.sin_addr : NULL, + (peer->nexthop.ifp) ? peer->nexthop.ifp->name : NULL, + peer->ttl, multihop, command, 1, vrf_id); + else if (peer->su.sa.sa_family == AF_INET6) + bfd_peer_sendmsg( + zclient, bfd_info, AF_INET6, &peer->su.sin6.sin6_addr, + (peer->su_local) ? &peer->su_local->sin6.sin6_addr + : NULL, + (peer->nexthop.ifp) ? peer->nexthop.ifp->name : NULL, + peer->ttl, multihop, command, 1, vrf_id); } /* * bgp_bfd_register_peer - register a peer with BFD through zebra * for monitoring the peer rechahability. */ -void -bgp_bfd_register_peer (struct peer *peer) +void bgp_bfd_register_peer(struct peer *peer) { - struct bfd_info *bfd_info; + struct bfd_info *bfd_info; - if (!peer->bfd_info) - return; - bfd_info = (struct bfd_info *)peer->bfd_info; + if (!peer->bfd_info) + return; + bfd_info = (struct bfd_info *)peer->bfd_info; - /* Check if BFD is enabled and peer has already been registered with BFD */ - if (CHECK_FLAG(bfd_info->flags, BFD_FLAG_BFD_REG)) - return; + /* Check if BFD is enabled and peer has already been registered with BFD + */ + if (CHECK_FLAG(bfd_info->flags, BFD_FLAG_BFD_REG)) + return; - bgp_bfd_peer_sendmsg(peer, ZEBRA_BFD_DEST_REGISTER); + bgp_bfd_peer_sendmsg(peer, ZEBRA_BFD_DEST_REGISTER); } /** @@ -156,138 +154,132 @@ bgp_bfd_register_peer (struct peer *peer) * for stopping the monitoring of the peer * rechahability. */ -void -bgp_bfd_deregister_peer (struct peer *peer) +void bgp_bfd_deregister_peer(struct peer *peer) { - struct bfd_info *bfd_info; + struct bfd_info *bfd_info; - if (!peer->bfd_info) - return; - bfd_info = (struct bfd_info *)peer->bfd_info; + if (!peer->bfd_info) + return; + bfd_info = (struct bfd_info *)peer->bfd_info; - /* Check if BFD is eanbled and peer has not been registered */ - if (!CHECK_FLAG(bfd_info->flags, BFD_FLAG_BFD_REG)) - return; + /* Check if BFD is eanbled and peer has not been registered */ + if (!CHECK_FLAG(bfd_info->flags, BFD_FLAG_BFD_REG)) + return; - bfd_info->status = BFD_STATUS_DOWN; - bfd_info->last_update = bgp_clock(); + bfd_info->status = BFD_STATUS_DOWN; + bfd_info->last_update = bgp_clock(); - bgp_bfd_peer_sendmsg(peer, ZEBRA_BFD_DEST_DEREGISTER); + bgp_bfd_peer_sendmsg(peer, ZEBRA_BFD_DEST_DEREGISTER); } /* * bgp_bfd_update_peer - update peer with BFD with new BFD paramters * through zebra. */ -static void -bgp_bfd_update_peer (struct peer *peer) +static void bgp_bfd_update_peer(struct peer *peer) { - struct bfd_info *bfd_info; + struct bfd_info *bfd_info; - if (!peer->bfd_info) - return; - bfd_info = (struct bfd_info *)peer->bfd_info; + if (!peer->bfd_info) + return; + bfd_info = (struct bfd_info *)peer->bfd_info; - /* Check if the peer has been registered with BFD*/ - if (!CHECK_FLAG(bfd_info->flags, BFD_FLAG_BFD_REG)) - return; + /* Check if the peer has been registered with BFD*/ + if (!CHECK_FLAG(bfd_info->flags, BFD_FLAG_BFD_REG)) + return; - bgp_bfd_peer_sendmsg(peer, ZEBRA_BFD_DEST_UPDATE); + bgp_bfd_peer_sendmsg(peer, ZEBRA_BFD_DEST_UPDATE); } /* * bgp_bfd_update_type - update session type with BFD through zebra. */ -static void -bgp_bfd_update_type (struct peer *peer) +static void bgp_bfd_update_type(struct peer *peer) { - struct bfd_info *bfd_info; - int multihop; - - if (!peer->bfd_info) - return; - bfd_info = (struct bfd_info *)peer->bfd_info; - - /* Check if the peer has been registered with BFD*/ - if (!CHECK_FLAG(bfd_info->flags, BFD_FLAG_BFD_REG)) - return; - - if (bfd_info->type == BFD_TYPE_NOT_CONFIGURED) - { - multihop = bgp_bfd_is_peer_multihop(peer); - if ((multihop && !CHECK_FLAG(bfd_info->flags, BFD_FLAG_BFD_TYPE_MULTIHOP)) || - (!multihop && CHECK_FLAG(bfd_info->flags, BFD_FLAG_BFD_TYPE_MULTIHOP))) - { - bgp_bfd_peer_sendmsg(peer, ZEBRA_BFD_DEST_DEREGISTER); - bgp_bfd_peer_sendmsg(peer, ZEBRA_BFD_DEST_REGISTER); - } - } - else - { - if ((bfd_info->type == BFD_TYPE_MULTIHOP && - !CHECK_FLAG(bfd_info->flags, BFD_FLAG_BFD_TYPE_MULTIHOP)) || - (bfd_info->type == BFD_TYPE_SINGLEHOP && - CHECK_FLAG(bfd_info->flags, BFD_FLAG_BFD_TYPE_MULTIHOP))) - { - bgp_bfd_peer_sendmsg(peer, ZEBRA_BFD_DEST_DEREGISTER); - bgp_bfd_peer_sendmsg(peer, ZEBRA_BFD_DEST_REGISTER); - } - } + struct bfd_info *bfd_info; + int multihop; + + if (!peer->bfd_info) + return; + bfd_info = (struct bfd_info *)peer->bfd_info; + + /* Check if the peer has been registered with BFD*/ + if (!CHECK_FLAG(bfd_info->flags, BFD_FLAG_BFD_REG)) + return; + + if (bfd_info->type == BFD_TYPE_NOT_CONFIGURED) { + multihop = bgp_bfd_is_peer_multihop(peer); + if ((multihop + && !CHECK_FLAG(bfd_info->flags, + BFD_FLAG_BFD_TYPE_MULTIHOP)) + || (!multihop && CHECK_FLAG(bfd_info->flags, + BFD_FLAG_BFD_TYPE_MULTIHOP))) { + bgp_bfd_peer_sendmsg(peer, ZEBRA_BFD_DEST_DEREGISTER); + bgp_bfd_peer_sendmsg(peer, ZEBRA_BFD_DEST_REGISTER); + } + } else { + if ((bfd_info->type == BFD_TYPE_MULTIHOP + && !CHECK_FLAG(bfd_info->flags, + BFD_FLAG_BFD_TYPE_MULTIHOP)) + || (bfd_info->type == BFD_TYPE_SINGLEHOP + && CHECK_FLAG(bfd_info->flags, + BFD_FLAG_BFD_TYPE_MULTIHOP))) { + bgp_bfd_peer_sendmsg(peer, ZEBRA_BFD_DEST_DEREGISTER); + bgp_bfd_peer_sendmsg(peer, ZEBRA_BFD_DEST_REGISTER); + } + } } /* * bgp_bfd_dest_replay - Replay all the peers that have BFD enabled * to zebra */ -static int -bgp_bfd_dest_replay (int command, struct zclient *client, zebra_size_t length, - vrf_id_t vrf_id) +static int bgp_bfd_dest_replay(int command, struct zclient *client, + zebra_size_t length, vrf_id_t vrf_id) { - struct listnode *mnode, *node, *nnode; - struct bgp *bgp; - struct peer *peer; + struct listnode *mnode, *node, *nnode; + struct bgp *bgp; + struct peer *peer; - if (BGP_DEBUG (zebra, ZEBRA)) - zlog_debug("Zebra: BFD Dest replay request"); + if (BGP_DEBUG(zebra, ZEBRA)) + zlog_debug("Zebra: BFD Dest replay request"); - /* Send the client registration */ - bfd_client_sendmsg(zclient, ZEBRA_BFD_CLIENT_REGISTER); + /* Send the client registration */ + bfd_client_sendmsg(zclient, ZEBRA_BFD_CLIENT_REGISTER); - /* Replay the peer, if BFD is enabled in BGP */ + /* Replay the peer, if BFD is enabled in BGP */ - for (ALL_LIST_ELEMENTS_RO (bm->bgp, mnode, bgp)) - for (ALL_LIST_ELEMENTS (bgp->peer, node, nnode, peer)) - { - bgp_bfd_update_peer(peer); - } + for (ALL_LIST_ELEMENTS_RO(bm->bgp, mnode, bgp)) + for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) { + bgp_bfd_update_peer(peer); + } - return 0; + return 0; } /* * bgp_bfd_peer_status_update - Update the BFD status if it has changed. Bring - * down the peer if the BFD session went down from * up. + * down the peer if the BFD session went down from + * * up. */ -static void -bgp_bfd_peer_status_update (struct peer *peer, int status) +static void bgp_bfd_peer_status_update(struct peer *peer, int status) { - struct bfd_info *bfd_info; - int old_status; + struct bfd_info *bfd_info; + int old_status; - bfd_info = (struct bfd_info *)peer->bfd_info; + bfd_info = (struct bfd_info *)peer->bfd_info; - if (bfd_info->status == status) - return; + if (bfd_info->status == status) + return; - old_status = bfd_info->status; - bfd_info->status = status; - bfd_info->last_update = bgp_clock(); + old_status = bfd_info->status; + bfd_info->status = status; + bfd_info->last_update = bgp_clock(); - if ((status == BFD_STATUS_DOWN) && (old_status == BFD_STATUS_UP)) - { - peer->last_reset = PEER_DOWN_BFD_DOWN; - BGP_EVENT_ADD (peer, BGP_Stop); - } + if ((status == BFD_STATUS_DOWN) && (old_status == BFD_STATUS_UP)) { + peer->last_reset = PEER_DOWN_BFD_DOWN; + BGP_EVENT_ADD(peer, BGP_Stop); + } } /* @@ -295,258 +287,254 @@ bgp_bfd_peer_status_update (struct peer *peer, int status) * has changed and bring down the peer * connectivity if the BFD session went down. */ -static int -bgp_bfd_dest_update (int command, struct zclient *zclient, - zebra_size_t length, vrf_id_t vrf_id) +static int bgp_bfd_dest_update(int command, struct zclient *zclient, + zebra_size_t length, vrf_id_t vrf_id) { - struct interface *ifp; - struct prefix dp; - struct prefix sp; - int status; - - ifp = bfd_get_peer_info (zclient->ibuf, &dp, &sp, &status, vrf_id); - - if (BGP_DEBUG (zebra, ZEBRA)) - { - char buf[2][PREFIX2STR_BUFFER]; - prefix2str(&dp, buf[0], sizeof(buf[0])); - if (ifp) - { - zlog_debug("Zebra: vrf %d interface %s bfd destination %s %s", - vrf_id, ifp->name, buf[0], bfd_get_status_str(status)); - } - else - { - prefix2str(&sp, buf[1], sizeof(buf[1])); - zlog_debug("Zebra: vrf %d source %s bfd destination %s %s", - vrf_id, buf[1], buf[0], bfd_get_status_str(status)); - } - } - - /* Bring the peer down if BFD is enabled in BGP */ - { - struct listnode *mnode, *node, *nnode; - struct bgp *bgp; - struct peer *peer; - - for (ALL_LIST_ELEMENTS_RO (bm->bgp, mnode, bgp)) - for (ALL_LIST_ELEMENTS (bgp->peer, node, nnode, peer)) - { - if (!peer->bfd_info) - continue; - - if ((dp.family == AF_INET) && (peer->su.sa.sa_family == AF_INET)) - { - if (dp.u.prefix4.s_addr != peer->su.sin.sin_addr.s_addr) - continue; - } - else if ((dp.family == AF_INET6) && - (peer->su.sa.sa_family == AF_INET6)) - { - if (memcmp(&dp.u.prefix6, &peer->su.sin6.sin6_addr, - sizeof (struct in6_addr))) - continue; - } - else - continue; - - if (ifp && (ifp == peer->nexthop.ifp)) - { - bgp_bfd_peer_status_update(peer, status); - } - else - { - if (!peer->su_local) - continue; - - if ((sp.family == AF_INET) && - (peer->su_local->sa.sa_family == AF_INET)) - { - if (sp.u.prefix4.s_addr != peer->su_local->sin.sin_addr.s_addr) - continue; - } - else if ((sp.family == AF_INET6) && - (peer->su_local->sa.sa_family == AF_INET6)) - { - if (memcmp(&sp.u.prefix6, &peer->su_local->sin6.sin6_addr, - sizeof (struct in6_addr))) - continue; - } - else - continue; - - if ((vrf_id != VRF_DEFAULT) && (peer->bgp->vrf_id != vrf_id)) - continue; - - bgp_bfd_peer_status_update(peer, status); - } - } - } - - return 0; + struct interface *ifp; + struct prefix dp; + struct prefix sp; + int status; + + ifp = bfd_get_peer_info(zclient->ibuf, &dp, &sp, &status, vrf_id); + + if (BGP_DEBUG(zebra, ZEBRA)) { + char buf[2][PREFIX2STR_BUFFER]; + prefix2str(&dp, buf[0], sizeof(buf[0])); + if (ifp) { + zlog_debug( + "Zebra: vrf %u interface %s bfd destination %s %s", + vrf_id, ifp->name, buf[0], + bfd_get_status_str(status)); + } else { + prefix2str(&sp, buf[1], sizeof(buf[1])); + zlog_debug( + "Zebra: vrf %u source %s bfd destination %s %s", + vrf_id, buf[1], buf[0], + bfd_get_status_str(status)); + } + } + + /* Bring the peer down if BFD is enabled in BGP */ + { + struct listnode *mnode, *node, *nnode; + struct bgp *bgp; + struct peer *peer; + + for (ALL_LIST_ELEMENTS_RO(bm->bgp, mnode, bgp)) + for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) { + if (!peer->bfd_info) + continue; + + if ((dp.family == AF_INET) + && (peer->su.sa.sa_family == AF_INET)) { + if (dp.u.prefix4.s_addr + != peer->su.sin.sin_addr.s_addr) + continue; + } else if ((dp.family == AF_INET6) + && (peer->su.sa.sa_family + == AF_INET6)) { + if (memcmp(&dp.u.prefix6, + &peer->su.sin6.sin6_addr, + sizeof(struct in6_addr))) + continue; + } else + continue; + + if (ifp && (ifp == peer->nexthop.ifp)) { + bgp_bfd_peer_status_update(peer, + status); + } else { + if (!peer->su_local) + continue; + + if ((sp.family == AF_INET) + && (peer->su_local->sa.sa_family + == AF_INET)) { + if (sp.u.prefix4.s_addr + != peer->su_local->sin + .sin_addr.s_addr) + continue; + } else if ((sp.family == AF_INET6) + && (peer->su_local->sa + .sa_family + == AF_INET6)) { + if (memcmp(&sp.u.prefix6, + &peer->su_local->sin6 + .sin6_addr, + sizeof(struct + in6_addr))) + continue; + } else + continue; + + if ((vrf_id != VRF_DEFAULT) + && (peer->bgp->vrf_id != vrf_id)) + continue; + + bgp_bfd_peer_status_update(peer, + status); + } + } + } + + return 0; } /* * bgp_bfd_peer_param_set - Set the configured BFD paramter values for peer. */ -static int -bgp_bfd_peer_param_set (struct peer *peer, u_int32_t min_rx, u_int32_t min_tx, - u_int8_t detect_mult, int defaults) +static int bgp_bfd_peer_param_set(struct peer *peer, uint32_t min_rx, + uint32_t min_tx, uint8_t detect_mult, + int defaults) { - struct peer_group *group; - struct listnode *node, *nnode; - int command = 0; - - bfd_set_param((struct bfd_info **)&(peer->bfd_info), min_rx, min_tx, - detect_mult, defaults, &command); - - if (CHECK_FLAG (peer->sflags, PEER_STATUS_GROUP)) - { - group = peer->group; - for (ALL_LIST_ELEMENTS (group->peer, node, nnode, peer)) - { - command = 0; - bfd_set_param((struct bfd_info **)&(peer->bfd_info), min_rx, min_tx, - detect_mult, defaults, &command); - - if ((peer->status == Established) && - (command == ZEBRA_BFD_DEST_REGISTER)) - bgp_bfd_register_peer(peer); - else if (command == ZEBRA_BFD_DEST_UPDATE) - bgp_bfd_update_peer(peer); - } - } - else - { - if ((peer->status == Established) && - (command == ZEBRA_BFD_DEST_REGISTER)) - bgp_bfd_register_peer(peer); - else if (command == ZEBRA_BFD_DEST_UPDATE) - bgp_bfd_update_peer(peer); - } - return 0; + struct peer_group *group; + struct listnode *node, *nnode; + int command = 0; + + bfd_set_param((struct bfd_info **)&(peer->bfd_info), min_rx, min_tx, + detect_mult, defaults, &command); + + if (CHECK_FLAG(peer->sflags, PEER_STATUS_GROUP)) { + group = peer->group; + for (ALL_LIST_ELEMENTS(group->peer, node, nnode, peer)) { + command = 0; + bfd_set_param((struct bfd_info **)&(peer->bfd_info), + min_rx, min_tx, detect_mult, defaults, + &command); + + if ((peer->status == Established) + && (command == ZEBRA_BFD_DEST_REGISTER)) + bgp_bfd_register_peer(peer); + else if (command == ZEBRA_BFD_DEST_UPDATE) + bgp_bfd_update_peer(peer); + } + } else { + if ((peer->status == Established) + && (command == ZEBRA_BFD_DEST_REGISTER)) + bgp_bfd_register_peer(peer); + else if (command == ZEBRA_BFD_DEST_UPDATE) + bgp_bfd_update_peer(peer); + } + return 0; } /* - * bgp_bfd_peer_param_unset - Delete the configured BFD paramter values for peer. + * bgp_bfd_peer_param_unset - Delete the configured BFD paramter values for + * peer. */ -static int -bgp_bfd_peer_param_unset (struct peer *peer) +static int bgp_bfd_peer_param_unset(struct peer *peer) { - struct peer_group *group; - struct listnode *node, *nnode; - - if (!peer->bfd_info) - return 0; - - if (CHECK_FLAG (peer->sflags, PEER_STATUS_GROUP)) - { - bfd_info_free(&(peer->bfd_info)); - group = peer->group; - for (ALL_LIST_ELEMENTS (group->peer, node, nnode, peer)) - { - bgp_bfd_deregister_peer(peer); - bfd_info_free(&(peer->bfd_info)); - } - } - else - { - bgp_bfd_deregister_peer(peer); - bfd_info_free(&(peer->bfd_info)); - } - return 0; + struct peer_group *group; + struct listnode *node, *nnode; + + if (!peer->bfd_info) + return 0; + + if (CHECK_FLAG(peer->sflags, PEER_STATUS_GROUP)) { + bfd_info_free(&(peer->bfd_info)); + group = peer->group; + for (ALL_LIST_ELEMENTS(group->peer, node, nnode, peer)) { + bgp_bfd_deregister_peer(peer); + bfd_info_free(&(peer->bfd_info)); + } + } else { + bgp_bfd_deregister_peer(peer); + bfd_info_free(&(peer->bfd_info)); + } + return 0; } /* - * bgp_bfd_peer_param_type_set - set the BFD session type (multihop or singlehop) + * bgp_bfd_peer_param_type_set - set the BFD session type (multihop or + * singlehop) */ -static int -bgp_bfd_peer_param_type_set (struct peer *peer, enum bfd_sess_type type) +static int bgp_bfd_peer_param_type_set(struct peer *peer, + enum bfd_sess_type type) { - struct peer_group *group; - struct listnode *node, *nnode; - int command = 0; - struct bfd_info *bfd_info; - - if (!peer->bfd_info) - bfd_set_param((struct bfd_info **)&(peer->bfd_info), BFD_DEF_MIN_RX, - BFD_DEF_MIN_TX, BFD_DEF_DETECT_MULT, 1, &command); - - bfd_info = (struct bfd_info *)peer->bfd_info; - bfd_info->type = type; - - if (CHECK_FLAG (peer->sflags, PEER_STATUS_GROUP)) - { - group = peer->group; - for (ALL_LIST_ELEMENTS (group->peer, node, nnode, peer)) - { - command = 0; - if (!peer->bfd_info) - bfd_set_param((struct bfd_info **)&(peer->bfd_info), - BFD_DEF_MIN_RX, BFD_DEF_MIN_TX, - BFD_DEF_DETECT_MULT, 1, &command); - - bfd_info = (struct bfd_info *)peer->bfd_info; - bfd_info->type = type; - - if (peer->status == Established) - { - if (command == ZEBRA_BFD_DEST_REGISTER) - bgp_bfd_register_peer(peer); - else - bgp_bfd_update_type(peer); - } - } - } - else - { - if (peer->status == Established) - { - if (command == ZEBRA_BFD_DEST_REGISTER) - bgp_bfd_register_peer(peer); - else - bgp_bfd_update_type(peer); - } - } - - return 0; + struct peer_group *group; + struct listnode *node, *nnode; + int command = 0; + struct bfd_info *bfd_info; + + if (!peer->bfd_info) + bfd_set_param((struct bfd_info **)&(peer->bfd_info), + BFD_DEF_MIN_RX, BFD_DEF_MIN_TX, + BFD_DEF_DETECT_MULT, 1, &command); + + bfd_info = (struct bfd_info *)peer->bfd_info; + bfd_info->type = type; + + if (CHECK_FLAG(peer->sflags, PEER_STATUS_GROUP)) { + group = peer->group; + for (ALL_LIST_ELEMENTS(group->peer, node, nnode, peer)) { + command = 0; + if (!peer->bfd_info) + bfd_set_param( + (struct bfd_info **)&(peer->bfd_info), + BFD_DEF_MIN_RX, BFD_DEF_MIN_TX, + BFD_DEF_DETECT_MULT, 1, &command); + + bfd_info = (struct bfd_info *)peer->bfd_info; + bfd_info->type = type; + + if (peer->status == Established) { + if (command == ZEBRA_BFD_DEST_REGISTER) + bgp_bfd_register_peer(peer); + else + bgp_bfd_update_type(peer); + } + } + } else { + if (peer->status == Established) { + if (command == ZEBRA_BFD_DEST_REGISTER) + bgp_bfd_register_peer(peer); + else + bgp_bfd_update_type(peer); + } + } + + return 0; } /* * bgp_bfd_peer_config_write - Write the peer BFD configuration. */ -void -bgp_bfd_peer_config_write(struct vty *vty, struct peer *peer, char *addr) +void bgp_bfd_peer_config_write(struct vty *vty, struct peer *peer, char *addr) { - struct bfd_info *bfd_info; - - if (!peer->bfd_info) - return; - - bfd_info = (struct bfd_info *)peer->bfd_info; - - if (CHECK_FLAG (bfd_info->flags, BFD_FLAG_PARAM_CFG)) - vty_outln (vty, " neighbor %s bfd %d %d %d", addr, - bfd_info->detect_mult, bfd_info->required_min_rx, - bfd_info->desired_min_tx); - - if (bfd_info->type != BFD_TYPE_NOT_CONFIGURED) - vty_outln (vty, " neighbor %s bfd %s", addr, - (bfd_info->type == BFD_TYPE_MULTIHOP) ? "multihop" : "singlehop"); - - if (!CHECK_FLAG (bfd_info->flags, BFD_FLAG_PARAM_CFG) && - (bfd_info->type == BFD_TYPE_NOT_CONFIGURED)) - vty_outln (vty, " neighbor %s bfd", addr); + struct bfd_info *bfd_info; + + if (!peer->bfd_info) + return; + + bfd_info = (struct bfd_info *)peer->bfd_info; + + if (CHECK_FLAG(bfd_info->flags, BFD_FLAG_PARAM_CFG)) +#if HAVE_BFDD > 0 + vty_out(vty, " neighbor %s bfd\n", addr); +#else + vty_out(vty, " neighbor %s bfd %d %d %d\n", addr, + bfd_info->detect_mult, bfd_info->required_min_rx, + bfd_info->desired_min_tx); +#endif /* HAVE_BFDD */ + + if (bfd_info->type != BFD_TYPE_NOT_CONFIGURED) + vty_out(vty, " neighbor %s bfd %s\n", addr, + (bfd_info->type == BFD_TYPE_MULTIHOP) ? "multihop" + : "singlehop"); + + if (!CHECK_FLAG(bfd_info->flags, BFD_FLAG_PARAM_CFG) + && (bfd_info->type == BFD_TYPE_NOT_CONFIGURED)) + vty_out(vty, " neighbor %s bfd\n", addr); } /* * bgp_bfd_show_info - Show the peer BFD information. */ -void -bgp_bfd_show_info(struct vty *vty, struct peer *peer, u_char use_json, json_object *json_neigh) +void bgp_bfd_show_info(struct vty *vty, struct peer *peer, bool use_json, + json_object *json_neigh) { - bfd_show_info(vty, (struct bfd_info *)peer->bfd_info, - bgp_bfd_is_peer_multihop(peer), 0, use_json, json_neigh); + bfd_show_info(vty, (struct bfd_info *)peer->bfd_info, + bgp_bfd_is_peer_multihop(peer), 0, use_json, json_neigh); } DEFUN (neighbor_bfd, @@ -556,24 +544,28 @@ DEFUN (neighbor_bfd, NEIGHBOR_ADDR_STR2 "Enables BFD support\n") { - int idx_peer = 1; - struct peer *peer; - int ret; - - peer = peer_and_group_lookup_vty (vty, argv[idx_peer]->arg); - if (! peer) - return CMD_WARNING_CONFIG_FAILED; + int idx_peer = 1; + struct peer *peer; + int ret; - ret = bgp_bfd_peer_param_set (peer, BFD_DEF_MIN_RX, BFD_DEF_MIN_TX, - BFD_DEF_DETECT_MULT, 1); - if (ret != 0) - return bgp_vty_return (vty, ret); + peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg); + if (!peer) + return CMD_WARNING_CONFIG_FAILED; - return CMD_SUCCESS; + ret = bgp_bfd_peer_param_set(peer, BFD_DEF_MIN_RX, BFD_DEF_MIN_TX, + BFD_DEF_DETECT_MULT, 1); + if (ret != 0) + return bgp_vty_return(vty, ret); + return CMD_SUCCESS; } -DEFUN (neighbor_bfd_param, +#if HAVE_BFDD > 0 +DEFUN_HIDDEN( +#else +DEFUN( +#endif /* HAVE_BFDD */ + neighbor_bfd_param, neighbor_bfd_param_cmd, "neighbor bfd (2-255) (50-60000) (50-60000)", NEIGHBOR_STR @@ -583,30 +575,31 @@ DEFUN (neighbor_bfd_param, "Required min receive interval\n" "Desired min transmit interval\n") { - int idx_peer = 1; - int idx_number_1 = 3; - int idx_number_2 = 4; - int idx_number_3 = 5; - struct peer *peer; - u_int32_t rx_val; - u_int32_t tx_val; - u_int8_t dm_val; - int ret; - - peer = peer_and_group_lookup_vty (vty, argv[idx_peer]->arg); - if (!peer) - return CMD_WARNING_CONFIG_FAILED; - - if ((ret = bfd_validate_param (vty, argv[idx_number_1]->arg, argv[idx_number_2]->arg, argv[idx_number_3]->arg, &dm_val, - &rx_val, &tx_val)) != CMD_SUCCESS) - return ret; - - ret = bgp_bfd_peer_param_set (peer, rx_val, tx_val, dm_val, 0); - if (ret != 0) - return bgp_vty_return (vty, ret); - - return CMD_SUCCESS; - + int idx_peer = 1; + int idx_number_1 = 3; + int idx_number_2 = 4; + int idx_number_3 = 5; + struct peer *peer; + uint32_t rx_val; + uint32_t tx_val; + uint8_t dm_val; + int ret; + + peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg); + if (!peer) + return CMD_WARNING_CONFIG_FAILED; + + if ((ret = bfd_validate_param( + vty, argv[idx_number_1]->arg, argv[idx_number_2]->arg, + argv[idx_number_3]->arg, &dm_val, &rx_val, &tx_val)) + != CMD_SUCCESS) + return ret; + + ret = bgp_bfd_peer_param_set(peer, rx_val, tx_val, dm_val, 0); + if (ret != 0) + return bgp_vty_return(vty, ret); + + return CMD_SUCCESS; } DEFUN_HIDDEN (neighbor_bfd_type, @@ -618,54 +611,61 @@ DEFUN_HIDDEN (neighbor_bfd_type, "Multihop session\n" "Single hop session\n") { - int idx_peer = 1; - int idx_hop = 3; - struct peer *peer; - enum bfd_sess_type type; - int ret; - - peer = peer_and_group_lookup_vty (vty, argv[idx_peer]->arg); - if (!peer) - return CMD_WARNING_CONFIG_FAILED; - - if (strmatch(argv[idx_hop]->text, "singlehop")) - type = BFD_TYPE_SINGLEHOP; - else if (strmatch(argv[idx_hop]->text, "multihop")) - type = BFD_TYPE_MULTIHOP; - else - return CMD_WARNING_CONFIG_FAILED; - - ret = bgp_bfd_peer_param_type_set (peer, type); - if (ret != 0) - return bgp_vty_return (vty, ret); - - return CMD_SUCCESS; + int idx_peer = 1; + int idx_hop = 3; + struct peer *peer; + enum bfd_sess_type type; + int ret; + + peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg); + if (!peer) + return CMD_WARNING_CONFIG_FAILED; + + if (strmatch(argv[idx_hop]->text, "singlehop")) + type = BFD_TYPE_SINGLEHOP; + else if (strmatch(argv[idx_hop]->text, "multihop")) + type = BFD_TYPE_MULTIHOP; + else + return CMD_WARNING_CONFIG_FAILED; + + ret = bgp_bfd_peer_param_type_set(peer, type); + if (ret != 0) + return bgp_vty_return(vty, ret); + + return CMD_SUCCESS; } DEFUN (no_neighbor_bfd, no_neighbor_bfd_cmd, +#if HAVE_BFDD > 0 + "no neighbor bfd", +#else "no neighbor bfd [(2-255) (50-60000) (50-60000)]", +#endif /* HAVE_BFDD */ NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2 "Disables BFD support\n" +#if HAVE_BFDD == 0 "Detect Multiplier\n" "Required min receive interval\n" - "Desired min transmit interval\n") + "Desired min transmit interval\n" +#endif /* !HAVE_BFDD */ +) { - int idx_peer = 2; - struct peer *peer; - int ret; + int idx_peer = 2; + struct peer *peer; + int ret; - peer = peer_and_group_lookup_vty (vty, argv[idx_peer]->arg); - if (! peer) - return CMD_WARNING_CONFIG_FAILED; + peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg); + if (!peer) + return CMD_WARNING_CONFIG_FAILED; - ret = bgp_bfd_peer_param_unset(peer); - if (ret != 0) - return bgp_vty_return (vty, ret); + ret = bgp_bfd_peer_param_unset(peer); + if (ret != 0) + return bgp_vty_return(vty, ret); - return CMD_SUCCESS; + return CMD_SUCCESS; } @@ -679,37 +679,36 @@ DEFUN_HIDDEN (no_neighbor_bfd_type, "Multihop session\n" "Singlehop session\n") { - int idx_peer = 2; - struct peer *peer; - int ret; + int idx_peer = 2; + struct peer *peer; + int ret; - peer = peer_and_group_lookup_vty (vty, argv[idx_peer]->arg); - if (! peer) - return CMD_WARNING_CONFIG_FAILED; + peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg); + if (!peer) + return CMD_WARNING_CONFIG_FAILED; - if (!peer->bfd_info) - return 0; + if (!peer->bfd_info) + return 0; - ret = bgp_bfd_peer_param_type_set(peer, BFD_TYPE_NOT_CONFIGURED); - if (ret != 0) - return bgp_vty_return (vty, ret); + ret = bgp_bfd_peer_param_type_set(peer, BFD_TYPE_NOT_CONFIGURED); + if (ret != 0) + return bgp_vty_return(vty, ret); - return CMD_SUCCESS; + return CMD_SUCCESS; } -void -bgp_bfd_init(void) +void bgp_bfd_init(void) { - bfd_gbl_init(); - - /* Initialize BFD client functions */ - zclient->interface_bfd_dest_update = bgp_bfd_dest_update; - zclient->bfd_dest_replay = bgp_bfd_dest_replay; - - /* "neighbor bfd" commands. */ - install_element (BGP_NODE, &neighbor_bfd_cmd); - install_element (BGP_NODE, &neighbor_bfd_param_cmd); - install_element (BGP_NODE, &neighbor_bfd_type_cmd); - install_element (BGP_NODE, &no_neighbor_bfd_cmd); - install_element (BGP_NODE, &no_neighbor_bfd_type_cmd); + bfd_gbl_init(); + + /* Initialize BFD client functions */ + zclient->interface_bfd_dest_update = bgp_bfd_dest_update; + zclient->bfd_dest_replay = bgp_bfd_dest_replay; + + /* "neighbor bfd" commands. */ + install_element(BGP_NODE, &neighbor_bfd_cmd); + install_element(BGP_NODE, &neighbor_bfd_param_cmd); + install_element(BGP_NODE, &neighbor_bfd_type_cmd); + install_element(BGP_NODE, &no_neighbor_bfd_cmd); + install_element(BGP_NODE, &no_neighbor_bfd_type_cmd); }