Commit Graph

4249 Commits

Author SHA1 Message Date
msaitoh d0735544b6 s/repsonse/response/ in comment. 2021-11-22 05:33:57 +00:00
yamaguchi 6e72bac802 Added a kernel option to set SYNC bit of LACP
while the lagg interface is in STANDBY state
2021-11-16 04:48:43 +00:00
yamaguchi 2bf026269c Set SYNC bit of LACPDU when the interface is on STANDBY state 2021-11-16 04:01:11 +00:00
yamaguchi 4263242bc9 introduced APIs to configure VLAN TAG to ethernet devices 2021-11-15 07:07:05 +00:00
yamaguchi 6ee98b469b Configure vlan to an added interface after setting ifnet::if_lagg
The configuration uses ioctl of the interface, and the ioctl
for port (lagg_port_ioctl) needs ifnet:::if_lagg setting.
2021-11-12 05:56:54 +00:00
yamaguchi 22d2d7038b lagg: Add vid to vlanid_list in ethercom 2021-11-12 05:48:58 +00:00
yamaguchi afc8fc7c38 Fix the wrong check of interface type
- lp->lp_iftype: original ifnet::if_type
 - lp->lp_ifp->if_type: current ifnet::if_type
    - always IFT_IEEE8023ADLAG
2021-11-12 05:40:44 +00:00
yamaguchi bcfe44c54a lagg: Notify the changes of capenables of interface
to child interfaces
2021-11-12 05:34:45 +00:00
yamaguchi da8dae575e lagg: Use promiscuous mode instead of if_init() to avoid panic
when the interface has no if_init()
2021-11-11 01:10:09 +00:00
christos b0f3d8a093 Don't classify dropped packets that we don't understand as errors, for
example etype 0x88CA (TIPC (Transparent Inter Process Communication,)
or 0x893A (IEEE 1905).
Classify them as dropped like Linux does (FreeBSD just ignores them). From RVP.
2021-11-08 16:50:05 +00:00
yamaguchi 9f066ed011 remove unused ioctl command named SIOCGLAGGPORT
to get status of l2tp(4) added to lagg

NOTE:
SIOCGLAGGPORT is based on FreeBSD implementation.
And, currently, it is not used in NetBSD kernel/userland.
2021-11-08 06:29:16 +00:00
yamaguchi 1875049c2b lagg: renew MAC addresses to change the value of interface type
The interface type(ifnet::if_type) is changed on adding to lagg(4)
and deleting from it.
2021-11-08 06:22:16 +00:00
yamaguchi 2ac78ccc77 Update the MAC address of all child interface
when that of lagg is changed.
2021-11-08 06:17:05 +00:00
ryo f682244b8e frame's vlan tag must be ntohs()'ed.
VLAN 0 Priority tag was misrecognized on non vlan-hwtagging interfaces.
2021-10-25 17:05:43 +00:00
knakahara 4deb111acf kpreempt_disable() before sppp_get_{ip,ip6}_addrs() are unnecessary now. 2021-10-25 02:10:56 +00:00
knakahara c10769fe7c Fix missing curlwp_bind() for ifa_release(), ok'ed by yamaguchi@n.o.
This causes the following KASSERT failure in pppoe server.
    - sppp_rcr_event()
      - sppp_ipcp_confreq()
        - sppp_get_ip_addrs()
          - psref_release()

After if_spppsubr.c:1.227, sppp_ipcp_confreq() is done in workqueue
instead of softint.
2021-10-25 02:06:29 +00:00
yamaguchi e903d516ab lagg: change hash logic to generate the same value
when pairs of source and destination are the same
2021-10-22 06:20:47 +00:00
yamaguchi 3e05162506 lagg: reject a vlan interface that is not configured
The vlan I/F has no MAC address used in LACP.
2021-10-19 08:02:42 +00:00
yamaguchi a5c0a90f03 lagg: support l2tp(4) aggregation
- Accept "ifconfig lagg* laggport l2tp*"
- Set promiscuous mode when the added interface is l2tp*
- check IFF_UP in addition to IFF_RUNNING on
  SIOCSIFFLAGS to a child interface.
2021-10-19 07:52:33 +00:00
yamaguchi 396733a098 lagg: clear I/G bitg and set G/L bit in a generated MAC address 2021-10-19 07:40:52 +00:00
yamaguchi edab87ec90 Set a port interface of lagg(4) in promiscuous mode
when the lagg(4) is in promiscuous mode.
2021-10-12 08:30:58 +00:00
yamaguchi 80bf8caa92 lagg: update capabilities of ifnet and ethercom
Commonly capabilities of all child interface are configured
to a lagg interface.
2021-10-12 08:26:47 +00:00
knakahara 7128a14d48 Make pktq_rps_hash() pluggable for each interface type. Reviewed by gdt@n.o, thorpej@n.o, and riastradh@n.o, thanks. 2021-10-11 05:13:10 +00:00
andvar e6cce71780 s/acccess/access/ 2021-10-06 20:42:44 +00:00
yamaguchi cfe7bfbe04 Drop unicast packets that are not for us
when lagg(4) is not in promisc
2021-10-05 04:17:58 +00:00
yamaguchi 1a79ef4ab4 Replace the list for vlan interfaces with the counter
The list had been used in vlan_ifdetach(), but it is no longer in
use as a linked list by introducing ether_ifdetach hook.
2021-10-05 04:09:49 +00:00
mrg 0eda81aab2 avoid set-but-unused-variable warnings. 2021-10-02 22:14:32 +00:00
yamaguchi 1f3caf1ea7 lagg: Register lagg_ifdetach to ether_ifdetach hook 2021-09-30 04:29:16 +00:00
yamaguchi 74194586cd Make a link-layer address of lagg(4) configurable by ifconfig(8)
lagg(4) uses a configured link-layer (MAC) address instead
of a random MAC address generated on creating.
The configured MAC address is copied to all child interface
and used for a system id of LACP.
2021-09-30 04:23:30 +00:00
yamaguchi bbf66daf1a Fix to acquire LAGG_LOCK without psref
to remove possibility of deadlock

the deadlock maybe happened between lagg_ifdetach()
and lagg_delport()

1. lagg_ifdetach calls psref_target_acquire()
2. lagg_delport calls LAGG_LOCK()
3. lagg_ifdetach calls LAGG_LOCK()
   - wait for lagg_delport
4. lagg_delport calls psref_target_destroy()
   - wait for lagg_ifdetach
2021-09-30 04:20:14 +00:00
yamaguchi e87863469b vlan: Register vlan_ifdetach to ether_ifdetach hook 2021-09-30 04:13:42 +00:00
yamaguchi c06d6dc9b0 bridge: Register bridge_ifdetach to ether_ifdetach hook 2021-09-30 03:57:48 +00:00
yamaguchi e83dba728e Provide a hook point called when ether_ifdetach is called 2021-09-30 03:54:04 +00:00
yamaguchi b9fe3c4690 net: obsolete ifnet::if_link_state_chenged
that was used for updating link-state of vlan I/F

The obsoleted function is replaced with
ifnet::if_linkstate_hooks
2021-09-30 03:51:05 +00:00
yamaguchi 1202a27903 vlan: Register the callback to update link-state of vlan I/F
to link-state change hook

The callback is registered in every vlan I/F even if the parent
interface is the same. Therefore it is not needed to search the
vlan I/F by the parent interface unlike the previous callback.
2021-09-30 03:47:27 +00:00
yamaguchi 16737cff1d carp: Register carp_carpdev_state to link-state change hook 2021-09-30 03:43:25 +00:00
yamaguchi 4a93a140ea lagg: Register lagg_linkstate_changed to link-state change hook 2021-09-30 03:39:39 +00:00
yamaguchi b2fb0ac7fd bridge: Register bridge_calc_link_state to link-state change hook 2021-09-30 03:35:55 +00:00
yamaguchi c4267a5360 Provide a hook point called at change of link state 2021-09-30 03:23:48 +00:00
yamaguchi 5efe2d40a7 Replace ifnet::if_agriprivate with ifnet::if_lagg
agr(4) and lagg(4) can not be used on the same interface so that
if_agrprivate and if_lagg are not used at the same time.
For resolve this wasteful, if_lagg is used in not only lagg(4)
but also agr(4).

After this modification, if_lagg has 3 states:
1. if_lagg == NULL
   - Both agr(4) and lagg(4) are not running on the interface
2. if_lagg != NULL && ifp->if_type != IFT_IEEE8023ADLAG
   - agr(4) is running on the I/F
3. if_lagg != NULL && ifp->if_type == IFT_IEEE8023ADLAG
   - lagg(4) is running on the I/F
2021-09-30 03:15:25 +00:00
msaitoh 44b1f8a1c3 Use unsigned to avoid undefined behavior in pppasyncstart().
Reported-by: syzbot+7c8c7977e2756ac13f0a@syzkaller.appspotmail.com
2021-09-27 07:13:30 +00:00
thorpej 8326460e38 Use seltrue_filtops rather than rolling our own with filt_seltrue. 2021-09-26 15:58:33 +00:00
thorpej 12ae65d98c Change the kqueue filterops::f_isfd field to filterops::f_flags, and
define a flag FILTEROP_ISFD that has the meaning of the prior f_isfd.
Field and flag name aligned with OpenBSD.

This does not constitute a functional or ABI change, as the field location
and size, and the value placed in that field, are the same as the previous
code, but we're bumping __NetBSD_Version__ so 3rd-party module source code
can adapt, as needed.

NetBSD 9.99.89
2021-09-26 01:16:07 +00:00
knakahara 8364d2d21b Add copyright for no-memcpy toeplitz hash, pointed out by wiz@n.o, thanks. 2021-09-24 08:40:35 +00:00
knakahara c056381787 Fix build failure for i386 INSTALL_XEN3PAE_DOMU, sorry. 2021-09-24 05:26:06 +00:00
knakahara 67bc29b45b Add RSS toeplitz hash functions which calculate from mbuf. 2021-09-24 04:11:02 +00:00
knakahara 3d4863dc67 Import asymmetric toeplitz hash without memcpy implemented by ryo@n.o.
This implementation has better performance than memcpy'ed one.
(30%-60% improvement in micro benchmark)

import from
    https://github.com/ryo/l2pkt/blob/master/l2pkt/toeplitz_hash.c
2021-09-24 04:09:32 +00:00
christos 35c89f2941 don't opencode kauth_cred_get() 2021-09-21 14:59:14 +00:00
christos 11ad70e9fd remove extra changes 2021-09-21 14:57:26 +00:00
christos 813a709df2 don't opencode kauth_cred_get() 2021-09-21 14:54:26 +00:00
andvar b58602814f fix typos in word "successful". 2021-09-16 22:19:10 +00:00
andvar b780d9b67b fix various typos, mainly in comments. 2021-09-16 20:17:46 +00:00
andvar f9faf20aef fix typos in comments, mainly s/extention/extension/ and s/sufficent/sufficient/ 2021-09-03 21:54:58 +00:00
christos 01cb1ae623 Some signnes, casts, and constant sizes.
Add module dependencies.
2021-08-17 17:31:13 +00:00
andvar 6584ea569e fix various typos in compatibility, mainly in comments. 2021-08-09 20:49:08 +00:00
andvar d7fca1ab3d fix typos in asymmetry, asymmetric(al), symmetrical. 2021-08-09 19:57:57 +00:00
andvar 077d1c0f36 fix various typos in comments and log messages. 2021-08-02 12:56:22 +00:00
hannken e28106a5fc Mark vlan_safe_ifpromisc_locked() as "__unused" to appease LLVM.
Maybe completely remove this short helper?
2021-07-17 15:37:04 +00:00
yamaguchi dd89d377aa vlan: drop tagged outgoing packets
vlan(4) doesn't support Q-in-Q yet.
2021-07-15 04:05:47 +00:00
yamaguchi 844437ebb1 unset IFF_PROMISC at bpf_detach()
Doing "d->bd_promisc = 0" is that bpf_detach() does not call
ifpromisc(ifp, 0). Currently, there is no reason for
this behavior so that it is removed.
In addition to the change, the workaround for it in vlan(4)
is also removed.
2021-07-14 06:50:22 +00:00
yamaguchi 727ab4daef Make an mbuf writable before un-tagging 2021-07-14 06:23:06 +00:00
ozaki-r 94c10bc8ee lagg: fix typo for ALTQ 2021-07-13 09:00:26 +00:00
yamaguchi 77572c2dd5 Drop unicast packets that are not for us
when vlan(4) is not in promisc
2021-07-06 02:39:46 +00:00
yamaguchi 9403a263ef vlan: added NULL check for the parent interface
The pointer may set to NULL by vlan_unconfig
while packet processing
2021-07-06 02:34:12 +00:00
yamaguchi a358086bc4 vlan: set the link state to DOWN when its parent detaches 2021-07-06 01:16:01 +00:00
yamaguchi 5ef42deb19 Use if_ioctl() for changing MTU, not ether_ioctl to prevent panic
Fix PR kern/56292
2021-07-02 03:30:46 +00:00
blymn eda2fe3d50 Back out fix for kern_pmf.c calling a null if_stop and apply a fix
suggested by Jared McNeill which sets if_stop to a stub function
which means that more than just the pmf is protected from the NULL call.
2021-07-01 22:08:13 +00:00
yamaguchi 10f9801f9d lagg: fix an uninitialize variable
pointed out by tnn@n.o., thanks.
2021-06-30 06:39:47 +00:00
riastradh 731d783606 Make if_stats_init, if_attach, if_initialize return void.
percpu_alloc can't fail.


Author: Maya Rashish <maya@NetBSD.org>
Committer: Taylor R Campbell <riastradh@NetBSD.org>
2021-06-29 21:19:58 +00:00
riastradh 076e35792d if_attach and if_initialize cannot fail, don't test return value
These were originally made failable back in 2017 when if_initialize
allocated a softint in every interface for link state changes, so
that it could fail gracefully instead of panicking:

https://mail-index.NetBSD.org/source-changes/2017/10/23/msg089053.html

However, this spawned many seldom- or never-tested error branches,
which are risky to have around.  And that softint in every interface
has since been replaced by a single global workqueue, because link
state changes require thread context but not low latency or high
throughput:

https://mail-index.NetBSD.org/source-changes/2020/02/06/msg113759.html

So there is no longer any reason for if_initialize to fail.  (The
subroutine if_stats_init can't fail because percpu_alloc can't fail
either.)

There is a snag: the softint_establish in if_percpuq_create could
fail, potentially leading to bad consequences later on trying to use
the softint.  This change doesn't introduce any new bugs because of
the snag -- if_percpuq_attach was already broken.  However, the snag
can be better addressed without spawning error branches, either by
using a single softint or making softints less scarce.

(Separate commit will change the signatures of if_attach and
if_initialize to return void, scheduled to ride whatever is the next
convenient kernel bump.)

Patch and testing on amd64 and evbmips64-eb by maya@; commit message
soliloquy, and compile-testing on evbppc/i386/earmv7hf, by me.
2021-06-16 00:21:17 +00:00
martin 774f252e41 Add a bpf_register_track_event() function (and deregister equivalent)
that allows a driver to track listeners attaching/detaching from tap
points.

This is usefull for drivers that would have to do extra work for some
taps and can not easily decide (at the driver level) if the work would
be needed further up the stack.

An example is providing radiotap headers for IEEE 802.11 frames.
2021-06-09 15:44:15 +00:00
martin e16f203ce5 Add a (FreeBSD compatible) bpf_peers_present() predicate to allow
testing for active listeners on a tap.
2021-06-09 15:38:39 +00:00
yamaguchi fd5c5f4c7c Added missing definition of sppp_ipv6cp_tld
Fixed build without INET6
2021-06-02 00:47:59 +00:00
yamaguchi 050417271f Fix the wrong timeout event handler for PAP
sppp_auth_to_event() is a implementation of TO+/TO- event for
authentication protocol and it drops TO+ event in Ack-rcvd state.
2021-06-01 05:22:57 +00:00
yamaguchi a0c48bcbbc Send Up event in tlu action of LCP
When LCP is stopping, the layer send Down event and Close event
(Down -> Close). To align the sequence, Up event is moved
before Open event.
2021-06-01 05:16:46 +00:00
yamaguchi a53bc2f880 Added logs when IPCP and IPv6CP are up or down 2021-06-01 05:11:22 +00:00
yamaguchi c68f0c23b6 Added SPPP_LOG() for refactoring around log 2021-06-01 05:08:46 +00:00
yamaguchi c8891e4be9 Send RTM_IFINFO when a network configuration protocol
is up or down
2021-06-01 05:04:06 +00:00
yamaguchi 6a44efb540 Drop the Open event of LCP to stop the interface
even a reconnection is scheduled

The queue for events in if_spppsubr.c is not possible
to enqueue the same event. So, The close event caused
while a close event and open event are enqueued for
reconnection is not possible to stop interface.
To solve this issue, The open event after
"ifconfig pppoe? down" is dropped.
2021-06-01 04:59:50 +00:00
yamaguchi 63a0a2cb16 remove PP_CISCO that was used in obsoleted drivers e.g. lmc(4) 2021-06-01 04:55:55 +00:00
yamaguchi 143fc24656 Remove open event on tlf of PAP/CHAP when retry of them is over
to prevent that LCP stops at Starting state.

And also remove retry counter check on tls of LCP because of
unnecessary.
2021-06-01 04:45:22 +00:00
yamaguchi 876c307570 Do not if_down() when a down event of the lower layer of LCP is happened
since the layer try to reconnect.
2021-06-01 04:19:57 +00:00
yamaguchi 4910df2e45 Fix not to do if_down() before reconnect
Almost network interface do not use if_down() even when there is no
connectivity. So, pppoe(4) is also made be not used it.
This behavior can be rollbacked by SPPP_IFDOWN_RECONNECT option.
2021-06-01 03:51:33 +00:00
yamaguchi 0c5b42cf15 restart LCP when loopback packets are detected
In if_spppsubr.c down and up do not mean that LCP is stopping
or running, but mean that the lower layer of LCP is up or down.
And, restarting of LCP is had to use close event and open event.
2021-06-01 03:27:23 +00:00
christos e99a3658f8 Simplify; no need to special case the small buffer zero src_len.
lla_snprintf1 never returns -1.
2021-05-27 13:40:38 +00:00
christos b61183c7bc Don't use the stack, print to the buffer directly (this was one of the
biggest stack users).
2021-05-27 13:36:33 +00:00
thorpej f96fdbe0df Remove leading blank line. 2021-05-24 13:43:21 +00:00
thorpej 026b9470e2 Move __KERNEL_RCSID() to the traditional location. 2021-05-24 13:42:58 +00:00
yamaguchi 30d8f4da8e Added missing copyright and license notice
pointed out by thorpej@n.o., Thanks.
2021-05-24 06:24:20 +00:00
yamaguchi 15e65644fa Added missing copyright and license notice
pointed out by thorpej@n.o., Thanks.
2021-05-24 06:08:28 +00:00
rillig 3112350466 if_lagg: fix format string incompatibility
In struct ifnet, the member if_mtu has type uint64_t, which differs from
struct ifreq, where the member ifru_mtu has type int.
2021-05-19 10:20:50 +00:00
rillig 06dbbe5487 if_lagg: fix Clang build
Clang is stricter than GCC when it comes to nonliteral format strings.

