Commit Graph

9286 Commits

Author SHA1 Message Date
Conrad Meyer
d82e4d759d fsirand(8): Just use arc4random(3)
Remove single use of dubious srandomdev(3) + random(3) and replace with
arc4random(3), as is used already in this program.

Follow-up question: Do we really need this program anymore?  In base?
2019-12-13 04:12:13 +00:00
Simon J. Gerraty
2c9a9dfc18 Update Makefile.depend files
Update a bunch of Makefile.depend files as
a result of adding Makefile.depend.options files

Reviewed by:	 bdrewery
MFC after:	1 week
Sponsored by:   Juniper Networks
Differential Revision:  https://reviews.freebsd.org/D22494
2019-12-11 17:37:53 +00:00
Simon J. Gerraty
5ab1c5846f Add Makefile.depend.options
Leaf directories that have dependencies impacted
by options need a Makefile.depend.options file
to avoid churn in Makefile.depend

DIRDEPS for cases such as OPENSSL, TCP_WRAPPERS etc
can be set in local.dirdeps-options.mk
which can add to those set in Makefile.depend.options

See share/mk/dirdeps-options.mk

Reviewed by:	 bdrewery
MFC after:	1 week
Sponsored by:   Juniper Networks
Differential Revision:  https://reviews.freebsd.org/D22469
2019-12-11 17:37:37 +00:00
Eric van Gyzen
15da40b0af fsck_ffs: fix some memory leaks found by Coverity.
Reported by:	Coverity
CID:		1380549 1380550 1380551
MFC after:	1 week
Sponsored by:	Dell EMC Isilon
2019-12-10 20:04:08 +00:00
Don Lewis
1bf6738f80 Fix a logic bug in error handling code. It is an error if p == NULL.
The linelen tests are only meaningful when p != NULL.

Reported by:	Coverity
Coverity CID:	1368655
MFC after:	1 month
2019-12-09 07:18:40 +00:00
Xin LI
2780a26b6a Fix a couple of minor issues with newfs_msdos:
- Do not unnecessarily strdup().
 - Check return value of getdiskinfo(), if it failed, bail out.

Reviewed by:	imp
MFC after:	2 weeks
Differential Revision:	https://reviews.freebsd.org/D22729
2019-12-08 01:20:37 +00:00
Jens Schweikhardt
e7114e1e11 Correct a handful of typos/grammos. 2019-12-07 15:17:00 +00:00
Warner Losh
f86e60008b Regularize my copyright notice
o Remove All Rights Reserved from my notices
o imp@FreeBSD.org everywhere
o regularize punctiation, eliminate date ranges
o Make sure that it's clear that I don't claim All Rights reserved by listing
  All Rights Reserved on same line as other copyright holders (but not
  me). Other such holders are also listed last where it's clear.
2019-12-04 16:56:11 +00:00
Xin LI
7b9934a1c6 Explicitly exit() instead of return in main().
MFC after:	2 weeks
2019-12-03 07:03:25 +00:00
Xin LI
e453f01668 newfs_msdos: -A is incompatible with -r, not -o.
PR:		242314
Submitted by:	Guy Yur <guyyur gmail com>
MFC after:	2 weeks
2019-12-03 07:01:28 +00:00
Benedict Reuschling
23614c2b39 Capitalize some user-visible output messages in
the bectl utility.

No functional changes.

Approved by:	    imp@
MFC after:	    7 days
Differential Revision:	https://reviews.freebsd.org/D22330
2019-11-30 14:17:45 +00:00
Xin LI
f00c55e25a Use strlcat().
MFC after:	2 weeks
2019-11-30 05:57:54 +00:00
Conrad Meyer
74aed808a1 Fix braino in previous bugfix r300174
The previous revision missed the exact same error in a copy paste block
of the same code in another function.  Fix the identical case, too.

A DHCP client identifier is simply the hardware type (one byte)
concatenated with the hardware address (some variable number of bytes,
but at most 16).  Limit the size of the temporary buffer to match and
the rest of the calculations shake out correctly.

PR:		238022
Reported by:	Young <yangx92 AT hotmail.com>
Submitted by:	Young <yangx92 AT hotmail.com>
MFC after:	I don't plan to but you should feel free
Security:	yes
2019-11-29 03:31:47 +00:00
Alan Somers
2eb6acc277 ping, ping6: Use setitimer(2) instead of obsolete alarm(3)
Submitted by:	Ján Sučan <sucanjan@gmail.com>
Differential Revision:	https://reviews.freebsd.org/D22103
2019-11-26 05:06:25 +00:00
Dave Cottlehuber
130cfcf3fc dhclient: support option 114, default-url ascii
This will enable further automation of HTTP UEFI boot loader support by
providing a specific option for providing the boot URL to FreeBSD.

Documented in:

https://www.iana.org/assignments/bootp-dhcp-parameters/bootp-dhcp-parameters.xhtml
https://kb.isc.org/docs/isc-dhcp-44-manual-pages-dhcp-options
https://tools.ietf.org/html/rfc3679

Approved by:	emaste
MFC after:	2 weeks
Sponsored by:	SkunkWerks, GmbH
Differential Revision:	https://reviews.freebsd.org/D22475
2019-11-22 20:22:16 +00:00
Alexander Motin
f97cf1a168 Fix off-by-one error in HPA/AMA maximum reporting.
Before my refactoring the code reported value as maximum number of sectors,
adding one to the maximum sector number returned by respective command.
While this difference is somewhat confusing, restore previous behavior.

MFC after:	3 days
2019-11-22 15:41:47 +00:00
Gleb Smirnoff
71f0077631 Remove sio(4).
It had been disconnected from build in r181233 in 2008.

Reviewed by:	imp
2019-11-21 01:24:49 +00:00
Ed Maste
d9aee13f6f makefs: avoid warning when creating FAT filesystem on existing file
Previously the mkfs_msdos function (from newfs_msdos) emitted warnings
in the case that an image size is specified and the target is not a
file, or no size is specified and the target is not a character device.
The latter warning (not a character device) doesn't make sense when this
code is used in makefs, regardless of whether an image size is specified
or not.

