Commit Graph

3475 Commits

Author SHA1 Message Date
maxv 5c98710094 Remove the 't' argument from m_tag_find(). 2018-11-15 10:23:55 +00:00
maxv e7985a6afd Simplify the mtag API:
- Remove m_tag_init(), m_tag_first(), m_tag_next() and
   m_tag_delete_nonpersistent().

 - Remove the 't' argument from m_tag_delete_chain().
2018-11-15 10:06:06 +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
knakahara 96d91f815c Fix ALTQ on gif(4). Reported and tested by Anthony Mallet, advised by Greg Troxel, thanks.
l2tp(4) and ipsecif(4) don't support ALTQ yet. So, they don't require this fix.

XXX pullup-8
2018-11-12 03:37:33 +00:00
ozaki-r 63f183af76 Fix that brconfig <bridge> (addr) can't show a large number of MAC addresses
The command shows only 256 addresses at maximum even if a bridge caches more
addresses.  It occurs because the kernel doesn't return an error if the command
passes a short buffer that can't store all cached addresses; the kernel fills
cached addresses as much as possible and returns it without telling that the
result is truncated.

Fix the issue by telling a required size of a buffer if a buffer passed from the
command is not enough, which lets the command retry with an enough buffer.

Reported by k-goda@IIJ
2018-11-09 06:44:31 +00:00
ozaki-r cb8a413a5e Use rt_update framework on updating a rtentry 2018-10-30 05:56:02 +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
ozaki-r 954d82d49e Avoid a dangling pointer during rt_replace_ifa 2018-10-30 05:30:31 +00:00
ozaki-r 334ceb81c9 Use atomic operations for ifa_refcnt 2018-10-30 05:29:21 +00:00
ozaki-r 9b83640c45 Remove a wrong assertion in ifaref
Doing ifref on an ifa with IFA_DESTROYING is not a problem; the reference should
be dropped during the destruction of the ifa.
2018-10-30 05:27:51 +00:00
christos 2a18a80d51 We need to have rump tests work in two modes:
1. npf unit tests. In this case only the npf subsystem is created
   and dictionaries are passed directly.
2. kernel system tests (like the ipsec natt test). In this case, npf is
   instantiated regularly as part of the kernel and dictionaries are
   passed via ioctl.

We differentiate between the two cases by checking the "mbufops" member
which is NULL, regularly and non-NULL in the npf unit tests. Previously
this was done using an ifdef which obviously can't work for both cases.
2018-10-29 15:37:06 +00:00
maxv 7678f2a6fc Remove printfs that are too easily reachable, switch to M_REGION_GET,
and simplify the initialization. No real functional change.
2018-10-27 06:46:43 +00:00
maxv 9fa1aecd3e style 2018-10-27 05:56:10 +00:00
christos 3e34f26766 enable the sampling function for _NPF_RUMP 2018-10-26 23:35:06 +00:00
knakahara ebac3c728d Fix panic when doing ioctl to multiple pseudo interfaces. Pointed out by k-goda@IIJ.
XXX pullup-8
2018-10-19 00:12:56 +00:00
knakahara eecb6bd8af fix panic when do ifconfig -vlanif and ifconfig vlanif again. advised by ozaki-r@.
e.g. do the following commands.
    ====================
    # ifconfig vlan0 create
    # ifconfig vlan0 vlan 100 vlanif wm0
    # ifconfig vlan0 -vlanif wm0
    # ifconfig vlan0 vlan 100 vlanif wm0
    ====================

ATF net/if_vlan do this type of test, however it cannot detect this bug.
Because the shmif(4)'s ifp->if_hwdl is always NULL as shmif(4)'s ethernet
address is set U/L bit.
See: https://nxr.netbsd.org/xref/src/sys/net/if_ethersubr.c#997
2018-10-18 11:34:54 +00:00
maxv 7156151032 remove hardcoded bullshit, probably fixes PR/53644 2018-09-30 10:00:24 +00:00
rmind df92f5b5a5 npf_return_tcp: fix no-INET6 case. 2018-09-29 18:00:35 +00:00
rmind 39013e66c1 NPF: Major rework -- migrate NPF to the libnv library.
- This conversion significantly simplifies the code and moves NPF to
  a binary serialisation format (replacing the XML-like format).
- Fix some memory/reference leaks and possibly use-after-free bugs.
- Bump NPF_VERSION as this change makes libnpf incompatible with the
  previous versions.  Also, different serialisation format means NPF
  connection/config saving and loading is not compatible with the
  previous versions either.