sys/net/lagg/if_lagg.c:2372:12: error:
    format string is not a string literal [-Werror,-Wformat-nonliteral]
2021-05-19 06:13:08 +00:00
yamaguchi 353f49b857 Added a kernel option to change the number of processing packets
at one pppoeintr()
2021-05-19 03:44:46 +00:00
yamaguchi a98c13e644 Added a limitation of the number of processing packets
because a enqueuing process can not add packets over IFQ_MAXLEN

and removed reschedule at pppoeintr()
because it also scheduled at enqueuing process.
2021-05-19 03:35:27 +00:00
yamaguchi 8539c94ed7 Make functions that use for logging MP-safe
There is no change in behavior.
2021-05-19 02:14:19 +00:00
yamaguchi 8bd40ada6c Added clear of dns addresses when IPCP is closed 2021-05-19 02:07:20 +00:00
yamaguchi 1c8972237f Added logs on dropping IPCP and IPv6CP packets 2021-05-19 02:02:46 +00:00
yamaguchi 99e663ae82 remove a wrong ntohs().
The variable is already host-byte-order.
2021-05-19 01:54:09 +00:00
yamaguchi 070cb7ea5c Added a log about rejection of IPCP address option 2021-05-19 01:42:35 +00:00
hannken 43ac48be8c Make this compile without DIAGNOSTIC. 2021-05-18 11:02:58 +00:00
yamaguchi a47fe33408 Added missing PPPOE_UNLOCK() on dropping PADS and PADT 2021-05-18 01:46:29 +00:00
yamaguchi f0101d0e08 Add a new link-aggregation pseudo interface named lagg(4)
- FreeBSD's lagg(4) based implementation
 - MP-safe and MP-scalable
