Page tree
Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 5 Next »

PCAP-filters are used for the following purposes:

  • Selecting an appropriate switching group when a packet is received through eth* interface. The packet will be switched only by the group that fully satisfies the rules.
  • When the packet is chosen by the switching group the group decides whether this packet needs to be sent through one of the interfaces. The packet will only be sent if it satisfies the rules of this interface.

The rules consist of a "rules list" and a decision by default (deny/permit). Each rule consists of a condition and a decision (deny/permit). While going through the list, the switch checks whether a packet matches the rule. If it matches the rule, the decision set for this rule is applied to the packet.

Otherwise, the list of rules is viewed further. Rules are taken one at a time. If a packet does not match to any rule, the default decision for this group or interface is taken.

The expression selects which packets will fit into the group. Only packets for which expression is 'true' will be matched to the group. The expression consists of one or more primitives. Primitives usually consist of an id (name or number) preceeded by one or more qualifiers.



Detailed filter expression syntax description

Filter expression determines which packets will be selected by the filter for further processing. If no expression is given, all packets on the net will be selected. Otherwise, only packets for which expression is `true' will be selected.

The expression consists of one or more primitives. Primitives usually consist of an id (name or number) preceded by one or more qualifiers. There are three different kinds of qualifier:

  • typequalifiers say what kind of thing the id name or number refers to. Possible types are hostnet , port and portrange. E.g., `host foo', `net 128.3', `port 20', `portrange 6000-6008'. If there is no type qualifier, host is assumed.
  • dirqualifiers specify a particular transfer direction to and/or from id. Possible directions are srcdstsrc or dst and src and dst. E.g., `src 1.1.1.1', `dst net 128.3', `src or dst port 21'. If there is no dir qualifier, src or dst is assumed.
  • protoqualifiers restrict the match to a particular protocol. Possible protos are: etheripip6arprarptcp and udp. E.g., `ether src 00:12:13:14:15:16', `arp net 128.3', `tcp port 21', `udp portrange 7000-7009'. If there is no proto qualifier, all protocols consistent with the type are assumed. E.g., `src 1.1.1.1' means `(ip or arp or rarp) src foo' (except the latter is not legal syntax), `net 1.2.3.0/24' means `(ip or arp or rarp) net 1.2.3.0/24' and `port 53' means `(tcp or udp) port 53'.

In addition to the above, there are some special `primitive' keywords that don't follow the pattern: broadcastlessgreater and arithmetic expressions. All of these are described below.

More complex filter expressions are built up by using the words andor and not to combine primitives. E.g., `host foo and not port ftp and not port ftp-data'. To save typing, identical qualifier lists can be omitted. E.g., `tcp dst port ftp or ftp-data or domain' is exactly the same as `tcp dst port ftp or tcp dst port ftp-data or tcp dst port domain'.

Allowable primitives are:

  • "dst host host" - True if the IPv4 destination field of the packet is host, which may be either an address or a name.
  • "src host host" - True if the IPv4 source field of the packet is host.
  • "host host" - True if either the IPv4 source or destination of the packet is host.


Any of the above host expressions can be prefixed with the keywords, ipip6arprarp as in:

"ip host host"         

which is equivalent to:

"ether proto \ip and host host "        

  • "ether dst ehost".  True if the ethernet destination address is ehost. Ehost must be in numeric format: XX:XX:XX:XX:XX:XX
  • "ether src ehost".True if the ethernet source address is ehost.
  • "ether host ehost". True if either the ethernet source or destination address is ehost.
  • "dst net net". True if the IPv4 destination address of the packet has a network number of net.
  • "src net net". True if the IPv4 source address of the packet has a network number of net.
  • "net net". True if either the IPv4 source or destination address of the packet has a network number of net.
  • "net net mask netmask". True if the IPv4 address matches net with the specific netmask. May be qualified with src or dst
  • "net net/len". True if the IPv4 address matches net with a netmask len bits wide. May be qualified with src or dst.
  • "dst port port". True if the packet is ip/tcp, ip/udp and has a destination port value of port
  • "src port port". True if the packet has a source port value of port.
  • "port port". True if either the source or destination port of the packet is port.
  • "dst portrange port1-port2". True if the packet is ip/tcp, ip/udp and has a destination port value between port1 and port2port1 and port2 are interpreted in the same fashion as the port parameter for port.
  • "src portrange port1-port2". True if the packet has a source port value between port1 and port2.
  • "portrange port1-port2". True if either the source or destination port of the packet is between port1 and port2.

Any of the above port or port range expressions can be prefixed with the keywords, tcp or udp, as in:

tcp src port port           

which matches only tcp packets whose source port is port.

  • "less length". True if the packet has a length less than or equal to length. This is equivalent to:

