Barrelfish
Functions
tools.h File Reference

Header file for helper and additional functions. More...

Functions

int find_msb (uint64_t value)
 Finds the index of the most significant 1-bit in 'value'. More...
 
char * get_error_position_string (int pos)
 Returns a string with pos-1 spaces and a '^' character. Used to indicate error position in filter string! More...
 
char * build_ipv4_filter (addr_t srcip, addr_t dstip)
 IPv4 filter template. More...
 
char * build_icmp_filter (void)
 ICMP filter template. More...
 
char * build_tcp_filter (port_t srcport, port_t dstport)
 TCP filter template. More...
 
char * build_udp_filter (port_t srcport, port_t dstport)
 UDP filter template. More...
 
char * build_ipv4_icmp_filter (addr_t srcip, addr_t dstip)
 ICMP over IPv4 filter template. More...
 
char * build_ipv4_tcp_filter (addr_t srcip, addr_t dstip, port_t srcport, port_t dstport)
 TCP over IPv4 filter template. More...
 
char * build_ipv4_udp_filter (addr_t srcip, addr_t dstip, port_t srcport, port_t dstport)
 UDP over IPv4 filter template. More...
 

Detailed Description

Header file for helper and additional functions.

Function Documentation

char* build_icmp_filter ( void  )

ICMP filter template.

Create a generic ICMP packet filter

Returns
A filter sting. Caller has to free it after use.
char* build_ipv4_filter ( addr_t  srcip,
addr_t  dstip 
)

IPv4 filter template.

Create an IPv4 filter based on a source IP and a destination IP. The source IP is a 32bit field in the IPv4 header starting at offset 12Bytes, the destination IP is also a 32bit field starting at 16Bytes.

Parameters
srcipFilter packets coming from this source IP (BFDMUX_IP_ADDR_ANY for any source)
dstipFilter packets going to this destination IP (BFDMUX_IP_ADDR_ANY for any target)
Returns
A filter string. Caller has to free it after use.
char* build_ipv4_icmp_filter ( addr_t  srcip,
addr_t  dstip 
)

ICMP over IPv4 filter template.

This function build a ICMP over IPv4 filter based on the given arguments using the build_tcp_filter and build_ipv4_filter helper functions.

Parameters
srcipSource IP-Address to filter for (BFDMUX_IP_ADDR_ANY for any)
dstipDestination IP-Address to filter for (BFDMUX_IP_ADDR_ANY for any)
Returns
A filter string. Caller has to free it after use.
char* build_ipv4_tcp_filter ( addr_t  srcip,
addr_t  dstip,
port_t  srcport,
port_t  dstport 
)

TCP over IPv4 filter template.

This function build a TCP over IPv4 filter based on the given arguments using the build_tcp_filter and build_ipv4_filter helper functions.

Parameters
srcipSource IP-Address to filter for (BFDMUX_IP_ADDR_ANY for any)
dstipDestination IP-Address to filter for (BFDMUX_IP_ADDR_ANY for any)
srcportSource TCP port to filter for (PORT_ANY for any)
dstportDestination TCP port to filter for (PORT_ANY for any)
Returns
A filter string. Caller has to free it after use.
char* build_ipv4_udp_filter ( addr_t  srcip,
addr_t  dstip,
port_t  srcport,
port_t  dstport 
)

UDP over IPv4 filter template.

This function build a UDP over IPv4 filter based on the given arguments using the build_tcp_filter and build_ipv4_filter helper functions.

Parameters
srcipSource IP-Address to filter for (BFDMUX_IP_ADDR_ANY for any)
dstipDestination IP-Address to filter for (BFDMUX_IP_ADDR_ANY for any)
srcportSource UDP port to filter for (PORT_ANY for any)
dstportDestination UDP port to filter for (PORT_ANY for any)
Returns
A filter string. Caller has to free it after use.
char* build_tcp_filter ( port_t  srcport,
port_t  dstport 
)

TCP filter template.

Create a TCP filter based on the source and destination TCP Port. This filter looks for the TCP protocol number (0x06) in the IP header and sets the 16bit long source port field positioned at offset 20Bytes (with IP header) and the 16bit long destination port filed positioned at offset 22Bytes to the given arguments.

Parameters
srcportTCP source port to filter on (PORT_ANY for any port)
dstportTCP destination port to filter on (PORT_ANY for any port)
Returns
A filter sting. Caller has to free it after use.
char* build_udp_filter ( port_t  srcport,
port_t  dstport 
)

UDP filter template.

Create a UDP filter based on the source and destination UDP Port. This filter looks for the UDP protocol number (0x11) in the IP header and sets the 16bit long source port field positioned at offset 20Bytes (with IP header) and the 16bit long destination port filed positioned at offset 22Bytes to the given arguments.

Parameters
srcportUDP source port to filter on (PORT_ANY for any port)
dstportUDP destination port to filter on (PORT_ANY for any port)
Returns
A filter sting. Caller has to free it after use.
int find_msb ( uint64_t  value)
inline

Finds the index of the most significant 1-bit in 'value'.

Parameters
valueThe integer to be analyzed
Returns
The index of the most significant 1-bit in value (bits numbered 1..64); 0 if value = 0.
char* get_error_position_string ( int  pos)

Returns a string with pos-1 spaces and a '^' character. Used to indicate error position in filter string!

Parameters
posThe position to point at
Returns
A string with a '^' character at the given position. Caller should free memory after use!