summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorpamela <pamela@cvs.openbsd.org>2019-03-02 03:40:46 +0000
committerpamela <pamela@cvs.openbsd.org>2019-03-02 03:40:46 +0000
commit390d205928098d6a576c2f13570a206055c17f2e (patch)
tree73ed3d2bba7770f686896662b09651cb6717153d
parent2770391dce2656283cc30762ce43bdc499ac6d1f (diff)
Introduce the IMSG_DATA_SIZE() macro to replace recurring math on imsg.hdr.len to shorten and simplify code.
OK florian@
-rw-r--r--usr.sbin/rad/control.c12
-rw-r--r--usr.sbin/rad/engine.c20
-rw-r--r--usr.sbin/rad/frontend.c14
-rw-r--r--usr.sbin/rad/rad.h4
4 files changed, 25 insertions, 25 deletions
diff --git a/usr.sbin/rad/control.c b/usr.sbin/rad/control.c
index 65d69f97a72..8232ca96c16 100644
--- a/usr.sbin/rad/control.c
+++ b/usr.sbin/rad/control.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: control.c,v 1.4 2018/08/04 09:37:17 florian Exp $ */
+/* $OpenBSD: control.c,v 1.5 2019/03/02 03:40:45 pamela Exp $ */
/*
* Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org>
@@ -240,16 +240,14 @@ control_dispatch_imsg(int fd, short event, void *bula)
frontend_imsg_compose_main(imsg.hdr.type, 0, NULL, 0);
break;
case IMSG_CTL_LOG_VERBOSE:
- if (imsg.hdr.len != IMSG_HEADER_SIZE +
- sizeof(verbose))
+ if (IMSG_DATA_SIZE(imsg) != sizeof(verbose))
break;
/* Forward to all other processes. */
frontend_imsg_compose_main(imsg.hdr.type, imsg.hdr.pid,
- imsg.data, imsg.hdr.len - IMSG_HEADER_SIZE);
+ imsg.data, IMSG_DATA_SIZE(imsg));
frontend_imsg_compose_engine(imsg.hdr.type,
- imsg.hdr.pid, imsg.data,
- imsg.hdr.len - IMSG_HEADER_SIZE);
+ imsg.hdr.pid, imsg.data, IMSG_DATA_SIZE(imsg));
memcpy(&verbose, imsg.data, sizeof(verbose));
log_setverbose(verbose);
@@ -274,5 +272,5 @@ control_imsg_relay(struct imsg *imsg)
return (0);
return (imsg_compose_event(&c->iev, imsg->hdr.type, 0, imsg->hdr.pid,
- -1, imsg->data, imsg->hdr.len - IMSG_HEADER_SIZE));
+ -1, imsg->data, IMSG_DATA_SIZE(*imsg)));
}
diff --git a/usr.sbin/rad/engine.c b/usr.sbin/rad/engine.c
index 0b3d58ab790..73284877cee 100644
--- a/usr.sbin/rad/engine.c
+++ b/usr.sbin/rad/engine.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: engine.c,v 1.10 2019/01/29 15:43:33 florian Exp $ */
+/* $OpenBSD: engine.c,v 1.11 2019/03/02 03:40:45 pamela Exp $ */
/*
* Copyright (c) 2018 Florian Obser <florian@openbsd.org>
@@ -211,23 +211,23 @@ engine_dispatch_frontend(int fd, short event, void *bula)
switch (imsg.hdr.type) {
case IMSG_RA_RS:
- if (imsg.hdr.len != IMSG_HEADER_SIZE + sizeof(ra_rs))
- fatal("%s: IMSG_RA_RS wrong length: %d",
- __func__, imsg.hdr.len);
+ if (IMSG_DATA_SIZE(imsg) != sizeof(ra_rs))
+ fatal("%s: IMSG_RA_RS wrong length: %lu",
+ __func__, IMSG_DATA_SIZE(imsg));
memcpy(&ra_rs, imsg.data, sizeof(ra_rs));
parse_ra_rs(&ra_rs);
break;
case IMSG_UPDATE_IF:
- if (imsg.hdr.len != IMSG_HEADER_SIZE + sizeof(if_index))
- fatal("%s: IMSG_UPDATE_IF wrong length: %d",
- __func__, imsg.hdr.len);
+ if (IMSG_DATA_SIZE(imsg) != sizeof(if_index))
+ fatal("%s: IMSG_UPDATE_IF wrong length: %lu",
+ __func__, IMSG_DATA_SIZE(imsg));
memcpy(&if_index, imsg.data, sizeof(if_index));
update_iface(if_index);
break;
case IMSG_REMOVE_IF:
- if (imsg.hdr.len != IMSG_HEADER_SIZE + sizeof(if_index))
- fatal("%s: IMSG_REMOVE_IF wrong length: %d",
- __func__, imsg.hdr.len);
+ if (IMSG_DATA_SIZE(imsg) != sizeof(if_index))
+ fatal("%s: IMSG_REMOVE_IF wrong length: %lu",
+ __func__, IMSG_DATA_SIZE(imsg));
memcpy(&if_index, imsg.data, sizeof(if_index));
remove_iface(if_index);
break;
diff --git a/usr.sbin/rad/frontend.c b/usr.sbin/rad/frontend.c
index 938bb099841..507bbe9ded0 100644
--- a/usr.sbin/rad/frontend.c
+++ b/usr.sbin/rad/frontend.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: frontend.c,v 1.21 2019/03/01 16:35:17 florian Exp $ */
+/* $OpenBSD: frontend.c,v 1.22 2019/03/02 03:40:45 pamela Exp $ */
/*
* Copyright (c) 2018 Florian Obser <florian@openbsd.org>
@@ -506,18 +506,18 @@ frontend_dispatch_engine(int fd, short event, void *bula)
switch (imsg.hdr.type) {
case IMSG_SEND_RA:
- if (imsg.hdr.len != IMSG_HEADER_SIZE + sizeof(send_ra))
- fatal("%s: IMSG_SEND_RA wrong length: %d",
- __func__, imsg.hdr.len);
+ if (IMSG_DATA_SIZE(imsg) != sizeof(send_ra))
+ fatal("%s: IMSG_SEND_RA wrong length: %lu",
+ __func__, IMSG_DATA_SIZE(imsg));
memcpy(&send_ra, imsg.data, sizeof(send_ra));
ra_iface = find_ra_iface_by_id(send_ra.if_index);
if (ra_iface)
ra_output(ra_iface, &send_ra.to);
break;
case IMSG_REMOVE_IF:
- if (imsg.hdr.len != IMSG_HEADER_SIZE + sizeof(if_index))
- fatal("%s: IMSG_REMOVE_IF wrong length: %d",
- __func__, imsg.hdr.len);
+ if (IMSG_DATA_SIZE(imsg) != sizeof(if_index))
+ fatal("%s: IMSG_REMOVE_IF wrong length: %lu",
+ __func__, IMSG_DATA_SIZE(imsg));
memcpy(&if_index, imsg.data, sizeof(if_index));
ra_iface = find_ra_iface_by_id(if_index);
if (ra_iface) {
diff --git a/usr.sbin/rad/rad.h b/usr.sbin/rad/rad.h
index 2390223a1eb..2bbf7c8ed5c 100644
--- a/usr.sbin/rad/rad.h
+++ b/usr.sbin/rad/rad.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: rad.h,v 1.16 2019/01/29 15:43:33 florian Exp $ */
+/* $OpenBSD: rad.h,v 1.17 2019/03/02 03:40:45 pamela Exp $ */
/*
* Copyright (c) 2018 Florian Obser <florian@openbsd.org>
@@ -32,6 +32,8 @@
#define MAX_SEARCH 1025 /* same as MAXDNAME in arpa/nameser.h */
#define DEFAULT_RDNS_LIFETIME 600 * 1.5
+#define IMSG_DATA_SIZE(imsg) ((imsg).hdr.len - IMSG_HEADER_SIZE)
+
enum {
PROC_MAIN,
PROC_ENGINE,