NFTables.Formatter (NFTables v0.8.2)
View SourceConvert nftables JSON expressions to nft command syntax strings.
This module provides formatting functions to convert structured JSON expressions (generated by Match) into human-readable nft syntax strings for debugging, display, and documentation purposes.
Examples
# Format a single expression
expr = %{"drop" => nil}
Formatter.format_expr(expr)
#=> "drop"
# Format an expression list
expr_list = [
%{"match" => %{...}},
%{"counter" => nil},
%{"drop" => nil}
]
Formatter.format_expr_list(expr_list)
#=> "ip saddr 192.168.1.1 counter drop"Note
This formatter covers 90%+ of common use cases. For complex or uncommon expressions, it may produce simplified output or fall back to JSON representation.
Summary
Functions
Format a single JSON expression to nft syntax.
Format a list of JSON expressions to nft syntax.
Functions
Format a single JSON expression to nft syntax.
Examples
format_expr(%{"accept" => nil})
#=> "accept"
format_expr(%{"match" => %{
"left" => %{"payload" => %{"protocol" => "tcp", "field" => "dport"}},
"right" => 80,
"op" => "=="
}})
#=> "tcp dport 80"
Format a list of JSON expressions to nft syntax.
Examples
format_expr_list([
%{"match" => %{...}},
%{"counter" => nil},
%{"drop" => nil}
])
#=> "ip saddr 192.168.1.1 counter drop"