]> git.proxmox.com Git - mirror_frr.git/blob - bgpd/bgp_vty.h
*: auto-convert to SPDX License IDs
[mirror_frr.git] / bgpd / bgp_vty.h
1 // SPDX-License-Identifier: GPL-2.0-or-later
2 /* BGP VTY interface.
3 * Copyright (C) 1996, 97, 98, 99, 2000 Kunihiro Ishiguro
4 */
5
6 #ifndef _QUAGGA_BGP_VTY_H
7 #define _QUAGGA_BGP_VTY_H
8
9 #include "bgpd/bgpd.h"
10 #include "stream.h"
11 struct bgp;
12
13 #define BGP_INSTANCE_HELP_STR "BGP view\nBGP VRF\nView/VRF name\n"
14 #define BGP_INSTANCE_ALL_HELP_STR "BGP view\nBGP VRF\nAll Views/VRFs\n"
15
16 #define BGP_AF_STR "Address Family\n"
17 #define BGP_AF_MODIFIER_STR "Address Family modifier\n"
18 #define BGP_AFI_CMD_STR "<ipv4|ipv6>"
19 #define BGP_AFI_HELP_STR BGP_AF_STR BGP_AF_STR
20 #define BGP_SAFI_CMD_STR "<unicast|multicast|vpn>"
21 #define BGP_SAFI_HELP_STR \
22 BGP_AF_MODIFIER_STR BGP_AF_MODIFIER_STR BGP_AF_MODIFIER_STR
23 #define BGP_AFI_SAFI_CMD_STR BGP_AFI_CMD_STR" "BGP_SAFI_CMD_STR
24 #define BGP_AFI_SAFI_HELP_STR BGP_AFI_HELP_STR BGP_SAFI_HELP_STR
25
26 #define BGP_SAFI_WITH_LABEL_CMD_STR "<unicast|multicast|vpn|labeled-unicast|flowspec>"
27 #define BGP_SAFI_WITH_LABEL_HELP_STR \
28 BGP_AF_MODIFIER_STR BGP_AF_MODIFIER_STR BGP_AF_MODIFIER_STR \
29 BGP_AF_MODIFIER_STR BGP_AF_MODIFIER_STR
30
31 #define SHOW_GR_HEADER \
32 "Codes: GR - Graceful Restart," \
33 " * - Inheriting Global GR Config,\n" \
34 " Restart - GR Mode-Restarting," \
35 " Helper - GR Mode-Helper,\n" \
36 " Disable - GR Mode-Disable.\n\n"
37
38 #define BGP_SHOW_SUMMARY_HEADER_ALL \
39 "V AS MsgRcvd MsgSent TblVer InQ OutQ Up/Down State/PfxRcd PfxSnt Desc\n"
40 #define BGP_SHOW_SUMMARY_HEADER_ALL_WIDE \
41 "V AS LocalAS MsgRcvd MsgSent TblVer InQ OutQ Up/Down State/PfxRcd PfxSnt Desc\n"
42 #define BGP_SHOW_SUMMARY_HEADER_FAILED "EstdCnt DropCnt ResetTime Reason\n"
43
44 #define BGP_SHOW_PEER_GR_CAPABILITY(vty, p, json) \
45 do { \
46 bgp_show_neighbor_graceful_restart_local_mode(vty, p, json); \
47 bgp_show_neighbor_graceful_restart_remote_mode(vty, p, json); \
48 bgp_show_neighnor_graceful_restart_flags(vty, p, json); \
49 bgp_show_neighbor_graceful_restart_time(vty, p, json); \
50 bgp_show_neighbor_graceful_restart_capability_per_afi_safi( \
51 vty, p, json); \
52 } while (0)
53
54 #define VTY_BGP_GR_DEFINE_LOOP_VARIABLE \
55 struct peer *peer_loop = NULL; \
56 struct listnode *node = NULL; \
57 struct listnode *nnode = NULL; \
58 bool gr_router_detected = false
59
60 #define VTY_BGP_GR_ROUTER_DETECT(_bgp, _peer, _peer_list) \
61 do { \
62 if (_peer->bgp->t_startup) \
63 bgp_peer_gr_flags_update(_peer); \
64 for (ALL_LIST_ELEMENTS(_peer_list, node, nnode, peer_loop)) { \
65 if (CHECK_FLAG(peer_loop->flags, \
66 PEER_FLAG_GRACEFUL_RESTART)) \
67 gr_router_detected = true; \
68 } \
69 } while (0)
70
71
72 #define VTY_SEND_BGP_GR_CAPABILITY_TO_ZEBRA(_bgp, _ret) \
73 do { \
74 if (gr_router_detected \
75 && _bgp->present_zebra_gr_state == ZEBRA_GR_DISABLE) { \
76 if (bgp_zebra_send_capabilities(_bgp, false)) \
77 _ret = BGP_ERR_INVALID_VALUE; \
78 } else if (!gr_router_detected \
79 && _bgp->present_zebra_gr_state \
80 == ZEBRA_GR_ENABLE) { \
81 if (bgp_zebra_send_capabilities(_bgp, true)) \
82 _ret = BGP_ERR_INVALID_VALUE; \
83 } \
84 } while (0)
85
86 #define VTY_BGP_GR_ROUTER_DETECT_AND_SEND_CAPABILITY_TO_ZEBRA( \
87 _bgp, _peer_list, _ret) \
88 do { \
89 struct peer *peer_loop; \
90 bool gr_router_detected = false; \
91 struct listnode *node = {0}; \
92 struct listnode *nnode = {0}; \
93 for (ALL_LIST_ELEMENTS(_peer_list, node, nnode, peer_loop)) { \
94 if (peer_loop->bgp->t_startup) \
95 bgp_peer_gr_flags_update(peer_loop); \
96 if (CHECK_FLAG(peer_loop->flags, \
97 PEER_FLAG_GRACEFUL_RESTART)) \
98 gr_router_detected = true; \
99 } \
100 if (gr_router_detected \
101 && _bgp->present_zebra_gr_state == ZEBRA_GR_DISABLE) { \
102 if (bgp_zebra_send_capabilities(_bgp, false)) \
103 _ret = BGP_ERR_INVALID_VALUE; \
104 } else if (!gr_router_detected \
105 && _bgp->present_zebra_gr_state \
106 == ZEBRA_GR_ENABLE) { \
107 if (bgp_zebra_send_capabilities(_bgp, true)) \
108 _ret = BGP_ERR_INVALID_VALUE; \
109 } \
110 } while (0)
111
112
113 #define PRINT_EOR(_eor_flag) \
114 do { \
115 if (eor_flag) \
116 vty_out(vty, "Yes\n"); \
117 else \
118 vty_out(vty, "No\n"); \
119 } while (0)
120
121 #define PRINT_EOR_JSON(_eor_flag) \
122 do { \
123 if (eor_flag) \
124 json_object_boolean_true_add( \
125 json_endofrib_status, \
126 "endOfRibSentAfterUpdate"); \
127 else \
128 json_object_boolean_false_add( \
129 json_endofrib_status, \
130 "endOfRibSentAfterUpdate"); \
131 } while (0)
132
133 extern void bgp_clear_soft_in(struct bgp *bgp, afi_t afi, safi_t safi);
134 extern void bgp_vty_init(void);
135 extern void community_alias_vty(void);
136 extern const char *get_afi_safi_str(afi_t afi, safi_t safi, bool for_json);
137 extern int bgp_get_vty(struct bgp **bgp, as_t *as, const char *name,
138 enum bgp_instance_type inst_type);
139 extern void bgp_config_write_update_delay(struct vty *vty, struct bgp *bgp);
140 extern void bgp_config_write_wpkt_quanta(struct vty *vty, struct bgp *bgp);
141 extern void bgp_config_write_rpkt_quanta(struct vty *vty, struct bgp *bgp);
142 extern void bgp_config_write_listen(struct vty *vty, struct bgp *bgp);
143 extern void bgp_config_write_coalesce_time(struct vty *vty, struct bgp *bgp);
144 extern int bgp_vty_return(struct vty *vty, int ret);
145 extern bool bgp_config_inprocess(void);
146 extern struct peer *peer_and_group_lookup_vty(struct vty *vty,
147 const char *peer_str);
148
149 extern afi_t bgp_vty_afi_from_str(const char *afi_str);
150
151 extern safi_t bgp_vty_safi_from_str(const char *safi_str);
152
153 extern int argv_find_and_parse_afi(struct cmd_token **argv, int argc,
154 int *index, afi_t *afi);
155
156 extern int argv_find_and_parse_safi(struct cmd_token **argv, int argc,
157 int *index, safi_t *safi);
158
159 extern int bgp_vty_find_and_parse_afi_safi_bgp(struct vty *vty,
160 struct cmd_token **argv,
161 int argc, int *idx, afi_t *afi,
162 safi_t *safi, struct bgp **bgp,
163 bool use_json);
164 int bgp_vty_find_and_parse_bgp(struct vty *vty, struct cmd_token **argv,
165 int argc, struct bgp **bgp, bool use_json);
166 extern int bgp_show_summary_vty(struct vty *vty, const char *name, afi_t afi,
167 safi_t safi, const char *neighbor, int as_type,
168 as_t as, uint16_t show_flags);
169
170 #endif /* _QUAGGA_BGP_VTY_H */