Commit Graph

1864 Commits

Author SHA1 Message Date
christos b9baaeeb55 PR/52382: BERTRAND Joel: Fix mapped IPv4 source selection; this got broken
in the last code refactoring. in6_selectif failing is not fatal.
XXX: pullup-8
2017-08-27 12:34:21 +00:00
christos a2c4fad4b4 PR/52472: Edgar Fuss: Document handling of scoped IPv6 addresses by embedding
ASCII art from:
	IPv6 Core Protocols Implementation
	By Qing Li, Tatuya Jinmei, Keiichi Shima
	Page 56, Figure 2.12
2017-08-09 17:20:44 +00:00
ozaki-r ae6fc59569 Add missing IPsec policy checks to icmp6_rip6_input
icmp6_rip6_input is quite similar to rip6_input and the same checks exist
in rip6_input.
2017-08-02 02:18:17 +00:00
ozaki-r 0c084e85e9 Make IPsec SPD MP-safe
We use localcount(9), not psref(9), to make the sptree and secpolicy (SP)
entries MP-safe because SPs need to be referenced over opencrypto
processing that executes a callback in a different context.

SPs on sockets aren't managed by the sptree and can be destroyed in softint.
localcount_drain cannot be used in softint so we delay the destruction of
such SPs to a thread context. To do so, a list to manage such SPs is added
(key_socksplist) and key_timehandler_spd deletes dead SPs in the list.

For more details please read the locking notes in key.c.

Proposed on tech-kern@ and tech-net@
2017-08-02 01:28:02 +00:00
ozaki-r e1c9808fed Don't acquire global locks for IPsec if NET_MPSAFE
Note that the change is just to make testing easy and IPsec isn't MP-safe yet.
2017-07-27 06:59:28 +00:00
knakahara a431af6bf4 l2tp(4): fix mbuf leak when tunnel nested over the limit
XXX need pullup -8 branch
2017-07-11 05:03:45 +00:00
knakahara 25917aa5e0 fix PR kern/52353. implemented by ozaki-r@n.o. I just commit by proxy.
XXX need to pullup to -8.
2017-07-07 00:55:15 +00:00
christos 1922edaa5b remove unnecessary casts; use sizeof(var) instead of sizeof(type). 2017-07-06 17:14:35 +00:00
christos 2b50acc97b Merge the two copies SO_TIMESTAMP/SO_OTIMESTAMP processing to a single
function, and add a SOOPT_TIMESTAMP define reducing compat pollution from
5 places to 1.
2017-07-06 17:08:57 +00:00
ozaki-r 50558ab0df Fix usage of ip6_get_membership
It may set nothing to ifp even if returning 0. So we need to NULL-clear
ifp before calling it.

Fix PR kern/52324
2017-06-26 08:01:53 +00:00
ozaki-r d59e7b9e71 Purge ARP/NDP entries on an interface when the interface is down
Fix PR kern/51179
2017-06-22 09:53:24 +00:00
ozaki-r a4910d9c60 Allow in6_lltable_free_entry to be called without holding the afdata lock of ifp as well as in_lltable_free_entry
This behavior is a bit odd and should be fixed in the future...
2017-06-22 09:29:23 +00:00
ozaki-r e765209802 Remove unused function (nd6_rem_ifa_lle) 2017-06-22 09:24:02 +00:00
ozaki-r dc9233b94b Don't create a permanent L2 cache entry on adding an address to an interface
It was created to copy FreeBSD, however actually the cache isn't
necessary. Remove it to simplify the code and reduce the cost to
maintain it (e.g., keep a consistency with a corresponding local
route).
2017-06-21 09:05:31 +00:00
ozaki-r 5ecc1e1d8c Sending a routing message (RTM_ADD) on adding an llentry
A message used to be sent on adding a cloned route. Restore the
behavior for backward compatibility.

Requested by ryo@
2017-06-16 02:24:54 +00:00
chs fd34ea77eb remove checks for failure after memory allocation calls that cannot fail:
kmem_alloc() with KM_SLEEP
  kmem_zalloc() with KM_SLEEP
  percpu_alloc()
  pserialize_create()
  psref_class_create()

all of these paths include an assertion that the allocation has not failed,
so callers should not assert that again.
2017-06-01 02:45:05 +00:00
kardel acf7aadada avoid a double ifa_release() and thus a panic when e. g. running ifmcstat 2017-05-13 20:13:26 +00:00
ozaki-r 808b116a48 Add missing KEY_FREESP to ip6_forward 2017-05-09 04:24:10 +00:00
ozaki-r c33d80e3e4 Don't output debugging logs just if DIAGNOSTIC
Also make log messages informative.
2017-04-28 05:56:33 +00:00
ozaki-r 5cfcce1f60 Check if solock of PCB is held when SP caches in the PCB are accessed
To this end, a back pointer from inpcbpolicy to inpcb_hdr is added.
2017-04-25 05:44:11 +00:00
ozaki-r c5b713b4e3 Fix build of kernel with SCTP 2017-04-20 09:19:19 +00:00
ozaki-r ed8b1986a9 Remove unnecessary NULL checks for inp_socket and in6p_socket
They cannot be NULL except for programming errors.
2017-04-20 08:46:07 +00:00
ozaki-r c4cc9034cb Simplify logic of udp4_sendup and udp6_sendup
They are always passed a socket with the same protocol faimiliy
as its own: AF_INET for udp4_sendup and AF_INET6 for udp6_sendup.
2017-04-20 08:45:09 +00:00
ozaki-r 469c0f099a Rumpify netipsec
Note that we should modularize netipsec and reduce reverse symbol references
(referencing symbols of netipsec from net, netinet and netinet6) though,
the task needs lots of code changes. Prior to doing so, rumpifying it and
having ATF tests should be useful.
2017-04-14 02:43:27 +00:00
knakahara 685eeb51f1 fix module build 2017-04-04 23:49:17 +00:00
sevan cb2085f041 Revert change to allow builds to continue until the missing vlan.h file is committed.
https://mail-index.netbsd.org/source-changes/2017/04/04/msg083283.html
2017-04-04 16:49:15 +00:00
knakahara 6f4f1b05e1 remove unnecessary if_vlanvar.h. add missing include "vlan.h".
pointed out by s-yamaguchi@IIJ, thanks.
2017-04-04 10:25:38 +00:00
knakahara d35df4a96d remove duplicated validation. That is already done in l2tp_lookup_session_ref().
pointed out by s-yamaguchi@IIJ, thanks.
2017-03-30 23:13:54 +00:00
ozaki-r 07a4b673ca Replace DIAGNOSTIC + panic with KASSERT 2017-03-14 04:25:10 +00:00
ozaki-r 4ea7185a98 Replace DIAGNOSTIC + panic with CTASSERT 2017-03-14 04:24:04 +00:00
ozaki-r 752d3b8752 Remove unnecessary NULL check 2017-03-14 04:21:38 +00:00
ozaki-r 2495e7a0c7 Pass inpcb/in6pcb instead of socket to ip_output/ip6_output
- Passing a socket to Layer 3 is layer violation and even unnecessary
- The change makes codes of callers and IPsec a bit simple
2017-03-03 07:13:06 +00:00
msaitoh f71865e18b Add missing opt_net_mpsafe.h. 2017-03-03 06:27:20 +00:00
ozaki-r f27f4e283c Plug a race condition on accessing i6mm_maddr 2017-03-02 09:48:20 +00:00
ozaki-r 362a23cbc0 Fix racy in6m_sol
Relook up the entry instead of reusing it, which makes locking simple.
2017-03-02 09:16:46 +00:00
ozaki-r 549f799fbf Protect ia6_memberships by in6_ifaddr_lock 2017-03-02 05:27:39 +00:00
ozaki-r 3e6e186e8a Make sure im6o_memberships is protected by in6p's lock (solock) 2017-03-02 05:26:24 +00:00
ozaki-r 36ae5d22b0 Make usages of ifp MP-safe in some functions of IP multicast 2017-03-02 05:24:23 +00:00
ozaki-r 0b2f4040ea Use LIST_* macros
No functional change.
2017-03-02 01:05:02 +00:00
ozaki-r 73c95a6a4c Make IPv6 multicast MP-safe partially
To complete the task, we need to make users of IPv6 multicast MP-safe, for
example socket/PCB and CARP.
2017-03-01 09:09:37 +00:00
ozaki-r ef30413ffd Provide in6_multi_group
Use it when checking if we belong to the group, instead of in6_lookup_multi.

