1999-10-29 12:10:10 +00:00
|
|
|
/*
|
|
|
|
* BIRD Internet Routing Daemon -- Command-Line Interface
|
|
|
|
*
|
2000-06-03 14:40:39 +00:00
|
|
|
* (c) 1999--2000 Martin Mares <mj@ucw.cz>
|
1999-10-29 12:10:10 +00:00
|
|
|
*
|
|
|
|
* Can be freely distributed and used under the terms of the GNU GPL.
|
|
|
|
*/
|
|
|
|
|
2000-06-03 14:40:39 +00:00
|
|
|
/**
|
|
|
|
* DOC: Command line interface
|
|
|
|
*
|
|
|
|
* This module takes care of the BIRD's command-line interface (CLI).
|
|
|
|
* The CLI exists to provide a way to control BIRD remotely and to inspect
|
|
|
|
* its status. It uses a very simple textual protocol over a stream
|
|
|
|
* connection provided by the platform dependent code (on UNIX systems,
|
|
|
|
* it's a UNIX domain socket).
|
|
|
|
*
|
|
|
|
* Each session of the CLI consists of a sequence of request and replies,
|
|
|
|
* slightly resembling the FTP and SMTP protocols.
|
|
|
|
* Requests are commands encoded as a single line of text, replies are
|
|
|
|
* sequences of lines starting with a four-digit code followed by either
|
|
|
|
* a space (if it's the last line of the reply) or a minus sign (when the
|
|
|
|
* reply is going to continue with the next line), the rest of the line
|
|
|
|
* contains a textual message semantics of which depends on the numeric
|
|
|
|
* code. If a reply line has the same code as the previous one and it's
|
|
|
|
* a continuation line, the whole prefix can be replaced by a single
|
|
|
|
* white space character.
|
|
|
|
*
|
2000-06-07 13:25:53 +00:00
|
|
|
* Reply codes starting with 0 stand for `action successfully completed' messages,
|
2000-06-03 14:40:39 +00:00
|
|
|
* 1 means `table entry', 8 `runtime error' and 9 `syntax error'.
|
|
|
|
*
|
|
|
|
* Each CLI session is internally represented by a &cli structure and a
|
|
|
|
* resource pool containing all resources associated with the connection,
|
2000-06-07 13:25:53 +00:00
|
|
|
* so that it can be easily freed whenever the connection gets closed, not depending
|
2000-06-03 14:40:39 +00:00
|
|
|
* on the current state of command processing.
|
|
|
|
*
|
|
|
|
* The CLI commands are declared as a part of the configuration grammar
|
2000-06-08 12:37:21 +00:00
|
|
|
* by using the |CF_CLI| macro. When a command is received, it is processed
|
2000-06-07 12:29:08 +00:00
|
|
|
* by the same lexical analyzer and parser as used for the configuration, but
|
2000-06-03 14:40:39 +00:00
|
|
|
* it's switched to a special mode by prepending a fake token to the text,
|
|
|
|
* so that it uses only the CLI command rules. Then the parser invokes
|
|
|
|
* an execution routine corresponding to the command, which either constructs
|
2000-06-08 12:37:21 +00:00
|
|
|
* the whole reply and returns it back or (in case it expects the reply will be long)
|
2000-06-03 14:40:39 +00:00
|
|
|
* it prints a partial reply and asks the CLI module (using the @cont hook)
|
2000-06-07 13:25:53 +00:00
|
|
|
* to call it again when the output is transferred to the user.
|
2000-06-03 14:40:39 +00:00
|
|
|
*
|
|
|
|
* The @this_cli variable points to a &cli structure of the session being
|
|
|
|
* currently parsed, but it's of course available only in command handlers
|
|
|
|
* not entered using the @cont hook.
|
2009-07-14 12:18:54 +00:00
|
|
|
*
|
|
|
|
* TX buffer management works as follows: At cli.tx_buf there is a
|
|
|
|
* list of TX buffers (struct cli_out), cli.tx_write is the buffer
|
|
|
|
* currently used by the producer (cli_printf(), cli_alloc_out()) and
|
|
|
|
* cli.tx_pos is the buffer currently used by the consumer
|
|
|
|
* (cli_write(), in system dependent code). The producer uses
|
|
|
|
* cli_out.wpos ptr as the current write position and the consumer
|
|
|
|
* uses cli_out.outpos ptr as the current read position. When the
|
|
|
|
* producer produces something, it calls cli_write_trigger(). If there
|
|
|
|
* is not enough space in the current buffer, the producer allocates
|
|
|
|
* the new one. When the consumer processes everything in the buffer
|
|
|
|
* queue, it calls cli_written(), tha frees all buffers (except the
|
|
|
|
* first one) and schedules cli.event .
|
2018-02-06 16:43:55 +00:00
|
|
|
*
|
2000-06-03 14:40:39 +00:00
|
|
|
*/
|
|
|
|
|
1999-10-29 12:10:10 +00:00
|
|
|
#include "nest/bird.h"
|
|
|
|
#include "nest/cli.h"
|
Parse CLI commands. We use the same parser as for configuration files (because
we want to allow filter and similar complex constructs to be used in commands
and we should avoid code duplication), only with CLI_MARKER token prepended
before the whole input.
Defined macro CF_CLI(cmd, args, help) for defining CLI commands in .Y files.
The first argument specifies the command itself, the remaining two arguments
are copied to the help file (er, will be copied after the help file starts
to exist). This macro automatically creates a skeleton rule for the command,
you only need to append arguments as in:
CF_CLI(STEAL MONEY, <$>, [[Steal <$> US dollars or equivalent in any other currency]]): NUM {
cli_msg(0, "%d$ stolen", $3);
} ;
Also don't forget to reset lexer state between inputs.
1999-10-31 17:47:47 +00:00
|
|
|
#include "conf/conf.h"
|
|
|
|
#include "lib/string.h"
|
1999-10-29 12:10:10 +00:00
|
|
|
|
|
|
|
pool *cli_pool;
|
|
|
|
|
1999-12-06 12:34:45 +00:00
|
|
|
static byte *
|
|
|
|
cli_alloc_out(cli *c, int size)
|
|
|
|
{
|
|
|
|
struct cli_out *o;
|
|
|
|
|
|
|
|
if (!(o = c->tx_write) || o->wpos + size > o->end)
|
|
|
|
{
|
|
|
|
if (!o && c->tx_buf)
|
|
|
|
o = c->tx_buf;
|
|
|
|
else
|
|
|
|
{
|
|
|
|
o = mb_alloc(c->pool, sizeof(struct cli_out) + CLI_TX_BUF_SIZE);
|
|
|
|
if (c->tx_write)
|
|
|
|
c->tx_write->next = o;
|
|
|
|
else
|
|
|
|
c->tx_buf = o;
|
|
|
|
o->wpos = o->outpos = o->buf;
|
|
|
|
o->end = o->buf + CLI_TX_BUF_SIZE;
|
|
|
|
}
|
|
|
|
c->tx_write = o;
|
|
|
|
if (!c->tx_pos)
|
|
|
|
c->tx_pos = o;
|
2000-04-27 22:35:08 +00:00
|
|
|
o->next = NULL;
|
1999-12-06 12:34:45 +00:00
|
|
|
}
|
|
|
|
o->wpos += size;
|
|
|
|
return o->wpos - size;
|
|
|
|
}
|
|
|
|
|
2000-06-03 14:40:39 +00:00
|
|
|
/**
|
|
|
|
* cli_printf - send reply to a CLI connection
|
|
|
|
* @c: CLI connection
|
|
|
|
* @code: numeric code of the reply, negative for continuation lines
|
|
|
|
* @msg: a printf()-like formatting string.
|
|
|
|
*
|
|
|
|
* This function send a single line of reply to a given CLI connection.
|
|
|
|
* In works in all aspects like bsprintf() except that it automatically
|
|
|
|
* prepends the reply line prefix.
|
|
|
|
*
|
|
|
|
* Please note that if the connection can be already busy sending some
|
|
|
|
* data in which case cli_printf() stores the output to a temporary buffer,
|
|
|
|
* so please avoid sending a large batch of replies without waiting
|
|
|
|
* for the buffers to be flushed.
|
|
|
|
*
|
|
|
|
* If you want to write to the current CLI output, you can use the cli_msg()
|
|
|
|
* macro instead.
|
|
|
|
*/
|
1999-10-29 12:10:10 +00:00
|
|
|
void
|
2024-11-14 19:46:45 +00:00
|
|
|
cli_vprintf(cli *c, int code, const char *msg, va_list args)
|
1999-10-29 12:10:10 +00:00
|
|
|
{
|
2011-07-03 17:43:30 +00:00
|
|
|
byte buf[CLI_LINE_SIZE];
|
1999-10-31 15:43:44 +00:00
|
|
|
int cd = code;
|
2012-12-26 11:40:48 +00:00
|
|
|
int errcode;
|
1999-10-31 15:43:44 +00:00
|
|
|
int size, cnt;
|
1999-10-29 12:10:10 +00:00
|
|
|
|
1999-10-31 15:43:44 +00:00
|
|
|
if (cd < 0)
|
|
|
|
{
|
|
|
|
cd = -cd;
|
|
|
|
if (cd == c->last_reply)
|
|
|
|
size = bsprintf(buf, " ");
|
|
|
|
else
|
|
|
|
size = bsprintf(buf, "%04d-", cd);
|
2012-12-26 11:40:48 +00:00
|
|
|
errcode = -8000;
|
|
|
|
}
|
|
|
|
else if (cd == CLI_ASYNC_CODE)
|
|
|
|
{
|
2018-02-06 16:43:55 +00:00
|
|
|
size = 1; buf[0] = '+';
|
2012-12-26 11:40:48 +00:00
|
|
|
errcode = cd;
|
1999-10-31 15:43:44 +00:00
|
|
|
}
|
1999-10-29 12:10:10 +00:00
|
|
|
else
|
2012-12-26 11:40:48 +00:00
|
|
|
{
|
|
|
|
size = bsprintf(buf, "%04d ", cd);
|
|
|
|
errcode = 8000;
|
2019-11-26 15:43:09 +00:00
|
|
|
cd = 0; /* Final message - no more continuation lines */
|
2012-12-26 11:40:48 +00:00
|
|
|
}
|
|
|
|
|
1999-10-31 15:43:44 +00:00
|
|
|
c->last_reply = cd;
|
|
|
|
cnt = bvsnprintf(buf+size, sizeof(buf)-size-1, msg, args);
|
|
|
|
if (cnt < 0)
|
|
|
|
{
|
2012-12-26 11:40:48 +00:00
|
|
|
cli_printf(c, errcode, "<line overflow>");
|
1999-10-31 15:43:44 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
size += cnt;
|
1999-10-29 12:10:10 +00:00
|
|
|
buf[size++] = '\n';
|
1999-12-06 12:34:45 +00:00
|
|
|
memcpy(cli_alloc_out(c, size), buf, size);
|
|
|
|
}
|
|
|
|
|
1999-10-31 15:43:44 +00:00
|
|
|
static void
|
|
|
|
cli_hello(cli *c)
|
|
|
|
{
|
|
|
|
cli_printf(c, 1, "BIRD " BIRD_VERSION " ready.");
|
|
|
|
c->cont = NULL;
|
|
|
|
}
|
|
|
|
|
1999-10-29 12:10:10 +00:00
|
|
|
static void
|
|
|
|
cli_free_out(cli *c)
|
|
|
|
{
|
|
|
|
struct cli_out *o, *p;
|
|
|
|
|
|
|
|
if (o = c->tx_buf)
|
|
|
|
{
|
|
|
|
o->wpos = o->outpos = o->buf;
|
|
|
|
while (p = o->next)
|
|
|
|
{
|
|
|
|
o->next = p->next;
|
|
|
|
mb_free(p);
|
|
|
|
}
|
|
|
|
}
|
2000-04-27 22:35:08 +00:00
|
|
|
c->tx_write = c->tx_pos = NULL;
|
1999-12-06 12:34:45 +00:00
|
|
|
c->async_msg_size = 0;
|
1999-10-29 12:10:10 +00:00
|
|
|
}
|
|
|
|
|
2009-07-14 12:18:54 +00:00
|
|
|
void
|
|
|
|
cli_written(cli *c)
|
|
|
|
{
|
|
|
|
cli_free_out(c);
|
|
|
|
ev_schedule(c->event);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
Parse CLI commands. We use the same parser as for configuration files (because
we want to allow filter and similar complex constructs to be used in commands
and we should avoid code duplication), only with CLI_MARKER token prepended
before the whole input.
Defined macro CF_CLI(cmd, args, help) for defining CLI commands in .Y files.
The first argument specifies the command itself, the remaining two arguments
are copied to the help file (er, will be copied after the help file starts
to exist). This macro automatically creates a skeleton rule for the command,
you only need to append arguments as in:
CF_CLI(STEAL MONEY, <$>, [[Steal <$> US dollars or equivalent in any other currency]]): NUM {
cli_msg(0, "%d$ stolen", $3);
} ;
Also don't forget to reset lexer state between inputs.
1999-10-31 17:47:47 +00:00
|
|
|
static byte *cli_rh_pos;
|
2015-05-19 06:53:34 +00:00
|
|
|
static uint cli_rh_len;
|
Parse CLI commands. We use the same parser as for configuration files (because
we want to allow filter and similar complex constructs to be used in commands
and we should avoid code duplication), only with CLI_MARKER token prepended
before the whole input.
Defined macro CF_CLI(cmd, args, help) for defining CLI commands in .Y files.
The first argument specifies the command itself, the remaining two arguments
are copied to the help file (er, will be copied after the help file starts
to exist). This macro automatically creates a skeleton rule for the command,
you only need to append arguments as in:
CF_CLI(STEAL MONEY, <$>, [[Steal <$> US dollars or equivalent in any other currency]]): NUM {
cli_msg(0, "%d$ stolen", $3);
} ;
Also don't forget to reset lexer state between inputs.
1999-10-31 17:47:47 +00:00
|
|
|
static int cli_rh_trick_flag;
|
|
|
|
struct cli *this_cli;
|
|
|
|
|
|
|
|
static int
|
2015-05-19 06:53:34 +00:00
|
|
|
cli_cmd_read_hook(byte *buf, uint max, UNUSED int fd)
|
Parse CLI commands. We use the same parser as for configuration files (because
we want to allow filter and similar complex constructs to be used in commands
and we should avoid code duplication), only with CLI_MARKER token prepended
before the whole input.
Defined macro CF_CLI(cmd, args, help) for defining CLI commands in .Y files.
The first argument specifies the command itself, the remaining two arguments
are copied to the help file (er, will be copied after the help file starts
to exist). This macro automatically creates a skeleton rule for the command,
you only need to append arguments as in:
CF_CLI(STEAL MONEY, <$>, [[Steal <$> US dollars or equivalent in any other currency]]): NUM {
cli_msg(0, "%d$ stolen", $3);
} ;
Also don't forget to reset lexer state between inputs.
1999-10-31 17:47:47 +00:00
|
|
|
{
|
|
|
|
if (!cli_rh_trick_flag)
|
|
|
|
{
|
|
|
|
cli_rh_trick_flag = 1;
|
|
|
|
buf[0] = '!';
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
if (max > cli_rh_len)
|
|
|
|
max = cli_rh_len;
|
|
|
|
memcpy(buf, cli_rh_pos, max);
|
|
|
|
cli_rh_pos += max;
|
|
|
|
cli_rh_len -= max;
|
|
|
|
return max;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
cli_command(struct cli *c)
|
|
|
|
{
|
|
|
|
struct config f;
|
|
|
|
int res;
|
|
|
|
|
2024-06-13 10:15:38 +00:00
|
|
|
if (OBSREF_GET(config)->cli_debug > 1)
|
2000-05-29 22:10:18 +00:00
|
|
|
log(L_TRACE "CLI: %s", c->rx_buf);
|
1999-11-30 14:04:09 +00:00
|
|
|
bzero(&f, sizeof(f));
|
Parse CLI commands. We use the same parser as for configuration files (because
we want to allow filter and similar complex constructs to be used in commands
and we should avoid code duplication), only with CLI_MARKER token prepended
before the whole input.
Defined macro CF_CLI(cmd, args, help) for defining CLI commands in .Y files.
The first argument specifies the command itself, the remaining two arguments
are copied to the help file (er, will be copied after the help file starts
to exist). This macro automatically creates a skeleton rule for the command,
you only need to append arguments as in:
CF_CLI(STEAL MONEY, <$>, [[Steal <$> US dollars or equivalent in any other currency]]): NUM {
cli_msg(0, "%d$ stolen", $3);
} ;
Also don't forget to reset lexer state between inputs.
1999-10-31 17:47:47 +00:00
|
|
|
f.mem = c->parser_pool;
|
2023-04-21 13:26:06 +00:00
|
|
|
f.pool = rp_new(c->pool, the_bird_domain.the_bird, "Config");
|
2024-06-13 10:15:38 +00:00
|
|
|
obstacle_target_init(&f.obstacles, &f.obstacles_cleared, c->pool, "Config");
|
|
|
|
|
2019-03-20 15:50:58 +00:00
|
|
|
init_list(&f.symbols);
|
Parse CLI commands. We use the same parser as for configuration files (because
we want to allow filter and similar complex constructs to be used in commands
and we should avoid code duplication), only with CLI_MARKER token prepended
before the whole input.
Defined macro CF_CLI(cmd, args, help) for defining CLI commands in .Y files.
The first argument specifies the command itself, the remaining two arguments
are copied to the help file (er, will be copied after the help file starts
to exist). This macro automatically creates a skeleton rule for the command,
you only need to append arguments as in:
CF_CLI(STEAL MONEY, <$>, [[Steal <$> US dollars or equivalent in any other currency]]): NUM {
cli_msg(0, "%d$ stolen", $3);
} ;
Also don't forget to reset lexer state between inputs.
1999-10-31 17:47:47 +00:00
|
|
|
cf_read_hook = cli_cmd_read_hook;
|
|
|
|
cli_rh_pos = c->rx_buf;
|
|
|
|
cli_rh_len = strlen(c->rx_buf);
|
|
|
|
cli_rh_trick_flag = 0;
|
|
|
|
this_cli = c;
|
2024-06-13 10:15:38 +00:00
|
|
|
this_cli->main_config = OBSREF_GET(config);
|
Parse CLI commands. We use the same parser as for configuration files (because
we want to allow filter and similar complex constructs to be used in commands
and we should avoid code duplication), only with CLI_MARKER token prepended
before the whole input.
Defined macro CF_CLI(cmd, args, help) for defining CLI commands in .Y files.
The first argument specifies the command itself, the remaining two arguments
are copied to the help file (er, will be copied after the help file starts
to exist). This macro automatically creates a skeleton rule for the command,
you only need to append arguments as in:
CF_CLI(STEAL MONEY, <$>, [[Steal <$> US dollars or equivalent in any other currency]]): NUM {
cli_msg(0, "%d$ stolen", $3);
} ;
Also don't forget to reset lexer state between inputs.
1999-10-31 17:47:47 +00:00
|
|
|
lp_flush(c->parser_pool);
|
2024-06-13 10:15:38 +00:00
|
|
|
res = cli_parse(this_cli->main_config, &f);
|
Parse CLI commands. We use the same parser as for configuration files (because
we want to allow filter and similar complex constructs to be used in commands
and we should avoid code duplication), only with CLI_MARKER token prepended
before the whole input.
Defined macro CF_CLI(cmd, args, help) for defining CLI commands in .Y files.
The first argument specifies the command itself, the remaining two arguments
are copied to the help file (er, will be copied after the help file starts
to exist). This macro automatically creates a skeleton rule for the command,
you only need to append arguments as in:
CF_CLI(STEAL MONEY, <$>, [[Steal <$> US dollars or equivalent in any other currency]]): NUM {
cli_msg(0, "%d$ stolen", $3);
} ;
Also don't forget to reset lexer state between inputs.
1999-10-31 17:47:47 +00:00
|
|
|
if (!res)
|
|
|
|
cli_printf(c, 9001, f.err_msg);
|
2017-05-31 11:31:03 +00:00
|
|
|
|
2024-06-13 10:29:21 +00:00
|
|
|
this_cli->main_config = NULL;
|
2017-05-31 11:31:03 +00:00
|
|
|
config_free(&f);
|
Parse CLI commands. We use the same parser as for configuration files (because
we want to allow filter and similar complex constructs to be used in commands
and we should avoid code duplication), only with CLI_MARKER token prepended
before the whole input.
Defined macro CF_CLI(cmd, args, help) for defining CLI commands in .Y files.
The first argument specifies the command itself, the remaining two arguments
are copied to the help file (er, will be copied after the help file starts
to exist). This macro automatically creates a skeleton rule for the command,
you only need to append arguments as in:
CF_CLI(STEAL MONEY, <$>, [[Steal <$> US dollars or equivalent in any other currency]]): NUM {
cli_msg(0, "%d$ stolen", $3);
} ;
Also don't forget to reset lexer state between inputs.
1999-10-31 17:47:47 +00:00
|
|
|
}
|
|
|
|
|
2000-04-27 22:35:08 +00:00
|
|
|
static void
|
1999-10-29 12:10:10 +00:00
|
|
|
cli_event(void *data)
|
|
|
|
{
|
|
|
|
cli *c = data;
|
|
|
|
int err;
|
|
|
|
|
1999-10-31 15:43:44 +00:00
|
|
|
if (c->tx_pos)
|
|
|
|
;
|
|
|
|
else if (c->cont)
|
|
|
|
c->cont(c);
|
|
|
|
else
|
1999-10-29 12:10:10 +00:00
|
|
|
{
|
1999-10-31 15:43:44 +00:00
|
|
|
err = cli_get_command(c);
|
|
|
|
if (!err)
|
2000-04-27 22:35:08 +00:00
|
|
|
return;
|
1999-10-31 15:43:44 +00:00
|
|
|
if (err < 0)
|
|
|
|
cli_printf(c, 9000, "Command too long");
|
|
|
|
else
|
Parse CLI commands. We use the same parser as for configuration files (because
we want to allow filter and similar complex constructs to be used in commands
and we should avoid code duplication), only with CLI_MARKER token prepended
before the whole input.
Defined macro CF_CLI(cmd, args, help) for defining CLI commands in .Y files.
The first argument specifies the command itself, the remaining two arguments
are copied to the help file (er, will be copied after the help file starts
to exist). This macro automatically creates a skeleton rule for the command,
you only need to append arguments as in:
CF_CLI(STEAL MONEY, <$>, [[Steal <$> US dollars or equivalent in any other currency]]): NUM {
cli_msg(0, "%d$ stolen", $3);
} ;
Also don't forget to reset lexer state between inputs.
1999-10-31 17:47:47 +00:00
|
|
|
cli_command(c);
|
1999-10-29 12:10:10 +00:00
|
|
|
}
|
2009-07-14 12:18:54 +00:00
|
|
|
|
2022-10-11 09:06:32 +00:00
|
|
|
if (c->tx_pos)
|
|
|
|
cli_write_trigger(c);
|
2024-11-15 09:04:51 +00:00
|
|
|
else
|
|
|
|
ev_schedule(c->event);
|
1999-10-29 12:10:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
cli *
|
2024-11-28 11:07:30 +00:00
|
|
|
cli_new(struct birdsock *sock, struct cli_config *cf)
|
1999-10-29 12:10:10 +00:00
|
|
|
{
|
2023-04-21 13:26:06 +00:00
|
|
|
pool *p = rp_new(cli_pool, the_bird_domain.the_bird, "CLI");
|
1999-10-29 12:10:10 +00:00
|
|
|
cli *c = mb_alloc(p, sizeof(cli));
|
|
|
|
|
1999-12-06 12:34:45 +00:00
|
|
|
bzero(c, sizeof(cli));
|
1999-10-29 12:10:10 +00:00
|
|
|
c->pool = p;
|
2023-01-19 09:53:09 +00:00
|
|
|
c->sock = sock;
|
1999-10-29 12:10:10 +00:00
|
|
|
c->event = ev_new(p);
|
|
|
|
c->event->hook = cli_event;
|
|
|
|
c->event->data = c;
|
1999-10-31 15:43:44 +00:00
|
|
|
c->cont = cli_hello;
|
2017-05-16 12:31:16 +00:00
|
|
|
c->parser_pool = lp_new_default(c->pool);
|
1999-12-06 12:34:45 +00:00
|
|
|
c->rx_buf = mb_alloc(c->pool, CLI_RX_BUF_SIZE);
|
2024-06-24 11:46:12 +00:00
|
|
|
|
|
|
|
if (cf->restricted)
|
|
|
|
c->restricted = 1;
|
|
|
|
|
1999-10-31 15:43:44 +00:00
|
|
|
ev_schedule(c->event);
|
1999-10-29 12:10:10 +00:00
|
|
|
return c;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
cli_kick(cli *c)
|
|
|
|
{
|
1999-10-31 15:43:44 +00:00
|
|
|
if (!c->cont && !c->tx_pos)
|
|
|
|
ev_schedule(c->event);
|
1999-10-29 12:10:10 +00:00
|
|
|
}
|
|
|
|
|
1999-12-06 12:34:45 +00:00
|
|
|
static list cli_log_hooks;
|
|
|
|
static int cli_log_inited;
|
|
|
|
|
2024-11-05 17:53:22 +00:00
|
|
|
/* Set time format override for the current session */
|
|
|
|
void
|
|
|
|
cli_set_timeformat(cli *c, const struct timeformat tf)
|
|
|
|
{
|
|
|
|
size_t len1 = strlen(tf.fmt1) + 1;
|
|
|
|
size_t len2 = tf.fmt2 ? strlen(tf.fmt2) + 1 : 0;
|
|
|
|
|
|
|
|
if (len1 > TM_DATETIME_BUFFER_SIZE || len2 > TM_DATETIME_BUFFER_SIZE)
|
|
|
|
{
|
|
|
|
cli_msg(9003, "Format string too long");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
struct timeformat *old_tf = c->tf;
|
|
|
|
struct timeformat *new_tf = mb_allocz(c->pool, sizeof(struct timeformat));
|
|
|
|
new_tf->fmt1 = memcpy(mb_alloc(c->pool, len1), tf.fmt1, len1);
|
|
|
|
new_tf->fmt2 = tf.fmt2 ? memcpy(mb_alloc(c->pool, len2), tf.fmt2, len2) : NULL;
|
|
|
|
new_tf->limit = tf.limit;
|
|
|
|
c->tf = new_tf;
|
|
|
|
|
|
|
|
if (old_tf)
|
|
|
|
{
|
|
|
|
mb_free((void *) old_tf->fmt1);
|
|
|
|
mb_free((void *) old_tf->fmt2);
|
|
|
|
mb_free(old_tf);
|
|
|
|
}
|
|
|
|
|
|
|
|
cli_msg(0, "");
|
|
|
|
}
|
|
|
|
|
2012-12-26 11:40:48 +00:00
|
|
|
/* Hack for scheduled undo notification */
|
|
|
|
extern cli *cmd_reconfig_stored_cli;
|
|
|
|
|
1999-10-29 12:10:10 +00:00
|
|
|
void
|
|
|
|
cli_free(cli *c)
|
|
|
|
{
|
2024-05-02 09:39:34 +00:00
|
|
|
CALL(c->cleanup, c);
|
|
|
|
|
2012-12-26 11:40:48 +00:00
|
|
|
if (c == cmd_reconfig_stored_cli)
|
|
|
|
cmd_reconfig_stored_cli = NULL;
|
2022-06-24 13:27:26 +00:00
|
|
|
|
2024-05-02 09:39:34 +00:00
|
|
|
rp_free(c->pool);
|
1999-10-29 12:10:10 +00:00
|
|
|
}
|
|
|
|
|
2000-06-03 14:40:39 +00:00
|
|
|
/**
|
|
|
|
* cli_init - initialize the CLI module
|
|
|
|
*
|
|
|
|
* This function is called during BIRD startup to initialize
|
|
|
|
* the internal data structures of the CLI module.
|
|
|
|
*/
|
1999-10-29 12:10:10 +00:00
|
|
|
void
|
|
|
|
cli_init(void)
|
|
|
|
{
|
2023-04-21 13:26:06 +00:00
|
|
|
cli_pool = rp_new(&root_pool, the_bird_domain.the_bird, "CLI");
|
1999-12-06 12:34:45 +00:00
|
|
|
init_list(&cli_log_hooks);
|
|
|
|
cli_log_inited = 1;
|
1999-10-29 12:10:10 +00:00
|
|
|
}
|