back to topotato report
topotato coverage report
Current view: top level - bgpd - bgp_community.h (source / functions) Hit Total Coverage
Test: test_bgp_minimum_holdtime.py::TestBGPMinimumHoldtime Lines: 0 15 0.0 %
Date: 2023-02-24 18:37:25 Functions: 0 1 0.0 %

          Line data    Source code
       1             : /* Community attribute related functions.
       2             :  * Copyright (C) 1998 Kunihiro Ishiguro
       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 _QUAGGA_BGP_COMMUNITY_H
      22             : #define _QUAGGA_BGP_COMMUNITY_H
      23             : 
      24             : #include "lib/json.h"
      25             : #include "bgpd/bgp_route.h"
      26             : #include "bgpd/bgp_attr.h"
      27             : 
      28             : /* Communities attribute.  */
      29             : struct community {
      30             :         /* Reference count of communities value.  */
      31             :         unsigned long refcnt;
      32             : 
      33             :         /* Communities value size.  */
      34             :         int size;
      35             : 
      36             :         /* Communities value.  */
      37             :         uint32_t *val;
      38             : 
      39             :         /* Communities as a json object */
      40             :         json_object *json;
      41             : 
      42             :         /* String of community attribute.  This sring is used by vty output
      43             :            and expanded community-list for regular expression match.  */
      44             :         char *str;
      45             : };
      46             : 
      47             : /* Well-known communities value.  */
      48             : #define COMMUNITY_INTERNET                      0x0
      49             : #define COMMUNITY_GSHUT                         0xFFFF0000
      50             : #define COMMUNITY_ACCEPT_OWN                    0xFFFF0001
      51             : #define COMMUNITY_ROUTE_FILTER_TRANSLATED_v4    0xFFFF0002
      52             : #define COMMUNITY_ROUTE_FILTER_v4               0xFFFF0003
      53             : #define COMMUNITY_ROUTE_FILTER_TRANSLATED_v6    0xFFFF0004
      54             : #define COMMUNITY_ROUTE_FILTER_v6               0xFFFF0005
      55             : #define COMMUNITY_LLGR_STALE                    0xFFFF0006
      56             : #define COMMUNITY_NO_LLGR                       0xFFFF0007
      57             : #define COMMUNITY_ACCEPT_OWN_NEXTHOP            0xFFFF0008
      58             : #define COMMUNITY_BLACKHOLE                     0xFFFF029A
      59             : #define COMMUNITY_NO_EXPORT                     0xFFFFFF01
      60             : #define COMMUNITY_NO_ADVERTISE                  0xFFFFFF02
      61             : #define COMMUNITY_NO_EXPORT_SUBCONFED           0xFFFFFF03
      62             : #define COMMUNITY_LOCAL_AS                      0xFFFFFF03
      63             : #define COMMUNITY_NO_PEER                       0xFFFFFF04
      64             : 
      65             : #define COMMUNITY_SIZE 4
      66             : 
      67             : /* Macros of community attribute.  */
      68             : #define com_length(X)    ((X)->size * COMMUNITY_SIZE)
      69             : #define com_lastval(X)   ((X)->val + (X)->size - 1)
      70             : #define com_nthval(X,n)  ((X)->val + (n))
      71             : 
      72             : /* Prototypes of communities attribute functions.  */
      73             : extern void community_init(void);
      74             : extern void community_finish(void);
      75             : extern void community_free(struct community **comm);
      76             : extern struct community *community_uniq_sort(struct community *com);
      77             : extern struct community *community_parse(uint32_t *pnt, unsigned short length);
      78             : extern struct community *community_intern(struct community *com);
      79             : extern void community_unintern(struct community **com);
      80             : extern char *community_str(struct community *com, bool make_json,
      81             :                            bool translate_alias);
      82             : extern unsigned int community_hash_make(const struct community *com);
      83             : extern struct community *community_str2com(const char *str);
      84             : extern bool community_match(const struct community *com1,
      85             :                             const struct community *com2);
      86             : extern bool community_cmp(const struct community *c1,
      87             :                           const struct community *c2);
      88             : extern struct community *community_merge(struct community *com1,
      89             :                                          struct community *com2);
      90             : extern struct community *community_delete(struct community *com1,
      91             :                                           struct community *com2);
      92             : extern struct community *community_dup(struct community *com);
      93             : extern bool community_include(struct community *com, uint32_t val);
      94             : extern void community_add_val(struct community *com, uint32_t val);
      95             : extern void community_del_val(struct community *com, uint32_t *val);
      96             : extern unsigned long community_count(void);
      97             : extern struct hash *community_hash(void);
      98             : extern uint32_t community_val_get(struct community *com, int i);
      99             : extern void bgp_compute_aggregate_community(struct bgp_aggregate *aggregate,
     100             :                                             struct community *community);
     101             : 
     102             : extern void bgp_compute_aggregate_community_val(
     103             :                                                struct bgp_aggregate *aggregate);
     104             : extern void bgp_compute_aggregate_community_hash(
     105             :                                                 struct bgp_aggregate *aggregate,
     106             :                                                 struct community *community);
     107             : extern void bgp_remove_community_from_aggregate(struct bgp_aggregate *aggregate,
     108             :                                                 struct community *community);
     109             : extern void bgp_remove_comm_from_aggregate_hash(struct bgp_aggregate *aggregate,
     110             :                                                 struct community *community);
     111             : extern void bgp_aggr_community_remove(void *arg);
     112             : 
     113             : /* This implies that when propagating routes into a VRF, the ACCEPT_OWN
     114             :  * community SHOULD NOT be propagated.
     115             :  */
     116           0 : static inline void community_strip_accept_own(struct attr *attr)
     117             : {
     118           0 :         struct community *old_com = bgp_attr_get_community(attr);
     119           0 :         struct community *new_com = NULL;
     120           0 :         uint32_t val = COMMUNITY_ACCEPT_OWN;
     121             : 
     122           0 :         if (old_com && community_include(old_com, val)) {
     123           0 :                 new_com = community_dup(old_com);
     124           0 :                 val = htonl(val);
     125           0 :                 community_del_val(new_com, &val);
     126             : 
     127           0 :                 if (!old_com->refcnt)
     128           0 :                         community_free(&old_com);
     129             : 
     130           0 :                 if (!new_com->size) {
     131           0 :                         community_free(&new_com);
     132           0 :                         bgp_attr_set_community(attr, NULL);
     133             :                 } else {
     134           0 :                         bgp_attr_set_community(attr, new_com);
     135             :                 }
     136             :         }
     137           0 : }
     138             : 
     139             : #endif /* _QUAGGA_BGP_COMMUNITY_H */

Generated by: LCOV version v1.16-topotato