Commit Graph

273 Commits

Author SHA1 Message Date
mrg
85303579aa add or adjust fallthru comments. 2019-02-04 10:09:31 +00:00
msaitoh
7b54e0066d Add SIOCSETHERCAP. It's used to change ec_capenable. 2018-12-21 08:58:08 +00:00
maxv
5c98710094 Remove the 't' argument from m_tag_find(). 2018-11-15 10:23:55 +00:00
yamaguchi
70db832747 Use ether_lookup_multi() instead of the macro
ok ozaki-r@
2018-06-14 07:54:57 +00:00
ozaki-r
8434fb2752 Check if ether_ifdetach is called without INET_LOCK 2018-06-12 07:12:35 +00:00
maxv
375907a025 Remove an XXX of mine, actually it's fine. While here also remove a
misleading printf.
2018-05-29 16:24:34 +00:00
maxv
4b9322a057 Replace KASSERT by m_pullup. While the ethernet header is always there
when the packet was received on a physical interface, it may not be if
the packet was received over L2TP/EtherIP.

In particular, if the inner ethernet header ends up on two separate IP
fragments. Here the KASSERT is triggered, and on !DIAGNOSTIC we corrupt
memory.

Note that this is a widespread problem: a lot of L2 code was written with
the assumption that "most" headers are present in the first mbuf.
Obviously, that's not true if L2 encapsulation is being used.
2018-05-29 08:24:59 +00:00
maxv
0be2ad1a12 Replace
m_copym(m, 0, M_COPYALL, M_DONTWAIT)
by
	m_copypacket(m, M_DONTWAIT)
when it is clear that we are copying a packet (that has M_PKTHDR) and not
a raw mbuf chain.
2018-05-09 06:35:10 +00:00
maxv
37402c2ad5 Remove references to m_copy in comments. 2018-04-29 07:13:10 +00:00
maxv
ecb801f971 m_copy -> m_copym 2018-04-26 19:56:55 +00:00
maxv
d2e2e0f086 Replace KASSERTMSG by a real check. L2 encapsulation protocols (at least
L2TP) don't ensure the LLC is there, and in !DIAGNOSTIC configurations
m_copydata will crash. Tested with L2TP.
2018-04-09 16:14:11 +00:00
maxv
00a2f9f8be Add KASSERT. The input point expects struct ether_header to be there.
Now, I'm wondering whether it can be triggered by L2 encapsulation
protocols - they may not provide a contiguous area.
2018-04-09 11:35:22 +00:00
maxv
ce5bc9fcd8 Minor stylistic changes, add XXX and fix typo. No functional change. 2018-04-09 11:05:59 +00:00
maxv
995aacb845 Make the arpresolve branch more readable, fix typo, fix XXX (which I
added), add missing pserialize_read_exit (which I forgot).
2018-02-13 15:21:59 +00:00
maxv
b46d58304b Remove KERNEL_LOCK around the MPLS code. It's not needed, since we're only
touching the tag of the mbuf - the tag belongs only to the mbuf, and the
mbuf is not shared.

ok knakahara@
2018-02-13 10:50:38 +00:00
maxv
70018dfa34 Fix typo, and add a comment about MPLS. 2018-02-12 12:17:38 +00:00
nakayama
48608812ca Fix inverted logic. 2018-01-19 12:31:27 +00:00
maxv
ac53d0edb7 Style, and fix a bug in the AppleTalk path: we're doing
M_PREPEND(M_DONTWAIT), but we forgot to NULL-check the mbuf afterwards.
2018-01-15 14:00:34 +00:00
maxv
9cdd75561f Fix two bugs in altq_etherclassify. When scanning the mbuf chain we need
to make sure that m_next is not NULL, otherwise NULL deref. After that,
we must not touch m->m_pkthdr, given that 'm' may not be the first mbuf
of the chain anymore.

Declare mtop, and add a KASSERT to make sure it has M_PKTHDR set.
2018-01-15 13:14:18 +00:00
maxv
5a476cc8db Fix a bug in the VLAN path: there's an inverted logic, the mbuf needs to
be bigger than struct ether_vlan_header, not smaller.

