Skip to content

Commit 4f9dbed

Browse files
committed
pcap-filter(7): Refine more prose and formatting. [skip ci]
Split the main section into six. Fix "net NETNAMEADDR". Move known MTP issues to the BUGS section. Refine the definition of an arithmetic expression. Say "packet data accessors" instead of "index operation" more often and clarify the syntax. Clarify that compound expression syntax includes relations. Update the "most recent keyword" example to convey the point better.
1 parent 732df31 commit 4f9dbed

File tree

1 file changed

+60
-36
lines changed

1 file changed

+60
-36
lines changed

pcap-filter.manmisc.in

Lines changed: 60 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
.\" WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
1919
.\" MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
2020
.\"
21-
.TH PCAP-FILTER @MAN_MISC_INFO@ "27 February 2025"
21+
.TH PCAP-FILTER @MAN_MISC_INFO@ "9 March 2025"
2222
.SH NAME
2323
pcap-filter \- packet filter syntax
2424
.br
@@ -174,7 +174,7 @@ that don't follow the pattern, for example:
174174
.BR wlan ,
175175
.BR less ,
176176
.BR greater ,
177-
the index operation and arithmetic expressions.
177+
packet data accessors and arithmetic expressions.
178178
All of these are described below.
179179
.LP
180180
More complex filter expressions are built up by using the words
@@ -189,8 +189,7 @@ To save typing, identical qualifier lists can be omitted.
189189
E.g.,
190190
`\fBtcp dst port\fP ftp \fBor\fP ftp-data \fBor\fP domain' is exactly the same as
191191
`\fBtcp dst port\fP ftp \fBor tcp dst port\fP ftp-data \fBor tcp dst port\fP domain'.
192-
.LP
193-
Allowable primitives are:
192+
.SH PRIMITIVES
194193
.IP "\fBhost \fIhostnameaddr\fR"
195194
True if the source or the destination ARP/IPv4/IPv6/RARP address of the packet is
196195
.IR hostnameaddr .
@@ -283,7 +282,7 @@ and/or a different direction
283282
.BR "src and dst" ),
284283
in the latter case the
285284
.B net
286-
keyword is optional.
285+
keyword remains mandatory.
287286
.I netnameaddr
288287
may be either a name from the networks database
289288
(/etc/networks, etc.) or a network number.
@@ -1196,16 +1195,14 @@ means the same as
11961195
.I val
11971196
is an integer.
11981197
.B sio
1199-
stands for the Service Information Octet (SIO) field of the MTP2 MSU header;
1200-
note that this keyword does not test whether the packet is an MSU packet.
1198+
stands for the Service Information Octet (SIO) field of the MTP2 MSU header.
12011199
.BR dpc ,
12021200
.B opc
12031201
and
12041202
.B sls
12051203
stand for the Destination Point Code (DPC), Originating Point Code (OPC) and
12061204
Signalling Link Selection (SLS) fields respectively of the MTP3 standard
1207-
routing label; note that these keywords do not test whether the packet is an
1208-
MTP3 packet.
1205+
routing label.
12091206
.IP "\fImtpfield\fP \fIval\fR"
12101207
Abbreviation for
12111208
.in +.5i
@@ -1272,8 +1269,17 @@ are equivalent to
12721269
Note that this address syntax clashes with the parameter expansion syntax
12731270
in POSIX-compatible shells and elsewhere, so depending on the use case the
12741271
filter string may require the use of single quotes or a backslash.
1275-
.IP "\fIexpr1 relop expr2\fR"
1276-
True if the relation holds. \fIRelop\fR is one of
1272+
.SH ARITHMETIC EXPRESSIONS
1273+
Arithmetic expressions are the operands of a relational operator in a
1274+
relation of the following form:
1275+
.in +.5i
1276+
.nf
1277+
\fIexpr1 relop expr2\fR
1278+
.fi
1279+
.in -.5i
1280+
This evaluates to true if and only if the relation holds.
1281+
.I relop
1282+
(the relational operator) is one of
12771283
.RB { > ,
12781284
.BR < ,
12791285
.BR >= ,
@@ -1286,7 +1292,8 @@ True if the relation holds. \fIRelop\fR is one of
12861292
means the same as
12871293
.BR == ).
12881294
Each of \fIexpr1\fR and \fIexpr2\fR is an arithmetic expression composed of
1289-
integer constants (expressed in standard C syntax), the normal binary operators
1295+
integer constants (expressed in standard C syntax), the common arithmetic and
1296+
bitwise binary operations
12901297
.RB { + ,
12911298
.BR - ,
12921299
.BR * ,
@@ -1297,10 +1304,11 @@ integer constants (expressed in standard C syntax), the normal binary operators
12971304
.BR ^ ,
12981305
.BR << ,
12991306
.BR >> },
1300-
a length operator, and special packet data
1301-
accessors. Note that all comparisons are unsigned, so that, for example,
1302-
0x80000000 and 0xffffffff are > 0.
1303-
.IP
1307+
a length operator, and packet data accessors. All arithmetic expressions
1308+
regardless of the complexity and composition resolve to an integer value.
1309+
Note that all comparisons are unsigned, so that, for example, both 0x80000000
1310+
and 0xffffffff are > 0.
1311+
.LP
13041312
The
13051313
.B %
13061314
and
@@ -1312,11 +1320,11 @@ OpenBSD), if
13121320
those operators are used, filtering will be done in user mode, which
13131321
will increase the overhead of capturing packets and may cause more
13141322
packets to be dropped.
1315-
.IP
1323+
.LP
13161324
The length operator, indicated by the keyword \fBlen\fP, gives the
13171325
length of the packet.
1318-
.IP
1319-
To access data inside the packet, use the following syntax:
1326+
.SH PACKET DATA ACCESSORS
1327+
To use the packet data in an arithmetic expression, use the following syntax:
13201328
.in +.5i
13211329
.nf
13221330
\fIproto\fB [ \fIexpr\fB : \fIsize\fB ]\fR
@@ -1364,14 +1372,17 @@ indicates the protocol layer for the index operation.
13641372
and
13651373
.BR wlan
13661374
all refer to the
1367-
link layer. \fBradio\fR refers to the "radio header" added to some
1375+
link layer, \fBradio\fR refers to the "radio header" added to some
13681376
802.11 captures.)
13691377
Note that \fBtcp\fR, \fBudp\fR and other upper-layer protocol types only
13701378
apply to IPv4, not IPv6 (this will be fixed in the future).
13711379
The byte offset, relative to the indicated protocol layer, is
1372-
given by \fIexpr\fR.
1380+
given by \fIexpr\fR, which can be an integer constant or any other valid
1381+
arithmetic expression.
13731382
\fISize\fR is optional and indicates the number of bytes in the
1374-
field of interest; it can be either one, two, or four, and defaults to one.
1383+
field of interest; it can be either one, two, or four, and defaults to one;
1384+
also it must be one of these valid integer constants only and cannot be a
1385+
more complex expression.
13751386

