aboutgitcodebugslistschat
diff options
context:
space:
mode:
authorDavid Gibson <david@gibson.dropbear.id.au>2024-01-16 11:50:32 +1100
committerStefano Brivio <sbrivio@redhat.com>2024-01-22 23:35:10 +0100
commit8563e7c870e139baf14ef00b26cdc7db4884246c (patch)
tree766e432a1bfa21c863eef434e0a9a68ffabec856
parent17bbab1c97516048fdcc6c2e6c8efc524e56e71e (diff)
downloadpasst-8563e7c870e139baf14ef00b26cdc7db4884246c.tar
passt-8563e7c870e139baf14ef00b26cdc7db4884246c.tar.gz
passt-8563e7c870e139baf14ef00b26cdc7db4884246c.tar.bz2
passt-8563e7c870e139baf14ef00b26cdc7db4884246c.tar.lz
passt-8563e7c870e139baf14ef00b26cdc7db4884246c.tar.xz
passt-8563e7c870e139baf14ef00b26cdc7db4884246c.tar.zst
passt-8563e7c870e139baf14ef00b26cdc7db4884246c.zip
treewide: Standardise on 'now' for current timestamp variables
In a number of places we pass around a struct timespec representing the (more or less) current time. Sometimes we call it 'now', and sometimes we call it 'ts'. Standardise on the more informative 'now'. Signed-off-by: David Gibson <david@gibson.dropbear.id.au> Signed-off-by: Stefano Brivio <sbrivio@redhat.com>
-rw-r--r--icmp.c12
-rw-r--r--icmp.h2
-rw-r--r--log.c34
-rw-r--r--tcp.c6
-rw-r--r--tcp.h2
-rw-r--r--udp.c16
-rw-r--r--udp.h2
7 files changed, 37 insertions, 37 deletions
diff --git a/icmp.c b/icmp.c
index c82efd0..325dfb0 100644
--- a/icmp.c
+++ b/icmp.c
@@ -275,14 +275,14 @@ fail_sock:
* @c: Execution context
* @v6: Set for IPv6 echo identifier bindings
* @id: Echo identifier, host order
- * @ts: Timestamp from caller
+ * @now: Current timestamp
*/
static void icmp_timer_one(const struct ctx *c, int v6, uint16_t id,
- const struct timespec *ts)
+ const struct timespec *now)
{
struct icmp_id_sock *id_map = &icmp_id_map[v6 ? V6 : V4][id];
- if (ts->tv_sec - id_map->ts <= ICMP_ECHO_TIMEOUT)
+ if (now->tv_sec - id_map->ts <= ICMP_ECHO_TIMEOUT)
return;
bitmap_clear(icmp_act[v6 ? V6 : V4], id);
@@ -296,9 +296,9 @@ static void icmp_timer_one(const struct ctx *c, int v6, uint16_t id,
/**
* icmp_timer() - Scan activity bitmap for identifiers with timed events
* @c: Execution context
- * @ts: Timestamp from caller
+ * @now: Current timestamp
*/
-void icmp_timer(const struct ctx *c, const struct timespec *ts)
+void icmp_timer(const struct ctx *c, const struct timespec *now)
{
long *word, tmp;
unsigned int i;
@@ -310,7 +310,7 @@ v6:
tmp = *word;
while ((n = ffsl(tmp))) {
tmp &= ~(1UL << (n - 1));
- icmp_timer_one(c, v6, i * 8 + n - 1, ts);
+ icmp_timer_one(c, v6, i * 8 + n - 1, now);
}
}
diff --git a/icmp.h b/icmp.h
index 44cc495..1a08594 100644
--- a/icmp.h
+++ b/icmp.h
@@ -15,7 +15,7 @@ void icmpv6_sock_handler(const struct ctx *c, union epoll_ref ref);
int icmp_tap_handler(const struct ctx *c, uint8_t pif, int af,
const void *saddr, const void *daddr,
const struct pool *p, const struct timespec *now);
-void icmp_timer(const struct ctx *c, const struct timespec *ts);
+void icmp_timer(const struct ctx *c, const struct timespec *now);
void icmp_init(void);
/**
diff --git a/log.c b/log.c
index f71d0e2..4a70e29 100644
--- a/log.c
+++ b/log.c
@@ -216,11 +216,11 @@ void logfile_init(const char *name, const char *path, size_t size)
/**
* logfile_rotate_fallocate() - Write header, set log_written after fallocate()
* @fd: Log file descriptor
- * @ts: Current timestamp
+ * @now: Current timestamp
*
* #syscalls lseek ppc64le:_llseek ppc64:_llseek armv6l:_llseek armv7l:_llseek
*/
-static void logfile_rotate_fallocate(int fd, const struct timespec *ts)
+static void logfile_rotate_fallocate(int fd, const struct timespec *now)
{
char buf[BUFSIZ];
const char *nl;
@@ -233,8 +233,8 @@ static void logfile_rotate_fallocate(int fd, const struct timespec *ts)
n = snprintf(buf, BUFSIZ,
"%s - log truncated at %lli.%04lli", log_header,
- (long long int)(ts->tv_sec - log_start),
- (long long int)(ts->tv_nsec / (100L * 1000)));
+ (long long int)(now->tv_sec - log_start),
+ (long long int)(now->tv_nsec / (100L * 1000)));
/* Avoid partial lines by padding the header with spaces */
nl = memchr(buf + n + 1, '\n', BUFSIZ - n - 1);
@@ -253,12 +253,12 @@ static void logfile_rotate_fallocate(int fd, const struct timespec *ts)
/**
* logfile_rotate_move() - Fallback: move recent entries toward start, then cut
* @fd: Log file descriptor
- * @ts: Current timestamp
+ * @now: Current timestamp
*
* #syscalls lseek ppc64le:_llseek ppc64:_llseek armv6l:_llseek armv7l:_llseek
* #syscalls ftruncate
*/
-static void logfile_rotate_move(int fd, const struct timespec *ts)
+static void logfile_rotate_move(int fd, const struct timespec *now)
{
int header_len, write_offset, end, discard, n;
char buf[BUFSIZ];
@@ -266,8 +266,8 @@ static void logfile_rotate_move(int fd, const struct timespec *ts)
header_len = snprintf(buf, BUFSIZ,
"%s - log truncated at %lli.%04lli\n", log_header,
- (long long int)(ts->tv_sec - log_start),
- (long long int)(ts->tv_nsec / (100L * 1000)));
+ (long long int)(now->tv_sec - log_start),
+ (long long int)(now->tv_nsec / (100L * 1000)));
if (lseek(fd, 0, SEEK_SET) == -1)
return;
if (write(fd, buf, header_len) == -1)
@@ -316,7 +316,7 @@ out:
/**
* logfile_rotate() - "Rotate" log file once it's full
* @fd: Log file descriptor
- * @ts: Current timestamp
+ * @now: Current timestamp
*
* Return: 0 on success, negative error code on failure
*
@@ -324,7 +324,7 @@ out:
*
* fallocate() passed as EXTRA_SYSCALL only if FALLOC_FL_COLLAPSE_RANGE is there
*/
-static int logfile_rotate(int fd, const struct timespec *ts)
+static int logfile_rotate(int fd, const struct timespec *now)
{
if (fcntl(fd, F_SETFL, O_RDWR /* Drop O_APPEND: explicit lseek() */))
return -errno;
@@ -332,10 +332,10 @@ static int logfile_rotate(int fd, const struct timespec *ts)
#ifdef FALLOC_FL_COLLAPSE_RANGE
/* Only for Linux >= 3.15, extent-based ext4 or XFS, glibc >= 2.18 */
if (!fallocate(fd, FALLOC_FL_COLLAPSE_RANGE, 0, log_cut_size))
- logfile_rotate_fallocate(fd, ts);
+ logfile_rotate_fallocate(fd, now);
else
#endif
- logfile_rotate_move(fd, ts);
+ logfile_rotate_move(fd, now);
if (fcntl(fd, F_SETFL, O_RDWR | O_APPEND))
return -errno;
@@ -351,16 +351,16 @@ static int logfile_rotate(int fd, const struct timespec *ts)
*/
void logfile_write(int pri, const char *format, va_list ap)
{
- struct timespec ts;
+ struct timespec now;
char buf[BUFSIZ];
int n;
- if (clock_gettime(CLOCK_REALTIME, &ts))
+ if (clock_gettime(CLOCK_REALTIME, &now))
return;
n = snprintf(buf, BUFSIZ, "%lli.%04lli: %s",
- (long long int)(ts.tv_sec - log_start),
- (long long int)(ts.tv_nsec / (100L * 1000)),
+ (long long int)(now.tv_sec - log_start),
+ (long long int)(now.tv_nsec / (100L * 1000)),
logfile_prefix[pri]);
n += vsnprintf(buf + n, BUFSIZ - n, format, ap);
@@ -368,7 +368,7 @@ void logfile_write(int pri, const char *format, va_list ap)
if (format[strlen(format)] != '\n')
n += snprintf(buf + n, BUFSIZ - n, "\n");
- if ((log_written + n >= log_size) && logfile_rotate(log_file, &ts))
+ if ((log_written + n >= log_size) && logfile_rotate(log_file, &now))
return;
if ((n = write(log_file, buf, n)) >= 0)
diff --git a/tcp.c b/tcp.c
index 22c3a0e..dbf5509 100644
--- a/tcp.c
+++ b/tcp.c
@@ -3181,13 +3181,13 @@ static int tcp_port_rebind_outbound(void *arg)
/**
* tcp_timer() - Periodic tasks: port detection, closed connections, pool refill
* @c: Execution context
- * @ts: Unused
+ * @now: Current timestamp
*/
-void tcp_timer(struct ctx *c, const struct timespec *ts)
+void tcp_timer(struct ctx *c, const struct timespec *now)
{
union flow *flow;
- (void)ts;
+ (void)now;
if (c->mode == MODE_PASTA) {
if (c->tcp.fwd_out.mode == FWD_AUTO) {
diff --git a/tcp.h b/tcp.h
index 87a6bf9..b9f546d 100644
--- a/tcp.h
+++ b/tcp.h
@@ -20,7 +20,7 @@ int tcp_tap_handler(struct ctx *c, uint8_t pif, int af,
int tcp_sock_init(const struct ctx *c, sa_family_t af, const void *addr,
const char *ifname, in_port_t port);
int tcp_init(struct ctx *c);
-void tcp_timer(struct ctx *c, const struct timespec *ts);
+void tcp_timer(struct ctx *c, const struct timespec *now);
void tcp_defer_handler(struct ctx *c);
void tcp_update_l2_buf(const unsigned char *eth_d, const unsigned char *eth_s);
diff --git a/udp.c b/udp.c
index 252d353..b5b8f8a 100644
--- a/udp.c
+++ b/udp.c
@@ -1138,10 +1138,10 @@ int udp_init(struct ctx *c)
* @v6: Set for IPv6 connections
* @type: Socket type
* @port: Port number, host order
- * @ts: Timestamp from caller
+ * @now: Current timestamp
*/
static void udp_timer_one(struct ctx *c, int v6, enum udp_act_type type,
- in_port_t port, const struct timespec *ts)
+ in_port_t port, const struct timespec *now)
{
struct udp_splice_port *sp;
struct udp_tap_port *tp;
@@ -1151,7 +1151,7 @@ static void udp_timer_one(struct ctx *c, int v6, enum udp_act_type type,
case UDP_ACT_TAP:
tp = &udp_tap_map[v6 ? V6 : V4][port];
- if (ts->tv_sec - tp->ts > UDP_CONN_TIMEOUT) {
+ if (now->tv_sec - tp->ts > UDP_CONN_TIMEOUT) {
sockp = &tp->sock;
tp->flags = 0;
}
@@ -1160,14 +1160,14 @@ static void udp_timer_one(struct ctx *c, int v6, enum udp_act_type type,
case UDP_ACT_SPLICE_INIT:
sp = &udp_splice_init[v6 ? V6 : V4][port];
- if (ts->tv_sec - sp->ts > UDP_CONN_TIMEOUT)
+ if (now->tv_sec - sp->ts > UDP_CONN_TIMEOUT)
sockp = &sp->sock;
break;
case UDP_ACT_SPLICE_NS:
sp = &udp_splice_ns[v6 ? V6 : V4][port];
- if (ts->tv_sec - sp->ts > UDP_CONN_TIMEOUT)
+ if (now->tv_sec - sp->ts > UDP_CONN_TIMEOUT)
sockp = &sp->sock;
break;
@@ -1247,9 +1247,9 @@ static int udp_port_rebind_outbound(void *arg)
/**
* udp_timer() - Scan activity bitmaps for ports with associated timed events
* @c: Execution context
- * @ts: Timestamp from caller
+ * @now: Current timestamp
*/
-void udp_timer(struct ctx *c, const struct timespec *ts)
+void udp_timer(struct ctx *c, const struct timespec *now)
{
int n, t, v6 = 0;
unsigned int i;
@@ -1279,7 +1279,7 @@ v6:
tmp = *word;
while ((n = ffsl(tmp))) {
tmp &= ~(1UL << (n - 1));
- udp_timer_one(c, v6, t, i * 8 + n - 1, ts);
+ udp_timer_one(c, v6, t, i * 8 + n - 1, now);
}
}
}
diff --git a/udp.h b/udp.h
index 85ebaaa..087e482 100644
--- a/udp.h
+++ b/udp.h
@@ -17,7 +17,7 @@ int udp_tap_handler(struct ctx *c, uint8_t pif, int af,
int udp_sock_init(const struct ctx *c, int ns, sa_family_t af,
const void *addr, const char *ifname, in_port_t port);
int udp_init(struct ctx *c);
-void udp_timer(struct ctx *c, const struct timespec *ts);
+void udp_timer(struct ctx *c, const struct timespec *now);
void udp_update_l2_buf(const unsigned char *eth_d, const unsigned char *eth_s);
/**