1 /* BGP-4 Finite State Machine
2 * From RFC1771 [A Border Gateway Protocol 4 (BGP-4)]
3 * Copyright (C) 1998 Kunihiro Ishiguro
5 * This file is part of GNU Zebra.
7 * GNU Zebra is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU General Public License as published by the
9 * Free Software Foundation; either version 2, or (at your option) any
12 * GNU Zebra is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License for more details.
17 * You should have received a copy of the GNU General Public License along
18 * with this program; see the file COPYING; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
22 #ifndef _QUAGGA_BGP_FSM_H
23 #define _QUAGGA_BGP_FSM_H
25 /* Macro for BGP read, write and timer thread. */
26 #define BGP_TIMER_ON(T, F, V) \
28 if ((peer->status != Deleted)) \
29 thread_add_timer(bm->master, (F), peer, (V), &(T)); \
32 #define BGP_TIMER_OFF(T) \
35 THREAD_TIMER_OFF(T); \
38 #define BGP_EVENT_ADD(P, E) \
40 if ((P)->status != Deleted) \
41 thread_add_event(bm->master, bgp_event, (P), (E), \
45 #define BGP_EVENT_FLUSH(P) \
48 thread_cancel_event(bm->master, (P)); \
51 #define BGP_MSEC_JITTER 10
53 /* Status codes for bgp_event_update() */
54 #define FSM_PEER_NOOP 0
55 #define FSM_PEER_STOPPED 1
56 #define FSM_PEER_TRANSFERRED 2
57 #define FSM_PEER_TRANSITIONED 3
59 #define BGP_PEER_GR_HELPER_ENABLE(peer) \
62 peer->peer_gr_new_status_flag, \
63 PEER_GRACEFUL_RESTART_NEW_STATE_RESTART); \
65 peer->peer_gr_new_status_flag, \
66 PEER_GRACEFUL_RESTART_NEW_STATE_HELPER);\
69 #define BGP_PEER_GR_ENABLE(peer)\
72 peer->peer_gr_new_status_flag, \
73 PEER_GRACEFUL_RESTART_NEW_STATE_RESTART); \
75 peer->peer_gr_new_status_flag, \
76 PEER_GRACEFUL_RESTART_NEW_STATE_HELPER);\
79 #define BGP_PEER_GR_DISABLE(peer)\
82 peer->peer_gr_new_status_flag, \
83 PEER_GRACEFUL_RESTART_NEW_STATE_RESTART);\
85 peer->peer_gr_new_status_flag, \
86 PEER_GRACEFUL_RESTART_NEW_STATE_HELPER);\
89 #define BGP_PEER_GR_GLOBAL_INHERIT_SET(peer) \
90 SET_FLAG(peer->peer_gr_new_status_flag, \
91 PEER_GRACEFUL_RESTART_NEW_STATE_INHERIT)
93 #define BGP_PEER_GR_GLOBAL_INHERIT_UNSET(peer) \
94 UNSET_FLAG(peer->peer_gr_new_status_flag, \
95 PEER_GRACEFUL_RESTART_NEW_STATE_INHERIT)
98 extern void bgp_fsm_event_update(struct peer
*peer
, int valid
);
99 extern int bgp_event(struct thread
*);
100 extern int bgp_event_update(struct peer
*, int event
);
101 extern int bgp_stop(struct peer
*peer
);
102 extern void bgp_timer_set(struct peer
*);
103 extern int bgp_routeadv_timer(struct thread
*);
104 extern void bgp_fsm_change_status(struct peer
*peer
, int status
);
105 extern const char *const peer_down_str
[];
106 extern void bgp_update_delay_end(struct bgp
*);
107 extern void bgp_maxmed_update(struct bgp
*);
108 extern int bgp_maxmed_onstartup_configured(struct bgp
*);
109 extern int bgp_maxmed_onstartup_active(struct bgp
*);
112 * Start the route advertisement timer (that honors MRAI) for all the
113 * peers. Typically called at the end of initial convergence, coming
114 * out of read-only mode.
116 extern void bgp_start_routeadv(struct bgp
*);
119 * See if the route advertisement timer needs to be adjusted for a
120 * peer. For example, if the last update was written to the peer a
121 * long while back, we don't need to wait for the periodic advertisement
122 * timer to expire to send the new set of prefixes. It should fire
123 * instantly and updates should go out sooner.
125 extern void bgp_adjust_routeadv(struct peer
*);
128 DECLARE_HOOK(peer_backward_transition
, (struct peer
*peer
), (peer
))
129 DECLARE_HOOK(peer_established
, (struct peer
*peer
), (peer
))
131 int bgp_gr_update_all(struct bgp
*bgp
, int global_GR_Cmd
);
132 int bgp_neighbor_graceful_restart(struct peer
*peer
,
134 unsigned int bgp_peer_gr_action(struct peer
*peer
,
135 int old_peer_state
, int new_peer_state
);
136 void bgp_peer_move_to_gr_mode(struct peer
*peer
, int new_state
);
137 unsigned int bgp_peer_gr_helper_enable(struct peer
*peer
);
138 unsigned int bgp_peer_gr_enable(struct peer
*peer
);
139 unsigned int bgp_peer_gr_global_inherit(struct peer
*peer
);
140 unsigned int bgp_peer_gr_disable(struct peer
*peer
);
141 enum peer_mode
bgp_peer_gr_mode_get(struct peer
*peer
);
142 enum global_mode
bgp_global_gr_mode_get(struct bgp
*bgp
);
143 enum peer_mode
bgp_get_peer_gr_mode_from_flags(struct peer
*peer
);
144 unsigned int bgp_peer_gr_global_inherit_unset(struct peer
*peer
);
145 int bgp_gr_lookup_n_update_all_peer(struct bgp
*bgp
,
146 enum global_mode global_new_state
,
147 enum global_mode global_old_state
);
148 void bgp_peer_gr_flags_update(struct peer
*peer
);
149 #endif /* _QUAGGA_BGP_FSM_H */