]> git.ipfire.org Git - thirdparty/bird.git/blame - nest/cli.h
Kernel: Do not use route replace when krt_metric differs
[thirdparty/bird.git] / nest / cli.h
CommitLineData
7d3aab1c
MM
1/*
2 * BIRD Internet Routing Daemon -- Command-Line Interface
3 *
4b87e256 4 * (c) 1999--2000 Martin Mares <mj@ucw.cz>
7d3aab1c
MM
5 *
6 * Can be freely distributed and used under the terms of the GNU GPL.
7 */
8
9#ifndef _BIRD_CLI_H_
10#define _BIRD_CLI_H_
11
12#include "lib/resource.h"
13#include "lib/event.h"
14
15#define CLI_RX_BUF_SIZE 4096
16#define CLI_TX_BUF_SIZE 4096
34350a52 17#define CLI_MAX_ASYNC_QUEUE 4096
7d3aab1c 18
fdf16eb6
OZ
19#define CLI_MSG_SIZE 500
20#define CLI_LINE_SIZE 512
21
7d3aab1c
MM
22struct cli_out {
23 struct cli_out *next;
24 byte *wpos, *outpos, *end;
25 byte buf[0];
26};
27
28typedef struct cli {
34350a52 29 node n; /* Node in list of all log hooks */
7d3aab1c
MM
30 pool *pool;
31 void *priv; /* Private to sysdep layer */
4c19a8a9 32 byte *rx_buf, *rx_pos; /* sysdep */
7d3aab1c
MM
33 struct cli_out *tx_buf, *tx_pos, *tx_write;
34 event *event;
b9672a84 35 void (*cont)(struct cli *c);
ffb59d24 36 void (*cleanup)(struct cli *c);
b9672a84
MM
37 void *rover; /* Private to continuation routine */
38 int last_reply;
e0a45fb4 39 int restricted; /* CLI is restricted to read-only commands */
bc2fb680 40 struct linpool *parser_pool; /* Pool used during parsing */
f8d44b01 41 struct linpool *show_pool; /* Pool used during route show */
34350a52
MM
42 byte *ring_buf; /* Ring buffer for asynchronous messages */
43 byte *ring_end, *ring_read, *ring_write; /* Pointers to the ring buffer */
ae80a2de
PT
44 uint ring_overflow; /* Counter of ring overflows */
45 uint log_mask; /* Mask of allowed message levels */
46 uint log_threshold; /* When free < log_threshold, store only important messages */
47 uint async_msg_size; /* Total size of async messages queued in tx_buf */
7d3aab1c
MM
48} cli;
49
50extern pool *cli_pool;
bc2fb680 51extern struct cli *this_cli; /* Used during parsing */
7d3aab1c 52
a92cf57d
OZ
53#define CLI_ASYNC_CODE 10000
54
b9672a84
MM
55/* Functions to be called by command handlers */
56
57void cli_printf(cli *, int, char *, ...);
35793769 58#define cli_msg(x...) cli_printf(this_cli, x)
ae80a2de 59void cli_set_log_echo(cli *, uint mask, uint size);
b9672a84 60
c26c6bc2
OZ
61static inline void cli_separator(cli *c)
62{ if (c->last_reply) cli_printf(c, -c->last_reply, ""); };
63
b9672a84
MM
64/* Functions provided to sysdep layer */
65
7d3aab1c
MM
66cli *cli_new(void *);
67void cli_init(void);
68void cli_free(cli *);
69void cli_kick(cli *);
70void cli_written(cli *);
ae80a2de 71void cli_echo(uint class, byte *msg);
7d3aab1c 72
e0a45fb4
OZ
73static inline int cli_access_restricted(void)
74{
75 if (this_cli && this_cli->restricted)
76 return (cli_printf(this_cli, 8007, "Access denied"), 1);
77 else
78 return 0;
79}
80
b9672a84 81/* Functions provided by sysdep layer */
7d3aab1c 82
6baef17e 83void cli_write_trigger(cli *);
7d3aab1c
MM
84int cli_get_command(cli *);
85
86#endif