2021-05-17 04:07:41 +00:00
yamaguchi 409d08390a Add a parameter to change keepalive interval in each PPPoE I/F 2021-05-14 08:41:25 +00:00
yamaguchi 542218674b Added SPPP_NORECV_TIME option to change pp_max_noreceive 2021-05-14 08:31:14 +00:00
yamaguchi aec75754e3 Send echo request even while user data is received
if pp_max_noreceive is 0
2021-05-14 08:11:08 +00:00
yamaguchi 5b036654ab Introduce SPPP_KEEPALIVE_INTERVAL option
to change the interval between LCP echo requests
2021-05-14 08:06:32 +00:00
yamaguchi 7fa77e9ff4 Drop PADS and PADT from unknown host for safety 2021-05-13 03:48:55 +00:00
yamaguchi 90be7a8a21 Change reconnect delay after PADT received (15 sec -> 5 sec)
5 sec is the same as minimum PADI resending interval
2021-05-13 03:28:36 +00:00
yamaguchi 5ea21c7cb4 Accept a frame like a PADT just containing PPPoE header 2021-05-13 01:01:10 +00:00
yamaguchi 77103423a2 clear authentication protocol when SPPP_AUTHPROTO_NONE is specified 2021-05-11 06:42:42 +00:00
yamaguchi 99fdb9d66a Drop packets that have no NCP not to start auto-dial 2021-05-11 06:33:17 +00:00
yamaguchi 0d7b654a12 Added missing if_oerror incrementing 2021-05-11 06:27:18 +00:00
yamaguchi 9500534129 Move RCA event after RCR event
A authentication failed by TO+ event between RCA and RCR events
 1. RCA event in REQ-SENT state
   - REQ-SENT => ACK-RCVD
 2. TO+ event
   - ACK-RCVD => REQ-SENT
 3. RCR+ event
   - REQ-SENT => ACK-SENT

