summaryrefslogtreecommitdiffhomepage
path: root/pkg/tcpip/header/tcp.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/tcp.go
parentb1a2bc539b5c531fcc0e21179cc8d576261bb318 (diff)
parent1f113b96e68fed452e40855db0cf3efa24b2b9b6 (diff)
Merge release-20210614.0-29-g1f113b96e (automated)
Diffstat (limited to 'pkg/tcpip/header/tcp.go')
-rw-r--r--pkg/tcpip/header/tcp.go29
1 files changed, 29 insertions, 0 deletions
diff --git a/pkg/tcpip/header/tcp.go b/pkg/tcpip/header/tcp.go
index 8dabe3354..a75e51a28 100644
--- a/pkg/tcpip/header/tcp.go
+++ b/pkg/tcpip/header/tcp.go
@@ -390,6 +390,35 @@ func (b TCP) EncodePartial(partialChecksum, length uint16, seqnum, acknum uint32
b.SetChecksum(^checksum)
}
+// SetSourcePortWithChecksumUpdate implements ChecksummableTransport.
+func (b TCP) SetSourcePortWithChecksumUpdate(new uint16) {
+ old := b.SourcePort()
+ b.SetSourcePort(new)
+ b.SetChecksum(^checksumUpdate2ByteAlignedUint16(^b.Checksum(), old, new))
+}
+
+// SetDestinationPortWithChecksumUpdate implements ChecksummableTransport.
+func (b TCP) SetDestinationPortWithChecksumUpdate(new uint16) {
+ old := b.DestinationPort()
+ b.SetDestinationPort(new)
+ b.SetChecksum(^checksumUpdate2ByteAlignedUint16(^b.Checksum(), old, new))
+}
+
+// UpdateChecksumPseudoHeaderAddress implements ChecksummableTransport.
+func (b TCP) 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)
+}
+
// ParseSynOptions parses the options received in a SYN segment and returns the
// relevant ones. opts should point to the option part of the TCP header.
func ParseSynOptions(opts []byte, isAck bool) TCPSynOptions {