MoonGen
 All Files Functions Variables Pages
tcp.lua File Reference

Transmission control protocol (TCP) utility. More...

Go to the source code of this file.

Functions

function tcpHeader setSrcPort (int)
 Set the source port. More...
 
function tcpHeader getSrcPort ()
 Retrieve the source port. More...
 
function tcpHeader getSrcPortString ()
 Retrieve the source port. More...
 
function tcpHeader setDstPort (int)
 Set the destination port. More...
 
function tcpHeader getDstPort ()
 Retrieve the destination port. More...
 
function tcpHeader getDstPortString ()
 Retrieve the destination port. More...
 
function tcpHeader setSeqNumber (int)
 Set the sequence number. More...
 
function tcpHeader getSeqNumber ()
 Retrieve the sequence number. More...
 
function tcpHeader getSeqNumberString ()
 Retrieve the sequence number. More...
 
function tcpHeader setAckNumber (int)
 Set the acknowledgement number. More...
 
function tcpHeader getAckNumber ()
 Retrieve the acknowledgement number. More...
 
function tcpHeader getAckNumberString ()
 Retrieve the acknowledgement number. More...
 
function tcpHeader setDataOffset (int)
 Set the data offset. More...
 
function tcpHeader getDataOffset ()
 Retrieve the data offset. More...
 
function tcpHeader getDataOffsetString ()
 Retrieve the data offset. More...
 
function tcpHeader setReserved (int)
 Set the reserved field. More...
 
function tcpHeader getReserved ()
 Retrieve the reserved field. More...
 
function tcpHeader getReservedString ()
 Retrieve the reserved field. More...
 
function tcpHeader setFlags (int)
 Set the flags. More...
 
function tcpHeader getFlags ()
 Retrieve the flags. More...
 
function tcpHeader getFlagsString ()
 Retrieve the flags. More...
 
function tcpHeader setUrg ()
 Set the Urg flag.
 
function tcpHeader unsetUrg ()
 Unset the Urg flag.
 
function tcpHeader getUrg ()
 Retrieve the Urg flag. More...
 
function tcpHeader getUrgString ()
 Retrieve the Urg flag. More...
 
function tcpHeader setAck ()
 Set the Ack flag.
 
function tcpHeader unsetAck ()
 Unset the Ack flag.
 
function tcpHeader getAck ()
 Retrieve the Ack flag. More...
 
function tcpHeader getAckString ()
 Retrieve the Ack flag. More...
 
function tcpHeader setPsh ()
 Set the Psh flag.
 
function tcpHeader unsetPsh ()
 Unset the Psh flag.
 
function tcpHeader getPsh ()
 Retrieve the Psh flag. More...
 
function tcpHeader getPshString ()
 Retrieve the Psh flag. More...
 
function tcpHeader setRst ()
 Set the Rst flag.
 
function tcpHeader unsetRst ()
 Unset the Rst flag.
 
function tcpHeader getRst ()
 Retrieve the Rst flag. More...
 
function tcpHeader getRstString ()
 Retrieve the Rst flag. More...
 
function tcpHeader setSyn ()
 Set the Syn flag.
 
function tcpHeader unsetSyn ()
 Unset the Syn flag.
 
function tcpHeader getSyn ()
 Retrieve the Syn flag. More...
 
function tcpHeader getSynString ()
 Retrieve the Syn flag. More...
 
function tcpHeader setFin ()
 Set the Fin flag.
 
function tcpHeader unsetFin ()
 Unset the Fin flag.
 
function tcpHeader getFin ()
 Retrieve the Fin flag. More...
 
function tcpHeader getFinString ()
 Retrieve the Fin flag. More...
 
function tcpHeader setWindow (int)
 Set the window field. More...
 
function tcpHeader getWindow ()
 Retrieve the window field. More...
 
function tcpHeader getWindowString ()
 Retrieve the window field. More...
 
function tcpHeader setChecksum (int)
 Set the checksum. More...
 
function tcpHeader calculateChecksum (len)
 Calculate the checksum. More...
 
function tcpHeader getChecksum ()
 Retrieve the checksum. More...
 
function tcpHeader getChecksumString ()
 Retrieve the checksum. More...
 
function tcpHeader setUrgentPointer (int)
 Set the urgent pointer. More...
 