By moving RCA after RCR, the state is transisted to OPENED
 1. RCR event
   - REQ-SENT => ACK-SENT
 2. TO+ event
   - state is not changed
 3. RCA event
   - ACK-SENT => OPENED
2021-05-11 06:21:28 +00:00
yamaguchi bdaf362302 Added ioctl commands for configuring NCP of pppoe(4) 2021-05-11 01:27:45 +00:00
yamaguchi daaf816306 back to r1.34 because of mistake of commit log 2021-05-11 01:23:21 +00:00
yamaguchi 8a818d09dc Revert previous commit because of mistake of commit log
back to r1.230(if_spppsubr.c) and r1.31(if_sppp.h)
2021-05-11 01:15:11 +00:00
yamaguchi 6921f43579 Added keywords that are ipcp, noipcp, ipv6cp, noipv6cp
for configuring NCP
2021-05-11 01:00:49 +00:00
yamaguchi 5d69fa28dc do not clear destination address if there is no saved address
and add initialization of saved_hisaddr for safety

0.0.0.0 was sometimes configured to destination address when
ipcp close was occurred before ipcp tlu.
Following messages will be appeared when the issue is encountered and
debug for pppoe(4) is enabled.

tc-so:[     1.890005] pppoe0: ipcp close(starting)
(snip)
tc-so:[     1.890005] pppoe0: ipcp_open(): no IP interface
2021-05-06 06:18:16 +00:00
yamaguchi a0c635c379 Added m_freem for safety
pointed out by knakahara@, thanks.
2021-05-06 02:05:09 +00:00
riastradh 0a8f39d604 Sprinkle __noinline to reduce gigantic stack frames in ALL kernels.
In principle this might just push a real problem around, but this is
unlikely to be a real problem because:

