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

Function makeUDP6PacketBuffer

wgengine/netstack/netstack_test.go:1415–1457  ·  view source on GitHub ↗
(src, dst netip.AddrPort)

Source from the content-addressed store, hash-verified

1413}
1414
1415func makeUDP6PacketBuffer(src, dst netip.AddrPort) *stack.PacketBuffer {
1416 if !src.Addr().Is6() || !dst.Addr().Is6() {
1417 panic("src and dst must be IPv6")
1418 }
1419 data := []byte("hello world\n")
1420
1421 packetLen := header.IPv6MinimumSize + header.UDPMinimumSize
1422 pkt := stack.NewPacketBuffer(stack.PacketBufferOptions{
1423 ReserveHeaderBytes: packetLen,
1424 Payload: buffer.MakeWithData(data),
1425 })
1426
1427 srcAddr := tcpip.AddrFrom16(src.Addr().As16())
1428 dstAddr := tcpip.AddrFrom16(dst.Addr().As16())
1429
1430 // Add IP header
1431 ipHdr := header.IPv6(pkt.NetworkHeader().Push(header.IPv6MinimumSize))
1432 pkt.NetworkProtocolNumber = header.IPv6ProtocolNumber
1433 ipHdr.Encode(&header.IPv6Fields{
1434 SrcAddr: srcAddr,
1435 DstAddr: dstAddr,
1436 PayloadLength: uint16(header.UDPMinimumSize + len(data)),
1437 TransportProtocol: header.UDPProtocolNumber,
1438 HopLimit: 64,
1439 })
1440
1441 // Initialize the UDP header.
1442 udp := header.UDP(pkt.TransportHeader().Push(header.UDPMinimumSize))
1443 pkt.TransportProtocolNumber = header.UDPProtocolNumber
1444
1445 length := uint16(pkt.Size())
1446 udp.Encode(&header.UDPFields{
1447 SrcPort: src.Port(),
1448 DstPort: dst.Port(),
1449 Length: length,
1450 })
1451
1452 // Calculate the UDP pseudo-header checksum.
1453 xsum := header.PseudoHeaderChecksum(header.UDPProtocolNumber, srcAddr, dstAddr, uint16(len(udp)))
1454 udp.SetChecksum(^udp.CalculateChecksum(xsum))
1455
1456 return pkt
1457}
1458
1459// TestIsSelfDst verifies that isSelfDst correctly identifies packets whose
1460// destination IP is a local Tailscale IP assigned to this node.

Callers 3

TestShouldSendToHostFunction · 0.85
TestIsSelfDstFunction · 0.85
TestDeliverLoopbackFunction · 0.85

Calls 8

IPv6Method · 0.80
NetworkHeaderMethod · 0.80
EncodeMethod · 0.80
TransportHeaderMethod · 0.80
PushMethod · 0.65
AddrMethod · 0.45
SizeMethod · 0.45
PortMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…