Meanwhile add a KASSERT in the LLC path.
2018-01-15 12:17:05 +00:00
maxv
35a7dddc87 Style, make the code more readable, and add a KASSERT (we expect the mbuf
to have M_PKTHDR set).
2018-01-15 11:57:27 +00:00
maxv
6cc48dd1f8 Several fixes:
- Style and typos
 - Use kmem_zalloc, in case there is a padding between the fields of
   the structures
 - Use ETHER_ADDR_LEN instead of a hard-coded '6'
 - kmem_alloc(KM_SLEEP) can't fail
 - Simplify ether_aton_r
 - Use mutex_obj_free, not to leak memory
2018-01-15 10:27:51 +00:00
maxv
0c81f027ad Fix the net.ether.multicast sysctl. If there is no multicast address
don't kmem_alloc(0) (which panics the kernel), and if the number of
multicast addresses has decreased don't copyout uninitialized kernel
data.
2018-01-15 07:59:48 +00:00
maxv
1487166d45 style 2017-12-09 10:51:30 +00:00
maxv
4be9fe9d79 Make sure we have an llc structure in the packet, and don't read past the
end of the mbuf if we don't. I'm wondering whether we should not pull up
instead, but whatever.
2017-12-09 10:19:42 +00:00
ozaki-r
3386db3a55 Use kmem_alloc instead of kmem_intr_alloc in ether_addmulti
ether_addmulti is now not called in softint thanks to wqinput that
pulled input routines of ICMP out of softint.
2017-12-06 04:00:07 +00:00
msaitoh
df22004151 - Modify ether_ioctl() for readability. No functional change.
- KNF
2017-11-22 04:27:57 +00:00
ozaki-r
ab3cd725ea Unify IFEF_*_MPSAFE into IFEF_MPSAFE
There are already two flags for if_output and if_start, however, it seems such
MPSAFE flags are eventually needed for all if_XXX operations. Having discrete
flags for each operation is wasteful of if_extflags bits. So let's unify
the flags into one: IFEF_MPSAFE.

Fortunately IFEF_*_MPSAFE flags have never been included in any releases, so
we can change them without breaking backward compatibility of the releases
(though the kernel version of -current should be bumped).

Note that if an interface have both MP-safe and non-MP-safe operations at a
time, we have to set the IFEF_MPSAFE flag and let callees of non-MP-safe
opeartions take the kernel lock.

Proposed on tech-kern@ and tech-net@
2017-11-16 03:07:17 +00:00
msaitoh
6e5de68e15 Use macro(ETHER_LOCK() and ETHER_UNLOCK()). No functional change. 2017-10-26 09:41:15 +00:00
knakahara
a6e88d7809 VLAN ID uses pkthdr instead of mtag now. Contributed by s-yamaguchi@IIJ.
I just commit by proxy. Reviewed by joerg@n.o and christos@n.o, thanks.
See http://mail-index.netbsd.org/tech-net/2017/09/26/msg006459.html

XXX need pullup to -8 branch
2017-09-26 07:42:05 +00:00
para
e3902ee896 kmem_intr_free kmem_intr_[z]alloced memory
the underlying pools are the same but api-wise those should match
2017-07-23 10:55:00 +00:00
ozaki-r
31d0775c4c Revert "Make sure to hold if_ioctl_lock when calling ifp->if_ioctl"
As per pgoyette@ and riastradh@ requests; we shouldn't decide to
hold a lock based on if the lock is held or not.
2017-04-06 03:54:59 +00:00
ozaki-r
bd2b5ee8eb Make sure to hold if_ioctl_lock when calling ifp->if_ioctl
Unfortunately callers of ifp->if_ioctl (if_addr_init, if_flags_set
and if_mcast_op) may or may not hold if_ioctl_lock, so we have to
hold the lock only if it's not held.
2017-04-05 03:47:51 +00:00
ozaki-r
d3cc86362c Remove KERNEL_LOCK for arpresolve in ether_output
Because arpresolve should be already MP-safe.
2017-03-24 09:22:46 +00:00
ozaki-r
1f29833ec6 Sweep unnecessary malloc.h inclusions 2017-02-21 03:59:31 +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
skrll
fdfc876dd7 Remove redundant splnet/splx calls - ec_lock is IPL_NET. 2017-02-12 09:36:05 +00:00
maxv
a2073096ee Don't forget to free the mbuf when we decide not to reply to an ARP
request. This obviously is a terrible bug, since it allows a remote sender
to DoS the system with specially-crafted requests sent in a loop.
2017-01-24 18:37:20 +00:00
msaitoh
98ff4b5f9f Fix a bug that the parent interface's callback wasn't called when the vlan
interface is configured. A callback function uses VLAN_ATTACHED() function
which check ec->ec_nvlans, the value should be incremented before calling the
callback. This bug was added in if_vlan.c rev. 1.83 (2015/11/19).
2017-01-13 06:11:56 +00:00
ozaki-r
a94a205118 Enable some sysctl knobs on rump kernels for ifmcstat 2017-01-10 05:42:34 +00:00
ozaki-r
9ac3cb6dea Replace adaptive mutex for ethercom with spin one
Unfortunately even wm(4) doesn't allow adaptive mutex because wm(4)
tries to hold it with holding its own spin mutex.
2017-01-10 05:40:59 +00:00
ozaki-r
0e2548254a Use kmem_intr_alloc instead of kmem_alloc
ether_addmulti still can be called in softint.