1. The large stack frames are really only in the setup state machine
   message handlers, which run at the top loop of a thread with a
   shallow stack anyway.

2. If these are inlined, gcc might create multiple nonoverlapping
   stack buffers, whereas if not inlined, the stack frames from
   consecutive or alternative procedure calls would overlap anyway.

(I haven't investigated exactly what's going on leading to ~5 KB-byte
stack frames, but this shuts gcc up, at least, and the hypotheses
sound plausible to me!)
2021-04-29 17:55:51 +00:00
yamaguchi 989b1d029b Introduce a pointer to refer sp->scp[cp->protoidx]
There is no functional difference.
2021-04-28 09:39:39 +00:00
yamaguchi a87544e73a Move paese of conf-req, conf-nak and conf-rej into workqueue
from softint context

When the pases were processed in softint, the state machine
in if_spppsubr.c had been broken by simultaneous events
on rare occasions.

Example:
 1. Do ifconfig pppoe* up
    - lcp open event is enqueued to workqueue
 2. Receive conf-ack, and parse the packet
    - save mru to sp->lcp.their_mru
    - lcp RCR+ event is enqueued to workqueue
 3. Process lcp open event
    - initialize data including sp->lcp.their_mru
 4. Process lcp RCR+ event
    - Use sp->lcp.their_mru
        - but it was initialized
