Commit Graph

256 Commits

Author SHA1 Message Date
skrll 3d88d6ec96 Add a little const. NFC. 2022-08-27 08:36:41 +00:00
roy 5ff17943ef route: RTM_MISS now puts the message source address in RTA_AUTHOR
route(8) also reports this.
A userland app could use this to blacklist nodes who probe for machines
that doesn't exist on a subnet / prefix.
2020-03-09 21:20:55 +00:00
roy 5e6231cff4 rtsock: favour ifatoia and ifatoia6 over direct struct casts 2020-02-03 20:34:13 +00:00
thorpej 74f4907c2d Do not reference ifp->if_data directly; use if_export_if_data(). 2020-01-29 04:35:13 +00:00
roy ca19b5765e inet6: Send RTM_MISS when we fail to resolve an address.
Takes the same approach as when adding a new address - we no longer
announce the new lladdr right away but we announce the result.
This will either be RTM_ADD or RTM_MISS.
RTM_DELETE is only sent if we have a lladdr assigned OR gc'ed.

This results in less messages via route(4) and tells us when a new
lladdr has been added (RTM_ADD), changed (RTM_CHANGE), deleted (RTM_DELETED)
or has failed to been resolved (RTM_MISS). The latter case can be
interpreted as unreachable.
2019-09-01 18:54:38 +00:00
roy 508a301f81 rtsock: rework rt_clonedmsg to take a message type and lladdr
We will use this in a future patch to notify userland of lladdr
changes.

XXX pullup -8 -9
2019-08-22 21:14:45 +00:00
ozaki-r 16e3f802dd Don't take softnet_lock in sysctl_rtable
Taking softnet_lock there can cause a locking error with nfs sosend, so we don't.
Having only KERNEL_LOCK is enough because now the routing table is protected by
KERNEL_LOCK that was introduced by the fix for PR 53043.

PR kern/54227 from Paul Ripke
2019-05-27 05:33:48 +00:00
pgoyette aa343ec34c For the rtsock compat code, make sure we create the "oroute" sysctl
tree.  Otherwise a 5.2 version of getifaddrs(2) gets errors.

This makes the 5.2 version of ifconfig(8) behave the same on both
NetBSD-8 and -current.  HOWEVER, both of them print nothing (for
``ifconfig -l'' command) so there's still a bug somewhere.

As reported originally by der Mouse.
2019-04-29 05:42:09 +00:00
pgoyette 8c2f80f160 Rename the MODULE_*_HOOK() macros to MODULE_HOOK_*() as briefly
discussed on irc.

NFCI intended.

Ride the earlier kernel bump - it;s getting crowded.
2019-03-01 11:06:55 +00:00
ozaki-r fa40dfcf97 Protect sysctl_rtable with KERNEL_LOCK and softnet_lock
In the function the routing table could be accessed without any locks, which was
unsafe.  Actually, on netbsd-7, a kernel panic happened(*).  The situation of
locking hasn't changed since netbsd-7 so we still need to hold the big locks on
-current (and netbsd-8) too.

Note that if NET_MPSAFE is enabled, the routing table is protected by its own
lock and we don't need the locks.

Reported and tested on netbsd-7 by sborrill@

(*) http://mail-index.netbsd.org/tech-net/2018/11/08/msg007153.html
2019-02-27 04:03:06 +00:00
pgoyette c1283e70fa Normalize all the compat hooks' names to the form
<subsystem>_<function>_<version>_hook

NFCI

XXX Note that although this introduces a change in the kernel-to-
XXX module interface, we are NOT bumping the kernel version number.
XXX We will bump the version number once the interface stabilizes.
2019-01-29 09:28:50 +00:00
pgoyette d91f98a871 Merge the [pgoyette-compat] branch 2019-01-27 02:08:33 +00:00
maxv f0cdb4272b Fix kernel info leak. There are 2 bytes of padding in struct if_msghdr.
[  944.607323] kleak: Possible leak in copyout: [len=176, leaked=2]
[  944.617335] #0 0xffffffff80b7c44a in kleak_note <netbsd>
[  944.627332] #1 0xffffffff80b7c4ca in kleak_copyout <netbsd>
[  944.627332] #2 0xffffffff80c91698 in sysctl_iflist_if <netbsd>
[  944.637336] #3 0xffffffff80c91d3c in sysctl_iflist <netbsd>
[  944.647343] #4 0xffffffff80c93855 in sysctl_rtable <netbsd>
[  944.647343] #5 0xffffffff80b5b328 in sysctl_dispatch <netbsd>
[  944.657346] #6 0xffffffff80b5b62e in sys___sysctl <netbsd>
[  944.667354] #7 0xffffffff8025ab3c in sy_call <netbsd>
[  944.667354] #8 0xffffffff8025ad6e in sy_invoke <netbsd>
[  944.677365] #9 0xffffffff8025adf4 in syscall <netbsd>
2018-11-13 07:45:43 +00:00
maxv ec3696147d Set unused pr_input field to NULL, discussed on tech-net@. 2018-09-07 06:08:16 +00:00
maxv e8e58773e9 Fix buffer overflow, detected by kASan.
ifconfig gif0 create
	ifconfig gif0 up

