1.\" $NetBSD: npfctl.8,v 1.25 2020/05/30 14:16:56 rmind Exp $ 2.\" 3.\" Copyright (c) 2009-2014 The NetBSD Foundation, Inc. 4.\" All rights reserved. 5.\" 6.\" This material is based upon work partially supported by The 7.\" NetBSD Foundation under a contract with Mindaugas Rasiukevicius. 8.\" 9.\" Redistribution and use in source and binary forms, with or without 10.\" modification, are permitted provided that the following conditions 11.\" are met: 12.\" 1. Redistributions of source code must retain the above copyright 13.\" notice, this list of conditions and the following disclaimer. 14.\" 2. Redistributions in binary form must reproduce the above copyright 15.\" notice, this list of conditions and the following disclaimer in the 16.\" documentation and/or other materials provided with the distribution. 17.\" 18.\" THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 19.\" ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 20.\" TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 21.\" PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 22.\" BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 23.\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 24.\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 25.\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 26.\" CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 27.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 28.\" POSSIBILITY OF SUCH DAMAGE. 29.\" 30.Dd May 12, 2020 31.Dt NPFCTL 8 32.Os 33.Sh NAME 34.Nm npfctl 35.Nd control NPF packet filter 36.Sh SYNOPSIS 37.Nm npfctl 38.Ar command 39.Op Ar arguments 40.\" ----- 41.Sh DESCRIPTION 42The 43.Nm 44command can be used to control the NPF packet filter. 45For a description of NPF's configuration file, see 46.Xr npf.conf 5 . 47.Pp 48The first argument, 49.Ar command , 50specifies the action to take. 51Valid commands are: 52.Bl -tag -width reload -offset 3n 53.It Ic start 54Enable packet inspection using the currently loaded configuration, if any. 55Note that this command does not load or reload the configuration, 56or affect existing connections. 57.It Ic stop 58Disable packet inspection. 59This command does not change the currently loaded configuration, 60or affect existing connections. 61.It Ic reload Op Ar path 62Load or reload configuration from file. 63The configuration file at 64.Pa /etc/npf.conf 65will be used unless a file is specified by 66.Ar path . 67All connections will be preserved during the reload, except those which 68will lose NAT policy due to removal. 69NAT policy is determined by the translation type and address. 70Note that change of filter criteria will not expire associated connections. 71The reload operation (i.e., replacing the ruleset, NAT policies and tables) 72is atomic. 73.It Ic flush 74Flush configuration. 75That is, remove all rules, tables and expire all connections. 76This command does not disable packet inspection. 77.It Ic show 78Show the current state and configuration. 79Syntax of printed configuration is for the user and may not match the 80.Xr npf.conf 5 81syntax. 82.It Ic validate Op Ar path 83Validate the configuration file and the processed form. 84The configuration file at 85.Pa /etc/npf.conf 86will be used unless a file is specified by 87.Ar path . 88The 89.Ar path 90may also be set to "-" for reading from 91.Em stdin . 92.\" --- 93.It Ic rule Ar name Ic add Aq rule-syntax 94Add a rule to a dynamic ruleset specified by 95.Ar name . 96On success, returns a unique identifier which can be used to remove 97the rule with 98.Ic rem-id 99command. 100The identifier is alphanumeric string. 101.It Ic rule Ar name Ic rem Aq rule-syntax 102Remove a rule from a dynamic ruleset specified by 103.Ar name . 104This method uses SHA1 hash computed on a rule to identify it. 105Although very unlikely, it is subject to hash collisions. 106For a fully reliable and more efficient method, it is recommended to use 107.Ic rem-id 108command. 109.It Ic rule Ar name Ic rem-id Aq id 110Remove a rule specified by unique 111.Ar id 112from a dynamic ruleset specified by 113.Ar name . 114.It Ic rule Ar name Ic list 115List all rules in the dynamic ruleset specified by 116.Ar name . 117.It Ic rule Ar name Ic flush 118Remove all rules from the dynamic ruleset specified by 119.Ar name . 120.\" --- 121.It Ic table Ar name Ic add Aq Ar addr/mask 122In table 123.Ar name , 124add the IP address and optionally netmask, specified by 125.Aq Ar addr/mask . 126Only the tables of type "lpm" support masks. 127.It Ic table Ar name Ic rem Aq Ar addr/mask 128In table 129.Ar name , 130remove the IP address and optionally netmask, specified by 131.Aq Ar addr/mask . 132Only the tables of type "lpm" support masks. 133.It Ic table Ar name Ic test Aq Ar addr 134Query the table 135.Ar name 136for a specific IP address, specified by 137.Ar addr . 138If no mask is specified, a single host is assumed. 139.It Ic table Ar name Ic list 140List all entries in the currently loaded table specified by 141.Ar name . 142This operation is expensive and should be used with caution. 143.It Ic table Ar name Ic replace Oo Fl n Ar newname Oc Oo Fl t Ar type Oc Aq Ar path 144Replace the existing table specified by 145.Ar name 146with a new table built from the file specified by 147.Ar path . 148Optionally, the new table will: 149.Bl -tag -width xxxxxxxxxx -compact -offset 3n 150.It Fl n Ar newname 151be named 152.Ar newname , 153effectively renaming the table. 154If not specified, the name of the table being replaced will be used. 155.It Fl t Ar type 156be of type 157.Ar type ; 158currently supported types are 159.Cm ipset , 160.Cm lpm , 161or 162.Cm const . 163If not specified, the type of the table being replaced will be used. 164.El 165.\" --- 166.It Ic save Op Ar path 167Save the active configuration with a snapshot of the current connections. 168The data will be stored in the 169.Pa /var/db/npf.db 170file unless a file is specified by 171.Ar path . 172Administrator may want to stop the packet inspection before saving. 173.It Ic load 174Load the saved configuration file and the connections from the file. 175Note that any existing connections will be destroyed. 176Administrator may want to start packet inspection after the load. 177.It Ic stats 178Print various statistics. 179.It Ic debug ( Fl a | Fl b Ar binary-config | Fl c Ar config ) \ 180Oo Fl o Ar outfile Oc 181Process the active configuration (if 182.Fl a 183is set), the given binary configuration (if 184.Fl b 185is set) or the given the plain configuration (if 186.Fl c 187is set). 188Print the byte-code of each rule and the encoded configuration data. 189Also, if 190.Fl o 191is set, write the binary configuration data into the given file. 192.Pp 193This is primarily for developer use. 194.It Ic list Oo Fl 46hNnW Oc Op Fl i Ar ifname 195Display a list of tracked connections: 196.Bl -tag -width xxxxxxxxx -compact -offset 3n 197.It Fl 4 198Display only IPv4 connections. 199.It Fl 6 200Display only IPv6 connections. 201.It Fl h 202Don't display a header. 203.It Fl N 204Try to resolve addresses. 205.It Fl n 206Only show NAT connections. 207.It Fl W 208Restrict the display width. 209.It Fl i Ar ifname 210Display only connections through the named interface. 211.El 212.El 213.Sh PERFORMANCE 214Reloading the configuration is a relatively expensive operation. 215Therefore, frequent reloads should be avoided. 216Use of tables should be considered as an alternative design. 217See 218.Xr npf.conf 5 219for details. 220.\" ----- 221.Sh FILES 222.Bl -tag -width Pa -compact 223.It Pa /dev/npf 224control device 225.It Pa /etc/npf.conf 226default configuration file 227.El 228.\" ----- 229.Sh EXAMPLES 230Starting the NPF packet filter: 231.Bd -literal -offset indent 232# npfctl reload 233# npfctl start 234# npfctl show 235.Ed 236.Pp 237Addition and removal of entries in the table whose ID is "vip": 238.Bd -literal -offset indent 239# npfctl table "vip" add 10.0.0.1 240# npfctl table "vip" rem 182.168.0.0/24 241.Ed 242.Pp 243Replacing the existing table which has ID "svr" 244with a new const table populated from file "/tmp/npf_vps_new", 245and renamed to "vps": 246.Bd -literal -offset indent 247# npfctl table "svr" replace -n "vps" -t const "/tmp/npf_vps_new" 248.Ed 249.\" ----- 250.Sh SEE ALSO 251.Xr bpf 4 , 252.Xr npf.conf 5 , 253.Xr npf 7 , 254.Xr npfd 8 255.Sh HISTORY 256NPF first appeared in 257.Nx 6.0 . 258.Sh AUTHORS 259NPF was designed and implemented by 260.An Mindaugas Rasiukevicius . 261