No functional change.
2017-03-01 08:54:12 +00:00
ozaki-r 2496195667 Restore/add some softnet_lock for nd6_rt_flush and defrouter_addreq
May help PR kern/52015
2017-03-01 03:02:35 +00:00
ozaki-r 2d60fd0074 Separate the code of joining multicast groups
No functional change.
2017-02-28 04:07:11 +00:00
ozaki-r b44b24fe31 Prevent ia6 from being freed in in6_ifinit
It fixes a panic (diagnostic assertion "entry->ple_prevp != NULL" failed)
on:
  ifconfig lo1 create
  ifconfig lo1 127.0.0.2
reported by ryo@
2017-02-28 02:56:49 +00:00
ozaki-r 00a9cf741d Remove mkludge stuffs
For unknown reasons, IPv6 multicast addresses are linked to a first
IPv6 address assigned to an interface. Due to the design, when removing
a first address having multicast addresses, we need to save them to
somewhere and later restore them once a new IPv6 address is activated.
mkludge stuffs support the operations.

This change links multicast addresses to an interface directly and
throws the kludge away.

Note that as usual some obsolete member variables remain for kvm(3)
users. And also sysctl net.inet6.multicast_kludge remains to avoid
breaking old ifmcstat.

TODO: currently ifnet has a list of in6_multi but obviously the list
should be protocol independent. Provide a common structure (if_multi
or something) to handle in6_multi and in_multi together as well as
ifaddr does for in_ifaddr and in6_ifaddr.
2017-02-23 07:57:09 +00:00
ozaki-r 40914f019e Stop using useless IN6_*_MULTI macros 2017-02-22 07:46:00 +00:00
ozaki-r fcf7d70e3a Get rid of unnecessary splsoftnet 2017-02-22 07:05:47 +00:00
ozaki-r 559b831490 Add assertions and comments for lock states of socket and pcb 2017-02-22 07:05:04 +00:00
ozaki-r 66d96cc093 Use kmem istead of malloc 2017-02-22 03:41:54 +00:00
ozaki-r 93f6b1d8be Fix prefix invalidation via nd6_timer
We cannot remove a prefix there. Instead just invalidate it; the prefix
will be removed when purging an associated address. This is the same as
the original behavior.
2017-02-22 03:02:55 +00:00
ozaki-r 1f29833ec6 Sweep unnecessary malloc.h inclusions 2017-02-21 03:59:31 +00:00
ozaki-r 67412bb47f Replace malloc for DAD with kmem and move them out of the lock for DAD 2017-02-21 03:58:23 +00:00
ozaki-r c5696d3c25 Rename if_acquire_NOMPSAFE to if_acquire
It can be used in MP-safe ways. So let's remove the confusing postfix.
If it's used in a unsafe way, warn NOMPSAFE in a comment.
2017-02-17 03:57:17 +00:00
knakahara 706b73f634 add missing files. 2017-02-16 08:23:35 +00:00
knakahara 939a415a7d add l2tp(4) L2TPv3 interface.
originally implemented by IIJ SEIL team.
2017-02-16 08:12:43 +00:00
ozaki-r 3f909d1769 Do ND in L2_output in the same manner as arpresolve
The benefits of this change are:
- The flow is consistent with IPv4 (and FreeBSD and OpenBSD)
  - old: ip6_output => nd6_output (do ND if needed) => L2_output (lookup a stored cache)
  - new: ip6_output => L2_output (lookup a cache. Do ND if cache not found)
- We can remove some workarounds in nd6_output
- We can move L2 specific operations to their own place
- The performance slightly improves because one cache lookup is reduced
2017-02-14 03:05:06 +00:00
ozaki-r 19c4d830db Protect mtudisc and redirect stuffs of icmp/icmp6 with mutex
We have to run pr_init of icmp and icmp6 prior to tcp and tcp6 ones
for mutex initialization.
2017-02-13 07:18:20 +00:00
ozaki-r b070ee09f7 Replace splnet with splsoftnet 2017-02-13 04:05:58 +00:00
ozaki-r 57c38b2894 Add missing NULL checks for m_get_rcvif 2017-02-07 02:38:08 +00:00
ozaki-r 589739056f Defer some pr_input to workqueue
pr_input is currently called in softint. Some pr_input such as ICMP, ICMPv6
and CARP can add/delete/update IP addresses and routing table entries. For
example, icmp6_redirect_input updates an a routing table entry and
nd6_ra_input may delete an IP address.

Basically such operations shouldn't be done in softint. That aside, we have
a reason to avoid the situation; psz/psref waits cannot be used in softint,
however they are required to work in such pr_input in the MP-safe world.

The change implements the workqueue pr_input framework called wqinput which
provides a means to defer pr_input of a protocol to workqueue easily.
Currently icmp_input, icmp6_input, carp_proto_input and carp6_proto_input
are deferred to workqueue by the framework.

Proposed and discussed on tech-kern and tech-net
2017-02-02 02:52:10 +00:00
ozaki-r 9e8d969cf0 Tweak softnet_lock and NET_MPSAFE
- Don't hold softnet_lock in some functions if NET_MPSAFE
- Add softnet_lock to sysctl_net_inet_icmp_redirtimeout
- Add softnet_lock to expire_upcalls of ip_mroute.c
- Restore softnet_lock for in{,6}_pcbpurgeif{,0} if NET_MPSAFE
- Mark some softnet_lock for future work
2017-01-24 07:09:24 +00:00
ozaki-r c26964ba3f Replace some splnet with splsoftnet 2017-01-23 10:19:03 +00:00
ozaki-r 14cc93cb28 Get rid of splnet for pool(9)
We don't need it anymore.
2017-01-23 09:14:24 +00:00
christos 35561f6b22 ip6_sprintf -> IN6_PRINT so that we pass the size. 2017-01-16 15:44:46 +00:00
ozaki-r e4b1e1923a Remove KASSERT (revert in6.c,v 1.232)
We don't need it (it's harmless though).
2017-01-16 08:26:30 +00:00
ryo 28f4c24cc2 Make ip6_sprintf(), in_fmtaddr(), lla_snprintf() and icmp6_redirect_diag() mpsafe.
Reviewed by ozaki-r@
2017-01-16 07:33:36 +00:00
ozaki-r e4f13796f3 Tweak icmp6_input; always use off, not *offp 2017-01-13 10:38:37 +00:00
ozaki-r 046e2eafb0 Prevent in6_ifaddr from being freed with holding its psref
This is a possible fix for PR kern/51828.
2017-01-12 04:43:59 +00:00
christos 88f657f139 Add KASSERT. 2017-01-11 18:25:46 +00:00
ozaki-r 2b82ef9b8f Get rid of unnecessary header inclusions 2017-01-11 13:08:29 +00:00
ozaki-r a94a205118 Enable some sysctl knobs on rump kernels for ifmcstat 2017-01-10 05:42:34 +00:00
knakahara cc189cdb90 remove unnecessary conversion.
gif_softc->gif_pdst is already valid sockaddr.
2017-01-06 03:25:13 +00:00
christos 92bd3d8559 - kill NULL argument from in6_update_ifa
- amend in6_update_ifa1 to return the ia, so that we can use it in pfil hooks
  to avoid NULL pointer crash.
2017-01-04 19:37:14 +00:00
christos 042834e792 simplify, and call the hooks after the address has been deleted like we did
for the ipv4 case.
2017-01-03 15:14:31 +00:00
ryo 30456e82a3 In the case of SIOCDIFADDR, call pfil_run_addrhooks before release ia. 2016-12-31 09:41:05 +00:00
ozaki-r 12da772ecc Fix panic in pfil_run_hooks on bootup
XXX a kernel with pf still fails to boot up. Please someone fix it.
2016-12-27 10:53:11 +00:00
ozaki-r ec260ed075 Remove assertion that the lock isn't held
It's useless in this case, because without it we can know that
the lock is held or not on a next lock acquisition and even more
if LOCKDEBUG is enabled a failure on the acquisition will provide
useful information for debugging while an assertion failure will
provide just the fact that the assertion failed.
2016-12-22 03:46:51 +00:00
ozaki-r 6261537b3d Fix deadlock between llentry timers and destruction of llentry
llentry timer (of nd6) holds both llentry's lock and softnet_lock.
A caller also holds them and calls callout_halt to wait for the
timer to quit. However we can pass only one lock to callout_halt,
so passing either of them can cause a deadlock. Fix it by avoid
calling callout_halt without holding llentry's lock.

