MoonGen
 All Files Functions Variables Pages
arp.lua File Reference

Address resolution protocol (ARP) utility. More...

Go to the source code of this file.

Functions

function arpHeader setHardwareAddressType (int)
 Set the hardware address type. More...
 
function arpHeader getHardwareAddressType ()
 Retrieve the hardware address type. More...
 
function arpHeader getHardwareAddressTypeString ()
 Retrieve the hardware address type. More...
 
function arpHeader setProtoAddressType (int)
 Set the protocol address type. More...
 
function arpHeader getProtoAddressType ()
 Retrieve the protocol address type. More...
 
function arpHeader getProtoAddressTypeString ()
 Retrieve the protocol address type. More...
 
function arpHeader setHardwareAddressLength (int)
 Set the hardware address length. More...
 
function arpHeader getHardwareAddressLength ()
 Retrieve the hardware address length. More...
 
function arpHeader getHardwareAddressLengthString ()
 Retrieve the hardware address length. More...
 
function arpHeader setProtoAddressLength (int)
 Set the protocol address length. More...
 
function arpHeader getProtoAddressLength ()
 Retrieve the protocol address length. More...
 
function arpHeader getProtoAddressLengthString ()
 Retrieve the protocol address length. More...
 
function arpHeader setOperation (int)
 Set the operation. More...
 
function arpHeader getOperation ()
 Retrieve the operation. More...
 
function arpHeader getOperationString ()
 Retrieve the operation. More...
 
function arpHeader setHardwareSrc (addr)
 Set the hardware source address. More...
 
function arpHeader getHardwareSrc ()
 Retrieve the hardware source address. More...
 
function arpHeader setHardwareSrcString (addr)
 Set the hardware source address. More...
 
function arpHeader getHardwareSrcString ()
 Retrieve the hardware source address. More...
 
function arpHeader setHardwareDst (addr)
 Set the hardware destination address. More...
 
function arpHeader getHardwareDst ()
 Retrieve the hardware destination address. More...
 
function arpHeader setHardwareDstString (addr)
 Set the hardware destination address. More...
 
function arpHeader getHardwareDstString ()
 Retrieve the hardware destination address. More...
 
function arpHeader setProtoSrc (addr)
 Set the protocol source address. More...
 
function arpHeader getProtoSrc ()
 Retrieve the protocol source address. More...
 
function arpHeader setProtoSrcString (addr)
 Set the protocol source address. More...
 
function arpHeader getProtoSrcString ()
 Retrieve the protocol source address. More...
 
function arpHeader setProtoDst (addr)
 Set the protocol destination address. More...
 
function arpHeader getProtoDst ()
 Retrieve the protocol destination address. More...
 
function arpHeader setProtoDstString (addr)
 Set the protocol destination address. More...
 
function arpHeader getProtoDstString ()
 Retrieve the protocol destination address. More...
 
function arpHeader fill (args, pre)
 Set all members of the ip header. More...
 
function arpHeader get (pre)
 Retrieve the values of all members. More...
 
function arpHeader getString ()
 Retrieve the values of all members. More...
 
function arpHeader resolveNextHeader ()
 Resolve which header comes after this one (in a packet). More...
 
function arpHeader setDefaultNamedArgs (pre, namedArgs, nextHeader, accumulatedLength)
 Change the default values for namedArguments (for fill/get). More...
 
local function arpTask (qs)
 Arp handler task. More...
 
function arp lookup (ip)
 Perform a lookup in the ARP table. More...
 
function arp blockingLookup (ip, timeout)
 Perform a non-blocking lookup in the ARP table. More...
 

Variables

local arp = {}
 Arp protocol constants.
 
arp HARDWARE_ADDRESS_TYPE_ETHERNET = 1
 Hardware address type for ethernet.
 
arp PROTO_ADDRESS_TYPE_IP = 0x0800
 Proto address type for IP (for ethernet based protocols uses etherType numbers ethernet.lua)
 
arp OP_REQUEST = 1
 Operation: request.
 
arp OP_REPLY = 2
 Operation: reply.
 
local arpHeader = {}
 Module for arp_header struct (see headers.lua).
 
pkt getArpPacket = packetCreate("eth", "arp")
 Cast the packet to an Arp packet.
 
arp arpTask = "__MG_ARP_TASK"
 Arp handler task, responds to ARP queries for given IPs and performs arp lookups. More...
 
local arpTable = ns:get()
 Arp table TODO docu.
 

Detailed Description

Address resolution protocol (ARP) utility.

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

  • Arp constants
  • Arp address utility
  • Arp header utility
  • Definition of Arp packets
  • Arp handler task

Definition in file arp.lua.

Function Documentation

local function arpTask ( qs  )

Arp handler task.

Parameters
qsTODO
Todo:
TODO docu
function arp blockingLookup ( ip  ,
timeout   
)

Perform a non-blocking lookup in the ARP table.