2021-04-28 09:36:24 +00:00
yamaguchi 90e5cc3774 Fix the wrong CHAP option length in conf-nak
RFC 1994 defines that the CHAP option length in conf-nak is 5.
However, 4 was used when CHAP is cofigured and PPP is proposed
by a peer.
2021-04-26 08:45:57 +00:00
yamaguchi c58fde1d88 Avoid updating of the state if the state is not changed
not to reset the timer for state machine
2021-04-26 08:42:19 +00:00
yamaguchi a672d72767 Reset LCP fail counter when doing "ifconfig pppoe* up" 2021-04-26 08:37:54 +00:00
yamaguchi 648856a579 Added ipcp option name for logging 2021-04-26 08:34:22 +00:00
yamaguchi e1bdd0a24f Ignore 0.0.0.0 offered from PPPoE server 2021-04-26 08:31:21 +00:00
yamaguchi 121b27d0d0 Fix locking order since IFNET_LOCK must be held
before acquiring SPPP_LOCK
2021-04-26 02:36:45 +00:00
yamaguchi f0773bb1c5 Adjust mtu at LCP instead at IPCP
The adjustment must be done at LCP when a PPPoE connection
does not use IPCP.
2021-04-23 03:36:13 +00:00
yamaguchi e9679de3fb Fix to set mtu even if it is bigger than mru notified at LCP 2021-04-23 03:31:33 +00:00
yamaguchi ba783f9d03 Introduct a new flag to accept different authentication protocol
in myauthproto and hisauthproto

When the flag is enabled, a authentication protocol notified
at LCP negotiation is used as my authentication protocol.
When the flags is NOT enabled, my authentication protoco is
not changed at LCP negotiation.
2021-04-23 01:13:25 +00:00
yamaguchi a9a3fd4504 Added missing free of sc_hunique to prevent memory leak
when using PPPoE server
2021-04-22 10:26:24 +00:00
yamaguchi db6b169977 Added missing locking order between sppp and IFNET_LOCK 2021-04-16 02:26:25 +00:00
yamaguchi 3955989b41 Stop and destroy timeout after sppp_detach and if_detach
for safety

The functions may use resources of pppoe(4) while detaching,
so the release should move after it.
2021-04-16 02:23:25 +00:00
yamaguchi 67c987e115 Remove unnecessaly lock holdings to avoid dead lock
The locks were held while callout_halt() and workqueue_wait()
without reason.
And the locks also were held at callout and workqueue handler
so that the handler kicked by those function couldn't acquire
the lock.

The reasons why those are unneccesary are:
 - Items of callout_t are protected by callout_lock
 - Items of struct workqueue and struct work are protected
   by q_mutex in struct workqueue
 - Items of struct sppp_work protected by atomic_cas(3)
 - struct pppoe_softc does not free before workqueue_wait() and
   callout_halt() even if the locks are not held
2021-04-16 02:12:00 +00:00
yamaguchi d0255047d4 Fix not to put the wrong error message 2021-04-16 02:05:37 +00:00
yamaguchi 382b1e495e Stop ppp layer at first of destroying pppoe interface 2021-04-16 01:59:50 +00:00
yamaguchi ab945900b9 Sort initialization sequence in pppoe_clone_create() out
for refactoring