BTW in the first place we cannot pass llentry's lock to callout_halt
because it's a rwlock...
2016-12-21 08:47:02 +00:00
ozaki-r 3f765c212e Hold the big locks only where they are needed 2016-12-21 04:08:47 +00:00
ozaki-r 3adf4b3b3e Protect IPv6 default router and prefix lists with coarse-grained rwlock
in6_purgeaddr (in6_unlink_ifa) itself unrefernces a prefix entry and calls
nd6_prelist_remove if the counter becomes 0, so callers doesn't need to
handle the reference counting.

Performance-sensitive paths (sending/forwarding packets) call just one
reader lock. This is a trade-off between performance impact vs. the amount
of efforts; if we want to remove the reader lock, we need huge amount of
works including destroying objects with psz/psref in softint, for example.
2016-12-19 07:51:34 +00:00
ozaki-r 834995ee17 Kill pr->ndpr_refcnt = 0
The reference counter represents the numuber of references from IPv6
addresses to a prefix entry. If all IPv6 addresses assigned to an
interface are purged, all references to a prefix for the interface are
also released. For now nd6_purge is always called after purging all IPv6
addresses, so we can get rid of clearing pr->ndpr_refcnt from nd6_purge
and instead we can assert it's 0 there.

Note that nd6_ifdetach is only called via dom_ifdetach when processing
if_detach where dom_ifdetach is called after pr_purgeif that eventually
calls in6_ifdetach. So in the call path nd6_purge in nd6_ifdetach does
nothing. That said, we should explicitly make it sure to purge all
IPv6 addresses before nd6_purge for future changes (or the case I missed
something). So if_purgeaddrs is added to nd6_ifdetach.
2016-12-19 04:52:17 +00:00
ozaki-r 1ce4a727f8 Get rid of extra nd6_purge from in6_ifdetach
There were two nd6_purge in in6_ifdetach for some reason, but at least now
We don't need extra nd6_purge. Remove it and instead add assertions that
check if surely purged.
2016-12-19 03:32:54 +00:00
ozaki-r dd8638eea5 Move bpf_mtap and if_ipackets++ on Rx of each driver to percpuq if_input
The benefits of the change are:
- We can reduce codes
- We can provide the same behavior between drivers
  - Where/When if_ipackets is counted up
  - Note that some drivers still update packet statistics in their own
    way (periodical update)
- Moved bpf_mtap run in softint
  - This makes it easy to MP-ify bpf

Proposed on tech-kern and tech-net
2016-12-15 09:28:02 +00:00
knakahara 237f476937 fix race of gif_softc->gif_ro when we send multiple flows over gif on NET_MPSAFE enabled kernel.
make gif_softc->gif_ro percpu as well as ipforward_rt to resolve this race.
and add future TODO comment for etherip(4).
2016-12-14 11:19:15 +00:00
ozaki-r 8e7c1da780 Reduce return points
No functional change intended.
2016-12-14 06:33:01 +00:00
ozaki-r 0195cee9ea Use macro to iterate on the nd_prefix list 2016-12-14 04:13:50 +00:00
ozaki-r 9d79cf8c86 Make functions static 2016-12-14 04:05:11 +00:00
ozaki-r 44375ea93d Remove unnecessary inclusions of nd6.h 2016-12-13 08:29:03 +00:00
ozaki-r 6fb8880601 Make the routing table and rtcaches MP-safe
See the following descriptions for details.

Proposed on tech-kern and tech-net


Overview
--------

We protect the routing table with a rwock and protect
rtcaches with another rwlock. Each rtentry is protected
from being freed or updated via reference counting and psref.

Global rwlocks
--------------

There are two rwlocks; one for the routing table (rt_lock) and
the other for rtcaches (rtcache_lock). rtcache_lock covers
all existing rtcaches; there may have room for optimizations
(future work).

The locking order is rtcache_lock first and rt_lock is next.

rtentry references
------------------

References to an rtentry is managed with reference counting
and psref. Either of the two mechanisms is used depending on
where a rtentry is obtained. Reference counting is used when
we obtain a rtentry from the routing table directly via
rtalloc1 and rtrequest{,1} while psref is used when we obtain
a rtentry from a rtcache via rtcache_* APIs. In both cases,
a caller can sleep/block with holding an obtained rtentry.

The reasons why we use two different mechanisms are (i) only
using reference counting hurts the performance due to atomic
instructions (rtcache case) (ii) ease of implementation;
applying psref to APIs such rtaloc1 and rtrequest{,1} requires
additional works (adding a local variable and an argument).

We will finally migrate to use only psref but we can do it
when we have a lockless routing table alternative.

Reference counting for rtentry
------------------------------

rt_refcnt now doesn't count permanent references such as for
rt_timers and rtcaches, instead it is used only for temporal
references when obtaining a rtentry via rtalloc1 and rtrequest{,1}.
We can do so because destroying a rtentry always involves
removing references of rt_timers and rtcaches to the rtentry
and we don't need to track such references. This also makes
it easy to wait for readers to release references on deleting
or updating a rtentry, i.e., we can simply wait until the
reference counter is 0 or 1. (If there are permanent references
the counter can be arbitrary.)