Parameters
ipThe ip address in string or cdata format to look up.
timeoutTODO
Todo:
FIXME: this only sends a single request
function arpHeader 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: HardwareAddressType, ProtoAddressType, HardwareAddressLength, ProtoAddressLength, Operation, HardwareSrc, HardwareDst, ProtoSrc, ProtoDst
preprefix for namedArgs. Default 'arp'.
fill() --- only default values
fill{ arpOperation=2, ipTTL=100 } --- all members are set to default values with the exception of arpOperation
function arpHeader get ( pre  )

Retrieve the values of all members.

Parameters
preprefix for namedArgs. Default 'arp'.
Returns
Table of named arguments. For a list of arguments see "See also".
See Also
arpHeader:fill
function arpHeader getHardwareAddressLength ( )

Retrieve the hardware address length.

Returns
Length as 8 bit integer.
function arpHeader getHardwareAddressLengthString ( )

Retrieve the hardware address length.

Returns
Length in string format.
function arpHeader getHardwareAddressType ( )

Retrieve the hardware address type.

Returns
Type as 16 bit integer.
function arpHeader getHardwareAddressTypeString ( )

Retrieve the hardware address type.

Returns
Type in string format.
function arpHeader getHardwareDst ( )

Retrieve the hardware destination address.

Returns
Address in 'struct mac_address' format.
function arpHeader getHardwareDstString ( )

Retrieve the hardware destination address.

Returns
Address in string format.
function arpHeader getHardwareSrc ( )

Retrieve the hardware source address.

Returns
Address in 'struct mac_address' format.
function arpHeader getHardwareSrcString ( )

Retrieve the hardware source address.

Returns
Address in string format.
function arpHeader getOperation ( )

Retrieve the operation.

Returns
Operation as 16 bit integer.
function arpHeader getOperationString ( )

Retrieve the operation.

Returns
Operation in string format.
function arpHeader getProtoAddressLength ( )

Retrieve the protocol address length.

Returns
Length as 8 bit integer.
function arpHeader getProtoAddressLengthString ( )

Retrieve the protocol address length.

Returns
Length in string format.
function arpHeader getProtoAddressType ( )

Retrieve the protocol address type.

Returns
Type as 16 bit integer.
function arpHeader getProtoAddressTypeString ( )

Retrieve the protocol address type.

Returns
Type in string format.
function arpHeader getProtoDst ( )

Retrieve the protocol destination address.

Returns
Address in 'struct ip4_address' format.
function arpHeader getProtoDstString ( )

Retrieve the protocol destination address.

Returns
Address in string format.
function arpHeader getProtoSrc ( )

Retrieve the protocol source address.

Returns
Address in 'struct ip4_address' format.
function arpHeader getProtoSrcString ( )

Retrieve the protocol source address.

Returns
Address in string format.
function arpHeader getString ( )

Retrieve the values of all members.

Returns
Values in string format.
function arp lookup ( ip  )

Perform a lookup in the ARP table.

Lookup the MAC address for a given IP. Blocks for up to 1 second if the arp task is not yet running Caution: this function uses locks and namespaces, must not be used in the fast path

Parameters
ipThe ip address in string or cdata format to look up.
function arpHeader 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 arpHeader 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. 'arp'
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
arpHeader:fill
function arpHeader setHardwareAddressLength ( int  )

Set the hardware address length.

Parameters
intLength as 8 bit integer.
function arpHeader setHardwareAddressType ( int  )

Set the hardware address type.

Parameters
intType as 16 bit integer.
function arpHeader setHardwareDst ( addr  )

Set the hardware destination address.

Parameters
addrAddress in 'struct mac_address' format.
function arpHeader setHardwareDstString ( addr  )

Set the hardware destination address.

Parameters
addrAddress in string format.
function arpHeader setHardwareSrc ( addr  )

Set the hardware source address.

Parameters
addrAddress in 'struct mac_address' format.
function arpHeader setHardwareSrcString ( addr  )

Set the hardware source address.

Parameters
addrAddress in string format.
function arpHeader setOperation ( int  )

Set the operation.

Parameters
intOperation as 16 bit integer.
function arpHeader setProtoAddressLength ( int  )

Set the protocol address length.

Parameters
intLength as 8 bit integer.
function arpHeader setProtoAddressType ( int  )

Set the protocol address type.

Parameters
intType as 16 bit integer.
function arpHeader setProtoDst ( addr  )

Set the protocol destination address.

Parameters
addrAddress in 'struct ip4_address' format.
function arpHeader setProtoDstString ( addr  )

Set the protocol destination address.

Parameters
addrAddress in string format.
function arpHeader setProtoSrc ( addr  )

Set the protocol source address.

Parameters
addrAddress in 'struct ip4_address' format.
function arpHeader setProtoSrcString ( addr  )

Set the protocol source address.

Parameters
addrAddress in source format.

Variable Documentation

arp arpTask = "__MG_ARP_TASK"

Arp handler task, responds to ARP queries for given IPs and performs arp lookups.

Todo:

TODO implement garbage collection/refreshing entries
the current implementation does not handle large tables efficiently

TODO multi-NIC support

Definition at line 233 of file arp.lua.