Commit Graph

311 Commits

Author SHA1 Message Date
roy d66a17fc6d arp: Validate ARP source hardware address matches Ethernet source
RFC 5227 section 1.1 states that for a DaD ARP probe the sender hardware
address must match the hardware address of the interface sending the
packet.

We can now verify this by checking the mbuf tag PACKET_TAG_ETHERNET_SRC.

This fixes an obsure issue where an old router was sending out bogus
ARP probes.

Thanks to Ryo Shimizu <ryo@nerv.org> for the re-implementation.
2022-11-15 10:47:39 +00:00
roy 7f8cc08460 Revert prior. 2022-11-15 09:13:43 +00:00
roy ef5ec13dab arp: Validate L2 sender hardware address matches ARP probe
RFC 5227 section 1.1 states that for a DaD ARP probe the sender hardware
address must match the hardware address of the interface sending the
packet.

We can now verify this by checking the mbuf packet header.

This fixes an obsure issue where an old router was sending out bogus
ARP probes.
2022-11-14 09:32:21 +00:00
thorpej 63ae4dd2e0 Convert ARP from a legacy netisr to pktqueue. 2022-09-03 01:35:03 +00:00
christos 2143da8717 - Make ALIGNED_POINTER use __alignof(t) instead of sizeof(t). This is more
correct because it works with non-primitive types and provides the ABI
  alignment for the type the compiler will use.
- Remove all the *_HDR_ALIGNMENT macros and asserts
- Replace POINTER_ALIGNED_P with ACCESSIBLE_POINTER which is identical to
  ALIGNED_POINTER, but returns that the pointer is always aligned if the
  CPU supports unaligned accesses.
[ as proposed in tech-kern ]
2021-02-19 14:51:59 +00:00
martin b2f1163792 One more time: backout arp header alignment, now that the alignment
asserted has been aligned to reality.
Also remove unused ARP_HDR_ALIGNED_P macro. Pointed out by roy.
2021-02-16 10:22:52 +00:00
martin aee51c4b29 Undo previous backout: alignment is needed here.
The reason for the previous backout was a misunderstanding (POINTER_ALIGNED_P
was broken, but the assertion fired even after it got fixed).
2021-02-16 05:44:13 +00:00
christos 9a1851622c Undo previous; POINTER_ALIGNED_P was broken. 2021-02-15 19:49:17 +00:00
christos 356b4fcb30 put back alignment (reported by martin@) 2021-02-15 19:19:29 +00:00
christos 9183889817 - centralize header align and pullup into a single inline function
- use a single macro to align pointers and expose the alignment, instead
  of hard-coding 3 in 1/2 the macros.
- fix an issue in the ipv6 lt2p where it was aligning for ipv4 and pulling
  for ipv6.
2021-02-14 20:58:34 +00:00
roy 2a093b6406 if_arp: Just KASSERT that arphrd is aligned
While here improve readability of checking ARP IEEE1394 matches interface.
2021-02-14 19:47:16 +00:00
roy cb6917aa0d Prior alignment fixes should not use an offset 2021-02-13 13:00:16 +00:00
roy dd39d07da7 if_arp: Ensure that arphdr is aligned 2021-02-13 07:57:09 +00:00
yamt 113b5fa6d9 arp: Plug an mbuf leak 2021-02-02 10:48:33 +00:00
roy e53a363e2b Implement RFC 7048, making Neighbor Unreachability Detection less impatient
RFC 7048 Section 3 says in the UNREACHABLE state packets continue to be
sent to the link-layer address and then backoff exponentially.
We adjust this slightly and move to the INCOMPLETE state after
`nd_mmaxtries` probes and then start backing off.

This results in simpler code whilst providing a more robust model which
doubles the time to failure over what we did before.
We don't want to be back to the old ARP model where no unreachability
errors are returned because very few applications would look at
unreachability hints provided such as ND_LLINFO_UNREACHABLE or RTM_MISS.
2020-09-15 10:05:36 +00:00
roy 20c15691a3 nd: Name l3addr union of llentry and use in-place of nd_addr.
Probably makes more sense and makes nd.h less messy.
2020-09-14 15:09:57 +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 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 ae8028f2c4 arp: report RTM_MISS when removing an unresolved entry in the arp table
Otherwise we only get it when renewing and we've sent too many requests.
This mirrors INET6 behaviour.
2020-03-09 17:57:19 +00:00
roy 532e639965 arp: find source address then target address when processing input
This fixes the case where another host having a duplicate ip address
starts using it right away without probing for it's availability.

While here, prefer ifatoia over a strict cast.
2020-01-23 17:27:35 +00:00
thorpej 4541d6828b Remove FDDI support. 2020-01-20 18:38:17 +00:00
thorpej ed469c22d6 Remove Token Ring support. 2020-01-19 20:00:35 +00:00
roy 8e89aa684a ARP: Don't defend ARP probes.
We should let the nature of ARP takes it's course here when our address
is neither tentative nor duplicated.
This allows the host to work with ARP ping, which was broken in r1.279.
2019-10-11 13:32:46 +00:00
ozaki-r 042d1b5f86 Initialize DAD components properly
The original code initialized each component in non-init functions such as
arp_dad_start and nd6_dad_find, conditionally based on a global flag for each.
However, it was racy because the flag and the code around it were not
protected by a lock and could cause a kernel panic at worst.

