diff options
author | 2021-01-19 16:02:06 +0000 | |
---|---|---|
committer | 2021-01-19 16:02:06 +0000 | |
commit | 8efa32dfffc59a50a4a00a391631d196d6639c80 (patch) | |
tree | 67831ea645111885fd85ef2e7e07b7c69e81e354 | |
parent | Allocate the recv buffer with malloc() on first call. This code assumes (diff) | |
download | wireguard-openbsd-8efa32dfffc59a50a4a00a391631d196d6639c80.tar.xz wireguard-openbsd-8efa32dfffc59a50a4a00a391631d196d6639c80.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/ospf6d/packet.c | 11 |
1 files changed, 8 insertions, 3 deletions
diff --git a/usr.sbin/ospf6d/packet.c b/usr.sbin/ospf6d/packet.c index efbf891df1d..eaac35c612e 100644 --- a/usr.sbin/ospf6d/packet.c +++ b/usr.sbin/ospf6d/packet.c @@ -1,4 +1,4 @@ -/* $OpenBSD: packet.c,v 1.19 2021/01/19 09:43:40 claudio Exp $ */ +/* $OpenBSD: packet.c,v 1.20 2021/01/19 16:02:06 claudio Exp $ */ /* * Copyright (c) 2004, 2005 Esben Norby <norby@openbsd.org> @@ -42,6 +42,8 @@ int ospf_hdr_sanity_check(struct ospf_hdr *, u_int16_t, struct iface *find_iface(struct ospfd_conf *, unsigned int, struct in6_addr *); +static u_int8_t *recv_buf; + int gen_ospf_hdr(struct ibuf *buf, struct iface *iface, u_int8_t type) { @@ -114,7 +116,6 @@ send_packet(struct iface *iface, struct ibuf *buf, 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 in6_pktinfo))]; @@ -137,9 +138,13 @@ recv_packet(int fd, short event, void *bula) if (event != EV_READ) return; + if (recv_buf == NULL) + if ((recv_buf = malloc(READ_BUF_SIZE)) == NULL) + fatal(__func__); + /* setup buffer */ bzero(&msg, sizeof(msg)); - iov.iov_base = buf = pkt_ptr; + iov.iov_base = buf = recv_buf; iov.iov_len = READ_BUF_SIZE; msg.msg_name = &src; msg.msg_namelen = sizeof(src); |