0
0
mirror of https://gitlab.nic.cz/labs/bird.git synced 2024-12-22 09:41:54 +00:00

Merge commit '82d57fb7' into thread-merge-2.16

This commit is contained in:
Maria Matejka 2024-11-29 11:26:18 +01:00
commit 1b0ffdf80e
11 changed files with 72 additions and 20 deletions

View File

@ -100,7 +100,8 @@ CF_DECLS
struct f_prefix px; struct f_prefix px;
struct proto_spec ps; struct proto_spec ps;
struct channel_limit cl; struct channel_limit cl;
struct timeformat *tf; struct timeformat tf;
struct timeformat *tfp;
struct settle_config settle; struct settle_config settle;
struct adata *ad; struct adata *ad;
const struct adata *bs; const struct adata *bs;

View File

@ -1489,6 +1489,13 @@ This argument can be omitted if there exists only a single instance.
pipe protocol, both directions are always reloaded together (<cf/in/ or pipe protocol, both directions are always reloaded together (<cf/in/ or
<cf/out/ options are ignored in that case). <cf/out/ options are ignored in that case).
<tag><label id="cli-timeformat">timeformat "<m/format1/" [<m/limit/ "<m/format2/"]</tag>
Override format of date/time used by BIRD in this CLI session.
Meaning of "<m/format1/", <m/limit/, and "<m/format2/" is the same as in the
<ref id="opt-timeformat" name="timeformat"> configuration option. Also, the
same <cf/iso .../ shorthands may be used.
<tag><label id="cli-down">down</tag> <tag><label id="cli-down">down</tag>
Shut BIRD down. Shut BIRD down.

View File

@ -77,3 +77,4 @@ Reply codes of BIRD command-line interface
9000 Command too long 9000 Command too long
9001 Parse error 9001 Parse error
9002 Invalid symbol type 9002 Invalid symbol type
9003 Argument too long

View File

@ -304,6 +304,36 @@ cli_kick(cli *c)
static list cli_log_hooks; static list cli_log_hooks;
static int cli_log_inited; static int cli_log_inited;
/* 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, "");
}
/* Hack for scheduled undo notification */ /* Hack for scheduled undo notification */
extern cli *cmd_reconfig_stored_cli; extern cli *cmd_reconfig_stored_cli;

View File

