diff options
-rw-r--r-- | src/compat/compat.h | 4 | ||||
-rw-r--r-- | src/device.c | 9 | ||||
-rw-r--r-- | src/send.c | 3 |
3 files changed, 12 insertions, 4 deletions
diff --git a/src/compat/compat.h b/src/compat/compat.h index 5978fe9..0d109be 100644 --- a/src/compat/compat.h +++ b/src/compat/compat.h @@ -1020,6 +1020,10 @@ out: #endif #endif +#if LINUX_VERSION_CODE < KERNEL_VERSION(4, 10, 0) +#define COMPAT_CANNOT_USE_MAX_MTU +#endif + #if defined(ISUBUNTU1604) #include <linux/siphash.h> #ifndef _WG_LINUX_SIPHASH_H diff --git a/src/device.c b/src/device.c index 2883bad..73c892a 100644 --- a/src/device.c +++ b/src/device.c @@ -266,6 +266,8 @@ static void wg_setup(struct net_device *dev) enum { WG_NETDEV_FEATURES = NETIF_F_HW_CSUM | NETIF_F_RXCSUM | NETIF_F_SG | NETIF_F_GSO | NETIF_F_GSO_SOFTWARE | NETIF_F_HIGHDMA }; + const int overhead = MESSAGE_MINIMUM_LENGTH + sizeof(struct udphdr) + + max(sizeof(struct ipv6hdr), sizeof(struct iphdr)); dev->netdev_ops = &netdev_ops; dev->hard_header_len = 0; @@ -283,9 +285,10 @@ static void wg_setup(struct net_device *dev) dev->features |= WG_NETDEV_FEATURES; dev->hw_features |= WG_NETDEV_FEATURES; dev->hw_enc_features |= WG_NETDEV_FEATURES; - dev->mtu = ETH_DATA_LEN - MESSAGE_MINIMUM_LENGTH - - sizeof(struct udphdr) - - max(sizeof(struct ipv6hdr), sizeof(struct iphdr)); + dev->mtu = ETH_DATA_LEN - overhead; +#ifndef COMPAT_CANNOT_USE_MAX_MTU + dev->max_mtu = round_down(INT_MAX, MESSAGE_PADDING_MULTIPLE) - overhead; +#endif SET_NETDEV_DEVTYPE(dev, &device_type); @@ -149,7 +149,8 @@ static unsigned int calculate_skb_padding(struct sk_buff *skb) * wouldn't want the final subtraction to overflow in the case of the * padded_size being clamped. */ - unsigned int last_unit = skb->len % PACKET_CB(skb)->mtu; + unsigned int last_unit = PACKET_CB(skb)->mtu ? + skb->len % PACKET_CB(skb)->mtu : skb->len; unsigned int padded_size = ALIGN(last_unit, MESSAGE_PADDING_MULTIPLE); if (padded_size > PACKET_CB(skb)->mtu) |