summaryrefslogtreecommitdiff
path: root/sys/net/npf
AgeCommit message (Collapse)Author
2023-02-24npf: Eliminate __HAVE_ATOMIC_AS_MEMBAR conditionals.riastradh
Discussed on tech-kern: https://mail-index.netbsd.org/tech-kern/2023/02/23/msg028729.html Requested by rmind@: https://github.com/rmind/npf/pull/127#issuecomment-1399573125
2023-02-12PR kern/56052:kardel
allow block-return packets passed through without rule matching. Included up-stream as https://github.com/rmind/npf/pull/115
2023-02-12PR kern/55654:kardel
Switch default for parameter npf ip4.reassembly to 1. This makes the NPF default configuration comply with host requirements for IPv4.
2023-01-23npf(9): Drop table lock around copyout.riastradh
It is forbidden to hold a spin lock around copyout, and t_lock is a spin lock. We need t_lock in order to iterate over the list of entries. However, during copyout itself, we only need to ensure that the object we're copying out isn't freed by npf_table_remove or npf_table_gc. Fortunately, the only caller of npf_table_list, npf_table_remove, and npf_table_gc is npfctl_table, and it serializes all of them by the npf config lock. So we can safely drop t_lock across copyout. PR kern/57136 PR kern/57181
2023-01-22npf(9): Another comment tweak to match upstream.riastradh
No functional change.
2023-01-22npf(9): Update comment to reduce diff from upstream.riastradh
No functional change.
2023-01-22npf(9): Use __HAVE_ATOMIC_AS_MEMBAR around refcnt consistently.riastradh
2022-04-28Make the thmap(9) used for params use sleepable allocations,martin
suggested by rmind@. Should fix PR 56802.
2022-04-28Temporary hack to make PR 56802 (when it happens) tell us for sure thatmartin
it is caused by KM_NOSLEEP memory allocation failure.
2022-04-09sys: Use membar_release/acquire around reference drop.riastradh
This just goes through my recent reference count membar audit and changes membar_exit to membar_release and membar_enter to membar_acquire -- this should make everything cheaper on most CPUs without hurting correctness, because membar_acquire is generally cheaper than membar_enter.
2022-03-12sys: Membar audit around reference count releases.riastradh
If two threads are using an object that is freed when the reference count goes to zero, we need to ensure that all memory operations related to the object happen before freeing the object. Using an atomic_dec_uint_nv(&refcnt) == 0 ensures that only one thread takes responsibility for freeing, but it's not enough to ensure that the other thread's memory operations happen before the freeing. Consider: Thread A Thread B obj->foo = 42; obj->baz = 73; mumble(&obj->bar); grumble(&obj->quux); /* membar_exit(); */ /* membar_exit(); */ atomic_dec -- not last atomic_dec -- last /* membar_enter(); */ KASSERT(invariant(obj->foo, obj->bar)); free_stuff(obj); The memory barriers ensure that obj->foo = 42; mumble(&obj->bar); in thread A happens before KASSERT(invariant(obj->foo, obj->bar)); free_stuff(obj); in thread B. Without them, this ordering is not guaranteed. So in general it is necessary to do membar_exit(); if (atomic_dec_uint_nv(&obj->refcnt) != 0) return; membar_enter(); to release a reference, for the `last one out hit the lights' style of reference counting. (This is in contrast to the style where one thread blocks new references and then waits under a lock for existing ones to drain with a condvar -- no membar needed thanks to mutex(9).) I searched for atomic_dec to find all these. Obviously we ought to have a better abstraction for this because there's so much copypasta. This is a stop-gap measure to fix actual bugs until we have that. It would be nice if an abstraction could gracefully handle the different styles of reference counting in use -- some years ago I drafted an API for this, but making it cover everything got a little out of hand (particularly with struct vnode::v_usecount) and I ended up setting it aside to work on psref/localcount instead for better scalability. I got bored of adding #ifdef __HAVE_ATOMIC_AS_MEMBAR everywhere, so I only put it on things that look performance-critical on 5sec review. We should really adopt membar_enter_preatomic/membar_exit_postatomic or something (except they are applicable only to atomic r/m/w, not to atomic_load/store_*, making the naming annoying) and get rid of all the ifdefs.
2022-02-13npf(4): Use atomic_store_release and atomic_load_consume for conn_db.riastradh
...or atomic_load_relaxed, when npf->conn_lock is held, for the sake of C11. No need for store-before-load implied by membar_sync.
2022-02-13npf(4): Use atomic_store_release and atomic_load_consume for config.riastradh
...or atomic_load_relaxed, when the config is locked. (Not necessary to use atomic_* at all in NetBSD, but in C11 it will be cheaper to say atomic_load_relaxed explicitly so an _Atomic-qualified object doesn't cause the load to be surrounded by unnecessary membars.) No need for store-before-load ordering here, so no need to membar_sync.
2021-03-08reinstate a simple version of ip_randomid()christos
2021-01-27Don't silently ignore the errors from npfctl_run_op. We end up returningchristos
packets to userland that are missing required fields (like in rule_add the id of the rule) and npfctl aborts.
2021-01-25s/npf_config_lock/npf->config_lock/ in the commentschristos
2021-01-25Fix locking issue: npf_default_pass needs to be called with the config lockchristos
held.
2020-08-28npf: Remove harmless vestiges of debugging hacks.riastradh
2020-08-27npf: Make sure to initialize portmap_lock only once.riastradh
PR kern/55586
2020-08-27npf: Don't stop early after sleeping and before processing instances.riastradh
We already check winfo->exit below, after processing instances and before sleeping again. Candidate fix for: panic: kernel diagnostic assertion "LIST_EMPTY(&winfo->instances)" failed: file "/home/riastradh/netbsd/current/src/sys/rump/net/lib/libnpf/../../../..//net/npf/npf_worker.c", line 300 NPF instances must be discharged before the npfk_sysfini() call
2020-08-18Add missing cases, to prevent memory corruption.maxv
Reported-by: syzbot+f8b8a689a3560dda27f7@syzkaller.appspotmail.com
2020-05-30npf_worker_sys{init,fini}: initialize/destroy the exit_cv condvar.rmind
2020-05-30Major NPF improvements (merge from upstream):rmind
- Switch to the C11-style atomic primitives using atomic_loadstore(9). - npfkern: introduce the 'state.key.interface' and 'state.key.direction' settings. Users can now choose whether the connection state should be strictly per-interface or global at the configuration level. Keep NAT logic to be always per-interface, though. - npfkern: rewrite the G/C worker logic and make it self-tuning. - npfkern and libnpf: multiple bug fixes; add param exporting; introduce more parameters. Remove npf_nvlist_{copyin,copyout}() functions and refactor npfctl_load_nvlist() with others; add npfctl_run_op() to have a single entry point for operations. Introduce npf_flow_t and clean up some code. - npfctl: lots of fixes for the 'npfctl show' logic; make 'npfctl list' more informative; misc usability improvements and more user-friendly error messages. - Amend and improve the manual pages.
2020-05-23Backport selected NPF fixes from the upstream (to be pulled up):rmind
- npf_conndb_lookup: protect the connection lookup with pserialize(9), instead of incorrectly assuming that the handler always runs at IPL_SOFNET. Should fix crashes reported on high load (PR/55182). - npf_config_destroy: handle partially initialized config; fixes crashes with some invalid configurations. - NAT policy creation / destruction: set the initial reference and do not wait for reference draining on destruction; destroy the policy on the last reference drop instead. Fixes a lockup with the dynamic NAT rules. - npf_nat_{export,import}: fix a regression since dynamic NAT rules. - npfctl: fix a regression and restore the default group behaviour. - Add npf_cache_tcp() and validate the TCP data offset (from maxv@).
2020-02-12PR/54950: Lloyd Parkes: Avoid NULL deref.christos
2020-02-07Use percpu_foreach_xcall() to gather volatile per-cpu counters. Thesethorpej
must be serialized against the interrupts / soft-interrupts in which they're manipulated, as well as protected from non-atomic 64-bit memory loads on 32-bit platforms.
2020-01-29Adopt <net/if_stats.h>.thorpej
2019-12-14Skip npf_config_sync if nothing to do.riastradh
Saves an unnecessary pserialize_perform every second.
2019-09-30npf_ifmap_copylogname: be more defensive.rmind
2019-09-30libnpf/npfctl: support dynamic NAT rulesets using a name prefix.rmind
2019-09-29NPF ifmap: rework and fix a few small bugs.rmind
2019-09-26Cast m_mbuflen() result to "size_t". It could also be "u_int" since it ischristos
assigned to "u_int", but all the other "standalone" equivalent functions return "size_t".
2019-08-25 ake npfctl_switch() and pfil private to OS-specific module.rmind
2019-08-25Move PACKET_TAG_NPF where it belongs to.rmind
2019-08-25- npfctl_load_nvlist: simplify the config loading logic.rmind
- Fix a small race condition in npf_nat_getaddr(). - Rework pserialize/EBR wrappers, make it easier to maintain.
2019-08-21npfkern/libnpf: Add support for the table replace/swap operation.rmind
Contributed by Timshel Knoll-Miller.
2019-08-11Adjust some internal NPF APIs:rmind
* npfkern: use the npfk_ prefix. * NPF portmap: amend the API so it could be used elsewhere. * Make npf_connkey_t public.
2019-08-10Add the ifnet_t::if_npf_private field. Bump the kernel version.rmind
Fixes PR/54098.
2019-08-06- npf_conn_init(): fix a race when initialising the G/C thread.christos
- Fix a bug when partially initialised connection is destroyed on error. (from rmind@)
2019-08-06Introduce an npf_conn_destroy_idx() that can handle partially constructedchristos
conn structures.
2019-07-25npf_portmap_flush: remove invalid assert (this routine can be callied viarmind
the npf_destroy() path where the constraint is not applicable).
2019-07-23NPF portmap: add a workaround for archs without 64-bit CAS.rmind
2019-07-23NPF improvements:rmind
- Add support for dynamic NETMAP algorithm (stateful net-to-net). - Add most of the support for the dynamic NAT rules; a little bit more userland work is needed to finish this up and enable. - Replace 'stateful-ends' with more permissive 'stateful-all'. - Add various tunable parameters and document them, see npf-params(7). - Reduce the memory usage of the connection state table (conndb). - Portmap rewrite: use memory more efficiently, handle addresses dynamically. - Bug fix: add splsoftnet()/splx() around the thmap writers and comment. - npftest: clean up and simplify; fix some memleaks to make ASAN happy.
2019-06-20Add error checking for previous memory allocation failure.christos
2019-06-20PR/54314: Frank Kardel: LOCKDEBUG: Mutex error: assert_sleepable,70:christos
spin lock held when loading NPF
2019-06-12Avoid LOCKDEBUG pserialize panic by implementing suggestion #1 fromchristos
http://mail-index.netbsd.org/current-users/2019/02/24/msg035220.html: Convert the mutex to spin-lock at IPL_NET (but it is excessive) and convert the memory allocations in that code path to KM_NOSLEEP.
2019-04-11Fix CVS Id usagekamil
2019-02-27work around a GCC 7 vs sparc (32 bit) issue i haven't figured outmrg
the real cause of yet. mark npf_init() as non-static. for a yet-unknown reason, when this function is inlined by the compiler (or a human!) into the single caller, some CPUs end up in a hung state that can't be interrupted eventually leading to system hang. eg: [ 8.9693040] root on hme0 [ 8.9862690] nfs_boot: trying DHCP/BOOTP xcall(cpu2,0xf0240ac8) from 0xf0241170: couldn't ping cpus: cpu1 is the symptom though sometimes nfs_boot is actually able to complete mountroot before it hangs. this may be a compiler bug but the symptom and the trigger are far removed and my so-far reading of the "broken" npf_init inlining has shown no issues, however, i haven't completed a full scan of this asm in the past month so i'm commiting this workaround for now.
2019-01-19Major NPF improvements:rmind
- Convert NPF connection table to thmap. State lookup is now lock-free. - Improve connection state G/C: it is now incremental and tunable. - Add support for dynamic NAT address. Translation addresses can now be selected from a pool of addresses. There are two selection algorithms, "ip-hash" and "round-robin" (see the man page). - Translation address can be specified as e.g. ifaddrs(wm0) in npf.conf to dynamically choose an IP from the interface address(es). - Add support for the NETMAP algorithm with static NAT for net-to-net translation (it is equivalent to iptables NETMAP logic). - Convert 'ipset' tables to use thmap; the table lookup is now lock-free. - Misc improvements, bug fixes and more unit tests. - Bump NPF_VERSION (will also bump libnpf).
2018-11-15Remove the 't' argument from m_tag_find().maxv