diff options
author | 2021-01-19 16:02:56 +0000 | |
---|---|---|
committer | 2021-01-19 16:02:56 +0000 | |
commit | 2d4baefbc5138aa494b88e94cd22e77f0efa0a6c (patch) | |
tree | 46064f8deceaa143e9a632c09aa51bf28ba44c06 /usr.sbin/dvmrpd/packet.c | |
parent | Like ospfd allocate the recv buffer with malloc() on first call. (diff) | |
download | wireguard-openbsd-2d4baefbc5138aa494b88e94cd22e77f0efa0a6c.tar.xz wireguard-openbsd-2d4baefbc5138aa494b88e94cd22e77f0efa0a6c.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.
Diffstat (limited to 'usr.sbin/dvmrpd/packet.c')
-rw-r--r-- | usr.sbin/dvmrpd/packet.c | 13 |
1 files changed, 8 insertions, 5 deletions
diff --git a/usr.sbin/dvmrpd/packet.c b/usr.sbin/dvmrpd/packet.c index 757598c82d6..0a7dd6d7a3b 100644 --- a/usr.sbin/dvmrpd/packet.c +++ b/usr.sbin/dvmrpd/packet.c @@ -1,4 +1,4 @@ -/* $OpenBSD: packet.c,v 1.6 2021/01/19 11:46:10 claudio Exp $ */ +/* $OpenBSD: packet.c,v 1.7 2021/01/19 16:02:56 claudio Exp $ */ /* * Copyright (c) 2004, 2005, 2006 Esben Norby <norby@openbsd.org> @@ -41,7 +41,7 @@ int dvmrp_hdr_sanity_check(const struct ip *, struct dvmrp_hdr *, u_int16_t, const struct iface *); struct iface *find_iface(struct dvmrpd_conf *, struct in_addr); -extern struct dvmrpd_conf *deconf; +static u_int8_t *recv_buf; int gen_dvmrp_hdr(struct ibuf *buf, struct iface *iface, u_int8_t code) @@ -97,7 +97,6 @@ recv_packet(int fd, short event, void *bula) struct nbr *nbr = NULL; struct in_addr addr; char *buf; - char pkt[READ_BUF_SIZE]; ssize_t r; u_int16_t len; int l; @@ -105,14 +104,18 @@ recv_packet(int fd, short event, void *bula) if (event != EV_READ) return; - if ((r = recvfrom(fd, pkt, sizeof(pkt), 0, NULL, NULL)) == -1) { + if (recv_buf == NULL) + if ((recv_buf = malloc(READ_BUF_SIZE)) == NULL) + fatal(__func__); + + buf = recv_buf; + if ((r = recvfrom(fd, buf, READ_BUF_SIZE, 0, NULL, NULL)) == -1) { if (errno != EAGAIN && errno != EINTR) log_debug("recv_packet: error receiving packet"); return; } len = (u_int16_t)r; - buf = pkt; /* IP header sanity checks */ if (len < sizeof(ip_hdr)) { |