Commit Graph

35 Commits

Author SHA1 Message Date
yamt 34172d955e Make arp have its own mowner
This helped me to debug mbuf leaks in arp.
(if_arp.c rev. 1.298)
2022-11-19 08:00:51 +00:00
andvar cdc507f0d2 fix various typos in comment, documentation and log messages. 2022-05-24 20:50:17 +00:00
roy caccb5729a ARP: Use ND rather than our own.
This brings the benefit of Neighbour Unreachability Detection which is
something ARP sorely lacks.

The new timings mirror those of IPv6 and are adjustable via sysctl(8).
Unlike IPv6 ND, these are global and not per interface.
2020-09-11 15:16:00 +00:00
roy a300b3334b if_llatbl.c: adjust for nd changes 2020-09-11 15:01:26 +00:00
ozaki-r 760452d22f Make panic messages more informative 2019-09-25 09:53:37 +00:00
kre 861218d79d UPdate previous so that there is no unused (but assigned) variable
left when there is no ARP.   Thanks gcc!
2018-07-10 19:30:37 +00:00
kre 0eb6700350 Avoid attempting to call arp related functions if there is no
arp in the kernel.
2018-07-10 11:00:40 +00:00
ozaki-r 8d19d392bf Don't overwrite an existing llentry on RTM_ADD to avoid race conditions
Reported and tested by christos@
2018-07-10 01:23:13 +00:00
nonaka 0ee3d110d2 It is necessary to set wall time instead of monotonic time to rmx_expire. 2018-06-05 01:25:59 +00:00
ozaki-r f502c3b602 Use pool(9) for llentry allocations
llentry is easy to be leaked and pool suits for it because pool is usable to
detect leaks.

Also sweep unnecessary wrappers for llentry, in_llentry and in6_llentry.
2018-03-06 07:27:55 +00:00
ozaki-r 9891458159 Fix memory leaks on arp -d and ndp -d for static entries
We have to delete entries on in_lltable_delete and in6_lltable_delete
unconditionally.  Note that we don't need to worry about LLE_IFADDR because
there is no such entries now.
2018-03-06 07:25:27 +00:00
ozaki-r 0e7f921617 Fix reference leaks of llentry
callout_reset and callout_halt can cancel a pending callout without telling us.
Detect a cancel and remove a reference by using callout_pending and
callout_stop (it's a bit tricy though, we can detect it).

While here, we can remove remaining abuses of mutex_owned for softnet_lock.
2018-03-06 07:24:01 +00:00
maxv 0c95a1b211 Remove IFF_STATICARP, we don't support this, and the code is useless in its
current form.

ok ozaki-r@
2018-02-14 14:15:53 +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 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 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 3659ef5665 Purge all related L2 caches on removing a route
The change addresses situations similar to PR 51179.
2017-06-22 09:56:48 +00:00
msaitoh f71865e18b Add missing opt_net_mpsafe.h. 2017-03-03 06:27:20 +00:00
christos 35561f6b22 ip6_sprintf -> IN6_PRINT so that we pass the size. 2017-01-16 15:44:46 +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
roy 103ec7fade Mark arprequest static and introduce arpannounce so that gratuitous
ARP requests are only send from valid addresses.
2016-10-11 12:32:30 +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 59c50f3fa9 Fill rtm_addrs properly
This fixes that arp(8) on some archs (only 32bit?) shows "(weird)"
for every entries unexpectedly.

Confirmed on evbarm by ryo@ and i386 by me.
2016-04-06 08:45:46 +00:00
ozaki-r 25d196eae4 Fill sdl with sockaddr_dl_init
And add an assertion of if_addrlen and ll_addr.

From christos@
2016-04-06 07:59:26 +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 1926a64c9e Remove workaround for GATEWAY
The workaround was introduced because lltable/llentry uses rwlock
but it may be executed in hardware interrupt due to fast forward.
Now we don't run fast forward in hardware interrupt anymore, so
we can remove the workaround.
2016-02-16 01:31:26 +00:00
ozaki-r f373fa78e6 Fix build dependency of if_llatbl.c
if_llatbl.c is required if inet or inet6 is enabled. Depending on ether
doesn't suit for NDP case.
2015-11-26 01:41:20 +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 e4a5751875 Stop using softnet_lock (fix possible deadlock)
Using softnet_lock for mutual exclusion between lltable_free and
arptimer was wrong and had an issue causing a deadlock between
them;  lltable_free waits arptimer completion by calling
callout_halt with softnet_lock that is held in arptimer, however
lltable_free also holds llentry's lock that is also held in
arptimer so arptimer never obtain the lock and both never go
forward eventually.  We have to pass llentry's lock to
callout_halt instead.
2015-10-20 07:35:15 +00:00
ozaki-r 99284d7cc5 Make GATEWAY (fastforward) work again
With GATEWAY (fastforward), the whole forwarding processing runs in
hardware interrupt context. So we cannot use rwlock for lltable and
llentry in that case.

This change replaces rwlock with mutex(IPL_NET) for lltable and llentry
when GATEWAY is enabled. We need to tweak locking only around rtree
in lltable_free. Other than that, what we need to do is to change macros
for locks.

I hope fastforward runs in softint some day in the future...
2015-09-30 07:12:32 +00:00
ozaki-r fc47734756 Tweak mutex_enter(softnet_lock) position
The previous code took locks the following order:
- LLE_WLOCKs
- mutex_enter(softnet_lock)
- LLE_WUNLOCKs
- mutex_exit(softnet_lock)

This fix moves mutex_enter(softnet_lock) before LLE_WLOCKs.
2015-09-28 07:55:26 +00:00
ozaki-r 30818f7132 Fix race condition on la_rt between lltable_free and other places touching la_rt
We have to touch la_rt always with holding softnet_lock. And we have to
use callout_halt with softnet_lock instead of callout_stop for
la_timer (arptimer) because arptimer holds softnet_lock inside it.

This fix may solve a kernel panic christos@ encountered.
2015-09-09 01:26:50 +00:00
pooka 1d2b607cca #if __NetBSD__ -> #if defined(__NetBSD__) 2015-08-31 12:57:45 +00:00
ozaki-r 8997ac8f09 Replace ARP cache (llinfo) with lltable/llentry
Highlights of the change are:
- Use llentry instead of llinfo to manage ARP caches
  - ARP specific data are stored in the hashed list
    of an interface instead of the global list (llinfo_arp)
- Fine-grain locking on llentry
- arptimer (callout) per ARP cache
  - the global timer callout with the big locks can be
    removed (though softnet_lock is still required for now)
- net.inet.arp.prune is now obsoleted
  - it was the interval of the global timer callout
- net.inet.arp.refresh is now obsoleted
  - it was a parameter that prevents expiration of active caches
  - Removed to simplify the timer logic, but we may be able to
    restore the feature if really needed

Proposed on tech-kern and tech-net.
2015-08-31 08:05:20 +00:00
ozaki-r 85e26631cc Import lltable/llentry from FreeBSD
lltable/llentry is new L2 nexthop cache data structures that
store caches in each interface (struct ifnet). It is imported
to replace the current ARP cache implementation that uses the
global list with the big kernel lock, and provide fine-grain
locking for cache operations. It is also planned to replace
NDP caches.

The code is based on FreeBSD's lltable/llentry as of r286629
and tweaked for NetBSD.
2015-08-31 07:56:58 +00:00