]> git.proxmox.com Git - mirror_frr.git/blobdiff - bgpd/bgp_community.h
Merge pull request #13649 from donaldsharp/unlock_the_node_or_else
[mirror_frr.git] / bgpd / bgp_community.h
index 616ddb4405b371228e4797558313e1c7b4a505c4..e7af362ea845d3c0ff8b1443c8ba3ae0b4b3ad58 100644 (file)
@@ -1,21 +1,6 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
 /* Community attribute related functions.
  * Copyright (C) 1998 Kunihiro Ishiguro
- *
- * This file is part of GNU Zebra.
- *
- * GNU Zebra is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License as published by the
- * Free Software Foundation; either version 2, or (at your option) any
- * later version.
- *
- * GNU Zebra is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License along
- * with this program; see the file COPYING; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
  */
 
 #ifndef _QUAGGA_BGP_COMMUNITY_H
@@ -23,6 +8,7 @@
 
 #include "lib/json.h"
 #include "bgpd/bgp_route.h"
+#include "bgpd/bgp_attr.h"
 
 /* Communities attribute.  */
 struct community {
@@ -44,6 +30,9 @@ struct community {
 };
 
 /* Well-known communities value.  */
+#if CONFDATE > 20230801
+CPP_NOTICE("Deprecate COMMUNITY_INTERNET BGP community")
+#endif
 #define COMMUNITY_INTERNET                      0x0
 #define COMMUNITY_GSHUT                         0xFFFF0000
 #define COMMUNITY_ACCEPT_OWN                    0xFFFF0001
@@ -109,4 +98,30 @@ extern void bgp_remove_comm_from_aggregate_hash(struct bgp_aggregate *aggregate,
                                                struct community *community);
 extern void bgp_aggr_community_remove(void *arg);
 
+/* This implies that when propagating routes into a VRF, the ACCEPT_OWN
+ * community SHOULD NOT be propagated.
+ */
+static inline void community_strip_accept_own(struct attr *attr)
+{
+       struct community *old_com = bgp_attr_get_community(attr);
+       struct community *new_com = NULL;
+       uint32_t val = COMMUNITY_ACCEPT_OWN;
+
+       if (old_com && community_include(old_com, val)) {
+               new_com = community_dup(old_com);
+               val = htonl(val);
+               community_del_val(new_com, &val);
+
+               if (!old_com->refcnt)
+                       community_free(&old_com);
+
+               if (!new_com->size) {
+                       community_free(&new_com);
+                       bgp_attr_set_community(attr, NULL);
+               } else {
+                       bgp_attr_set_community(attr, new_com);
+               }
+       }
+}
+
 #endif /* _QUAGGA_BGP_COMMUNITY_H */