13761387
For example, `\fBether[\fP0\fB] &\fP 1 \fB!=\fP 0' catches all multicast traffic.
13771388
The expression `\fBip[\fP0\fB] &\fP 0xf \fB!=\fP 5'
@@ -1395,14 +1406,14 @@ index operations.
13951406
For instance, \fBtcp[\fP0\fB]\fP always means the first
13961407
byte of the TCP \fIheader\fP, and never means the first byte of an
13971408
intervening fragment.
1398-
.IP
1409+
.SH NAMED VALUES
13991410
Some offsets and field values may be expressed as names rather than
14001411
as numeric values.
14011412
The following protocol header field offsets are
14021413
available: \fBicmptype\fP (ICMP type field), \fBicmp6type\fP (ICMPv6 type field),
14031414
\fBicmpcode\fP (ICMP code field), \fBicmp6code\fP (ICMPv6 code field) and
14041415
\fBtcpflags\fP (TCP flags field).
1405-
.IP
1416+
.LP
14061417
The following ICMP type field values are available:
14071418
.BR \%icmp-echoreply ,
14081419
.BR \%icmp-unreach ,
@@ -1419,7 +1430,7 @@ The following ICMP type field values are available:
14191430
.BR \%icmp-ireqreply ,
14201431
.BR \%icmp-maskreq ,
14211432
.BR \%icmp-maskreply .
1422-
.IP
1433+
.LP
14231434
The following ICMPv6 type field values are available:
14241435
.BR \%icmp6-destinationunreach ,
14251436
.BR \%icmp6-packettoobig ,
@@ -1450,29 +1461,28 @@ The following ICMPv6 type field values are available:
14501461
.BR \%icmp6-multicastrouteradvert ,
14511462
.BR \%icmp6-multicastroutersolicit ,
14521463
.BR \%icmp6-multicastrouterterm .
1453-
.IP
1464+
.LP
14541465
The following TCP flags field values are available: \fBtcp-fin\fP,
14551466
\fBtcp-syn\fP, \fBtcp-rst\fP, \fBtcp-push\fP,
14561467
\fBtcp-ack\fP, \fBtcp-urg\fP, \fBtcp-ece\fP,
14571468
\fBtcp-cwr\fP.
1469+
.SH COMPOUND EXPRESSIONS
1470+
Primitives and relations may be combined using:
1471+
.LP
1472+
Parentheses.
14581473
.LP
1459-
Primitives may be combined using:
1460-
.IP
1461-
A parenthesized group of primitives and operators.
1462-
.IP
14631474
Negation (`\fB!\fP' or `\fBnot\fP').
1464-
.IP
1475+
.LP
14651476
Concatenation (`\fB&&\fP' or `\fBand\fP').
1466-
.IP
1477+
.LP
14671478
Alternation (`\fB||\fP' or `\fBor\fP').
14681479
.LP
14691480
Negation has the highest precedence.
14701481
Alternation and concatenation have equal precedence and associate
14711482
left to right.
14721483
.LP
1473-
If an identifier is given without a keyword, the most recent keyword
1474-
is assumed.
1475-
For example,
1484+
For primitives, if an identifier is given without a keyword, the most recent
1485+
keyword is assumed. For example,
14761486
.in +.5i
14771487
.nf
14781488
\fBnot host\fP vs \fBand\fR ace
@@ -1487,7 +1497,7 @@ is short for
14871497
which should not be confused with
14881498
.in +.5i
14891499
.nf
1490-
\fBnot (host \fPvs\fB or \fPace\fB)\fR
1500+
\fBnot (host \fPvs\fB and host \fPace\fB)\fR
14911501
.fi
14921502
.in -.5i
14931503
.SH EXAMPLES
@@ -1654,6 +1664,20 @@ Arithmetic expression against transport layer headers, like \fBtcp[0]\fP,
16541664
does not work against IPv6 packets.
16551665
It only looks at IPv4 packets.
16561666
.LP
1667+
The
1668+
.B sio
1669+
and
1670+
.B hsio
1671+
keywords do not test whether the packet is an MSU packet. The
1672+
.BR dpc ,
1673+
.BR opc ,
1674+
.BR sls ,
1675+
.BR hdpc ,
1676+
.B hopc
1677+
and
1678+
.B hsls
1679+
keywords do not test whether the packet is an MTP3 packet.
1680+
.LP
16571681
For ARP and RARP the current implementation assumes IPv4 over Ethernet and may
16581682
incorrectly match packets that have a different combination of protocol and
16591683
hardware.

0 commit comments

Comments
 (0)