mirror of
https://git.proxmox.com/git/mirror_frr
synced 2025-05-17 06:27:02 +00:00

The API messages are used by zebra to exchange the interfaces, addresses, routes and router-id information with its clients. To distinguish which VRF the information belongs to, a new field "VRF ID" is added in the message header. And hence the message version is increased to 3. * The new field "VRF ID" in the message header: Length (2 bytes) Marker (1 byte) Version (1 byte) VRF ID (2 bytes, newly added) Command (2 bytes) - Client side: - zclient_create_header() adds the VRF ID in the message header. - zclient_read() extracts and validates the VRF ID from the header, and passes the VRF ID to the callback functions registered to the API messages. - All relative functions are appended with a new parameter "vrf_id", including all the callback functions. - "vrf_id" is also added to "struct zapi_ipv4" and "struct zapi_ipv6". Clients need to correctly set the VRF ID when using the API functions zapi_ipv4_route() and zapi_ipv6_route(). - Till now all messages sent from a client have the default VRF ID "0" in the header. - The HELLO message is special, which is used as the heart-beat of a client, and has no relation with VRF. The VRF ID in the HELLO message header will always be 0 and ignored by zebra. - Zebra side: - zserv_create_header() adds the VRF ID in the message header. - zebra_client_read() extracts and validates the VRF ID from the header, and passes the VRF ID to the functions which process the received messages. - All relative functions are appended with a new parameter "vrf_id". * Suppress the messages in a VRF which a client does not care: Some clients may not care about the information in the VRF X, and zebra should not send the messages in the VRF X to those clients. Extra flags are used to indicate which VRF is registered by a client, and a new message ZEBRA_VRF_UNREGISTER is introduced to let a client can unregister a VRF when it does not need any information in that VRF. A client sends any message other than ZEBRA_VRF_UNREGISTER in a VRF will automatically register to that VRF. - lib/vrf: A new utility "VRF bit-map" is provided to manage the flags for VRFs, one bit per VRF ID. - Use vrf_bitmap_init()/vrf_bitmap_free() to initialize/free a bit-map; - Use vrf_bitmap_set()/vrf_bitmap_unset() to set/unset a flag in the given bit-map, corresponding to the given VRF ID; - Use vrf_bitmap_check() to test whether the flag, in the given bit-map and for the given VRF ID, is set. - Client side: - In "struct zclient", the following flags are changed from "u_char" to "vrf_bitmap_t": redist[ZEBRA_ROUTE_MAX] default_information These flags are extended for each VRF, and controlled by the clients themselves (or with the help of zclient_redistribute() and zclient_redistribute_default()). - Zebra side: - In "struct zserv", the following flags are changed from "u_char" to "vrf_bitmap_t": redist[ZEBRA_ROUTE_MAX] redist_default ifinfo ridinfo These flags are extended for each VRF, as the VRF registration flags. They are maintained on receiving a ZEBRA_XXX_ADD or ZEBRA_XXX_DELETE message. When sending an interface/address/route/router-id message in a VRF to a client, if the corresponding VRF registration flag is not set, this message will not be dropped by zebra. - A new function zread_vrf_unregister() is introduced to process the new command ZEBRA_VRF_UNREGISTER. All the VRF registration flags are cleared for the requested VRF. Those clients, who support only the default VRF, will never receive a message in a non-default VRF, thanks to the filter in zebra. * New callback for the event of successful connection to zebra: - zclient_start() is splitted, keeping only the code of connecting to zebra. - Now zclient_init()=>zclient_connect()=>zclient_start() operations are purely dealing with the connection to zbera. - Once zebra is successfully connected, at the end of zclient_start(), a new callback is used to inform the client about connection. - Till now, in the callback of connect-to-zebra event, all clients send messages to zebra to request the router-id/interface/routes information in the default VRF. Of corse in future the client can do anything it wants in this callback. For example, it may send requests for both default VRF and some non-default VRFs. Signed-off-by: Feng Lu <lu.feng@6wind.com> Reviewed-by: Alain Ritoux <alain.ritoux@6wind.com> Signed-off-by: Nicolas Dichtel <nicolas.dichtel@6wind.com> Acked-by: Donald Sharp <sharpd@cumulusnetworks.com> Conflicts: lib/zclient.h lib/zebra.h zebra/zserv.c zebra/zserv.h Conflicts: bgpd/bgp_nexthop.c bgpd/bgp_nht.c bgpd/bgp_zebra.c isisd/isis_zebra.c lib/zclient.c lib/zclient.h lib/zebra.h nhrpd/nhrp_interface.c nhrpd/nhrp_route.c nhrpd/nhrpd.h ospf6d/ospf6_zebra.c ospf6d/ospf6_zebra.h ospfd/ospf_vty.c ospfd/ospf_zebra.c pimd/pim_zebra.c pimd/pim_zlookup.c ripd/rip_zebra.c ripngd/ripng_zebra.c zebra/redistribute.c zebra/rt_netlink.c zebra/zebra_rnh.c zebra/zebra_rnh.h zebra/zserv.c zebra/zserv.h
439 lines
12 KiB
C
439 lines
12 KiB
C
/**
|
|
* ospf_bfd.c: OSPF BFD handling routines
|
|
*
|
|
* @copyright Copyright (C) 2015 Cumulus Networks, Inc.
|
|
*
|
|
* This file is part of GNU Zebra.
|
|
*
|
|
* GNU Zebra is free software; you can redistribute it and/or modify it
|
|
* under the terms of the GNU General Public License as published by the
|
|
* Free Software Foundation; either version 2, or (at your option) any
|
|
* later version.
|
|
*
|
|
* GNU Zebra is distributed in the hope that it will be useful, but
|
|
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
* General Public License for more details.
|
|
*
|
|
* You should have received a copy of the GNU General Public License
|
|
* along with GNU Zebra; see the file COPYING. If not, write to the Free
|
|
* Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
|
|
* 02111-1307, USA.
|
|
*/
|
|
|
|
#include <zebra.h>
|
|
|
|
#include "command.h"
|
|
#include "linklist.h"
|
|
#include "memory.h"
|
|
#include "prefix.h"
|
|
#include "thread.h"
|
|
#include "buffer.h"
|
|
#include "stream.h"
|
|
#include "zclient.h"
|
|
#include "vty.h"
|
|
#include "table.h"
|
|
#include "bfd.h"
|
|
#include "ospfd.h"
|
|
#include "ospf_asbr.h"
|
|
#include "ospf_lsa.h"
|
|
#include "ospf_lsdb.h"
|
|
#include "ospf_neighbor.h"
|
|
#include "ospf_interface.h"
|
|
#include "ospf_nsm.h"
|
|
#include "ospf_bfd.h"
|
|
#include "ospf_dump.h"
|
|
#include "ospf_vty.h"
|
|
|
|
extern struct zclient *zclient;
|
|
|
|
/*
|
|
* ospf_bfd_info_free - Free BFD info structure
|
|
*/
|
|
void
|
|
ospf_bfd_info_free(void **bfd_info)
|
|
{
|
|
bfd_info_free((struct bfd_info **) bfd_info);
|
|
}
|
|
|
|
/*
|
|
* ospf_bfd_reg_dereg_nbr - Register/Deregister a neighbor with BFD through
|
|
* zebra for starting/stopping the monitoring of
|
|
* the neighbor rechahability.
|
|
*/
|
|
static void
|
|
ospf_bfd_reg_dereg_nbr (struct ospf_neighbor *nbr, int command)
|
|
{
|
|
struct ospf_interface *oi = nbr->oi;
|
|
struct interface *ifp = oi->ifp;
|
|
struct ospf_if_params *params;
|
|
struct bfd_info *bfd_info;
|
|
|
|
/* Check if BFD is enabled */
|
|
params = IF_DEF_PARAMS (ifp);
|
|
|
|
/* Check if BFD is enabled */
|
|
if (!params->bfd_info)
|
|
return;
|
|
bfd_info = (struct bfd_info *)params->bfd_info;
|
|
|
|
if (IS_DEBUG_OSPF(zebra, ZEBRA_INTERFACE))
|
|
zlog_debug ("%s nbr (%s) with BFD",
|
|
bfd_get_command_dbg_str(command),
|
|
inet_ntoa (nbr->src));
|
|
|
|
bfd_peer_sendmsg (zclient, bfd_info, AF_INET,
|
|
&nbr->src, NULL, ifp->name, 0, 0, command, 0, VRF_DEFAULT);
|
|
}
|
|
|
|
/*
|
|
* ospf_bfd_trigger_event - Neighbor is registered/deregistered with BFD when
|
|
* neighbor state is changed to/from 2way.
|
|
*/
|
|
void
|
|
ospf_bfd_trigger_event(struct ospf_neighbor *nbr, int old_state, int state)
|
|
{
|
|
if ((old_state < NSM_TwoWay) && (state >= NSM_TwoWay))
|
|
ospf_bfd_reg_dereg_nbr(nbr, ZEBRA_BFD_DEST_REGISTER);
|
|
else if ((old_state >= NSM_TwoWay) && (state < NSM_TwoWay))
|
|
ospf_bfd_reg_dereg_nbr(nbr, ZEBRA_BFD_DEST_DEREGISTER);
|
|
}
|
|
|
|
/*
|
|
* ospf_bfd_reg_dereg_all_nbr - Register/Deregister all neighbors associated
|
|
* with a interface with BFD through
|
|
* zebra for starting/stopping the monitoring of
|
|
* the neighbor rechahability.
|
|
*/
|
|
static int
|
|
ospf_bfd_reg_dereg_all_nbr (struct interface *ifp, int command)
|
|
{
|
|
struct ospf_interface *oi;
|
|
struct route_table *nbrs;
|
|
struct ospf_neighbor *nbr;
|
|
struct route_node *irn;
|
|
struct route_node *nrn;
|
|
|
|
for (irn = route_top (IF_OIFS (ifp)); irn; irn = route_next (irn))
|
|
{
|
|
if ((oi = irn->info) == NULL)
|
|
continue;
|
|
|
|
if ((nbrs = oi->nbrs) == NULL)
|
|
continue;
|
|
|
|
for (nrn = route_top (nbrs); nrn; nrn = route_next (nrn))
|
|
{
|
|
if ((nbr = nrn->info) == NULL || nbr == oi->nbr_self)
|
|
continue;
|
|
|
|
if (command != ZEBRA_BFD_DEST_DEREGISTER)
|
|
ospf_bfd_info_nbr_create(oi, nbr);
|
|
else
|
|
bfd_info_free((struct bfd_info **)&nbr->bfd_info);
|
|
|
|
if (nbr->state < NSM_TwoWay)
|
|
continue;
|
|
|
|
ospf_bfd_reg_dereg_nbr(nbr, command);
|
|
}
|
|
}
|
|
|
|
return 0;
|
|
}
|
|
|
|
/*
|
|
* ospf_bfd_nbr_replay - Replay all the neighbors that have BFD enabled
|
|
* to zebra
|
|
*/
|
|
static int
|
|
ospf_bfd_nbr_replay (int command, struct zclient *client, zebra_size_t length,
|
|
vrf_id_t vrf_id)
|
|
{
|
|
struct listnode *inode, *node, *onode;
|
|
struct ospf *ospf;
|
|
struct ospf_interface *oi;
|
|
struct route_table *nbrs;
|
|
struct route_node *rn;
|
|
struct ospf_neighbor *nbr;
|
|
struct ospf_if_params *params;
|
|
|
|
if (IS_DEBUG_OSPF(zebra, ZEBRA_INTERFACE))
|
|
{
|
|
zlog_debug("Zebra: BFD Dest replay request");
|
|
}
|
|
|
|
/* Replay the neighbor, if BFD is enabled in BGP */
|
|
for (ALL_LIST_ELEMENTS (om->ospf, node, onode, ospf))
|
|
{
|
|
for (ALL_LIST_ELEMENTS_RO (ospf->oiflist, inode, oi))
|
|
{
|
|
if ((nbrs = oi->nbrs) == NULL)
|
|
continue;
|
|
|
|
params = IF_DEF_PARAMS (oi->ifp);
|
|
if (!params->bfd_info)
|
|
continue;
|
|
|
|
for (rn = route_top (nbrs); rn; rn = route_next (rn))
|
|
{
|
|
if ((nbr = rn->info) == NULL || nbr == oi->nbr_self)
|
|
continue;
|
|
|
|
if (nbr->state < NSM_TwoWay)
|
|
continue;
|
|
|
|
if (IS_DEBUG_OSPF(zebra, ZEBRA_INTERFACE))
|
|
zlog_debug ("Replaying nbr (%s) to BFD", inet_ntoa (nbr->src));
|
|
|
|
ospf_bfd_reg_dereg_nbr(nbr, ZEBRA_BFD_DEST_UPDATE);
|
|
}
|
|
}
|
|
}
|
|
return 0;
|
|
}
|
|
|
|
/*
|
|
* ospf_bfd_interface_dest_update - Find the neighbor for which the BFD status
|
|
* has changed and bring down the neighbor
|
|
* connectivity if the BFD status changed to
|
|
* down.
|
|
*/
|
|
static int
|
|
ospf_bfd_interface_dest_update (int command, struct zclient *zclient,
|
|
zebra_size_t length, vrf_id_t vrf_id)
|
|
{
|
|
struct interface *ifp;
|
|
struct ospf_interface *oi;
|
|
struct ospf_if_params *params;
|
|
struct ospf_neighbor *nbr;
|
|
struct route_node *node;
|
|
struct prefix p;
|
|
int status;
|
|
int old_status;
|
|
struct bfd_info *bfd_info;
|
|
struct timeval tv;
|
|
|
|
ifp = bfd_get_peer_info (zclient->ibuf, &p, NULL, &status);
|
|
|
|
if ((ifp == NULL) || (p.family != AF_INET))
|
|
return 0;
|
|
|
|
if (IS_DEBUG_OSPF (zebra, ZEBRA_INTERFACE))
|
|
{
|
|
char buf[128];
|
|
prefix2str(&p, buf, sizeof(buf));
|
|
zlog_debug("Zebra: interface %s bfd destination %s %s", ifp->name, buf,
|
|
bfd_get_status_str(status));
|
|
}
|
|
|
|
params = IF_DEF_PARAMS (ifp);
|
|
if (!params->bfd_info)
|
|
return 0;
|
|
|
|
for (node = route_top (IF_OIFS (ifp)); node; node = route_next (node))
|
|
{
|
|
if ((oi = node->info) == NULL)
|
|
continue;
|
|
|
|
nbr = ospf_nbr_lookup_by_addr (oi->nbrs, &p.u.prefix4);
|
|
if (!nbr || !nbr->bfd_info)
|
|
continue;
|
|
|
|
bfd_info = (struct bfd_info *)nbr->bfd_info;
|
|
if (bfd_info->status == status)
|
|
continue;
|
|
|
|
old_status = bfd_info->status;
|
|
bfd_info->status = status;
|
|
quagga_gettime (QUAGGA_CLK_MONOTONIC, &tv);
|
|
bfd_info->last_update = tv.tv_sec;
|
|
|
|
if ((status == BFD_STATUS_DOWN) && (old_status == BFD_STATUS_UP))
|
|
{
|
|
if (IS_DEBUG_OSPF (nsm, NSM_EVENTS))
|
|
zlog_debug ("NSM[%s:%s]: BFD Down",
|
|
IF_NAME (nbr->oi), inet_ntoa (nbr->address.u.prefix4));
|
|
|
|
OSPF_NSM_EVENT_SCHEDULE (nbr, NSM_InactivityTimer);
|
|
}
|
|
}
|
|
|
|
return 0;
|
|
}
|
|
|
|
/*
|
|
* ospf_bfd_info_nbr_create - Create/update BFD information for a neighbor.
|
|
*/
|
|
void
|
|
ospf_bfd_info_nbr_create (struct ospf_interface *oi, struct ospf_neighbor *nbr)
|
|
{
|
|
struct bfd_info *oi_bfd_info;
|
|
struct bfd_info *nbr_bfd_info;
|
|
struct interface *ifp = oi->ifp;
|
|
struct ospf_if_params *params;
|
|
|
|
/* Check if BFD is enabled */
|
|
params = IF_DEF_PARAMS (ifp);
|
|
|
|
/* Check if BFD is enabled */
|
|
if (!params->bfd_info)
|
|
return;
|
|
|
|
oi_bfd_info = (struct bfd_info *)params->bfd_info;
|
|
if (!nbr->bfd_info)
|
|
nbr->bfd_info = bfd_info_create();
|
|
|
|
nbr_bfd_info = (struct bfd_info *)nbr->bfd_info;
|
|
nbr_bfd_info->detect_mult = oi_bfd_info->detect_mult;
|
|
nbr_bfd_info->desired_min_tx = oi_bfd_info->desired_min_tx;
|
|
nbr_bfd_info->required_min_rx = oi_bfd_info->required_min_rx;
|
|
}
|
|
|
|
/*
|
|
* ospf_bfd_write_config - Write the interface BFD configuration.
|
|
*/
|
|
void
|
|
ospf_bfd_write_config(struct vty *vty, struct ospf_if_params *params)
|
|
|
|
{
|
|
struct bfd_info *bfd_info;
|
|
|
|
if (!params->bfd_info)
|
|
return;
|
|
|
|
bfd_info = (struct bfd_info *)params->bfd_info;
|
|
|
|
if (CHECK_FLAG(bfd_info->flags, BFD_FLAG_PARAM_CFG))
|
|
vty_out (vty, " ip ospf bfd %d %d %d%s",
|
|
bfd_info->detect_mult, bfd_info->required_min_rx,
|
|
bfd_info->desired_min_tx, VTY_NEWLINE);
|
|
else
|
|
vty_out (vty, " ip ospf bfd%s", VTY_NEWLINE);
|
|
}
|
|
|
|
/*
|
|
* ospf_bfd_show_info - Show BFD info structure
|
|
*/
|
|
void
|
|
ospf_bfd_show_info(struct vty *vty, void *bfd_info, json_object *json_obj,
|
|
u_char use_json, int param_only)
|
|
{
|
|
if (param_only)
|
|
bfd_show_param(vty, (struct bfd_info *)bfd_info, 1, 0, use_json, json_obj);
|
|
else
|
|
bfd_show_info(vty, (struct bfd_info *)bfd_info, 0, 1, use_json, json_obj);
|
|
}
|
|
|
|
/*
|
|
* ospf_bfd_interface_show - Show the interface BFD configuration.
|
|
*/
|
|
void
|
|
ospf_bfd_interface_show(struct vty *vty, struct interface *ifp,
|
|
json_object *json_interface_sub, u_char use_json)
|
|
{
|
|
struct ospf_if_params *params;
|
|
|
|
params = IF_DEF_PARAMS (ifp);
|
|
|
|
ospf_bfd_show_info(vty, params->bfd_info, json_interface_sub, use_json, 1);
|
|
}
|
|
|
|
/*
|
|
* ospf_bfd_if_param_set - Set the configured BFD paramter values for
|
|
* interface.
|
|
*/
|
|
static void
|
|
ospf_bfd_if_param_set (struct interface *ifp, u_int32_t min_rx,
|
|
u_int32_t min_tx, u_int8_t detect_mult, int defaults)
|
|
{
|
|
struct ospf_if_params *params;
|
|
int command = 0;
|
|
|
|
params = IF_DEF_PARAMS (ifp);
|
|
|
|
bfd_set_param((struct bfd_info **)&(params->bfd_info), min_rx, min_tx,
|
|
detect_mult, defaults, &command);
|
|
if (command)
|
|
ospf_bfd_reg_dereg_all_nbr(ifp, command);
|
|
}
|
|
|
|
DEFUN (ip_ospf_bfd,
|
|
ip_ospf_bfd_cmd,
|
|
"ip ospf bfd",
|
|
"IP Information\n"
|
|
"OSPF interface commands\n"
|
|
"Enables BFD support\n")
|
|
{
|
|
struct interface *ifp = (struct interface *) vty->index;
|
|
|
|
assert (ifp);
|
|
ospf_bfd_if_param_set (ifp, BFD_DEF_MIN_RX, BFD_DEF_MIN_TX,
|
|
BFD_DEF_DETECT_MULT, 1);
|
|
|
|
return CMD_SUCCESS;
|
|
}
|
|
|
|
DEFUN (ip_ospf_bfd_param,
|
|
ip_ospf_bfd_param_cmd,
|
|
"ip ospf bfd " BFD_CMD_DETECT_MULT_RANGE BFD_CMD_MIN_RX_RANGE BFD_CMD_MIN_TX_RANGE,
|
|
"IP Information\n"
|
|
"OSPF interface commands\n"
|
|
"Enables BFD support\n"
|
|
"Detect Multiplier\n"
|
|
"Required min receive interval\n"
|
|
"Desired min transmit interval\n")
|
|
{
|
|
struct interface *ifp = (struct interface *) vty->index;
|
|
u_int32_t rx_val;
|
|
u_int32_t tx_val;
|
|
u_int8_t dm_val;
|
|
int ret;
|
|
|
|
assert (ifp);
|
|
|
|
if ((ret = bfd_validate_param (vty, argv[0], argv[1], argv[2], &dm_val,
|
|
&rx_val, &tx_val)) != CMD_SUCCESS)
|
|
return ret;
|
|
|
|
ospf_bfd_if_param_set (ifp, rx_val, tx_val, dm_val, 0);
|
|
|
|
return CMD_SUCCESS;
|
|
}
|
|
|
|
DEFUN (no_ip_ospf_bfd,
|
|
no_ip_ospf_bfd_cmd,
|
|
"no ip ospf bfd",
|
|
NO_STR
|
|
"IP Information\n"
|
|
"OSPF interface commands\n"
|
|
"Disables BFD support\n")
|
|
{
|
|
struct interface *ifp = (struct interface *)vty->index;
|
|
struct ospf_if_params *params;
|
|
|
|
assert (ifp);
|
|
|
|
params = IF_DEF_PARAMS (ifp);
|
|
if (params->bfd_info)
|
|
{
|
|
ospf_bfd_reg_dereg_all_nbr(ifp, ZEBRA_BFD_DEST_DEREGISTER);
|
|
bfd_info_free(&(params->bfd_info));
|
|
}
|
|
|
|
return CMD_SUCCESS;
|
|
}
|
|
|
|
void
|
|
ospf_bfd_init(void)
|
|
{
|
|
/* Initialize BFD client functions */
|
|
zclient->interface_bfd_dest_update = ospf_bfd_interface_dest_update;
|
|
zclient->bfd_dest_replay = ospf_bfd_nbr_replay;
|
|
|
|
/* Install BFD command */
|
|
install_element (INTERFACE_NODE, &ip_ospf_bfd_cmd);
|
|
install_element (INTERFACE_NODE, &ip_ospf_bfd_param_cmd);
|
|
install_element (INTERFACE_NODE, &no_ip_ospf_bfd_cmd);
|
|
}
|