]>
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 { \ | |
34 | if (T) \ | |
35 | THREAD_TIMER_OFF(T); \ | |
36 | } while (0) | |
37 | ||
38 | #define BGP_EVENT_ADD(P, E) \ | |
39 | do { \ | |
40 | if ((P)->status != Deleted) \ | |
41 | thread_add_event(bm->master, bgp_event, (P), (E), \ | |
42 | NULL); \ | |
43 | } while (0) | |
44 | ||
45 | #define BGP_EVENT_FLUSH(P) \ | |
46 | do { \ | |
47 | assert(peer); \ | |
48 | thread_cancel_event(bm->master, (P)); \ | |
49 | } while (0) | |
718e3744 | 50 | |
cb1faec9 DS |
51 | #define BGP_MSEC_JITTER 10 |
52 | ||
d8151687 QY |
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 | |
58 | ||
b0965c44 | 59 | #define BGP_PEER_GR_HELPER_ENABLE(peer) \ |
60 | do { \ | |
61 | UNSET_FLAG( \ | |
62 | peer->peer_gr_new_status_flag, \ | |
63 | PEER_GRACEFUL_RESTART_NEW_STATE_RESTART); \ | |
64 | SET_FLAG( \ | |
65 | peer->peer_gr_new_status_flag, \ | |
66 | PEER_GRACEFUL_RESTART_NEW_STATE_HELPER);\ | |
67 | } while (0) | |
68 | ||
b0965c44 | 69 | #define BGP_PEER_GR_ENABLE(peer)\ |
70 | do { \ | |
71 | SET_FLAG( \ | |
72 | peer->peer_gr_new_status_flag, \ | |
73 | PEER_GRACEFUL_RESTART_NEW_STATE_RESTART); \ | |
74 | UNSET_FLAG( \ | |
75 | peer->peer_gr_new_status_flag, \ | |
76 | PEER_GRACEFUL_RESTART_NEW_STATE_HELPER);\ | |
77 | } while (0) | |
78 | ||
b0965c44 | 79 | #define BGP_PEER_GR_DISABLE(peer)\ |
80 | do { \ | |
81 | UNSET_FLAG( \ | |
82 | peer->peer_gr_new_status_flag, \ | |
83 | PEER_GRACEFUL_RESTART_NEW_STATE_RESTART);\ | |
84 | UNSET_FLAG(\ | |
85 | peer->peer_gr_new_status_flag, \ | |
86 | PEER_GRACEFUL_RESTART_NEW_STATE_HELPER);\ | |
87 | } while (0) | |
88 | ||
b0965c44 | 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) | |
92 | ||
b0965c44 | 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) | |
96 | ||
36235319 QY |
97 | #define BGP_PEER_GRACEFUL_RESTART_CAPABLE(peer) \ |
98 | (CHECK_FLAG(peer->cap, PEER_CAP_RESTART_ADV) \ | |
99 | && CHECK_FLAG(peer->cap, PEER_CAP_RESTART_RCV)) | |
f009ff26 | 100 | |
36235319 QY |
101 | #define BGP_PEER_RESTARTING_MODE(peer) \ |
102 | (CHECK_FLAG(peer->flags, PEER_FLAG_GRACEFUL_RESTART) \ | |
103 | && CHECK_FLAG(peer->cap, PEER_CAP_RESTART_BIT_ADV) \ | |
104 | && !CHECK_FLAG(peer->cap, PEER_CAP_RESTART_BIT_RCV)) | |
f009ff26 | 105 | |
36235319 QY |
106 | #define BGP_PEER_HELPER_MODE(peer) \ |
107 | (CHECK_FLAG(peer->flags, PEER_FLAG_GRACEFUL_RESTART_HELPER) \ | |
108 | && CHECK_FLAG(peer->cap, PEER_CAP_RESTART_BIT_RCV) \ | |
109 | && !CHECK_FLAG(peer->cap, PEER_CAP_RESTART_BIT_ADV)) | |
f009ff26 | 110 | |
718e3744 | 111 | /* Prototypes. */ |
fc04a677 | 112 | extern void bgp_fsm_event_update(struct peer *peer, int valid); |
d62a17ae | 113 | extern int bgp_event(struct thread *); |
d1060698 | 114 | extern int bgp_event_update(struct peer *, enum bgp_fsm_events event); |
d62a17ae | 115 | extern int bgp_stop(struct peer *peer); |
116 | extern void bgp_timer_set(struct peer *); | |
117 | extern int bgp_routeadv_timer(struct thread *); | |
118 | extern void bgp_fsm_change_status(struct peer *peer, int status); | |
2b64873d | 119 | extern const char *const peer_down_str[]; |
d62a17ae | 120 | extern void bgp_update_delay_end(struct bgp *); |
121 | extern void bgp_maxmed_update(struct bgp *); | |
3dc339cd DA |
122 | extern bool bgp_maxmed_onstartup_configured(struct bgp *); |
123 | extern bool bgp_maxmed_onstartup_active(struct bgp *); | |
3893aeee | 124 | extern int bgp_fsm_error_subcode(int status); |
00d252cb | 125 | |
cb1faec9 DS |
126 | /** |
127 | * Start the route advertisement timer (that honors MRAI) for all the | |
128 | * peers. Typically called at the end of initial convergence, coming | |
129 | * out of read-only mode. | |
130 | */ | |
d62a17ae | 131 | extern void bgp_start_routeadv(struct bgp *); |
cb1faec9 DS |
132 | |
133 | /** | |
134 | * See if the route advertisement timer needs to be adjusted for a | |
135 | * peer. For example, if the last update was written to the peer a | |
136 | * long while back, we don't need to wait for the periodic advertisement | |
137 | * timer to expire to send the new set of prefixes. It should fire | |
138 | * instantly and updates should go out sooner. | |
139 | */ | |
d62a17ae | 140 | extern void bgp_adjust_routeadv(struct peer *); |
cb1faec9 | 141 | |
3012671f | 142 | #include "hook.h" |
b0965c44 | 143 | DECLARE_HOOK(peer_backward_transition, (struct peer *peer), (peer)) |
144 | DECLARE_HOOK(peer_established, (struct peer *peer), (peer)) | |
145 | ||
2ba1fe69 | 146 | int bgp_gr_update_all(struct bgp *bgp, int global_gr_cmd); |
36235319 | 147 | int bgp_neighbor_graceful_restart(struct peer *peer, int peer_gr_cmd); |
b0965c44 | 148 | unsigned int bgp_peer_gr_action(struct peer *peer, |
149 | int old_peer_state, int new_peer_state); | |
150 | void bgp_peer_move_to_gr_mode(struct peer *peer, int new_state); | |
151 | unsigned int bgp_peer_gr_helper_enable(struct peer *peer); | |
152 | unsigned int bgp_peer_gr_enable(struct peer *peer); | |
153 | unsigned int bgp_peer_gr_global_inherit(struct peer *peer); | |
154 | unsigned int bgp_peer_gr_disable(struct peer *peer); | |
155 | enum peer_mode bgp_peer_gr_mode_get(struct peer *peer); | |
156 | enum global_mode bgp_global_gr_mode_get(struct bgp *bgp); | |
157 | enum peer_mode bgp_get_peer_gr_mode_from_flags(struct peer *peer); | |
158 | unsigned int bgp_peer_gr_global_inherit_unset(struct peer *peer); | |
159 | int bgp_gr_lookup_n_update_all_peer(struct bgp *bgp, | |
160 | enum global_mode global_new_state, | |
161 | enum global_mode global_old_state); | |
b0965c44 | 162 | void bgp_peer_gr_flags_update(struct peer *peer); |
2ba1fe69 | 163 | const char *print_peer_gr_mode(enum peer_mode pr_mode); |
164 | const char *print_peer_gr_cmd(enum peer_gr_command pr_gr_cmd); | |
165 | const char *print_global_gr_mode(enum global_mode gl_mode); | |
166 | const char *print_global_gr_cmd(enum global_gr_command gl_gr_cmd); | |
00d252cb | 167 | #endif /* _QUAGGA_BGP_FSM_H */ |