@ -12,6 +12,7 @@
#include "lib/resource.h" #include "lib/resource.h"
#include "lib/lists.h" #include "lib/lists.h"
#include "lib/event.h" #include "lib/event.h"
#include "lib/timer.h"
#include "lib/tlists.h" #include "lib/tlists.h"
#include "conf/conf.h" #include "conf/conf.h"
@ -41,6 +42,7 @@ typedef struct cli {
struct config *main_config; /* Main config currently in use */ struct config *main_config; /* Main config currently in use */
int last_reply; int last_reply;
int restricted; /* CLI is restricted to read-only commands */ int restricted; /* CLI is restricted to read-only commands */
struct timeformat *tf; /* Time format override */
struct linpool *parser_pool; /* Pool used during parsing */ struct linpool *parser_pool; /* Pool used during parsing */
uint log_mask; /* Mask of allowed message levels */ uint log_mask; /* Mask of allowed message levels */
uint log_threshold; /* When free < log_threshold, store only important messages */ uint log_threshold; /* When free < log_threshold, store only important messages */
@ -73,6 +75,7 @@ extern struct cli *this_cli; /* Used during parsing */
void cli_printf(cli *, int, char *, ...); void cli_printf(cli *, int, char *, ...);
#define cli_msg(x...) cli_printf(this_cli, x) #define cli_msg(x...) cli_printf(this_cli, x)
void cli_set_timeformat(cli *c, const struct timeformat tf);
static inline void cli_separator(cli *c) static inline void cli_separator(cli *c)
{ if (c->last_reply) cli_printf(c, -c->last_reply, ""); }; { if (c->last_reply) cli_printf(c, -c->last_reply, ""); };

View File

@ -22,11 +22,10 @@ extern int configuring;
void void
cmd_show_status(void) cmd_show_status(void)
{ {
byte tim[TM_DATETIME_BUFFER_SIZE];
rcu_read_lock(); rcu_read_lock();
struct global_runtime *gr = atomic_load_explicit(&global_runtime, memory_order_acquire); struct global_runtime *gr = atomic_load_explicit(&global_runtime, memory_order_acquire);
struct timeformat *tf = &gr->tf_base; struct timeformat *tf = this_cli->tf ?: &gr->tf_base;
byte tim[TM_DATETIME_BUFFER_SIZE];
cli_msg(-1000, "BIRD " BIRD_VERSION); cli_msg(-1000, "BIRD " BIRD_VERSION);
tm_format_time(tim, tf, current_time()); tm_format_time(tim, tf, current_time());

View File

@ -191,6 +191,8 @@ CF_ENUM(T_ENUM_MPLS_POLICY, MPLS_POLICY_, NONE, STATIC, PREFIX, AGGREGATE, VRF)
%type <ps> proto_patt proto_patt2 %type <ps> proto_patt proto_patt2
%type <cc> channel_start proto_channel %type <cc> channel_start proto_channel
%type <cl> limit_spec %type <cl> limit_spec
%type <tf> timeformat_spec
%type <tfp> timeformat_which
%type <net> r_args_for_val %type <net> r_args_for_val
%type <net_ptr> r_args_for %type <net_ptr> r_args_for
%type <t> channel_sym %type <t> channel_sym
@ -453,6 +455,10 @@ debug_default:
conf: timeformat_base ; conf: timeformat_base ;
timeformat_base:
TIMEFORMAT timeformat_which timeformat_spec ';' { *$2 = $3; }
;
timeformat_which: timeformat_which:
ROUTE { $$ = &new_config->tf_route; } ROUTE { $$ = &new_config->tf_route; }
| PROTOCOL { $$ = &new_config->tf_proto; } | PROTOCOL { $$ = &new_config->tf_proto; }
@ -461,18 +467,14 @@ timeformat_which:
; ;
timeformat_spec: timeformat_spec:
timeformat_which TEXT { *$1 = (struct timeformat){$2, NULL, 0}; } TEXT { $$ = (struct timeformat){$1, NULL, 0}; }
| timeformat_which TEXT expr TEXT { *$1 = (struct timeformat){$2, $4, (s64) $3 S_}; } | TEXT expr TEXT { $$ = (struct timeformat){$1, $3, (s64) $2 S_}; }
| timeformat_which ISO SHORT { *$1 = TM_ISO_SHORT_S; } | ISO SHORT { $$ = TM_ISO_SHORT_S; }
| timeformat_which ISO SHORT MS { *$1 = TM_ISO_SHORT_MS; } | ISO SHORT MS { $$ = TM_ISO_SHORT_MS; }
| timeformat_which ISO SHORT US { *$1 = TM_ISO_SHORT_US; } | ISO SHORT US { $$ = TM_ISO_SHORT_US; }
| timeformat_which ISO LONG { *$1 = TM_ISO_LONG_S; } | ISO LONG { $$ = TM_ISO_LONG_S; }
| timeformat_which ISO LONG MS { *$1 = TM_ISO_LONG_MS; } | ISO LONG MS { $$ = TM_ISO_LONG_MS; }
| timeformat_which ISO LONG US { *$1 = TM_ISO_LONG_US; } | ISO LONG US { $$ = TM_ISO_LONG_US; }
;
timeformat_base:
TIMEFORMAT timeformat_spec ';'
; ;
/* Interface patterns */ /* Interface patterns */
@ -1004,6 +1006,16 @@ CF_CLI(MRTDUMP, proto_patt mrtdump_mask, (<protocol> | \"<pattern>\" | all) (all
CF_CLI(RESTRICT,,,[[Restrict current CLI session to safe commands]]) CF_CLI(RESTRICT,,,[[Restrict current CLI session to safe commands]])
{ this_cli->restricted = 1; cli_msg(16, "Access restricted"); } ; { this_cli->restricted = 1; cli_msg(16, "Access restricted"); } ;
CF_CLI_HELP(TIMEFORMAT, ..., [[Set time format for this CLI session]])
CF_CLI(TIMEFORMAT, timeformat_spec, \"<format1>\" [limit \"format2\"] | iso (short | long) [ ms | us ], [[Set time format for this CLI session]])
{ cli_set_timeformat(this_cli, $2); } ;
CF_CLI_OPT(TIMEFORMAT ISO)
CF_CLI_OPT(TIMEFORMAT SHORT)
CF_CLI_OPT(TIMEFORMAT LONG)
CF_CLI_OPT(TIMEFORMAT MS)
CF_CLI_OPT(TIMEFORMAT US)
proto_patt: proto_patt:
CF_SYM_KNOWN { cf_assert_symbol($1, SYM_PROTO); $$.ptr = $1; $$.patt = 0; } CF_SYM_KNOWN { cf_assert_symbol($1, SYM_PROTO); $$.ptr = $1; $$.patt = 0; }
| ALL { $$.ptr = NULL; $$.patt = 1; } | ALL { $$.ptr = NULL; $$.patt = 1; }

View File

@ -2610,7 +2610,7 @@ proto_cmd_show(struct proto *p, uintptr_t verbose, int cnt)
p->proto->get_status(p, buf); p->proto->get_status(p, buf);
rcu_read_lock(); rcu_read_lock();
tm_format_time(tbuf, &atomic_load_explicit(&global_runtime, memory_order_acquire)->tf_proto, p->last_state_change); tm_format_time(tbuf, this_cli->tf ?: &atomic_load_explicit(&global_runtime, memory_order_acquire)->tf_proto, p->last_state_change);
rcu_read_unlock(); rcu_read_unlock();
cli_msg(-1002, "%-10s %-10s %-10s %-6s %-12s %s", cli_msg(-1002, "%-10s %-10s %-10s %-6s %-12s %s",
p->name, p->name,

View File

@ -50,7 +50,7 @@ rt_show_rte(struct cli *c, byte *ia, rte *e, struct rt_show_data *d, int primary
int dest = nhad ? (NEXTHOP_IS_REACHABLE(nhad) ? RTD_UNICAST : nhad->dest) : RTD_NONE; int dest = nhad ? (NEXTHOP_IS_REACHABLE(nhad) ? RTD_UNICAST : nhad->dest) : RTD_NONE;
int flowspec_valid = net_is_flow(e->net) ? rt_get_flowspec_valid(e) : FLOWSPEC_UNKNOWN; int flowspec_valid = net_is_flow(e->net) ? rt_get_flowspec_valid(e) : FLOWSPEC_UNKNOWN;
tm_format_time(tm, &d->tf_route, e->lastmod); tm_format_time(tm, c->tf ?: &d->tf_route, e->lastmod);
ip_addr a_from = ea_get_ip(a, &ea_gen_from, IPA_NONE); ip_addr a_from = ea_get_ip(a, &ea_gen_from, IPA_NONE);
if (ipa_nonzero(a_from) && (!nhad || !ipa_equal(a_from, nhad->nh.gw))) if (ipa_nonzero(a_from) && (!nhad || !ipa_equal(a_from, nhad->nh.gw)))
bsprintf(from, " from %I", a_from); bsprintf(from, " from %I", a_from);

View File

@ -1248,7 +1248,7 @@ bfd_show_session(struct bfd_session *s, int details)
rcu_read_lock(); rcu_read_lock();
struct global_runtime *gr = atomic_load_explicit(&global_runtime, memory_order_relaxed); struct global_runtime *gr = atomic_load_explicit(&global_runtime, memory_order_relaxed);
tm_format_time(tbuf, &gr->tf_proto, s->last_state_change); tm_format_time(tbuf, this_cli->tf ?: &gr->tf_proto, s->last_state_change);
rcu_read_unlock(); rcu_read_unlock();
if (!details) if (!details)

View File

@ -25,7 +25,6 @@ CF_KEYWORDS(GRACEFUL, RESTART, FIXED)
%type <i> log_mask log_mask_list log_cat cfg_timeout debug_unix latency_debug_mask latency_debug_flag latency_debug_list %type <i> log_mask log_mask_list log_cat cfg_timeout debug_unix latency_debug_mask latency_debug_flag latency_debug_list
%type <t> cfg_name %type <t> cfg_name
%type <tf> timeformat_which
%type <t> syslog_name %type <t> syslog_name
CF_GRAMMAR CF_GRAMMAR