Sponsored by:	The FreeBSD Foundation
2019-11-08 14:11:25 +00:00
Kyle Evans
f852618602 mdmfs(8): add -k skel option to populate fs from a skeleton
mdmfs(8) lacks the ability to populate throwaway memory filesystems from an
existing directory.

This features permits an interesting setup where /var for instance lives on
a device where wear-leveling is something you want to avoid as much as
possible and nonetheless you don't want to lose your logs, ports metadata,
etc. Here are the steps:

1. Copy /var to /var.bak;
2. Mount an mfs into /var using -k /var.bak at startup;
3. Synchronize /var to /var.bak weekly and on shutdown.

Note that this more or less mimics OpenBSD's mount_mfs(8) -P flag.

PR:		146254
Submitted by:	jlh (many moons ago)
MFC after:	1 week
2019-11-01 03:10:53 +00:00
Kirk McKusick
e39c92986d Replace an uninitialized variable with the correct element from the
superblock when doing recovery with journalled soft updates.

Reported by:  Chuck Silvers
MFC after:    3 days
Sponsored by: Netflix
2019-10-22 22:23:59 +00:00
Alan Somers
e9dfc15a83 Fix option names in the Examples section of the manual page
This corrects an oversight from r351423.

Submitted by:	Ján Sučan <sucanjan@gmail.com>
MFC after:	Never
Differential Revision:	https://reviews.freebsd.org/D22093
2019-10-20 20:29:17 +00:00
Andriy Gapon
47adb0e0e0 ddb: use 'textdump dump' instead of 'call doadump'
The change is for the example in textdump.4 and the default ddb.conf.

First of all, doadump now requires an argument and it won't do a
textdump if the argument is not 'true'.
And 'textdump dump' is more idiomatic anyway.

For what it's worth, ddb 'dump' command seems to always request a vmcore
dump even if a textdump was requested earlier, e.g., by 'textdump set'.
Finally, ddb 'call' command is not documented.

MFC after:	2 weeks
2019-10-18 12:32:01 +00:00
Kyle Evans
8338f584dc bectl(8): destroy: use BE_DESTROY_AUTOORIGIN if -o is not specified
-o will force the origin to be destroyed unconditionally.
BE_DESTROY_AUTOORIGIN, on the other hand, will only destroy the origin if it
matches the format used by be_snapshot. This lets us clean up the snapshots
that are clearly not user-managed (because we're creating them) while
leaving user-created snapshots in place and warning that they're still
around when the BE created goes away.
2019-10-16 14:55:56 +00:00
Andrey V. Elsukov
51b1593065 Explicitly initialize the memory buffer to store O_ICMP6TYPE opcode.
By default next_cmd() initializes only first u32 of opcode. O_ICMP6TYPE
opcode has array of bit masks to store corresponding ICMPv6 types.
An opcode that precedes O_ICMP6TYPE, e.g. O_IP6_DST, can have variable
length and during opcode filling it can modify memory that will be used
by O_ICMP6TYPE opcode. Without explicit initialization this leads to
creation of wrong opcode.

Reported by:	Boris N. Lytochkin
Obtained from:	Yandex LLC
MFC after:	3 days
2019-10-15 09:50:02 +00:00
Andriy Gapon
5fda0d60c1 add ability to set watchdog timeout for a shutdown
This change allows to specify a watchdog(9) timeout for a system
shutdown.  The timeout is activated when the watchdogd daemon is
stopped.  The idea is to a prevent any indefinite hang during late
stages of the shutdown.  The feature is implemented in rc.d/watchdogd,
it builds upon watchdogd -x option.

Note that the shutdown timeout is not actiavted when the watchdogd
service is individually stopped by an operator.  It is also not
activated for the 'shutdown' to the single-user mode.  In those cases it
is assumed that the operator knows what they are doing and they have
means to recover the system should it hang.

Significant subchanges and implementation details:
- the argument to rc.shutdown, completely unused before, is assigned to
  rc_shutdown variable that can be inspected by rc scripts
- init(8) passes "single" or "reboot" as the argument, this is not
  changed
- the argument is not mandatory and if it is not set then rc_shutdown is
  set to "unspecified"
- however, the default jail management scripts and jail configuration
  examples have been updated to pass "jail" to rc.shutdown, just in case
- the new timeout can be set via watchdogd_shutdown_timeout rc option
- for consistency, the regular timeout can now be set via
  watchdogd_timeout rc option
- watchdogd_shutdown_timeout and watchdogd_timeout override timeout
  specifications in watchdogd_flags
- existing configurations, where the new rc options are not set, should
  keep working as before

I am not particularly wed to any of the implementation specifics.
I am open to changing or removing any of them as long as the provided
functionality is the same (or very close) to the proposed one.
For example, I think it can be implemented without using watchdogd -x,
by means of watchdog(1) alone.  In that case there would be a small
window between stopping watchdogd and running watchdog, but I think that
that is acceptable.

Reviewed by:	bcr (man page changes)
MFC after:	5 weeks
Relnotes:	yes
Differential Revision: https://reviews.freebsd.org/D21221
2019-10-03 11:23:10 +00:00
Warner Losh
a35a97ae12 Size is unsigned, so remove the test entirely.
The kernel won't crash if you have a bad value and I'd rather not have
nvmecontrol know the internal details about how the nvme driver limits
the transfer size.
2019-09-25 07:51:30 +00:00
Warner Losh
087d0e0b5e After my comnd changes, the number of threads and size weren't set. In
addition, the flags are optional, but were made to be mandatory. Set
these things, as well as santiy check the specified size.

Submitted by: Stefan Rink
PR: 240798
2019-09-25 00:24:57 +00:00
Mark Johnston
d395e985b2 ping6: Use caph_rights_limit(3) for STDIN_FILENO
Update some error messages while here.

Reported by:	olivier
MFC after:	3 days
2019-09-23 22:20:11 +00:00
Sean Eric Fagan
ba7a55d934 Add two options to allow mount to avoid covering up existing mount points.
The two options are

* nocover/cover:  Prevent/allow mounting over an existing root mountpoint.
E.g., "mount -t ufs -o nocover /dev/sd1a /usr/local" will fail if /usr/local
is already a mountpoint.
* emptydir/noemptydir:  Prevent/allow mounting on a non-empty directory.
E.g., "mount -t ufs -o emptydir /dev/sd1a /usr" will fail.

Neither of these options is intended to be a default, for historical and
compatibility reasons.

Reviewed by:	allanjude, kib
Differential Revision:	https://reviews.freebsd.org/D21458
2019-09-23 04:28:07 +00:00
Konstantin Belousov
093aa3e311 ifconfig: add report of the string from SIOCGIFDOWNREASON.
Sample output:
# ifconfig mce0
mce0: flags=8802<BROADCAST,SIMPLEX,MULTICAST> metric 0 mtu 1500
options=3ed07bb<RXCSUM,TXCSUM,VLAN_MTU,VLAN_HWTAGGING,JUMBO_MTU,VLAN_HWCSUM,TSO4,TSO6,LRO,VLAN_HWFILTER,VLAN_HWTSO,LINKSTATE,RXCSUM_IPV6,TXCSUM_IPV6,TXRTLMT,HWRXTSTMP>
        ether e4:1d:2d:e7:10:0a
        media: Ethernet autoselect <full-duplex,rxpause,txpause>
        status: no carrier (Negotiation failure)
        nd6 options=21<PERFORMNUD,AUTO_LINKLOCAL>

Reviewed by:	hselasky, rrs
Sponsored by:	Mellanox Technologies
MFC after:	1 week
Differential revision:	https://reviews.freebsd.org/D21527
2019-09-17 18:51:10 +00:00
Xin LI
eb1c42c1f0 Avoid mixing cluster numbers and sector numbers. Makes code more readable.
Obtained from:	NetBSD
MFC after:	2 weeks
2019-09-15 19:41:54 +00:00
Alexander Motin
34454e9a6e Remove Tagged Command Queuing feature reporting.
I never saw those devices myself, FreeBSD never supported them, and it is
officially obsolete since ACS-2 specification.

MFC after:	3 days
2019-09-12 17:42:37 +00:00
Alexander Motin
43e22acce2 Report Trusted Computing feature set support.
It practically means the device is SED.

MFC after:	3 days
2019-09-12 17:20:51 +00:00
Alan Somers
b17fb99228 ping: Verify whether a datagram timestamp was actually received.
ping(8) uses SO_TIMESTAMP, which attaches a timestamp to each IP datagram at
the time it's received by the kernel.  Except that occasionally it doesn't.
Add a check to see whether such a timestamp was actually set before trying
to read it.  This fixes segfaults that can happen when the kernel doesn't
attach a timestamp.

The bug has always existed, but prior to r351461 it manifested as an
implausible round-trip-time, not a segfault.

Reported by:	pho
MFC after:	3 days
MFC-With:	351461
2019-09-11 18:54:45 +00:00
Alan Somers
301bc9f959 ping: fix a string in an error message
MFC after:	3 days
2019-09-11 18:08:40 +00:00
Warner Losh
21fae2d64f Assume all the short args have optional args so allocate space for the
':'. It's slightly wasteful, but much easier (and the savings in bytes
at runtime would be tiny, but the code to do it larger).

Submitted by: Sebastian Huber
2019-09-11 13:34:19 +00:00
Kyle Evans
490e13c140 bectl(8): Add a "check" command
This command simply returns 0 at the moment and explicitly takes no
arguments. This should be used by utilities wanting to see if bectl can
operate on the system they're running, or with a specific root (`bectl -r`).
It may grow more checks than "will libbe successfully init" in the future,
but for now this is enough as that checks for the dataset mounted at "/" and
that it looks capable of being a BE root (e.g. it's not a top-level dataset)

bectl commands can now specify if they want to be silent, and this will turn
off libbe_print_on_error so they can control the output as needed. This is
already used in `bectl check`, and may be turned on in the future for some
other commands where libbe errors are better suppressed as the failure mode
may be obvious.

Requested by:	David Fullard
MFC after:	3 days
2019-09-11 13:27:10 +00:00
Alexander Motin
5b7145c6d4 Remove struct ata_res_pass16, unneeded after r352082.
MFC after:	4 days
2019-09-10 23:51:46 +00:00
Baptiste Daroussin
e6f059a96c Stop linking to libl by specifying we do not need yywrap
MFC after: 3 days
2019-09-10 08:19:46 +00:00
Alexander Motin
576649b30a Initialize page/subpage in case of modepage -d.
Previously without -m parameter it worked mostly by concodence.

While there, make page/subpage values validation more strict.

MFC after:	5 days
Sponsored by:	iXsystems, Inc.
2019-09-09 22:08:22 +00:00
Alexander Motin
2090029769 Add one more error message to r352082.
MFC after:	5 days
Sponsored by:	iXsystems, Inc.
2019-09-09 19:00:37 +00:00
Kyle Evans
a58f19e687 bectl(8): initialize reverse earlier
This turns into a warning in GCC 4.2 that 'reverse' may be used
uninitialized in this function. While I don't immediately see where it's
deciding this from (there's only two paths that make column != NULL, and
they both set reverse), initializing reverse earlier is good for clarity.

MFC after:	3 days
2019-09-09 18:17:30 +00:00
Alexander Motin
ca847845e3 Fix number of problems found while testing on SAT devices.
- Remove incomplete and dangerous ata_res decoding from ata_do_cmd().
Instead switch all functions that need the result to use get_ata_status(),
doing the same, but more careful, also reducing code duplication.
 - Made get_ata_status() to also decode fixed format sense.  In many cases
it is still not enough to make it useful, since it can only report results
of 28-bit command, but it is slightly better then nothing.
 - Organize error reporting in ata_do_cmd(), so that if caller specified
AP_FLAG_CHK_COND, it is responsible for command errors (non-ioctl ones).
 - Make HPA/AMA errors not fatal for `identify` subcommand.
 - Fix reprobe() not being called on HPA/AMA when in quiet mode.
 - Remove not very useful messages from `format` and `sanitize` commands
with -y flag.  Once they started, they often can't be stopped any way.

MFC after:	5 days
Sponsored by:	iXsystems, Inc.
2019-09-09 17:36:29 +00:00
Alan Somers
8c50ee012f mount_fusefs: fix a segfault on memory allocation failure
Reported by:	Coverity
Coverity CID:	1354188
MFC after:	4 days
Sponsored by:	The FreeBSD Foundation
2019-09-07 21:49:01 +00:00
Alexander Motin
268c280675 Unify cam_send_ccb() error reporting.
Error there mean that command was not even executed, and all information
we have about it is errno, and cam_error_print() call is not very useful.
Plus it is most likely a programmatic error, that shoud not happen.

MFC after:	1 week
Sponsored by:	iXsystems, Inc.
2019-09-07 16:52:40 +00:00
Alexander Motin
16614d3518 Supply SAT layer with valid transfer sizes.
This is a rework of r344701, that noticed that number of bytes passes to
8 bit sector count field gets truncated.  First decision was to not pass
anything, since ATA specs define the field as N/A.  But it appeared to be a
problem for some SAT devices, that require information about data transfer
to operate properly.  Some additional investigation shown that it is quite
a common practice to set unused fields of ATA commands (fortunately ATA
specs formally allow it) to supply the information to SAT layer.  I have
found SAS-SATA interposer that does not allow pass-through without it.

As side effect, reduce code duplication by removing ata_do_28bit_cmd()
function, replacing it with more universal ata_do_cmd().

MFC after:	1 week
Sponsored by:	iXsystems, Inc.
2019-09-07 15:56:00 +00:00
Warner Losh
2c24ffacd6 Fix typo not -> nor and add 'the' because we are talking about specific flags
and make the punctuation parallel between the three cases.

Submitted by: Yoshihiro Ota-san
Differential Revision: https://reviews.freebsd.org/D21530
2019-09-06 15:01:47 +00:00
Emmanuel Vadot
92fd0827c1 pkgbase: pfctl: tests: Put tests files in the FreeBSD-tests package
Reviewed by:	kp, gjb
Differential Revision:	https://reviews.freebsd.org/D21521
2019-09-05 14:19:06 +00:00
Emmanuel Vadot
4c1a82cea5 pkgbase: Create a FreeBSD-utilities package and make it the default one
The default package use to be FreeBSD-runtime but it should only contain
binaries and libs enough to boot to single user and repair the system, it
is also very handy to have a package that can be tranform to a small mfsroot.
So create a new package named FreeBSD-utilities and make it the default one.
Also move a few binaries and lib into this package when it make sense.
Reviewed by:	bapt, gjb
Differential Revision:	https://reviews.freebsd.org/D21506
2019-09-05 14:15:47 +00:00
Emmanuel Vadot
8c15be73b6 pkgbase: Move rc scripts and related files to their own packages
It doesn't need to be in runtime and might help people who want to
experiment with other rc system or don't use one (like in small
embedded mfsroot).

Reviewed by:	bapt, gjb
Differential Revision:	https://reviews.freebsd.org/D21499
2019-09-05 14:08:45 +00:00
Warner Losh
10bb6d358d Report the Host Buffer Memory minimum and preferred sizes.
The Host Buffer feature (NVMe 1.4 section 89) allows for the NVMe card
request the host provide it buffer for lookaside tables and maybe
other things. Report the card's minimum and preferred sizes with
nvmecontrol/camcontrol identify.
2019-09-04 19:19:23 +00:00
Kyle Evans
f0298be018 bectl(8): implement sorting for 'bectl list' output
Allow 'bectl list' to sort output by a given property name. The property
name is passed in using a command-line flag, '-c' for ascending order and
'-C' for descending order. The properties allowed to sort by are:

- name (the default output, even if '-c' or '-C' are not used)
- creation
- origin
- used
- usedds
- usedsnap
- usedrefreserv

The default output for 'bectl list' is now ascending alphabetical order of
BE name.

To sort by creation time from earliest to latest, the command would be
'bectl list -c creation'

Submitted by:	Rob Fairbanks <rob.fx907 gmail com>
Reviewed by:	ler
MFC after:	1 week
Differential Revision:	https://reviews.freebsd.org/D20818
2019-09-04 13:59:06 +00:00
Xin LI
07282103f5 Correct overflow logic in fullpath().
Obtained from:	OpenBSD
MFC after:	3 days
2019-09-04 04:44:03 +00:00
Xin LI
cf955ebf6f Remove unneeded blank line. No functional change.
MFC after:	2 weeks
2019-08-30 06:06:12 +00:00
Alan Somers
95b523ea71 ping: raise WARNS level to 6
Submitted by:	Ján Sučan <sucanjan@gmail.com>
MFC after:	2 weeks
Sponsored by:	Google LLC (Google Summer of Code 2019)
Differential Revision:	https://reviews.freebsd.org/D21405
2019-08-27 15:34:37 +00:00
John Baldwin
b2e60773c6 Add kernel-side support for in-kernel TLS.
KTLS adds support for in-kernel framing and encryption of Transport
Layer Security (1.0-1.2) data on TCP sockets.  KTLS only supports
offload of TLS for transmitted data.  Key negotation must still be
performed in userland.  Once completed, transmit session keys for a
connection are provided to the kernel via a new TCP_TXTLS_ENABLE
socket option.  All subsequent data transmitted on the socket is
placed into TLS frames and encrypted using the supplied keys.

Any data written to a KTLS-enabled socket via write(2), aio_write(2),
or sendfile(2) is assumed to be application data and is encoded in TLS
frames with an application data type.  Individual records can be sent
with a custom type (e.g. handshake messages) via sendmsg(2) with a new
control message (TLS_SET_RECORD_TYPE) specifying the record type.

At present, rekeying is not supported though the in-kernel framework
should support rekeying.

KTLS makes use of the recently added unmapped mbufs to store TLS
frames in the socket buffer.  Each TLS frame is described by a single
ext_pgs mbuf.  The ext_pgs structure contains the header of the TLS
record (and trailer for encrypted records) as well as references to
the associated TLS session.

KTLS supports two primary methods of encrypting TLS frames: software
TLS and ifnet TLS.

Software TLS marks mbufs holding socket data as not ready via
M_NOTREADY similar to sendfile(2) when TLS framing information is
added to an unmapped mbuf in ktls_frame().  ktls_enqueue() is then
called to schedule TLS frames for encryption.  In the case of
sendfile_iodone() calls ktls_enqueue() instead of pru_ready() leaving
the mbufs marked M_NOTREADY until encryption is completed.  For other
writes (vn_sendfile when pages are available, write(2), etc.), the
PRUS_NOTREADY is set when invoking pru_send() along with invoking
ktls_enqueue().

A pool of worker threads (the "KTLS" kernel process) encrypts TLS
frames queued via ktls_enqueue().  Each TLS frame is temporarily
mapped using the direct map and passed to a software encryption
backend to perform the actual encryption.

(Note: The use of PHYS_TO_DMAP could be replaced with sf_bufs if
someone wished to make this work on architectures without a direct
map.)

KTLS supports pluggable software encryption backends.  Internally,
Netflix uses proprietary pure-software backends.  This commit includes
a simple backend in a new ktls_ocf.ko module that uses the kernel's
OpenCrypto framework to provide AES-GCM encryption of TLS frames.  As
a result, software TLS is now a bit of a misnomer as it can make use
of hardware crypto accelerators.

Once software encryption has finished, the TLS frame mbufs are marked
ready via pru_ready().  At this point, the encrypted data appears as
regular payload to the TCP stack stored in unmapped mbufs.

ifnet TLS permits a NIC to offload the TLS encryption and TCP
segmentation.  In this mode, a new send tag type (IF_SND_TAG_TYPE_TLS)
is allocated on the interface a socket is routed over and associated
with a TLS session.  TLS records for a TLS session using ifnet TLS are
not marked M_NOTREADY but are passed down the stack unencrypted.  The
ip_output_send() and ip6_output_send() helper functions that apply
send tags to outbound IP packets verify that the send tag of the TLS
record matches the outbound interface.  If so, the packet is tagged
with the TLS send tag and sent to the interface.  The NIC device
driver must recognize packets with the TLS send tag and schedule them
for TLS encryption and TCP segmentation.  If the the outbound
interface does not match the interface in the TLS send tag, the packet
is dropped.  In addition, a task is scheduled to refresh the TLS send
tag for the TLS session.  If a new TLS send tag cannot be allocated,
the connection is dropped.  If a new TLS send tag is allocated,
however, subsequent packets will be tagged with the correct TLS send
tag.  (This latter case has been tested by configuring both ports of a
Chelsio T6 in a lagg and failing over from one port to another.  As
the connections migrated to the new port, new TLS send tags were
allocated for the new port and connections resumed without being
dropped.)

ifnet TLS can be enabled and disabled on supported network interfaces
via new '[-]txtls[46]' options to ifconfig(8).  ifnet TLS is supported
across both vlan devices and lagg interfaces using failover, lacp with
flowid enabled, or lacp with flowid enabled.

Applications may request the current KTLS mode of a connection via a
new TCP_TXTLS_MODE socket option.  They can also use this socket
option to toggle between software and ifnet TLS modes.

In addition, a testing tool is available in tools/tools/switch_tls.
This is modeled on tcpdrop and uses similar syntax.  However, instead
of dropping connections, -s is used to force KTLS connections to
switch to software TLS and -i is used to switch to ifnet TLS.

Various sysctls and counters are available under the kern.ipc.tls
sysctl node.  The kern.ipc.tls.enable node must be set to true to
enable KTLS (it is off by default).  The use of unmapped mbufs must
also be enabled via kern.ipc.mb_use_ext_pgs to enable KTLS.

KTLS is enabled via the KERN_TLS kernel option.

This patch is the culmination of years of work by several folks
including Scott Long and Randall Stewart for the original design and
implementation; Drew Gallatin for several optimizations including the
use of ext_pgs mbufs, the M_NOTREADY mechanism for TLS records
awaiting software encryption, and pluggable software crypto backends;
and John Baldwin for modifications to support hardware TLS offload.

Reviewed by:	gallatin, hselasky, rrs
Obtained from:	Netflix
Sponsored by:	Netflix, Chelsio Communications
Differential Revision:	https://reviews.freebsd.org/D21277
2019-08-27 00:01:56 +00:00
Xin LI
b770b08061 Comment boot block checks and perform additional sanity checks:
The following checks are now being enforced:

 - bpbBytesPerSec: only accept 512, 1024, 2048 and 4096.
 - bpbSecPerClust: only accept 1, 2, 4, 8, 16, 32, 64 and 128.
 - bpbResSectors: require non-zero.
 - bpbFATs: require non-zero.
 - bpbSectors: require zero for FAT32.
 - bpbFATsmall: require zero for FAT32.
 - bpbHugeSectors: require non-zero for FAT32.

Bail out if the BPB contained values that do not meet these requirements.

We also require FATsecs * FATsecs to not overflow 32-bit unsigned
integer.

Check for backup boot block was removed because the checker does not take
corrective action, and msdosfs driver ignores it too.
2019-08-26 06:41:17 +00:00
Alan Somers
67511a4c4c ping: fix unaligned access to ancillary data
Use CMSG_FIRSTHDR rather than assume that an array is correctly aligned.
Fixes warnings on sparc64 and powerpcspe.

Submitted by:	Ján Sučan <sucanjan@gmail.com>
MFH:		2 weeks
Sponsored by:	Google LLC (Google Summer of Code 2019)
Differential Revision:	https://reviews.freebsd.org/D21406
2019-08-24 18:00:18 +00:00
Alan Somers
d9cacf605e ping: Fix alignment errors
This fixes -Wcast-align errors when compiled with WARNS=6.

Submitted by:	Ján Sučan <sucanjan@gmail.com>
MFC after:	2 weeks
Sponsored by:	Google LLC (Google Summer of Code 2019)
Differential Revision:	https://reviews.freebsd.org/D21327
2019-08-23 22:04:26 +00:00
Alan Somers
ec7ea489e0 ping: fix include guard symbol name to reflect the header file name
Submitted by:	Ján Sučan <sucanjan@gmail.com>
MFC after:	2 weeks
MFC-With:	351171
Sponsored by:	Google LLC (Google Summer of Code 2019)
Differential Revision:	https://reviews.freebsd.org/D21374
2019-08-23 15:24:18 +00:00
Alan Somers
208ae7b7b4 ping6: Rename options for better consistency with ping
Now equivalent options have the same flags, and nonequivalent options have
different flags.  This is a prelude to merging the two commands.

Submitted by:	Ján Sučan <sucanjan@gmail.com>
MFC:		Never
Sponsored by:	Google LLC (Google Summer of Code 2019)
Differential Revision:	https://reviews.freebsd.org/D21345
2019-08-23 15:22:20 +00:00
Alan Somers
299e2c58b7 ping: By default, don't reverse lookup IP addresses
ping's default is now not to attempt reverse DNS lookups.  The -H flag will
enable them.  This change is not quite a reversion of r351330.  That change
made the happy path and error path do reverse lookups consistently; this
change changes the default for both paths.

Submitted by:	Ján Sučan <sucanjan@gmail.com>
Discussed with:	cem
MFC after:	2 weeks
MFC-With:	351330
Sponsored by:	Google LLC (Google Summer of Code 2019)
Differential Revision:	https://reviews.freebsd.org/D21364
2019-08-22 18:57:24 +00:00
Alan Somers
8e0f76c8f4 ping6: add a basic functional test
Submitted by:	Ján Sučan <sucanjan@gmail.com>
MFC after:	2 weeks
Sponsored by:	Google, inc. (Google Summer of Code 2019)
Differential Revision:	https://reviews.freebsd.org/D21292
2019-08-22 15:08:04 +00:00
Alan Somers
7cc426fb42 ping: add a basic functional test
Submitted by:	Ján Sučan <sucanjan@gmail.com>
MFC after:	2 weeks
Sponsored by:	Google, inc. (Google Summer of Code 2019)
Differential Revision:	https://reviews.freebsd.org/D21289
2019-08-22 15:00:36 +00:00
Xin LI
aa9cb40e30 When creating a new FAT32 filesystem, use "unknown" (0xFFFFFFFF) for
FSI_Nxt_Free instead of providing a wrong value.

With this change, fsck_msdosfs would no longer complain about invalid
FSInfo information.

MFC after:	2 weeks
2019-08-22 06:14:06 +00:00
Alan Somers
99f13ae12c ping: add -H option for enabling reverse DNS lookup
This is the reverse of the -n flag.

Submitted by:	Ján Sučan <sucanjan@gmail.com>
Sponsored by:	Google LLC (Google Summer of Code 2019)
Differential Revision:	https://reviews.freebsd.org/D21356
2019-08-21 21:05:15 +00:00
Alan Somers
229e8bf2bb ping: do reverse DNS lookup of the target address
When printing replies, ping will now attempt a reverse DNS lookup of the
target.  That can be suppressed by using the "-n" option.  Curiously, ping
has always done reverse lookups in certain error paths, but never in the
success path.

Submitted by:	Ján Sučan <sucanjan@gmail.com>
MFC after:	2 weeks
Sponsored by:	Google LLC (Google Summer of Code 2019)
Differential Revision:	https://reviews.freebsd.org/D21351
2019-08-21 14:52:12 +00:00
Alan Somers
c43633c6a1 ping: Add tests of the Internet checksum function
Submitted by:	Ján Sučan <sucanjan@gmail.com>
MFC after:	2 weeks
Sponsored by:	Google LLC (Google Summer of Code 2019)
Differential Revision:	https://reviews.freebsd.org/D21340
2019-08-20 21:59:48 +00:00
Alan Somers
a3ce769851 Fix uninitialized variable warnings when MK_CASPER=no
Submitted by:	Ján Sučan <sucanjan@gmail.com>
MFC after:	2 weeks
Sponsored by:	Google, inc. (Google Summer of Code 2019)
Differential Revision:	https://reviews.freebsd.org/D21322
2019-08-19 17:54:40 +00:00
Alan Somers
7898770a26 ping: fix -Wformat-truncating warning with GCC
Increase buffer size for the string representation of n_time

ICMP timestamp is a 32-bit number. In pr_ntime(), number of minutes
and seconds is always 2 characters wide. Max. number of hours is 4
characters wide. The buffer size should be at least:

4 + 2 + 2 + 1 (':') + 1 (':') + 1 ('\0') = 11

Submitted by:	Ján Sučan <sucanjan@gmail.com>
MFC after:	2 weeks
Sponsored by:	Google, inc. (Google Summer of Code 2019)
Differential Revision:	https://reviews.freebsd.org/D21325
2019-08-19 17:28:12 +00:00
Alan Somers
818f498f29 ping6: revert r350857
Some socket options require root privileges to set.  The old code did indeed
drop privileges at the earliest opportunity.

