summaryrefslogtreecommitdiffhomepage
path: root/src/send.c
diff options
context:
space:
mode:
authorJason A. Donenfeld <Jason@zx2c4.com>2018-04-16 02:45:30 +0200
committerJason A. Donenfeld <Jason@zx2c4.com>2018-04-16 02:45:30 +0200
commit7b16ee53178b21b55591ccb1ca01ee141dcfdaf3 (patch)
tree8c51dded3b0cc649d4b5feb8695b43a2d77bafdf /src/send.c
parent0b12a85f27e9a41f8fd10536ebd23768f0d97519 (diff)
send: simplify skb_padding with nice macro
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
Diffstat (limited to 'src/send.c')
-rw-r--r--src/send.c7
1 files changed, 3 insertions, 4 deletions
diff --git a/src/send.c b/src/send.c
index 9c9f694..9b1aec0 100644
--- a/src/send.c
+++ b/src/send.c
@@ -112,12 +112,11 @@ static inline void keep_key_fresh(struct wireguard_peer *peer)
static inline unsigned int skb_padding(struct sk_buff *skb)
{
/* We do this modulo business with the MTU, just in case the networking layer
- * gives us a packet that's bigger than the MTU. Since we support GSO, this
- * isn't strictly neccessary, but it's better to be cautious here, especially
- * if that code ever changes.
+ * gives us a packet that's bigger than the MTU. In that case, we 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 padded_size = (last_unit + MESSAGE_PADDING_MULTIPLE - 1) & ~(MESSAGE_PADDING_MULTIPLE - 1);
+ unsigned int padded_size = ALIGN(last_unit, MESSAGE_PADDING_MULTIPLE);
if (padded_size > PACKET_CB(skb)->mtu)
padded_size = PACKET_CB(skb)->mtu;