tcp

package
v0.19.29 Latest Latest
Warning

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

Go to latest
Published: Mar 11, 2021 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// MaxWndScale is maximum allowed window scaling, as described in
	// RFC 1323, section 2.3, page 11.
	MaxWndScale = 14

	// TCPMaxSACKBlocks is the maximum number of SACK blocks that can
	// be encoded in a TCP option field.
	TCPMaxSACKBlocks = 4
)
View Source
const (
	// TCPMinimumSize is the minimum size of a valid TCP packet.
	TCPMinimumSize = 20

	// TCPProtocolNumber is TCP's transport protocol number.
	TCPProtocolNumber int = 6
)
View Source
const (
	TCPFlagFin = 1 << iota
	TCPFlagSyn
	TCPFlagRst
	TCPFlagPsh
	TCPFlagAck
	TCPFlagUrg
)

Flags that may be set in a TCP segment.

View Source
const (
	TCPOptionEOL           = 0
	TCPOptionNOP           = 1
	TCPOptionMSS           = 2
	TCPOptionWS            = 3
	TCPOptionTS            = 8
	TCPOptionSACKPermitted = 4
	TCPOptionSACK          = 5
)

Options that may be present in a TCP segment.

Variables

This section is empty.

Functions

func AddTCPOptionPadding

func AddTCPOptionPadding(options []byte, offset int) int

AddTCPOptionPadding adds the required number of TCPOptionNOP to quad align the option buffer. It adds padding bytes after the offset specified and returns the number of padding bytes added. The passed in options slice must have space for the padding bytes.

func EncodeMSSOption

func EncodeMSSOption(mss uint32, b []byte) int

EncodeMSSOption encodes the MSS TCP option with the provided MSS values in the supplied buffer. If the provided buffer is not large enough then it just returns without encoding anything. It returns the number of bytes written to the provided buffer.

func EncodeNOP

func EncodeNOP(b []byte) int

EncodeNOP adds an explicit NOP to the option list.

func EncodeSACKPermittedOption

func EncodeSACKPermittedOption(b []byte) int

EncodeSACKPermittedOption encodes a SACKPermitted option into the provided buffer. If the buffer is smaller than required it just returns without encoding anything. It returns the number of bytes written to the provided buffer.

func EncodeTSOption

func EncodeTSOption(tsVal, tsEcr uint32, b []byte) int

EncodeTSOption encodes the provided tsVal and tsEcr values as a TCP timestamp option into the provided buffer. If the buffer is smaller than expected it just returns without encoding anything. It returns the number of bytes written to the provided buffer.

func EncodeWSOption

func EncodeWSOption(ws int, b []byte) int

EncodeWSOption encodes the WS TCP option with the WS value in the provided buffer. If the provided buffer is not large enough then it just returns without encoding anything. It returns the number of bytes written to the provided buffer.

func Enqueue

func Enqueue(provider tunnel.FabricProvider, srcIP, dstIP net.IP, pdu []byte, dev io.ReadWriter, tunMTU uint, release func()) bool

func RegisterService

func RegisterService(service *entities.Service, interceptIP net.IP)

func UnregisterService

func UnregisterService(serviceName string)

Types

type ClientConn

type ClientConn struct {
	net.Conn
	// contains filtered or unexported fields
}

func NewClientConn

func NewClientConn(clientAddr, interceptAddr string, rxq chan *tcpQItem, dev io.ReadWriter, tunMTU uint) (*ClientConn, error)

func (*ClientConn) Close

func (conn *ClientConn) Close() error

func (*ClientConn) CloseWrite added in v0.17.0

func (conn *ClientConn) CloseWrite() error

func (*ClientConn) LocalAddr

func (conn *ClientConn) LocalAddr() net.Addr

func (*ClientConn) Read

func (conn *ClientConn) Read(buf []byte) (int, error)

Reads the next packet from the local client implements server state transitions described in https://raw.githubusercontent.com/GordonMcKinney/gist-assets/master/TCPIP_State_Transition_Diagram.png

func (*ClientConn) RemoteAddr

func (conn *ClientConn) RemoteAddr() net.Addr

func (*ClientConn) SetDeadline

func (conn *ClientConn) SetDeadline(t time.Time) error

func (*ClientConn) SetReadDeadline

func (conn *ClientConn) SetReadDeadline(t time.Time) error

func (*ClientConn) SetWriteDeadline

func (conn *ClientConn) SetWriteDeadline(t time.Time) error

