back to topotato report
topotato coverage report
Current view: top level - bgpd - bgp_evpn.h (source / functions) Hit Total Coverage
Test: aggregated run ( view descriptions ) Lines: 15 62 24.2 %
Date: 2023-02-24 19:38:44 Functions: 3 4 75.0 %

          Line data    Source code
       1             : /* E-VPN header for packet handling
       2             :  * Copyright (C) 2016 6WIND
       3             :  *
       4             :  * This file is part of FRRouting.
       5             :  *
       6             :  * FRRouting 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
       8             :  * Free Software Foundation; either version 2, or (at your option) any
       9             :  * later version.
      10             :  *
      11             :  * FRRouting is distributed in the hope that it will be useful, but
      12             :  * WITHOUT ANY WARRANTY; without even the implied warranty of
      13             :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
      14             :  * General Public License for 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             : 
      21             : #ifndef _QUAGGA_BGP_EVPN_H
      22             : #define _QUAGGA_BGP_EVPN_H
      23             : 
      24             : #include "vxlan.h"
      25             : #include "bgpd.h"
      26             : 
      27             : #define EVPN_ROUTE_STRLEN 200 /* Must be >> MAC + IPv6 strings. */
      28             : #define EVPN_AUTORT_VXLAN 0x10000000
      29             : 
      30             : #define EVPN_ENABLED(bgp)  (bgp)->advertise_all_vni
      31          90 : static inline int is_evpn_enabled(void)
      32             : {
      33          90 :         struct bgp *bgp = NULL;
      34             : 
      35          90 :         bgp = bgp_get_evpn();
      36          90 :         return bgp ? EVPN_ENABLED(bgp) : 0;
      37             : }
      38             : 
      39           0 : static inline void vni2label(vni_t vni, mpls_label_t *label)
      40             : {
      41           0 :         uint8_t *tag = (uint8_t *)label;
      42             : 
      43           0 :         tag[0] = (vni >> 16) & 0xFF;
      44           0 :         tag[1] = (vni >> 8) & 0xFF;
      45           0 :         tag[2] = vni & 0xFF;
      46           0 : }
      47             : 
      48           0 : static inline vni_t label2vni(mpls_label_t *label)
      49             : {
      50           0 :         uint8_t *tag = (uint8_t *)label;
      51           0 :         vni_t vni;
      52             : 
      53           0 :         vni = ((uint32_t)*tag++ << 16);
      54           0 :         vni |= (uint32_t)*tag++ << 8;
      55           0 :         vni |= (uint32_t)(*tag & 0xFF);
      56             : 
      57           0 :         return vni;
      58             : }
      59             : 
      60         127 : static inline int advertise_type5_routes(struct bgp *bgp_vrf,
      61             :                                          afi_t afi)
      62             : {
      63         127 :         if (!bgp_vrf->l3vni)
      64             :                 return 0;
      65             : 
      66           0 :         if ((afi == AFI_IP)
      67           0 :             && ((CHECK_FLAG(bgp_vrf->af_flags[AFI_L2VPN][SAFI_EVPN],
      68             :                             BGP_L2VPN_EVPN_ADV_IPV4_UNICAST))
      69             :                 || (CHECK_FLAG(bgp_vrf->af_flags[AFI_L2VPN][SAFI_EVPN],
      70             :                                BGP_L2VPN_EVPN_ADV_IPV4_UNICAST_GW_IP))))
      71             :                 return 1;
      72             : 
      73           0 :         if ((afi == AFI_IP6)
      74           0 :             && ((CHECK_FLAG(bgp_vrf->af_flags[AFI_L2VPN][SAFI_EVPN],
      75             :                             BGP_L2VPN_EVPN_ADV_IPV6_UNICAST))
      76             :                 || (CHECK_FLAG(bgp_vrf->af_flags[AFI_L2VPN][SAFI_EVPN],
      77             :                                BGP_L2VPN_EVPN_ADV_IPV6_UNICAST_GW_IP))))
      78           0 :                 return 1;
      79             : 
      80             :         return 0;
      81             : }
      82             : 
      83             : /* Flag if the route's parent is a EVPN route. */
      84             : static inline struct bgp_path_info *
      85         186 : get_route_parent_evpn(struct bgp_path_info *ri)
      86             : {
      87         186 :         struct bgp_path_info *parent_ri;
      88             : 
      89             :         /* If not imported (or doesn't have a parent), bail. */
      90         186 :         if (ri->sub_type != BGP_ROUTE_IMPORTED ||
      91           0 :             !ri->extra ||
      92           0 :             !ri->extra->parent)
      93             :                 return NULL;
      94             : 
      95             :         /* Determine parent recursively */
      96             :         for (parent_ri = ri->extra->parent;
      97           0 :              parent_ri->extra && parent_ri->extra->parent;
      98             :              parent_ri = parent_ri->extra->parent)
      99             :                 ;
     100             : 
     101             :         return parent_ri;
     102             : }
     103             : 
     104             : /* Flag if the route's parent is a EVPN route. */
     105         131 : static inline int is_route_parent_evpn(struct bgp_path_info *ri)
     106             : {
     107         131 :         struct bgp_path_info *parent_ri;
     108         131 :         struct bgp_table *table;
     109         131 :         struct bgp_dest *dest;
     110             : 
     111         131 :         parent_ri = get_route_parent_evpn(ri);
     112         131 :         if (!parent_ri)
     113             :                 return 0;
     114             : 
     115             :         /* See if of family L2VPN/EVPN */
     116           0 :         dest = parent_ri->net;
     117           0 :         if (!dest)
     118             :                 return 0;
     119           0 :         table = bgp_dest_table(dest);
     120           0 :         if (table &&
     121           0 :             table->afi == AFI_L2VPN &&
     122             :             table->safi == SAFI_EVPN)
     123           0 :                 return 1;
     124             :         return 0;
     125             : }
     126             : 
     127             : /* Flag if the route path's family is EVPN. */
     128           0 : static inline bool is_pi_family_evpn(struct bgp_path_info *pi)
     129             : {
     130           0 :         return is_pi_family_matching(pi, AFI_L2VPN, SAFI_EVPN);
     131             : }
     132             : 
     133             : /* Flag if the route is injectable into EVPN. This would be either a
     134             :  * non-imported route or a non-EVPN imported route.
     135             :  */
     136           0 : static inline bool is_route_injectable_into_evpn(struct bgp_path_info *pi)
     137             : {
     138           0 :         struct bgp_path_info *parent_pi;
     139           0 :         struct bgp_table *table;
     140           0 :         struct bgp_dest *dest;
     141             : 
     142           0 :         if (pi->sub_type != BGP_ROUTE_IMPORTED ||
     143           0 :             !pi->extra ||
     144           0 :             !pi->extra->parent)
     145             :                 return true;
     146             : 
     147           0 :         parent_pi = (struct bgp_path_info *)pi->extra->parent;
     148           0 :         dest = parent_pi->net;
     149           0 :         if (!dest)
     150             :                 return true;
     151           0 :         table = bgp_dest_table(dest);
     152           0 :         if (table &&
     153           0 :             table->afi == AFI_L2VPN &&
     154             :             table->safi == SAFI_EVPN)
     155           0 :                 return false;
     156             :         return true;
     157             : }
     158             : 
     159           0 : static inline bool evpn_resolve_overlay_index(void)
     160             : {
     161           0 :         struct bgp *bgp = NULL;
     162             : 
     163           0 :         bgp = bgp_get_evpn();
     164           0 :         return bgp ? bgp->resolve_overlay_index : false;
     165             : }
     166             : 
     167             : extern void bgp_evpn_advertise_type5_route(struct bgp *bgp_vrf,
     168             :                                            const struct prefix *p,
     169             :                                            struct attr *src_attr, afi_t afi,
     170             :                                            safi_t safi);
     171             : extern void bgp_evpn_withdraw_type5_route(struct bgp *bgp_vrf,
     172             :                                           const struct prefix *p, afi_t afi,
     173             :                                           safi_t safi);
     174             : extern void bgp_evpn_withdraw_type5_routes(struct bgp *bgp_vrf, afi_t afi,
     175             :                                            safi_t safi);
     176             : extern void bgp_evpn_advertise_type5_routes(struct bgp *bgp_vrf, afi_t afi,
     177             :                                             safi_t safi);
     178             : extern void bgp_evpn_vrf_delete(struct bgp *bgp_vrf);
     179             : extern void bgp_evpn_handle_router_id_update(struct bgp *bgp, int withdraw);
     180             : extern char *bgp_evpn_label2str(mpls_label_t *label, uint32_t num_labels,
     181             :                                 char *buf, int len);
     182             : extern void bgp_evpn_route2json(const struct prefix_evpn *p, json_object *json);
     183             : extern void bgp_evpn_encode_prefix(struct stream *s, const struct prefix *p,
     184             :                                    const struct prefix_rd *prd,
     185             :                                    mpls_label_t *label, uint32_t num_labels,
     186             :                                    struct attr *attr, bool addpath_capable,
     187             :                                    uint32_t addpath_tx_id);
     188             : extern int bgp_nlri_parse_evpn(struct peer *peer, struct attr *attr,
     189             :                                struct bgp_nlri *packet, int withdraw);
     190             : extern int bgp_evpn_import_route(struct bgp *bgp, afi_t afi, safi_t safi,
     191             :                                  const struct prefix *p,
     192             :                                  struct bgp_path_info *ri);
     193             : extern int bgp_evpn_unimport_route(struct bgp *bgp, afi_t afi, safi_t safi,
     194             :                                    const struct prefix *p,
     195             :                                    struct bgp_path_info *ri);
     196             : extern int bgp_filter_evpn_routes_upon_martian_nh_change(struct bgp *bgp);
     197             : extern int bgp_evpn_local_macip_del(struct bgp *bgp, vni_t vni,
     198             :                                     struct ethaddr *mac, struct ipaddr *ip,
     199             :                                         int state);
     200             : extern int bgp_evpn_local_macip_add(struct bgp *bgp, vni_t vni,
     201             :                                     struct ethaddr *mac, struct ipaddr *ip,
     202             :                                     uint8_t flags, uint32_t seq, esi_t *esi);
     203             : extern int bgp_evpn_local_l3vni_add(vni_t vni, vrf_id_t vrf_id,
     204             :                                     struct ethaddr *rmac,
     205             :                                     struct ethaddr *vrr_rmac,
     206             :                                     struct in_addr originator_ip, int filter,
     207             :                                     ifindex_t svi_ifindex, bool is_anycast_mac);
     208             : extern int bgp_evpn_local_l3vni_del(vni_t vni, vrf_id_t vrf_id);
     209             : extern int bgp_evpn_local_vni_del(struct bgp *bgp, vni_t vni);
     210             : extern int bgp_evpn_local_vni_add(struct bgp *bgp, vni_t vni,
     211             :                                   struct in_addr originator_ip,
     212             :                                   vrf_id_t tenant_vrf_id,
     213             :                                   struct in_addr mcast_grp,
     214             :                                   ifindex_t svi_ifindex);
     215             : extern void bgp_evpn_flood_control_change(struct bgp *bgp);
     216             : extern void bgp_evpn_cleanup_on_disable(struct bgp *bgp);
     217             : extern void bgp_evpn_cleanup(struct bgp *bgp);
     218             : extern void bgp_evpn_init(struct bgp *bgp);
     219             : extern int bgp_evpn_get_type5_prefixlen(const struct prefix *pfx);
     220             : extern bool bgp_evpn_is_prefix_nht_supported(const struct prefix *pfx);
     221             : extern void update_advertise_vrf_routes(struct bgp *bgp_vrf);
     222             : extern void bgp_evpn_show_remote_ip_hash(struct hash_bucket *bucket,
     223             :                                          void *args);
     224             : extern void bgp_evpn_show_vni_svi_hash(struct hash_bucket *bucket, void *args);
     225             : extern bool bgp_evpn_is_gateway_ip_resolved(struct bgp_nexthop_cache *bnc);
     226             : extern void
     227             : bgp_evpn_handle_resolve_overlay_index_set(struct hash_bucket *bucket,
     228             :                                           void *arg);
     229             : extern void
     230             : bgp_evpn_handle_resolve_overlay_index_unset(struct hash_bucket *bucket,
     231             :                                             void *arg);
     232             : 
     233             : #endif /* _QUAGGA_BGP_EVPN_H */

Generated by: LCOV version v1.16-topotato