clashtcpip

package
v0.4.2 Latest Latest
Warning

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

Go to latest
Published: Nov 26, 2024 License: GPL-2.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ICMPTypePingRequest  byte = 0x8
	ICMPTypePingResponse byte = 0x0
)
View Source
const (
	ICMPv6HeaderSize = 4

	ICMPv6MinimumSize = 8

	ICMPv6PayloadOffset = 8

	ICMPv6EchoMinimumSize = 8

	ICMPv6ErrorHeaderSize = 8

	ICMPv6DstUnreachableMinimumSize = ICMPv6MinimumSize

	ICMPv6PacketTooBigMinimumSize = ICMPv6MinimumSize

	ICMPv6ChecksumOffset = 2

	NDPHopLimit = 255
)
View Source
const (
	FlagDontFragment = 1 << 1
	FlagMoreFragment = 1 << 2
)
View Source
const (
	IPv4HeaderSize = 20

	IPv4Version = 4

	IPv4OptionsOffset   = 20
	IPv4PacketMinLength = IPv4OptionsOffset
)
View Source
const (
	IPv6PayloadLenOffset = 4

	IPv6NextHeaderOffset = 6

	IPv6FixedHeaderSize = v6DstAddr + IPv6AddressSize
)
View Source
const (
	IPv6MinimumSize = IPv6FixedHeaderSize

	IPv6AddressSize = 16

	IPv6Version = 6

	IPv6MinimumMTU = 1280
)
View Source
const (
	TCPFin uint16 = 1 << 0
	TCPSyn uint16 = 1 << 1
	TCPRst uint16 = 1 << 2
	TCPPuh uint16 = 1 << 3
	TCPAck uint16 = 1 << 4
	TCPUrg uint16 = 1 << 5
	TCPEce uint16 = 1 << 6
	TCPEwr uint16 = 1 << 7
	TCPNs  uint16 = 1 << 8
)
View Source
const (
	IPv4IHLStride = 4
)
View Source
const TCPHeaderSize = 20
View Source
const UDPHeaderSize = 8

Variables

View Source
var (
	ErrInvalidLength    = errors.New("invalid packet length")
	ErrInvalidIPVersion = errors.New("invalid ip version")
	ErrInvalidChecksum  = errors.New("invalid checksum")
)
View Source
var SumFnc = SumCompat

Functions

func Checksum

func Checksum(sum uint32, b []byte) (answer [2]byte)

Checksum for Internet Protocol family headers

func IPVersion

func IPVersion(b []byte) int

func SetIPv4

func SetIPv4(packet []byte)

func Sum

func Sum(b []byte) uint32

func SumAVX2

func SumAVX2(data []byte) uint32

func SumCompat

func SumCompat(b []byte) (sum uint32)

Types

type ICMPPacket

type ICMPPacket []byte

func (ICMPPacket) Checksum

func (p ICMPPacket) Checksum() uint16

func (ICMPPacket) Code

func (p ICMPPacket) Code() byte

func (ICMPPacket) ResetChecksum

func (p ICMPPacket) ResetChecksum()

func (ICMPPacket) SetChecksum

func (p ICMPPacket) SetChecksum(sum [2]byte)

func (ICMPPacket) SetType

func (p ICMPPacket) SetType(v ICMPType)

func (ICMPPacket) Type

func (p ICMPPacket) Type() ICMPType

type ICMPType

type ICMPType = byte

type ICMPv6Code

type ICMPv6Code byte
const (
	ICMPv6NetworkUnreachable ICMPv6Code = 0
	ICMPv6Prohibited         ICMPv6Code = 1
	ICMPv6BeyondScope        ICMPv6Code = 2
	ICMPv6AddressUnreachable ICMPv6Code = 3
	ICMPv6PortUnreachable    ICMPv6Code = 4
	ICMPv6Policy             ICMPv6Code = 5
	ICMPv6RejectRoute        ICMPv6Code = 6
)
const (
	ICMPv6HopLimitExceeded  ICMPv6Code = 0
	ICMPv6ReassemblyTimeout ICMPv6Code = 1
)
const (
	ICMPv6ErroneousHeader ICMPv6Code = 0

	ICMPv6UnknownHeader ICMPv6Code = 1

	ICMPv6UnknownOption ICMPv6Code = 2
)
const ICMPv6UnusedCode ICMPv6Code = 0

