Home | History | Annotate | Line # | Download | only in doc
TODO.npf revision 1.11
      1 # $NetBSD: TODO.npf,v 1.11 2025/04/17 18:11:58 gdt Exp $
      2 
      3 # Meta
      4 
      5 This file intends to be the location for all work needing to be done
      6 for npf within NetBSD, except for bugs that are straightforward enough to live
      7 in gnats.
      8 
      9 (The older TODO list, last modified in May, 2020:
     10   https://www.netbsd.org/~rmind/npf/__tasklist.html
     11 has been merged into this file.)
     12 
     13 ## Review all items to see if they are still relevant and correct.
     14 
     15 # Documentation
     16 
     17 ## how to convert other packet filters to npf
     18 
     19 ## add more examples
     20 
     21 # npfctl
     22 
     23 ## npfctl start does not load
     24 
     25 npfctl start does not load the configuration if not loaded.
     26 It is not clear you need to reload first. Or if it loads it should
     27 print the error messages. Or it should be called enable/disable since
     28 this is what it does. It does not "start" because like an engine with
     29 no fuel, an npf with no configuration does not do much.
     30 
     31 ## better error reporting
     32 
     33 although the framework checks the file for consistency, returning
     34 EINVAL for system failures is probably not good enough. For example if
     35 a module failed to autoload, it is probably an error and it should be
     36 reported differently?
     37 
     38 ## startup/stop script does not load and save session state
     39 
     40 ## add support for "with short"
     41 
     42 ## implement "port-unr"
     43 
     44 ## implement block return-icmp in log final all with ipopts
     45 
     46 ## handle array variables in more places
     47 
     48 ## support variables and inline sets which contain both IPv4 and IPv6 addresses
     49 
     50 for example: $ext_if = { inet4(wm0), inet6(wm0) }
     51 
     52 ## support inline blocks with different types of data in the rule.
     53 
     54 This will require a clean-up of the type system in
     55 npfctl parser, since it is currently a bit of a mess. Examples:
     56 
     57 	pass in from all to { inet4(wm0), $some_var, 10.0.0.1,  }
     58 	pass in final proto tcp to 172.28.1.2 port { 161, 162 }
     59 	pass in final proto { tcp, udp } to 172.28.1.2 port 53
     60 
     61 [MOSTLY DONE?]
     62 
     63 ## npf show improvements
     64 
     65 Consistent `npfctl show' output with rule syntax.  Difficult/messy
     66 because rules are compiled into the byte-code.
     67 
     68 # Architectural changes
     69 
     70 ## Layer 2 filtering
     71 
     72 1. All rules in NPF are added to a ruleset.  At this moment, it is assumed
     73    that there is only one ruleset and all rules are processed at layer 3.
     74    One approach is to support another ruleset for layer 2 (or rather, have
     75    capability to specify the "starting layer").
     76 
     77 2. One way to separate L2 and L3 rules could be by marking groups.  In NPF,
     78    a group is just a rule (i.e. rules can be nested).
     79 
     80 3. npfctl: update the parser such that the group would have an option for
     81    specifying a layer.  See "group_opts" token in npf_parse.y file.  Also,
     82    we may want to add support for "hwaddr <mac>" syntax or something.
     83 
     84 4. npfctl_build_rule() code will need to distinguish groups/rules which
     85    were marked as layer 2, i.e. byte-code generation (npfctl_build_code()
     86    and the logic in it) needs to know that we are starting from Ethernet
     87    header and not IP header.  Note: it needs to be passed to all nested
     88    rules, so basically take the option from the "current group".
     89 
     90 5. For a start (i.e. less work to do), you can just add byte-code to parse
     91    Ethernet header and compare the MAC addresses.  Just return "not supported"
     92    error for any other filter pattern.
     93 
     94 6. libnpf: create a new ruleset for L2 and add all groups (and its nested
     95    rules) there.  To keep it simpler, we can add npf_rule_setlayer() function
     96    and just handle this separation in libnpf rather than npfctl.
     97 
     98 7. libnpf-kernel: currently, proplib dictionary has only one "ruleset" dict.
     99    This needs to be split into "ruleset-l3" and "ruleset-l2".  Retrieve and
    100    construct a new ruleset in npfctl_reload(); it is simple, but disgusting
    101    proplib code.  It is just re-using the existing code to handle another
    102    ruleset.
    103 
    104 8. Kernel: add a new handler in npf_handler.c, e.g. npf_packet_l2handler()
    105    or something.  Register it in npf_pfil_register() using Ethernet pfil
    106    hook.  In the handler, call npf_ruleset_inspect() passing L2 ruleset.
    107 
    108 ## Consider single large BPF program
    109 
    110 Implement NPF rules as a single large BPF program, instead of
    111 providing BPF byte-code per each rule. In combination with BPF JIT
    112 compilation, such approach would significantly improve the performance
    113 of very large rulesets. Problems: BPF byte-code limitations; we can
    114 either extend the byte-code or workaround them.
    115 
    116 ## Multiple rule matching
    117 
    118 Multiple rule matching to call the rule-procedures or a suitable
    119 design alternative to that.
    120 
    121 ## ipchains-like feature
    122 
    123 Implement ipchains-like feature to support nested rules and sharing of
    124 a rule group. NPF already supports nested rules. Unresolved questions
    125 are: 1) what kind of complexity of rule chains do we want to support,
    126 e.g. a directed graph with loop resolution or more strict hierarchy
    127 which does not allow jumping up the chain? 2) syntax in npf.conf file.
    128 
    129 ## redundancy and load balancing
    130 
    131 Redundancy and load balancing: initially, add state replication and
    132 replace in-kernel CARP/VRRP with a userlevel daemon. Note: we probably
    133 want to eliminate proplib in NPF before doing this.
    134 
    135 ##  QoS
    136 
    137 QoS: rate limiting, traffic shaping, prioritising. Question: how much
    138 of this should be a part of the packet filter and how much of the
    139 network stack (merely involving some integration with the packet
    140 filters)?
    141 
    142 ## tuples in tables
    143 
    144 Support for tuples in tables: address and port, as well as just port. 
    145 
    146 # Features (not needing architectural changes)
    147 
    148 ## Add an extension to support source routing / re-routing of packets.
    149 
    150 See: http://mail-index.netbsd.org/tech-net/2014/05/19/msg004526.html 
    151 
    152 ## support for ALTQ
    153 
    154 Integration with ALTQ as an intermediate solution. In the long term,
    155 we should implement a better QoS mechanism as part of NPF. Meanwhile,
    156 NPF can integrate with ALTQ quite easily using the mbuf tags.
    157 
    158 ## Support for NAT64 i.e. the protocol translation. 
    159 
    160 ## Implement ftp-proxy forward proxy support
    161 
    162 (for active FTP client behind NAT).
    163     
    164 ## Patch Squid proxy to support transparent-proxy with NPF.
    165 
    166 Just an ioctl call to perform a state lookup?
    167 
    168 ## MiniUPnP
    169 
    170 Add support for MiniUPnP (see http://miniupnp.free.fr/ web page). 
    171 
    172 # Security
    173 
    174 ## Extra measures to prevent from SYN flood attacks.
    175 
    176 E.g. accelerate connection expiration on low memory or after certain
    177 threshold. The timeout can also be self-balancing.
    178 
    179 ## Consider blind reset attack using SYN (see RFC 5961).
    180 
    181 ## Consider experimentation to use bloom filters against certain DoS attacks.
    182 
    183 # General
    184 
    185 ## disable IPv4 options by default
    186 
    187 and add a "allow-ip4opts" feature to enable them
    188 
    189 ## disable IPv6 options
    190 
    191 (IPPROTO_ROUTING, IPPROTO_HOPOPTS and IPPROTO_DSTOPTS) by default, and
    192 add a "allow-ip6opts" feature to enable them
    193 
    194 ## add an ioctl, similar to PF's DIOCNATLOOK and IPF's SIOCGNATL
    195 
    196 document it so that it can be added in third-party software, like:
    197    https://github.com/squid-cache/squid/blob/5b74111aff8948e869959113241adada0cd488c2/src/ip/Intercept.cc#L263
    198 
    199 ## support IPv6 jumbograms
    200 
    201 ## support large IPv6 options
    202 
    203 as explained here:
    204        http://mail-index.netbsd.org/tech-net/2018/04/08/msg006786.html
    205 But it's not a big problem - perhaps we don't care at all.
    206 
    207 ## add command line variables.  See -D option in pf.
    208 
    209 ## improve mss clamping
    210 
    211 as explained here:
    212        http://mail-index.netbsd.org/tech-net/2017/01/15/msg006224.html
    213 
    214 ## IPv6 reassembly
    215 
    216 Investigate and fix the IPv6 reassembly (there is a memory leak).
    217 
    218 ## nbuf_ensure_writable
    219 
    220 Use nbuf_ensure_writable() where appropriate.
    221 
    222 ## TCP FSM enhancement
    223 
    224 Minor TCP FSM investigation: should it be not allowed to immediately re-open the connection after RST or FIN?
    225