From: Maria Matejka Date: Fri, 29 Nov 2024 10:26:18 +0000 (+0100) Subject: Merge commit '82d57fb7' into thread-merge-2.16 X-Git-Tag: v3.0.0~46 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=1b0ffdf80e6d1aa93d235d847622dd406c3108de;p=thirdparty%2Fbird.git Merge commit '82d57fb7' into thread-merge-2.16 --- 1b0ffdf80e6d1aa93d235d847622dd406c3108de diff --cc conf/confbase.Y index 3e88b832b,5b00937f2..0eafdb148 --- a/conf/confbase.Y +++ b/conf/confbase.Y @@@ -100,9 -96,9 +100,10 @@@ CF_DECL struct f_prefix px; struct proto_spec ps; struct channel_limit cl; - struct timeformat *tf; + struct timeformat tf; + struct timeformat *tfp; - mpls_label_stack *mls; + struct settle_config settle; + struct adata *ad; const struct adata *bs; struct aggr_item_node *ai; } diff --cc nest/cli.c index dd0ce4079,9573f7700..37f310b0a --- a/nest/cli.c +++ b/nest/cli.c @@@ -304,6 -339,103 +304,36 @@@ cli_kick(cli *c static list cli_log_hooks; static int cli_log_inited; -void -cli_set_log_echo(cli *c, uint mask, uint size) -{ - if (c->ring_buf) - { - mb_free(c->ring_buf); - c->ring_buf = c->ring_end = c->ring_read = c->ring_write = NULL; - rem_node(&c->n); - } - c->log_mask = mask; - if (mask && size) - { - c->ring_buf = mb_alloc(c->pool, size); - c->ring_end = c->ring_buf + size; - c->ring_read = c->ring_write = c->ring_buf; - add_tail(&cli_log_hooks, &c->n); - c->log_threshold = size / 8; - } - c->ring_overflow = 0; -} - -void -cli_echo(uint class, byte *msg) -{ - unsigned len, free, i, l; - cli *c; - byte *m; - - if (!cli_log_inited || EMPTY_LIST(cli_log_hooks)) - return; - len = strlen(msg) + 1; - WALK_LIST(c, cli_log_hooks) - { - if (!(c->log_mask & (1 << class))) - continue; - if (c->ring_read <= c->ring_write) - free = (c->ring_end - c->ring_buf) - (c->ring_write - c->ring_read + 1); - else - free = c->ring_read - c->ring_write - 1; - if ((len > free) || - (free < c->log_threshold && class < (unsigned) L_INFO[0])) - { - c->ring_overflow++; - continue; - } - if (c->ring_read == c->ring_write) - ev_schedule(c->event); - m = msg; - l = len; - while (l) - { - if (c->ring_read <= c->ring_write) - i = c->ring_end - c->ring_write; - else - i = c->ring_read - c->ring_write; - if (i > l) - i = l; - memcpy(c->ring_write, m, i); - m += i; - l -= i; - c->ring_write += i; - if (c->ring_write == c->ring_end) - c->ring_write = c->ring_buf; - } - } -} - + /* 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 */ extern cli *cmd_reconfig_stored_cli; diff --cc nest/cli.h index c3dfc3eb5,e48216c2e..e9b59c515 --- a/nest/cli.h +++ b/nest/cli.h @@@ -10,8 -10,8 +10,9 @@@ #define _BIRD_CLI_H_ #include "lib/resource.h" +#include "lib/lists.h" #include "lib/event.h" + #include "lib/timer.h" #include "lib/tlists.h" #include "conf/conf.h" @@@ -36,12 -36,16 +37,13 @@@ typedef struct cli struct cli_out *tx_buf, *tx_pos, *tx_write; event *event; void (*cont)(struct cli *c); - void (*cleanup)(struct cli *c); + void (*cleanup)(struct cli *c); /* The CLI has closed prematurely */ void *rover; /* Private to continuation routine */ + struct config *main_config; /* Main config currently in use */ int last_reply; 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 *show_pool; /* Pool used during route show */ - byte *ring_buf; /* Ring buffer for asynchronous messages */ - byte *ring_end, *ring_read, *ring_write; /* Pointers to the ring buffer */ - uint ring_overflow; /* Counter of ring overflows */ uint log_mask; /* Mask of allowed message levels */ uint log_threshold; /* When free < log_threshold, store only important messages */ uint async_msg_size; /* Total size of async messages queued in tx_buf */ @@@ -73,6 -77,8 +75,7 @@@ extern struct cli *this_cli; /* Used d void cli_printf(cli *, int, char *, ...); #define cli_msg(x...) cli_printf(this_cli, x) -void cli_set_log_echo(cli *, uint mask, uint size); + void cli_set_timeformat(cli *c, const struct timeformat tf); static inline void cli_separator(cli *c) { if (c->last_reply) cli_printf(c, -c->last_reply, ""); }; diff --cc nest/cmds.c index b55d2c235,09996c46c..a596773c9 --- a/nest/cmds.c +++ b/nest/cmds.c @@@ -22,20 -22,17 +22,19 @@@ extern int configuring void cmd_show_status(void) { - byte tim[TM_DATETIME_BUFFER_SIZE]; - - struct timeformat *tf_base = this_cli->tf ?: &config->tf_base; + rcu_read_lock(); + 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); - tm_format_time(tim, tf_base, current_time()); - cli_msg(-1011, "Router ID is %R", config->router_id); - cli_msg(-1011, "Hostname is %s", config->hostname); + tm_format_time(tim, tf, current_time()); + cli_msg(-1011, "Router ID is %R", gr->router_id); + cli_msg(-1011, "Hostname is %s", gr->hostname); cli_msg(-1011, "Current server time is %s", tim); - tm_format_time(tim, tf_base, boot_time); + tm_format_time(tim, tf, boot_time); cli_msg(-1011, "Last reboot on %s", tim); - tm_format_time(tim, tf_base, config->load_time); + tm_format_time(tim, tf, gr->load_time); cli_msg(-1011, "Last reconfiguration on %s", tim); graceful_restart_show_status(); diff --cc nest/config.Y index 4eedca529,3fcf3068e..c0b468e4b --- a/nest/config.Y +++ b/nest/config.Y @@@ -461,20 -404,17 +467,16 @@@ timeformat_which ; timeformat_spec: - timeformat_which TEXT { *$1 = (struct timeformat){$2, NULL, 0}; } - | timeformat_which TEXT expr TEXT { *$1 = (struct timeformat){$2, $4, (s64) $3 S_}; } - | timeformat_which ISO SHORT { *$1 = TM_ISO_SHORT_S; } - | timeformat_which ISO SHORT MS { *$1 = TM_ISO_SHORT_MS; } - | timeformat_which ISO SHORT US { *$1 = TM_ISO_SHORT_US; } - | timeformat_which ISO LONG { *$1 = TM_ISO_LONG_S; } - | timeformat_which ISO LONG MS { *$1 = TM_ISO_LONG_MS; } - | timeformat_which ISO LONG US { *$1 = TM_ISO_LONG_US; } - ; - - timeformat_base: - TIMEFORMAT timeformat_spec ';' + TEXT { $$ = (struct timeformat){$1, NULL, 0}; } + | TEXT expr TEXT { $$ = (struct timeformat){$1, $3, (s64) $2 S_}; } + | ISO SHORT { $$ = TM_ISO_SHORT_S; } + | ISO SHORT MS { $$ = TM_ISO_SHORT_MS; } + | ISO SHORT US { $$ = TM_ISO_SHORT_US; } + | ISO LONG { $$ = TM_ISO_LONG_S; } + | ISO LONG MS { $$ = TM_ISO_LONG_MS; } + | ISO LONG US { $$ = TM_ISO_LONG_US; } ; - /* Interface patterns */ iface_patt_node_init: diff --cc nest/proto.c index 42d479d0a,a6c5a0c11..ea521ceb5 --- a/nest/proto.c +++ b/nest/proto.c @@@ -2608,10 -2135,7 +2608,10 @@@ proto_cmd_show(struct proto *p, uintptr buf[0] = 0; if (p->proto->get_status) p->proto->get_status(p, buf); - tm_format_time(tbuf, (this_cli->tf ?: &config->tf_proto), p->last_state_change); + + 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(); cli_msg(-1002, "%-10s %-10s %-10s %-6s %-12s %s", p->name, p->proto->name, diff --cc nest/rt-show.c index 84d6dcb0a,0ecc8637b..e4149e66e --- a/nest/rt-show.c +++ b/nest/rt-show.c @@@ -41,19 -42,14 +41,19 @@@ rt_show_rte(struct cli *c, byte *ia, rt { byte from[IPA_MAX_TEXT_LENGTH+8]; byte tm[TM_DATETIME_BUFFER_SIZE], info[256]; - rta *a = e->attrs; - int sync_error = d->kernel ? krt_get_sync_error(d->kernel, e) : 0; - void (*get_route_info)(struct rte *, byte *buf); - struct nexthop *nh; - - tm_format_time(tm, (c->tf ?: &config->tf_route), e->lastmod); - if (ipa_nonzero(a->from) && !ipa_equal(a->from, a->nh.gw)) - bsprintf(from, " from %I", a->from); + ea_list *a = e->attrs; + int sync_error = d->tab->kernel ? krt_get_sync_error(d->tab->kernel, e) : 0; + void (*get_route_info)(const rte *, byte *buf); + const eattr *nhea = net_type_match(e->net, NB_DEST) ? + ea_find(a, &ea_gen_nexthop) : NULL; + struct nexthop_adata *nhad = nhea ? (struct nexthop_adata *) nhea->u.ptr : NULL; + 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; + - 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); + if (ipa_nonzero(a_from) && (!nhad || !ipa_equal(a_from, nhad->nh.gw))) + bsprintf(from, " from %I", a_from); else from[0] = 0; diff --cc proto/bfd/bfd.c index 2cb72c540,cde7f11b5..c85a1b630 --- a/proto/bfd/bfd.c +++ b/proto/bfd/bfd.c @@@ -1245,11 -1205,7 +1245,11 @@@ bfd_show_session(struct bfd_session *s byte dbuf[BFD_DIAG_BUFFER_SIZE]; byte tbuf[TM_DATETIME_BUFFER_SIZE]; - tm_format_time(tbuf, (this_cli->tf ?: &config->tf_proto), s->last_state_change); + + rcu_read_lock(); + 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(); if (!details) { diff --cc sysdep/unix/config.Y index 25eb36ede,f4e70d198..42d78c6f6 --- a/sysdep/unix/config.Y +++ b/sysdep/unix/config.Y @@@ -18,14 -18,12 +18,13 @@@ static struct cli_config *this_cli_conf CF_DECLS -CF_KEYWORDS(LOG, SYSLOG, NAME, STDERR, UDP, PORT, CLI) -CF_KEYWORDS(ALL, DEBUG, TRACE, INFO, REMOTE, WARNING, ERROR, AUTH, FATAL, BUG) -CF_KEYWORDS(DEBUG, LATENCY, LIMIT, WATCHDOG, WARNING, TIMEOUT, THREADS) +CF_KEYWORDS(LOG, SYSLOG, ALL, DEBUG, TRACE, INFO, REMOTE, WARNING, ERROR, AUTH, FATAL, BUG, STDERR, SOFT, UDP, PORT, CLI) +CF_KEYWORDS(NAME, CONFIRM, UNDO, CHECK, TIMEOUT, DEBUG, LATENCY, LIMIT, WATCHDOG, WARNING, STATUS) +CF_KEYWORDS(PING, WAKEUP, SOCKETS, SCHEDULING, EVENTS, TIMERS, ALLOCATOR) +CF_KEYWORDS(GRACEFUL, RESTART, FIXED) -%type log_mask log_mask_list log_cat cfg_timeout +%type log_mask log_mask_list log_cat cfg_timeout debug_unix latency_debug_mask latency_debug_flag latency_debug_list %type cfg_name - %type timeformat_which %type syslog_name CF_GRAMMAR