type ICMPv6Packet

type ICMPv6Packet []byte

func (ICMPv6Packet) Checksum

func (b ICMPv6Packet) Checksum() uint16

func (ICMPv6Packet) Code

func (b ICMPv6Packet) Code() ICMPv6Code

func (ICMPv6Packet) DestinationPort

func (ICMPv6Packet) DestinationPort() uint16

func (ICMPv6Packet) Ident

func (b ICMPv6Packet) Ident() uint16

func (ICMPv6Packet) MTU

func (b ICMPv6Packet) MTU() uint32

func (ICMPv6Packet) MessageBody

func (b ICMPv6Packet) MessageBody() []byte

func (ICMPv6Packet) Payload

func (b ICMPv6Packet) Payload() []byte

func (ICMPv6Packet) ResetChecksum

func (b ICMPv6Packet) ResetChecksum(psum uint32)

func (ICMPv6Packet) Sequence

func (b ICMPv6Packet) Sequence() uint16

func (ICMPv6Packet) SetChecksum

func (b ICMPv6Packet) SetChecksum(sum [2]byte)

func (ICMPv6Packet) SetCode

func (b ICMPv6Packet) SetCode(c ICMPv6Code)

func (ICMPv6Packet) SetDestinationPort

func (ICMPv6Packet) SetDestinationPort(uint16)

func (ICMPv6Packet) SetIdent

func (b ICMPv6Packet) SetIdent(ident uint16)

func (ICMPv6Packet) SetMTU

func (b ICMPv6Packet) SetMTU(mtu uint32)

func (ICMPv6Packet) SetSequence

func (b ICMPv6Packet) SetSequence(sequence uint16)

func (ICMPv6Packet) SetSourcePort

func (ICMPv6Packet) SetSourcePort(uint16)

func (ICMPv6Packet) SetType

func (b ICMPv6Packet) SetType(t ICMPv6Type)

func (ICMPv6Packet) SetTypeSpecific

func (b ICMPv6Packet) SetTypeSpecific(val uint32)

func (ICMPv6Packet) SourcePort

func (ICMPv6Packet) SourcePort() uint16

func (ICMPv6Packet) Type

func (b ICMPv6Packet) Type() ICMPv6Type

func (ICMPv6Packet) TypeSpecific

func (b ICMPv6Packet) TypeSpecific() uint32

type ICMPv6Type

type ICMPv6Type byte
const (
	ICMPv6DstUnreachable ICMPv6Type = 1
	ICMPv6PacketTooBig   ICMPv6Type = 2
	ICMPv6TimeExceeded   ICMPv6Type = 3
	ICMPv6ParamProblem   ICMPv6Type = 4
	ICMPv6EchoRequest    ICMPv6Type = 128
	ICMPv6EchoReply      ICMPv6Type = 129

	ICMPv6RouterSolicit   ICMPv6Type = 133
	ICMPv6RouterAdvert    ICMPv6Type = 134
	ICMPv6NeighborSolicit ICMPv6Type = 135
	ICMPv6NeighborAdvert  ICMPv6Type = 136
	ICMPv6RedirectMsg     ICMPv6Type = 137

	ICMPv6MulticastListenerQuery  ICMPv6Type = 130
	ICMPv6MulticastListenerReport ICMPv6Type = 131
	ICMPv6MulticastListenerDone   ICMPv6Type = 132
)

func (ICMPv6Type) IsErrorType

func (typ ICMPv6Type) IsErrorType() bool

type IP

