diff options
author | Greg Kroah-Hartman <gregkh@linuxfoundation.org> | 2020-02-24 08:39:55 +0100 |
---|---|---|
committer | Greg Kroah-Hartman <gregkh@linuxfoundation.org> | 2020-02-24 08:39:55 +0100 |
commit | ba08cf452f3493e96793c9fec4ebb45e7101a0c0 (patch) | |
tree | 61200038de5d9c6ba50dadfa7f065d029fa06174 /drivers/net/wireguard/send.c | |
parent | e24cd4e6d6aa3ca741cdfdfc01118c4016acebea (diff) | |
parent | f8788d86ab28f61f7b46eb6be375f8a726783636 (diff) | |
download | kernel_replicant_linux-ba08cf452f3493e96793c9fec4ebb45e7101a0c0.tar.gz kernel_replicant_linux-ba08cf452f3493e96793c9fec4ebb45e7101a0c0.tar.bz2 kernel_replicant_linux-ba08cf452f3493e96793c9fec4ebb45e7101a0c0.zip |
Merge 5.6-rc3 into tty-next
We want the tty fixes in here as well.
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Diffstat (limited to 'drivers/net/wireguard/send.c')
-rw-r--r-- | drivers/net/wireguard/send.c | 16 |
1 files changed, 11 insertions, 5 deletions
diff --git a/drivers/net/wireguard/send.c b/drivers/net/wireguard/send.c index c13260563446..7348c10cbae3 100644 --- a/drivers/net/wireguard/send.c +++ b/drivers/net/wireguard/send.c @@ -143,16 +143,22 @@ static void keep_key_fresh(struct wg_peer *peer) static unsigned int calculate_skb_padding(struct sk_buff *skb) { + unsigned int padded_size, last_unit = skb->len; + + if (unlikely(!PACKET_CB(skb)->mtu)) + return ALIGN(last_unit, MESSAGE_PADDING_MULTIPLE) - last_unit; + /* We do this modulo business with the MTU, just in case the networking * layer 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. + * padded_size being clamped. Fortunately, that's very rarely the case, + * so we optimize for that not happening. */ - unsigned int last_unit = skb->len % PACKET_CB(skb)->mtu; - unsigned int padded_size = ALIGN(last_unit, MESSAGE_PADDING_MULTIPLE); + if (unlikely(last_unit > PACKET_CB(skb)->mtu)) + last_unit %= PACKET_CB(skb)->mtu; - if (padded_size > PACKET_CB(skb)->mtu) - padded_size = PACKET_CB(skb)->mtu; + padded_size = min(PACKET_CB(skb)->mtu, + ALIGN(last_unit, MESSAGE_PADDING_MULTIPLE)); return padded_size - last_unit; } |