Thanks to christos@ for extra testing.
2018-09-29 14:41:35 +00:00
maxv ebec90347e Remove ISDN from the kernel. It has remained unmaintained for a long time,
is of poor quality, and is now an obstacle to MP-ification. It was removed
ten years ago from FreeBSD for the same reason.

This retires a big user of the mbuf API, and will ease maintenance of the
kernel.
2018-09-23 09:20:57 +00:00
msaitoh 8553f24d94 Micro optimization. m_copym(M_COPYALL) -> m_copypacket(). 2018-09-19 07:51:23 +00:00
msaitoh ad29c40915 - Fix bridge_enqueue() which was broken by last commit. Use correct mbuf
pointer.
- Modify comment.
2018-09-18 09:27:35 +00:00
msaitoh 22e37dedf0 Fix a bug that bridge_enqueue() incorrectly cleared outgoing packet's offload
flags. bridge_enqueue() is called from bridge_output() when a packet is
spontaneous. Clear csum_flags before calling brige_enqueue() in
bridge_forward() or bridge_broadcast() instead of in the beginning of
bridge_enqueue().

Note that this change doesn't fix a problem on the following configuration:

	A bridge has two or more interfaces.

	An address is assigned to an bridge member interface and
	some offload flags are set.

	Another interface has no address and has no any offload flag.

XXX pullup-[78]
2018-09-14 11:05:09 +00:00
christos b7d09b8024 Fix lockdebug diagnostic error of trying to acquire an rw_lock from a
pserialized active context. From riastradh@
2018-09-12 21:58:38 +00:00
christos 68d92d47f7 Flip the order of free'ing things to avoid crash (from ozaki-r). Tested
with a month's uptime. Used to crash once a week.
2018-09-07 13:24:14 +00:00
maxv e9cdd6de13 Make raw_input non-variadic. 2018-09-07 06:13:14 +00:00
maxv ec3696147d Set unused pr_input field to NULL, discussed on tech-net@. 2018-09-07 06:08:16 +00:00
maxv f922b0f6bd Remove the network ATM code. 2018-09-06 06:41:59 +00:00
ozaki-r c63a18c273 route: avoid overwriting rt_free_global.enqueued unexpectedly
rt_free_global.enqueued can be set to true by rt_free during rt_free_work
because rt_free_work releases rt_free_global.lock.  So rt_free_work must update
it once and not update after releasing the lock.
2018-09-05 02:49:40 +00:00
ozaki-r b3d6924018 route: don't take an extra reference of a rtentry for the delayed free mechanism
Because a reference is already taken at that point.
2018-09-05 02:49:09 +00:00
riastradh d1579b2d70 Rename min/max -> uimin/uimax for better honesty.
These functions are defined on unsigned int.  The generic name
min/max should not silently truncate to 32 bits on 64-bit systems.
This is purely a name change -- no functional change intended.

HOWEVER!  Some subsystems have

	#define min(a, b)	((a) < (b) ? (a) : (b))
	#define max(a, b)	((a) > (b) ? (a) : (b))

even though our standard name for that is MIN/MAX.  Although these
may invite multiple evaluation bugs, these do _not_ cause integer
truncation.

