]> git.proxmox.com Git - mirror_frr.git/blob - bgpd/bgp_vty.h
bgpd: Refactor subgroup_announce_table() to reuse an existing helpers
[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 BGP_SELF_ORIG_CMD_STR "self-originate"
32 #define BGP_SELF_ORIG_HELP_STR "Display only self-originated routes\n"
33
34 #define SHOW_GR_HEADER \
35 "Codes: GR - Graceful Restart," \
36 " * - Inheriting Global GR Config,\n" \
37 " Restart - GR Mode-Restarting," \
38 " Helper - GR Mode-Helper,\n" \
39 " Disable - GR Mode-Disable.\n\n"
40
41 #define BGP_SHOW_SUMMARY_HEADER_ALL \
42 "V AS MsgRcvd MsgSent TblVer InQ OutQ Up/Down State/PfxRcd PfxSnt Desc\n"
43 #define BGP_SHOW_SUMMARY_HEADER_ALL_WIDE \
44 "V AS LocalAS MsgRcvd MsgSent TblVer InQ OutQ Up/Down State/PfxRcd PfxSnt Desc\n"
45 #define BGP_SHOW_SUMMARY_HEADER_FAILED "EstdCnt DropCnt ResetTime Reason\n"
46
47 #define BGP_SHOW_PEER_GR_CAPABILITY(vty, p, json) \
48 do { \
49 bgp_show_neighbor_graceful_restart_local_mode(vty, p, json); \
50 bgp_show_neighbor_graceful_restart_remote_mode(vty, p, json); \
51 bgp_show_neighnor_graceful_restart_flags(vty, p, json); \
52 bgp_show_neighbor_graceful_restart_time(vty, p, json); \
53 bgp_show_neighbor_graceful_restart_capability_per_afi_safi( \
54 vty, p, json); \
55 } while (0)
56
57 #define VTY_BGP_GR_DEFINE_LOOP_VARIABLE \
58 struct peer *peer_loop = NULL; \
59 struct listnode *node = NULL; \
60 struct listnode *nnode = NULL; \
61 bool gr_router_detected = false
62
63 #define VTY_BGP_GR_ROUTER_DETECT(_bgp, _peer, _peer_list) \
64 do { \
65 if (_peer->bgp->t_startup) \
66 bgp_peer_gr_flags_update(_peer); \
67 for (ALL_LIST_ELEMENTS(_peer_list, node, nnode, peer_loop)) { \
68 if (CHECK_FLAG(peer_loop->flags, \
69 PEER_FLAG_GRACEFUL_RESTART)) \
70 gr_router_detected = true; \
71 } \
72 } while (0)
73
74
75 #define VTY_SEND_BGP_GR_CAPABILITY_TO_ZEBRA(_bgp, _ret) \
76 do { \
77 if (gr_router_detected \
78 && _bgp->present_zebra_gr_state == ZEBRA_GR_DISABLE) { \
79 if (bgp_zebra_send_capabilities(_bgp, false)) \
80 _ret = BGP_ERR_INVALID_VALUE; \
81 } else if (!gr_router_detected \
82 && _bgp->present_zebra_gr_state \
83 == ZEBRA_GR_ENABLE) { \
84 if (bgp_zebra_send_capabilities(_bgp, true)) \
85 _ret = BGP_ERR_INVALID_VALUE; \
86 } \
87 } while (0)
88
89 #define VTY_BGP_GR_ROUTER_DETECT_AND_SEND_CAPABILITY_TO_ZEBRA( \
90 _bgp, _peer_list, _ret) \
91 do { \
92 struct peer *peer_loop; \
93 bool gr_router_detected = false; \
94 struct listnode *node = {0}; \
95 struct listnode *nnode = {0}; \
96 for (ALL_LIST_ELEMENTS(_peer_list, node, nnode, peer_loop)) { \
97 if (peer_loop->bgp->t_startup) \
98 bgp_peer_gr_flags_update(peer_loop); \
99 if (CHECK_FLAG(peer_loop->flags, \
100 PEER_FLAG_GRACEFUL_RESTART)) \
101 gr_router_detected = true; \
102 } \
103 if (gr_router_detected \
104 && _bgp->present_zebra_gr_state == ZEBRA_GR_DISABLE) { \
105 if (bgp_zebra_send_capabilities(_bgp, false)) \
106 _ret = BGP_ERR_INVALID_VALUE; \
107 } else if (!gr_router_detected \
108 && _bgp->present_zebra_gr_state \
109 == ZEBRA_GR_ENABLE) { \
110 if (bgp_zebra_send_capabilities(_bgp, true)) \
111 _ret = BGP_ERR_INVALID_VALUE; \
112 } \
113 } while (0)
114
115
116 #define PRINT_EOR(_eor_flag) \
117 do { \
118 if (eor_flag) \
119 vty_out(vty, "Yes\n"); \
120 else \
121 vty_out(vty, "No\n"); \
122 } while (0)
123
124 #define PRINT_EOR_JSON(_eor_flag) \
125 do { \
126 if (eor_flag) \
127 json_object_boolean_true_add( \
128 json_endofrib_status, \
129 "endOfRibSentAfterUpdate"); \
130 else \
131 json_object_boolean_false_add( \
132 json_endofrib_status, \
133 "endOfRibSentAfterUpdate"); \
134 } while (0)
135
136 extern void bgp_clear_soft_in(struct bgp *bgp, afi_t afi, safi_t safi);
137 extern void bgp_vty_init(void);
138 extern void community_alias_vty(void);
139 extern const char *get_afi_safi_str(afi_t afi, safi_t safi, bool for_json);
140 extern int bgp_get_vty(struct bgp **bgp, as_t *as, const char *name,
141 enum bgp_instance_type inst_type, const char *as_pretty,
142 enum asnotation_mode asnotation);
143 extern void bgp_config_write_update_delay(struct vty *vty, struct bgp *bgp);
144 extern void bgp_config_write_wpkt_quanta(struct vty *vty, struct bgp *bgp);
145 extern void bgp_config_write_rpkt_quanta(struct vty *vty, struct bgp *bgp);
146 extern void bgp_config_write_listen(struct vty *vty, struct bgp *bgp);
147 extern void bgp_config_write_coalesce_time(struct vty *vty, struct bgp *bgp);
148 extern int bgp_vty_return(struct vty *vty, int ret);
149 extern bool bgp_config_inprocess(void);
150 extern struct peer *peer_and_group_lookup_vty(struct vty *vty,
151 const char *peer_str);
152
153 extern afi_t bgp_vty_afi_from_str(const char *afi_str);
154
155 extern safi_t bgp_vty_safi_from_str(const char *safi_str);
156
157 extern int argv_find_and_parse_afi(struct cmd_token **argv, int argc,
158 int *index, afi_t *afi);
159
160 extern int argv_find_and_parse_safi(struct cmd_token **argv, int argc,
161 int *index, safi_t *safi);
162
163 extern int bgp_vty_find_and_parse_afi_safi_bgp(struct vty *vty,
164 struct cmd_token **argv,
165 int argc, int *idx, afi_t *afi,
166 safi_t *safi, struct bgp **bgp,
167 bool use_json);
168 int bgp_vty_find_and_parse_bgp(struct vty *vty, struct cmd_token **argv,
169 int argc, struct bgp **bgp, bool use_json);
170 extern int bgp_show_summary_vty(struct vty *vty, const char *name, afi_t afi,
171 safi_t safi, const char *neighbor, int as_type,
172 as_t as, uint16_t show_flags);
173 extern bool peergroup_flag_check(struct peer *peer, uint64_t flag);
174
175 #endif /* _QUAGGA_BGP_VTY_H */