From 3502425221399270180fe33081e67c56e0f1f892 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Sun, 24 Feb 2019 09:52:18 -0600 Subject: [PATCH] drivers/net/tun.c: Packet buffer size should include the configured GUARD_SIZE. And, given how the buffers are allocated, the allocation size must be an even number of 16-bit values to preserve alignment. --- drivers/net/tun.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/drivers/net/tun.c b/drivers/net/tun.c index 50452170b2..0813f6918e 100644 --- a/drivers/net/tun.c +++ b/drivers/net/tun.c @@ -102,6 +102,12 @@ # define CONFIG_TUN_NINTERFACES 1 #endif +/* Make sure that packet buffers include in configured guard size and are an + * even multiple of 16-bits in length. + */ + +#define NET_TUN_PKTSIZE ((CONFIG_NET_TUN_PKTSIZE + CONFIG_NET_GUARDSIZE + 1) & ~1) + /* TX poll delay = 1 seconds. CLK_TCK is the number of clock ticks per * second */ @@ -149,8 +155,8 @@ struct tun_device_s * is assured only by the preceding wide data types. */ - uint8_t read_buf[CONFIG_NET_TUN_PKTSIZE]; - uint8_t write_buf[CONFIG_NET_TUN_PKTSIZE]; + uint8_t read_buf[NET_TUN_PKTSIZE]; + uint8_t write_buf[NET_TUN_PKTSIZE]; /* This holds the information visible to the NuttX network */