A single nftables rule — an ordered list of expressions that the kernel evaluates against each packet visiting the rule's chain.
Fields
:expressions— ordered list of%Linx.Netfilter.Expr{}. The terminator is typically a verdict-bearingimmediateexpression; if absent, falls through to the next rule.:chain— name (string) of the chain this rule belongs to.nilfor free-standing rules; populated when the rule is inserted into a chain (and when pulled from the kernel).:handle— the kernel-assigned rule handle (positive integer).nilfor authoring-time rules; populated on the first successfulpush/2and round-tripped onpull/1..2. Required for in-place:replace/:deleteof rules without a tag.:tag— Linx-side stable identity (atom). The basis of:reconcilemode's diffing: a Rule keeps its identity across pushes regardless of position or handle, as long as the tag matches.nilis allowed; untagged rules fall back to positional identity (and forfeit:reconcilediffability).:comment— a user-supplied comment string, round-tripped via the kernel'sNFTNL_RULE_USERDATAopaque slot.
Construction
Use build/1 or build/2 with an expression list. The list may
include verdict sugar — atoms (:accept), tuples ({:jump, name}),
or %Linx.Netfilter.Verdict{} values — which are normalised to
Expr.immediate/1 calls so the resulting Rule is uniform.
iex> Rule.build([Expr.immediate(:accept)])
{:ok, #Linx.Netfilter.Rule<[immediate accept]>}
iex> Rule.build([:drop], tag: :default_deny, comment: "block-all")
{:ok, #Linx.Netfilter.Rule<:default_deny [immediate drop]>}
iex> Rule.build([{:jump, "input_extras"}])
{:ok, #Linx.Netfilter.Rule<[immediate jump "input_extras"]>}Bang variant build!/2 raises ArgumentError on validation
failure. The non-bang form returns {:error, {:bad_rule, reason}}.
Inspect
Compact: tag (if set) then bracketed expressions. Comment + handle are omitted from the brief rendering; pattern-match on the struct fields if you need the full detail.
Summary
Functions
Builds a Rule from a list of expressions (or verdict-sugar).
Bang variant of build/2 — returns the rule or raises
ArgumentError describing the failure.
Returns the rule's terminal verdict, if any — the trailing
verdict-bearing expression. nil for fall-through rules.
Types
@type expression_input() :: Linx.Netfilter.Expr.t() | Linx.Netfilter.Verdict.t() | Linx.Netfilter.Verdict.input()
@type t() :: %Linx.Netfilter.Rule{ chain: String.t() | nil, comment: String.t() | nil, expressions: [Linx.Netfilter.Expr.t()], handle: pos_integer() | nil, tag: atom() | nil }
Functions
@spec build( [expression_input()], keyword() ) :: {:ok, t()} | {:error, {:bad_rule, term()}}
Builds a Rule from a list of expressions (or verdict-sugar).
Options:
:chain— the owning chain's name; usually set by the chain-level helpers, but allowed at build time for round-trip from apull/1..2.:handle— the kernel-assigned handle; usuallyniluntil the firstpush/2.:tag— atom identity (for:reconcile-mode diffing).:comment— round-trips viaNFTNL_RULE_USERDATA.
@spec build!( [expression_input()], keyword() ) :: t()
Bang variant of build/2 — returns the rule or raises
ArgumentError describing the failure.
@spec verdict(t()) :: Linx.Netfilter.Verdict.t() | nil
Returns the rule's terminal verdict, if any — the trailing
verdict-bearing expression. nil for fall-through rules.