back to topotato report
topotato coverage report
Current view: top level - staticd - static_routes.h (source / functions) Hit Total Coverage
Test: test_pim_cbsr.py::PIMCandidateBSRTest Lines: 4 4 100.0 %
Date: 2023-02-16 02:09:14 Functions: 2 2 100.0 %

          Line data    Source code
       1             : /*
       2             :  * STATICd - static routes header
       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             : #ifndef __STATIC_ROUTES_H__
      21             : #define __STATIC_ROUTES_H__
      22             : 
      23             : #include "lib/bfd.h"
      24             : #include "lib/mpls.h"
      25             : #include "table.h"
      26             : #include "memory.h"
      27             : 
      28             : #ifdef __cplusplus
      29             : extern "C" {
      30             : #endif
      31             : 
      32             : DECLARE_MGROUP(STATIC);
      33             : 
      34             : #include "staticd/static_vrf.h"
      35             : 
      36             : /* Static route label information */
      37             : struct static_nh_label {
      38             :         uint8_t num_labels;
      39             :         uint8_t reserved[3];
      40             :         mpls_label_t label[MPLS_MAX_LABELS];
      41             : };
      42             : 
      43             : enum static_blackhole_type {
      44             :         STATIC_BLACKHOLE_DROP = 0,
      45             :         STATIC_BLACKHOLE_NULL,
      46             :         STATIC_BLACKHOLE_REJECT
      47             : };
      48             : 
      49             : /*
      50             :  * The order for below macros should be in sync with
      51             :  * yang model typedef nexthop-type
      52             :  */
      53             : enum static_nh_type {
      54             :         STATIC_IFNAME = 1,
      55             :         STATIC_IPV4_GATEWAY,
      56             :         STATIC_IPV4_GATEWAY_IFNAME,
      57             :         STATIC_IPV6_GATEWAY,
      58             :         STATIC_IPV6_GATEWAY_IFNAME,
      59             :         STATIC_BLACKHOLE,
      60             : };
      61             : 
      62             : /*
      63             :  * Route Creation gives us:
      64             :  *  START -> Initial State, only exit is when we send the route to
      65             :  *          zebra for installation
      66             :  * When we send the route to Zebra move to SENT_TO_ZEBRA
      67             :  *  SENT_TO_ZEBRA -> A way to notice that we've sent the route to zebra
      68             :  *                   But have not received a response on it's status yet
      69             :  * After The response from zebra we move to INSTALLED or FAILED
      70             :  *  INSTALLED -> Route was accepted
      71             :  *  FAILED -> Route was rejected
      72             :  * When we receive notification about a nexthop that a route uses
      73             :  * We move the route back to START and initiate the process again.
      74             :  */
      75             : enum static_install_states {
      76             :         STATIC_START,
      77             :         STATIC_SENT_TO_ZEBRA,
      78             :         STATIC_INSTALLED,
      79             :         STATIC_NOT_INSTALLED,
      80             : };
      81             : 
      82             : PREDECL_DLIST(static_path_list);
      83             : PREDECL_DLIST(static_nexthop_list);
      84             : 
      85             : /* Static route information */
      86             : struct static_route_info {
      87             :         struct static_vrf *svrf;
      88             :         safi_t safi;
      89             :         /* path list */
      90             :         struct static_path_list_head path_list;
      91             : };
      92             : 
      93             : /* Static path information */
      94             : struct static_path {
      95             :         /* Route node back pointer. */
      96             :         struct route_node *rn;
      97             :         /* Linkage for static path lists */
      98             :         struct static_path_list_item list;
      99             :         /* Administrative distance. */
     100             :         uint8_t distance;
     101             :         /* Tag */
     102             :         route_tag_t tag;
     103             :         /* Table-id */
     104             :         uint32_t table_id;
     105             :         /* Nexthop list */
     106             :         struct static_nexthop_list_head nexthop_list;
     107             : };
     108             : 
     109         414 : DECLARE_DLIST(static_path_list, struct static_path, list);
     110             : 
     111             : /* Static route information. */
     112             : struct static_nexthop {
     113             :         /* Path back pointer. */
     114             :         struct static_path *pn;
     115             :         /* For linked list. */
     116             :         struct static_nexthop_list_item list;
     117             : 
     118             :         /* VRF identifier. */
     119             :         vrf_id_t nh_vrf_id;
     120             :         char nh_vrfname[VRF_NAMSIZ + 1];
     121             : 
     122             :         /*
     123             :          * States that we walk the route through
     124             :          * To know where we are.
     125             :          */
     126             :         enum static_install_states state;
     127             : 
     128             :         /* Flag for this static route's type. */
     129             :         enum static_nh_type type;
     130             : 
     131             :         /*
     132             :          * Nexthop value.
     133             :          */
     134             :         enum static_blackhole_type bh_type;
     135             :         union g_addr addr;
     136             :         ifindex_t ifindex;
     137             :         bool nh_registered;
     138             :         bool nh_valid;
     139             : 
     140             :         char ifname[INTERFACE_NAMSIZ + 1];
     141             : 
     142             :         /* Label information */
     143             :         struct static_nh_label snh_label;
     144             : 
     145             :         /*
     146             :          * Whether to pretend the nexthop is directly attached to the specified
     147             :          * link. Only meaningful when both a gateway address and interface name
     148             :          * are specified.
     149             :          */
     150             :         bool onlink;
     151             : 
     152             :         /* SR-TE color */
     153             :         uint32_t color;
     154             : 
     155             :         /** BFD integration data. */
     156             :         struct bfd_session_params *bsp;
     157             :         /** Back pointer for route node. */
     158             :         struct route_node *rn;
     159             :         /** Path connection status. */
     160             :         bool path_down;
     161             : };
     162             : 
     163         452 : DECLARE_DLIST(static_nexthop_list, struct static_nexthop, list);
     164             : 
     165             : 
     166             : /*
     167             :  * rib_dest_from_rnode
     168             :  */
     169             : static inline struct static_route_info *
     170         141 : static_route_info_from_rnode(struct route_node *rn)
     171             : {
     172         141 :         return (struct static_route_info *)(rn->info);
     173             : }
     174             : 
     175             : extern bool mpls_enabled;
     176             : extern uint32_t zebra_ecmp_count;
     177             : 
     178             : extern struct zebra_privs_t static_privs;
     179             : 
     180             : void static_fixup_vrf_ids(struct static_vrf *svrf);
     181             : 
     182             : extern struct static_nexthop *
     183             : static_add_nexthop(struct static_path *pn, enum static_nh_type type,
     184             :                    struct ipaddr *ipaddr, const char *ifname,
     185             :                    const char *nh_vrf, uint32_t color);
     186             : extern void static_install_nexthop(struct static_nexthop *nh);
     187             : 
     188             : extern void static_delete_nexthop(struct static_nexthop *nh);
     189             : 
     190             : extern void static_cleanup_vrf_ids(struct static_vrf *disable_svrf);
     191             : 
     192             : extern void static_install_intf_nh(struct interface *ifp);
     193             : 
     194             : extern void static_ifindex_update(struct interface *ifp, bool up);
     195             : 
     196             : extern void static_install_path(struct static_path *pn);
     197             : 
     198             : extern struct route_node *static_add_route(afi_t afi, safi_t safi,
     199             :                                            struct prefix *p,
     200             :                                            struct prefix_ipv6 *src_p,
     201             :                                            struct static_vrf *svrf);
     202             : extern void static_del_route(struct route_node *rn);
     203             : 
     204             : extern struct static_path *static_add_path(struct route_node *rn,
     205             :                                            uint32_t table_id, uint8_t distance);
     206             : extern void static_del_path(struct static_path *pn);
     207             : 
     208             : extern void static_get_nh_type(enum static_nh_type stype, char *type,
     209             :                                size_t size);
     210             : extern bool static_add_nexthop_validate(const char *nh_vrf_name,
     211             :                                         enum static_nh_type type,
     212             :                                         struct ipaddr *ipaddr);
     213             : extern struct stable_info *static_get_stable_info(struct route_node *rn);
     214             : 
     215             : extern void zebra_stable_node_cleanup(struct route_table *table,
     216             :                                       struct route_node *node);
     217             : 
     218             : /*
     219             :  * Max string return via API static_get_nh_str in size_t
     220             :  */
     221             : 
     222             : #define NEXTHOP_STR (INET6_ADDRSTRLEN + INTERFACE_NAMSIZ + 25)
     223             : /*
     224             :  * For the given nexthop, returns the string
     225             :  * nexthop : returns the formatted string in nexthop
     226             :  * size : max size of formatted string
     227             :  */
     228             : extern void static_get_nh_str(struct static_nexthop *nh, char *nexthop,
     229             :                               size_t size);
     230             : 
     231             : /*
     232             :  * BFD integration.
     233             :  */
     234             : extern void static_next_hop_bfd_source(struct static_nexthop *sn,
     235             :                                        const struct ipaddr *source);
     236             : extern void static_next_hop_bfd_auto_source(struct static_nexthop *sn);
     237             : extern void static_next_hop_bfd_monitor_enable(struct static_nexthop *sn,
     238             :                                                const struct lyd_node *dnode);
     239             : extern void static_next_hop_bfd_monitor_disable(struct static_nexthop *sn);
     240             : extern void static_next_hop_bfd_profile(struct static_nexthop *sn,
     241             :                                         const char *name);
     242             : extern void static_next_hop_bfd_multi_hop(struct static_nexthop *sn, bool mhop);
     243             : 
     244             : /** Call this function after zebra client initialization. */
     245             : extern void static_bfd_initialize(struct zclient *zc, struct thread_master *tm);
     246             : 
     247             : extern void static_bfd_show(struct vty *vty, bool isjson);
     248             : 
     249             : #ifdef __cplusplus
     250             : }
     251             : #endif
     252             : 
     253             : #endif

Generated by: LCOV version v1.16-topotato