function tcpHeader getUrgentPointer ()
 Retrieve the urgent pointer. More...
 
function tcpHeader getUrgentPointerString ()
 Retrieve the urgent pointer. More...
 
function tcpHeader fill (args, pre)
 Set all members of the ip header. More...
 
function tcpHeader get (pre)
 Retrieve the values of all members. More...
 
function tcpHeader getString ()
 Retrieve the values of all members. More...
 
function tcpHeader resolveNextHeader ()
 Resolve which header comes after this one (in a packet). More...
 
function tcpHeader setDefaultNamedArgs (pre, namedArgs, nextHeader, accumulatedLength)
 Change the default values for namedArguments (for fill/get). More...
 

Variables

local tcpHeader = {}
 Module for tcp_header struct (see headers.lua).
 
pkt getTcp4Packet = packetCreate("eth", "ip4", "tcp")
 Cast the packet to a Tcp (IP4) packet.
 
pkt getTcp6Packet = packetCreate("eth", "ip6", "tcp")
 Cast the packet to a Tcp (IP6) packet.
 
pkt getTcpPacket = function(self, ip4)
 Cast the packet to a Tcp packet, either using IP4 (nil/true) or IP6 (false), depending on the passed boolean.
 

Detailed Description

Transmission control protocol (TCP) utility.

Utility functions for the tcp_header struct defined in headers.lua .
Includes:

  • TCP constants
  • TCP header utility
  • Definition of TCP packets

Definition in file tcp.lua.

Function Documentation

function tcpHeader calculateChecksum ( len  )

Calculate the checksum.

Parameters
lenNumber of bytes to calculate the checksum over.
Todo:
FIXME NYI
function tcpHeader fill ( args  ,
pre   
)

Set all members of the ip header.

Per default, all members are set to default values specified in the respective set function. Optional named arguments can be used to set a member to a user-provided value.

Parameters
argsTable of named arguments. Available arguments: Src, Dst, SeqNumber, AckNumber, DataOffset, Reserved, Flags, Urg, Ack, Psh, Rst, Syn, Fin, Window, Checksum, UrgentPointer
preprefix for namedArgs. Default 'tcp'.
fill() --- only default values
fill{ tcpSrc=1234, ipTTL=100 } --- all members are set to default values with the exception of tcpSrc
function tcpHeader get ( pre  )

Retrieve the values of all members.

Returns
Table of named arguments. For a list of arguments see "See also".
See Also
tcpHeader:fill
function tcpHeader getAck ( )

Retrieve the Ack flag.

Returns
Flag as 1 bit integer.
function tcpHeader getAckNumber ( )

Retrieve the acknowledgement number.

Returns
Seq number as 8 bit integer.
function tcpHeader getAckNumberString ( )

Retrieve the acknowledgement number.

Returns
Ack number in string format.
function tcpHeader getAckString ( )

Retrieve the Ack flag.

Returns
Flag in string format.
function tcpHeader getChecksum ( )

Retrieve the checksum.

Returns
Checksum as 16 bit integer.
function tcpHeader getChecksumString ( )

Retrieve the checksum.

Returns
Checksum in string format.
function tcpHeader getDataOffset ( )

Retrieve the data offset.

Returns
Offset as 4 bit integer.
function tcpHeader getDataOffsetString ( )

Retrieve the data offset.

Returns
Offset in string format.
function tcpHeader getDstPort ( )

Retrieve the destination port.

Returns
Port as 16 bit integer.
Examples:
quality-of-service-test.lua.
function tcpHeader getDstPortString ( )

Retrieve the destination port.

Returns
Port in string format.
function tcpHeader getFin ( )

Retrieve the Fin flag.

Returns
Flag as 1 bit integer.
function tcpHeader getFinString ( )

Retrieve the Fin flag.

Returns
Flag in string format.
function tcpHeader getFlags ( )

Retrieve the flags.

Returns
Flags as 6 bit integer.
function tcpHeader getFlagsString ( )

Retrieve the flags.

Returns
Flags in string format.
function tcpHeader getPsh ( )

Retrieve the Psh flag.

Returns
Flag as 1 bit integer.
function tcpHeader getPshString ( )

Retrieve the Psh flag.

