Commit Graph

3847 Commits

Author SHA1 Message Date
riastradh
d8c777ca20 wg: Sprinkle #ifdef INET6. Avoid unconditional use of ip6 structs.
Fixes no-INET6 build.

Based on patch from Brad Spencer:

https://mail-index.NetBSD.org/current-users/2020/11/11/msg039883.html
2020-11-11 18:08:34 +00:00
roy
b9f024beb1 bridge: revert prior
It's of little use.
If we need to do this in the future, consider a sysctl to do it for all
interfaces in the bridge and not just the one being added.
2020-11-02 12:14:59 +00:00
christos
8047934f22 use c99 initializers 2020-10-30 22:51:08 +00:00
roy
9c54a212f9 l2tp: call if_link_state_change rather then directly setting it.
This allows protocols to do their thing.
2020-10-25 08:18:39 +00:00
roy
1478407e3a l2tp: Revert prior
It proves I can't read comments and that if_initialize should not be used.
2020-10-25 08:15:54 +00:00
gson
a59360497a Suppress the "rn_init: radix functions require max_keylen be set"
message when _KERNEL is defined, to avoid spurious messages from
kernels that have no routable network domains.  Fixes PR kern/55691.
2020-10-18 13:07:31 +00:00
roy
3fa9fd328e net: remove IFEF_NO_LINK_STATE_CHANGE
This flag was only set for virtual interfaces.
All virtual interfaces have a means of knowing if they are going to work
or not and as such now support link state changes.

If we want this flag back, it should be used as an indicator that
the interfaces does not support link state changes that userland can use
so it can make a decision on what to do when the link state is UNKNOWN.
2020-10-15 10:20:44 +00:00
roy
efd9f92994 wg: with no peers, the link status is DOWN, otherwise UP
This mirrors the recent changes to gif(4) where the link is UP when a
tunnel is set, otherwise DOWN.
2020-10-15 10:09:49 +00:00
roy
85154fffbe l2tp: Set the link state UP if we have a tunnel, otherwise DOWN. 2020-10-15 02:54:10 +00:00
roy
120b194ae9 ipsecif: Set the link state UP if we have a tunnel, otherwise DOWN. 2020-10-14 18:48:05 +00:00
roy
4a2f7fc211 loop: set LINK_STATE_UP a touch earlier 2020-10-14 16:10:32 +00:00
roy
83204e5bcb loop: this interface's link state cannot be anything other than UP
Let's not pretend it's UNKNOWN anymore.
2020-10-14 15:55:49 +00:00
roy
680a94be6a gif: Set the link state UP if we have a tunnel, otherwise DOWN. 2020-10-14 15:22:17 +00:00
roy
9fd3530377 ppp: Remove media
There is none after all.
Applications should be using ifi_link_state and not checking media.
2020-10-05 16:11:25 +00:00
roy
25752de6ab tun: Report link state based on if the interface has been opened or not
This mirrors tap(4).
2020-09-27 19:25:54 +00:00
roy
039adaac92 bridge: When an interface joins then mark addresses on it as tentative
The exact flow is detatch addresses, join bridge and then mark detached
addresses as tentative.
This ensures that Duplicate Address Detection for the joining interface
are performed across all members of the bridge.
2020-09-27 19:16:28 +00:00
roy
e81d19b9cb tap: Report link state based on if the interface has been opened or not
While a nice addition, it does render tap(4) useless as a bridge(4)
endpoint. We now have vether(4) for use as bridge endpoint.
2020-09-27 13:44:47 +00:00
roy
4b44dc0b5e vether: Implement a virtual ethernet interface
The vether interface simulates a normal Ethernet interface by encapsulating
standard network frames with an Ethernet header, specifically for use as
a member in a bridge(4).

To use vether the administrator needs to configure an address onto the
interface so that packets can be routed to it. An Ethernet header will
be prepended and, if the vether interface is a member of a bridge(4),
the frame will show up there.

Taken from OpenBSD.
2020-09-27 13:31:04 +00:00
roy
1f76477386 bridge: Calculate link state as the best link state of any member
If any member is LINK_STATE_UP then it's LINK_STATE_UP.
Otherwise if any member is LINK_STATE_UNKNOWN then it's LINK_STATE_UNKNOWN.
Otherwise it's LINK_STATE_DOWN.
2020-09-27 00:32:17 +00:00
roy
8c2fc68b9f tap: Remove media from this virtual interface
It serves no purpose at all.
2020-09-26 19:38:45 +00:00
roy
c271800399 vlan: match the interface link state with that of the parent
Now addresses on a vlan will detach and undergo duplicate address
dectection on link state changes just as on a standard interface.
2020-09-26 18:38:09 +00:00
roy
13c88b88b0 net: Add a callback to ifnet to notify of link state changes 2020-09-26 18:35:12 +00:00
roy
a00afd3a07 net: Fix the setting of if_link_state
Link state changes are not dependant on the interface being up, but we also
need to guard against more link state changes being scheduled when the
interface is being detached.