[   50.682919] kASan: Unauthorized Access In 0xffffffff80f22655: Addr 0xffffffff81b997a0 [8 bytes, read]
[   50.682919] #0 0xffffffff8021ce6a in kasan_memcpy <netbsd>
[   50.692999] #1 0xffffffff80f22655 in m_copyback_internal <netbsd>
[   50.692999] #2 0xffffffff80f22e81 in m_copyback <netbsd>
[   50.692999] #3 0xffffffff8103109a in rt_msg1 <netbsd>
[   50.692999] #4 0xffffffff8159109a in compat_70_rt_newaddrmsg1 <netbsd>
[   50.692999] #5 0xffffffff81031b0f in rt_newaddrmsg <netbsd>
[   50.692999] #6 0xffffffff8102c35e in rt_ifa_addlocal <netbsd>
[   50.692999] #7 0xffffffff80a5287c in in6_update_ifa1 <netbsd>
[   50.692999] #8 0xffffffff80a54149 in in6_update_ifa <netbsd>
[   50.692999] #9 0xffffffff80a59176 in in6_ifattach <netbsd>
[   50.692999] #10 0xffffffff80a56dd4 in in6_if_up <netbsd>
[   50.692999] #11 0xffffffff80fc5cb8 in if_up_locked <netbsd>
[   50.703622] #12 0xffffffff80fcc4c1 in ifioctl_common <netbsd>
[   50.703622] #13 0xffffffff80fde694 in gif_ioctl <netbsd>
[   50.703622] #14 0xffffffff80fcdb1f in doifioctl <netbsd>
2018-08-31 15:15:23 +00:00
ozaki-r 9a87af0fbd Fix a deadlock (rt_free vs. route_intr on rt_so_mtx)
It occurs only if NET_MPSAFE is enabled.
2018-04-25 03:49:57 +00:00
ozaki-r 55b7c5b86a Resolve tangled lock dependencies in route.c
This change sweeps remaining lock decisions based on if locked or not by moving
utility functions of rtentry updates from rtsock.c and ensuring holding the
rt_lock.  It also improves the atomicity of a update of a rtentry.
2018-04-12 04:38:13 +00:00
roy 03ee279e62 rtsock: log dropped messages that we cannot report to userland 2018-03-19 16:34:48 +00:00
ozaki-r 488f641d4a Fix another deadlock
When waiting for a route update to finish, a waiter has to release its reference
to the route to avoid a deadlock. Because a updater tries to wait for references
to a target route (except for a reference by the updater itself) to be released.
2018-01-25 03:09:05 +00:00
ozaki-r e1861756c2 Release rt_so_mtx on updating a rtentry to avoid a deadlock with route_intr
The deadlock happened only if NET_MPSAFE on.
2018-01-19 05:19:29 +00:00
ozaki-r 927ca71150 Fix compile error (may be used uninitialized)
Hmm, __noinline had hidden this error.
2017-12-18 05:35:36 +00:00
ozaki-r 913c95a630 Revert "Spinkle __noinline to some non-performance-sensitive functions for debugging"
We should do this kind of tweaks for debugging just locally and personally.

Requested by christos@
2017-12-18 05:35:01 +00:00
ozaki-r bbead959c0 Fix a bug that tries to psref_acquire ifa with a psref used before
This fixes ATF tests that started to fail by a recent change to psref.
2017-12-14 05:48:59 +00:00
ozaki-r 5b3be63e24 Protect ifp returned from route_output_get_ifa surely
An ifp returned from route_output_get_ifa was supposed to be protected
by a returned ifa; if the ifa belongs to ifp, holding the ifa prevents
the ifp from being freed. However route_output_get_ifa can return an ifp
to which a returned ifa doesn't belong. So we need to take a reference
to a returning ifp separately.
2017-12-14 05:47:45 +00:00
ozaki-r 45c59e4760 Spinkle __noinline to some non-performance-sensitive functions for debugging 2017-12-14 05:43:14 +00:00
christos 0eeb9c747d Avoid using a zero family mask. 2017-11-19 18:49:51 +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
ozaki-r 4cfe7ee520 Use a dedicated mutex for rt_rawcb instead of softnet_lock if NET_MPSAFE 2017-09-25 01:57:54 +00:00
ozaki-r 475ed81624 Fix race condition on the rawcb list shared by rtsock and keysock
keysock now protects itself by its own mutex, which means that
the rawcb list is protected by two different mutexes (keysock's one
and softnet_lock for rtsock), of course it's useless.

