NPF.CONF(5) | File Formats Manual | NPF.CONF(5) |
This manual page serves as a reference for editing npf.conf. Please refer to the official NPF documentation for comprehensive and in-depth information.
There are multiple structural elements npf.conf may contain: variable and table definitions (with or without content), abstraction groups, packet filtering rules, map rules for address translation and procedure definitions to call on filtered packets. The minimal npf.conf must contain a mandatory default group.
$var1 = 10.0.0.1
A variable may also be defined as a set:
$var2 = { 10.0.0.1, 10.0.0.2 }
Common variable definitions are for IP addresses, networks, ports, and interfaces.
table <1> type hash dynamicCurrently, tables support two storage types: "hash" or "tree". They can also be "dynamic" or static i.e. loaded from the specified file.
The file should contain a list of IP addresses and/or networks in the form of:
10.0.0.0/24 10.1.1.1
Tables of type "hash" can only contain IP addresses.
$pub_if_list = { ifnet(wm0), ifnet(wm1) }
In the context of filtering, an interface provides a list of its all IP addresses, including IPv4 and IPv6. Specific interface addresses can be selected by the family, e.g.:
$pub_if4 = inet4(wm0) $pub_if6 = { inet6(wm0) }
group (name "my_group", interface wm0, in) { # List of rules }
A "fully-featured" rule would for example be:
pass stateful in final family inet proto tcp flags S/SA \ from $source port $sport to $dest port $dport apply "someproc"
Any protocol in /etc/protocols can be specified. Further packet specification at present is limited to protocol TCP understanding flags, TCP and UDP understanding source and destination ports, and ICMP and IPv6-ICMP understanding icmp-type.
Fragments are not selectable since NPF always reassembles packets before further processing.
The following would translate the source to the IP address specified by the $pub_ip for the packets on the interface $ext_if.
map $ext_if dynamic 10.1.1.0/24 -> $pub_ip
Translations are implicitly filtered by limiting the operation to the network segments specified, that is, translation would be performed only on packets originating from 10.1.1.0/24 network. Explicit filter criteria can be specified using "pass <criteria>" as an additional option of the mapping.
procedure "someproc" { log: npflog0 normalise: "random-id", "min-ttl" 64 }
In this case, the procedure calls the logging and normalisation modules.
; Syntax of a single line. Lines can be separated by LF (\n) or ; a semicolon. Comments start with a hash (#) character. syntax = var-def | table-def | map | group | rproc | comment ; Variable definition. Names can be alpha-numeric, including "_" character. var-name = "$" . string interface = interface-name | var-name var-def = var "=" ( var-value | "{" value *[ "," value ] "}" ) ; Table definition. Table ID shall be numeric. Path is in the double quotes. table-id = <tid> table-def = "table" table-id "type" ( "hash" | "tree" ) ( "dynamic" | "file" path ) ; Mapping for address translation. map = "map" interface ( "static" | "dynamic" ) net-seg ( "->" | "<-" | "<->" ) net-seg [ "pass" filt-opts ] ; Rule procedure definition. The name should be in the double quotes. ; ; Each call can have its own options in a form of key-value pairs. ; Both key and values may be strings (either in double quotes or not) ; and numbers, depending on the extension. proc = "procedure" proc-name "{" *( proc-call [ new-line ] ) "}" proc-opts = key " " val [ "," proc-opts ] proc-call = call-name ":" proc-opts new-line ; Group definition and the ruleset. group = "group" "(" ( "default" | group-opts ) ")" "{" ruleset "}" group-opts = [ "name" string ] [ "interface" interface ] [ "in" | "out" ] ruleset = [ rule new-line ] [ ruleset ] rule = ( "block" [ block-opts ] | "pass" ) [ "stateful" ] [ "in" | out" ] [ "final" ] [ "on" iface ] [ "family" fam-opt ] [ "proto" protocol [ proto-opts ] ] ( "all" | filt-opts ) [ "apply" proc-name ] block-opts = "return-rst" | "return-icmp" | "return" fam-opt = "inet" | "inet6" proto-opts = "flags" tcp-flags [ "/" tcp-flag-mask ] | "icmp-type" type [ "code" icmp-code ] addr-mask = addr [ "/" mask ] filt-opts = "from" filt-addr [ port-opts ] "to" filt-addr [ port-opts ] filt-addr = [ interface | var-name | addr-mask | table-id | "any" ] filt-port = "port" ( port-num | port-from "-" port-to | var-name )
$ext_if = ifnet(wm0) $int_if = ifnet(wm1) table <1> type hash file "/etc/npf_blacklist" table <2> type tree dynamic $services_tcp = { http, https, smtp, domain, 6000, 9022 } $services_udp = { domain, ntp, 6000 } $localnet = { 10.1.1.0/24 } # Note: if $ext_if has multiple IP address (e.g. IPv6 as well), # then the translation address has to be specified explicitly. map $ext_if dynamic 10.1.1.0/24 -> $ext_if map $ext_if dynamic 10.1.1.2 port 22 <- $ext_if port 9022 procedure "log" { # Note: npf_ext_log kernel module should be loaded, if not built-in. # Also, the interface created, e.g.: ifconfig npflog0 create log: npflog0 } group (name "external", interface $ext_if) { pass stateful out final all block in final from <1> pass stateful in final family inet proto tcp to $ext_if port ssh apply "log" pass stateful in final proto tcp to $ext_if port $services_tcp pass stateful in final proto udp to $ext_if port $services_udp pass stateful in final proto tcp to $ext_if port 49151-65535 # Passive FTP pass stateful in final proto udp to $ext_if port 33434-33600 # Traceroute } group (name "internal", interface $int_if) { block in all pass in final from <2> pass out final all } group (default) { pass final on lo0 all block all }
January 11, 2013 | NetBSD 6.1 |