Commit Graph

1913 Commits

Author SHA1 Message Date
ozaki-r
ebc34b07ac Simplify; pass dp to nd6_dad_duplicated instead of looking it up again in it 2018-02-24 07:40:40 +00:00
ozaki-r
588831e435 Use KASSERT for checking a programming error 2018-02-24 07:38:05 +00:00
ozaki-r
ef58cf2ca2 Avoid a deadlock between softnet_lock and IFNET_LOCK
A deadlock occurs because there is a violation of the rule of lock ordering;
softnet_lock is held with hodling IFNET_LOCK, which violates the rule.
To avoid the deadlock, replace softnet_lock in in_control and in6_control
with KERNEL_LOCK.

We also need to add some KERNEL_LOCKs to protect the network stack surely.
This is required, for example, for PR kern/51356.

Fix PR kern/53043
2018-02-24 07:37:08 +00:00
maxv
f574a1384a Re-make ip6_nexthdr global, it will be used in soon-to-be-added code... 2018-02-14 05:29:39 +00:00
maxv
42fdf13228 Replace bcopy -> memcpy when it is obvious that the areas don't overlap.
Rearrange ip6_splithdr() for clarity.
2018-02-12 12:52:12 +00:00
maxv
f93abcea1a Remove dead code. 2018-02-09 18:31:52 +00:00
maxv
89306ac8eb Remove the IN6_IS_ADDR_V4MAPPED checks in the protocol functions. They
are useless, because the IPv6 entry point (ip6_input) already performs
them.

The checks were first added in the protocol functions:

	Wed Dec 22 04:03:02 1999 UTC (18 years, 1 month ago) by itojun

"drop IPv6 packets with v4 mapped address on src/dst.  they are illegal
and may be used to fool IPv6 implementations (by using ::ffff:127.0.0.1 as
source you may be able to pretend the packet is from local node)"

Shortly afterwards they were also added in the IPv6 entry point, but
where not removed from the protocol functions:

	Mon Jan 31 10:33:22 2000 UTC (18 years ago) by itojun

"be proactive about malicious packet on the wire.  we fear that v4 mapped
address to be used as a tool to hose security filters (like bypassing
"local host only" filter by using ::ffff:127.0.0.1)."

OpenBSD did the same a few months ago. FreeBSD has never had these checks.
2018-02-08 19:58:05 +00:00
maxv
51ef7eba4e pr_send can be given a NULL lwp. It looks like the
control != NULL && lwp == NULL

condition is never supposed to happen, but add a panic for safety.
2018-02-08 11:49:37 +00:00
maxv
63ecc40c9f Move udp6_output() into udp6_usrreq.c, and remove udp6_output.c. This is
more consistent with IPv4, and there is no good reason for keeping a
separate file only for one function. FreeBSD did the same.
2018-02-08 11:34:35 +00:00
maxv
d607124519 Style, no functional change. 2018-02-08 11:13:20 +00:00
dholland
32cded6cc9 Typos. 2018-02-08 09:05:16 +00:00
maxv
74d6a802d1 Style, and localify IPV6FORWARDING. No functional change. 2018-02-07 10:52:20 +00:00
maxv
21089e6cb0 Change ip6_hdrnestlimit to be 15 instead of 50. I couldn't find any
reference in RFCs about what a correct limit should be, but FreeBSD already
uses 15.

If an IPv6 packet has 50 options, there is clearly something wrong with it.
2018-02-07 10:21:59 +00:00
maxv
1fd7efcc06 Rename back to ip6af_mff. It was actually clearer than ip6af_more. 2018-02-07 09:53:08 +00:00
maxv
e040d0652e Remove dead code. 2018-02-06 06:32:25 +00:00
ozaki-r
2c87fbb8b4 Shorten the name of a workqueue instance to fit to the limit (15) 2018-02-06 03:37:00 +00:00
maxv
e6ee9f6b31 Fix memory leak. Contrary to what the XXX indicates, this place is 100%
reachable remotely.
2018-02-02 10:49:01 +00:00
maxv
0928747602 Style, no functional change. 2018-02-02 09:01:17 +00:00
maxv
a201ebeeff Fix a pretty simple, yet pretty tragic typo: we should return IPPROTO_DONE,
not IPPROTO_NONE. With IPPROTO_NONE we will keep parsing the header chain
on an mbuf that was already freed.
2018-02-02 06:23:45 +00:00
maxv
c4a55989cb Style, no real functional change. 2018-02-01 16:36:01 +00:00
maxv
8c1fdc3b35 Remove this code, RH0 must be dropped, according to RFC5095. FreeBSD and
OpenBSD already do the same. Also, style, and remove useless includes.
2018-02-01 16:23:28 +00:00
maxv
ef80388f64 Fix the ICMP error code. rh was obtained via IP6_EXTHDR_GET, and it is not
guaranteed to be in the same mbuf as ip6, so computing the difference
between the pointers may result in a wrong offset.

