7.4. Tcp

Tcp state-less dissector module.

Usage:

local tcp = require('protocol/tcp')

7.4.1. Dissector

dissector TcpDissector
Name :'tcp'
Extend :haka.helper.PacketDissector 

Dissector data for a TCP packet. This dissector is state-less. It will only parse the packet headers.

tcp.create(ip) → tcp
Parameters:
Returns:

Create a new TCP packet on top of the given IP packet.

<TcpDissector>.srcport
<TcpDissector>.dstport
<TcpDissector>.seq
<TcpDissector>.ack_seq
<TcpDissector>.res
<TcpDissector>.hdr_len
<TcpDissector>.window_size
<TcpDissector>.checksum
<TcpDissector>.urgent_pointer
Type:number

TCP fields.

<TcpDissector>.flags.fin
<TcpDissector>.flags.syn
<TcpDissector>.flags.rst
<TcpDissector>.flags.psh
<TcpDissector>.flags.ack
<TcpDissector>.flags.urg
<TcpDissector>.flags.ecn
<TcpDissector>.flags.cwr
Type:boolean

TCP flags.

<TcpDissector>.flags.all
Type:number

All flags raw value.

<TcpDissector>.payload
Type:vbuffer 

Payload of the packet.

const <TcpDissector>.ip
Type:Ipv4Dissector 

IPv4 packet.

<TcpDissector>:verify_checksum() → correct
Returns:
  • correct (boolean) – true if the checksum is correct.

Verify if the checksum is correct.

<TcpDissector>:compute_checksum()

Recompute the checksum and set the resulting value in the packet.

<TcpDissector>:drop()

Drop the TCP packet.

<TcpDissector>:send()

Send the packet.

<TcpDissector>:inject()

Inject the packet.

7.4.2. Events

event tcp.events.receive_packet(pkt)
Parameters:

Event that is triggered whenever a new packet is received.

event tcp.events.send_packet(pkt)
Parameters:

Event that is triggered just before sending a packet on the network.

7.4.3. Utilities

Warning

This section introduces advanced feature of Haka.

object tcp_stream

TCP stream helper object.

tcp.tcp_stream() → stream
Returns:

Create a new TCP stream.

<tcp_stream>:init(seq)
Parameters:
  • seq (number) – Initial sequence number for this stream.

Initialize the initial sequence number of the stream.

<tcp_stream>:push(tcp)
Parameters:

Push a tcp packet into the stream.

<tcp_stream>:pop() → tcp
Returns:

Pop a tcp packet out of the stream.

<tcp_stream>:seq(tcp)
Parameters:

Update the sequence number of a tcp packet.

<tcp_stream>:ack(tcp)
Parameters:

Update the ack number of a packet.

<tcp_stream>:clear()

Clear the stream and drop all remaining packets.

<tcp_stream>.stream
Type:vbuffer_stream

Associated raw stream.

const <tcp_stream>.lastseq
Type:number

Last received sequence number.