Matchers¶
Matchers are defined such as:
$TYPE [not] [$OP] $PAYLOAD
- With:
$TYPE: type of the matcher, defines which part of the processed network packet needs to be compared against. All the exact matcher types are defined below.not: optional comparison negation. When used, it prefixes an operator, e.g.tcp.sport not eq 80,(ip4.saddr) not in foo, or, with no operator,tcp.sport not 80(equivalent totcp.sport not eq 80).$OP: comparison operation, not all$TYPEof matchers support all the existing comparison operators:eq: exact equality. This is the default if no$OPis provided.any: match the packet against a set of data defined as the payload. If any of the member of the payload set is found in the packet, the matcher is positive. For example, if you want to match all the packets with theSYNor theACKflag set:tcp.flags any syn,ack.all: match the packet against a set of data defined as the payload. If all the member of the payload set are found in the packet, the matcher is positive, even if the packet contains more than only the members defined in the payload. For example, to match all the packets containing at least theACKTCP flag:tcp.flags all ACK.in: matches the packet against a hashed set of reference values. Using theinoperator is useful when the packet’s data needs to be compared against a large set of different values. The matcher’s type is then used as the set’s key, and must be enclosed in parentheses:(ip4.saddr) in {192.0.2.1; 192.0.2.2}is valid,ip4.saddr in {...}is not. The tables below describe the payload for a key made of a single matcher. See Sets to combine multiple matchers in a key, to use named sets, and for the list of matchers supported by sets.range: matches in a range of values. Formatted as$START-$END. Both$STARTand$ENDare included in the range.
$PAYLOAD: payload to compare to the processed network packet. The exact payload format depends on$TYPE.
Meta¶
Matches |
Type |
Operator |
Payload |
Notes |
|---|---|---|---|---|
Interface |
|
|
|
For chains attached to an ingress hook, |
L3 protocol |
|
|
|
|
L4 protocol |
|
|
|
|
Source port |
|
|
|
|
|
|
|||
|
|
|
||
Destination port |
|
|
|
|
|
|
|||
|
|
|
||
Probability |
|
|
|
|
Mark |
|
|
|
|
Flow hash |
|
|
|
|
|
|
|
||
Flow probability |
|
|
|
|
Process ID |
|
|
|
|
|
|
Note
On packet-based hooks, meta.sport and meta.dport are protocol-neutral across TCP and UDP. They do not match packets with other L4 protocols.
IPv4¶
Matches |
Type |
Operator |
Payload |
Notes |
|---|---|---|---|---|
Source address |
|
|
|
|
|
|
|||
Destination address |
|
|
|
|
|
|
|||
Source network |
|
|
|
|
|
|
|||
Destination network |
|
|
|
|
|
|
|||
Protocol |
|
|
|
|
DSCP |
|
|
|
|
IPv6¶
Matches |
Type |
Operator |
Payload |
Notes |
|---|---|---|---|---|
Source address |
|
|
|
|
|
|
|||
Destination address |
|
|
|
|
|
|
|||
Source network |
|
|
|
|
|
|
|||
Destination network |
|
|
|
|
|
|
|||
Next header |
|
|
|
|
DSCP |
|
|
|
|
Tip
The following IPv6 extension header names are recognized by bpfilter: hop, routing, frag, ah, dst, mh.
TCP¶
Matches |
Type |
Operator |
Payload |
Notes |
|---|---|---|---|---|
Source port |
|
|
|
|
|
|
|||
|
|
|
||
Destination port |
|
|
|
|
|
|
|||
|
|
|
||
Flags |
|
|
|
|
|
||||
|
Tip
The tcp.flags operators can be confusing, as they can be used to match all, some, or none of the flags available in the TCP header. This section aims to provide clarity to their exact behavior:
eq: the TCP header must contain the exact same flags as defined in the rule. The matchertcp.flags eq syn,ackwill matchsyn,ack, but notsyn,ack,finnorrst.any: the TCP header must contain any of the flags defined in the rule. The matchertcp.flags any syn,ackwill matchsyn, orack, orsyn,ack, but notfin.all: the TCP header must contain at least the flags defined in the rule. The matchertcp.flags all syn,ackwill matchsyn,ack,fin, but notsyn, orack,fin.
Each operator can be negated with not to invert the match:
not eq: the TCP header must not contain the exact same flags. The matchertcp.flags not eq synwill matchack, orsyn,ack, but notsynalone.not any: none of the specified flags may be present. The matchertcp.flags not any syn,ackwill matchfinorrst, but notsyn,ack, orsyn,ack.not all: not all of the specified flags are present. The matchertcp.flags not all syn,ackwill matchsynorackalone, but notsyn,ackorsyn,ack,fin.
UDP¶
Matches |
Type |
Operator |
Payload |
Notes |
|---|---|---|---|---|
Source port |
|
|
|
|
|
|
|||
|
|
|
||
Destination port |
|
|
|
|
|
|
|||
|
|
|
ICMP¶
Matches |
Type |
Operator |
Payload |
Notes |
|---|---|---|---|---|
Type |
|
|
|
|
Code |
|
|
|
|
Tip
The following ICMP type names are recognized by bpfilter: echo-reply, destination-unreachable, source-quench, redirect, echo-request, time-exceeded, parameter-problem, timestamp-request, timestamp-reply, info-request, info-reply, address-mask-request, address-mask-reply, router-advertisement, router-solicitation.
ICMPv6¶
Matches |
Type |
Operator |
Payload |
Notes |
|---|---|---|---|---|
Type |
|
|
|
|
Code |
|
|
|
|
Tip
The following ICMPv6 type names are recognized by bpfilter: destination-unreachable, packet-too-big, time-exceeded, echo-request, echo-reply, mld-listener-query, mld-listener-report, mld-listener-reduction, nd-router-solicit, nd-router-advert, nd-neighbor-solicit, nd-neighbor-advert, parameter-problem, mld2-listener-report.