ip6 is now unused, so remove it.
2018-02-01 16:17:00 +00:00
maxv
0ae50bb62f Fix use-after-free, the first m_copyback_cow may have freed the mbuf, so
it is wrong to read ip6->ip6_nxt.
2018-02-01 15:53:16 +00:00
maxv
a39eb722f7 Style, and remove the 'len' argument from mld_allocbuf(), it is misleading,
we only want a static struct. Beyond that no functional change.
2018-02-01 07:49:19 +00:00
maxv
45478fd8ef Correct the check; we want to find IPPROTO_HOPOPTS, not IPV6_HOPOPTS. This
just couldn't work.

By the way, I'm wondering what is the point of this block. Calling
ip6_hopopts_input() won't achieve anything useful, and it could actually
be a problem, because there are several paths in it that call icmp6_error,
which calls ip6_output, and then we're back in the same function. Besides
it is possible to reach icmp6_error with a packet we emitted (as opposed
to a packet we are forwarding), and in that case we are sending an ICMP
error back to ourselves.
2018-01-31 15:23:08 +00:00
maxv
e39bdcbb31 Remove a misleading instruction. We don't care about increasing
m_pkthdr.len in ip6_insertfraghdr(), it gets recomputed after calling
this function.

If we cared there would be a bug, since we don't increase it in the
other branches.
2018-01-31 14:16:28 +00:00
maxv
52eac47c39 Try to sound a little less pessimistic, there is nothing wrong here. 2018-01-31 14:10:11 +00:00
maxv
a71c7a1500 Style, localify, constify, and reorder a bit. No real functional change. 2018-01-31 13:57:08 +00:00
maxv
4e9bde34d6 Style, localify, remove dead code, and fix typos. No functional change. 2018-01-30 15:54:02 +00:00
maxv
5b47e99add Kick nested fragments. 2018-01-30 15:35:31 +00:00
maxv
71ad96023a Fix a buffer overflow in ip6_get_prevhdr. Doing
mtod(m, char *) + len

is wrong, an option is allowed to be located in another mbuf of the chain.
If the offset of an option within the chain is bigger than the length of
the first mbuf in that chain, we are reading/writing one byte of packet-
controlled data beyond the end of the first mbuf.

The length of this first mbuf depends on the layout the network driver
chose. In the most difficult case, it will allocate a 2KB cluster, which
is bigger than the Ethernet MTU.

But there is at least one way of exploiting this case: by sending a
special combination of nested IPv6 fragments, the packet can control a
good bunch of 'len'. By luck, the memory pool containing clusters does not
embed the pool header in front of the items, so it is not straightforward
to predict what is located at 'mtod(m, char *) + len'.

However, by sending offending fragments in a loop, it is possible to
crash the kernel - at some point we will hit important data structures.

As far as I can tell, PF protects against this difficult case, because
it kicks nested fragments. NPF does not protect against this. IPF I don't
know.

Then there are the more easy cases, if the MTU is bigger than a cluster,
or if the network driver did not allocate a cluster, or perhaps if the
fragments are received via a tunnel; I haven't investigated these cases.

Change ip6_get_prevhdr so that it returns an offset in the chain, and
always use IP6_EXTHDR_GET to get a writable pointer. IP6_EXTHDR_GET
leaves M_PKTHDR untouched.

