(tb testing.TB, src, dst netip.Addr, sport, dport uint16)
| 668 | } |
| 669 | |
| 670 | func 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. |
no test coverage detected
searching dependent graphs…