Returns
Flag in string format.
function tcpHeader getReserved ( )

Retrieve the reserved field.

Returns
Reserved field as 6 bit integer.
function tcpHeader getReservedString ( )

Retrieve the reserved field.

Returns
Reserved field in string format.
function tcpHeader getRst ( )

Retrieve the Rst flag.

Returns
Flag as 1 bit integer.
function tcpHeader getRstString ( )

Retrieve the Rst flag.

Returns
Flag in string format.
function tcpHeader getSeqNumber ( )

Retrieve the sequence number.

Returns
Seq number as 8 bit integer.
function tcpHeader getSeqNumberString ( )

Retrieve the sequence number.

Returns
Sequence number in string format.
function tcpHeader getSrcPort ( )

Retrieve the source port.

Returns
Port as 16 bit integer.
function tcpHeader getSrcPortString ( )

Retrieve the source port.

Returns
Port in string format.
function tcpHeader getString ( )

Retrieve the values of all members.

Returns
Values in string format.
function tcpHeader getSyn ( )

Retrieve the Syn flag.

Returns
Flag as 1 bit integer.
function tcpHeader getSynString ( )

Retrieve the Syn flag.

Returns
Flag in string format.
function tcpHeader getUrg ( )

Retrieve the Urg flag.

Returns
Flag as 1 bit integer.
function tcpHeader getUrgentPointer ( )

Retrieve the urgent pointer.

Returns
Urgent pointer as 16 bit integer.
function tcpHeader getUrgentPointerString ( )

Retrieve the urgent pointer.

Returns
Urgent pointer in string format.
function tcpHeader getUrgString ( )

Retrieve the Urg flag.

Returns
Flag in string format.
function tcpHeader getWindow ( )

Retrieve the window field.

Returns
Window as 16 bit integer.
function tcpHeader getWindowString ( )

Retrieve the window field.

Returns
Window in string format.
function tcpHeader resolveNextHeader ( )

Resolve which header comes after this one (in a packet).

For instance: in tcp/udp based on the ports. This function must exist and is only used when get/dump is executed on an unknown (mbuf not yet casted to e.g. tcpv6 packet) packet (mbuf)

Returns
String next header (e.g. 'udp', 'icmp', nil)
function tcpHeader setAckNumber ( int  )

Set the acknowledgement number.

Parameters
intAck number as 8 bit integer.
function tcpHeader setChecksum ( int  )

Set the checksum.

Parameters
intChecksum as 16 bit integer.
function tcpHeader setDataOffset ( int  )

Set the data offset.

Parameters
intOffset as 4 bit integer. Header size is counted in 32 bit words (min. 5 (no options), max. 15)
function tcpHeader setDefaultNamedArgs ( pre  ,
namedArgs  ,
nextHeader  ,
accumulatedLength   
)

Change the default values for namedArguments (for fill/get).

This can be used to for instance calculate a length value based on the total packet length. See proto/ip4.setDefaultNamedArgs as an example. This function must exist and is only used by packet.fill.

Parameters
preThe prefix used for the namedArgs, e.g. 'tcp'
namedArgsTable of named arguments (see See Also)
nextHeaderThe header following after this header in a packet
accumulatedLengthThe so far accumulated length for previous headers in a packet
Returns
Table of namedArgs
See Also
tcpHeader:fill
function tcpHeader setDstPort ( int  )

Set the destination port.

Parameters
intPort as 16 bit integer.
function tcpHeader setFlags ( int  )

Set the flags.

Parameters
intFlags as 6 bit integer.
Todo:
TODO RFC 3168 specifies new CWR and ECE flags (reserved reduced to 4 bit)
function tcpHeader setReserved ( int  )

Set the reserved field.

Parameters
intReserved field as 6 bit integer.
function tcpHeader setSeqNumber ( int  )

Set the sequence number.

Parameters
intSequence number as 8 bit integer.
function tcpHeader setSrcPort ( int  )

Set the source port.

Parameters
intPort as 16 bit integer.
function tcpHeader setUrgentPointer ( int  )

Set the urgent pointer.

Parameters
intUrgent pointer as 16 bit integer.
function tcpHeader setWindow ( int  )

Set the window field.

Parameters
intWindow as 16 bit integer.