This place is still fragile.
2018-01-30 14:49:25 +00:00
christos
81afadce96 more cleanup (don't allow oldlenp == NULL) 2018-01-29 19:51:15 +00:00
maxv
6f5024f576 Start cleaning up ip6_input.c. Several pieces of code have evolved but
their neighboring comments were not updated. So update them, and remove
code that has been disabled for years (it has no use anyway).
2018-01-29 10:57:13 +00:00
maxv
6163bade20 Style, and use __cacheline_aligned.
By the way, it would be nice to revisit the use of 'ip6flow_lock' in
ip6flow_fastforward(): it is taken right away because of 'ip6flow_inuse',
but then we perform several checks that do not require it.
2018-01-29 08:27:10 +00:00
maxv
90dd9967f8 style 2018-01-29 08:17:18 +00:00
maxv
a7c056383d Fix two pretty bad mistakes. If ipsec6_check_policy fails m is not freed,
and a 'goto out' is missing after ipsec6_process_packet.
2018-01-29 08:14:54 +00:00
pgoyette
b418119fb8 One more from christos@
No need to initialize fill_func
2018-01-29 03:42:53 +00:00
pgoyette
eea2cd6dc9 More simplification, this time from ozaki-r@
No need to break after return.
2018-01-29 03:35:23 +00:00
pgoyette
ce7078ed7c Simplify, from christos@ 2018-01-29 03:29:26 +00:00
pgoyette
3bf8ebadfd Use existing fill_[pd]rlist() functions to calculate size of buffer to
allocate, rather than relying on an arbitrary length passed in from
userland.

Allow copyout() of partial results if the user buffer is too small, to
be consistent with the way sysctl(3) is documented.

Garbage-collect now-unused third parrameter in the fill_[pd]rlist()
functions.

As discussed on IRC.
OK kamil@ and christos@

XXX Needs pull-up to netbsd-8 branch.
2018-01-29 02:02:14 +00:00
maxv
9d928fe0f1 A few fixes:
* Style.

 * Don't add M_PKTHDR manually, that's absolutely forbidden. Add a
   KASSERT to make sure it's already there.

 * Add a missing NULL check after m_pullup.
2018-01-26 14:47:41 +00:00
maxv
7bd67feaa8 Several fixes in L2TP:
* l2tp_input(): use m_copydata, and ensure there is enough space in the
   chain. Otherwise overflow.

 * l2tp_tcpmss_clamp(): ensure there is enough space in the chain.

 * in_l2tp_output(): don't check 'sc' against NULL, it can't be NULL.

 * in_l2tp_input(): no need to call m_pullup since we use m_copydata.
   Just check the space in the chain.

 * in_l2tp_input(): if there is a cookie, make sure the chain has enough
   space.

 * in6_l2tp_input(): same changes as in_l2tp_input().

Ok knakahara@
2018-01-26 07:49:15 +00:00
ozaki-r
aaa0898633 Get rid of unnecessary splsoftnet (redo)
Unless NET_MPSAFE, splsoftnet is still needed for rt_* functions.
2018-01-26 06:49:02 +00:00
ozaki-r
6c6efc296a Revert "Get rid of unnecessary splsoftnet" (v1.133)
It's not always true that softnet_lock is held these places.
See PR kern/52947.
2018-01-26 06:37:21 +00:00
maxv
2cd98cd7f9 Kick zero-sized fragments. We can't allow them to enter; two fragments
could be put at the same offset.
2018-01-25 20:55:15 +00:00
maxv
4eac13772c Remove outdated comment and fix typo. 2018-01-25 15:55:57 +00:00
maxv
e3090ee154 Several changes:
* Move the structure definitions into frag6.c, they should not be used
   elsewhere.

 * Rename ip6af_mff -> ip6af_more, and switch it to bool, easier to
   understand.

 * Remove IP6_REASS_MBUF, no point in keeping this.

 * Remove ip6q_arrive and ip6q_nxtp, unused.

 * Style.
2018-01-25 15:33:06 +00:00
maxv
eb74a6f9ba Style, reduce the indentation level when possible, and add a missing NULL
check after M_PREPEND.
2018-01-25 10:45:58 +00:00
ozaki-r
2de460fa34 Fix constraint violation of pserialize in in6_ifattach
in6_ifattach_loopback can sleep so we cannot use pserialize for it. Fortunately
in6_ifattach is alwasy called with IFNET_LOCK so pserialize isn't needed there
actually.
2018-01-24 03:44:10 +00:00
maxv
0a378e1d2b Fix the calculation of the ICMP6 error pointer. It is not correct to use
pointer = opt - mtod(m, u_int8_t *)

because m may have gone through m_pulldown, and it is possible that
m->m_data is no longer the beginning of the packet.
2018-01-23 15:13:56 +00:00
maxv
8d81257030 Style, localify, remove XXX when there's no issue, and switch 'extra'
to int.
2018-01-23 10:55:38 +00:00
maxv
64e3e4a7da Fix the check on 'maxlen', we are not creating struct icmp6_hdr but
struct nd_redirect (which is bigger). Also, make sure we can add a
struct nd_opt_rd_hdr.

Normally this doesn't change anything, since the mbuf has IPV6_MMTU
bytes, and it's always way bigger than what we need.
2018-01-23 10:46:59 +00:00
maxv
c0011bd096 Fix info leak. We are allocating a slot of size:
roundup(sizeof(*nd_opt) + ifp->if_addrlen, 8)

But we are not filling in the padding caused by the roundup, and therefore
several bytes are leaked, in the mbuf we're about to send to the network.
2018-01-23 10:32:50 +00:00
maxv
300aacb2b0 Fix twice the same mistake: 'last' can't be null, so there's no point in
having this misleading branch.
2018-01-23 09:21:59 +00:00
maxv
cde3086ed1 Style, and four fixes:
* Remove the (disabled) IPPROTO_ESP check. If the packet was decrypted it
   will have M_DECRYPTED, and this is already checked.

 * Memory leaks in icmp6_error2. They seem hardly triggerable.

 * Fix miscomputation in _icmp6_input, the ICMP6 header is not guaranteed
   to be located right after the IP6 header. ok mlelstv@

 * Memory leak in _icmp6_input. This one seems to be impossible to trigger.
2018-01-23 07:02:57 +00:00
ozaki-r
606d8da495 Suppress noisy debugging outputs
Even if DEBUG they are too noisy under load.
2018-01-19 08:01:05 +00:00
ozaki-r
1b37ab7b8c Make DAD destructions (MP-)safe with callout_stop
arp_dad_stoptimer and nd6_dad_stoptimer can be called with or without
softnet_lock held and unfortunately we have no easy way to statically know which.
So it is hard to use callout_halt there.

To address the situation, we use callout_stop to make the code safe. The new
approach copes with the issue by delegating the destruction of a callout to
callout itself, which allows us to not wait the callout to finish. This can be
done thanks to that DAD objects are separated from other data such as ifa.

The approach is suggested by riastradh@
Proposed on tech-kern@ and tech-net@
2018-01-16 08:13:47 +00:00
ozaki-r
d8462ff5f2 Revert "Work around softnet_lock handling" as per pgoyette@'s request
We should avoid if (mutex_owned(softnet_lock)).
2018-01-16 07:56:55 +00:00
ozaki-r
4090a5f5a5 Remove extra pserialize_perform from in_purgeaddr
It's already performed in ifa_remove. Note so there (in in6_unlink_ifa too).
2018-01-15 08:17:34 +00:00
knakahara
fe5d98860a apply in{,6}_tunnel_validate() to gif(4). 2018-01-10 11:13:26 +00:00
knakahara
4ab3af3e3e add ipsec(4) interface, which is used for route-based VPN.
man and ATF are added later, please see man for details.

reviewed by christos@n.o, joerg@n.o and ozaki-r@n.o, thanks.
https://mail-index.netbsd.org/tech-net/2017/12/18/msg006557.html
2018-01-10 10:56:30 +00:00
ozaki-r
62fd3b8c8a Get rid of unnecessary ifdef for IFT_IEEE80211 2018-01-10 07:34:31 +00:00
ozaki-r
013cd23759 Fix a deadlock on callout_halt of nd6_dad_timer
We must not call callout_halt of nd6_dad_timer with holding nd6_dad_lock because
the lock is taken in nd6_dad_timer. Once softnet_lock goes away, we can pass the
lock to callout_halt, but for now we cannot.
2018-01-10 07:11:38 +00:00
ozaki-r
8c09e9f90b Fix use-after-free of mbuf by ip6flow_create (one more)
XXX need pullup-[678]
2018-01-09 04:41:19 +00:00
ozaki-r
a29d76a139 Fix use-after-free of mbuf by ip6flow_create
This fixes recent failures of some ATF tests such as t_ipsec_tunnel_odd.

XXX need pullup-[678]
2018-01-09 04:21:26 +00:00
knakahara
d88bfb301b Committed debugging logs by mistake, sorry. Revert cryoto.c:r.1.103 and ip6_flow.c:r.1.37. 2018-01-08 23:33:40 +00:00
knakahara
f2516b4ae6 Fix PR kern/52910. Reported and implemented a patch by Sevan Janiyan, thanks. 2018-01-08 23:23:25 +00:00
ozaki-r
3283da7f0f Work around softnet_lock handling
nd6_dad_stoptimer can be called with or without softnet_lock held.
callout_halt has to take softnet_lock depending on the situation.
2017-12-26 02:26:45 +00:00
ozaki-r
d6af4f8075 Fix wrong usage of psref_held
We can't use it for checking if a caller does NOT hold a given target.
If you want to do it you should have psref_not_held or something.
2017-12-25 04:41:48 +00:00
ozaki-r
3bc7c9e607 Add missing curlwp_bindx 2017-12-22 09:53:06 +00:00
knakahara
decfa6a54a fix mbuf leaks. pointed out and suggested by kre@n.o, thanks. 2017-12-18 03:21:44 +00:00
knakahara
5a6bcc75c1 backout wrong fix again, sorry. 2017-12-18 03:20:12 +00:00
knakahara
38abdefc72 Fix pullup'ed mbuf leaks. The match function just requires enough mbuf length.
XXX need pullup-8
2017-12-15 05:01:16 +00:00
knakahara
ca9d7f2f69 backout wrong fix as it causes atf net/ipsec/t_ipsec_l2tp failures. 2017-12-15 04:58:31 +00:00
ozaki-r
bde7231efb Ensure to call if_mcast_op with holding IFNET_LOCK
Note that CARP doesn't deal with IFNET_LOCK yet.
2017-12-15 04:03:46 +00:00
knakahara
e56a093de8 fix pullup'ed mbuf leaks. pointed out by maxv@n.o, thanks.
XXX need pullup-8
2017-12-11 02:17:35 +00:00
maxv
df4b74a91d Fix use-after-free: if m_pullup fails the (freed) mbuf is pushed on the
ip6_pktq queue and re-processed later. Return 1 to say "processed and
freed".
2017-12-10 09:06:46 +00:00
roy
195d1af85f Treat unvalidated addresses as deprecated in rule 3. 2017-12-06 14:17:42 +00:00
knakahara
753ed3406c IFF_RUNNING checking in Rx and Tx processing is unnecessary now.
Because the configs of gif (members of gif_var) are protected by psref(9).
2017-11-27 05:05:50 +00:00
knakahara
493e35e35d preserve gif(4) configs by psref(9) like vlan(4) and l2tp(4).
After Tx side does not use softint, gif(4) can use psref(9) for config
preservation like vlan(4) and l2tp(4).

update locking notes later.
2017-11-27 05:02:22 +00:00
kre
814f99dcb6 Attempt to restore v6 networking. Not 100% certain that these
changes are all that is needed, but they're certainly a big part of it
(especially the ip6_input.c change.)
2017-11-25 13:18:02 +00:00
roy
fbb6c0f8fa Allow local communication over DETACHED addresses.
Allow binding to DETACHED or TENTATIVE addresses as we deny
sending upstream from them anyway.
Prefer non DETACHED or TENTATIVE addresses.
2017-11-24 14:03:25 +00:00
ozaki-r
f9ba03bb1c Fix a race condition of in6_ifinit
in6_ifinit checks the number of IPv6 addresses on a given interface and
if it's zero (i.e., an IPv6 address being assigned to the interface
is the first one), call if_addr_init. However, the actual assignment of
the address (ifa_insert) is out of in6_ifinit. The check and the
assignment must be done atomically.