type IP interface {
	Payload() []byte
	SourceIP() netip.Addr
	DestinationIP() netip.Addr
	SetSourceIP(ip netip.Addr)
	SetDestinationIP(ip netip.Addr)
	Protocol() IPProtocol
	DecTimeToLive()
	ResetChecksum()
	PseudoSum() uint32
}

type IPProtocol

type IPProtocol = byte
const (
	ICMP   IPProtocol = 0x01
	TCP    IPProtocol = 0x06
	UDP    IPProtocol = 0x11
	ICMPv6 IPProtocol = 0x3a
)

IPProtocol type

type IPv4Packet

type IPv4Packet []byte

func (IPv4Packet) Checksum

func (p IPv4Packet) Checksum() uint16

func (IPv4Packet) DataLen

func (p IPv4Packet) DataLen() uint16

func (IPv4Packet) DecTimeToLive

func (p IPv4Packet) DecTimeToLive()

func (IPv4Packet) DestinationIP

func (p IPv4Packet) DestinationIP() netip.Addr

func (IPv4Packet) Flags

func (p IPv4Packet) Flags() byte

func (IPv4Packet) FragmentOffset

func (p IPv4Packet) FragmentOffset() uint16

func (IPv4Packet) HeaderLen

func (p IPv4Packet) HeaderLen() uint16

func (IPv4Packet) Identification

func (p IPv4Packet) Identification() uint16

func (IPv4Packet) Payload

func (p IPv4Packet) Payload() []byte

func (IPv4Packet) Protocol

func (p IPv4Packet) Protocol() IPProtocol

func (IPv4Packet) PseudoSum

func (p IPv4Packet) PseudoSum() uint32

PseudoSum for tcp checksum

func (IPv4Packet) ResetChecksum

func (p IPv4Packet) ResetChecksum()

func (IPv4Packet) SetChecksum

func (p IPv4Packet) SetChecksum(sum [2]byte)

func (IPv4Packet) SetDestinationIP

func (p IPv4Packet) SetDestinationIP(ip netip.Addr)

func (IPv4Packet) SetFlags

func (p IPv4Packet) SetFlags(flags byte)

func (IPv4Packet) SetFragmentOffset

func (p IPv4Packet) SetFragmentOffset(offset uint32)

func (IPv4Packet) SetHeaderLen

func (p IPv4Packet) SetHeaderLen(length uint16)

func (IPv4Packet) SetIdentification

func (p IPv4Packet) SetIdentification(id uint16)

func (IPv4Packet) SetProtocol

func (p IPv4Packet) SetProtocol(protocol IPProtocol)

func (IPv4Packet) SetSourceIP

func (p IPv4Packet) SetSourceIP(ip netip.Addr)

func (IPv4Packet) SetTimeToLive

func (p IPv4Packet) SetTimeToLive(ttl uint8)

func (IPv4Packet) SetTotalLength

func (p IPv4Packet) SetTotalLength(length uint16)

func (IPv4Packet) SetTypeOfService

func (p IPv4Packet) SetTypeOfService(tos byte)

func (IPv4Packet) SourceIP

func (p IPv4Packet) SourceIP() netip.Addr

func (IPv4Packet) TimeToLive

func (p IPv4Packet) TimeToLive() uint8

func (IPv4Packet) TotalLen

func (p IPv4Packet) TotalLen() uint16

func (IPv4Packet) TypeOfService

func (p IPv4Packet) TypeOfService() byte

func (IPv4Packet) Valid

func (p IPv4Packet) Valid() bool

func (IPv4Packet) Verify

func (p IPv4Packet) Verify() error

type IPv6Packet

type IPv6Packet []byte

func (IPv6Packet) Checksum

func (IPv6Packet) Checksum() uint16

func (IPv6Packet) DecTimeToLive

func (b IPv6Packet) DecTimeToLive()

func (IPv6Packet) DestinationIP

func (b IPv6Packet) DestinationIP() netip.Addr

func (IPv6Packet) HopLimit

func (b IPv6Packet) HopLimit() uint8

func (IPv6Packet) NextHeader

func (b IPv6Packet) NextHeader() byte

