1 1.15 gdt # $NetBSD: TODO.npf,v 1.15 2025/04/17 19:54:24 gdt Exp $ 2 1.1 maxv 3 1.10 gdt # Meta 4 1.9 gdt 5 1.11 gdt This file intends to be the location for all work needing to be done 6 1.15 gdt for npf within NetBSD, except for bugs that are straightforward enough 7 1.15 gdt to live in gnats. The presence of an item does not imply that there 8 1.15 gdt is consensus that the item should be implemented. 9 1.1 maxv 10 1.11 gdt (The older TODO list, last modified in May, 2020: 11 1.10 gdt https://www.netbsd.org/~rmind/npf/__tasklist.html 12 1.11 gdt has been merged into this file.) 13 1.9 gdt 14 1.10 gdt ## Review all items to see if they are still relevant and correct. 15 1.1 maxv 16 1.14 gdt # Syncing 17 1.14 gdt 18 1.14 gdt ## from https://github.com/rmind/npf/ 19 1.14 gdt 20 1.14 gdt Periodically, check this repo to see if there are changes/improvements 21 1.14 gdt that are not in NetBDS and which are appopriate, and merge them. 22 1.14 gdt 23 1.14 gdt ## to https://github.com/rmind/npf/ 24 1.14 gdt 25 1.14 gdt Periodically, compare code between NetBSD and this repo, and file PRs 26 1.14 gdt for changes in NetBSD as appropriate, when there are not already PRs. 27 1.14 gdt 28 1.14 gdt ## Merge https://github.com/rmind/npf doc subdir 29 1.14 gdt 30 1.14 gdt rmind's repo has a doc directory. Some content is in man pages and 31 1.14 gdt thus available within NetBSD. Understand if there are things that 32 1.14 gdt aren't (likely), decide how to have them in NetBSD 33 1.14 gdt (/usr/share/doc/npf?) and add them. 34 1.14 gdt 35 1.10 gdt # Documentation 36 1.1 maxv 37 1.12 gdt ## Conversion Guides 38 1.1 maxv 39 1.12 gdt Add instructions for converting configuration for other packet filters 40 1.12 gdt to npf configuration. 41 1.12 gdt 42 1.12 gdt ## More Examples 43 1.12 gdt 44 1.14 gdt ## Man page nits 45 1.14 gdt 46 1.14 gdt ### npf.conf: rule group processing 47 1.14 gdt 48 1.14 gdt Explain if groups are processed in the same order as npf.conf. 49 1.14 gdt Explain what happens if a packet matches the group header, but does 50 1.14 gdt not match a rule in the group. Currently it is unclear exactly when 51 1.14 gdt the default group is run, and if multiple matching groups might run. 52 1.14 gdt 53 1.14 gdt ### npf.conf dynamic ruleset 54 1.14 gdt 55 1.14 gdt Dynamic rulesets are mentioned in npfctl, and blocklistd examples, but 56 1.14 gdt they are not explained in npf.conf. In addition to the basics, while 57 1.14 gdt it is not expected that these rules be treated as if they have the 58 1.14 gdt final flag, the code seems to do that. 59 1.14 gdt 60 1.12 gdt # NetBSD integration 61 1.12 gdt 62 1.12 gdt ## save/restore 63 1.12 gdt 64 1.12 gdt /etc/rc.d/npf lacks the ability to save and load state (stateful rules 65 1.12 gdt and NAT). 66 1.1 maxv 67 1.10 gdt # npfctl 68 1.1 maxv 69 1.10 gdt ## npfctl start does not load 70 1.1 maxv 71 1.10 gdt npfctl start does not load the configuration if not loaded. 72 1.10 gdt It is not clear you need to reload first. Or if it loads it should 73 1.10 gdt print the error messages. Or it should be called enable/disable since 74 1.10 gdt this is what it does. It does not "start" because like an engine with 75 1.10 gdt no fuel, an npf with no configuration does not do much. 76 1.1 maxv 77 1.12 gdt Alternatively: warn if there are no rules, or decide that npfctl 78 1.12 gdt behaves as documented. 79 1.12 gdt 80 1.10 gdt ## better error reporting 81 1.1 maxv 82 1.10 gdt although the framework checks the file for consistency, returning 83 1.10 gdt EINVAL for system failures is probably not good enough. For example if 84 1.10 gdt a module failed to autoload, it is probably an error and it should be 85 1.10 gdt reported differently? 86 1.1 maxv 87 1.12 gdt ## handle array variables in more places 88 1.1 maxv 89 1.12 gdt (Decide if this is just about npfctl or also about the kernel, and if 90 1.12 gdt the latter move it.) 91 1.1 maxv 92 1.11 gdt ## support variables and inline sets which contain both IPv4 and IPv6 addresses 93 1.11 gdt 94 1.11 gdt for example: $ext_if = { inet4(wm0), inet6(wm0) } 95 1.11 gdt 96 1.12 gdt (Decide if this is just about npfctl or also about the kernel, and if 97 1.12 gdt the latter move it.) 98 1.12 gdt 99 1.11 gdt ## support inline blocks with different types of data in the rule. 100 1.11 gdt 101 1.11 gdt This will require a clean-up of the type system in 102 1.11 gdt npfctl parser, since it is currently a bit of a mess. Examples: 103 1.11 gdt 104 1.11 gdt pass in from all to { inet4(wm0), $some_var, 10.0.0.1, } 105 1.11 gdt pass in final proto tcp to 172.28.1.2 port { 161, 162 } 106 1.11 gdt pass in final proto { tcp, udp } to 172.28.1.2 port 53 107 1.11 gdt 108 1.11 gdt [MOSTLY DONE?] 109 1.11 gdt 110 1.12 gdt (Decide if this is just about npfctl or also about the kernel, and if 111 1.12 gdt the latter move it.) 112 1.12 gdt 113 1.11 gdt ## npf show improvements 114 1.11 gdt 115 1.11 gdt Consistent `npfctl show' output with rule syntax. Difficult/messy 116 1.11 gdt because rules are compiled into the byte-code. 117 1.11 gdt 118 1.12 gdt Add examples of what is wrong. 119 1.12 gdt 120 1.12 gdt ## -D option to set variables 121 1.12 gdt 122 1.12 gdt Allow `npfctl -D varname=value` to set a variable, as if were defined 123 1.12 gdt in the config file. See pfctl(8). 124 1.12 gdt 125 1.11 gdt # Architectural changes 126 1.11 gdt 127 1.11 gdt ## Layer 2 filtering 128 1.11 gdt 129 1.11 gdt 1. All rules in NPF are added to a ruleset. At this moment, it is assumed 130 1.11 gdt that there is only one ruleset and all rules are processed at layer 3. 131 1.11 gdt One approach is to support another ruleset for layer 2 (or rather, have 132 1.11 gdt capability to specify the "starting layer"). 133 1.11 gdt 134 1.11 gdt 2. One way to separate L2 and L3 rules could be by marking groups. In NPF, 135 1.11 gdt a group is just a rule (i.e. rules can be nested). 136 1.11 gdt 137 1.11 gdt 3. npfctl: update the parser such that the group would have an option for 138 1.11 gdt specifying a layer. See "group_opts" token in npf_parse.y file. Also, 139 1.11 gdt we may want to add support for "hwaddr <mac>" syntax or something. 140 1.11 gdt 141 1.11 gdt 4. npfctl_build_rule() code will need to distinguish groups/rules which 142 1.11 gdt were marked as layer 2, i.e. byte-code generation (npfctl_build_code() 143 1.11 gdt and the logic in it) needs to know that we are starting from Ethernet 144 1.11 gdt header and not IP header. Note: it needs to be passed to all nested 145 1.11 gdt rules, so basically take the option from the "current group". 146 1.11 gdt 147 1.11 gdt 5. For a start (i.e. less work to do), you can just add byte-code to parse 148 1.11 gdt Ethernet header and compare the MAC addresses. Just return "not supported" 149 1.11 gdt error for any other filter pattern. 150 1.11 gdt 151 1.11 gdt 6. libnpf: create a new ruleset for L2 and add all groups (and its nested 152 1.11 gdt rules) there. To keep it simpler, we can add npf_rule_setlayer() function 153 1.11 gdt and just handle this separation in libnpf rather than npfctl. 154 1.11 gdt 155 1.11 gdt 7. libnpf-kernel: currently, proplib dictionary has only one "ruleset" dict. 156 1.11 gdt This needs to be split into "ruleset-l3" and "ruleset-l2". Retrieve and 157 1.11 gdt construct a new ruleset in npfctl_reload(); it is simple, but disgusting 158 1.11 gdt proplib code. It is just re-using the existing code to handle another 159 1.11 gdt ruleset. 160 1.11 gdt 161 1.11 gdt 8. Kernel: add a new handler in npf_handler.c, e.g. npf_packet_l2handler() 162 1.11 gdt or something. Register it in npf_pfil_register() using Ethernet pfil 163 1.11 gdt hook. In the handler, call npf_ruleset_inspect() passing L2 ruleset. 164 1.11 gdt 165 1.11 gdt ## Consider single large BPF program 166 1.11 gdt 167 1.11 gdt Implement NPF rules as a single large BPF program, instead of 168 1.11 gdt providing BPF byte-code per each rule. In combination with BPF JIT 169 1.11 gdt compilation, such approach would significantly improve the performance 170 1.11 gdt of very large rulesets. Problems: BPF byte-code limitations; we can 171 1.11 gdt either extend the byte-code or workaround them. 172 1.11 gdt 173 1.11 gdt ## Multiple rule matching 174 1.11 gdt 175 1.11 gdt Multiple rule matching to call the rule-procedures or a suitable 176 1.11 gdt design alternative to that. 177 1.11 gdt 178 1.12 gdt (Explain what this means more clearly.) 179 1.12 gdt 180 1.11 gdt ## ipchains-like feature 181 1.11 gdt 182 1.11 gdt Implement ipchains-like feature to support nested rules and sharing of 183 1.11 gdt a rule group. NPF already supports nested rules. Unresolved questions 184 1.11 gdt are: 1) what kind of complexity of rule chains do we want to support, 185 1.11 gdt e.g. a directed graph with loop resolution or more strict hierarchy 186 1.11 gdt which does not allow jumping up the chain? 2) syntax in npf.conf file. 187 1.11 gdt 188 1.15 gdt ## Support for packets arriving at or departing the socket layer 189 1.15 gdt 190 1.15 gdt Similar to how one can do this in nftables, add a way to write a rule 191 1.15 gdt that will be applied to all packets being delivered to sockets, or 192 1.15 gdt really processed by the system as a host rather than simply forwarded. 193 1.15 gdt The point is to be able to express rules like "block connections to 194 1.15 gdt this machine's ssh daemon, but don't block ssh connections that are 195 1.15 gdt merely being routed", without having to match on addresses. 196 1.15 gdt 197 1.11 gdt ## redundancy and load balancing 198 1.11 gdt 199 1.11 gdt Redundancy and load balancing: initially, add state replication and 200 1.12 gdt replace in-kernel CARP/VRRP with a userlevel daemon. 201 1.12 gdt 202 1.12 gdt Check "Note: we probably want to eliminate proplib in NPF before doing 203 1.12 gdt this." and drop if proplib has in fact been eliminated. 204 1.11 gdt 205 1.13 gdt ## QoS 206 1.11 gdt 207 1.11 gdt QoS: rate limiting, traffic shaping, prioritising. Question: how much 208 1.11 gdt of this should be a part of the packet filter and how much of the 209 1.11 gdt network stack (merely involving some integration with the packet 210 1.11 gdt filters)? 211 1.11 gdt 212 1.12 gdt ## address/port and port in tables 213 1.11 gdt 214 1.12 gdt Tables currently contain addresses. Add support for address/port 215 1.12 gdt tuples, and ports. 216 1.11 gdt 217 1.13 gdt ## Separate mss clamping from normal rules 218 1.13 gdt 219 1.13 gdt Currently, mss clamping is a rule procedure and has to be specified on 220 1.13 gdt a matching rule. But, if there are both firewall rules and a desire 221 1.13 gdt to clamp, then one has to add clamping to all rules. This item is 222 1.13 gdt about having a way to express rules normally, and also say that 223 1.13 gdt clamping shouldhappen. 224 1.13 gdt 225 1.13 gdt http://mail-index.netbsd.org/tech-net/2017/01/15/msg006224.html 226 1.13 gdt 227 1.11 gdt # Features (not needing architectural changes) 228 1.11 gdt 229 1.13 gdt ## Add an extension for "route-to" 230 1.11 gdt 231 1.13 gdt The essence is to change the next hop of a packet if it matches a 232 1.13 gdt rule. 233 1.13 gdt 234 1.13 gdt http://mail-index.netbsd.org/tech-net/2014/05/19/msg004526.html 235 1.11 gdt 236 1.11 gdt ## support for ALTQ 237 1.11 gdt 238 1.13 gdt ALTQ is a QoS scheme, and it expects a way to classify packets so that 239 1.13 gdt different flows can be treated differently. Currently, ALTQ in NetBSD 240 1.13 gdt uses pf. (An earlier comment indicated a solution might involve mbuf 241 1.13 gdt tags.) 242 1.12 gdt 243 1.11 gdt ## Support for NAT64 i.e. the protocol translation. 244 1.11 gdt 245 1.12 gdt ## MiniUPnP 246 1.11 gdt 247 1.12 gdt Add support for MiniUPnP (see http://miniupnp.free.fr/ web page). 248 1.11 gdt 249 1.12 gdt ## add support for "with short" 250 1.12 gdt 251 1.13 gdt (Clarify: is this about dropping packets that are shorter than they 252 1.13 gdt should be? Why would the user choose?) 253 1.13 gdt 254 1.13 gdt ## Add specific kinds of ICMP unreachable 255 1.11 gdt 256 1.13 gdt Currently, rules are documented to allow returning `ICMP UNREACHABLE` 257 1.13 gdt given the keyword `return-icmp`. Probably this is ICMP Admin 258 1.13 gdt Prohibited, but this is not clear. 259 1.13 gdt 260 1.13 gdt This item is about different or additional keywords to allow the user 261 1.13 gdt to specify network, host, or port unreachable instead. 262 1.11 gdt 263 1.11 gdt # Security 264 1.11 gdt 265 1.12 gdt ## Extra measures to protect npf from SYN flood attacks. 266 1.11 gdt 267 1.11 gdt E.g. accelerate connection expiration on low memory or after certain 268 1.12 gdt threshold. The timeout can also be self-balancing. This item is about 269 1.12 gdt protecting npf state in situations where excessive SYNs arrive in 270 1.12 gdt situations where a legitimate SYN should trigger a state entry. 271 1.12 gdt 272 1.12 gdt ## Consider blind reset attacks (see RFC 5961). 273 1.12 gdt 274 1.12 gdt This is about the situation when npf is doing stateful processing on a 275 1.12 gdt TCP connection and only allowing packets matching the connection. 276 1.12 gdt Extend the definition of a packet matching the connection to meet the 277 1.12 gdt new rules in RFC5961, and perhaps generate the specified response 278 1.12 gdt packets. 279 1.11 gdt 280 1.14 gdt ## Add counters 281 1.14 gdt 282 1.14 gdt Add a hit counter to rules, or some other way so that the user can say 283 1.14 gdt "show me the list of rules and for each rules, how many times it was 284 1.14 gdt invoked". This is similar to ipfilter's `ipfstat -inh`. 285 1.14 gdt 286 1.10 gdt # General 287 1.1 maxv 288 1.12 gdt ## IPv4 options 289 1.12 gdt 290 1.12 gdt Implement "block return-icmp in log final all with ipopts". 291 1.12 gdt (Explain if this is more than "enable writing rules to match packets 292 1.12 gdt with ip options".) 293 1.2 maxv 294 1.12 gdt Consider defaulting to blocking options, with "allow-ip4opts" to 295 1.12 gdt enable them. 296 1.10 gdt 297 1.12 gdt ## IPv6 options 298 1.10 gdt 299 1.12 gdt (Jointly with IPv4 options.) 300 1.12 gdt 301 1.12 gdt Perhaps a limited set (IPPROTO_ROUTING, IPPROTO_HOPOPTS and 302 1.12 gdt IPPROTO_DSTOPTS) by default, and "allow-ip6opts" to enable others. 303 1.10 gdt 304 1.10 gdt ## add an ioctl, similar to PF's DIOCNATLOOK and IPF's SIOCGNATL 305 1.10 gdt 306 1.10 gdt document it so that it can be added in third-party software, like: 307 1.10 gdt https://github.com/squid-cache/squid/blob/5b74111aff8948e869959113241adada0cd488c2/src/ip/Intercept.cc#L263 308 1.10 gdt 309 1.13 gdt ### patch squid to support transparent-proxy with NPF. 310 1.12 gdt 311 1.12 gdt (Likely, simply using the ioctl from the previous item.) 312 1.12 gdt 313 1.10 gdt ## support IPv6 jumbograms 314 1.10 gdt 315 1.12 gdt (Explain what is or is not supported now, and what needs to happen 316 1.12 gdt differently.) 317 1.12 gdt 318 1.13 gdt ## IPv6 reassembly 319 1.13 gdt 320 1.13 gdt Investigate and fix the IPv6 reassembly (there is a memory leak). 321 1.13 gdt 322 1.13 gdt ## nbuf_ensure_writable 323 1.13 gdt 324 1.13 gdt Use nbuf_ensure_writable() where appropriate. 325 1.10 gdt 326 1.13 gdt # Low priority items 327 1.10 gdt 328 1.13 gdt These items are left in the list, but there's no reason to think 329 1.13 gdt anyone will address them any time soon, or that they are high enough 330 1.13 gdt priority that anyone should. They can of course be moved (up likely 331 1.13 gdt clarified if someeone, especially someone intending to work on them, 332 1.13 gdt doesn't see it that way. (Perhaps we should drop them, but for now 333 1.13 gdt they are parked.) 334 1.13 gdt 335 1.13 gdt ## NAT Application Level Gateways for FTP 336 1.13 gdt 337 1.13 gdt Generally, FTP is done in passive mode, so that the data connection is 338 1.13 gdt created by the client, and no particular support is needed in 339 1.13 gdt firewalls. This item is about creating an alg that allows the 340 1.13 gdt (regular, not passive mode) inbound connection from the server, based 341 1.13 gdt on watching the control connection. 342 1.5 sborrill 343 1.13 gdt (It is likely that there are almost no remaining uses of active FTP, 344 1.13 gdt and thus it is unlikely this would be implemented.) 345 1.11 gdt 346 1.13 gdt ## Consider experimentation to use bloom filters against certain DoS attacks. 347 1.11 gdt 348 1.13 gdt (This needs much more clarity.) 349 1.11 gdt 350 1.13 gdt ## support large IPv6 options 351 1.11 gdt 352 1.13 gdt as explained here: 353 1.13 gdt http://mail-index.netbsd.org/tech-net/2018/04/08/msg006786.html 354 1.13 gdt But it's not a big problem - perhaps we don't care at all. 355 1.11 gdt 356 1.11 gdt ## TCP FSM enhancement 357 1.11 gdt 358 1.12 gdt Minor TCP FSM investigation: should it be not allowed to immediately 359 1.12 gdt re-open the connection after RST or FIN? 360 1.12 gdt 361 1.12 gdt (Explain what this means, how it relates to standards, and what the 362 1.12 gdt concerns are.) 363