To avoid `fixing' these cases, I first changed the name in libkern,
and then compile-tested every file where min/max occurred in order to
confirm that it failed -- and thus confirm that nothing shadowed
min/max -- before changing it.

I have left a handful of bootloaders that are too annoying to
compile-test, and some dead code:

cobalt ews4800mips hp300 hppa ia64 luna68k vax
acorn32/if_ie.c (not included in any kernels)
macppc/if_gm.c (superseded by gem(4))

It should be easy to fix the fallout once identified -- this way of
doing things fails safe, and the goal here, after all, is to _avoid_
silent integer truncations, not introduce them.

Maybe one day we can reintroduce min/max as type-generic things that
never silently truncate.  But we should avoid doing that for a while,
so that existing code has a chance to be detected by the compiler for
conversion to uimin/uimax without changing the semantics until we can
properly audit it all.  (Who knows, maybe in some cases integer
truncation is actually intended!)
2018-09-03 16:29:22 +00:00
christos f21477121e Add definitions from libpcap-1.9.0 2018-09-03 15:16:11 +00:00
christos 0966f88465 sync with libpcap-1.9.0 2018-09-03 14:58:04 +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
maxv 10d6722b09 Introduce npf_set_mss(). When the MSS is not 16bit-aligned, it sets:
0      8           16          24    32
	+------+-----------+-----------+------+
	| data | MSS (low) | MSS (hig) | data |
	+------+-----------+-----------+------+
	^                  ^
	old[0]             old[1]

And sets new[0,1] accordingly with the new value. The MSS-clamping code
then adjusts twice the checksum on a 16bit boundary:

	from old[0] to new[0]
	from old[1] to new[1]

Fixes PR/53479, opened by myself. Tested with wireshark and kASan.
2018-08-31 14:16:06 +00:00
ozaki-r 07f0937270 Restore splx removed accidentally at v1.406
Pointed out by k-goda@IIJ
2018-08-27 04:53:24 +00:00
maxv a8a3fd3cca Use a random hunique, instead of sending the pointer of the interface.
Tested via ATF.
2018-08-24 17:06:29 +00:00
msaitoh 61e1eb0d0b - Cleanup for dynamic sysctl:
- Remove unused *_NAMES macros for sysctl.
  - Remove unused *_MAXID for sysctls.
- Move CTL_MACHDEP sysctl definitions for m68k into m68k/include/cpu.h and
  use them on all m68k machines.
2018-08-22 01:05:21 +00:00
maxv 735ddbc5b3 Retire EtherIP, we have L2TP instead. 2018-08-14 14:49:13 +00:00
maxv 3f80412be2 Clarify two functions. 2018-08-13 09:29:13 +00:00
knakahara 726424d6e0 fix if_snd_is_used(), ifp->if_snd is also used by if.c::if_transmit(). 2018-08-10 10:31:01 +00:00
msaitoh 80bf5cccde - Fix a bug that drop counter shows incorrect vaule like
"net.inet.ip.ifq.drops = 72059810241052672"
- Change pktq's length sysctl to uint64_t.
2018-08-10 07:24:09 +00:00
maxv d22d69a653 Rename
ip6_undefer_csum  -> in6_undefer_cksum
	in6_delayed_cksum -> in6_undefer_cksum_tcpudp

The two previous names were inconsistent and misleading.

Put the two functions into in6_offload.c. Add comments to explain what
we're doing.

Same as IPv4.
2018-08-10 06:46:08 +00:00
msaitoh 68ccef5262 Change pktq's drops count sysctl from CTLTYPE_INT to CTLTYPE_QUAD. 2018-08-06 06:54:40 +00:00
ozaki-r f243d55f59 Fix tun(4) kevent locking
filt_tunread gets called in two contexts:

- by calls to selnotify in if_tun.c (or knote, as the case may be,
  but not here), in which case tp->tun_lock is held; and

- by internal logic in kevent, in which tp->tun_lock is not held.

The standard convention to discriminate between these two cases is by
setting the kernel-only NOTE_SUBMIT bit in the hint to selnotify or
knote; then in filt_*:

        if (hint & NOTE_SUBMIT)
                KASSERT(mutex_owned(&tp->tun_lock));
        else
                mutex_enter(&tp->tun_lock);
        ...
        if (hint & NOTE_SUBMIT)
                KASSERT(mutex_owned(&tp->tun_lock));
        else
                mutex_exit(&tp->tun_lock);

Pointed out by and patch from riastradh@
Tested by ozaki-r@ (only the former path)
2018-08-06 03:58:59 +00:00
jmcneill 8c7579d3a9 Use a different psz for a different lock. Patch from riastradh, reviewed
by ozaki-r.
2018-08-03 11:24:19 +00:00
ozaki-r 5a670ba8b5 tun: fix locking against myself
filt_tunread is called with tun_lock held from tun_output (via tun_output =>
selnotify => knote), so we must not take tun_lock in filt_tunread.  The bug
is triggered only if a tun is used through kqueue.

Found by k-goda@IIJ
2018-08-03 09:54:40 +00:00
khorben d7f036be09 Add a port of the umb(4) driver from OpenBSD
The umb(4) driver provides support for USB MBIM (Mobile Broadband
Interface Model) devices.

MBIM devices establish connections via cellular networks such as GPRS,
UMTS, and LTE. They appear as a regular point-to-point network interface, transporting raw IP frames.

Required configuration parameters like PIN and APN have to be set with
umbctl(8), a new tool specific to this driver. The IP address is configured
automatically; the default route and DNS server information have to be set
separately.

The driver is not fully functional yet, it is therefore still marked as
experimental and disabled by default. Any help welcome to complete it!

Tested on NetBSD/amd64, with a Sierra Wireless EM7345 LTE modem on a Lenovo
ThinkPad T440s. No functional change expected otherwise.
2018-07-31 16:44:28 +00:00
msaitoh c33f30648e Initialize some members in a mbuf which is on stack. 2018-07-25 07:55:44 +00:00
ozaki-r 94cb3ba316 Don't use aprint_* functions for logging unrelated to autoconf(9) 2018-07-12 02:26:04 +00:00