func (IPv6Packet) Payload

func (b IPv6Packet) Payload() []byte

func (IPv6Packet) PayloadLength

func (b IPv6Packet) PayloadLength() uint16

func (IPv6Packet) Protocol

func (b IPv6Packet) Protocol() IPProtocol

func (IPv6Packet) PseudoSum

func (b IPv6Packet) PseudoSum() uint32

func (IPv6Packet) ResetChecksum

func (IPv6Packet) ResetChecksum()

func (IPv6Packet) SetChecksum

func (IPv6Packet) SetChecksum(uint16)

func (IPv6Packet) SetDestinationIP

func (b IPv6Packet) SetDestinationIP(addr netip.Addr)

func (IPv6Packet) SetHopLimit

func (b IPv6Packet) SetHopLimit(v uint8)

func (IPv6Packet) SetNextHeader

func (b IPv6Packet) SetNextHeader(v byte)

func (IPv6Packet) SetPayloadLength

func (b IPv6Packet) SetPayloadLength(payloadLength uint16)

func (IPv6Packet) SetProtocol

func (b IPv6Packet) SetProtocol(p IPProtocol)

func (IPv6Packet) SetSourceIP

func (b IPv6Packet) SetSourceIP(addr netip.Addr)

func (IPv6Packet) SetTOS

func (b IPv6Packet) SetTOS(t uint8, l uint32)

func (IPv6Packet) SourceIP

func (b IPv6Packet) SourceIP() netip.Addr

func (IPv6Packet) TOS

func (b IPv6Packet) TOS() (uint8, uint32)

func (IPv6Packet) Valid

func (b IPv6Packet) Valid() bool

type TCPPacket

type TCPPacket []byte

func (TCPPacket) Checksum

func (p TCPPacket) Checksum() uint16

func (TCPPacket) DestinationPort

func (p TCPPacket) DestinationPort() uint16

func (TCPPacket) Flags

func (p TCPPacket) Flags() uint16

func (TCPPacket) OffloadChecksum added in v0.2.0

func (p TCPPacket) OffloadChecksum()

func (TCPPacket) ResetChecksum

func (p TCPPacket) ResetChecksum(psum uint32)

func (TCPPacket) SetChecksum

func (p TCPPacket) SetChecksum(sum [2]byte)

func (TCPPacket) SetDestinationPort

func (p TCPPacket) SetDestinationPort(port uint16)

func (TCPPacket) SetSourcePort

func (p TCPPacket) SetSourcePort(port uint16)

func (TCPPacket) SourcePort

func (p TCPPacket) SourcePort() uint16

func (TCPPacket) Valid

func (p TCPPacket) Valid() bool

func (TCPPacket) Verify

func (p TCPPacket) Verify(sourceAddress net.IP, targetAddress net.IP) error

type UDPPacket

type UDPPacket []byte

func (UDPPacket) Checksum

func (p UDPPacket) Checksum() uint16

func (UDPPacket) DestinationPort

func (p UDPPacket) DestinationPort() uint16

func (UDPPacket) Length

func (p UDPPacket) Length() uint16

func (UDPPacket) OffloadChecksum added in v0.2.0

func (p UDPPacket) OffloadChecksum()

func (UDPPacket) Payload

func (p UDPPacket) Payload() []byte

func (UDPPacket) ResetChecksum

func (p UDPPacket) ResetChecksum(psum uint32)

func (UDPPacket) SetChecksum

func (p UDPPacket) SetChecksum(sum [2]byte)

func (UDPPacket) SetDestinationPort

func (p UDPPacket) SetDestinationPort(port uint16)

func (UDPPacket) SetLength

func (p UDPPacket) SetLength(length uint16)

func (UDPPacket) SetSourcePort

func (p UDPPacket) SetSourcePort(port uint16)

func (UDPPacket) SourcePort

func (p UDPPacket) SourcePort() uint16

func (UDPPacket) Valid

func (p UDPPacket) Valid() bool

Jump to

Keyboard shortcuts

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