Fix it by holding in6_ifaddr_lock during in6_ifinit and ifa_insert.
And also add missing pserialize to IFADDR_READER_FOREACH.
2017-11-23 07:09:20 +00:00
ozaki-r
97d0399779 Tweak a condition; we don't need to care ifacount to be negative 2017-11-23 07:06:14 +00:00
ozaki-r
70c2bde852 Remove unnecessary goto because there is no cleanup code to share (NFC) 2017-11-23 07:05:02 +00:00
ozaki-r
9faa031948 Mention IPv6 address selection policy isn't MP-safe yet
Though it's not a problem until a policy is set.
2017-11-20 09:01:20 +00:00
ozaki-r
cead3b8854 Provide macros for softnet_lock and KERNEL_LOCK hiding NET_MPSAFE switch
It reduces C&P codes such as "#ifndef NET_MPSAFE KERNEL_LOCK(1, NULL); ..."
scattered all over the source code and makes it easy to identify remaining
KERNEL_LOCK and/or softnet_lock that are held even if NET_MPSAFE.

No functional change
2017-11-17 07:37:12 +00:00
knakahara
fb23bb2cff Add argument to encapsw->pr_input() instead of m_tag. 2017-11-15 10:42:41 +00:00
ozaki-r
b9e3a5a1e9 Use psref instead of pserialize because that code is sleepable 2017-11-10 07:25:39 +00:00
ozaki-r
1c27f64d6f Fix a deadlock between a route update and lltable
It happens because rtalloc1 is called from lltable with holding
IF_AFDATA_WLOCK.

