MCPcopy Index your code
hub / github.com/tailscale/tailscale / tcp4syn

Function tcp4syn

wgengine/netstack/netstack_test.go:670–706  ·  view source on GitHub ↗
(tb testing.TB, src, dst netip.Addr, sport, dport uint16)

Source from the content-addressed store, hash-verified

668}
669
670func tcp4syn(tb testing.TB, src, dst netip.Addr, sport, dport uint16) []byte {
671 ip := header.IPv4(make([]byte, header.IPv4MinimumSize+header.TCPMinimumSize))
672 ip.Encode(&header.IPv4Fields{
673 Protocol: uint8(header.TCPProtocolNumber),
674 TotalLength: header.IPv4MinimumSize + header.TCPMinimumSize,
675 TTL: 64,
676 SrcAddr: tcpip.AddrFrom4Slice(src.AsSlice()),
677 DstAddr: tcpip.AddrFrom4Slice(dst.AsSlice()),
678 })
679 ip.SetChecksum(^ip.CalculateChecksum())
680 if !ip.IsChecksumValid() {
681 tb.Fatal("test broken; packet has incorrect IP checksum")
682 }
683
684 tcp := header.TCP(ip[header.IPv4MinimumSize:])
685 tcp.Encode(&header.TCPFields{
686 SrcPort: sport,
687 DstPort: dport,
688 SeqNum: 0,
689 DataOffset: header.TCPMinimumSize,
690 Flags: header.TCPFlagSyn,
691 WindowSize: 65535,
692 Checksum: 0,
693 })
694 xsum := header.PseudoHeaderChecksum(
695 header.TCPProtocolNumber,
696 tcpip.AddrFrom4Slice(src.AsSlice()),
697 tcpip.AddrFrom4Slice(dst.AsSlice()),
698 uint16(header.TCPMinimumSize),
699 )
700 tcp.SetChecksum(^tcp.CalculateChecksum(xsum))
701 if !tcp.IsChecksumValid(tcpip.AddrFrom4Slice(src.AsSlice()), tcpip.AddrFrom4Slice(dst.AsSlice()), 0, 0) {
702 tb.Fatal("test broken; packet has incorrect TCP checksum")
703 }
704
705 return ip
706}
707
708// makeHangDialer returns a dialer that notifies the returned channel when a
709// connection is dialed and then hangs until the test finishes.

Calls 5

IPv4Method · 0.80
EncodeMethod · 0.80
FatalMethod · 0.65
AsSliceMethod · 0.45
TCPMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…