-
-/* CLI stuff */
-
-#include <libcli.h>
-
-int cmd_show_bgp(struct cli_def *cli, char *command, char **argv, int argc)
-{
- int i;
- int hdr = 0;
- char *addr;
-
- if (!bgp_configured)
- return CLI_OK;
-
- if (CLI_HELP_REQUESTED)
- return cli_arg_help(cli, 1,
- "A.B.C.D", "BGP peer address",
- "NAME", "BGP peer name",
- NULL);
-
- cli_print(cli, "BGPv%d router identifier %s, local AS number %d, "
- "hold time %ds", BGP_VERSION, inet_toa(my_address), (int) our_as,
- BGP_HOLD_TIME);
-
- time(&time_now);
-
- for (i = 0; i < BGP_NUM_PEERS; i++)
- {
- if (!*bgp_peers[i].name)
- continue;
-
- addr = inet_toa(bgp_peers[i].addr);
- if (argc && strcmp(addr, argv[0]) &&
- strncmp(bgp_peers[i].name, argv[0], strlen(argv[0])))
- continue;
-
- if (!hdr++)
- {
- cli_print(cli, "");
- cli_print(cli, "Peer AS Address "
- "State Retries Retry in Route Pend");
- cli_print(cli, "------------------ ----- --------------- "
- "----------- ------- -------- ----- ----");
- }
-
- cli_print(cli, "%-18.18s %5d %15s %-11s %7d %7ds %5s %4s",
- bgp_peers[i].name,
- bgp_peers[i].as,
- addr,
- bgp_state_str(bgp_peers[i].state),
- bgp_peers[i].retry_count,
- bgp_peers[i].retry_time ? bgp_peers[i].retry_time - time_now : 0,
- bgp_peers[i].routing ? "yes" : "no",
- bgp_peers[i].update_routes ? "yes" : "no");
- }
-
- return CLI_OK;
-}
-
-int cmd_suspend_bgp(struct cli_def *cli, char *command, char **argv, int argc)
-{
- int i;
- char *addr;
-
- if (!bgp_configured)
- return CLI_OK;
-
- if (CLI_HELP_REQUESTED)
- return cli_arg_help(cli, 1,
- "A.B.C.D", "BGP peer address",
- "NAME", "BGP peer name",
- NULL);
-
- for (i = 0; i < BGP_NUM_PEERS; i++)
- {
- if (bgp_peers[i].state != Established)
- continue;
-
- if (!bgp_peers[i].routing)
- continue;
-
- addr = inet_toa(bgp_peers[i].addr);
- if (argc && strcmp(addr, argv[0]) && strcmp(bgp_peers[i].name, argv[0]))
- continue;
-
- bgp_peers[i].cli_flag = BGP_CLI_SUSPEND;
- cli_print(cli, "Suspending peer %s", bgp_peers[i].name);
- }
-
- return CLI_OK;
-}
-
-int cmd_no_suspend_bgp(struct cli_def *cli, char *command, char **argv, int argc)
-{
- int i;
- char *addr;
-
- if (!bgp_configured)
- return CLI_OK;
-
- if (CLI_HELP_REQUESTED)
- return cli_arg_help(cli, 1,
- "A.B.C.D", "BGP peer address",
- "NAME", "BGP peer name",
- NULL);
-
- for (i = 0; i < BGP_NUM_PEERS; i++)
- {
- if (bgp_peers[i].state != Established)
- continue;
-
- if (bgp_peers[i].routing)
- continue;
-
- addr = inet_toa(bgp_peers[i].addr);
- if (argc && strcmp(addr, argv[0]) &&
- strncmp(bgp_peers[i].name, argv[0], strlen(argv[0])))
- continue;
-
- bgp_peers[i].cli_flag = BGP_CLI_ENABLE;
- cli_print(cli, "Un-suspending peer %s", bgp_peers[i].name);
- }
-
- return CLI_OK;
-}
-
-int cmd_restart_bgp(struct cli_def *cli, char *command, char **argv, int argc)
-{
- int i;
- char *addr;
-
- if (!bgp_configured)
- return CLI_OK;
-
- if (CLI_HELP_REQUESTED)
- return cli_arg_help(cli, 1,
- "A.B.C.D", "BGP peer address",
- "NAME", "BGP peer name",
- NULL);
-
- for (i = 0; i < BGP_NUM_PEERS; i++)
- {
- if (!*bgp_peers[i].name)
- continue;
-
- addr = inet_toa(bgp_peers[i].addr);
- if (argc && strcmp(addr, argv[0]) &&
- strncmp(bgp_peers[i].name, argv[0], strlen(argv[0])))
- continue;
-
- bgp_peers[i].cli_flag = BGP_CLI_RESTART;
- cli_print(cli, "Restarting peer %s", bgp_peers[i].name);
- }
-
- return CLI_OK;
-}