"len <= length".

  • "greater length". True if the packet has a length greater than or equal to length. This is equivalent to:

"len >= length".

  • "ip proto protocol". True if the packet is an IPv4 packet of protocol type protocolProtocol can be a number or one of the names icmpicmp6igmpigrppimahespvrrpudp, or tcp. Note that the identifiers tcpudp, and icmp are also keywords and must be escaped via backslash (\), which is \\ in the C-shell. Note that this primitive does not chase the protocol header chain.
  • "ip protochain protocol". True if the packet is IPv4 packet, and contains protocol header with type protocol in its protocol header chain. For example,
  • "ip protochain 6"  matches any IPv4 packet with TCP protocol header in the protocol header chain. The packet may contain, for example, authentication header, routing header, or hop-by-hop option header, between IPv4 header and TCP header. The code emitted by this primitive is complex and cannot be optimized, so this can be somewhat slow.
  • "ether broadcast". True if the packet is an Ethernet broadcast packet. The ether keyword is optional.
  • "ether multicast". True if the packet is an Ethernet multicast (or broadcast) packet. The ether keyword is optional. This is shorthand for `ether[0] & 1 != 0'.
  • "ip multicast". True if the packet is an IPv4 multicast (or broadcast) packet.
  • "ether proto protocol". True if the packet is of ether type protocolProtocol can be a number or one of the names ipip6 ,arprarpatalkaarpscalatmopdlmoprcisostpipx, or netbeui. Note these identifiers are also keywords and must be escaped via backslash (\).


In the case of Ethernet, WANFleX checks the Ethernet type field for most of those protocols. The exceptions are:

  • isostp, and netbeui

WANFLeX checks for an 802.3 frame and then checks the LLC header as it does for FDDI, Token Ring, and 802.11;

  • atalk

WANFLeX checks both for the AppleTalk etype in an Ethernet frame and for a SNAP-format packet as it does for FDDI, Token Ring, and 802.11;

  • aarp

WANFLeX checks for the AppleTalk ARP etype in either an Ethernet frame or an 802.2 SNAP frame with an OUI of 0x000000;

  • ipx

WANFLeX checks for the IPX etype in an Ethernet frame, the IPX DSAP in the LLC header, the 802.3-with-no-LLC-header encapsulation of IPX, and the IPX etype in a SNAP frame.


iparprarpatalkaarpisostpipxnetbeui

Abbreviations for:

ether proto p           

where p is one of the above protocols.


  • "svlan [vlan_id]". True if the packet is an IEEE 802.1Q Service VLAN packet (ether proto 0x88a8)
  • "vlan [vlan_id]". True if the packet is an IEEE 802.1Q VLAN packet (ether proto 0x8100). If [vlan_id] is specified, only true if the packet has the specified vlan_id. Note that the first vlan or svlan keyword encountered in expression changes the decoding offsets for the remainder of expression on the assumption that the packet is a VLAN packet. The vlan [vlan_id] expression may be used more than once, to filter on VLAN hierarchies. Each use of that expression increments the filter offsets by 4.

For example:

svlan 100 && vlan 200   

filters on VLAN 200 encapsulated within Service VLAN 100, and

vlan 300 && ip 

filters IPv4 protocols encapsulated in VLAN 300.

svlan 100   

filters all packets encapsulated within Service VLAN 100

  • "mpls [label_num]". True if the packet is an MPLS packet. If [label_num] is specified, only true is the packet has the specified label_num. Note that the first mpls keyword encountered in expression changes the decoding offsets for the remainder of expression on the assumption that the packet is a MPLS-encapsulated IP packet. The mpls [label_num] expression may be used more than once, to filter on MPLS hierarchies. Each use of that expression increments the filter offsets by 4.

For example:

mpls 100000 && mpls 1024       

filters packets with an outer label of 100000 and an inner label of 1024, and

mpls && mpls 1024 && host 192.9.200.1       

filters packets to or from 192.9.200.1 with an inner label of 1024 and any outer label.

  • "pppoed". True if the packet is a PPP-over-Ethernet Discovery packet (Ethernet type 0x8863).
  • "pppoes". True if the packet is a PPP-over-Ethernet Session packet (Ethernet type 0x8864). Note that the first pppoes keyword encountered in expression changes the decoding offsets for the remainder of expression on the assumption that the packet is a PPPoE session packet.

For example:

pppoes && ppp proto 0x21      

filters IPv4 protocols encapsulated in PPPoE.

  • tcpudpicmp

Abbreviations for:

"ip proto p", where p is one of the above protocols.

  • "iso proto protocol". True if the packet is an OSI packet of protocol type protocolProtocol can be a number or one of the names clnpesis, or isis.
  • clnpesisisis

Abbreviations for:

"iso proto p" , where p is one of the above protocols.

  • expr relop expr

True if the relation holds, where relop is one of >, <, >=, <=, =, !=, and expr is an arithmetic expression composed of integer constants (expressed in standard C syntax), the normal binary operators [+, -, *, /, &, |, <<, >>], a length operator, and special packet data accessors. Note that all comparisons are unsigned, so that, for example, 0x80000000 and 0xffffffff are > 0. To access data inside the packet, use the following syntax:

proto [ expr : size ]           

Proto is one of ether, fddi, tr, wlan, ppp, slip, link, ip, arp, rarp, tcp, udp, icmp, and indicates the protocol layer for the index operation. (ether, fddi, wlan, tr, ppp, slip and link all refer to the link layer.) Note that tcp, udp and other upper-layer protocol types only apply to IPv4. The byte offset, relative to the indicated protocol layer, is given by exprSize is optional and indicates the number of bytes in the field of interest; it can be either one, two, or four, and defaults to one. The length operator, indicated by the keyword len, gives the length of the packet.

For example, `ether[0] & 1 != 0' catches all multicast traffic. The expression `ip[0] & 0xf != 5' catches all IPv4 packets with options. The expression `ip[6:2] & 0x1fff = 0' catches only unfragmented IPv4 datagrams and frag zero of fragmented IPv4 datagrams. This check is implicitly applied to the tcp and udp index operations. For instance, tcp[0] always means the first byte of the TCP header, and never means the first byte of an intervening fragment.

Some offsets and field values may be expressed as names rather than as numeric values. The following protocol header field offsets are available: icmptype (ICMP type field), icmpcode (ICMP code field), and tcpflags (TCP flags field).

The following ICMP type field values are available: icmp-echoreplyicmp-unreachicmp-sourcequenchicmp-redirecticmp-echoicmp-routeradverticmp-routersoliciticmp-timxceedicmp-paramprobicmp-tstampicmp-tstampreplyicmp-ireqicmp-ireqreplyicmp-maskreqicmp-maskreply.

The following TCP flags field values are available: tcp-fintcp-syntcp-rsttcp-pushtcp-acktcp-urg.

Primitives may be combined using:

A parenthesized group of primitives and operators (parentheses are special to the Shell and must be escaped).

  • Negation (`!' or `not').
  • Concatenation (`&&' or `and').
  • Alternation (`||' or `or').

Negation has highest precedence. Alternation and concatenation have equal precedence and associate left to right. Note that explicit and tokens, not juxtaposition, are now required for concatenation.

If an identifier is given without a keyword, the most recent keyword is assumed. For example,

not host 1.1.1.1 and 2.2.2.2     

is short for

not host 1.1.1.1 and host 2.2.2.2 

which should not be confused with

not ( host 1.1.1.1 or 2.2.2.2 )

Packet Filter Rule Examples

Single IP subnet:

net 192.168.1.0/24

Several IP subnets:

net 192.168.1.0/24 or net 192.168.100.0/24

Several IP subnets with exceptions:

net 192.168.1.0/16 and not net (192.168.100.0/24 or 192.168.200.0/24)

Several IP subnets inside VLAN:

vlan 50 and (net 192.168.1.0/24 or net 192.168.100.0/24)

DSCP labels:

ip[1]>>2 == 1 or ip[1]>>2 == 2vlan and (ip[1]>>2 > 5)

Disable IP multicast and broadcast:

not ip multicast

To select the start and end packets (the SYN and FIN packets) of each TCP conversation:

(tcp[tcpflags] & (tcp-syn|tcp-fin) != 0)

To select all ICMP packets that are not echo requests/replies (i.e., not ping packets):

icmp[icmptype] != icmp-echo and icmp[icmptype] != icmp-echoreply

To select all the packets to or from IP 192.168.0.1

host 192.168.0.1                     

To select all the packets from or to port 80

port 80                  

To select the traffic to subnet 172.16.0.0/16

dst net 172.16.0.0/16         

To select all the tcp traffic to or from 192.168.0.0/24 subnet and uses port 21

net 192.168.0.0/24 and tcp port 21      

To select all the traffic to or from 192.168.0.1 OR to or from 192.168.0.221 (it doesn't matter who is source or destination, and it's enough to satisfy only one condition)



host 192.168.0.1 or host 192.168.0.221   

To sellect all the traffic exept TCP traffic using port 22 to or from 192.168.0.1 or 192.168.0.2 (any of them or both at once)

(host 192.168.0.1 || host 192.168.0.1) && not tcp port 22
  • No labels