Fix the issue by initializing the components in bootup as usual.
2019-09-25 09:52:32 +00:00
roy a07ba9f67e inet: 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 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 22:09:02 +00:00
roy aea1c01f20 ARP: change default sysctl entry log_movements to 0
IP address sharing is a thing and shouldn't cause needless diagnostics
by default.
2019-08-30 18:52:00 +00:00
roy fe361a82f3 ARP: remove unused sysctl entry log_unknown_network 2019-08-30 18:48:34 +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 a7ffb47942 Initialize dom_mowner for MBUFTRACE 2019-08-19 03:23:30 +00:00
roy 2e9156b7e4 Introduce rt_addrmsg_src which adds RTA_AUTHOR to the message.
Use this when we notify userland of a duplicate address
and set RTA_AUTHOR to the hardware address of the sender.

While here, match the logging diagnostic of INET6 to the simpler one
of INET so it's consistent.
2019-04-29 16:12:30 +00:00
roy 0fe61e8e0d Move lla_snprintf from if_arp.c to dl_print.c 2019-04-29 16:05:46 +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
roy 441773b2b2 ARP: Enable Address Defence again.
Revert the tentative/duplicated check and test for if it's been broadcast
or not. This reverts r1.245.
2019-04-24 10:20:36 +00:00
maxv 5b040abec8 Replace M_ALIGN and MH_ALIGN by m_align. 2018-12-22 14:28:56 +00:00
ozaki-r 42cd9a0569 Introduce and use ip_dad_enabled() and ip6_dad_enabled() functions 2018-11-29 09:51:20 +00:00
ozaki-r 973496ef18 Avoid double rt_replace_ifa on rtrequest1(RTM_ADD)
Some callers of rtrequest1(RTM_ADD) adjust rt_ifa of an rtentry created by
rtrequest1 that may change rt_ifa (in ifa_rtrequest) with another ifa that is
different from requested one.  It's wasteful and even worse introduces a race
condition.  rtrequest1 should just use a passed ifa as is if a caller hopes so.
2018-10-30 05:54:41 +00:00
maxv 2afab7aa0f static 2018-05-11 13:56:43 +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 f439735471 Add XXX. 2018-04-11 05:38:47 +00:00
maxv 64e951a489 Remove unused mbuf argument from arpcreate() and arplookup(). 2018-04-10 08:41:14 +00:00
ozaki-r f670488b19 Fix a race condition on DAD destructions (again)
The previous fix to DAD timers was wrong; it avoided a use-after-free but
instead introduced a memory leak.  The destruction method had delegated
a destruction of a DAD timer to the timer itself and told that by setting NULL
to dp->dad_ifa.  However, the previous fix made DAD timers do nothing on
the sign.

Fixing the issue with using callout_stop isn't easy.  One approach is to have
a refcount on dp but it introduces extra complexity that we want to avoid.

The new fix falls back to using callout_halt, which was abandoned because of
softnet_lock.  Fortunately now the network stack is protected by KERNEL_LOCK
so we can remove softnet_lock from DAD timers (callout) and use callout_halt
safely.
2018-03-08 06:48:23 +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
ozaki-r e3a4d36d02 Tweak sanity checks
Scheduling a timer of static entries is wrong.
2018-03-06 07:19:03 +00:00
roy 81467f5340 Sprinkle some const. 2018-03-01 14:40:57 +00:00
ozaki-r daf303d013 Avoid a race condition of DAD timer destructions
When we see dp->dad_ifa == NULL, it means that the ifa is being deleted and also
the callout is scheduled again by someone.  We shouldn't rely on a result of
callout_pending to know if the callout is scheduled because it returns false if
the subsequent callout handler is already on the fly.

We have to always delegate the destruction of dp to the subsequent handler
unconditionally if dp->dad_ifa == NULL. Otherwise, the first handler destroys
the dp and the second handler tries to handle destroyed dp.
2018-02-24 07:53:15 +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
maxv 78024c919d Mmh. Add a missing check: if ARP was disabled on the interface, don't
process ARP packets. Otherwise the kernel will add ARP entries even if

	ifconfig wm0 -arp

was entered.
2018-02-13 14:50:28 +00:00
maxv 9f3f1d81a9 Be tougher:
* In arpintr(), don't allow IEEE1394 packets on non-IEEE1394 interfaces.

 * In revarpinput(), kick IEEE1394 packets right away. They are not
   supported.
2018-02-13 10:47:41 +00:00
maxv 66dc46f13b Same change as rev1.258, but this time in revarpinput: use m_pullup. 2018-02-13 10:31:01 +00:00
maxv cc65a52d20 Minor stylistic changes, and use C99 types. 2018-02-13 10:20:50 +00:00