Fix some casting required in mask/endian calculation
[flowspec-xdp] / README.md
1 FlowSpec -> XDP Conversion Utility
2 ==================================
3
4 This utility allows you to convert flowspec rules (extracted from a local BIRD instance with birdc)
5 to an XDP program. It currently supports the entire flowspec match grammar, rate limits, traffic
6 action packet match counting (sample bit) and terminal bit, and traffic marking. The redirect
7 community is not supported.
8
9 Note that correctly sorting rules is *not* implemented as it requires implementing the flowspec
10 wire serialization format and it may better be done inside bird/birdc. Thus, be vary careful using
11 the terminal bit in the traffict action community.
12
13 `install.sh` provides a simple example script which will compile and install a generated XDP program
14 from the rules in bird's `flowspec4` and `flowspec6` routing tables. It will drop any packets which
15 match any flowspec filter.
16
17 `genrules.py` will accept birdc output on stdin and generate a rules.h file which is included in
18 xdp.c to check individual rules. The specific behavior of some less-common parsing options can be
19 controlled by parameters to `genrules.py` -
20  * --8021q can be either "drop-vlan", "accept-vlan" or "parse-vlan" to either drop all traffic with
21    a VLAN tag, accept all traffic with a VLAN tag (without comparing it against any flowspec rules),
22    or parse VLAN traffic and compare it against flowspec rules just like any other traffic.
23  * If --8021q is set to "parse-vlan", --require-8021q can be set to a specific VLAN tag, and all
24    traffic with different VLAN tags is dropped.
25  * --ihl can be set to "drop-options", "accept-options", or "parse-options" to drop all traffic with
26    extra IPv4 option fields, accept all traffic with extra IPv4 options fields (without comparing it
27    to any flowspec rules), or parse IPv4 traffic with option fields like normal.
28  * --v6frag can be set to "drop-frags","ignore","parse-frags","ignore-parse-if-rule" to:
29    * drop all IPv6 fragments,
30    * ignore IPv6 fragments, matching only the IPv6 header but no ICMP/TCP/UDP options,
31    * parse IPv6 fragments, matching ICMP/TCP/UDP options if relevant (eg often only in the first
32      fragment), or
33    * ignore IPv6 fragments as above, unless a flow6 rule specifies the "fragment" keyword, in which
34      case parse all IPv6 fragments as above for all rules.
35
36 Note that if all of the above options are set to their "drop" or "ignore" variants, the parsing can
37 avoid all offset calculation, using static offsets for all fields.
38
39 Drop counts are tracked in XDP per-CPU arrays, and can be viewed with `dropcount.sh`.
40
41 Note that rate limiting is currently tracked under a single per-rule spinlock, which may be a
42 bottleneck for high speed NICs with many RX queues. Adapting this to per-RX-queue/CPU limits would
43 be trivial but is left as a future project.