Barrelfish
|
Helper functoin and additional tools used by libbfdmux. More...
Macros | |
#define | MAC_ADDR_SIZE 6 |
Parses a string consisting of hex digits to a byte array. 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_ipv4_icmp_filter (addr_t srcip, addr_t dstip) |
ICMP over IPv4 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_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... | |
Helper functoin and additional tools used by libbfdmux.
#define MAC_ADDR_SIZE 6 |
Parses a string consisting of hex digits to a byte array.
str | The string to be parsed, e.g. "fe01abc9" |
uint8_t * parse_hex_input(char *str) { char hex[3]; int i; int len = strlen(str); if ((len % 2) != 0) { return 0; }
len = len / 2; char *res = malloc(len); hex[2] = 0; for (i = 0; i < len; i++) { hex[0] = str[i * 2]; hex[1] = str[i * 2 + 1]; errno = 0; char *endptr = (char *) uint8_t val = strtol((char *) &hex, &endptr, 16); if ((errno == 0) && (endptr != (char *) &hex)) { res[i] = val; } else { free(res); return 0; } } return (uint8_t *) res; }
char* build_icmp_filter | ( | void | ) |
ICMP filter template.
Create a generic ICMP packet filter
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.
srcip | Filter packets coming from this source IP (BFDMUX_IP_ADDR_ANY for any source) |
dstip | Filter packets going to this destination IP (BFDMUX_IP_ADDR_ANY for any target) |
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.
srcip | Source IP-Address to filter for (BFDMUX_IP_ADDR_ANY for any) |
dstip | Destination IP-Address to filter for (BFDMUX_IP_ADDR_ANY for any) |
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.
srcip | Source IP-Address to filter for (BFDMUX_IP_ADDR_ANY for any) |
dstip | Destination IP-Address to filter for (BFDMUX_IP_ADDR_ANY for any) |
srcport | Source TCP port to filter for (PORT_ANY for any) |
dstport | Destination TCP port to filter for (PORT_ANY for any) |
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.
srcip | Source IP-Address to filter for (BFDMUX_IP_ADDR_ANY for any) |
dstip | Destination IP-Address to filter for (BFDMUX_IP_ADDR_ANY for any) |
srcport | Source UDP port to filter for (PORT_ANY for any) |
dstport | Destination UDP port to filter for (PORT_ANY for any) |
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.
srcport | TCP source port to filter on (PORT_ANY for any port) |
dstport | TCP destination port to filter on (PORT_ANY for any port) |
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.
srcport | UDP source port to filter on (PORT_ANY for any port) |
dstport | UDP destination port to filter on (PORT_ANY for any port) |
|
inline |
Finds the index of the most significant 1-bit in 'value'.
value | The integer to be analyzed |
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!
pos | The position to point at |