diff options
author | 2021-01-19 16:02:22 +0000 | |
---|---|---|
committer | 2021-01-19 16:02:22 +0000 | |
commit | a915386be2b388b2852580123bd21f71bfcffb10 (patch) | |
tree | 1b22df7130eb62e44eb3241a7e252363dfd433fe | |
parent | Like ospfd allocate the recv buffer with malloc() on first call. (diff) | |
download | wireguard-openbsd-a915386be2b388b2852580123bd21f71bfcffb10.tar.xz wireguard-openbsd-a915386be2b388b2852580123bd21f71bfcffb10.zip |
Like ospfd allocate the recv buffer with malloc() on first call.
This code assumes some alignment of the buffer which may not be
the case with bss memory.
-rw-r--r-- | usr.sbin/ripd/packet.c | 14 |
1 files changed, 8 insertions, 6 deletions
diff --git a/usr.sbin/ripd/packet.c b/usr.sbin/ripd/packet.c index 4a8b42f6661..b31c73385cd 100644 --- a/usr.sbin/ripd/packet.c +++ b/usr.sbin/ripd/packet.c @@ -1,4 +1,4 @@ -/* $OpenBSD: packet.c,v 1.16 2021/01/19 10:30:00 claudio Exp $ */ +/* $OpenBSD: packet.c,v 1.17 2021/01/19 16:02:22 claudio Exp $ */ /* * Copyright (c) 2006 Michele Marchetto <mydecay@openbeer.it> @@ -41,6 +41,8 @@ int rip_hdr_sanity_check(struct rip_hdr *); struct iface *find_iface(struct ripd_conf *, unsigned int, struct in_addr); +static u_int8_t *recv_buf; + int gen_rip_hdr(struct ibuf *buf, u_int8_t command) { @@ -78,7 +80,6 @@ send_packet(struct iface *iface, void *pkt, size_t len, struct sockaddr_in *dst) void recv_packet(int fd, short event, void *bula) { - static char pkt_ptr[READ_BUF_SIZE]; union { struct cmsghdr hdr; char buf[CMSG_SPACE(sizeof(struct sockaddr_dl))]; @@ -101,12 +102,13 @@ recv_packet(int fd, short event, void *bula) if (event != EV_READ) return; - /* setup buffer */ - buf = pkt_ptr; + if (recv_buf == NULL) + if ((recv_buf = malloc(READ_BUF_SIZE)) == NULL) + fatal(__func__); + /* setup buffer */ bzero(&msg, sizeof(msg)); - - iov.iov_base = buf; + iov.iov_base = buf = recv_buf; iov.iov_len = READ_BUF_SIZE; msg.msg_name = &src; msg.msg_namelen = sizeof(src); |