]> git.proxmox.com Git - mirror_frr.git/blobdiff - bgpd/bgpd.h
*: Convert `struct event_master` to `struct event_loop`
[mirror_frr.git] / bgpd / bgpd.h
index a0627af75192f70db1c8d1d003d93920316f9427..a08a2870ee7ce54fa1342e57ceb75a8c24c04715 100644 (file)
@@ -1,21 +1,6 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
 /* BGP message definition header.
  * Copyright (C) 1996, 97, 98, 99, 2000 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_BGPD_H
@@ -31,6 +16,7 @@
 #include "vty.h"
 #include "srv6.h"
 #include "iana_afi.h"
+#include "asn.h"
 
 /* For union sockunion.  */
 #include "queue.h"
@@ -77,7 +63,6 @@ enum zebra_gr_mode {
 };
 
 /* Typedef BGP specific types.  */
-typedef uint32_t as_t;
 typedef uint16_t as16_t; /* we may still encounter 16 Bit asnums */
 typedef uint16_t bgp_size_t;
 
@@ -113,7 +98,7 @@ struct bgp_master {
        struct list *bgp;
 
        /* BGP thread master.  */
-       struct thread_master *master;
+       struct event_loop *master;
 
        /* Listening sockets */
        struct list *listen_sockets;
@@ -141,7 +126,7 @@ struct bgp_master {
        uint64_t subgrp_idspace;
 
        /* timer to dampen route map changes */
-       struct thread *t_rmap_update; /* Handle route map updates */
+       struct event *t_rmap_update; /* Handle route map updates */
        uint32_t rmap_update_timer;   /* Route map update timer */
 #define RMAP_DEFAULT_UPDATE_TIMER 5 /* disabled by default */
 
@@ -218,6 +203,7 @@ struct vpn_policy {
        /* should be mpls_label_t? */
        uint32_t tovpn_label; /* may be MPLS_LABEL_NONE */
        uint32_t tovpn_zebra_vrf_label_last_sent;
+       char *tovpn_rd_pretty;
        struct prefix_rd tovpn_rd;
        struct prefix tovpn_nexthop; /* unset => set to 0 */
        uint32_t flags;
@@ -280,11 +266,11 @@ struct graceful_restart_info {
        /* Count of EOR received */
        uint32_t eor_received;
        /* Deferral Timer */
-       struct thread *t_select_deferral;
+       struct event *t_select_deferral;
        /* Routes Deferred */
        uint32_t gr_deferred;
        /* Best route select */
-       struct thread *t_route_select;
+       struct event *t_route_select;
        /* AFI, SAFI enabled */
        bool af_enabled[AFI_MAX][SAFI_MAX];
        /* Route update completed */
@@ -339,6 +325,11 @@ struct bgp_srv6_function {
        char locator_name[SRV6_LOCNAME_SIZE];
 };
 
+struct as_confed {
+       as_t as;
+       char *as_pretty;
+};
+
 /* BGP instance structure.  */
 struct bgp {
        /* AS number of this BGP instance.  */
@@ -399,6 +390,7 @@ struct bgp {
        uint16_t config;
 #define BGP_CONFIG_CLUSTER_ID             (1 << 0)
 #define BGP_CONFIG_CONFEDERATION          (1 << 1)
+#define BGP_CONFIG_ASNOTATION             (1 << 2)
 
        /* BGP router identifier.  */
        struct in_addr router_id;
@@ -410,18 +402,20 @@ struct bgp {
 
        /* BGP confederation information.  */
        as_t confed_id;
-       as_t *confed_peers;
+       char *confed_id_pretty;
+       struct as_confed *confed_peers;
        int confed_peers_cnt;
 
-       struct thread
-               *t_startup; /* start-up timer on only once at the beginning */
+       /* start-up timer on only once at the beginning */
+       struct event *t_startup;
 
        uint32_t v_maxmed_onstartup; /* Duration of max-med on start-up */
 #define BGP_MAXMED_ONSTARTUP_UNCONFIGURED  0 /* 0 means off, its the default */
        uint32_t maxmed_onstartup_value;     /* Max-med value when active on
                                                 start-up */
-       struct thread
-               *t_maxmed_onstartup; /* non-null when max-med onstartup is on */
+
+       /* non-null when max-med onstartup is on */
+       struct event *t_maxmed_onstartup;
        uint8_t maxmed_onstartup_over; /* Flag to make it effective only once */
 
        bool v_maxmed_admin; /* true/false if max-med administrative is on/off
@@ -435,9 +429,9 @@ struct bgp {
        uint32_t maxmed_value; /* Max-med value when its active */
 
        /* BGP update delay on startup */
-       struct thread *t_update_delay;
-       struct thread *t_establish_wait;
-       struct thread *t_revalidate[AFI_MAX][SAFI_MAX];
+       struct event *t_update_delay;
+       struct event *t_establish_wait;
+       struct event *t_revalidate[AFI_MAX][SAFI_MAX];
 
        uint8_t update_delay_over;
        uint8_t main_zebra_update_hold;
@@ -597,7 +591,7 @@ struct bgp {
        struct hash *pbr_action_hash;
 
        /* timer to re-evaluate neighbor default-originate route-maps */
-       struct thread *t_rmap_def_originate_eval;
+       struct event *t_rmap_def_originate_eval;
 #define RMAP_DEFAULT_ORIGINATE_EVAL_TIMER 5
 
        /* BGP distance configuration.  */
@@ -744,6 +738,7 @@ struct bgp {
 
        /* RD for this VRF */
        struct prefix_rd vrf_prd;
+       char *vrf_prd_pretty;
 
        /* import rt list for the vrf instance */
        struct list *vrf_import_rtl;
@@ -775,7 +770,7 @@ struct bgp {
        /* BGP Conditional advertisement */
        uint32_t condition_check_period;
        uint32_t condition_filter_count;
-       struct thread *t_condition_check;
+       struct event *t_condition_check;
 
        /* BGP VPN SRv6 backend */
        bool srv6_enabled;
@@ -798,6 +793,8 @@ struct bgp {
 
        bool allow_martian;
 
+       enum asnotation_mode asnotation;
+
        QOBJ_FIELDS;
 };
 DECLARE_QOBJ_TYPE(bgp);
@@ -982,7 +979,7 @@ struct peer_af {
        /*
         * Trigger timer for bgp_announce_route().
         */
-       struct thread *t_announce_route;
+       struct event *t_announce_route;
 
        afi_t afi;
        safi_t safi;
@@ -1121,6 +1118,8 @@ struct peer {
        /* Peer's remote AS number. */
        int as_type;
        as_t as;
+       /* for vty as format */
+       char *as_pretty;
 
        /* Peer's local AS number. */
        as_t local_as;
@@ -1129,6 +1128,8 @@ struct peer {
 
        /* Peer's Change local AS number. */
        as_t change_local_as;
+       /* for vty as format */
+       char *change_local_as_pretty;
 
        /* Remote router ID. */
        struct in_addr remote_id;
@@ -1251,6 +1252,8 @@ struct peer {
 #define PEER_CAP_GRACEFUL_RESTART_N_BIT_RCV (1U << 24)
 #define PEER_CAP_ROLE_ADV                   (1U << 25) /* role advertised */
 #define PEER_CAP_ROLE_RCV                   (1U << 26) /* role received */
+#define PEER_CAP_SOFT_VERSION_ADV (1U << 27)
+#define PEER_CAP_SOFT_VERSION_RCV (1U << 28)
 
        /* Capability flags (reset in bgp_stop) */
        uint32_t af_cap[AFI_MAX][SAFI_MAX];
@@ -1284,7 +1287,7 @@ struct peer {
         * so if a flag is unset, the corresponding override flag is unset too.
         * However if a flag is set, the corresponding override flag is set.
         */
-       uint32_t flags_override;
+       uint64_t flags_override;
        /*
         * Parallel array to flags that indicates whether the default behavior
         * of *flags_override* should be inverted. If a flag is unset and the
@@ -1322,11 +1325,13 @@ struct peer {
         * inversion state of the flag differs between peer and peer-group, the
         * newly set value must equal to the inverted state of the peer-group.
         */
-       uint32_t flags_invert;
+       uint64_t flags_invert;
        /*
         * Effective array for storing the peer/peer-group flags. In case of a
         * peer-group, the peer-specific overrides (see flags_override and
         * flags_invert) must be respected.
+        * When changing the structure of flags/af_flags, do not forget to
+        * change flags_invert/flags_override too.
         */
        uint64_t flags;
 #define PEER_FLAG_PASSIVE                   (1ULL << 0) /* passive mode */
@@ -1377,6 +1382,7 @@ struct peer {
 #define PEER_FLAG_PORT (1ULL << 33)
 #define PEER_FLAG_AIGP (1ULL << 34)
 #define PEER_FLAG_GRACEFUL_SHUTDOWN (1ULL << 35)
+#define PEER_FLAG_CAPABILITY_SOFT_VERSION (1ULL << 36)
 
        /*
         *GR-Disabled mode means unset PEER_FLAG_GRACEFUL_RESTART
@@ -1436,14 +1442,14 @@ struct peer {
 #define PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE (1ULL << 19)
 #define PEER_FLAG_AS_OVERRIDE (1ULL << 20)
 #define PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE (1ULL << 21)
-#define PEER_FLAG_WEIGHT (1ULL << 24)
-#define PEER_FLAG_ALLOWAS_IN_ORIGIN (1ULL << 25)
-#define PEER_FLAG_SEND_LARGE_COMMUNITY (1ULL << 26)
-#define PEER_FLAG_MAX_PREFIX_OUT (1ULL << 27)
-#define PEER_FLAG_MAX_PREFIX_FORCE (1ULL << 28)
-#define PEER_FLAG_DISABLE_ADDPATH_RX (1ULL << 29)
-#define PEER_FLAG_SOO (1ULL << 30)
-#define PEER_FLAG_ACCEPT_OWN (1ULL << 31)
+#define PEER_FLAG_WEIGHT (1ULL << 22)
+#define PEER_FLAG_ALLOWAS_IN_ORIGIN (1ULL << 23)
+#define PEER_FLAG_SEND_LARGE_COMMUNITY (1ULL << 24)
+#define PEER_FLAG_MAX_PREFIX_OUT (1ULL << 25)
+#define PEER_FLAG_MAX_PREFIX_FORCE (1ULL << 26)
+#define PEER_FLAG_DISABLE_ADDPATH_RX (1ULL << 27)
+#define PEER_FLAG_SOO (1ULL << 28)
+#define PEER_FLAG_ACCEPT_OWN (1ULL << 63)
 
        enum bgp_addpath_strat addpath_type[AFI_MAX][SAFI_MAX];
 
@@ -1504,24 +1510,24 @@ struct peer {
        _Atomic uint32_t v_gr_restart;
 
        /* Threads. */
-       struct thread *t_read;
-       struct thread *t_write;
-       struct thread *t_start;
-       struct thread *t_connect_check_r;
-       struct thread *t_connect_check_w;
-       struct thread *t_connect;
-       struct thread *t_holdtime;
-       struct thread *t_routeadv;
-       struct thread *t_delayopen;
-       struct thread *t_pmax_restart;
-       struct thread *t_gr_restart;
-       struct thread *t_gr_stale;
-       struct thread *t_llgr_stale[AFI_MAX][SAFI_MAX];
-       struct thread *t_revalidate_all[AFI_MAX][SAFI_MAX];
-       struct thread *t_generate_updgrp_packets;
-       struct thread *t_process_packet;
-       struct thread *t_process_packet_error;
-       struct thread *t_refresh_stalepath;
+       struct event *t_read;
+       struct event *t_write;
+       struct event *t_start;
+       struct event *t_connect_check_r;
+       struct event *t_connect_check_w;
+       struct event *t_connect;
+       struct event *t_holdtime;
+       struct event *t_routeadv;
+       struct event *t_delayopen;
+       struct event *t_pmax_restart;
+       struct event *t_gr_restart;
+       struct event *t_gr_stale;
+       struct event *t_llgr_stale[AFI_MAX][SAFI_MAX];
+       struct event *t_revalidate_all[AFI_MAX][SAFI_MAX];
+       struct event *t_generate_updgrp_packets;
+       struct event *t_process_packet;
+       struct event *t_process_packet_error;
+       struct event *t_refresh_stalepath;
 
        /* Thread flags. */
        _Atomic uint32_t thread_flags;
@@ -1769,6 +1775,13 @@ struct peer {
        /* Path attributes discard */
        bool discard_attrs[BGP_ATTR_MAX];
 
+       /* Path attributes treat-as-withdraw */
+       bool withdraw_attrs[BGP_ATTR_MAX];
+
+       /* BGP Software Version Capability */
+#define BGP_MAX_SOFT_VERSION 64
+       char *soft_version;
+
        QOBJ_FIELDS;
 };
 DECLARE_QOBJ_TYPE(peer);
@@ -2135,7 +2148,7 @@ extern void bgp_recalculate_all_bestpaths(struct bgp *bgp);
 extern struct peer *peer_create(union sockunion *su, const char *conf_if,
                                struct bgp *bgp, as_t local_as, as_t remote_as,
                                int as_type, struct peer_group *group,
-                               bool config_node);
+                               bool config_node, const char *as_str);
 extern struct peer *peer_create_accept(struct bgp *);
 extern void peer_xfer_config(struct peer *dst, struct peer *src);
 extern char *peer_uptime(time_t uptime2, char *buf, size_t len, bool use_json,
@@ -2143,7 +2156,7 @@ extern char *peer_uptime(time_t uptime2, char *buf, size_t len, bool use_json,
 
 extern int bgp_config_write(struct vty *);
 
-extern void bgp_master_init(struct thread_master *master, const int buffer_size,
+extern void bgp_master_init(struct event_loop *master, const int buffer_size,
                            struct list *addresses);
 
 extern void bgp_init(unsigned short instance);
@@ -2163,7 +2176,8 @@ extern void bgp_option_norib_set_runtime(void);
 extern void bgp_option_norib_unset_runtime(void);
 
 extern int bgp_get(struct bgp **bgp, as_t *as, const char *name,
-                  enum bgp_instance_type kind, const char *as_pretty);
+                  enum bgp_instance_type kind, const char *as_pretty,
+                  enum asnotation_mode asnotation);
 extern void bgp_instance_up(struct bgp *);
 extern void bgp_instance_down(struct bgp *);
 extern int bgp_delete(struct bgp *);
@@ -2179,11 +2193,13 @@ extern void bgp_suppress_fib_pending_set(struct bgp *bgp, bool set);
 extern void bgp_cluster_id_set(struct bgp *bgp, struct in_addr *cluster_id);
 extern void bgp_cluster_id_unset(struct bgp *bgp);
 
-extern void bgp_confederation_id_set(struct bgp *bgp, as_t as);
+extern void bgp_confederation_id_set(struct bgp *bgp, as_t as,
+                                    const char *as_str);
 extern void bgp_confederation_id_unset(struct bgp *bgp);
 extern bool bgp_confederation_peers_check(struct bgp *, as_t);
 
-extern void bgp_confederation_peers_add(struct bgp *bgp, as_t as);
+extern void bgp_confederation_peers_add(struct bgp *bgp, as_t as,
+                                       const char *as_str);
 extern void bgp_confederation_peers_remove(struct bgp *bgp, as_t as);
 
 extern void bgp_timers_set(struct bgp *, uint32_t keepalive, uint32_t holdtime,
@@ -2204,10 +2220,13 @@ extern void bgp_listen_limit_unset(struct bgp *bgp);
 extern bool bgp_update_delay_active(struct bgp *);
 extern bool bgp_update_delay_configured(struct bgp *);
 extern bool bgp_afi_safi_peer_exists(struct bgp *bgp, afi_t afi, safi_t safi);
-extern void peer_as_change(struct peer *, as_t, int);
-extern int peer_remote_as(struct bgp *, union sockunion *, const char *, as_t *,
-                         int);
-extern int peer_group_remote_as(struct bgp *, const char *, as_t *, int);
+extern void peer_as_change(struct peer *peer, as_t as, int as_type,
+                          const char *as_str);
+extern int peer_remote_as(struct bgp *bgp, union sockunion *su,
+                         const char *conf_if, as_t *as, int as_type,
+                         const char *as_str);
+extern int peer_group_remote_as(struct bgp *bgp, const char *peer_str, as_t *as,
+                               int as_type, const char *as_str);
 extern int peer_delete(struct peer *peer);
 extern void peer_notify_unconfig(struct peer *peer);
 extern int peer_group_delete(struct peer_group *);
@@ -2229,7 +2248,8 @@ extern int peer_af_flag_set(struct peer *peer, afi_t afi, safi_t safi,
                            uint64_t flag);
 extern int peer_af_flag_unset(struct peer *peer, afi_t afi, safi_t safi,
                              uint64_t flag);
-extern int peer_af_flag_check(struct peer *, afi_t, safi_t, uint32_t);
+extern bool peer_af_flag_check(struct peer *peer, afi_t afi, safi_t safi,
+                              uint64_t flag);
 extern void peer_af_flag_inherit(struct peer *peer, afi_t afi, safi_t safi,
                                 uint64_t flag);
 extern void peer_change_action(struct peer *peer, afi_t afi, safi_t safi,
@@ -2286,8 +2306,8 @@ extern int peer_distribute_unset(struct peer *, afi_t, safi_t, int);
 extern int peer_allowas_in_set(struct peer *, afi_t, safi_t, int, int);
 extern int peer_allowas_in_unset(struct peer *, afi_t, safi_t);
 
-extern int peer_local_as_set(struct peer *, as_t, bool no_prepend,
-                            bool replace_as);
+extern int peer_local_as_set(struct peer *peer, as_t as, bool no_prepend,
+                            bool replace_as, const char *as_str);
 extern int peer_local_as_unset(struct peer *);
 
 extern int peer_prefix_list_set(struct peer *, afi_t, safi_t, int,
@@ -2344,8 +2364,9 @@ extern int peer_ttl_security_hops_unset(struct peer *);
 extern void peer_tx_shutdown_message_set(struct peer *, const char *msg);
 extern void peer_tx_shutdown_message_unset(struct peer *);
 
-extern void bgp_route_map_update_timer(struct thread *thread);
+extern void bgp_route_map_update_timer(struct event *thread);
 extern const char *bgp_get_name_by_role(uint8_t role);
+extern enum asnotation_mode bgp_get_asnotation(struct bgp *bgp);
 
 extern void bgp_route_map_terminate(void);
 
@@ -2637,6 +2658,8 @@ extern void peer_on_policy_change(struct peer *peer, afi_t afi, safi_t safi,
                                  int outbound);
 extern bool bgp_path_attribute_discard(struct peer *peer, char *buf,
                                       size_t size);
+extern bool bgp_path_attribute_treat_as_withdraw(struct peer *peer, char *buf,
+                                                size_t size);
 #ifdef _FRR_ATTRIBUTE_PRINTFRR
 /* clang-format off */
 #pragma FRR printfrr_ext "%pBP" (struct peer *)