1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * Copyright (C) 1996, 97, 98, 99, 2000 Kunihiro Ishiguro
6 #ifndef _QUAGGA_BGP_VTY_H
7 #define _QUAGGA_BGP_VTY_H
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"
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
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
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"
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"
44 #define BGP_SHOW_PEER_GR_CAPABILITY(vty, p, json) \
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( \
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
60 #define VTY_BGP_GR_ROUTER_DETECT(_bgp, _peer, _peer_list) \
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; \
72 #define VTY_SEND_BGP_GR_CAPABILITY_TO_ZEBRA(_bgp, _ret) \
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; \
86 #define VTY_BGP_GR_ROUTER_DETECT_AND_SEND_CAPABILITY_TO_ZEBRA( \
87 _bgp, _peer_list, _ret) \
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; \
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; \
113 #define PRINT_EOR(_eor_flag) \
116 vty_out(vty, "Yes\n"); \
118 vty_out(vty, "No\n"); \
121 #define PRINT_EOR_JSON(_eor_flag) \
124 json_object_boolean_true_add( \
125 json_endofrib_status, \
126 "endOfRibSentAfterUpdate"); \
128 json_object_boolean_false_add( \
129 json_endofrib_status, \
130 "endOfRibSentAfterUpdate"); \
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
, const char *as_pretty
,
139 enum asnotation_mode asnotation
);
140 extern void bgp_config_write_update_delay(struct vty
*vty
, struct bgp
*bgp
);
141 extern void bgp_config_write_wpkt_quanta(struct vty
*vty
, struct bgp
*bgp
);
142 extern void bgp_config_write_rpkt_quanta(struct vty
*vty
, struct bgp
*bgp
);
143 extern void bgp_config_write_listen(struct vty
*vty
, struct bgp
*bgp
);
144 extern void bgp_config_write_coalesce_time(struct vty
*vty
, struct bgp
*bgp
);
145 extern int bgp_vty_return(struct vty
*vty
, int ret
);
146 extern bool bgp_config_inprocess(void);
147 extern struct peer
*peer_and_group_lookup_vty(struct vty
*vty
,
148 const char *peer_str
);
150 extern afi_t
bgp_vty_afi_from_str(const char *afi_str
);
152 extern safi_t
bgp_vty_safi_from_str(const char *safi_str
);
154 extern int argv_find_and_parse_afi(struct cmd_token
**argv
, int argc
,
155 int *index
, afi_t
*afi
);
157 extern int argv_find_and_parse_safi(struct cmd_token
**argv
, int argc
,
158 int *index
, safi_t
*safi
);
160 extern int bgp_vty_find_and_parse_afi_safi_bgp(struct vty
*vty
,
161 struct cmd_token
**argv
,
162 int argc
, int *idx
, afi_t
*afi
,
163 safi_t
*safi
, struct bgp
**bgp
,
165 int bgp_vty_find_and_parse_bgp(struct vty
*vty
, struct cmd_token
**argv
,
166 int argc
, struct bgp
**bgp
, bool use_json
);
167 extern int bgp_show_summary_vty(struct vty
*vty
, const char *name
, afi_t afi
,
168 safi_t safi
, const char *neighbor
, int as_type
,
169 as_t as
, uint16_t show_flags
);
170 extern bool peergroup_flag_check(struct peer
*peer
, uint64_t flag
);
172 #endif /* _QUAGGA_BGP_VTY_H */