From 87a02489f3880689a4e2ad72b0b981649dad2154 Mon Sep 17 00:00:00 2001 From: Alexander Zubkov Date: Sat, 8 Jan 2022 18:31:56 +0100 Subject: IO: Support nonlocal bind in socket interface Add option to socket interface for nonlocal binding, i.e. binding to an IP address that is not present on interfaces. This behaviour is enabled when SKF_FREEBIND socket flag is set. For Linux systems, it is implemented by IP_FREEBIND socket flag. Minor changes done by commiter. --- sysdep/unix/io.c | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'sysdep/unix/io.c') diff --git a/sysdep/unix/io.c b/sysdep/unix/io.c index 3d67d0a7..4fd77453 100644 --- a/sysdep/unix/io.c +++ b/sysdep/unix/io.c @@ -1436,6 +1436,10 @@ sk_open(sock *s) if (sk_set_high_port(s) < 0) log(L_WARN "Socket error: %s%#m", s->err); + if (s->flags & SKF_FREEBIND) + if (sk_set_freebind(s) < 0) + log(L_WARN "Socket error: %s%#m", s->err); + sockaddr_fill(&sa, s->af, bind_addr, s->iface, bind_port); if (bind(fd, &sa.sa, SA_LEN(sa)) < 0) ERR2("bind"); -- cgit v1.2.3 From 48bf1322aa141ca6259b26b37551402758cff0cc Mon Sep 17 00:00:00 2001 From: Maria Matejka Date: Wed, 2 Mar 2022 10:35:21 +0100 Subject: Introducing an universal temporary linpool flushed after every task --- lib/event.c | 2 ++ lib/mempool.c | 2 ++ lib/resource.c | 1 + lib/resource.h | 9 +++++++++ lib/timer.c | 1 + proto/bfd/io.c | 2 ++ sysdep/unix/io.c | 23 ++++++++++++++++++++--- test/birdtest.c | 4 ++++ test/bt-utils.c | 1 - 9 files changed, 41 insertions(+), 4 deletions(-) (limited to 'sysdep/unix/io.c') diff --git a/lib/event.c b/lib/event.c index 273447e0..33dc00b0 100644 --- a/lib/event.c +++ b/lib/event.c @@ -157,6 +157,7 @@ ev_run_list(event_list *l) io_log_event(e->hook, e->data); ev_run(e); + tmp_flush(); } return !EMPTY_LIST(*l); @@ -184,6 +185,7 @@ ev_run_list_limited(event_list *l, uint limit) io_log_event(e->hook, e->data); ev_run(e); + tmp_flush(); limit--; } diff --git a/lib/mempool.c b/lib/mempool.c index 90d7c774..169826d4 100644 --- a/lib/mempool.c +++ b/lib/mempool.c @@ -42,6 +42,8 @@ struct linpool { uint chunk_size, threshold, total, total_large; }; +_Thread_local linpool *tmp_linpool; + static void lp_free(resource *); static void lp_dump(resource *); static resource *lp_lookup(resource *, unsigned long); diff --git a/lib/resource.c b/lib/resource.c index 5d4c7780..5636872c 100644 --- a/lib/resource.c +++ b/lib/resource.c @@ -273,6 +273,7 @@ resource_init(void) root_pool.r.class = &pool_class; root_pool.name = "Root"; init_list(&root_pool.inside); + tmp_init(&root_pool); } /** diff --git a/lib/resource.h b/lib/resource.h index 9ec41ed8..0e4c44d8 100644 --- a/lib/resource.h +++ b/lib/resource.h @@ -79,6 +79,15 @@ void lp_flush(linpool *); /* Free everything, but leave linpool */ void lp_save(linpool *m, lp_state *p); /* Save state */ void lp_restore(linpool *m, lp_state *p); /* Restore state */ +extern _Thread_local linpool *tmp_linpool; /* Temporary linpool autoflushed regularily */ + +#define tmp_alloc(sz) lp_alloc(tmp_linpool, sz) +#define tmp_allocu(sz) lp_allocu(tmp_linpool, sz) +#define tmp_allocz(sz) lp_allocz(tmp_linpool, sz) + +#define tmp_init(p) tmp_linpool = lp_new_default(p) +#define tmp_flush() lp_flush(tmp_linpool) + extern const int lp_chunk_size; #define LP_GAS 1024 #define LP_GOOD_SIZE(x) (((x + LP_GAS - 1) & (~(LP_GAS - 1))) - lp_chunk_size) diff --git a/lib/timer.c b/lib/timer.c index 381163d0..c47e0bbc 100644 --- a/lib/timer.c +++ b/lib/timer.c @@ -233,6 +233,7 @@ timers_fire(struct timeloop *loop) io_log_event(t->hook, t->data); t->hook(t); + tmp_flush(); } } diff --git a/proto/bfd/io.c b/proto/bfd/io.c index 1cd9365a..e696cc89 100644 --- a/proto/bfd/io.c +++ b/proto/bfd/io.c @@ -482,6 +482,8 @@ birdloop_main(void *arg) birdloop_set_current(loop); + tmp_init(loop->pool); + pthread_mutex_lock(&loop->mutex); while (1) { diff --git a/sysdep/unix/io.c b/sysdep/unix/io.c index 4fd77453..8a116789 100644 --- a/sysdep/unix/io.c +++ b/sysdep/unix/io.c @@ -1854,8 +1854,8 @@ sk_read_ssh(sock *s) /* sk_read() and sk_write() are called from BFD's event loop */ -int -sk_read(sock *s, int revents) +static inline int +sk_read_noflush(sock *s, int revents) { switch (s->type) { @@ -1918,7 +1918,15 @@ sk_read(sock *s, int revents) } int -sk_write(sock *s) +sk_read(sock *s, int revents) +{ + int e = sk_read_noflush(s, revents); + tmp_flush(); + return e; +} + +static inline int +sk_write_noflush(sock *s) { switch (s->type) { @@ -1966,6 +1974,14 @@ sk_write(sock *s) } } +int +sk_write(sock *s) +{ + int e = sk_write_noflush(s); + tmp_flush(); + return e; +} + int sk_is_ipv4(sock *s) { return s->af == AF_INET; } @@ -1984,6 +2000,7 @@ sk_err(sock *s, int revents) } s->err_hook(s, se); + tmp_flush(); } void diff --git a/test/birdtest.c b/test/birdtest.c index 86a8882f..10d6d6de 100644 --- a/test/birdtest.c +++ b/test/birdtest.c @@ -119,6 +119,8 @@ bt_init(int argc, char *argv[]) clock_gettime(CLOCK_MONOTONIC, &bt_begin); bt_suite_case_begin = bt_suite_begin = bt_begin; + resource_init(); + return; usage: @@ -172,6 +174,8 @@ int bt_run_test_fn(int (*fn)(const void *), const void *fn_arg, int timeout) if (!bt_suite_result) result = 0; + tmp_flush(); + return result; } diff --git a/test/bt-utils.c b/test/bt-utils.c index cbca3a6b..2a7799c3 100644 --- a/test/bt-utils.c +++ b/test/bt-utils.c @@ -60,7 +60,6 @@ bt_bird_init(void) log_init_debug(""); log_switch(bt_verbose != 0, NULL, NULL); - resource_init(); olock_init(); timer_init(); io_init(); -- cgit v1.2.3 From f39e9aa20363eccc38289958f23c789d037c269b Mon Sep 17 00:00:00 2001 From: Ondrej Zajicek Date: Sat, 4 Jun 2022 17:54:08 +0200 Subject: IO: Improve resolution of latency debugging messages --- sysdep/unix/io.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'sysdep/unix/io.c') diff --git a/sysdep/unix/io.c b/sysdep/unix/io.c index 4fd77453..17dc05a3 100644 --- a/sysdep/unix/io.c +++ b/sysdep/unix/io.c @@ -2046,8 +2046,8 @@ io_update_time(void) event_open->duration = last_time - event_open->timestamp; if (event_open->duration > config->latency_limit) - log(L_WARN "Event 0x%p 0x%p took %d ms", - event_open->hook, event_open->data, (int) (event_open->duration TO_MS)); + log(L_WARN "Event 0x%p 0x%p took %u.%03u ms", + event_open->hook, event_open->data, (uint) (event_open->duration TO_MS), (uint) (event_open->duration % 1000)); event_open = NULL; } @@ -2151,8 +2151,8 @@ watchdog_stop(void) btime duration = last_time - loop_time; if (duration > config->watchdog_warning) - log(L_WARN "I/O loop cycle took %d ms for %d events", - (int) (duration TO_MS), event_log_num); + log(L_WARN "I/O loop cycle took %u.%03u ms for %d events", + (uint) (duration TO_MS), (uint) (duration % 1000), event_log_num); } -- cgit v1.2.3