Commit Graph

146 Commits

Author SHA1 Message Date
msaitoh 53636c3c61 s/referece/reference/ in comment. 2019-12-27 10:17:56 +00:00
ozaki-r 760452d22f Make panic messages more informative 2019-09-25 09:53:37 +00:00
roy 4af7afb834 rtsock: Route address message simplification
Rename rt_newaddrmsg to rt_addrmsg_rt.
Add rt_addrmsg which drops the error and route arguments which are only
needed by one caller.
2019-04-29 11:57:22 +00:00
ozaki-r 676214c5ed Don't call find_pfxlist_reachable_router, which may sleep, in a pserialize read section
Found by knakahara@
2018-08-14 01:10:58 +00:00
maxv 9a39ca57f2 Style. 2018-05-19 08:22:58 +00:00
maxv ae766c8de0 Add missing m_put_rcvif_psref. 2018-05-18 21:03:33 +00:00
maxv 86ac125b49 Remove now unused net_osdep.h includes, the other BSDs did the same. 2018-05-01 07:21:39 +00:00
maxv 906d782918 Remove nullcheck, m is not allowed to be null. 2018-04-24 08:22:16 +00:00
maxv 3e02f4fab8 Remove the M_AUTHIPDGM flag. It is equivalent to M_AUTHIPHDR, both
are set in IPsec-AH, and they are always handled together.
2018-04-24 08:07:05 +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
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
ozaki-r 752d3b8752 Remove unnecessary NULL check 2017-03-14 04:21:38 +00:00
msaitoh f71865e18b Add missing opt_net_mpsafe.h. 2017-03-03 06:27:20 +00:00
ozaki-r fcf7d70e3a Get rid of unnecessary splsoftnet 2017-02-22 07:05:47 +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
christos 35561f6b22 ip6_sprintf -> IN6_PRINT so that we pass the size. 2017-01-16 15:44:46 +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
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
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 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 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 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
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
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 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 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 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 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
ozaki-r c7e18ccbde Protect if_byindex by pserialize 2016-06-15 06:01:21 +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 a79dfa5db0 Sweep unnecessary route.h inclusions 2016-04-26 08:44:44 +00:00
ozaki-r 322b6a238d Sweep unncessary radix.h inclusions 2016-04-11 08:56:16 +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 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 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 91afbd53fe Use satosin6 instead of its own macro 2015-10-05 04:15:42 +00:00
ozaki-r b635aa0309 Change 0 to NULL for rtrequest's last argument (struct rtentry **ret_nrt) 2015-08-24 09:45:29 +00:00
ozaki-r 55140c1926 Use time_uptime instead of time_second to avoid time leaps
Some codes in sys/net* use time_second to manage time periods such as
cache expirations. However, time_second doesn't increase monotonically
and can leap by say settimeofday(2) according to time_second(9). We
should use time_uptime instead of it to avoid such time leaps.

This change replaces time_second with time_uptime. Additionally it
converts a time based on time_uptime to a time based on time_second
when the kernel passes the time to userland programs that expect
the latter, and vice versa.

Note that we shouldn't leak time_uptime to other hosts over the
netowrk. My investigation shows there is no such leak:
http://mail-index.netbsd.org/tech-net/2015/08/06/msg005332.html

Discussed on tech-kern and tech-net.
2015-08-07 08:11:33 +00:00
ozaki-r 9eae87d0c8 Reform use of rt_refcnt
rt_refcnt of rtentry was used in bad manners, for example, direct rt_refcnt++
and rt_refcnt-- outside route.c, "rt->rt_refcnt++; rtfree(rt);" idiom, and
touching rt after rt->rt_refcnt--.

These abuses seem to be needed because rt_refcnt manages only references
between rtentry and doesn't take care of references during packet processing
(IOW references from local variables). In order to reduce the above abuses,
the latter cases should be counted by rt_refcnt as well as the former cases.

This change improves consistency of use of rt_refcnt:
- rtentry is always accessed with rt_refcnt incremented
- rtentry's rt_refcnt is decremented after use (rtfree is always used instead
  of rt_refcnt--)
- functions returning rtentry increment its rt_refcnt (and caller rtfree it)

Note that rt_refcnt prevents rtentry from being freed but doesn't prevent
rtentry from being updated. Toward MP-safe, we need to provide another
protection for rtentry, e.g., locks. (Or introduce a better data structure
allowing concurrent readers during updates.)
2015-07-17 02:21:08 +00:00
ozaki-r eeab7eecc6 Fix nd6_numroutes counting
nd6_numroutes is intended to be incremented when a route is added via RA
and decremented when a RA route is deleted. However, a decrement of a RA
route was skipped when there remained references to the RA route.
2015-06-30 06:42:06 +00:00
roy 9cdef53c9c Mitigate Local Denial of Service with IPv6 Router Advertisements and
log attack attempts.

Fixes CVE-2015-2923, taken from FreeBSD.
2015-05-02 14:28:30 +00:00
roy 1d0df6e404 Rename nd6_rtmsg() to rt_newmsg() and move into the generic routing code
as it's not IPv6 specific and will be used elsewhere.
2015-02-25 12:45:34 +00:00