func (ClientConn) String added in v0.17.0

func (conn ClientConn) String() string

func (*ClientConn) Write

func (conn *ClientConn) Write(payload []byte) (int, error)

type TCP

type TCP []byte

func (TCP) AckNumber

func (b TCP) AckNumber() uint32

AckNumber returns the "ack number" field of the tcp header.

func (TCP) CalculateChecksum

func (b TCP) CalculateChecksum(partialChecksum uint16, totalLen uint16) uint16

CalculateChecksum calculates the checksum of the tcp segment given the totalLen and partialChecksum(descriptions below) totalLen is the total length of the segment partialChecksum is the checksum of the network-layer pseudo-header (excluding the total length) and the checksum of the segment data.

func (TCP) Checksum

func (b TCP) Checksum() uint16

Checksum returns the "checksum" field of the tcp header.

func (TCP) DataOffset

func (b TCP) DataOffset() uint8

DataOffset returns the "data offset" field of the tcp header.

func (TCP) DestinationPort

func (b TCP) DestinationPort() uint16

DestinationPort returns the "destination port" field of the tcp header.

func (TCP) Encode

func (b TCP) Encode(t *TCPFields)

Encode encodes all the fields of the tcp header.

func (TCP) EncodePartial

func (b TCP) EncodePartial(partialChecksum, length uint16, seqnum, acknum uint32, flags byte, rcvwnd uint16)

EncodePartial updates a subset of the fields of the tcp header. It is useful in cases when similar segments are produced.

func (TCP) Flags

func (b TCP) Flags() uint8

Flags returns the flags field of the tcp header.

func (TCP) HasFlags

func (b TCP) HasFlags(flags uint8) bool

func (TCP) Payload

func (b TCP) Payload() []byte

Payload returns the data in the tcp packet.

func (TCP) SequenceNumber

func (b TCP) SequenceNumber() uint32

SequenceNumber returns the "sequence number" field of the tcp header.

func (TCP) SetChecksum

func (b TCP) SetChecksum(checksum uint16)

SetChecksum sets the checksum field of the tcp header.

func (TCP) SetDestinationPort

func (b TCP) SetDestinationPort(port uint16)

SetDestinationPort sets the "destination port" field of the tcp header.

func (TCP) SetSourcePort

func (b TCP) SetSourcePort(port uint16)

SetSourcePort sets the "source port" field of the tcp header.

func (TCP) SourcePort

func (b TCP) SourcePort() uint16

SourcePort returns the "source port" field of the tcp header.

func (TCP) WindowSize

func (b TCP) WindowSize() uint16

WindowSize returns the "window size" field of the tcp header.

type TCPFields

type TCPFields struct {
	// SrcPort is the "source port" field of a TCP packet.
	SrcPort uint16

	// DstPort is the "destination port" field of a TCP packet.
	DstPort uint16

	// SeqNum is the "sequence number" field of a TCP packet.
	SeqNum uint32

	// AckNum is the "acknowledgement number" field of a TCP packet.
	AckNum uint32

	// DataOffset is the "data offset" field of a TCP packet.
	DataOffset uint8

	// Flags is the "flags" field of a TCP packet.
	Flags uint8

	// WindowSize is the "window size" field of a TCP packet.
	WindowSize uint16

	// Checksum is the "checksum" field of a TCP packet.
	Checksum uint16

	// UrgentPointer is the "urgent pointer" field of a TCP packet.
	UrgentPointer uint16
}

TCPFields contains the fields of a TCP packet. It is used to describe the fields of a packet that needs to be encoded.

type TCPSynOptions

type TCPSynOptions struct {
	// MSS is the maximum segment size provided by the peer in the SYN.
	MSS uint16

	// WS is the window scale option provided by the peer in the SYN.
	//
	// Set to -1 if no window scale option was provided.
	WS int

	// TS is true if the timestamp option was provided in the syn/syn-ack.
	TS bool

	// TSVal is the value of the TSVal field in the timestamp option.
	TSVal uint32

	// TSEcr is the value of the TSEcr field in the timestamp option.
	TSEcr uint32

	// SACKPermitted is true if the SACK option was provided in the SYN/SYN-ACK.
	SACKPermitted bool
}

func ParseSynOptions

func ParseSynOptions(opts []byte, isAck bool) TCPSynOptions

ParseSynOptions parses the options received in a SYN segment and returns the relevant ones. opts should point to the option part of the TCP Header.

Jump to

Keyboard shortcuts

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