back to topotato report
topotato coverage report
Current view: top level - staticd - static_vrf.c (source / functions) Hit Total Coverage
Test: test_pim6_prune_propagate.py::PIM6PrunePropagate Lines: 67 76 88.2 %
Date: 2023-02-24 18:39:23 Functions: 11 12 91.7 %

          Line data    Source code
       1             : /*
       2             :  * STATICd - vrf code
       3             :  * Copyright (C) 2018 Cumulus Networks, Inc.
       4             :  *               Donald Sharp
       5             :  *
       6             :  * This program is free software; you can redistribute it and/or modify it
       7             :  * under the terms of the GNU General Public License as published by the Free
       8             :  * Software Foundation; either version 2 of the License, or (at your option)
       9             :  * any later version.
      10             :  *
      11             :  * This program is distributed in the hope that it will be useful, but WITHOUT
      12             :  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
      13             :  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
      14             :  * more details.
      15             :  *
      16             :  * You should have received a copy of the GNU General Public License along
      17             :  * with this program; see the file COPYING; if not, write to the Free Software
      18             :  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
      19             :  */
      20             : #include <zebra.h>
      21             : 
      22             : #include "vrf.h"
      23             : #include "nexthop.h"
      24             : #include "table.h"
      25             : #include "srcdest_table.h"
      26             : #include "northbound_cli.h"
      27             : 
      28             : #include "static_vrf.h"
      29             : #include "static_routes.h"
      30             : #include "static_zebra.h"
      31             : 
      32          12 : DEFINE_MTYPE_STATIC(STATIC, STATIC_RTABLE_INFO, "Static Route Table Info");
      33             : 
      34           4 : static struct static_vrf *static_vrf_alloc(void)
      35             : {
      36           4 :         struct route_table *table;
      37           4 :         struct static_vrf *svrf;
      38           4 :         struct stable_info *info;
      39           4 :         safi_t safi;
      40           4 :         afi_t afi;
      41             : 
      42           4 :         svrf = XCALLOC(MTYPE_STATIC_RTABLE_INFO, sizeof(struct static_vrf));
      43             : 
      44          16 :         for (afi = AFI_IP; afi <= AFI_IP6; afi++) {
      45          24 :                 for (safi = SAFI_UNICAST; safi <= SAFI_MULTICAST; safi++) {
      46          16 :                         if (afi == AFI_IP6)
      47           8 :                                 table = srcdest_table_init();
      48             :                         else
      49           8 :                                 table = route_table_init();
      50             : 
      51          16 :                         info = XCALLOC(MTYPE_STATIC_RTABLE_INFO,
      52             :                                        sizeof(struct stable_info));
      53          16 :                         info->svrf = svrf;
      54          16 :                         info->afi = afi;
      55          16 :                         info->safi = safi;
      56          16 :                         route_table_set_info(table, info);
      57             : 
      58          16 :                         table->cleanup = zebra_stable_node_cleanup;
      59          16 :                         svrf->stable[afi][safi] = table;
      60             :                 }
      61             :         }
      62           4 :         return svrf;
      63             : }
      64             : 
      65           4 : static int static_vrf_new(struct vrf *vrf)
      66             : {
      67           4 :         struct static_vrf *svrf;
      68             : 
      69           4 :         svrf = static_vrf_alloc();
      70           4 :         vrf->info = svrf;
      71           4 :         svrf->vrf = vrf;
      72             : 
      73           4 :         return 0;
      74             : }
      75             : 
      76           4 : static int static_vrf_enable(struct vrf *vrf)
      77             : {
      78           4 :         static_zebra_vrf_register(vrf);
      79             : 
      80           4 :         static_fixup_vrf_ids(vrf->info);
      81             : 
      82           4 :         return 0;
      83             : }
      84             : 
      85           4 : static int static_vrf_disable(struct vrf *vrf)
      86             : {
      87           4 :         static_zebra_vrf_unregister(vrf);
      88           4 :         return 0;
      89             : }
      90             : 
      91           4 : static int static_vrf_delete(struct vrf *vrf)
      92             : {
      93           4 :         struct route_table *table;
      94           4 :         struct static_vrf *svrf;
      95           4 :         safi_t safi;
      96           4 :         afi_t afi;
      97           4 :         void *info;
      98             : 
      99           4 :         svrf = vrf->info;
     100          12 :         for (afi = AFI_IP; afi <= AFI_IP6; afi++) {
     101          24 :                 for (safi = SAFI_UNICAST; safi <= SAFI_MULTICAST; safi++) {
     102          16 :                         table = svrf->stable[afi][safi];
     103          16 :                         info = route_table_get_info(table);
     104          16 :                         route_table_finish(table);
     105          16 :                         XFREE(MTYPE_STATIC_RTABLE_INFO, info);
     106          16 :                         svrf->stable[afi][safi] = NULL;
     107             :                 }
     108             :         }
     109           4 :         XFREE(MTYPE_STATIC_RTABLE_INFO, svrf);
     110           4 :         return 0;
     111             : }
     112             : 
     113             : /* Lookup the static routing table in a VRF. */
     114         261 : struct route_table *static_vrf_static_table(afi_t afi, safi_t safi,
     115             :                                             struct static_vrf *svrf)
     116             : {
     117         261 :         if (!svrf)
     118             :                 return NULL;
     119             : 
     120         261 :         if (afi >= AFI_MAX || safi >= SAFI_MAX)
     121             :                 return NULL;
     122             : 
     123         261 :         return svrf->stable[afi][safi];
     124             : }
     125             : 
     126           6 : struct static_vrf *static_vrf_lookup_by_name(const char *name)
     127             : {
     128           6 :         struct vrf *vrf;
     129             : 
     130           6 :         if (!name)
     131           0 :                 name = VRF_DEFAULT_NAME;
     132             : 
     133           6 :         vrf = vrf_lookup_by_name(name);
     134           6 :         if (vrf)
     135           6 :                 return ((struct static_vrf *)vrf->info);
     136             : 
     137             :         return NULL;
     138             : }
     139             : 
     140           0 : static int static_vrf_config_write(struct vty *vty)
     141             : {
     142           0 :         struct lyd_node *dnode;
     143           0 :         int written = 0;
     144             : 
     145           0 :         dnode = yang_dnode_get(running_config->dnode, "/frr-routing:routing");
     146           0 :         if (dnode) {
     147           0 :                 nb_cli_show_dnode_cmds(vty, dnode, false);
     148           0 :                 written = 1;
     149             :         }
     150             : 
     151           0 :         return written;
     152             : }
     153             : 
     154           4 : void static_vrf_init(void)
     155             : {
     156           4 :         vrf_init(static_vrf_new, static_vrf_enable, static_vrf_disable,
     157             :                  static_vrf_delete);
     158             : 
     159           4 :         vrf_cmd_init(static_vrf_config_write);
     160           4 : }
     161             : 
     162           4 : void static_vrf_terminate(void)
     163             : {
     164           4 :         vrf_terminate();
     165           4 : }

Generated by: LCOV version v1.16-topotato