netfilter.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* nftables rule optimization - evaluating efficiency
@ 2024-07-02 19:03 William N.
  2024-07-03  9:37 ` Reindl Harald
  2024-07-10 18:34 ` William N.
  0 siblings, 2 replies; 8+ messages in thread
From: William N. @ 2024-07-02 19:03 UTC (permalink / raw)
  To: netfilter

Hi,

Since it is possible to do the same thing using different rules, I am
looking for the most optimal (low resource usage, high speed) way to
write my rules.

Here is just a very simple test to compare the different approaches:

#!/usr/sbin/nft -f

flush ruleset
table ip6 t {
	# Goal: fast processing through early "exit"
	chain A {
		ip6 hoplimit != 255 return
		icmpv6 type  != 133 return
		icmpv6 code  != 0   return
		accept
	}

	# Goal: compact syntax
	chain B {
		icmpv6 type . icmpv6 code . ip6 hoplimit {
				133 . 0 . 255
			} \
			accept
		return
	}

	# Goal: no specific, using "general" syntax
	chain C {
		icmpv6 type 133 icmpv6 code 0 ip6 hoplimit 255 \
			accept
		return
	}
}

Looking at the output of 'nft -c --debug=netlink -f <this file>', it
seems:

- chain A would work best (least instructions to verdict) if there is
  no match (e.g. if hoplimit is indeed not 255) but in all other cases
  the total number of instructions to be processed is greater

- chain B and C seem to have the same number of instructions but
  perhaps B would outperform C in case of multiple elements in the set
  (e.g. more types or codes to check)

Also, it is not clear what is the actual "load" of different
instructions in terms of CPU cycles and memory, i.e. one instruction
may look as "one" but may actually cost more than another 2, right?

What is the proper way to evaluate and optimize rule efficiency?

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2024-07-11 19:15 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-07-02 19:03 nftables rule optimization - evaluating efficiency William N.
2024-07-03  9:37 ` Reindl Harald
2024-07-03 10:44   ` William N.
2024-07-10 18:34 ` William N.
2024-07-10 21:27   ` Kerin Millar
2024-07-10 21:39     ` Florian Westphal
2024-07-11 19:15       ` William N.
2024-07-11 19:14     ` William N.

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).