Commit 88865347 authored by Roy, UjjaL's avatar Roy, UjjaL Committed by Daniel Borkmann

bpf, doc: Add heading and example for extensions in cbpf

Add new heading for extensions to make it more readable. Also, add one
more example of filtering interface index for better understanding.
Signed-off-by: default avatarRoy, UjjaL <royujjal@gmail.com>
Signed-off-by: default avatarDaniel Borkmann <daniel@iogearbox.net>
Acked-by: default avatarSong Liu <songliubraving@fb.com>
Acked-by: default avatarJohn Fastabend <john.fastabend@gmail.com>
Link: https://lore.kernel.org/bpf/CAADnVQJ=DoRDcVkaXmY3EmNdLoO7gq1mkJOn5G=00wKH8qUtZQ@mail.gmail.com
parent c7603cfa
...@@ -320,13 +320,6 @@ Examples for low-level BPF: ...@@ -320,13 +320,6 @@ Examples for low-level BPF:
ret #-1 ret #-1
drop: ret #0 drop: ret #0
**(Accelerated) VLAN w/ id 10**::
ld vlan_tci
jneq #10, drop
ret #-1
drop: ret #0
**icmp random packet sampling, 1 in 4**:: **icmp random packet sampling, 1 in 4**::
ldh [12] ldh [12]
...@@ -358,6 +351,22 @@ Examples for low-level BPF: ...@@ -358,6 +351,22 @@ Examples for low-level BPF:
bad: ret #0 /* SECCOMP_RET_KILL_THREAD */ bad: ret #0 /* SECCOMP_RET_KILL_THREAD */
good: ret #0x7fff0000 /* SECCOMP_RET_ALLOW */ good: ret #0x7fff0000 /* SECCOMP_RET_ALLOW */
Examples for low-level BPF extension:
**Packet for interface index 13**::
ld ifidx
jneq #13, drop
ret #-1
drop: ret #0
**(Accelerated) VLAN w/ id 10**::
ld vlan_tci
jneq #10, drop
ret #-1
drop: ret #0
The above example code can be placed into a file (here called "foo"), and The above example code can be placed into a file (here called "foo"), and
then be passed to the bpf_asm tool for generating opcodes, output that xt_bpf then be passed to the bpf_asm tool for generating opcodes, output that xt_bpf
and cls_bpf understands and can directly be loaded with. Example with above and cls_bpf understands and can directly be loaded with. Example with above
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment