Commit Graph

3579 Commits

Author SHA1 Message Date
msaitoh
b801416bbd Simplify "LIST_HEAD();" to make the code more understandable.
No functional change.
2019-06-25 12:30:50 +00:00
skrll
f89a668ad5 Fix 'unknown' spellos 2019-06-24 06:24:33 +00:00
christos
5db0dcccf9 Add error checking for previous memory allocation failure. 2019-06-20 17:12:37 +00:00
christos
cd3ba776bd PR/54314: Frank Kardel: LOCKDEBUG: Mutex error: assert_sleepable,70:
spin lock held when loading NPF
2019-06-20 17:08:52 +00:00
msaitoh
38d0497851 KNF. No functional change. 2019-06-18 08:36:52 +00:00
msaitoh
7ad35d74eb No functional change:
- Fix typo (s/configureation/configuration/)
- KNF
2019-06-18 07:50:43 +00:00
christos
a80fb12074 Avoid LOCKDEBUG pserialize panic by implementing suggestion #1 from
http://mail-index.netbsd.org/current-users/2019/02/24/msg035220.html:

Convert the mutex to spin-lock at IPL_NET (but it is excessive) and
convert the memory allocations in that code path to KM_NOSLEEP.
2019-06-12 14:36:32 +00:00
msaitoh
b9958efe6c Even if we don't use MII(4), use the common path of SIOC[GS]IFMEDIA in
sys/net/if_ethersubr.c if we can.
 - Add ec_ifmedia into struct ethercom.
 - ec_mii in struct ethercom is kept and used as it is. It might be used in
   future. Note that some Ethernet drivers which _DOESN'T_ use mii(4) use
   ec_mii for keeping the if_media. Those should be changed in future.
2019-05-29 10:07:28 +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
msaitoh
22d7e3fc82 KNF. No functional change. 2019-05-21 09:18:37 +00:00
msaitoh
bf354a0797 The max subtype of the ifmedia word is 31. It's too small for Ethernet now.
We currently use use it up to 30. We should extend the limit to be able to use
more than 10Gbps speeds. Our ifmedia(4) is inconvenience and have some problem
so we should redesign the interface, but it's too late for netbsd-9 to do it.
So, we keep the data structure size and modify the structure a bit. The
strategy is almost the same as FreeBSD. Many bits of IFM_OMASK for Ethernet
have not used, so use some of them for Ethernet's subtype.

The differences against FreeBSD are:
 - We use NetBSD style compat code (i.e. no SIOCGIFXMEDIA).
 - FreeBSD's IFM_ETH_XTYPE's bit location is from 11 to "14" even though
   IFM_OMASK is from 8 to "15". We use _IFM_ETH_XTMASK from bit 13 to "15".
 - FreeBSD changed the meaning of IFM_TYPE_MATCH(). I think we should
   not do it. We keep it not changing and added new IFM_TYPE_SUBTYPE_MATCH()
   macro for matching both TYPE and SUBTYPE.
 - Added up to 400GBASE-SR16.

New layout of the media word is as follows (from ifmedia_h):

 * if_media Options word:
 *	Bits	Use
 *	----	-------
 *	0-4	Media subtype	MAX SUBTYPE == 255 for ETH and 31 for others
 *	5-7	Media type
 *	8-15	Type specific options
 *	16-18	Mode (for multi-mode devices)
 *	19	(Reserved for Future Use)
 *	20-27	Shared (global) options
 *	28-31	Instance
 *
 *   3                     2                   1
 *   1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0
 *  +-------+---------------+-+-----+---------------+-----+---------+
 *  |       |               |R|     |               |     |         |
 *  | IMASK |     GMASK     |F|MMASK+-----+ OMASK   |NMASK|  TMASK  |
 *  |       |               |U|     |XTMSK|         |     |         |
 *  +-------+---------------+-+-----+-----+---------+-----+---------+
 *   <----->                   <--->                 <--->
 *  IFM_INST()               IFM_MODE()            IFM_TYPE()
 *
 *                              IFM_SUBTYPE(other than ETH)<------->
 *
 *                                   <---> IFM_SUBTYPE(ETH)<------->
 *
 *
 *           <------------->         <------------->
 *                        IFM_OPTIONS()
2019-05-17 07:37:11 +00:00
ozaki-r
7fc219a5ee Implement an aggressive psref leak detector
It is yet another psref leak detector that enables to tell where a leak occurs
while a simpler version that is already committed just tells an occurrence of a
leak.

Investigating of psref leaks is hard because once a leak occurs a percpu list of
psref that tracks references can be corrupted.  A reference to a tracking object
is memorized in the list via an intermediate object (struct psref) that is
normally allocated on a stack of a thread.  Thus, the intermediate object can be
overwritten on a leak resulting in corruption of the list.

The tracker makes a shadow entry to an intermediate object and stores some hints
into it (currently it's a caller address of psref_acquire).  We can detect a
leak by checking the entries on certain points where any references should be
released such as the return point of syscalls and the end of each softint
handler.

The feature is expensive and enabled only if the kernel is built with
PSREF_DEBUG.

Proposed on tech-kern
2019-05-17 03:34:26 +00:00
ozaki-r
6c6d1e4f71 Get rid of IFNET_LOCK for if_mcast_op to avoid a deadlock
The IFNET_LOCK was added to avoid data races on if_flags for IFF_ALLMULTI.
Unfortunatetly it caused a deadlock instead.  A known scenario causing a
deadlock is to occur the following two operations concurrently: (a) a removal of
an IP adddres assigned to an interface and (b) a manipulation of multicast
groups to the interface.  The resource dependency graph is like this:
  softnet_lock => IFNET_LOCK => psref_target_destroy => softint => softnet_lock

Thanks to the previous commit that avoids data races on if_flags for
IFF_ALLMULTI by another approach, we can remove IFNET_LOCK and defuse the
deadlock.

PR kern/54189
2019-05-15 02:59:18 +00:00
ozaki-r
99ec0af5eb Store IFF_ALLMULTI in ec_flags instead of if_flags to avoid data races
IFF_ALLMULTI is set/unset to if_flags via if_mcast_op.  To avoid data races on
if_flags, IFNET_LOCK was added for if_mcast_op.  Unfortunately it produces
a deadlock so we want to remove added IFNET_LOCK by avoiding the data races by
another approach.

This fix introduces ec_flags to struct ethercom and stores IFF_ALLMULTI to it.
ec_flags is protected by ETHER_LOCK and thus IFNET_LOCK is no longer necessary
for if_mcast_op.  Note that the fix is applied only to MP-safe drivers that
the data races matter.

In the kernel, IFF_ALLMULTI is set by a driver and used by the driver itself.
So changing the storing place doesn't break anything.  One exception is
ioctl(SIOCGIFFLAGS); we have to include IFF_ALLMULTI in a result if needed to
export the flag as well as before.

A upcoming commit will remove IFNET_LOCK.

PR kern/54189
2019-05-15 02:56:47 +00:00
msaitoh
007b45a492 Use %08x to print ifmedia word (IFMEDIA_DEBUG). 2019-05-10 08:24:54 +00:00
msaitoh
eff7c04a8e Remove extra parentheses. No functional change. 2019-05-10 06:53:42 +00:00
msaitoh
6a30297b4f Add missing parentheses for IFQ_CLASSIFY macro's argument. 2019-05-10 06:45:19 +00:00
msaitoh
d39d3b7cbe Remove extra parenthesis. 2019-05-10 06:33:14 +00:00
msaitoh
d154fb91b7 Modify comment to make the data structure clear. No functional change. 2019-05-10 05:16:34 +00:00
pgoyette
6f326fadc5 Only initialize the NET_MPSAFE stuff once, for the non-compat version
of route_init().
2019-05-03 02:10:58 +00:00
kre
56ac6e6072 Add the missing add. (Return to the earlier state, done differently.)
When dl_print() was converted to use lla_snprintf() the offset to
the LLA in dl_addr.dl_data was forgotten (dl_data contains both
the interface name and the LL addr, we want the latter, not the former).

When there is no data (src_len == 0), still null terminate the output buffer
(provided there is space in it for the \0).
2019-04-30 20:56:32 +00:00
kre
b4d93403a3 Whitespace consistency. NFC. 2019-04-30 20:55:41 +00:00
christos
f36b7ace41 match definition of hexdigits[] to the declaration in <sys/systm.h> 2019-04-29 19:08:11 +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
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
befc8be5c7 A few more empty-string --> NULL in required-modules lists 2019-04-27 06:18:15 +00:00
pgoyette
64eedb18ba Some more empty-string --> NULL conversions for module dependencies 2019-04-26 11:51:56 +00:00
pgoyette
dc68f5827a Set the "required modules" to NULL, not to an empty string.
It really doesn't make that much difference to the code, but the output
from modstat(8) is different!  (With an empty string in the MODULE() macro
modstat reports an empty string, but with a NULL in the macro, modstat
prints a '-' just like it does for other "empty" fields.)
2019-04-26 08:38:25 +00:00
msaitoh
4d51528bc0 KNF. No functional change. 2019-04-24 05:31:24 +00:00
msaitoh
2d2e9967e8 No functional change:
- IFM_AVALID and IFM_ACTIVE are NOT for the media word. Fix comment.
 - RFU stands for Reserved for Future Use.
2019-04-24 05:07:20 +00:00
msaitoh
1b9aeaf023 KNF. No functional change. 2019-04-23 07:29:04 +00:00
msaitoh
6a299f742d Add missing error check. 2019-04-22 11:10:52 +00:00
knakahara
ce1daba545 fix a potential bug of gif(4) check for tunnel duplicate.
This problem has not actualized thanks to check for duplicate
in encap_attach().
2019-04-22 08:09:59 +00:00
pgoyette
35c8bc0f3b Typos in comments. NFCI. 2019-04-20 22:16:47 +00:00
msaitoh
6fd86da20b Remove unused inclusion. 2019-04-17 07:47:56 +00:00
msaitoh
9cbcc61c49 Tabify. No functional change. 2019-04-17 07:04:03 +00:00
msaitoh
9fde34d208 It's not required (and can't do) to convert OSIOCSIFMEDIA in ifmedia_ioct()
because the conversiosn is done in doifioctl().
2019-04-16 06:48:33 +00:00
msaitoh
d6117c1651 Rename ifreqo2n() and ifreqo2n() to IFREQO2N_43() and IFREQN2O_43():
- ifreqo2n() and ifreqn2o() are for COMPAT_43, so add _43 to the name.
 - Uppercase to make it clear those are macros.