Submitted by:	Ján Sučan <sucanjan@gmail.com>
MFC after:	Never
Sponsored by:	Google, Inc. (Google Summer of Code 2019)
Differential Revision:	https://reviews.freebsd.org/D21319
2019-08-19 14:20:26 +00:00
Xin LI
55d26365b1 Use calloc().
MFC after:	2 weeks
2019-08-19 05:24:42 +00:00
Xin LI
b9919ec960 Remove redundant check and wrong fix: fat.c checks already take care
about cluster chains.

Obtained from:	OpenBSD
MFC after:	2 weeks
2019-08-19 04:28:12 +00:00
Alan Somers
60df116853 ping6: Raise WARNS level to 6
Submitted by:	Ján Sučan <sucanjan@gmail.com>
MFC after:	2 weeks
Sponsored by:	Google, inc. (Google Summer of Code 2019)
Differential Revision:	https://reviews.freebsd.org/D21260
2019-08-17 17:22:08 +00:00
Alan Somers
ff77ab831a ping: Move in_cksum() to a separate source file
This is a preparation step for adding ATF tests of in_cksum(), which has been
modified to operate on unaligned data. ping.o cannot be linked to the test
executable because both of them contain 'main' symbol.

Submitted by:	Ján Sučan <sucanjan@gmail.com>
MFC after:	2 weeks
Sponsored by:	Google, inc. (Google Summer of Code 2019)
Differential Revision:	https://reviews.freebsd.org/D21288
2019-08-17 15:25:01 +00:00
Alan Somers
62da1eef7f ping6: Fix dnsdecode() bug introduced by r350859
Revision 350859 removed level of indirection that was needed for setting the
caller's `cp' pointer. dnsdecode() uses return value to indicate error or
success. It returns pointer to a buffer holding a decompressed DNS name or
NULL. The caller uses that value only to find out the result, not for accessing
the buffer.

