1999-10-29 20:10:10 +08:00
|
|
|
/*
|
|
|
|
* BIRD Internet Routing Daemon -- Command-Line Interface
|
|
|
|
*
|
2000-01-19 20:30:19 +08:00
|
|
|
* (c) 1999--2000 Martin Mares <mj@ucw.cz>
|
1999-10-29 20:10:10 +08:00
|
|
|
*
|
|
|
|
* Can be freely distributed and used under the terms of the GNU GPL.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef _BIRD_CLI_H_
|
|
|
|
#define _BIRD_CLI_H_
|
|
|
|
|
|
|
|
#include "lib/resource.h"
|
|
|
|
#include "lib/event.h"
|
|
|
|
|
|
|
|
#define CLI_RX_BUF_SIZE 4096
|
|
|
|
#define CLI_TX_BUF_SIZE 4096
|
1999-12-06 20:34:45 +08:00
|
|
|
#define CLI_MAX_ASYNC_QUEUE 4096
|
1999-10-29 20:10:10 +08:00
|
|
|
|
|
|
|
struct cli_out {
|
|
|
|
struct cli_out *next;
|
|
|
|
byte *wpos, *outpos, *end;
|
|
|
|
byte buf[0];
|
|
|
|
};
|
|
|
|
|
|
|
|
typedef struct cli {
|
1999-12-06 20:34:45 +08:00
|
|
|
node n; /* Node in list of all log hooks */
|
1999-10-29 20:10:10 +08:00
|
|
|
pool *pool;
|
|
|
|
void *priv; /* Private to sysdep layer */
|
1999-12-06 20:34:45 +08:00
|
|
|
byte *rx_buf, *rx_pos, *rx_aux; /* sysdep */
|
1999-10-29 20:10:10 +08:00
|
|
|
struct cli_out *tx_buf, *tx_pos, *tx_write;
|
|
|
|
event *event;
|
1999-10-31 23:43:44 +08:00
|
|
|
void (*cont)(struct cli *c);
|
1999-11-17 20:00:21 +08:00
|
|
|
void (*cleanup)(struct cli *c);
|
1999-10-31 23:43:44 +08:00
|
|
|
void *rover; /* Private to continuation routine */
|
|
|
|
int last_reply;
|
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-11-01 01:47:47 +08:00
|
|
|
struct linpool *parser_pool; /* Pool used during parsing */
|
1999-12-06 20:34:45 +08:00
|
|
|
byte *ring_buf; /* Ring buffer for asynchronous messages */
|
|
|
|
byte *ring_end, *ring_read, *ring_write; /* Pointers to the ring buffer */
|
|
|
|
unsigned int ring_overflow; /* Counter of ring overflows */
|
|
|
|
unsigned int log_mask; /* Mask of allowed message levels */
|
|
|
|
unsigned int log_threshold; /* When free < log_threshold, store only important messages */
|
|
|
|
unsigned int async_msg_size; /* Total size of async messages queued in tx_buf */
|
1999-10-29 20:10:10 +08:00
|
|
|
} cli;
|
|
|
|
|
|
|
|
extern pool *cli_pool;
|
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-11-01 01:47:47 +08:00
|
|
|
extern struct cli *this_cli; /* Used during parsing */
|
1999-10-29 20:10:10 +08:00
|
|
|
|
1999-10-31 23:43:44 +08:00
|
|
|
/* Functions to be called by command handlers */
|
|
|
|
|
|
|
|
void cli_printf(cli *, int, char *, ...);
|
1999-11-25 23:34:51 +08:00
|
|
|
#define cli_msg(x...) cli_printf(this_cli, x)
|
1999-12-06 20:34:45 +08:00
|
|
|
void cli_set_log_echo(cli *, unsigned int mask, unsigned int size);
|
1999-10-31 23:43:44 +08:00
|
|
|
|
|
|
|
/* Functions provided to sysdep layer */
|
|
|
|
|
1999-10-29 20:10:10 +08:00
|
|
|
cli *cli_new(void *);
|
|
|
|
void cli_init(void);
|
|
|
|
void cli_free(cli *);
|
|
|
|
void cli_kick(cli *);
|
|
|
|
void cli_written(cli *);
|
1999-12-06 20:34:45 +08:00
|
|
|
void cli_echo(unsigned int class, byte *msg);
|
1999-10-29 20:10:10 +08:00
|
|
|
|
1999-10-31 23:43:44 +08:00
|
|
|
/* Functions provided by sysdep layer */
|
1999-10-29 20:10:10 +08:00
|
|
|
|
|
|
|
int cli_write(cli *);
|
|
|
|
int cli_get_command(cli *);
|
|
|
|
|
|
|
|
#endif
|