We do this by clearing the link queue but keeping if_link_sheduled = true.
We can check for this in both if_link_state_change() and
if_link_state_change_work() to abort early as there is no point in doing
anything if the interface is being detached because if_down() is called
in if_detach() after the workqueue has been drained to the same overall
effect.
2020-09-26 11:57:05 +00:00
yamaguchi
8b0845fca9 Add a function to copy AC-Name and Service-Name 2020-09-25 06:22:33 +00:00
yamaguchi
0ee4d5987e Clear AC-Name and Service-Name if params are not specified 2020-09-25 06:12:33 +00:00
roy
bfeafc760c ifconfig: Report link state even if media is not supported
For AF_LINK addrs from getifaddrs(2), ifa_data is struct if_data.
This in turn holds ifi_link_state which we can use to report
link status if the interface does not support media where it's normally
reported.

Based on OpenBSD.
2020-09-22 14:14:17 +00:00
yamaguchi
66fdad6aa8 Do pppoe_timeout() in thread context
OKed by knakahara@n.o
fix port-amd64/55661
2020-09-18 09:53:50 +00:00
yamaguchi
4acbb1f5ae Use callout_setfunc and callout_schedule 2020-09-18 09:48:56 +00:00
roy
bc68f87360 nd: give missed a default of ND_LLINFO_NOSTATE
It's impossible to miss from this state, where-as 0 is ND_LLINFO_INCOMPLETE
which we can miss from.
2020-09-15 23:40:03 +00:00
roy
e53a363e2b Implement RFC 7048, making Neighbor Unreachability Detection less impatient
RFC 7048 Section 3 says in the UNREACHABLE state packets continue to be
sent to the link-layer address and then backoff exponentially.
We adjust this slightly and move to the INCOMPLETE state after
`nd_mmaxtries` probes and then start backing off.

This results in simpler code whilst providing a more robust model which
doubles the time to failure over what we did before.
We don't want to be back to the old ARP model where no unreachability
errors are returned because very few applications would look at
unreachability hints provided such as ND_LLINFO_UNREACHABLE or RTM_MISS.
2020-09-15 10:05:36 +00:00
roy
20c15691a3 nd: Name l3addr union of llentry and use in-place of nd_addr.
Probably makes more sense and makes nd.h less messy.
2020-09-14 15:09:57 +00:00
riastradh
ac7d46f29d wg: Add altq hooks.
While here, remove the IFQ_CLASSIFY bottleneck (takes the ifq lock,
so it would serialize all transmission to all peers on a single wg(4)
interface).

altq can be disabled at compile-time or at run-time; even if included
at comple-time the run-time impact should be negligible if disabled.
2020-09-14 04:57:20 +00:00
riastradh
ae8480bf6a wg: Fix detach logic.
Not tested but this should be less of a rake to step on if anyone
made an unloadable wg module.
2020-09-13 17:18:54 +00:00
riastradh
b84c17b1ee wg: Use RUN_ONCE to defer workqueue_create until after configure.
Should really fix workqueue(9) so workqueue_create can be done before
CPUs have been detected in configure, but this will serve as a stop-
gap measure.
2020-09-13 17:18:13 +00:00
riastradh
ce8a401d37 wg: Add missing kpreempt_disable/enable around pktq_enqueue. 2020-09-13 17:17:31 +00:00
roy
2fdec13bc1 nd needs arp or inet6. inet is not enough. 2020-09-13 11:48:45 +00:00
roy
caccb5729a ARP: Use ND rather than our own.
This brings the benefit of Neighbour Unreachability Detection which is
something ARP sorely lacks.

The new timings mirror those of IPv6 and are adjustable via sysctl(8).
Unlike IPv6 ND, these are global and not per interface.
2020-09-11 15:16:00 +00:00
roy
a300b3334b if_llatbl.c: adjust for nd changes 2020-09-11 15:01:26 +00:00
roy
9d417b3669 Implement address agnostic Neighbor Detection.
This is heavily based on IPv6 Neighbor Detection and allows per protocol
timers which also facilitate Neighor Unreachability Detection.
2020-09-11 14:59:22 +00:00
riastradh
3612cafecf pktqueue(9): Use percpu_create to allow early initialization.
Otherwise pktqueues can't be created before all CPUs are detected --
they will have a queue only for the primary CPU, not for others.