2019-04-16 04:31:42 +00:00
msaitoh
01277d2430 The path of SOICSIFMEDA or TAPGIFNAME calls are as follows:
doifioctl()

    pre-convert (if_cvtcmd_43_hook & ifreqo2n)

    (*ifp->if_ioctl)(ifp, cmd, data);

    post-convert (ifreqn2o)

so it's not required to check OSIOCSIFMEDIA and OTAPGIFNAME in if_tap.c.
Those two command is converted to new command in if_cvtcmd_43_hook and
always new commands are seen in tap_ioctl().

OK'd by pgoyette.
2019-04-16 04:26:02 +00:00
christos
c9d0acaf5e Zero out the ifreq struct for SIOCGIFCONF to avoid up to 127 bytes of stack
disclosure. From Andy Nguyen, many thanks!
2019-04-15 20:51:46 +00:00
kamil
2244e8ee17 Fix CVS Id usage 2019-04-11 14:38:05 +00:00
msaitoh
4f0d5c60d3 Remove inclusion of compat/sys/socket.h. It's not required anymore. 2019-04-11 03:07:11 +00:00
msaitoh
53cc1211c3 KNF. No functional change. 2019-04-10 08:23:46 +00:00
msaitoh
b90791094b Fix a bug that OSIOCSIFMEDIA can't treat. Add missing inclusion of
compat/sys/sockio.h.
2019-04-10 08:22:18 +00:00
thorpej
17e09f6cfe Avoid a maybe-uninitialized warning by checking for an error return
that might indicate that 'len' was not initialized.
2019-04-10 04:06:52 +00:00
msaitoh
3a82450c68 KNF. No functional change. 2019-04-06 08:38:23 +00:00
pgoyette
21ccb941a9 Add cloned-interface-create code to srt open() routine so behavior
matches that which is documented in srtconfig(1) man page.  Without
this, srt only works if you first create the srtN interface with
ifconfig(8).
2019-03-26 06:59:11 +00:00
pgoyette
0a2e0c9260 Add devsw_{attach,detach} stuff for _MODULE variant. (Not needed for
built-in variant since the devsw is also built-in.)  This will allow
the modular srt devices to be accessed via open(2) and ioctl(2).

XXX Someone(tm) needs to update MAKEDEV to create the /dev/srtN device
nodes (with device-major 179)!
2019-03-26 00:23:32 +00:00