We use the return value to propagate the new value of `cp' pointer to
the caller instead of using an output argument.

Submitted by:	Ján Sučan <sucanjan@gmail.com>
MFC after:	2 weeks
MFC-With:	350859
Sponsored by:	Google, Inc (Google Summer of Code 2019)
Differential Revision:	https://reviews.freebsd.org/D21266
2019-08-17 14:28:32 +00:00
Eric Joyner
f4aa9b67eb net: Update SFF-8024 definitions and strings with values from rev 4.6
This will let ifconfig -v's SFF eeprom read functionality recognize more
module types.

Signed-off-by: Eric Joyner <erj@freebsd.org>

Reviewed by:	gallatin@
MFC after:	1 week
Sponsored by:	Intel Corporation
Differential Revision:	https://reviews.freebsd.org/D21041
2019-08-17 00:10:56 +00:00
Alan Somers
2933651bf4 ping6: Fix alignment errors
This fixes -Wcast-align errors when compiled with WARNS=6.

Submitted by:	Ján Sučan <sucanjan@gmail.com>
MFC after:	2 weeks
Sponsored by:	Google, inc. (Google Summer of Code 2019)
Differential Revision:	https://reviews.freebsd.org/D21217
2019-08-15 19:52:32 +00:00
Alan Somers
8a3107c8f3 ping6: fix uninitialized variable warnings when MK_CASPER=no
Submitted by:	Ján Sučan <sucanjan@gmail.com>
MFC after:	2 weeks
Sponsored by:	Google, inc. (Google Summer of Code 2019)
Differential Revision:	https://reviews.freebsd.org/D21273
2019-08-15 19:27:36 +00:00
Alan Somers
0b894a06bd ping6: Fix data type of the buffer for ancillary data of a received message
The old code worked, but wasted some stack space.

Submitted by:	Ján Sučan <sucanjan@gmail.com>
MFC after:	2 weeks
Sponsored by:	Google, inc. (Google Summer of Code 2019)
Differential Revision:	https://reviews.freebsd.org/D21275
2019-08-15 17:24:10 +00:00
John-Mark Gurney
a521fa63c2 finish the pcp feature, but documenting it in the man page... 2019-08-15 16:58:00 +00:00
Alan Somers
631b873cd8 ping6: fix uninitialized variable warning for intvl
GCC isn't smart enough to realize that this variable was always initialized.

Submitted by:	Ján Sučan <sucanjan@gmail.com>
MFC after:	2 weeks
Sponsored by:	Google, inc. (Google Summer of Code 2019)
Differential Revision:	https://reviews.freebsd.org/D21271
2019-08-15 16:09:27 +00:00
Alan Somers
899ecf0904 ping6: quiet an undefined variable warning
GCC 4.2 isn't smart enough to know that this variable is already defined by
the time it's used.

Submitted by:	Ján Sučan <sucanjan@gmail.com>
MFC after:	2 weeks
Sponsored by:	Google, inc. (Google Summer of Code 2019)
Differential Revision:	https://reviews.freebsd.org/D21269
2019-08-15 15:55:01 +00:00
Alan Somers
dab7253c41 ping6: quiet warning about unused copyright variable
Submitted by:	Ján Sučan <sucanjan@gmail.com>
MFC after:	2 weeks
Sponsored by:	Google, inc. (Google Summer of Code 2019)
Differential Revision:	https://reviews.freebsd.org/D21270
2019-08-15 15:49:01 +00:00
Doug Moore
504f5e294e swap_pager.c reserves 2 blocks for a bsd label. Change that 2 to the
expression howmany(BBSIZE, PAGE_SIZE), where BBSIZE is the size of the
boot block area.  That can be less than 2 if PAGE_SIZE is big.

swapon(8) has an option to trim (delete) all the blocks of a device at
startup.  However, if the first of those blocks is a bsd label, then
trimming those blocks is destructive.  Change swapon to leave the
first BBSIZE bytes untrimmed.

Update manual pages to reflect changes in how swapon and how it may be
used, espeically in association with savecore.

Reviewed by: alc
Approved by: markj (mentor)
MFC after: 3 days
Differential Revision: https://reviews.freebsd.org/D21191
2019-08-15 02:30:44 +00:00
Alexander Motin
4035e778f8 Print few more useful identify fields.
MFC after:	2 weeks
2019-08-14 17:36:26 +00:00
Alan Somers
d63a94876b ping: Make in_cksum() operate on u_char buffer
This fixes -Wcast-align errors for in_cksum() calls when compiled with
WARNS=6.

Submitted by:	Ján Sučan <sucanjan@gmail.com>
MFC after:	2 weeks
Sponsored by:	Google, inc. (Google Summer of Code 2019)
Differential Revision:	https://reviews.freebsd.org/D21261
2019-08-14 16:55:06 +00:00
Alan Somers
84633ef14a ping: fix triptime calculation after r350998
That revision changed the internal clock to the monotonic, but neglected to
change the datagram's timestamp source.

Reported by:	Oliver Hartmann, Michael Butler
Reviewed by:	Ján Sučan <sucanjan@gmail.com>, allanjude
MFC after:	2 weeks
MFC-With:	r350998
Differential Revision:	https://reviews.freebsd.org/D21258
2019-08-14 16:45:09 +00:00
Conrad Meyer
ac8e5d02cf Remove deprecated GEOM classes
Follow-up on r322318 and r322319 and remove the deprecated modules.

Shift some now-unused kernel files into userspace utilities that incorporate
them.  Remove references to removed GEOM classes in userspace utilities.

Reviewed by:	imp (earlier version)
Sponsored by:	Dell EMC Isilon
Differential Revision:	https://reviews.freebsd.org/D21249
2019-08-13 20:06:55 +00:00
Alan Somers
1ad76f1b60 ping: use the monotonic clock to measure durations
Submitted by:	Ján Sučan <sucanjan@gmail.com>
MFC after:	2 weeks
Sponsored by:	Google, inc. (Google Summer of Code 2019)
Differential Revision:	https://reviews.freebsd.org/D21245
2019-08-13 19:27:23 +00:00
Alan Somers
42bf965528 ping6: use the monotonic clock to measure durations
Submitted by:	Ján Sučan <sucanjan@gmail.com>
MFC after:	2 weeks
Sponsored by:	Google, inc. (Google Summer of Code 2019)
Differential Revision:	https://reviews.freebsd.org/D21226
2019-08-13 19:24:17 +00:00
Alan Somers
2c29d74c4f ping: fix data type of a variable for a packet sequence number
Submitted by:	Ján Sučan <sucanjan@gmail.com>
MFC after:	2 weeks
Sponsored by:	Google, inc. (Google Summer of Code 2019)
Differential Revision:	https://reviews.freebsd.org/D21244
2019-08-13 16:25:23 +00:00
Alan Somers
354c349080 Consistently use the byteorder functions in the correct direction
Though ntohs and htons are functionally identical, they have different meanings.Using the correct one helps to document the code.

Submitted by:	Ján Sučan <sucanjan@gmail.com>
MFC after:	2 weeks
Sponsored by:	Google, inc. (Google Summer of Code 2019)
Differential Revision:	https://reviews.freebsd.org/D21219
2019-08-13 16:22:43 +00:00
Alan Somers
5e9c6b7239 ping6: Fix data type of a variable for a packet sequence number
Submitted by:   Ján Sučan <sucanjan@gmail.com>
MFC after:      2 weeks
Sponsored by:   Google, inc. (Google Summer of Code 2019)
Differential Revision:  https://reviews.freebsd.org/D21218
2019-08-13 15:30:29 +00:00
Alan Somers
17e49888f6 ping6: Fix data type of a variable for a packet sequence number
Submitted by:	Ján Sučan <sucanjan@gmail.com>
MFC after:	2 weeks
Sponsored by:	Google, inc. (Google Summer of Code 2019)
Sponsored by:	The FreeBSD Foundation
Differential Revision:	https://reviews.freebsd.org/D21218
2019-08-12 19:14:11 +00:00
Alan Somers
401d89a9e2 ping6: Remove unnecessary level of indirection from dnsdecode() parameter
The `sp' pointer doesn't need to be modified in the caller of
dnsdecode().

This fixes -Wcast-qual error (`must have all intermediate pointers
const qualified to be safe') when compiled with WARNS=6.

Submitted by:	Ján Sučan <sucanjan@gmail.com>
MFC after:	2 weeks
Sponsored by:	Google, inc. (Google Summer of Code 2019)
Differential Revision:	https://reviews.freebsd.org/D21215
2019-08-11 15:36:18 +00:00
Alan Somers
5e35df9474 ping6: Add missing static keyword for a global variable
This fixes -Wmissing-variable-declarations error when compiled with
WARNS=6.

Submitted by:	Ján Sučan <sucanjan@gmail.com>
MFC after:	2 weeks
Sponsored by:	Google, inc. (Google Summer of Code 2019)
Differential Revision:	https://reviews.freebsd.org/D21214
2019-08-11 15:27:34 +00:00
Alan Somers
0ef7ac044a ping6: Revoke root privilege earlier
It can be done just after the sockets have been created.

Submitted by:	Ján Sučan <sucanjan@gmail.com>
MFC after:	2 weeks
Sponsored by:	Google, inc. (Google Summer of Code 2019)
Differential Revision:	https://reviews.freebsd.org/D21213
2019-08-11 15:22:53 +00:00
Mark Johnston
d4c8b7594f Fix formatting.
PR:		239726
Submitted by:	Gordon Bergling <gbergling@gmail.com>
MFC after:	3 days
2019-08-08 20:56:52 +00:00
Kirk McKusick
47d3e2f83b Correct the location of the first backup superblock in fsck_ffs.8.
Make a note in the newfs.8 manual page to update the first backup
superblock location when changing the default fragment size for
the filesystem.

Reported by:  O. Hartmann
2019-08-07 16:56:00 +00:00