Documentation ¶
Index ¶
- Constants
- func AddTCPOptionPadding(options []byte, offset int) int
- func EncodeMSSOption(mss uint32, b []byte) int
- func EncodeNOP(b []byte) int
- func EncodeSACKPermittedOption(b []byte) int
- func EncodeTSOption(tsVal, tsEcr uint32, b []byte) int
- func EncodeWSOption(ws int, b []byte) int
- func Enqueue(context ziti.Context, srcIP, dstIP net.IP, pdu []byte, dev io.ReadWriter, ...) bool
- func RegisterService(service *entities.Service, interceptIP net.IP)
- func UnregisterService(serviceName string)
- type ClientConn
- func (conn *ClientConn) Close() error
- func (conn *ClientConn) LocalAddr() net.Addr
- func (conn *ClientConn) Read(buf []byte) (int, error)
- func (conn *ClientConn) RemoteAddr() net.Addr
- func (conn *ClientConn) SetDeadline(t time.Time) error
- func (conn *ClientConn) SetReadDeadline(t time.Time) error
- func (conn *ClientConn) SetWriteDeadline(t time.Time) error
- func (conn *ClientConn) Write(payload []byte) (int, error)
- type TCP
- func (b TCP) AckNumber() uint32
- func (b TCP) CalculateChecksum(partialChecksum uint16, totalLen uint16) uint16
- func (b TCP) Checksum() uint16
- func (b TCP) DataOffset() uint8
- func (b TCP) DestinationPort() uint16
- func (b TCP) Encode(t *TCPFields)
- func (b TCP) EncodePartial(partialChecksum, length uint16, seqnum, acknum uint32, flags byte, ...)
- func (b TCP) Flags() uint8
- func (b TCP) HasFlags(flags uint8) bool
- func (b TCP) Payload() []byte
- func (b TCP) SequenceNumber() uint32
- func (b TCP) SetChecksum(checksum uint16)
- func (b TCP) SetDestinationPort(port uint16)
- func (b TCP) SetSourcePort(port uint16)
- func (b TCP) SourcePort() uint16
- func (b TCP) WindowSize() uint16
- type TCPFields
- type TCPSynOptions
Constants ¶
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 )
const ( // TCPMinimumSize is the minimum size of a valid TCP packet. TCPMinimumSize = 20 // TCPProtocolNumber is TCP's transport protocol number. TCPProtocolNumber int = 6 )
const ( TCPFlagFin = 1 << iota TCPFlagSyn TCPFlagRst TCPFlagPsh TCPFlagAck TCPFlagUrg )
Flags that may be set in a TCP segment.
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 ¶
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 ¶
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 EncodeSACKPermittedOption ¶
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 ¶
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 ¶
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 UnregisterService ¶
func UnregisterService(serviceName string)
Types ¶
type ClientConn ¶
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) 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
type TCP ¶
type TCP []byte
func (TCP) CalculateChecksum ¶
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) DataOffset ¶
DataOffset returns the "data offset" field of the tcp header.
func (TCP) DestinationPort ¶
DestinationPort returns the "destination port" field 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) SequenceNumber ¶
SequenceNumber returns the "sequence number" field of the tcp header.
func (TCP) SetChecksum ¶
SetChecksum sets the checksum field of the tcp header.
func (TCP) SetDestinationPort ¶
SetDestinationPort sets the "destination port" field of the tcp header.
func (TCP) SetSourcePort ¶
SetSourcePort sets the "source port" field of the tcp header.
func (TCP) SourcePort ¶
SourcePort returns the "source port" field of the tcp header.
func (TCP) WindowSize ¶
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.