]>
Commit | Line | Data |
---|---|---|
d62a17ae | 1 | /* BGP-4 Finite State Machine |
896014f4 DL |
2 | * From RFC1771 [A Border Gateway Protocol 4 (BGP-4)] |
3 | * Copyright (C) 1998 Kunihiro Ishiguro | |
4 | * | |
5 | * This file is part of GNU Zebra. | |
6 | * | |
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 | |
10 | * later version. | |
11 | * | |
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. | |
16 | * | |
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 | |
20 | */ | |
718e3744 | 21 | |
00d252cb | 22 | #ifndef _QUAGGA_BGP_FSM_H |
23 | #define _QUAGGA_BGP_FSM_H | |
24 | ||
718e3744 | 25 | /* Macro for BGP read, write and timer thread. */ |
d62a17ae | 26 | #define BGP_TIMER_ON(T, F, V) \ |
27 | do { \ | |
28 | if ((peer->status != Deleted)) \ | |
29 | thread_add_timer(bm->master, (F), peer, (V), &(T)); \ | |
30 | } while (0) | |
31 | ||
32 | #define BGP_TIMER_OFF(T) \ | |
33 | do { \ | |
a9318a32 | 34 | THREAD_OFF((T)); \ |
d62a17ae | 35 | } while (0) |
36 | ||
37 | #define BGP_EVENT_ADD(P, E) \ | |
38 | do { \ | |
39 | if ((P)->status != Deleted) \ | |
40 | thread_add_event(bm->master, bgp_event, (P), (E), \ | |
41 | NULL); \ | |
42 | } while (0) | |
43 | ||
44 | #define BGP_EVENT_FLUSH(P) \ | |
45 | do { \ | |
46 | assert(peer); \ | |
a9318a32 | 47 | thread_cancel_event_ready(bm->master, (P)); \ |
d62a17ae | 48 | } while (0) |
718e3744 | 49 | |
a77e2f4b S |
50 | #define BGP_UPDATE_GROUP_TIMER_ON(T, F) \ |
51 | do { \ | |
52 | if (BGP_SUPPRESS_FIB_ENABLED(peer->bgp) && \ | |
53 | PEER_ROUTE_ADV_DELAY(peer)) \ | |
54 | thread_add_timer_msec(bm->master, (F), peer, \ | |
55 | (BGP_DEFAULT_UPDATE_ADVERTISEMENT_TIME * 1000),\ | |
a9318a32 | 56 | (T)); \ |
a77e2f4b S |
57 | else \ |
58 | thread_add_timer_msec(bm->master, (F), peer, \ | |
a9318a32 | 59 | 0, (T)); \ |
a77e2f4b S |
60 | } while (0) \ |
61 | ||
cb1faec9 DS |
62 | #define BGP_MSEC_JITTER 10 |
63 | ||
d8151687 QY |
64 | /* Status codes for bgp_event_update() */ |
65 | #define FSM_PEER_NOOP 0 | |
66 | #define FSM_PEER_STOPPED 1 | |
67 | #define FSM_PEER_TRANSFERRED 2 | |
68 | #define FSM_PEER_TRANSITIONED 3 | |
69 | ||
b0965c44 | 70 | #define BGP_PEER_GR_HELPER_ENABLE(peer) \ |
71 | do { \ | |
72 | UNSET_FLAG( \ | |
73 | peer->peer_gr_new_status_flag, \ | |
74 | PEER_GRACEFUL_RESTART_NEW_STATE_RESTART); \ | |
75 | SET_FLAG( \ | |
76 | peer->peer_gr_new_status_flag, \ | |
77 | PEER_GRACEFUL_RESTART_NEW_STATE_HELPER);\ | |
78 | } while (0) | |
79 | ||
b0965c44 | 80 | #define BGP_PEER_GR_ENABLE(peer)\ |
81 | do { \ | |
82 | SET_FLAG( \ | |
83 | peer->peer_gr_new_status_flag, \ | |
84 | PEER_GRACEFUL_RESTART_NEW_STATE_RESTART); \ | |
85 | UNSET_FLAG( \ | |
86 | peer->peer_gr_new_status_flag, \ | |
87 | PEER_GRACEFUL_RESTART_NEW_STATE_HELPER);\ | |
88 | } while (0) | |
89 | ||
b0965c44 | 90 | #define BGP_PEER_GR_DISABLE(peer)\ |
91 | do { \ | |
92 | UNSET_FLAG( \ | |
93 | peer->peer_gr_new_status_flag, \ | |
94 | PEER_GRACEFUL_RESTART_NEW_STATE_RESTART);\ | |
95 | UNSET_FLAG(\ | |
96 | peer->peer_gr_new_status_flag, \ | |
97 | PEER_GRACEFUL_RESTART_NEW_STATE_HELPER);\ | |
98 | } while (0) | |
99 | ||
b0965c44 | 100 | #define BGP_PEER_GR_GLOBAL_INHERIT_SET(peer) \ |
101 | SET_FLAG(peer->peer_gr_new_status_flag, \ | |
102 | PEER_GRACEFUL_RESTART_NEW_STATE_INHERIT) | |
103 | ||
b0965c44 | 104 | #define BGP_PEER_GR_GLOBAL_INHERIT_UNSET(peer) \ |
105 | UNSET_FLAG(peer->peer_gr_new_status_flag, \ | |
106 | PEER_GRACEFUL_RESTART_NEW_STATE_INHERIT) | |
107 | ||
36235319 QY |
108 | #define BGP_PEER_GRACEFUL_RESTART_CAPABLE(peer) \ |
109 | (CHECK_FLAG(peer->cap, PEER_CAP_RESTART_ADV) \ | |
110 | && CHECK_FLAG(peer->cap, PEER_CAP_RESTART_RCV)) | |
f009ff26 | 111 | |
36235319 QY |
112 | #define BGP_PEER_RESTARTING_MODE(peer) \ |
113 | (CHECK_FLAG(peer->flags, PEER_FLAG_GRACEFUL_RESTART) \ | |
114 | && CHECK_FLAG(peer->cap, PEER_CAP_RESTART_BIT_ADV) \ | |
115 | && !CHECK_FLAG(peer->cap, PEER_CAP_RESTART_BIT_RCV)) | |
f009ff26 | 116 | |
36235319 QY |
117 | #define BGP_PEER_HELPER_MODE(peer) \ |
118 | (CHECK_FLAG(peer->flags, PEER_FLAG_GRACEFUL_RESTART_HELPER) \ | |
119 | && CHECK_FLAG(peer->cap, PEER_CAP_RESTART_BIT_RCV) \ | |
120 | && !CHECK_FLAG(peer->cap, PEER_CAP_RESTART_BIT_ADV)) | |
f009ff26 | 121 | |
718e3744 | 122 | /* Prototypes. */ |
f8dcd38d QY |
123 | |
124 | /* | |
125 | * Update FSM for peer based on whether we have valid nexthops or not. | |
126 | */ | |
127 | extern void bgp_fsm_nht_update(struct peer *peer, bool has_valid_nexthops); | |
d62a17ae | 128 | extern int bgp_event(struct thread *); |
d1060698 | 129 | extern int bgp_event_update(struct peer *, enum bgp_fsm_events event); |
d62a17ae | 130 | extern int bgp_stop(struct peer *peer); |
131 | extern void bgp_timer_set(struct peer *); | |
132 | extern int bgp_routeadv_timer(struct thread *); | |
133 | extern void bgp_fsm_change_status(struct peer *peer, int status); | |
2b64873d | 134 | extern const char *const peer_down_str[]; |
d62a17ae | 135 | extern void bgp_update_delay_end(struct bgp *); |
136 | extern void bgp_maxmed_update(struct bgp *); | |
3dc339cd DA |
137 | extern bool bgp_maxmed_onstartup_configured(struct bgp *); |
138 | extern bool bgp_maxmed_onstartup_active(struct bgp *); | |
3893aeee | 139 | extern int bgp_fsm_error_subcode(int status); |
00d252cb | 140 | |
cb1faec9 DS |
141 | /** |
142 | * Start the route advertisement timer (that honors MRAI) for all the | |
143 | * peers. Typically called at the end of initial convergence, coming | |
144 | * out of read-only mode. | |
145 | */ | |
d62a17ae | 146 | extern void bgp_start_routeadv(struct bgp *); |
cb1faec9 DS |
147 | |
148 | /** | |
149 | * See if the route advertisement timer needs to be adjusted for a | |
150 | * peer. For example, if the last update was written to the peer a | |
151 | * long while back, we don't need to wait for the periodic advertisement | |
152 | * timer to expire to send the new set of prefixes. It should fire | |
153 | * instantly and updates should go out sooner. | |
154 | */ | |
d62a17ae | 155 | extern void bgp_adjust_routeadv(struct peer *); |
cb1faec9 | 156 | |
3012671f | 157 | #include "hook.h" |
8451921b DL |
158 | DECLARE_HOOK(peer_backward_transition, (struct peer *peer), (peer)); |
159 | DECLARE_HOOK(peer_established, (struct peer *peer), (peer)); | |
b0965c44 | 160 | |
2ba1fe69 | 161 | int bgp_gr_update_all(struct bgp *bgp, int global_gr_cmd); |
36235319 | 162 | int bgp_neighbor_graceful_restart(struct peer *peer, int peer_gr_cmd); |
b0965c44 | 163 | unsigned int bgp_peer_gr_action(struct peer *peer, |
164 | int old_peer_state, int new_peer_state); | |
165 | void bgp_peer_move_to_gr_mode(struct peer *peer, int new_state); | |
166 | unsigned int bgp_peer_gr_helper_enable(struct peer *peer); | |
167 | unsigned int bgp_peer_gr_enable(struct peer *peer); | |
168 | unsigned int bgp_peer_gr_global_inherit(struct peer *peer); | |
169 | unsigned int bgp_peer_gr_disable(struct peer *peer); | |
170 | enum peer_mode bgp_peer_gr_mode_get(struct peer *peer); | |
171 | enum global_mode bgp_global_gr_mode_get(struct bgp *bgp); | |
172 | enum peer_mode bgp_get_peer_gr_mode_from_flags(struct peer *peer); | |
173 | unsigned int bgp_peer_gr_global_inherit_unset(struct peer *peer); | |
174 | int bgp_gr_lookup_n_update_all_peer(struct bgp *bgp, | |
175 | enum global_mode global_new_state, | |
176 | enum global_mode global_old_state); | |
b0965c44 | 177 | void bgp_peer_gr_flags_update(struct peer *peer); |
2ba1fe69 | 178 | const char *print_peer_gr_mode(enum peer_mode pr_mode); |
179 | const char *print_peer_gr_cmd(enum peer_gr_command pr_gr_cmd); | |
180 | const char *print_global_gr_mode(enum global_mode gl_mode); | |
181 | const char *print_global_gr_cmd(enum global_gr_command gl_gr_cmd); | |
996319e6 | 182 | int bgp_peer_reg_with_nht(struct peer *peer); |
00d252cb | 183 | #endif /* _QUAGGA_BGP_FSM_H */ |