summaryrefslogtreecommitdiffhomepage
path: root/pkg/tcpip/header/udp.go
diff options
context:
space:
mode:
authorgVisor bot <gvisor-bot@google.com>2021-06-25 05:49:55 +0000
committergVisor bot <gvisor-bot@google.com>2021-06-25 05:49:55 +0000
commit7b812f4e5dabaf445b3aa4a2d7bc285cc43b575b (patch)
tree080c37c6073c5fcb9c9670e36a2bec7a9205d403 /pkg/tcpip/header/udp.go
parentb1a2bc539b5c531fcc0e21179cc8d576261bb318 (diff)
parent1f113b96e68fed452e40855db0cf3efa24b2b9b6 (diff)
Merge release-20210614.0-29-g1f113b96e (automated)
Diffstat (limited to 'pkg/tcpip/header/udp.go')
-rw-r--r--pkg/tcpip/header/udp.go29
1 files changed, 29 insertions, 0 deletions
diff --git a/pkg/tcpip/header/udp.go b/pkg/tcpip/header/udp.go
index ae9d167ff..f69d53314 100644
--- a/pkg/tcpip/header/udp.go
+++ b/pkg/tcpip/header/udp.go
@@ -130,3 +130,32 @@ func (b UDP) Encode(u *UDPFields) {
binary.BigEndian.PutUint16(b[udpLength:], u.Length)
binary.BigEndian.PutUint16(b[udpChecksum:], u.Checksum)
}
+
+// SetSourcePortWithChecksumUpdate implements ChecksummableTransport.
+func (b UDP) SetSourcePortWithChecksumUpdate(new uint16) {
+ old := b.SourcePort()
+ b.SetSourcePort(new)
+ b.SetChecksum(^checksumUpdate2ByteAlignedUint16(^b.Checksum(), old, new))
+}
+
+// SetDestinationPortWithChecksumUpdate implements ChecksummableTransport.
+func (b UDP) SetDestinationPortWithChecksumUpdate(new uint16) {
+ old := b.DestinationPort()
+ b.SetDestinationPort(new)
+ b.SetChecksum(^checksumUpdate2ByteAlignedUint16(^b.Checksum(), old, new))
+}
+
+// UpdateChecksumPseudoHeaderAddress implements ChecksummableTransport.
+func (b UDP) UpdateChecksumPseudoHeaderAddress(old, new tcpip.Address, fullChecksum bool) {
+ xsum := b.Checksum()
+ if fullChecksum {
+ xsum = ^xsum
+ }
+
+ xsum = checksumUpdate2ByteAlignedAddress(xsum, old, new)
+ if fullChecksum {
+ xsum = ^xsum
+ }
+
+ b.SetChecksum(xsum)
+}