rt_ref increments a reference counter of a rtentry and rt_unref
decrements it. rt_ref is called inside APIs (rtalloc1 and
rtrequest{,1} so users don't need to care about it while
users must call rt_unref to an obtained rtentry after using it.

rtfree is removed and we use rt_unref and rt_free instead.
rt_unref now just decrements the counter of a given rtentry
and rt_free just tries to destroy a given rtentry.

See the next section for destructions of rtentries by rt_free.

Destructions of rtentries
-------------------------

We destroy a rtentry only when we call rtrequst{,1}(RTM_DELETE);
the original implementation can destroy in any rtfree where it's
the last reference. If we use reference counting or psref, it's
easy to understand if the place that a rtentry is destroyed is
fixed.

rt_free waits for references to a given rtentry to be released
before actually destroying the rtentry. rt_free uses a condition
variable (cv_wait) (and psref_target_destroy for psref) to wait.

Unfortunately rtrequst{,1}(RTM_DELETE) can be called in softint
that we cannot use cv_wait. In that case, we have to defer the
destruction to a workqueue.

rtentry#rt_cv, rtentry#rt_psref and global variables
(see rt_free_global) are added to conduct the procedure.

Updates of rtentries
--------------------

One difficulty to use refcnt/psref instead of rwlock for rtentry
is updates of rtentries. We need an additional mechanism to
prevent readers from seeing inconsistency of a rtentry being
updated.

We introduce RTF_UPDATING flag to rtentries that are updating.
While the flag is set to a rtentry, users cannot acquire the
rtentry. By doing so, we avoid users to see inconsistent
rtentries.

There are two options when a user tries to acquire a rtentry
with the RTF_UPDATING flag; if a user runs in softint context
the user fails to acquire a rtentry (NULL is returned).
Otherwise a user waits until the update completes by waiting
on cv.

The procedure of a updater is simpler to destruction of
a rtentry. Wait on cv (and psref) and after all readers left,
proceed with the update.

Global variables (see rt_update_global) are added to conduct
the procedure.

Currently we apply the mechanism to only RTM_CHANGE in
rtsock.c. We would have to apply other codes. See
"Known issues" section.

psref for rtentry
-----------------

When we obtain a rtentry from a rtcache via rtcache_* APIs,
psref is used to reference to the rtentry.

rtcache_ref acquires a reference to a rtentry with psref
and rtcache_unref releases the reference after using it.
rtcache_ref is called inside rtcache_* APIs and users don't
need to take care of it while users must call rtcache_unref
to release the reference.

struct psref and int bound that is needed for psref is
embedded into struct route. By doing so we don't need to
add local variables and additional argument to APIs.

However this adds another constraint to psref other than
reference counting one's; holding a reference of an rtentry
via a rtcache is allowed by just one caller at the same time.
So we must not acquire a rtentry via a rtcache twice and
avoid a recursive use of a rtcache. And also a rtcache must
be arranged to be used by a LWP/softint at the same time
somehow. For IP forwarding case, we have per-CPU rtcaches
used in softint so the constraint is guaranteed. For a h
rtcache of a PCB case, the constraint is guaranteed by the
solock of each PCB. Any other cases (pf, ipf, stf and ipsec)
are currently guaranteed by only the existence of the global
locks (softnet_lock and/or KERNEL_LOCK). If we've found the
cases that we cannot guarantee the constraint, we would need
to introduce other rtcache APIs that use simple reference
counting.

psref of rtcache is created with IPL_SOFTNET and so rtcache
shouldn't used at an IPL higher than IPL_SOFTNET.

Note that rtcache_free is used to invalidate a given rtcache.
We don't need another care by my change; just keep them as
they are.

Performance impact
------------------

When NET_MPSAFE is disabled the performance drop is 3% while
when it's enabled the drop is increased to 11%. The difference
comes from that currently we don't take any global locks and
don't use psref if NET_MPSAFE is disabled.

We can optimize the performance of the case of NET_MPSAFE
on by reducing lookups of rtcache that uses psref;
currently we do two lookups but we should be able to trim
one of two. This is a future work.

Known issues
------------

There are two known issues to be solved; one is that
a caller of rtrequest(RTM_ADD) may change rtentry (see rtinit).
We need to prevent new references during the update. Or
we may be able to remove the code (perhaps, need more
investigations).

The other is rtredirect that updates a rtentry. We need
to apply our update mechanism, however it's not easy because
rtredirect is called in softint and we cannot apply our
mechanism simply. One solution is to defer rtredirect to
a workqueue but it requires some code restructuring.
2016-12-12 03:55:57 +00:00
ozaki-r f2613b7f35 Introduce macros for the prefix list
No functional change.
2016-12-12 03:14:01 +00:00
ozaki-r f5a82c952d Introduce macros for the default router list
No functional change.
2016-12-12 03:13:14 +00:00
ozaki-r 95eeb954a9 Add nd6_ prefix to exported functions 2016-12-11 07:38:50 +00:00
ozaki-r 091c448c26 Move default interface things from nd6_rtr.c to nd6.c 2016-12-11 07:37:53 +00:00
ozaki-r 100c447a96 Make some functions static 2016-12-11 07:36:55 +00:00
ozaki-r c43c0bf31c Remove function declarations that have no actual definition 2016-12-11 07:36:20 +00:00
ozaki-r eecbd48e68 Correct sanity checks of icmp6_redirect_output
- rt->rt_ifp is always non-NULL
- Checking RTF_UP here is just racy and meaningless
- The arguments should be non-NULL (at least for now)
2016-12-11 07:35:42 +00:00
ozaki-r 4c25fb2f83 Add rtcache_unref to release points of rtentry stemming from rtcache
In the MP-safe world, a rtentry stemming from a rtcache can be freed at any
points. So we need to protect rtentries somehow say by reference couting or
passive references. Regardless of the method, we need to call some release
function of a rtentry after using it.

The change adds a new function rtcache_unref to release a rtentry. At this
point, this function does nothing because for now we don't add a reference
to a rtentry when we get one from a rtcache. We will add something useful
in a further commit.

This change is a part of changes for MP-safe routing table. It is separated
to avoid one big change that makes difficult to debug by bisecting.
2016-12-08 05:16:33 +00:00
knakahara 2126b5df9a remove unnecessary extern declaration.
inetsw has been declared since r1.1, however sctp6_usrreq.c can be built
without the declaration. It must be removed.
2016-12-06 08:58:16 +00:00
ozaki-r 3de81a8881 CID 1396598, CID 1396634: Fix null pointer dereferences 2016-12-02 00:19:54 +00:00
ozaki-r 0645ba174f Fix panic on destroying an interface with IPv6 addresses obtained with RA
nd6_purge depends on that IPv6 addresses are purged. If addresses remain,
pfxlist_onlink_check called from nd6_purge dereferences a dangling pointer
(ia->ia6_ndpr) that is freed before calling pfxlist_onlink_check. Fix it by
removing addresses before calling nd6_purge, which is the original behavior
that was changed by in6.c,v 1.203 and in6_ifattach.c,v 1.99.

Note that it seems the issue occurs because of a hack that forcibly destroys
prefix list entries of a given interface in nd6_purge. We should tackle the
hack in the future.

Fix PR kern/51467
2016-11-30 02:08:57 +00:00
knakahara 2526d8f639 fix: "ifconfig destory" can stalls when "ifconfig" is done parallel.
This problem occurs only if NET_MPSAFE on.

ifconfig destroy side:
    kernel entry point is ifioctl => if_clone_destroy.
    pr_purgeif() acquires softnet_lock, and then ifa_remove() calls
    pserialize_perform() holding softnet_lock.
ifconfig side:
    kernel entry point is socreate.
    pr_attach()(udp_attach_wrapper()) calls sosetlock(). In this call path,
    sosetlock() try to acquire softnet_lock.
These can cause dead lock.
2016-11-18 06:50:04 +00:00
mlelstv 700032562a nd6_dad_duplicated takes the lock itself. Move it out of the critical
section.
2016-11-15 21:17:07 +00:00
mlelstv 845a599209 Enforce alignment requirements that are violated in some cases.
For machines that don't need strict alignment (i386,amd64,vax,m68k) this
is a no-op.

Fixes PR kern/50766 but should be improved.
2016-11-15 20:50:28 +00:00
ozaki-r 5879478f65 Don't use rt_walktree to delete routes
Some functions use rt_walktree to scan the routing table and delete
matched routes. However, we shouldn't use rt_walktree to delete
routes because rt_walktree is recursive to the routing table (radix
tree) and isn't friendly to MP-ification. rt_walktree allows a caller
to pass a callback function to delete an matched entry. The callback
function is called from an API of the radix tree (rn_walktree) but
also calls an API of the radix tree to delete an entry.

This change adds a new API of the radix tree, rn_search_matched,
which returns a matched entry that is selected by a callback
function passed by a caller and the caller itself deletes the
entry. By using the API, we can avoid the recursive form.
2016-11-15 01:50:06 +00:00
ozaki-r c2f4bfe351 Add missing rtfree 2016-11-14 02:34:19 +00:00
ozaki-r d0432711b6 Tidy up in6_select*
This change tidies up in6_select* functions, especially
selectroute.

selectroute is annoying because:
- It returns both/either of a rtentry and/or an ifp
  - Yes, it may return only an ifp!
    - It is valid but selectroute shouldn't handle the case
  - Such conditional behavior makes it difficult
    to apply locking/psref thingy
- It may return a rtentry even if error
- It may use opt->ip6po_nextroute rtcache implicitly
  - The caller can know if it is used
    by rtcache_validate(&opt->ip6po_nextroute)
    but it's racy in MP-safe world
  - Even if it uses opt->ip6po_nextroute, it may
    return a rtentry that isn't derived from the rtcache

The change includes:
- Rename selectroute to in6_selectroute
  - Let a remaining caller of selectroute, in6_selectif,
    use in6_selectroute instead
- Let in6_selectroute return only an rtentry
  - If error, it doesn't return an rtentry
  - A caller gets an ifp from a returned rtentry
- Allow in6_selectroute to modify a passed rtcache
  and a caller can know if opt->ip6po_nextroute is
  used via the rtcache
- Let callers (ip6_output and in6_selectif) handle
  the case that only an ifp is required

Inspired by OpenBSD
Proposed on tech-kern and tech-net
LGTM by roy@
2016-11-10 04:13:53 +00:00
ozaki-r fbb7e30d1e Reduce the number of return points of frag6_input
No functional change.
2016-11-09 03:49:38 +00:00
ozaki-r 29a46075c0 Pull routing header handling out of ip6_output
No functional change.
2016-11-07 01:55:17 +00:00
ozaki-r 2ad0a3feca Tidy up ip6_getpmtu
Pull rtcache thing out of ip6_getpmtu; that isn't an essential
of the function. Add comments inspired by FreeBSD.

No functional change.
2016-11-07 01:05:39 +00:00
ozaki-r ede76fae4b Add missing pserialize_read_exit 2016-11-02 03:43:27 +00:00
ozaki-r d5dc0960bb Reduce the number of return points
No functional change.
2016-11-01 10:32:57 +00:00
christos e3992d8536 restore previous logic. 2016-10-31 14:34:32 +00:00
ozaki-r c5224ffd07 Pull best address selection code out of in6_selectsrc
No functional change.
2016-10-31 04:57:10 +00:00
ozaki-r 0f3a44863e Fix race condition of in6_selectsrc
in6_selectsrc returned a pointer to in6_addr that wan't guaranteed to be
safe by pserialize (or psref), which was racy. Let callers pass a pointer
to in6_addr and in6_selectsrc copy a result to it inside pserialize
critical sections.
2016-10-31 04:16:25 +00:00
ozaki-r 6e6136eaff Remove unnecessary NULL checks 2016-10-31 02:50:31 +00:00
ozaki-r cf96c34d79 Remove unnecessary argument
No functional change.
2016-10-25 02:45:09 +00:00
ozaki-r 3be3142886 Don't hold global locks if NET_MPSAFE is enabled
If NET_MPSAFE is enabled, don't hold KERNEL_LOCK and softnet_lock in
part of the network stack such as IP forwarding paths. The aim of the
change is to make it easy to test the network stack without the locks
and reduce our local diffs.

By default (i.e., if NET_MPSAFE isn't enabled), the locks are held
as they used to be.

Reviewed by knakahara@
2016-10-18 07:30:30 +00:00
ozaki-r 6cabf64625 Fix indentation 2016-10-18 02:46:50 +00:00
ozaki-r 5faeb64f4b Remove unnecessary pserialize_read_enter 2016-10-18 02:46:21 +00:00
ozaki-r 48ec99bd49 Add missing pserialize_read_exit 2016-10-18 02:45:41 +00:00
roy 0dbee937df Now that we disallow sending or receiving from invalid addresses,
allow binding to tentative addresses.
2016-09-29 12:19:47 +00:00
roy 8066689d53 Drop UDP packets as well as TCP without error when sending from detached or
tentative addresses.
2016-09-20 14:30:13 +00:00
roy 8c6871896f Ensure that packets are sent from a valid address.
If the packet is TCP and the address is detached or tentative then
it's just dropped, otherwise an error is returned.

This is needed because you can bind to a valid address and it can then
become invalid.

This satisfies RFC 4862 section 5.5.4.
2016-09-15 18:25:45 +00:00
christos 0d94f00ba4 fix typo 2016-09-14 16:17:17 +00:00
christos 959c247a60 revert previous, roy says it breaks DaD. 2016-09-13 15:57:50 +00:00
christos acab31252a When initializing addresses, reset the interface flags to 0. This fixes
an issue where point to point addresses that started down, and then came
up, were left with stale flags on one side of the point to point link.
2016-09-13 15:41:33 +00:00
christos 647765d084 remove trailing spaces. userland does not catch this? 2016-09-13 00:45:15 +00:00
christos 47afd135ed add bits for address flags 2016-09-13 00:19:28 +00:00
roy 3e6930820d Disallow input to detached addresses because they are not yet valid. 2016-09-07 15:41:44 +00:00
roy c85195ff64 This comment no longer applies. 2016-09-02 15:57:54 +00:00
ozaki-r ab06ed1240 Don't GC an NDP cache that is added just before GC
This fixes unstable test results of ndp_neighborgcthresh.
2016-09-02 07:15:14 +00:00
ozaki-r 543e39c0d3 Make ipforward_rt and ip6_forward_rt percpu
Sharing one rtcache between CPUs is just a bad idea.

Reviewed by knakahara@
2016-08-31 09:14:47 +00:00
dholland 2df5f31439 PR 51434 David Binderman: remove redundant test. 2016-08-26 21:48:31 +00:00
roy c63a839724 Simplify. 2016-08-26 20:29:31 +00:00
roy 333b0c4c48 Allow explicit binding to detached addresss.
Fixes PR kern/51435.
2016-08-26 19:45:55 +00:00
roy 1893d82b49 White space police. 2016-08-23 19:39:57 +00:00
roy da7a376e71 Sync denied flags. 2016-08-23 19:39:04 +00:00
knakahara 74c24413b3 improve fast-forward performance when the number of flows exceeds ip6_maxflows.
This is porting of ip_flow.c:r1.76

In ip6flow case, the before degradation is about 45%, the after degradation is
bout 55%.
2016-08-23 09:59:20 +00:00
roy dfadc24d64 Revert r1.148
IP6_EXTHDR_GET ensures that a icmp6 header can be fetched from the mbuf
so m_pullup does not need to be called.

While here, we can safely increament interface error stats even with an
invalidated mbuf because we have a saved reference to the interface.
2016-08-19 12:26:01 +00:00
roy e52094cac4 Revert part of the prior patch so loopback lladdr gets a working prefix route. 2016-08-18 09:34:43 +00:00
roy fe4671807c Separate ioctl address prefix management from RA prefix management
as we have no API for controlling the latter.

This fixes a long standing problem where addresses added with non /128
prefixes and non infinte address lifetimes would register a prefix route
which would expire. Subsequent calls set new lifetimes for the same address
would not affect the prefix route management, so once expired, the
prefix route would be impossible to add back as the kernel would remove it.
2016-08-16 10:31:57 +00:00
christos fa02ef2c34 In rump (ifp)->if_afdata[AF_INET6] == NULL if we did not register netinet6
yet. Treat this like we don't have a scope, and make the sid tests consistent.
2016-08-12 11:44:24 +00:00
roy e9c7e74884 Set RTF_CONNECTED instead of setting only RTF_CONNECTED. 2016-08-06 20:00:14 +00:00
ozaki-r e8f81e31c2 CID 1364757: remove unnecessary branching 2016-08-05 00:51:14 +00:00
knakahara 48235e8230 ip6flow refactor like ipflow.
- move ip6flow sysctls into ip6_flow.c like ip_flow.c:r1.64
    - build ip6_flow.c only if GATEWAY kernel option is enabled
2016-08-02 04:50:16 +00:00
ozaki-r 466f21f0b9 Fix kernel builds (gcc 4.8) 2016-08-01 04:37:53 +00:00
ozaki-r a403cbd4f5 Apply pserialize and psref to struct ifaddr and its variants
This change makes struct ifaddr and its variants (in_ifaddr and in6_ifaddr)
MP-safe by using pserialize and psref. At this moment, pserialize_perform
and psref_target_destroy are disabled because (1) we don't need them
because of softnet_lock (2) they cause a deadlock because of softnet_lock.
So we'll enable them when we remove softnet_lock in the future.
2016-08-01 03:15:30 +00:00
ozaki-r efee6976a2 Avoid memset and rtcache_free if unnecessary
It's the same as ip_output.
2016-07-29 06:02:03 +00:00
ozaki-r c68a77bc1d Fix panic on adding/deleting IP addresses under network load
Adding and deleting IP addresses aren't serialized with other network
opeartions, e.g., forwarding packets. So if we add or delete an IP
address under network load, a kernel panic may happen on manipulating
network-related shared objects such as rtentry and rtcache.

To avoid such panicks, we still need to hold softnet_lock in in_control
and in6_control that are called via ioctl and do network-related operations
including IP address additions/deletions.

Fix PR kern/51356
2016-07-28 09:03:50 +00:00
ozaki-r e449cc85bc Simplify by using atomic_swap instead of mutex
Suggested by kefren@
2016-07-26 05:53:30 +00:00
ozaki-r a3625f4d7b Make DAD of ARP/NDP MP-safe with coarse-grained locks
The change also prevents arp_dad_timer/nd6_dad_timer from running if
arp_dad_stop/nd6_dad_stop is called, which makes sure that callout_reset
won't be called during callout_halt.
2016-07-25 04:21:19 +00:00
ozaki-r 6b3e3b4814 Use KASSERT for checking non-NULL of ifa->ifa_ifp
ifa->ifa_ifp should be always non-NULL, so doing the check only if
DIAGNOSTIC is ok.
2016-07-25 01:52:21 +00:00
ozaki-r 1f39eeaeb9 Get rid of extra ifafree
It was wrongly imported from FreeBSD.
2016-07-20 07:56:10 +00:00
ozaki-r 4f21a42704 Apply pserialize to some iterations of IP address lists 2016-07-20 07:37:51 +00:00
ozaki-r 8759207c83 Use sin6tosa and sin6tocsa macros
No functional change.
2016-07-15 07:40:09 +00:00
ozaki-r 328b3c6b85 Use ifatoia6 macro
No functional change.
2016-07-15 07:33:41 +00:00
ozaki-r dca032f9f4 Run timers in workqueue
Timers (such as nd6_timer) typically free/destroy some data in callout
(softint). If we apply psz/psref for such data, we cannot do free/destroy
process in there because synchronization of psz/psref cannot be used in
softint. So run timer callbacks in workqueue works (normal LWP context).

Doing workqueue_enqueue a work twice (i.e., call workqueue_enqueue before
a previous task is scheduled) isn't allowed. For nd6_timer and
rt_timer_timer, this doesn't happen because callout_reset is called only
from workqueue's work. OTOH, ip{,6}flow_slowtimo's callout can be called
before its work starts and completes because the callout is periodically
called regardless of completion of the work. To avoid such a situation,
add a flag for each protocol; the flag is set true when a work is
enqueued and set false after the work finished. workqueue_enqueue is
called only if the flag is false.

Proposed on tech-net and tech-kern.
2016-07-11 07:37:00 +00:00
ozaki-r 94dba1b837 CID 1363345: remove unreachable code and cleanup returns 2016-07-08 06:18:29 +00:00
ozaki-r 4133a8eca8 Replace macros to get an IP address with proper inline functions
The inline functions are more friendly for applying psz/psref;
they consist of only simple interations.
2016-07-08 04:33:30 +00:00
ozaki-r 75a23513d7 Kill remaining use of the old lists of IP addresses 2016-07-08 03:40:34 +00:00
ozaki-r 9e4c2bda8a Switch the address list of intefaces to pslist(9)
As usual, we leave the old list to avoid breaking kvm(3) users.
2016-07-07 09:32:01 +00:00
ozaki-r 6106c473fc Move in6_ifaddr_list to a more proper place (from ip6_input.c to in6.c)
It's a similar place as the IPv4 address list, i.e., in.c.

More varibles will join together.
2016-07-06 10:49:49 +00:00
ozaki-r 806a31cb3c Add missing IN6_ADDRLIST_ENTRY_DESTROY 2016-07-06 07:52:53 +00:00
ozaki-r d04ff44ad6 Apply m_get_rcvif_psref (kill m_get_rcvif_NOMPSAFE) 2016-07-06 00:30:55 +00:00
ozaki-r ff67da833b Constify an argument of regen_tmpaddr 2016-07-05 06:32:18 +00:00
ozaki-r 2a3c249748 KNF 2016-07-05 04:25:23 +00:00
ozaki-r c30ba26977 Use ia6 or ia instead of ifa as a variable name of struct in6_ifaddr
We conventionally use ifa for struct ifaddr and use ia6 or ia for
struct in6_ifaddr.

No functional change.
2016-07-05 03:40:52 +00:00
ozaki-r d961591ee9 Fix userland compilations of those including in6_var.h 2016-07-04 07:32:18 +00:00
ozaki-r 6cf9fce745 Use pslist(9) for the global in6_ifaddr list
psz and psref will be applied in another commit.

No functional change intended.
2016-07-04 06:48:14 +00:00
knakahara a6d7586724 fix: gif(4) receive side race
A panic cause in rn_match() called by encap[46]_lookup(). The reason is that
gif(4) does not suspend receive packet processing in spite of suspending
transmit packet processing while anyone is doing gif(4) ioctl.
2016-07-04 04:22:47 +00:00
knakahara d81cd78ed7 let gif(4) promise softint(9) contract (1/2) : gif(4) side
To prevent calling softint_schedule() after called softint_disestablish(),
the following modifications are added
    + ioctl (writing configuration) side
      - off IFF_RUNNING flag before changing configuration
      - wait softint handler completion before changing configuration
    + packet processing (reading configuraiotn) side
      - if IFF_RUNNING flag is on, do nothing
    + in whole
      - add gif_list_lock_{enter,exit} to prevent the same configuration is
        set to other gif(4) interfaces
2016-07-04 04:14:47 +00:00
ozaki-r feeae45125 Remove redundant codes purging IPv6 addresses
Proposed on tech-net and tech-kern.
2016-07-04 02:41:18 +00:00
ozaki-r 17b4eb5edd Make sure to free all interface addresses in if_detach
Addresses of an interface (struct ifaddr) have a (reverse) pointer of an
interface object (ifa->ifa_ifp). If the addresses are surely freed when
their interface is destroyed, the pointer is always valid and we don't
need a tweak of replacing the pointer to if_index like mbuf.

In order to make sure the assumption, the following changes are required:
- Deactivate the interface at the firstish of if_detach. This prevents
  in6_unlink_ifa from saving multicast addresses (wrongly)
- Invalidate rtcache(s) and clear a rtentry referencing an address on
  RTM_DELETE. rtcache(s) may delay freeing an address
- Replace callout_stop with callout_halt of DAD timers to ensure stopping
  such timers in if_detach
2016-07-01 05:22:33 +00:00
ozaki-r d4c71b34a8 Make sure that ifaddr is published after its initialization finished
Basically we should insert an item to a collection (say a list) after
item's initialization has been completed to avoid accessing an item
that is initialized halfway. ifaddr (in{,6}_ifaddr) isn't processed
like so and needs to be fixed.

In order to do so, we need to tweak {arp,nd6}_rtrequest that depend
on that an ifaddr is inserted during its initialization; they explore
interface's address list to determine that rt_getkey(rt) of a given
rtentry is in the list to know whether the route's interface should
be a loopback, which doesn't work after the change. To make it work,
first check RTF_LOCAL flag that is set in rt_ifa_addlocal that calls
{arp,nd6}_rtrequest eventually. Note that we still need the original
code for the case to remove and re-add a local interface route.
2016-06-30 01:34:53 +00:00
ozaki-r a577cf2aa0 Introduce if_is_deactivated
Checking ifp->if_output == if_nulloutput is too implicit.

No functional change.
2016-06-28 02:36:54 +00:00
ozaki-r ca4ea29d93 Add missing NULL checks for m_get_rcvif_psref 2016-06-28 02:02:56 +00:00
christos 9471dccf97 CID 1362905: Initialize ifp early, so that we don't if_put garbage in the
IPSEC case.
2016-06-27 18:35:54 +00:00
ozaki-r 4b54d200aa Remove unnecessary NULL checks of ifa->ifa_addr
If it's NULL, it should be a bug. There many IFADDR_FOREACH that don't do
NULL check. If it can be NULL, they should fire already.
2016-06-22 07:48:17 +00:00
ozaki-r 4badfc204a Make sure returning ifp from in6_select* functions psref-ed
To this end, callers need to pass struct psref to the functions
and the fuctions acquire a reference of ifp with it. In some cases,
we can simply use if_get_byindex, however, in other cases
(say rt->rt_ifp and ia->ifa_ifp), we have no MP-safe way for now.
In order to take a reference anyway we use non MP-safe function
if_acquire_NOMPSAFE for the latter cases. They should be fixed in
the future somehow.
2016-06-21 10:25:27 +00:00
ozaki-r f7107c248e Protect if_byindex with pserialize 2016-06-21 10:21:04 +00:00
ozaki-r 43c5ab376f Replace ifp of ip_moptions and ip6_moptions with if_index
The motivation is the same as the mbuf's rcvif case; avoid having a pointer
of an ifnet object in ip_moptions and ip6_moptions, which is not MP-safe.

ip_moptions and ip6_moptions can be stored in a PCB for inet or inet6
that's life time is different from ifnet one and so an ifnet object can be
disappeared anytime we get it via them. Thus we need to look up an ifnet
object by if_index every time for safe.
2016-06-21 03:28:27 +00:00
ozaki-r 51db7a24e2 Fix nd6_output (if_output_lock conversion mistake) 2016-06-21 02:14:11 +00:00
knakahara 95fc145695 apply if_output_lock() to L3 callers which call ifp->if_output() of L2(or L3 tunneling). 2016-06-20 06:46:37 +00:00
ozaki-r f0423d34e6 Use if_get_byindex instead of if_byindex for MP-safe 2016-06-16 03:03:33 +00:00
ozaki-r e1135cd9b9 Use curlwp_bind and curlwp_bindx instead of open-coding LP_BOUND 2016-06-16 02:38:40 +00:00
ozaki-r c7e18ccbde Protect if_byindex by pserialize 2016-06-15 06:01:21 +00:00
knakahara a6f4292e65 eliminate unnecessary splnet 2016-06-13 08:37:15 +00:00
knakahara e4ff09f05d MP-ify fastforward to support GATEWAY kernel option.
I add "ipflow_lock" mutex in ip_flow.c and "ip6flow_lock" mutex in ip6_flow.c
to protect all data in each file. Of course, this is not MP-scalable. However,
it is sufficient as tentative workaround. We should make it scalable somehow
in the future.

ok by ozaki-r@n.o.
2016-06-13 08:34:23 +00:00
ozaki-r fe6d427551 Avoid storing a pointer of an interface in a mbuf
Having a pointer of an interface in a mbuf isn't safe if we remove big
kernel locks; an interface object (ifnet) can be destroyed anytime in any
packet processing and accessing such object via a pointer is racy. Instead
we have to get an object from the interface collection (ifindex2ifnet) via
an interface index (if_index) that is stored to a mbuf instead of an
pointer.

The change provides two APIs: m_{get,put}_rcvif_psref that use psref(9)
for sleep-able critical sections and m_{get,put}_rcvif that use
pserialize(9) for other critical sections. The change also adds another
API called m_get_rcvif_NOMPSAFE, that is NOT MP-safe and for transition
moratorium, i.e., it is intended to be used for places where are not
planned to be MP-ified soon.

The change adds some overhead due to psref to performance sensitive paths,
however the overhead is not serious, 2% down at worst.

Proposed on tech-kern and tech-net.
2016-06-10 13:31:43 +00:00
ozaki-r d938d837b3 Introduce m_set_rcvif and m_reset_rcvif
The API is used to set (or reset) a received interface of a mbuf.
They are counterpart of m_get_rcvif, which will come in another
commit, hide internal of rcvif operation, and reduce the diff of
the upcoming change.

No functional change.
2016-06-10 13:27:10 +00:00
ozaki-r 9f10dc7910 Get rcvif once and reuse it
No functional change.
2016-05-19 08:53:25 +00:00
ozaki-r 348f728f8e Replace DIAGNOSTIC & panic with KASSERT 2016-05-19 03:11:42 +00:00
ozaki-r 894d037bc1 Get rid of unnecessary assignment 2016-05-18 11:28:44 +00:00
ozaki-r 9f595a90fa Get rid of unnecessary NULL check
It's already checked just some lines above.
2016-05-18 09:32:05 +00:00
ozaki-r 27df9b11fc Don't try to get outif unnecessarily from in6_selectsrc
The got outif is unused.
2016-05-18 08:40:51 +00:00
ozaki-r 842c4ed6c1 Get rcvif once and reuse it
No functional change.
2016-05-17 03:27:02 +00:00
ozaki-r 31da384114 Make sure icmp6_redirect_input frees mbuf before return 2016-05-17 03:24:46 +00:00
ozaki-r 040205ae93 Protect ifnet list with psz and psref
The change ensures that ifnet objects in the ifnet list aren't freed during
list iterations by using pserialize(9) and psref(9).

Note that the change adds a pslist(9) for ifnet but doesn't remove the
original ifnet list (ifnet_list) to avoid breaking kvm(3) users. We
shouldn't use the original list in the kernel anymore.
2016-05-12 02:24:16 +00:00
is 142ff9d692 Let non-neighbor NS/NA debug error message include useful information. 2016-04-29 11:46:17 +00:00
ozaki-r ad0fbab4d2 Get rid of unused argument from get_rand_ifid 2016-04-27 07:51:14 +00:00
ozaki-r 9e0f6c5e36 Stop using rt_gwroute on packet sending paths
rt_gwroute of rtentry is a reference to a rtentry of the gateway
for a rtentry with RTF_GATEWAY. That was used by L2 (arp and ndp)
to look up L2 addresses. By separating L2 nexthop caches, we don't
need a route for the purpose and we can stop using rt_gwroute.
By doing so, we can reduce referencing and modifying rtentries,
which makes it easy to apply a lock (and/or psref) to the
routing table and rtentries.

One issue to do this is to keep RTF_REJECT behavior. It seems it
was broken when we moved rtalloc1 things from L2 output routines
(e.g., ether_output) to ip_hresolv_output, but (fortunately?)
it works unexpectedly. What we mistook are:
- RTF_REJECT was checked for any routes in L2 output routines,
  but in ip_hresolv_output it is checked only when the route
  is RTF_GATEWAY
- The RTF_REJECT check wasn't copied to IPv6 (nd6_output)

It seems that rt_gwroute checks hid the mistakes and it looked
work (unexpectedly) and removing rt_gwroute checks unveil the
issue. So we need to fix RTF_REJECT checks in ip_hresolv_output
and also add them to nd6_output.

One more point we have to care is returning an errno; we need
to mimic looutput behavior. Originally RTF_REJECT check was
done either in L2 output routines or in looutput. The latter is
applied when a reject route directs to a loopback interface.
However, now RTF_REJECT check is done before looutput so to keep
the original behavior we need to return an errno which looutput
chooses. Added rt_check_reject_route does such tweaks.
2016-04-26 09:30:01 +00:00
ozaki-r a79dfa5db0 Sweep unnecessary route.h inclusions 2016-04-26 08:44:44 +00:00
rjs 505ea9765f Fix build when IPSEC enabled. 2016-04-25 21:21:02 +00:00
ozaki-r 0c74cec625 Check error of rt_setgate and rt_settag 2016-04-25 14:38:08 +00:00
ozaki-r c325d0ca4f Fix RTF_{REJECT,BLACKHOLE} behavior for IPv6 routes
We still need a nexthop route to reflect RTF_{REJECT,BLACKHOLE}.
In the future, we would do it w/o looking up a route.
2016-04-21 05:07:50 +00:00
ozaki-r 322b6a238d Sweep unncessary radix.h inclusions 2016-04-11 08:56:16 +00:00
ozaki-r dd3c4fc3e5 Don't call pfxlist_onlink_check with holding llentry lock
From FreeBSD (as of 2016-04-11).

Should fix PR kern/51060.
2016-04-11 01:16:20 +00:00
ozaki-r f0071d85a1 Don't call pfxlist_onlink_check with holding llentry lock
Sync nd6_free with FreeBSD (as of 2016-04-10).

Should fix PR kern/51056.
2016-04-10 08:15:52 +00:00
roy 60a5a4a8a7 all1_sa is no longer used. 2016-04-04 12:05:40 +00:00
ozaki-r 09973b35ac Separate nexthop caches from the routing table
By this change, nexthop caches (IP-MAC address pair) are not stored
in the routing table anymore. Instead nexthop caches are stored in
each network interface; we already have lltable/llentry data structure
for this purpose. This change also obsoletes the concept of cloning/cloned
routes. Cloned routes no longer exist while cloning routes still exist
with renamed to connected routes.

Noticeable changes are:
- Nexthop caches aren't listed in route show/netstat -r
  - sysctl(NET_RT_DUMP) doesn't return them
  - If RTF_LLDATA is specified, it returns nexthop caches
- Several definitions of routing flags and messages are removed
  - RTF_CLONING, RTF_XRESOLVE, RTF_LLINFO, RTF_CLONED and RTM_RESOLVE
- RTF_CONNECTED is added
  - It has the same value of RTF_CLONING for backward compatibility
- route's -xresolve, -[no]cloned and -llinfo options are removed
  - -[no]cloning remains because it seems there are users
  - -[no]connected is introduced and recommended
    to be used instead of -[no]cloning
- route show/netstat -r drops some flags
  - 'L' and 'c' are not seen anymore
  - 'C' now indicates a connected route
- Gateway value of a route of an interface address is now not
  a L2 address but "link#N" like a connected (cloning) route
- Proxy ARP: "arp -s ... pub" doesn't create a route

You can know details of behavior changes by seeing diffs under tests/.

Proposed on tech-net and tech-kern:
  http://mail-index.netbsd.org/tech-net/2016/03/11/msg005701.html
2016-04-04 07:37:07 +00:00
ozaki-r 35b18fbb1d Remove unnecessary casts and do s/0/NULL/ for rtrequest 2016-04-01 09:16:02 +00:00
ozaki-r 103bd8df24 Refine nd6log
Add __func__ to nd6log itself instead of adding it to callers.
2016-04-01 08:12:00 +00:00
ozaki-r 19fb0179dc Use __func__ in log messages 2016-04-01 06:25:51 +00:00
ozaki-r acdecad069 Tidy up nd6_timer initialization 2016-04-01 05:11:38 +00:00
knakahara 9b7918b3ee remove unnecessary declarations and fix KNF
Thanks to riastradh@
2016-02-29 01:29:15 +00:00
knakahara e80f101289 To eliminate gif_softc_list linear search, add extra argument to encapsw.pr_ctlinput(). 2016-02-26 07:35:17 +00:00
rtr e2a3307b85 Reduce code duplication.
Split creation of IPv4-Mapped IPv6 addresses into its own function
and use it.

No functional change intended.  As posted to tech-net@
2016-02-15 14:59:03 +00:00
ozaki-r 9c4cd06355 Introduce softint-based if_input
This change intends to run the whole network stack in softint context
(or normal LWP), not hardware interrupt context. Note that the work is
still incomplete by this change; to that end, we also have to softint-ify
if_link_state_change (and bpf) which can still run in hardware interrupt.

This change softint-ifies at ifp->if_input that is called from
each device driver (and ieee80211_input) to ensure Layer 2 runs
in softint (e.g., ether_input and bridge_input). To this end,
we provide a framework (called percpuq) that utlizes softint(9)
and percpu ifqueues. With this patch, rxintr of most drivers just
queues received packets and schedules a softint, and the softint
dequeues packets and does rest packet processing.

To minimize changes to each driver, percpuq is allocated in struct
ifnet for now and that is initialized by default (in if_attach).
We probably have to move percpuq to softc of each driver, but it's
future work. At this point, only wm(4) has percpuq in its softc
as a reference implementation.

Additional information including performance numbers can be found
in the thread at tech-kern@ and tech-net@:
http://mail-index.netbsd.org/tech-kern/2016/01/14/msg019997.html

Acknowledgment: riastradh@ greatly helped this work.
Thank you very much!
2016-02-09 08:32:07 +00:00
riastradh 3bc04b00b8 Declare in6_tmpaddrtimer_ch in in6_var.h.
Do not declare extern variables in .c files!
2016-02-04 02:48:37 +00:00
knakahara b546d5277b implement encapsw instead of protosw and uniform prototype.
suggested and advised by riastradh@n.o, thanks.

BTW, It seems in_stf_input() had bugs...
2016-01-26 05:58:05 +00:00
riastradh fa50b451d4 Those were local changes not meant to be part of the revert. SORRY! 2016-01-23 14:48:55 +00:00
christos e28df70b14 make this compile again 2016-01-23 14:03:04 +00:00
riastradh e588d95c25 Back out previous change to introduce struct encapsw.
This change was intended, but Nakahara-san had already made a better
one locally!  So I'll let him commit that one, and I'll try not to
step on anyone's toes again.
2016-01-22 23:27:12 +00:00
riastradh 87bc652e3d Don't abuse struct protosw for ip_encap -- introduce struct encapsw.
Mostly mechanical change to replace it, culling some now-needless
boilerplate around all the users.

This does not substantively change the ip_encap API or eliminate
abuse of sketchy pointer casts -- that will come later, and will be
easier now that it is not tangled up with struct protosw.
2016-01-22 05:15:10 +00:00
riastradh 7c7b1739c8 Revert previous: ran cvs commit when I meant cvs diff. Sorry!
Hit up-arrow one too few times.
2016-01-21 15:41:29 +00:00
riastradh b41d562bd0 Give proper prototype to ip_output. 2016-01-21 15:27:48 +00:00
riastradh 65a8f527af Eliminate struct protosw::pr_output.
You can't use this unless you know what it is a priori: the formal
prototype is variadic, and the different instances (e.g., ip_output,
route_output) have different real prototypes.

Convert the only user of it, raw_send in net/raw_cb.c, to take an
explicit callback argument.  Convert the only instances of it,
route_output and key_output, to such explicit callbacks for raw_send.
Use assertions to make sure the conversion to explicit callbacks is
warranted.

Discussed on tech-net with no objections:
https://mail-index.netbsd.org/tech-net/2016/01/16/msg005484.html
2016-01-20 21:43:59 +00:00
knakahara d7b9bb29c0 Refactor protosw codes in gif(4). No functional change.
- remove unnecessary include
    - reduce scopes
2016-01-18 06:08:26 +00:00
ozaki-r 5c49460e3c Add missing RTF_LOCAL; sync with arp_setgate 2016-01-08 08:50:07 +00:00
knakahara 1c5d304e9c eliminate ip_input.c and ip6_input.c dependency on gif(4) 2016-01-08 03:55:39 +00:00
knakahara 6d50f36d54 use satosin{,6} macros instead of casts. 2015-12-25 06:47:56 +00:00
ozaki-r 9c1d124220 Add missing LLE_WUNLOCK to nd6_free 2015-12-18 09:04:33 +00:00
christos 5b5956f338 Hook up the addrctl stuff that's already there. 2015-12-12 23:34:25 +00:00
knakahara a00e94f4ff PR kern/50522: gif(4) ioctl causes panic while someone is using the gif(4) interface.
It is required to wait other CPU's softint completion before disestablishing
the softint handler.
2015-12-11 07:59:14 +00:00
ozaki-r c6e461ee0d CID 1341546: Fix integer handling issue (CONSTANT_EXPRESSION_RESULT)
n > INT_MAX where n is a long integer variable never be true on 32bit
architectures. Use time_t(int64_t) instead of long for the variable.
2015-12-07 06:19:13 +00:00
ozaki-r 2c1e216cf8 Replace __debugused with __diagused
Declaring __debugused was just a mistake. This fixes builds of kernels with
DEBUG but without DIAGNOSTIC.
2015-11-27 02:54:22 +00:00
ozaki-r ff97010dea Declare __debugused for no DIAGNOSTIC kernels
This unbreaks hpcsh GENERIC kernel build.
2015-11-25 07:06:19 +00:00
ozaki-r ecd5b23eef Use lltable/llentry for NDP
lltable and llentry were introduced to replace ARP cache data structure
for further restructuring of the routing table: L2 nexthop cache
separation. This change replaces the NDP cache data structure
(llinfo_nd6) with them as well as ARP.

One noticeable change is for neighbor cache GC mechanism that was
introduced to prevent IPv6 DoS attacks. net.inet6.ip6.neighborgcthresh
was the max number of caches that we store in the system. After
introducing lltable/llentry, the value is changed to be per-interface
basis because lltable/llentry stores neighbor caches in each interface
separately. And the change brings one degradation; the old GC mechanism
dropped exceeded packets based on LRU while the new implementation drops
packets in order from the beginning of lltable (a hash table + linked
lists). It would be improved in the future.

Added functions in in6.c come from FreeBSD (as of r286629) and are
tweaked for NetBSD.

Proposed on tech-kern and tech-net.
2015-11-25 06:21:26 +00:00
ozaki-r 0edb16352e Call icmp6_error2 after releasing ln
This is a restructuring for coming changes.

From FreeBSD
2015-11-19 03:02:10 +00:00
ozaki-r 5d81659a46 Stop passing llinfo_nd6 to nd6_ns_output
This is a restructuring for coming changes to nd6 (replacing
llinfo_nd6 with llentry). Once we have a lock of llinfo_nd6,
we need to pass it to nd6_ns_output with holding the lock.
However, in a function subsequent to nd6_ns_output, the llinfo_nd6
may be looked up, i.e., its lock would be acquired again.
To avoid such a situation, pass only required data (in6_addr) to
nd6_ns_output instead of passing whole llinfo_nd6.

Inspired by FreeBSD
2015-11-18 05:16:22 +00:00
ozaki-r 7cdf5bbe65 Unify nd6_ns_output calls in nd6_llinfo_timer
Inspired by FreeBSD
2015-11-18 02:51:11 +00:00
joerg a3e166507d Ensure that the callout of the multicast address is valid before
hooking it up.
2015-11-12 15:01:06 +00:00
rjs 8c2654abca Add core networking support for SCTP. 2015-10-13 21:28:34 +00:00
ozaki-r 91afbd53fe Use satosin6 instead of its own macro 2015-10-05 04:15:42 +00:00
ozaki-r 4f92eb6d47 Update icmp6_redirect_timeout_q when changing net.inet6.icmp6.redirtimeout
We have to update icmp6_redirect_timeout_q as well as icmp6_redirtimeout
when changing net.inet6.icmp6.redirtimeout via sysctl. The updating logic
is copied from sysctl_net_inet_icmp_redirtimeout.

This change is from s-yamaguchi@IIJ (with KNF by ozaki-r) and fixes
PR kern/50240.
2015-09-14 05:34:28 +00:00
roy f3b0c038a1 If, for whatever reason, a local interface route is removed and then
re-added, mark it as a local route.

While here, if changing the route to go via the loopback interface
remove any inherited MTU value.
2015-09-11 10:33:32 +00:00
dholland 1fbab01a93 More on PR 41200: headers that declare ioctls should include sys/ioccom.h.
This covers (I think) all the MI headers outside of external/ (and dist/).
2015-09-06 06:00:59 +00:00
ozaki-r 30a9349144 Pull nexthop determination routine from nd6_output
It simplifies nd6_output and the nexthop determination routine slightly.
2015-09-04 05:33:23 +00:00
ozaki-r 6af5fcf207 Fix rtfree in nd6_output
We have to check and avoid to rtfree the original rtentry passed to
nd6_output even when manipulating gateway routes.

This fixes panic on assertion "ro->_ro_rt ==NULL || ro->_ro_rt->rt_refcnt > 0"
failure and probably PR kern/50161.
2015-09-03 00:54:39 +00:00
ozaki-r 54c4f3b688 Do rt_refcnt++ when set a rtentry to another rtentry's rt_gwroute
And also do rtfree when deref a rtentry from rt_gwroute.
2015-09-02 11:35:11 +00:00