It has no functionality impact
2021-04-16 01:44:35 +00:00
yamaguchi 4e6f0c603c Use kmem_zalloc to allocate pppoe_softc 2021-04-16 01:32:04 +00:00
yamaguchi 324c3dd663 Move initialization of sc_lock in pppoe_softc to first
The lock may be held in callbacks for ppp layer or other
components so that it should be initialized early.
2021-04-16 01:28:51 +00:00
yamaguchi 87f753dafa commonize error handling in pppoe_clone_create() 2021-04-16 01:24:35 +00:00
yamaguchi c37c0ccd03 Reschedule softint to process packets enqueued to ppoediscinq
while doing pppoe_data_input

And added a empty check for ppoeinq, for safety
2021-04-13 05:04:54 +00:00
yamaguchi 17130f8c6e Added missing counter clear when a pppoe state changes to PADI_SENT 2021-04-13 05:00:06 +00:00
yamaguchi da3e5318c2 Added a NULL check for parent interface of pppoe 2021-04-13 04:57:15 +00:00
yamaguchi d0bd5f49aa Hold the lock for pppoe while referencing sc_id
that is an item of struct pppoe_softc
2021-04-13 04:53:22 +00:00
yamaguchi 3a0c206ee2 s/nitems/__arraycount/ 2021-04-05 06:56:47 +00:00
yamaguchi 909afa38a0 Include opt_inet.h for INET6 2021-04-05 06:53:45 +00:00
skrll f9f9515b55 Remove strange padding #define and replace with anonymous struct/union 2021-03-25 08:18:03 +00:00
christos f19451d962 Add a list of names 2021-03-22 18:40:18 +00:00
knakahara dbbec7e7e3 Fix l2tp(4) ioctl type. Pointed out by yamaguchi@n.o, thanks.
XXX pullup-[89]
2021-03-16 07:00:38 +00:00
christos fd63f5967c reinstate a simple version of ip_randomid() 2021-03-08 20:01:54 +00:00
christos 2143da8717 - Make ALIGNED_POINTER use __alignof(t) instead of sizeof(t). This is more
correct because it works with non-primitive types and provides the ABI
  alignment for the type the compiler will use.
- Remove all the *_HDR_ALIGNMENT macros and asserts
- Replace POINTER_ALIGNED_P with ACCESSIBLE_POINTER which is identical to
  ALIGNED_POINTER, but returns that the pointer is always aligned if the
  CPU supports unaligned accesses.
[ as proposed in tech-kern ]
2021-02-19 14:51:59 +00:00
christos fc0eb449a4 - pass the alignment instead of the mask (as Roy asked and to match the
other macro)
- use alignof to determine that alignment and CTASSERT what we expect
- remove unused macros
2021-02-17 22:32:04 +00:00
martin 6352f759f0 ARP headers only need 2 byte alignment - pointed out by roy. 2021-02-16 10:20:56 +00:00
christos 9183889817 - centralize header align and pullup into a single inline function
- use a single macro to align pointers and expose the alignment, instead
  of hard-coding 3 in 1/2 the macros.
- fix an issue in the ipv6 lt2p where it was aligning for ipv4 and pulling
  for ipv6.