This will also be necessary if we want to add CPU hotplug (still need
some way to block hotplug during pktq_set_maxlen but it's a start).
2020-09-11 14:29:00 +00:00
riastradh
3a2683694c wg: Drop wgp_lock while waiting for endpoint psref to drain.
- This is safe because wgp_endpoint_changing locks out any attempts
  to change the endpoint until the draining is complete.

- This is necessary to avoid a deadlock where the handshake thread
  holds a psref and awaits mutex_enter(wgp->wgp_lock).

XXX The same deadlock may occur in wg_destroy_session.  Not clear
that it's safe to just release wgp_lock there; may need to create a
new session state, say WGS_STATE_DRAINING, while we wait for
psref_target_destroy.  But this needs a little more thought; a new
state may not be necessary, and would be nice to avoid if not
necessary.
2020-09-08 16:39:57 +00:00
riastradh
e059bdb000 wg: Use threadpool(9) and workqueue(9) for asynchronous tasks.
- Using threadpool(9) job per interface to receive incoming handshake
  messages gives the same concurrency for active interfaces but
  doesn't waste kthreads for inactive ones.

  => Can't really do this with a global workqueue(9) because there's
     no bound on the amount of time wg_receive_packets() might run
     for; we really need separate threads or threadpool jobs in order
     to avoid having one interface starve all the others.

- Using a global workqueue(9) for asynchronous peer tasks avoids
  creating unnecessary kthreads.

  => Each task does a more or less bounded amount of work, so it's OK
     to share a global workqueue -- there's no advantage to adding
     concurrency for what is almost certainly going to be CPU-bound
     asymmetric crypto.

  => This way we don't need a thread per peer or iteration over a
     list of all peers, so the task mechanism should no longer be a
     bottleneck to scaling to thousands of peers.

XXX This doesn't distribute the load across CPUs -- it keeps it on
the same CPU where the packet came in.  Should consider doing
something to balance the load -- maybe note if the current CPU is
loaded, and if so, sort CPUs by queue length or some other measure of
load and pick the least loaded one or something.
2020-09-07 01:15:25 +00:00
riastradh
95085a12ec wg: Use a global pktqueue rather than a per-peer pcq.
- Improves scalability -- won't hit limit on softints no matter how
  many peers there are.
- Improves parallelism -- softint was kernel-locked to serialize
  access to the pcq.
- Requires per-peer queue on handshake init to avoid dropping first
  packet.
  . Per-peer queue is currently a single packet -- should serve well
    enough for pings, dns queries, tcp connections, &c.
2020-09-07 01:14:42 +00:00
riastradh
476688215f wg: Fix debug output now that the priority is mixed into it. 2020-09-07 00:33:08 +00:00
riastradh
17726d9b03 wg: Fix non-DIAGNOSTIC build. 2020-09-07 00:32:20 +00:00
riastradh
fa197dbf76 wg: Avoid memory leak if socreate fails. 2020-08-31 20:34:43 +00:00
riastradh
9ccb9ca69e wg: Make it build with WG_DEBUG on 32-bit platforms. 2020-08-31 20:34:18 +00:00
riastradh
d1a81d3157 wg: Simplify locking.
Summary: Access to a stable established session is still allowed via
psref; all other access to peer and session state is now serialized
by struct wg_peer::wgp_lock, with no dancing around a per-session
lock.  This way, the handshake paths are locked, while the data
transmission paths are pserialized.

- Eliminate struct wg_session::wgs_lock.

- Eliminate wg_get_unstable_session -- access to the unstable session
  is allowed only with struct wgp_peer::wgp_lock held.

- Push INIT_PASSIVE->ESTABLISHED transition down into a thread task.

- Push rekey down into a thread task.

- Allocate session indices only on transition from UNKNOWN and free
  them only on transition back to UNKNOWN.

- Be a little more explicit about allowed state transitions, and
  reject some nonsensical ones.

- Sprinkle assertions and comments.

- Reduce atomic r/m/w swap operations that can just as well be
  store-release.
2020-08-31 20:33:58 +00:00
riastradh
566d0c30dc wg: M_NOWAIT -> M_DONTWAIT
These happen to be aliases, but M_NOWAIT is part of the legacy malloc
API whereas M_DONTWAIT is part of the mbuf API.
2020-08-31 20:31:43 +00:00
riastradh
3ea30ceaf5 wg: wg_sockaddr audit.
- Ensure all access to struct wg_peer::wgp_endpoint happens while
  holding a psref.

- Simplify internalize/externalize logic and be more careful about
  verifying it before printing anything.
2020-08-31 20:31:03 +00:00