back to topotato report
topotato coverage report
Current view: top level - pimd - pim_bfd.c (source / functions) Hit Total Coverage
Test: test_pim6_bootstrap.py::PIM6Bootstrap Lines: 0 38 0.0 %
Date: 2023-02-16 02:07:22 Functions: 0 5 0.0 %

          Line data    Source code
       1             : /*
       2             :  * pim_bfd.c: PIM BFD handling routines
       3             :  *
       4             :  * Copyright (C) 2017 Cumulus Networks, Inc.
       5             :  * Chirag Shah
       6             :  *
       7             :  * This program is free software; you can redistribute it and/or modify
       8             :  * it under the terms of the GNU General Public License as published by
       9             :  * the Free Software Foundation; either version 2 of the License, or
      10             :  * (at your option) any later version.
      11             :  *
      12             :  * This program is distributed in the hope that it will be useful, but
      13             :  * WITHOUT ANY WARRANTY; without even the implied warranty of
      14             :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
      15             :  * General Public License for more details.
      16             :  *
      17             :  * You should have received a copy of the GNU General Public License
      18             :  * along with this program; see the file COPYING; if not, write to the
      19             :  * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,
      20             :  * MA 02110-1301 USA
      21             :  */
      22             : 
      23             : #include <zebra.h>
      24             : 
      25             : #include "lib/json.h"
      26             : #include "command.h"
      27             : #include "vty.h"
      28             : #include "zclient.h"
      29             : 
      30             : #include "pim_instance.h"
      31             : #include "pim_neighbor.h"
      32             : #include "pim_vty.h"
      33             : #include "pim_iface.h"
      34             : #include "pim_bfd.h"
      35             : #include "bfd.h"
      36             : #include "pimd.h"
      37             : #include "pim_zebra.h"
      38             : 
      39             : /*
      40             :  * pim_bfd_write_config - Write the interface BFD configuration.
      41             :  */
      42           0 : void pim_bfd_write_config(struct vty *vty, struct interface *ifp)
      43             : {
      44           0 :         struct pim_interface *pim_ifp = ifp->info;
      45             : 
      46           0 :         if (!pim_ifp || !pim_ifp->bfd_config.enabled)
      47             :                 return;
      48             : 
      49             : #if HAVE_BFDD == 0
      50             :         if (pim_ifp->bfd_config.detection_multiplier != BFD_DEF_DETECT_MULT
      51             :             || pim_ifp->bfd_config.min_rx != BFD_DEF_MIN_RX
      52             :             || pim_ifp->bfd_config.min_tx != BFD_DEF_MIN_TX)
      53             :                 vty_out(vty, " " PIM_AF_NAME " pim bfd %d %d %d\n",
      54             :                         pim_ifp->bfd_config.detection_multiplier,
      55             :                         pim_ifp->bfd_config.min_rx, pim_ifp->bfd_config.min_tx);
      56             :         else
      57             : #endif /* ! HAVE_BFDD */
      58           0 :                 vty_out(vty, " " PIM_AF_NAME " pim bfd\n");
      59             : 
      60           0 :         if (pim_ifp->bfd_config.profile)
      61           0 :                 vty_out(vty, " " PIM_AF_NAME " pim bfd profile %s\n",
      62             :                         pim_ifp->bfd_config.profile);
      63             : }
      64             : 
      65           0 : static void pim_neighbor_bfd_cb(struct bfd_session_params *bsp,
      66             :                                 const struct bfd_session_status *bss, void *arg)
      67             : {
      68           0 :         struct pim_neighbor *nbr = arg;
      69             : 
      70           0 :         if (PIM_DEBUG_PIM_TRACE) {
      71           0 :                 zlog_debug("%s: status %s old_status %s", __func__,
      72             :                            bfd_get_status_str(bss->state),
      73             :                            bfd_get_status_str(bss->previous_state));
      74             :         }
      75             : 
      76           0 :         if (bss->state == BFD_STATUS_DOWN
      77           0 :             && bss->previous_state == BFD_STATUS_UP)
      78           0 :                 pim_neighbor_delete(nbr->interface, nbr, "BFD Session Expired");
      79           0 : }
      80             : 
      81             : /*
      82             :  * pim_bfd_info_nbr_create - Create/update BFD information for a neighbor.
      83             :  */
      84           0 : void pim_bfd_info_nbr_create(struct pim_interface *pim_ifp,
      85             :                              struct pim_neighbor *neigh)
      86             : {
      87             :         /* Check if Pim Interface BFD is enabled */
      88           0 :         if (!pim_ifp || !pim_ifp->bfd_config.enabled)
      89             :                 return;
      90             : 
      91           0 :         if (neigh->bfd_session == NULL)
      92           0 :                 neigh->bfd_session = bfd_sess_new(pim_neighbor_bfd_cb, neigh);
      93             : 
      94           0 :         bfd_sess_set_timers(
      95           0 :                 neigh->bfd_session, pim_ifp->bfd_config.detection_multiplier,
      96             :                 pim_ifp->bfd_config.min_rx, pim_ifp->bfd_config.min_tx);
      97             : #if PIM_IPV == 4
      98             :         bfd_sess_set_ipv4_addrs(neigh->bfd_session, NULL, &neigh->source_addr);
      99             : #else
     100           0 :         bfd_sess_set_ipv6_addrs(neigh->bfd_session, NULL, &neigh->source_addr);
     101             : #endif
     102           0 :         bfd_sess_set_interface(neigh->bfd_session, neigh->interface->name);
     103           0 :         bfd_sess_set_vrf(neigh->bfd_session, neigh->interface->vrf->vrf_id);
     104           0 :         bfd_sess_set_profile(neigh->bfd_session, pim_ifp->bfd_config.profile);
     105           0 :         bfd_sess_install(neigh->bfd_session);
     106             : }
     107             : 
     108             : /*
     109             :  * pim_bfd_reg_dereg_all_nbr - Register/Deregister all neighbors associated
     110             :  *                              with a interface with BFD through
     111             :  *                              zebra for starting/stopping the monitoring of
     112             :  *                              the neighbor rechahability.
     113             :  */
     114           0 : void pim_bfd_reg_dereg_all_nbr(struct interface *ifp)
     115             : {
     116           0 :         struct pim_interface *pim_ifp = NULL;
     117           0 :         struct listnode *node = NULL;
     118           0 :         struct pim_neighbor *neigh = NULL;
     119             : 
     120           0 :         pim_ifp = ifp->info;
     121           0 :         if (!pim_ifp)
     122             :                 return;
     123             : 
     124           0 :         for (ALL_LIST_ELEMENTS_RO(pim_ifp->pim_neighbor_list, node, neigh)) {
     125           0 :                 if (pim_ifp->bfd_config.enabled)
     126           0 :                         pim_bfd_info_nbr_create(pim_ifp, neigh);
     127             :                 else
     128           0 :                         bfd_sess_free(&neigh->bfd_session);
     129             :         }
     130             : }
     131             : 
     132           0 : void pim_bfd_init(void)
     133             : {
     134           0 :         bfd_protocol_integration_init(pim_zebra_zclient_get(), router->master);
     135           0 : }

Generated by: LCOV version v1.16-topotato