Fix PR kern/51755
2016-12-31 15:07:02 +00:00
ozaki-r
bf5ce79b5b Protect ec_multi* with mutex
The data can be accessed from sysctl, ioctl, interface watchdog
(if_slowtimo) and interrupt handlers. We need to protect the data against
parallel accesses from them.

Currently the mutex is applied to some drivers, we need to apply it to all
drivers in the future.

Note that the mutex is adaptive one for ease of implementation but some
drivers access the data in interrupt context so we cannot apply the mutex
to every drivers as is. We have two options: one is to replace the mutex
with a spin one, which requires some additional works (see
ether_multicast_sysctl), and the other is to modify the drivers to access
the data not in interrupt context somehow.
2016-12-28 07:32:16 +00:00
ozaki-r
b79bd95d27 Use ether_ifattach in carp_clone_create instead of C&P code
carp_clone_destroy calls ether_ifdetach so not calling ether_ifattach is
inconsistent. If we add something pair of initialization and destruction
to ether_ifattach and ether_ifdetach (e.g., mutex_init/mutex_destroy),
ether_ifdetach of carp_clone_destroy won't work. So use ether_ifattach.

In order to do so, make ether_ifattach accept the 2nd argument (lla) as
NULL to allow carp to initialize its link level address by itself.
2016-12-28 07:26:24 +00:00
ozaki-r
3be3142886 Don't hold global locks if NET_MPSAFE is enabled
If NET_MPSAFE is enabled, don't hold KERNEL_LOCK and softnet_lock in
part of the network stack such as IP forwarding paths. The aim of the
change is to make it easy to test the network stack without the locks
and reduce our local diffs.

By default (i.e., if NET_MPSAFE isn't enabled), the locks are held
as they used to be.

Reviewed by knakahara@
2016-10-18 07:30:30 +00:00
ozaki-r
8f4376cb6f Fix race condition on ifqueue used by traditional netisr
If a underlying network device driver supports MSI/MSI-X, RX interrupts
can be delivered to arbitrary CPUs. This means that Layer 2 subroutines
such as ether_input (softint) and subsequent Layer 3 subroutines (softint)
which are called via traditional netisr can be dispatched on an arbitrary
CPU. Layer 2 subroutines now run without any locks (expected) and so a
Layer 2 subroutine and a Layer 3 subroutine can run in parallel.

There is a shared data between a Layer 2 routine and a Layer 3 routine,
that is ifqueue and IF_ENQUEUE (from L2) and IF_DEQUEUE (from L3) on it
are racy now.

To fix the race condition, use ifqueue#ifq_lock to protect ifqueue
instead of splnet that is meaningless now.

The same race condition exists in route_intr. Fix it as well.

Reviewed by knakahara@
2016-10-03 11:06:06 +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
rjs
0dd1bf859c Restore correct test for return value from aarpresolve(). 2016-07-25 23:46:09 +00:00
knakahara
36a04107c0 fix ATF net/carp failure 2016-06-21 03:54:04 +00:00
knakahara
58e1ba6e9c make ether_output() MP-safe, so that if_ether can enable IFEF_OUTPUT_MPSAFE.
making MP-scalable is future work.
2016-06-20 07:01:45 +00:00