2021-02-14 20:58:34 +00:00
roy 2a093b6406 if_arp: Just KASSERT that arphrd is aligned
While here improve readability of checking ARP IEEE1394 matches interface.
2021-02-14 19:47:16 +00:00
roy 951b7674b2 if_ether: revert prior alignment checks
Apparently not needed as our drivers ensure this.
2021-02-14 19:35:37 +00:00
roy 880dbbbc52 if_gre: Remove alignment checks in favour copying to stack
Makes the code a lot simpler, idea from dyoung@
2021-02-14 19:33:29 +00:00
roy cb6917aa0d Prior alignment fixes should not use an offset 2021-02-13 13:00:16 +00:00
roy dd39d07da7 if_arp: Ensure that arphdr is aligned 2021-02-13 07:57:09 +00:00
roy 1aaed635b1 if_ether: Ensure that ether_header is aligned 2021-02-13 07:28:04 +00:00
roy c77555a631 if_gre: Ensure that gre_h is aligned 2021-02-12 19:57:49 +00:00
roy f217990197 CTASSERT -> __CTASSERT to unbreak userland build.
While here move __packed in tcp_debug.h back to where it was and
note removal warrants more investigation.
2021-02-03 18:13:13 +00:00
roy 488f4a52aa if_llc.h: Replace __packed with CTASSERT 2021-02-03 12:11:34 +00:00
roy 7a849d032c Sprinkle CTASSERT to enforce on-wire layout without __packed 2021-02-03 11:53:43 +00:00
roy 45a53bf39b Whitespace 2021-02-03 10:31:10 +00:00
roy 1ca39e8727 Remove __packed from various network structures
They are already network aligned and adding the __packed attribute
just causes needless compiler warnings about accssing members of packed
objects.
2021-02-03 05:51:40 +00:00
jmcneill 5701779e64 Add symmetric toeplitz implementation with integration for NICs, from OpenBSD. 2021-01-30 21:23:08 +00:00
christos 8859b768f4 Don't silently ignore the errors from npfctl_run_op. We end up returning
packets to userland that are missing required fields (like in rule_add the
id of the rule) and npfctl aborts.
2021-01-27 17:39:13 +00:00
christos 9235241dcd s/npf_config_lock/npf->config_lock/ in the comments 2021-01-25 17:18:55 +00:00
christos c518bb5a58 Fix locking issue: npf_default_pass needs to be called with the config lock
held.
2021-01-25 17:17:19 +00:00
thorpej 1abee2b4f1 Use sel{record,remove}_knote(). 2020-12-18 01:31:49 +00:00
wiz 0fff63c9f6 comparision -> comparison 2020-12-02 14:20:19 +00:00
yamaguchi 4cd9defac1 Fix missing disable of kpreempt while getting interface address 2020-11-27 03:37:11 +00:00
yamaguchi 9ce4bce850 add KASSERT(!cpu_softintr_p());
pointed out by knakahara@n.o., thanks.
2020-11-25 10:44:53 +00:00
yamaguchi d6dd2b3582 Fix to reconnect after PADT received 2020-11-25 10:42:35 +00:00
yamaguchi 73f90acc3a add a logging function used at debugging pppoe(4) 2020-11-25 10:39:47 +00:00
yamaguchi f1cad8460f fix to remove trailing garbage 2020-11-25 10:38:10 +00:00
yamaguchi 2ac76fa708 stop callout even when the state is in PPPOE_STATE_INITIAL 2020-11-25 10:37:04 +00:00
yamaguchi d1cb5a89a6 Add commands to refer params of control protocols in if_spppsubr.c
reviewed by knakahara@n.o.
2020-11-25 10:30:51 +00:00
yamaguchi 493dff876c Reconnect when a down event caused by tlf caught 2020-11-25 10:27:18 +00:00
yamaguchi c65ff233be Move code related to module to bottom 2020-11-25 10:25:22 +00:00
yamaguchi 19fb509881 Reconnect lcp after authentication or network phase finish 2020-11-25 10:23:33 +00:00
yamaguchi 6562f17042 Close lcp when the lower layer down if the interface is passive or on-demand
reivewed by knakahara@n.o.
2020-11-25 10:18:49 +00:00
yamaguchi 58e2b843e5 Update ip addresses in the workqueue for control protocols
reviewed by knakahara@n.o.
2020-11-25 10:12:03 +00:00
yamaguchi 73ef60f704 Add the id check for TERM_ACK 2020-11-25 10:08:22 +00:00
yamaguchi 21f4535045 remove double newlines 2020-11-25 10:05:40 +00:00
yamaguchi 1fed31b4a1 change function name(RCR => parse_confreq)
reviewed by knakahara@n.o.
2020-11-25 10:03:38 +00:00
yamaguchi fb29eba267 Add a function to initialize parameters 2020-11-25 09:59:52 +00:00
yamaguchi 6d7a1a8cde Remove unused and unimplemented code related to CP_QUAL 2020-11-25 09:57:26 +00:00
yamaguchi 0d03c540b3 Simplify commonly used functions
reviewed by knakahara@n.o.
2020-11-25 09:55:01 +00:00
yamaguchi 2653a9caa8 implement auth protocols on the state-machine of control protocols
reviewed by knakahara@n.o.
2020-11-25 09:46:05 +00:00
yamaguchi 2c596a18e6 Insert an entry after initialization 2020-11-25 09:41:20 +00:00
yamaguchi 8c200c3fe2 call if_down() in workqueue instead of callout(9) 2020-11-25 09:38:39 +00:00
yamaguchi 7a8d2f5e5a Change a state of control protocol in thread context
reviewed by knakahara@n.o.
2020-11-25 09:35:23 +00:00
yamaguchi 78b0a7aa5b Add a function for RXJ event 2020-11-25 09:30:49 +00:00
yamaguchi babc78f240 Add a function for RTR and RTA event 2020-11-25 09:26:34 +00:00
yamaguchi f0bcf1b653 Add a function for RCA and RCN event 2020-11-25 09:21:53 +00:00
yamaguchi 7f4cc01664 Add a function for RCR event 2020-11-25 09:18:45 +00:00
yamaguchi 3337657cf4 Refactoring functions for RCR and RCN 2020-11-25 09:16:20 +00:00
yamaguchi 2f9fad35a8 Add a structure for params related to control protocols 2020-11-25 09:12:50 +00:00
yamaguchi bfa55b37c2 remove variable names in function declaration 2020-11-25 09:09:24 +00:00
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