Fix the situation by having a discrete rawcb list for each.
2017-09-25 01:56:22 +00:00
christos 7700e78cab put the code that returns the sizeof the socket by family in one place. 2017-07-01 16:59:12 +00:00
christos 5ca98f2167 Avoid DIAGNOSTIC warning with previous fix and simplify it (don't require
memory alloc/free).
2017-06-30 18:28:31 +00:00
ozaki-r f0a30a5d8f Restore the original length of a sockaddr for netmask
route(8) passes a sockaddr for netmask that is truncated with its
prefixlen. However the kernel basically doesn't expect such format
and may read beyond the data. So restore the original length of the
the data at the beginning of the kernel for the rest components.

Failures of ATF tests such as route_flags_blackhole6 should
be fixed.
2017-06-30 09:11:22 +00:00
ozaki-r da803ed70d Restore ARP/NDP entries to route show and netstat -r
Requested by dyoung@ some time ago
2017-06-28 04:14:53 +00:00
ozaki-r 59bb97369e Drop RTF_UP from a routing message of a deleted ARP/NDP entry 2017-06-26 06:59:56 +00:00
ozaki-r 61f13eaa6e Fix ifdef; care about a case w/ INET6 and w/o INET 2017-06-26 06:58:42 +00:00
ozaki-r 057fd82362 Improve backward compatibility of (fake) routing messages on adding an ARP/NDP entry
A message originally included only DST and GATEWAY. Restore it.
2017-06-26 03:16:28 +00:00
ozaki-r 60f1157fbd Fix usage of routing messages on arp -d and ndp -d
It didn't work as we expected; we should set RTA_GATEWAY not
RTA_IFP on RTM_GET to return an if_index and the kernel should
use it on RTM_DELETE.
2017-06-26 03:13:40 +00:00
ozaki-r c1eb4e0fd2 Tweak lltable_sysctl_dumparp
- Rename lltable_sysctl_dumparp to lltable_sysctl_dump
  because it's not only for ARP
- Enable it not only for INET but also for INET6
2017-06-23 05:46:10 +00:00
ozaki-r 1bc575f10c Fix build of kernels without both INET and INET6 2017-06-23 04:27:55 +00:00
ozaki-r a97e9b99d4 Purge L2 caches on changing an interface of a route
The change addresses situations similar to PR 51179.
2017-06-22 09:58:04 +00:00
ozaki-r 78cfd34100 Drop RTF_CONNECTED from a result of RTM_GET for ARP/NDP entries
ARP/NDP entries aren't connected routes.

Reported by ryo@
2017-06-16 02:26:17 +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
ozaki-r ca2cf44170 Simplify
We can assume that rt_ifp is always non-NULL.
2017-06-15 02:51:45 +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
roy 5135ab1948 Add RO_MSGFILTER socket option to PF_ROUTE to filter out
un-wanted route(4) messages.

Inspired by the ROUTE_MSGFILTER equivalent in OpenBSD,
but with an API which allows the full range of potential message types.
2017-04-11 13:55:54 +00:00
ozaki-r f4510b11c6 Forbit installing a route which its gateway is unreachable
This change needs a tweak in route_output_change to unbreak route
change commands (e.g., route change -inet6 default -reject).

PR kern/52077 (s-yamaguchi@IIJ and ozaki-r@)
2017-03-24 03:45:02 +00:00
ozaki-r 2b5b2086c8 Tweak and KNF some functions 2017-03-22 07:14:18 +00:00
ozaki-r 15ca1985b9 Add missing NULL check
Fix PR kern/52083
2017-03-17 10:05:02 +00:00
ozaki-r 6e669021a2 Add missing pserialize_read_exit
Pointed out by riastradh@
2017-03-14 09:39:28 +00:00
ozaki-r 0eaf4e5356 Use if_acquire and if_release instead of using psref API directly
- Provide if_release for consistency to if_acquire
- Use if_acquire and if_release for ifp iterations
- Make ifnet_psref_class static
2017-03-14 09:03:08 +00:00