If a route update is in action, rtalloc1 would wait for its completion with
holding IF_AFDATA_WLOCK. At the same moment, a softint (e.g., arpintr) may try
to take IF_AFDATA_WLOCK and get stuck on it. Unfortunately the stuck softint
prevents the route update from progressing because the route update calls
psref_target_destroy that needs the softint to complete.

A resource allocation graph of the senario looks like this:
    route update =(psref_target_destroy)=> softint => IF_AFDATA_WLOCK
    =(rt_update_wait)=> route update

Fix the deadlock by pulling rtalloc1 out of the lltable codes inside
IF_AFDATA_WLOCK.

Note that the deadlock happens only if NET_MPSAFE is enabled.
2017-11-10 07:24:28 +00:00
ozaki-r
faf7d24046 Remove redundant KASSERTMSG
The function is static, has just one caller and the caller does the same check.
2017-11-10 07:15:32 +00:00
ozaki-r
048933fa32 Fix usages of ipsec_used
If IPsec isn't used, we must go back to the normal path.

PR kern/52659
2017-11-05 07:03:37 +00:00
rjs
01b82b52c9 Make SCTP work when IPSEC is also defined. 2017-10-17 19:23:42 +00:00
ozaki-r
6bf0e671a0 Add missing NULL check
PR kern/52554
2017-10-05 03:42:14 +00:00
ozaki-r
bbda3ec76e Take softnet_lock on pr_input properly if NET_MPSAFE
Currently softnet_lock is taken unnecessarily in some cases, e.g.,
icmp_input and encap4_input from ip_input, or not taken even if needed,
e.g., udp_input and tcp_input from ipsec4_common_input_cb. Fix them.

NFC if NET_MPSAFE is disabled (default).
2017-09-27 10:05:04 +00:00
knakahara
56188c2a5a add lock for percpu route like l2tp(4). 2017-09-21 09:42:03 +00:00
ozaki-r
0092eb7df6 Invalidate rtcache based on a global generation counter
The change introduces a global generation counter that is incremented when any
routes have been added or deleted. When a rtcache caches a rtentry into itself,
it also stores a snapshot of the generation counter. If the snapshot equals to
the global counter, the cache is still valid, otherwise invalidated.

One drawback of the change is that all rtcaches of all protocol families are
invalidated when any routes of any protocol families are added or deleted.
If that matters, we should have separate generation counters based on
protocol families.

This change removes LIST_ENTRY from struct route, which fixes a part of
PR kern/52515.
2017-09-21 07:15:34 +00:00
christos
da66cce8cd explain why in6_setscope fails... 2017-09-17 17:36:06 +00:00
christos
548324cb09 Skip the scope test for loopback addresses in non-loopback interfaces.
While this test is also done in in6_setscope, testing here allows us
to log an error for other callers.
2017-09-17 17:35:10 +00:00
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