ctdb-common: Be more careful with packet sizes
authorMartin Schwenke <martin@meltin.net>
Tue, 14 Aug 2018 01:25:02 +0000 (11:25 +1000)
committerAmitay Isaacs <amitay@samba.org>
Thu, 30 Aug 2018 02:48:57 +0000 (04:48 +0200)
Ethernet packets must be at least 64 bytes.

For ARP the packet size was limited to 64 bytes.  This is probably OK
but the code might as well be a little more general.

For IPv6 NA there was no guarantee that the packet is at least 64
bytes.

Signed-off-by: Martin Schwenke <martin@meltin.net>
Reviewed-by: Amitay Isaacs <amitay@gmail.com>
ctdb/common/system_socket.c

index ab7f6be5d71709267a63b6c4144cc88db8994bd4..c60243e9801e030e4fad3c55df013bbbb324e2f1 100644 (file)
@@ -175,14 +175,19 @@ static uint16_t ip6_checksum(uint16_t *data, size_t n, struct ip6_hdr *ip6)
  * packets
  */
 
-#define ARP_BUFFER_SIZE 64
+#define ARP_STRUCT_SIZE sizeof(struct ether_header) + \
+                       sizeof(struct ether_arp)
 
-#define IP6_NA_BUFFER_SIZE sizeof(struct ether_header) + \
+#define IP6_NA_STRUCT_SIZE sizeof(struct ether_header) + \
                           sizeof(struct ip6_hdr) + \
                           sizeof(struct nd_neighbor_advert) + \
                           sizeof(struct nd_opt_hdr) + \
                           sizeof(struct ether_addr)
 
+#define ARP_BUFFER_SIZE MAX(ARP_STRUCT_SIZE, 64)
+
+#define IP6_NA_BUFFER_SIZE MAX(IP6_NA_STRUCT_SIZE, 64)
+
 static int arp_build(uint8_t *buffer,
                     size_t buflen,
                     const struct sockaddr_in *addr,