use a local recv_buf that is allocated on first call with malloc().
The memory returned from malloc() is properly aligned which may not
be the case for bss or stack memory.
-/* $OpenBSD: ldpd.h,v 1.91 2021/01/19 15:23:25 claudio Exp $ */
+/* $OpenBSD: ldpd.h,v 1.92 2021/01/19 15:59:25 claudio Exp $ */
/*
* Copyright (c) 2013, 2016 Renato Westphal <renato@openbsd.org>
#define TCP_MD5_KEY_LEN 80
#define L2VPN_NAME_LEN 32
+#define READ_BUF_SIZE 65535
#define RT_BUF_SIZE 16384
#define MAX_RTSOCK_BUF (2 * 1024 * 1024)
#define LDP_BACKLOG 128
-/* $OpenBSD: ldpe.c,v 1.79 2021/01/19 15:23:25 claudio Exp $ */
+/* $OpenBSD: ldpe.c,v 1.80 2021/01/19 15:59:25 claudio Exp $ */
/*
* Copyright (c) 2013, 2016 Renato Westphal <renato@openbsd.org>
/* listen on ldpd control socket */
control_listen();
- if ((pkt_ptr = calloc(1, IBUF_READ_SIZE)) == NULL)
- fatal(__func__);
-
event_dispatch();
ldpe_shutdown();
/* clean up */
free(iev_lde);
free(iev_main);
- free(pkt_ptr);
log_info("ldp engine exiting");
exit(0);
-/* $OpenBSD: ldpe.h,v 1.78 2021/01/19 15:14:35 claudio Exp $ */
+/* $OpenBSD: ldpe.h,v 1.79 2021/01/19 15:59:25 claudio Exp $ */
/*
* Copyright (c) 2013, 2016 Renato Westphal <renato@openbsd.org>
void pending_conn_del(struct pending_conn *);
struct pending_conn *pending_conn_find(int, union ldpd_addr *);
-char *pkt_ptr; /* packet buffer */
-
/* pfkey.c */
int pfkey_read(int, struct sadb_msg *);
int pfkey_establish(struct ldpd_conf *, struct nbr *);
-/* $OpenBSD: packet.c,v 1.71 2019/01/23 02:02:04 dlg Exp $ */
+/* $OpenBSD: packet.c,v 1.72 2021/01/19 15:59:25 claudio Exp $ */
/*
* Copyright (c) 2013, 2016 Renato Westphal <renato@openbsd.org>
static struct pending_conn *pending_conn_new(int, int, union ldpd_addr *);
static void pending_conn_timeout(int, short, void *);
+static u_int8_t *recv_buf;
+
int
gen_ldp_hdr(struct ibuf *buf, uint16_t size)
{
if (event != EV_READ)
return;
+ if (recv_buf == NULL)
+ if ((recv_buf = malloc(READ_BUF_SIZE)) == NULL)
+ fatal(__func__);
+
/* setup buffer */
memset(&m, 0, sizeof(m));
- iov.iov_base = buf = pkt_ptr;
- iov.iov_len = IBUF_READ_SIZE;
+ iov.iov_base = buf = recv_buf;
+ iov.iov_len = READ_BUF_SIZE;
m.msg_name = &from;
m.msg_namelen = sizeof(from);
m.msg_iov = &iov;