diff options
author | Alex Elder <elder@linaro.org> | 2021-06-11 14:05:28 -0500 |
---|---|---|
committer | David S. Miller <davem@davemloft.net> | 2021-06-11 13:37:49 -0700 |
commit | a2918a169f57f965e4e5949822c2602c90e388ab (patch) | |
tree | ab437506c667b66e6ef7952caa6e3564537a9a0a /fs/btrfs/compression.h | |
parent | e5adbbdfa2fb17e3d266011cef816ee492235581 (diff) | |
download | linux-a2918a169f57f965e4e5949822c2602c90e388ab.tar.gz |
net: qualcomm: rmnet: avoid unnecessary byte-swapping
Internet checksums are used for IPv4 header checksum, as well as TCP
segment and UDP datagram checksums. Such a checksum represents the
negated sum of adjacent pairs of bytes, using ones' complement
arithmetic.
One property of the Internet checkum is byte order independence [1].
Specifically, the sum of byte-swapped pairs is equal to the result
of byte swapping the sum of those same pairs when not byte-swapped.
So for example if a, b, c, d, y, and z are hexadecimal digits, and
PLUS represents ones' complement addition:
If: ab PLUS cd = yz
Then: ba PLUS dc = zy
For this reason, there is no need to swap the order of bytes in the
checksum value held in a message header, nor the one in the QMAPv4
trailer, in order to operate on them.
In other words, we can determine whether the hardware-computed
checksum matches the one in the message header without any byte
swaps.
(This patch leaves in place all existing type casts.)
[1] https://tools.ietf.org/html/rfc1071
Signed-off-by: Alex Elder <elder@linaro.org>
Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'fs/btrfs/compression.h')
0 files changed, 0 insertions, 0 deletions