pktgen

package
v0.0.0-...-31439de Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 7, 2024 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Overview

pkg/pktgen/af_inet.go

pkg/pktgen/af_inet.go

pkg/pktgen/af_packet.go

pkg/pktgen/af_packet.go

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BuildPacket

func BuildPacket(c *PacketConfig) ([]byte, error)

BuildPacket constructs the packet based on the PacketConfig. It automatically includes the Ethernet layer if both SrcMAC and DstMAC are provided.

func GetCurrentTXQueues

func GetCurrentTXQueues(interfaceName string) (int, error)

GetCurrentTXQueues returns the number of TX queues for the specified interface

Types

type AFInetSyscallSender

type AFInetSyscallSender struct {
	// contains filtered or unexported fields
}

AFInetSyscallSender is a Sender that uses the syscall package to send packets

func NewAFInetSyscallSender

func NewAFInetSyscallSender(dstIP net.IP, dstPort, payloadSize int) *AFInetSyscallSender

NewAFInetSyscallSender creates a new AFInetSyscallSender

func (*AFInetSyscallSender) Send

Send sends packets to the destination IP address

type AFPacketSender

type AFPacketSender struct {
	// contains filtered or unexported fields
}

AFPacketSender implements the Sender interface using AF_PACKET

func NewAFPacketSender

func NewAFPacketSender(iface string, srcIP, dstIP net.IP, srcPort, dstPort, payloadSize int, srcMAC, dstMAC net.HardwareAddr) *AFPacketSender

NewAFPacketSender creates a new AFPacketSender with specified parameters

func (*AFPacketSender) Send

func (s *AFPacketSender) Send(ctx context.Context) error

Send sends packets using AF_PACKET

type AFPcapSender

type AFPcapSender struct {
	// contains filtered or unexported fields
}

AFPcapSender implements the Sender

func NewAFPcapSender

func NewAFPcapSender(iface string, srcIP, dstIP net.IP, srcPort, dstPort, payloadSize int, srcMAC, dstMAC net.HardwareAddr) *AFPcapSender

NewAFPcapSender creates a new NewAFPcapSender with specified parameters

func (*AFPcapSender) Send

func (s *AFPcapSender) Send(ctx context.Context) error

Send sends packets using PCAP handle

type AFXdpSender

type AFXdpSender struct {
	// contains filtered or unexported fields
}

AFXdpSender implements the Sender interface using AF_XDP

func NewAFXdpSender

func NewAFXdpSender(iface string, srcIP, dstIP net.IP, srcPort, dstPort, payloadSize int, srcMAC, dstMAC net.HardwareAddr, queueID int) *AFXdpSender

NewAFXdpSender creates a new AFXdpSender with specified parameters

func (*AFXdpSender) Send

func (s *AFXdpSender) Send(ctx context.Context) error

Send sends packets using AFXdpSender

type BatchConnSender

type BatchConnSender struct {
	// contains filtered or unexported fields
}

func NewBatchConnSender

func NewBatchConnSender(dstIP net.IP, dstPort, payloadSize int) *BatchConnSender

func (*BatchConnSender) Send

func (s *BatchConnSender) Send(ctx context.Context) error

Send sends packets using WriteBatch func (s *BatchConnSender) Send(ctx context.Context, payloads [][]byte) error {

type NetConnSender

type NetConnSender struct {
	// contains filtered or unexported fields
}

AFInetSender is a Sender that uses the net package to send packets

func NewNetConnSender

func NewNetConnSender(dstIP net.IP, dstPort, payloadSize int) *NetConnSender

NewAFInetSender creates a new AFInetSender

func (*NetConnSender) Send

func (s *NetConnSender) Send(ctx context.Context) error

Send sends packets to the destination IP address

type PacketConfig

type PacketConfig struct {
	SrcIP, DstIP     net.IP
	SrcPort, DstPort layers.UDPPort
	SrcMAC, DstMAC   net.HardwareAddr
	PayloadSize      int
}

PacketConfig stores configuration for building a packet.

func NewPacketConfig

func NewPacketConfig(opts ...PacketOption) (*PacketConfig, error)

NewPacketConfig creates a new PacketConfig with specified options.

type PacketOption

type PacketOption func(*PacketConfig) error

PacketOption is a function that applies a configuration to a PacketConfig.

func WithEthernetLayer

func WithEthernetLayer(srcMAC, dstMAC net.HardwareAddr) PacketOption

WithEthernetLayer enables the Ethernet layer in the packet.

func WithIpLayer

func WithIpLayer(srcIp, dstIp net.IP) PacketOption

WithIpLayer enables the IP layer in the packet.

func WithPayloadSize

func WithPayloadSize(size int) PacketOption

WithPayloadSize sets the payload size for the packet.

func WithUdpLayer

func WithUdpLayer(srcPort, dstPort int) PacketOption

WithUdpLayer enables the UDP layer in the packet.

type RawSocketSender

type RawSocketSender struct {
	// contains filtered or unexported fields
}

RawSocketSender implements the Sender interface using raw sockets

func NewRawSocketSender

func NewRawSocketSender(srcIP, dstIP net.IP, srcPort, dstPort, payloadSize int) *RawSocketSender

NewRawSocketSender creates a new RawSocketSender with specified parameters

func (*RawSocketSender) Send

func (s *RawSocketSender) Send(ctx context.Context) error

Send sends packets using RawSocketSender

type Sender

type Sender interface {
	Send(ctx context.Context) error
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL