Blame extensions/libxt_bpf.man

Packit 7b22a4
Match using Linux Socket Filter. Expects a path to an eBPF object or a cBPF
Packit 7b22a4
program in decimal format.
Packit 7b22a4
.TP
Packit 7b22a4
\fB\-\-object\-pinned\fP \fIpath\fP
Packit 7b22a4
Pass a path to a pinned eBPF object.
Packit 7b22a4
.PP
Packit 7b22a4
Applications load eBPF programs into the kernel with the bpf() system call and
Packit 7b22a4
BPF_PROG_LOAD command and can pin them in a virtual filesystem with BPF_OBJ_PIN.
Packit 7b22a4
To use a pinned object in iptables, mount the bpf filesystem using
Packit 7b22a4
.IP
Packit 7b22a4
mount \-t bpf bpf ${BPF_MOUNT}
Packit 7b22a4
.PP
Packit 7b22a4
then insert the filter in iptables by path:
Packit 7b22a4
.IP
Packit 7b22a4
iptables \-A OUTPUT \-m bpf \-\-object\-pinned ${BPF_MOUNT}/{PINNED_PATH} \-j ACCEPT
Packit 7b22a4
.TP
Packit 7b22a4
\fB\-\-bytecode\fP \fIcode\fP
Packit 7b22a4
Pass the BPF byte code format as generated by the \fBnfbpf_compile\fP utility.
Packit 7b22a4
.PP
Packit 7b22a4
The code format is similar to the output of the tcpdump -ddd command: one line
Packit 7b22a4
that stores the number of instructions, followed by one line for each
Packit 7b22a4
instruction. Instruction lines follow the pattern 'u16 u8 u8 u32' in decimal
Packit 7b22a4
notation. Fields encode the operation, jump offset if true, jump offset if
Packit 7b22a4
false and generic multiuse field 'K'. Comments are not supported.
Packit 7b22a4
.PP
Packit 7b22a4
For example, to read only packets matching 'ip proto 6', insert the following,
Packit 7b22a4
without the comments or trailing whitespace:
Packit 7b22a4
.IP
Packit 7b22a4
4               # number of instructions
Packit 7b22a4
.br
Packit 7b22a4
48 0 0 9        # load byte  ip->proto
Packit 7b22a4
.br
Packit 7b22a4
21 0 1 6        # jump equal IPPROTO_TCP
Packit 7b22a4
.br
Packit 7b22a4
6 0 0 1         # return     pass (non-zero)
Packit 7b22a4
.br
Packit 7b22a4
6 0 0 0         # return     fail (zero)
Packit 7b22a4
.PP
Packit 7b22a4
You can pass this filter to the bpf match with the following command:
Packit 7b22a4
.IP
Packit 7b22a4
iptables \-A OUTPUT \-m bpf \-\-bytecode '4,48 0 0 9,21 0 1 6,6 0 0 1,6 0 0 0' \-j ACCEPT
Packit 7b22a4
.PP
Packit 7b22a4
Or instead, you can invoke the nfbpf_compile utility.
Packit 7b22a4
.IP
Packit 7b22a4
iptables \-A OUTPUT \-m bpf \-\-bytecode "`nfbpf_compile RAW 'ip proto 6'`" \-j ACCEPT
Packit 7b22a4
.PP
Packit 7b22a4
Or use tcpdump -ddd. In that case, generate BPF targeting a device with the
Packit 7b22a4
same data link type as the xtables match. Iptables passes packets from the
Packit 7b22a4
network layer up, without mac layer. Select a device with data link type RAW,
Packit 7b22a4
such as a tun device:
Packit 7b22a4
.IP
Packit 7b22a4
ip tuntap add tun0 mode tun
Packit 7b22a4
.br
Packit 7b22a4
ip link set tun0 up
Packit 7b22a4
.br
Packit 7b22a4
tcpdump -ddd -i tun0 ip proto 6
Packit 7b22a4
.PP
Packit 7b22a4
See tcpdump -L -i $dev for a list of known data link types for a given device.
Packit 7b22a4
.PP
Packit 7b22a4
You may want to learn more about BPF from FreeBSD's bpf(4) manpage.