back to topotato report
topotato coverage report
Current view: top level - bgpd - bgp_label.h (source / functions) Hit Total Coverage
Test: test_bgp_set_aspath_replace.py::BGPSetAspathReplace Lines: 2 32 6.2 %
Date: 2023-02-24 18:37:49 Functions: 0 1 0.0 %

          Line data    Source code
       1             : /* BGP carrying Label information
       2             :  * Copyright (C) 2013 Cumulus Networks, Inc.
       3             :  *
       4             :  * This file is part of GNU Zebra.
       5             :  *
       6             :  * GNU Zebra 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             :  * GNU Zebra 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 _BGP_LABEL_H
      22             : #define _BGP_LABEL_H
      23             : 
      24             : #define BGP_LABEL_BYTES 3
      25             : #define BGP_LABEL_BITS 24
      26             : #define BGP_WITHDRAW_LABEL 0x800000
      27             : #define BGP_PREVENT_VRF_2_VRF_LEAK 0xFFFFFFFE
      28             : 
      29             : struct bgp_dest;
      30             : struct bgp_path_info;
      31             : struct peer;
      32             : 
      33             : extern int bgp_reg_for_label_callback(mpls_label_t new_label, void *labelid,
      34             :                                     bool allocated);
      35             : extern void bgp_reg_dereg_for_label(struct bgp_dest *dest,
      36             :                                     struct bgp_path_info *pi, bool reg);
      37             : extern int bgp_parse_fec_update(void);
      38             : extern mpls_label_t bgp_adv_label(struct bgp_dest *dest,
      39             :                                   struct bgp_path_info *pi, struct peer *to,
      40             :                                   afi_t afi, safi_t safi);
      41             : 
      42             : extern int bgp_nlri_parse_label(struct peer *peer, struct attr *attr,
      43             :                                 struct bgp_nlri *packet);
      44             : 
      45           0 : static inline int bgp_labeled_safi(safi_t safi)
      46             : {
      47             :         /* NOTE: This API really says a label (tag) MAY be present. Not all EVPN
      48             :          * routes will have a label.
      49             :          */
      50           0 :         if ((safi == SAFI_LABELED_UNICAST) || (safi == SAFI_MPLS_VPN)
      51           0 :             || (safi == SAFI_EVPN))
      52           0 :                 return 1;
      53             :         return 0;
      54             : }
      55             : 
      56           0 : static inline int bgp_is_withdraw_label(mpls_label_t *label)
      57             : {
      58           0 :         uint8_t *pkt = (uint8_t *)label;
      59             : 
      60             :         /* The check on pkt[2] for 0x00 or 0x02 is in case bgp_set_valid_label()
      61             :          * was called on the withdraw label */
      62           0 :         if (((pkt[0] == 0x80) || (pkt[0] == 0x00)) && (pkt[1] == 0x00)
      63           0 :             && ((pkt[2] == 0x00) || (pkt[2] == 0x02)))
      64           0 :                 return 1;
      65             :         return 0;
      66             : }
      67             : 
      68          20 : static inline int bgp_is_valid_label(const mpls_label_t *label)
      69             : {
      70           0 :         uint8_t *t = (uint8_t *)label;
      71          20 :         if (!t)
      72             :                 return 0;
      73           0 :         return (t[2] & 0x02);
      74             : }
      75             : 
      76           0 : static inline void bgp_set_valid_label(mpls_label_t *label)
      77             : {
      78           0 :         uint8_t *t = (uint8_t *)label;
      79           0 :         if (t)
      80           0 :                 t[2] |= 0x02;
      81           0 : }
      82             : 
      83           0 : static inline void bgp_unset_valid_label(mpls_label_t *label)
      84             : {
      85           0 :         uint8_t *t = (uint8_t *)label;
      86           0 :         if (t)
      87           0 :                 t[2] &= ~0x02;
      88           0 : }
      89             : 
      90           0 : static inline void bgp_register_for_label(struct bgp_dest *dest,
      91             :                                           struct bgp_path_info *pi)
      92             : {
      93           0 :         bgp_reg_dereg_for_label(dest, pi, true);
      94           0 : }
      95             : 
      96           0 : static inline void bgp_unregister_for_label(struct bgp_dest *dest)
      97             : {
      98           0 :         bgp_reg_dereg_for_label(dest, NULL, false);
      99           0 : }
     100             : 
     101             : /* Return BOS value of label stream */
     102           0 : static inline uint8_t label_bos(mpls_label_t *label)
     103             : {
     104           0 :         uint8_t *t = (uint8_t *)label;
     105           0 :         return (t[2] & 0x01);
     106             : };
     107             : 
     108             : #endif /* _BGP_LABEL_H */

Generated by: LCOV version v1.16-topotato