summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorpamela <pamela@cvs.openbsd.org>2019-03-02 05:35:00 +0000
committerpamela <pamela@cvs.openbsd.org>2019-03-02 05:35:00 +0000
commit6b21bb991eebc2f22cbebd45a937b16c6b0be3f3 (patch)
tree542f60ce7c74df3df4d21b1e69f2ab952e17fb11
parent390d205928098d6a576c2f13570a206055c17f2e (diff)
Introduce the IMSG_DATA_SIZE() macro to replace recurring math on
imsg.hdr.len to shorten and simplify code. correction and OK florian@
-rw-r--r--sbin/slaacd/control.c18
-rw-r--r--sbin/slaacd/engine.c70
-rw-r--r--sbin/slaacd/slaacd.c40
-rw-r--r--sbin/slaacd/slaacd.h4
4 files changed, 64 insertions, 68 deletions
diff --git a/sbin/slaacd/control.c b/sbin/slaacd/control.c
index 1a0c2b0305a..b52dfd09ac5 100644
--- a/sbin/slaacd/control.c
+++ b/sbin/slaacd/control.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: control.c,v 1.4 2018/08/04 09:36:49 florian Exp $ */
+/* $OpenBSD: control.c,v 1.5 2019/03/02 05:34:59 pamela Exp $ */
/*
* Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org>
@@ -239,16 +239,14 @@ control_dispatch_imsg(int fd, short event, void *bula)
switch (imsg.hdr.type) {
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, 0,
- 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);
@@ -256,14 +254,12 @@ control_dispatch_imsg(int fd, short event, void *bula)
case IMSG_CTL_SHOW_INTERFACE_INFO:
c->iev.ibuf.pid = imsg.hdr.pid;
frontend_imsg_compose_engine(imsg.hdr.type, 0,
- imsg.hdr.pid, imsg.data, imsg.hdr.len -
- IMSG_HEADER_SIZE);
+ imsg.hdr.pid, imsg.data, IMSG_DATA_SIZE(imsg));
break;
case IMSG_CTL_SEND_SOLICITATION:
c->iev.ibuf.pid = imsg.hdr.pid;
frontend_imsg_compose_engine(imsg.hdr.type, 0,
- imsg.hdr.pid, imsg.data, imsg.hdr.len -
- IMSG_HEADER_SIZE);
+ imsg.hdr.pid, imsg.data, IMSG_DATA_SIZE(imsg));
break;
default:
log_debug("%s: error handling imsg %d", __func__,
@@ -285,5 +281,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/sbin/slaacd/engine.c b/sbin/slaacd/engine.c
index a212ffde8db..5ba2c44bbb5 100644
--- a/sbin/slaacd/engine.c
+++ b/sbin/slaacd/engine.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: engine.c,v 1.31 2018/07/27 06:23:08 bket Exp $ */
+/* $OpenBSD: engine.c,v 1.32 2019/03/02 05:34:59 pamela Exp $ */
/*
* Copyright (c) 2017 Florian Obser <florian@openbsd.org>
@@ -435,33 +435,35 @@ engine_dispatch_frontend(int fd, short event, void *bula)
log_setverbose(verbose);
break;
case IMSG_CTL_SHOW_INTERFACE_INFO:
- if (imsg.hdr.len != IMSG_HEADER_SIZE + sizeof(if_index))
+ if (IMSG_DATA_SIZE(imsg) != sizeof(if_index))
fatal("%s: IMSG_CTL_SHOW_INTERFACE_INFO wrong "
- "length: %d", __func__, imsg.hdr.len);
+ "length: %lu", __func__,
+ IMSG_DATA_SIZE(imsg));
memcpy(&if_index, imsg.data, sizeof(if_index));
engine_showinfo_ctl(&imsg, if_index);
break;
#endif /* SMALL */
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_slaacd_iface(if_index);
break;
case IMSG_RA:
- if (imsg.hdr.len != IMSG_HEADER_SIZE + sizeof(ra))
- fatal("%s: IMSG_RA wrong length: %d",
- __func__, imsg.hdr.len);
+ if (IMSG_DATA_SIZE(imsg) != sizeof(ra))
+ fatal("%s: IMSG_RA wrong length: %lu",
+ __func__, IMSG_DATA_SIZE(imsg));
memcpy(&ra, imsg.data, sizeof(ra));
iface = get_slaacd_iface_by_id(ra.if_index);
if (iface != NULL)
parse_ra(iface, &ra);
break;
case IMSG_CTL_SEND_SOLICITATION:
- if (imsg.hdr.len != IMSG_HEADER_SIZE + sizeof(if_index))
+ if (IMSG_DATA_SIZE(imsg) != sizeof(if_index))
fatal("%s: IMSG_CTL_SEND_SOLICITATION wrong "
- "length: %d", __func__, imsg.hdr.len);
+ "length: %lu", __func__,
+ IMSG_DATA_SIZE(imsg));
memcpy(&if_index, imsg.data, sizeof(if_index));
iface = get_slaacd_iface_by_id(if_index);
if (iface == NULL)
@@ -473,10 +475,9 @@ engine_dispatch_frontend(int fd, short event, void *bula)
&iface->if_index, sizeof(iface->if_index));
break;
case IMSG_PROPOSAL_ACK:
- if (imsg.hdr.len != IMSG_HEADER_SIZE +
- sizeof(proposal_ack))
- fatal("%s: IMSG_PROPOSAL_ACK wrong length: %d",
- __func__, imsg.hdr.len);
+ if (IMSG_DATA_SIZE(imsg) != sizeof(proposal_ack))
+ fatal("%s: IMSG_PROPOSAL_ACK wrong length: %lu",
+ __func__, IMSG_DATA_SIZE(imsg));
memcpy(&proposal_ack, imsg.data, sizeof(proposal_ack));
log_debug("%s: IMSG_PROPOSAL_ACK: %lld - %d", __func__,
proposal_ack.id, proposal_ack.pid);
@@ -511,10 +512,9 @@ engine_dispatch_frontend(int fd, short event, void *bula)
break;
case IMSG_DEL_ADDRESS:
- if (imsg.hdr.len != IMSG_HEADER_SIZE +
- sizeof(del_addr))
- fatal("%s: IMSG_DEL_ADDRESS wrong length: %d",
- __func__, imsg.hdr.len);
+ if (IMSG_DATA_SIZE(imsg) != sizeof(del_addr))
+ fatal("%s: IMSG_DEL_ADDRESS wrong length: %lu",
+ __func__, IMSG_DATA_SIZE(imsg));
memcpy(&del_addr, imsg.data, sizeof(del_addr));
iface = get_slaacd_iface_by_id(del_addr.if_index);
if (iface == NULL) {
@@ -534,10 +534,9 @@ engine_dispatch_frontend(int fd, short event, void *bula)
break;
case IMSG_DEL_ROUTE:
- if (imsg.hdr.len != IMSG_HEADER_SIZE +
- sizeof(del_route))
- fatal("%s: IMSG_DEL_ROUTE wrong length: %d",
- __func__, imsg.hdr.len);
+ if (IMSG_DATA_SIZE(imsg) != sizeof(del_route))
+ fatal("%s: IMSG_DEL_ROUTE wrong length: %lu",
+ __func__, IMSG_DATA_SIZE(imsg));
memcpy(&del_route, imsg.data, sizeof(del_route));
iface = get_slaacd_iface_by_id(del_route.if_index);
if (iface == NULL) {
@@ -556,10 +555,9 @@ engine_dispatch_frontend(int fd, short event, void *bula)
}
break;
case IMSG_DUP_ADDRESS:
- if (imsg.hdr.len != IMSG_HEADER_SIZE +
- sizeof(dup_addr))
- fatal("%s: IMSG_DUP_ADDRESS wrong length: %d",
- __func__, imsg.hdr.len);
+ if (IMSG_DATA_SIZE(imsg) != sizeof(dup_addr))
+ fatal("%s: IMSG_DUP_ADDRESS wrong length: %lu",
+ __func__, IMSG_DATA_SIZE(imsg));
memcpy(&dup_addr, imsg.data, sizeof(dup_addr));
iface = get_slaacd_iface_by_id(dup_addr.if_index);
if (iface == NULL) {
@@ -663,10 +661,9 @@ engine_dispatch_main(int fd, short event, void *bula)
fatal("pledge");
break;
case IMSG_UPDATE_IF:
- if (imsg.hdr.len != IMSG_HEADER_SIZE +
- sizeof(imsg_ifinfo))
- fatal("%s: IMSG_UPDATE_IF wrong length: %d",
- __func__, imsg.hdr.len);
+ if (IMSG_DATA_SIZE(imsg) != sizeof(imsg_ifinfo))
+ fatal("%s: IMSG_UPDATE_IF wrong length: %lu",
+ __func__, IMSG_DATA_SIZE(imsg));
memcpy(&imsg_ifinfo, imsg.data, sizeof(imsg_ifinfo));
iface = get_slaacd_iface_by_id(imsg_ifinfo.if_index);
@@ -750,10 +747,9 @@ engine_dispatch_main(int fd, short event, void *bula)
break;
#ifndef SMALL
case IMSG_UPDATE_ADDRESS:
- if (imsg.hdr.len != IMSG_HEADER_SIZE +
- sizeof(imsg_addrinfo))
+ if (IMSG_DATA_SIZE(imsg) != sizeof(imsg_addrinfo))
fatal("%s: IMSG_UPDATE_ADDRESS wrong length: "
- "%d", __func__, imsg.hdr.len);
+ "%lu", __func__, IMSG_DATA_SIZE(imsg));
memcpy(&imsg_addrinfo, imsg.data,
sizeof(imsg_addrinfo));
@@ -809,10 +805,10 @@ engine_dispatch_main(int fd, short event, void *bula)
break;
case IMSG_UPDATE_LINK_STATE:
- if (imsg.hdr.len != IMSG_HEADER_SIZE +
- sizeof(imsg_link_state))
+ if (IMSG_DATA_SIZE(imsg) != sizeof(imsg_link_state))
fatal("%s: IMSG_UPDATE_LINK_STATE wrong "
- "length: %d", __func__, imsg.hdr.len);
+ "length: %lu", __func__,
+ IMSG_DATA_SIZE(imsg));
memcpy(&imsg_link_state, imsg.data,
sizeof(imsg_link_state));
diff --git a/sbin/slaacd/slaacd.c b/sbin/slaacd/slaacd.c
index cd80bfffa60..3a1044596c8 100644
--- a/sbin/slaacd/slaacd.c
+++ b/sbin/slaacd/slaacd.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: slaacd.c,v 1.32 2019/01/22 09:25:29 krw Exp $ */
+/* $OpenBSD: slaacd.c,v 1.33 2019/03/02 05:34:59 pamela Exp $ */
/*
* Copyright (c) 2017 Florian Obser <florian@openbsd.org>
@@ -421,20 +421,19 @@ main_dispatch_frontend(int fd, short event, void *bula)
log_setverbose(verbose);
break;
case IMSG_UPDATE_ADDRESS:
- if (imsg.hdr.len != IMSG_HEADER_SIZE +
- sizeof(imsg_addrinfo))
+ if (IMSG_DATA_SIZE(imsg) != sizeof(imsg_addrinfo))
fatal("%s: IMSG_UPDATE_ADDRESS wrong length: "
- "%d", __func__, imsg.hdr.len);
+ "%lu", __func__, IMSG_DATA_SIZE(imsg));
memcpy(&imsg_addrinfo, imsg.data,
sizeof(imsg_addrinfo));
main_imsg_compose_engine(IMSG_UPDATE_ADDRESS, 0,
&imsg_addrinfo, sizeof(imsg_addrinfo));
break;
case IMSG_UPDATE_LINK_STATE:
- if (imsg.hdr.len != IMSG_HEADER_SIZE +
- sizeof(imsg_link_state))
+ if (IMSG_DATA_SIZE(imsg) != sizeof(imsg_link_state))
fatal("%s: IMSG_UPDATE_LINK_STATE wrong "
- "length: %d", __func__, imsg.hdr.len);
+ "length: %lu", __func__,
+ IMSG_DATA_SIZE(imsg));
memcpy(&imsg_link_state, imsg.data,
sizeof(imsg_link_state));
main_imsg_compose_engine(IMSG_UPDATE_LINK_STATE, 0,
@@ -442,10 +441,9 @@ main_dispatch_frontend(int fd, short event, void *bula)
break;
#endif /* SMALL */
case IMSG_UPDATE_IF:
- if (imsg.hdr.len != IMSG_HEADER_SIZE +
- sizeof(imsg_ifinfo))
- fatal("%s: IMSG_UPDATE_IF wrong length: %d",
- __func__, imsg.hdr.len);
+ if (IMSG_DATA_SIZE(imsg) != sizeof(imsg_ifinfo))
+ fatal("%s: IMSG_UPDATE_IF wrong length: %lu",
+ __func__, IMSG_DATA_SIZE(imsg));
memcpy(&imsg_ifinfo, imsg.data, sizeof(imsg_ifinfo));
if (get_soiikey(imsg_ifinfo.soiikey) == -1)
log_warn("get_soiikey");
@@ -504,30 +502,34 @@ main_dispatch_engine(int fd, short event, void *bula)
switch (imsg.hdr.type) {
case IMSG_PROPOSAL:
- if (imsg.hdr.len != IMSG_HEADER_SIZE + sizeof(proposal))
+ if (IMSG_DATA_SIZE(imsg) != sizeof(proposal))
fatal("%s: IMSG_PROPOSAL wrong "
- "length: %d", __func__, imsg.hdr.len);
+ "length: %lu", __func__,
+ IMSG_DATA_SIZE(imsg));
memcpy(&proposal, imsg.data, sizeof(proposal));
handle_proposal(&proposal);
break;
case IMSG_CONFIGURE_ADDRESS:
- if (imsg.hdr.len != IMSG_HEADER_SIZE + sizeof(address))
+ if (IMSG_DATA_SIZE(imsg) != sizeof(address))
fatal("%s: IMSG_CONFIGURE_ADDRESS wrong "
- "length: %d", __func__, imsg.hdr.len);
+ "length: %lu", __func__,
+ IMSG_DATA_SIZE(imsg));
memcpy(&address, imsg.data, sizeof(address));
configure_interface(&address);
break;
case IMSG_CONFIGURE_DFR:
- if (imsg.hdr.len != IMSG_HEADER_SIZE + sizeof(dfr))
+ if (IMSG_DATA_SIZE(imsg) != sizeof(dfr))
fatal("%s: IMSG_CONFIGURE_DFR wrong "
- "length: %d", __func__, imsg.hdr.len);
+ "length: %lu", __func__,
+ IMSG_DATA_SIZE(imsg));
memcpy(&dfr, imsg.data, sizeof(dfr));
add_gateway(&dfr);
break;
case IMSG_WITHDRAW_DFR:
- if (imsg.hdr.len != IMSG_HEADER_SIZE + sizeof(dfr))
+ if (IMSG_DATA_SIZE(imsg) != sizeof(dfr))
fatal("%s: IMSG_WITHDRAW_DFR wrong "
- "length: %d", __func__, imsg.hdr.len);
+ "length: %lu", __func__,
+ IMSG_DATA_SIZE(imsg));
memcpy(&dfr, imsg.data, sizeof(dfr));
delete_gateway(&dfr);
break;
diff --git a/sbin/slaacd/slaacd.h b/sbin/slaacd/slaacd.h
index 05dff3b6e1d..eea0d906516 100644
--- a/sbin/slaacd/slaacd.h
+++ b/sbin/slaacd/slaacd.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: slaacd.h,v 1.20 2018/07/27 06:23:08 bket Exp $ */
+/* $OpenBSD: slaacd.h,v 1.21 2019/03/02 05:34:59 pamela Exp $ */
/*
* Copyright (c) 2017 Florian Obser <florian@openbsd.org>
@@ -27,6 +27,8 @@
/* MAXDNAME from arpa/namesr.h */
#define SLAACD_MAX_DNSSL 1025
+#define IMSG_DATA_SIZE(imsg) ((imsg).hdr.len - IMSG_HEADER_SIZE)
+
static const char * const log_procnames[] = {
"main",
"engine",