Commit Graph

10278 Commits

Author SHA1 Message Date
Alexander V. Chernikov
444b9aa78c ifconfig: fix family selection after 982cd5ae8e 2023-05-10 12:40:51 +00:00
Alexander V. Chernikov
a3cb80bc63 ifconfig: fix interface selection after 982cd5ae8e. 2023-05-10 12:22:39 +00:00
Alexander V. Chernikov
982cd5ae8e ifconfig: split argument parsing and actual execution logic
Reduce the amount of global variables by creating the dedicated
 ifconfig_args structure and use it as a context-passing variable.
Simplify the code by moving all argument preparation code a
 separate function.

Reviewed by: kp (previous version)
Differential Revision: https://reviews.freebsd.org/D39932
MFC after:	2 weeks
2023-05-10 10:39:12 +00:00
Dag-Erling Smørgrav
facc213643 md5: Don't increment a bool.
Fixes:		4849767cb1
MFC after:	1 week
Sponsored by:	Klara, Inc.
Reviewed by:	kevans
Differential Revision:	https://reviews.freebsd.org/D40020
2023-05-10 09:25:21 +00:00
Dag-Erling Smørgrav
90eaf4b2f9 md5: Include <osreldate.h> for __FreeBSD_version.
It is usually provided by <sys/param.h>, but not when bootstrapping.

Fixes:		4849767cb1
MFC after:	1 week
Sponsored by:	Klara, Inc.
Reviewed by:	yuripv, kevans
Differential Revision:	https://reviews.freebsd.org/D40018
2023-05-10 09:25:21 +00:00
Dag-Erling Smørgrav
f1ceb05a46 md5: Fix input error check.
Fixes:		4849767cb1
MFC after:	1 week
Sponsored by:	Klara, Inc.
Reviewed by:	tsoome, kevans, lwhsu
Differential Revision:	https://reviews.freebsd.org/D40017
2023-05-10 09:25:21 +00:00
Kirk McKusick
b3fe5d9322 Fix off-by-one error in fsck_ffs(8) chkrange() block-number check.
On an amd64-CURRENT machine with an i-node that refers to a block
number that is one too large will cause a core dump, due to writing
beyond the end of blockmap[] and corrupting the next heap block,
which happens to contain a struct inoinfo in inphash[]. Note that
valgrind catches the blockmap[] access.

Reported by:  Robert Morris
PR:           271289
MFC after:    1 week
Sponsored by: The FreeBSD Foundation
2023-05-09 13:08:10 -07:00
Mateusz Piotrowski
794f5122bb geom.8: Fix typos and wordsmith
MFC after:	3 days
2023-05-09 16:20:13 +02:00
Dag-Erling Smørgrav
4849767cb1 md5: Improve compatibility.
* Overhaul the GNU compatibility mode to more closely emulate what the GNU tools do.

* Add a Perl compatibility mode which emulates the shasum tool that ships with Perl.  This is currently not installed.

* Overhaul the tests.

Sponsored by:	Klara, Inc.
Reviewed by:	kevans
Differential Revision:	https://reviews.freebsd.org/D39446
2023-05-08 06:56:22 +00:00
Simon J. Gerraty
b75d7e2cbe md5 Makefile.depend.host 2023-05-04 12:03:34 -07:00
Chuck Silvers
4064755812 fsck_ffs: fix the previous change that skipped pass 5 in some cases
The previous change involved calling check_cgmagic() twice in a row
for the same CG in order to differentiate when the CG was already ok vs.
when the CG was rebuilt, but that doesn't work because the second call
(which was supposed to rebuild the CG) returns 0 (indicating that
the CG was not rebuilt) due to the prevfailcg check causing an early
failure return.  Fix this by moving the rebuild part of check_cgmagic()
out into a separate function which is called by pass1() when it wants to
rebuild a CG.

Fixes: da86e7a20d
Reported by:	pho
Discussed with:	mckusick
Sponsored by:	Netflix
2023-05-03 13:31:32 -07:00
Mateusz Guzik
a50ef47c0a newfs: fix up 32-bit compile
Sponsored by:	Rubicon Communications, LLC ("Netgate")
2023-04-30 18:00:20 +00:00
Kirk McKusick
2e7797cd9b Yet another try to fix printf format conflict.
I find it very annoying that there is no FreeBSD infrastructure to
determine failures across architectures other than to check in
changes and then have Jenkins find them.

Suggested by: Jessica Clarke
MFC after:    1 week
2023-04-30 00:00:23 -07:00
Kirk McKusick
6995e6b323 Fix printf format conflict
MFC after:   1 week
2023-04-29 17:55:15 -07:00
Kirk McKusick
62dc21b107 Additional validity checking in newfs(8).
A check in the superblock validity code verifies that the computed
size of the filesystem cylinder groups (CGSIZE macro) does not
exceed the filesystem block size (fs_bsize).

A report was received that a filesystem had been flagged as failing
this check. We were unable to determine how the reported filesystem
could have been created. This commit adds a check at the end of the
newfs(8) command to verify that the the cylinder group size is valid.
If an oversize cylinder group is found newfs(8) prints a diagnostic
output and rebuilds the filesystem to make it compiliant.

MFC after:   1 week
2023-04-29 17:01:18 -07:00
Kirk McKusick
04997e19e2 Additional output from dumpfs(8).
Provide an additional line of output for the superblock giving the
computed size of the cylinder group (CGSIZE macro) along with the
details needed to calculate it.

MFC after:   1 week
2023-04-29 17:01:18 -07:00
Alexander V. Chernikov
30d7e724db route: show originator PID in netlink monitor
Replacing rtsock with netlink also means providing similar tracing facilities,
rtsock provides `route -n monitor` interface, where each message can be traced
to the originating PID.
This diff closes the feature gap between rtsock and netlink in that regard.

Netlink works slightly differently from rtsock, as it is a generic message
"broker". It calls some kernel KPIs and returns the result to the caller.
Other Netlink consumers gets notified on the changed kernel state using the
relevant subsystem callbacks. Typically, it is close to impossible to pass
some data through these KPIs to enhance the notification.

This diff approaches the problem by using osd(9) to assign the relevant
socket pointer (`'nlp`) to the per-socket taskqueue execution thread.
This change allows to recover the pointer in the aforementioned notification
callbacks and extract some additional data.
Using `osd(9)` (and adding additional metadata) to the notification receiver
comes with some additional cost attached, so this interface needs to be
enabled explicitly by using a newly-created `NETLINK_MSG_INFO` `SOL_NETLINK`
socket option.

The actual medatadata (which includes the originator PID) is provided via
control messages. To enable extensibility, the control message data is
encoded in the standard netlink(TLV-based) fashion. The list of the
currently-provided properties can be found in `nlmsginfo_attrs`.
snl(3) is extended to enable decoding of netlink messages with metadata
(`snl_read_message_dbg()` stores the parsed structure in the provided buffer).

Differential Revision: https://reviews.freebsd.org/D39391
2023-04-28 13:54:54 +00:00
Kristof Provost
9ec48bc31e pfctl: match expand_label_addr() prototype to definition
Sponsored by:	Rubicon Communications, LLC ("Netgate")
2023-04-26 17:09:46 +02:00
Christian McDonald
ef661d4a5b pf: introduce ridentifier and labels to ether rules
Make Ethernet rules more similar to the usual layer 3 rules by also
allowing ridentifier and labels to be set on them.

Reviewed by:	kp
Sponsored by:	Rubicon Communications, LLC ("Netgate")
2023-04-26 11:14:41 +02:00
Kyle Evans
3a5855dd22 gbde: stop rebuilding sha512 bits
In the early days of gbde, it linked against libmd.  Shortly after
conception, phk replaced ARC4 with SHA-512, but libmd did not have SHA2
at the time thus he built a copy of sha2.c for gbde.

Fast forward 3 years, cperciva adds SHA2 to libmd -- this makes gbde's
build of sha2.c redundant, but it's (understandably) overlooked.  Let's
simplify the gbde build now and just assume that libmd includes the most
optimal implementation.

Reported by:	koobs (weird lto errors?)
Differential Revision:	https://reviews.freebsd.org/D34668
2023-04-26 00:36:33 -05:00
Kyle Evans
4163bae030 bectl: document the -r flag to bectl
Independent of all of the commands, bectl itself takes an `-r` flag that
specifies the BE root to use.  This was originally added to facilitate
testing, but it was later discovered to be incredibly useful in other
scenarios; e.g., trying to recover some boot environments in rescue
media.

The "BE root" described here is the parent dataset that holds boot
environments, but I've no idea if that's an accepted definition for that
dataset.

Reviewed by:	gallatin, imp, Pau Amma
MFC after:	1 week
Differential Review:	https://reviews.freebsd.org/D39710
2023-04-26 00:33:25 -05:00
Boris Lytochkin
fc727ad63d ipfw: add [fw]mark implementation for ipfw
Packet Mark is an analogue to ipfw tags with O(1) lookup from mbuf while
regular tags require a single-linked list traversal.
Mark is a 32-bit number that can be looked up in a table
[with 'number' table-type], matched or compared with a number with optional
mask applied before comparison.
Having generic nature, Mark can be used in a variety of needs.
For example, it could be used as a security group: mark will hold a security
group id and represent a group of packet flows that shares same access
control policy.

Reviewed By: pauamma_gundo.com
Differential Revision: https://reviews.freebsd.org/D39555
MFC after:	1 month
2023-04-25 12:40:23 +00:00
Eugene Grosbein
9f5dc374d0 ipfw.8: improve description for interface matching
The manual describes "if*" form only while kernel uses fnmatch(3)
and allows use for more versatile shell-like patterns.
Note that explicitly and provide an example.

MFC after:	3 days
2023-04-25 18:16:22 +07:00
John Baldwin
0a04bb7a4f fdisk: Use valid prototypes for function declarations with no arguments.
Reviewed by:	emaste
Differential Revision:	https://reviews.freebsd.org/D39726
2023-04-24 08:53:49 -07:00
Bjoern A. Zeeb
e17944a821 ath10k: ath11k: ammend devd.conf regex
In order to match these drivers, and in expectiation of ath12k
happening add ath[0-9]+k to the regex pattern for wlan devices.

MFC after:	2 months
2023-04-23 21:31:07 +00:00
Bjoern A. Zeeb
88e71cc06d mt76: devd: add support for mt79* wireless drivers to devd.conf
Add the "mt79" to the regex for wireless drivers in devd.conf so
that they get handled as expected.

MFC after:	2 months
2023-04-23 21:31:07 +00:00
Kristof Provost
dbce131b8f pfctl: match geticmpcodeby*()/print_fromto() prototypes to definitions
The definitions use sa_family_t, not u_int8_t.

Sponsored by:	Rubicon Communications, LLC ("Netgate")
2023-04-22 19:43:56 +02:00
Kristof Provost
5e3bb05147 pfctl: remove unneeded includes
We don't use nvlists (directly) or sysctls, so there's no need to
include the headers.

Sponsored by:	Rubicon Communications, LLC ("Netgate")
2023-04-22 19:43:55 +02:00
Simon J. Gerraty
d9a4274795 Update/fix Makefile.depend for userland 2023-04-18 17:14:23 -07:00
Kirk McKusick
da86e7a20d Skip Pass 5 in fsck_ffs(8) when corrupt cylinder groups remain unfixed.
Pass 1 of fsck_ffs checks the integrity of all the cylinder groups.
If any are found to have been corrupted it offers to rebuild them.
Pass 5 then makes a second pass over the cylinder groups to validate
their block and inode maps. Pass 5 assumes that the cylinder groups
are not corrupted and can segment fault if they are corrupted. Rather
than rerunning the corruption checks a second time in pass 5, this
fix keeps track whether any corrupt cylinder groups were found but not
fixed in pass 1 either due to running with the -n flag or by explicitly
answering `no' when asked whether to fix a corrupted cylinder group.
If any corrupted cylinder groups remain after pass 1, fsck_ffs will
decline to run pass 5. Instead it marks the filesystem as unclean
so that fsck_ffs will need to be run again before the filesystem can
be mounted.

This patch cleans up and documents the return value from check_cgmagic().
It also renames the variable / parameter "rebuildcg" to "rebuiltcg".
This parameter describes whether the cylinder group has been rebuilt
rather than whether it should be rebuilt.

Reported by: Chuck Silvers
Reviewed by: Chuck Silvers
MFC after:   1 week
2023-04-18 16:13:26 -07:00
Kirk McKusick
18746531a8 Bug fixes for fsck_ffs(8).
Increment a reference count when returning a zero'ed out buffer
after a failed read.

Zero out a structure before using it.

Only dirty a buffer that has been modified.

Submitted by: Chuck Silvers
Sponsored by: Netflix
MFC after:    1 week
2023-04-18 16:13:26 -07:00
Kirk McKusick
7636973c68 Add `chdb' command to fsdb(8) to set direct block numbers.
Add the ability to set direct blocks numbers in inodes so that manual
corrections can be made. No checking of the values is attempted so
accidental or deliberate bad values can be set.

Submitted by: Chuck Silvers
MFC after:    1 week
2023-04-18 16:13:26 -07:00
John Baldwin
2ac057dd33 ipf: Use C89 function definitions.
Reviewed by:	zlei
Differential Revision:	https://reviews.freebsd.org/D39523
2023-04-18 11:22:28 -07:00
Gordon Bergling
c2a9d23736 mount_nfs.8: Fix a mandoc warning
- sections out of conventional order: Sh IMPLEMENTATION NOTES

MFC after:	3 days
2023-04-18 09:14:20 +02:00
Stephen J. Kiernan
88a3358ea4 veriexec: Add SPDX-License-Identifier 2023-04-16 21:23:00 -04:00
Stephen J. Kiernan
1c7ac0c23b veriexec: fix use of getopt
getopt(3) returns int type not char. Using char triggers the
-Wtautological-constant-out-of-range-compare warning with clang.
Change the type of the variable used for holding the return value
of getopt(3) to int to match the prototype and eliminate the warning.

MFC after:	1 week
2023-04-16 21:02:04 -04:00
Stephen J. Kiernan
2e6a433811 veriexec: allow sha512 fingerprint in manifest parser
MAC/veriexec already supports SHA512 fingerprints, therefore the
veriexec program should also.

Reviewed by:	sjg
2023-04-16 19:25:27 -04:00
Kajetan Staszkiewicz
39282ef356 pf: backport OpenBSD syntax of "scrub" option for "match" and "pass" rules
Introduce the OpenBSD syntax of "scrub" option for "match" and "pass"
rules and the "set reassemble" flag. The patch is backward-compatible,
pf.conf can be still written in FreeBSD-style.

Obtained from:	OpenBSD
MFC after:	never
Sponsored by:	InnoGames GmbH
Differential Revision:	https://reviews.freebsd.org/D38025
2023-04-14 09:04:06 +02:00
Reid Linnemann
f0311046a0 ifconfig: change carp commands mcast and mcast6 to DEF_CMD as they take no args
Reviewed by:	kp
Sponsored by:	Rubicon Communications, LLC ("Netgate")
Differential Revision:	https://reviews.freebsd.org/D39548
2023-04-13 09:18:18 +02:00
Rick Macklem
61330e494f mount_nfs.8: Update man page for the "syskrb5" option
Commit 896516e54a added a new NFS mount option
used for Kerberized NFSv4.1/4.2 mounts. It specifies that
AUTH_SYS be used for state maintenance (also called system)
operations. This allows the mount to be done without the
"gssname" option or a valid Kerberos TGT being held by the
user doing the mount (so it can be specified in fstab(5) for
example).

Reviewed by:	gbe (manpages), karels
MFC after:	3 months
Differential Revision:	https://reviews.freebsd.org/D39469
2023-04-11 12:17:09 -07:00
Rob Norris
461ccb55d5 dhclient: add ability to ignore options in offers
A machine might exist on multiple networks, all of which offer, say, default
routes or name servers. There's no easy way to indicate in the config
that those options are only valid for a single interface.

Now, we can write:

    interface "lan0" {
      request routers;
      require routers;
    }
    interface "lan1" {
      ignore routers;
    }

And only take action on default routes offered on lan0.

Tested by:	Jose Luis Duran <jlduran at gmail dot com>
MFC after:	2 months
Reviewed by:	allanjude, imp
Sponsored by:	Zenith Electronics LLC
Sponsored by:	Klara, Inc.
Pull Request:	#693
2023-04-10 23:13:18 +00:00
Alexander V. Chernikov
351e4592f6 route: remove always-true expression 2023-04-09 10:04:56 +00:00
Alexander V. Chernikov
091fec1188 route: switch transport protocol to Netlink.
All known bugs have been fixed, try to enable Netlink once again.
2023-04-08 18:02:57 +00:00
Alexander V. Chernikov
ee8f5c2a31 route: fix netlink route operations with link-local gw / dst.
Extract ifindex from either gw or dst sockaddr and add it as a
 dedicated RTA_OIF attribute.
2023-04-08 11:38:05 +00:00
Zhenlei Huang
09e5e3d598 ifconfig: Fix configuring if_bridge with additional operating parameters
For clone create and rename operations, the interface name get back can be
different from the one passed to ioctl(). Use the interface name we get back
so that ifconfig will not return unexpected ENXIO.

PR:		270618
Reviewed by:	kp
MFC after:	3 days
Differential Revision:	https://reviews.freebsd.org/D39396
2023-04-07 22:25:41 +08:00
Alexander V. Chernikov
f262b06a57 route: fix route get netlink translation.
route.c uses newroute() to handle the "route get" command. The logic
 inside newroute() adds RTF_GATEWAY flag if "-interface" flag is not
 specified. That results in the inconsistent RTM_GET message with
 RTF_GATEWAY set but no RTAX_GATEWAY provided. Address this in the
 translation code by checking if the gateway is actually provided.
2023-04-04 08:42:33 +00:00
Konstantin Belousov
bef81bc0ae setkey(8): ansify parser
Sponsored by:	NVidia networking
MFC after:	1 week
2023-04-03 22:48:49 +03:00
Konstantin Belousov
462c3d3cf4 setkey(8): remove redundand returns
Sponsored by:	NVidia networking
MFC after:	1 week
2023-04-03 22:48:49 +03:00
Konstantin Belousov
3cb808226c setkey(8): add -e option to take script from the command line
Reviewed by:	ae
Sponsored by:	Nvidia networking
MFC after:	1 week
Differential revision:	https://reviews.freebsd.org/D39393
2023-04-03 22:48:48 +03:00
Martin Matuska
2a58b312b6 zfs: merge openzfs/zfs@431083f75
Notable upstream pull request merges:
  #12194 Fix short-lived txg caused by autotrim
  #13368 ZFS_IOC_COUNT_FILLED does unnecessary txg_wait_synced()
  #13392 Implementation of block cloning for ZFS
  #13741 SHA2 reworking and API for iterating over multiple implementations
  #14282 Sync thread should avoid holding the spa config write lock
         when possible
  #14283 txg_sync should handle write errors in ZIL
  #14359 More adaptive ARC eviction
  #14469 Fix NULL pointer dereference in zio_ready()
  #14479 zfs redact fails when dnodesize=auto
  #14496 improve error message of zfs redact
  #14500 Skip memory allocation when compressing holes
  #14501 FreeBSD: don't verify recycled vnode for zfs control directory
  #14502 partially revert PR 14304 (eee9362a7)
  #14509 Fix per-jail zfs.mount_snapshot setting
  #14514 Fix data race between zil_commit() and zil_suspend()
  #14516 System-wide speculative prefetch limit
  #14517 Use rw_tryupgrade() in dmu_bonus_hold_by_dnode()
  #14519 Do not hold spa_config in ZIL while blocked on IO
  #14523 Move dmu_buf_rele() after dsl_dataset_sync_done()
  #14524 Ignore too large stack in case of dsl_deadlist_merge
  #14526 Use .section .rodata instead of .rodata on FreeBSD
  #14528 ICP: AES-GCM: Refactor gcm_clear_ctx()
  #14529 ICP: AES-GCM: Unify gcm_init_ctx() and gmac_init_ctx()
  #14532 Handle unexpected errors in zil_lwb_commit() without ASSERT()
  #14544 icp: Prevent compilers from optimizing away memset()
         in gcm_clear_ctx()
  #14546 Revert zfeature_active() to static
  #14556 Remove bad kmem_free() oversight from previous zfsdev_state_list
         patch
  #14563 Optimize the is_l2cacheable functions
  #14565 FreeBSD: zfs_znode_alloc: lock the vnode earlier
  #14566 FreeBSD: fix false assert in cache_vop_rmdir when replaying ZIL
  #14567 spl: Add cmn_err_once() to log a message only on the first call
  #14568 Fix incremental receive silently failing for recursive sends
  #14569 Restore ASMABI and other Unify work
  #14576 Fix detection of IBM Power8 machines (ISA 2.07)
  #14577 Better handling for future crypto parameters
  #14600 zcommon: Refactor FPU state handling in fletcher4
  #14603 Fix prefetching of indirect blocks while destroying
  #14633 Fixes in persistent error log
  #14639 FreeBSD: Remove extra arc_reduce_target_size() call
  #14641 Additional limits on hole reporting
  #14649 Drop lying to the compiler in the fletcher4 code
  #14652 panic loop when removing slog device
  #14653 Update vdev state for spare vdev
  #14655 Fix cloning into already dirty dbufs
  #14678 Revert "Do not hold spa_config in ZIL while blocked on IO"

Obtained from:	OpenZFS
OpenZFS commit:	431083f75b
2023-04-03 16:49:30 +02:00
Zhenlei Huang
28b498e65a ifconfig: Improve VLAN identifier parsing
VLAN identifier 0xFFF is reserved. It must not be configured or
transmitted.

Also validate during parsing to prevent potential integer overflow.

Reviewed by:	#network, melifaro
Fixes:		c7cffd65c5 Add support for stacked VLANs (IEEE 802.1ad, AKA Q-in-Q)
MFC after:	1 week
Differential Revision:	https://reviews.freebsd.org/D39282
2023-04-03 01:54:31 +08:00
Alexander V. Chernikov
25b86f8559 ping: fix failing test_pinger[_3_1_verbose_false] test. 2023-04-02 14:10:16 +00:00
Alexander V. Chernikov
68f9e13563 route: add support for exact-prefix-match via netlink. 2023-04-02 13:50:05 +00:00
Andrew Gallatin
588f03ec9b bectl: Improve error message when ZFS root is not found.
When recovering a system that is unbootable due to some
problem with the active BE, it is likely you'll be booted
from a rescue image running UFS.  In this case, bectl
needs help finding the zpool root that you want to operate
on.  In this case, improve the error message to suggest
specifying a root, rather than just emitting a generic
error message that might imply, to the naive user, that
there is a ZFS compatibility issue between the rescue
image and the on-disk ZFS pool.

Reviewed by: imp, kevans
Sponsored by: Netflix
Differential Revision:	https://reviews.freebsd.org/D39346
2023-03-31 10:27:38 -04:00
Alexander V. Chernikov
140ddeba08 route: try to autoload netlink(4) module if not present in the kernel.
Differential Revision: https://reviews.freebsd.org/D39324
2023-03-30 09:53:06 +00:00
Kirk McKusick
fe5e6e2cc5 Improvement in UFS/FFS directory placement when doing mkdir(2).
The algorithm for laying out new directories was devised in the 1980s
and markedly improved the performance of the filesystem. In those days
large disks had at most 100 cylinder groups and often as few as 10-20.
Modern multi-terrabyte disks have thousands of cylinder groups. The
original algorithm does not handle these large sizes well. This change
attempts to expand the scope of the original algorithm to work well
with these much larger disks while still retaining the properties
of the original algorithm for small disks.

The filesystem implementation is divided into policy routines and
implementation routines. The policy routines can be changed in any
way desired without risk of corrupting the filesystem. The policy
requests are handled by the implementation layer. If the policy
asks for an available resource, it is granted. But if it asks for
an already in-use resource, then the implementation will provide
an available one nearby the request. Thus it is impossible for a
policy to double allocate. This change is limited to the policy
implementation.

This change updates the ffs_dirpref() routine which is responsible
for selecting the cylinder group into which a new directory should
be placed. If we are near the root of the filesystem we aim to
spread them out as much as possible. As we descend deeper from the
root we cluster them closer together around their parent as we
expect them to be more closely interactive. Higher-level directories
like usr/src/sys and usr/src/bin should be separated while the
directories in these areas are more likely to be accessed together
so should be closer. And directories within commands or kernel
subsystems should be closer still.

We pick a range of cylinder groups around the cylinder group of the
directory in which we are being created. The size of the range for
our search is based on our depth from the root of our filesystem.
We then probe that range based on how many directories are already
present. The first new directory is at 1/2 (middle) of the range;
the second is in the first 1/4 of the range, then at 3/4, 1/8, 3/8,
5/8, 7/8, 1/16, 3/16, 5/16, etc.

It is desirable to store the depth of a directory in its on-disk
inode so that it is available when we need it. We add a new field
di_dirdepth to track the depth of each directory. Because there are
few spare fields left in the inode, we choose to share an existing
field in the inode rather than having one of our own. Specifically
we create a union with the di_freelink field. The di_freelink field
is used to track inodes that have been unlinked but remain referenced.
It is not needed until a rmdir(2) operation has been done on a
directory. At that point, the directory has no contents and even
if it is kept active as a current directory is no longer able to
have any new directories or files created in it. Thus the use of
di_dirdepth and di_freelink will never coincide.

Reported by:  Timo Voelker
Reviewed by:  kib
Tested by:    Peter Holm
MFC after:    2 weeks
Sponsored by: The FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D39246
2023-03-29 21:13:27 -07:00
Eric van Gyzen
3bbd1a1a00 camcontrol powermode: fix use-after-free
Free the ccb after processing the response therein.

Reported by:	Coverity
Fixes:		3bed0179ee
MFC after:	1 week
Sponsored by:	Dell EMC Isilon
2023-03-29 14:17:16 -05:00
Alexander V. Chernikov
bd9d75e49f route: revert transport to rtsock
Temporary switch route(8) back to using rtsock to address
 the discovered issues.
2023-03-28 08:56:18 +00:00
Yuri Pankov
21af4e09f4 nvmecontrol(8): fix resv register -i synopsis
-i is "ignore existing key" and does not take argument

Reviewed by:	pauamma (manpages)
Differential Revision:	https://reviews.freebsd.org/D37709
2023-03-27 15:00:33 +02:00
Yuri Pankov
6aa5b10d0c nvme: fix resv commands with nda device
- passing I/O commands through nda requires nsid field to be set (it was
  unused when going through nvme_ns_ioctl())
- ccb's status can be OR'ed with the flags, use CAM_STATUS_MASK

Reviewed by:	imp (cam)
Differential Revision:	https://reviews.freebsd.org/D37696
2023-03-27 14:53:24 +02:00
Jose Luis Duran
9fc2d858b4 ping tests: Add a regression test
Test regression fixed in 4630a3252a. Add two tests that do not
use the verbose flag, so the code path in question can be reached:

1. Respond with a proper ICMP destination host unreachable packet.
2. Respond with a doctored ICMP destination host unreachable packet,
   that has the ICMP Identifier field modified (+1 bit).

Reviewed by:	cy
MFC after:	1 week
Differential Revision:	https://reviews.freebsd.org/D39244
2023-03-26 19:54:29 -07:00
Alexander V. Chernikov
3a151e31ac route: fix RTF_HOST & non-empty mask handling in netlink translation. 2023-03-26 18:07:23 +00:00
Alexander V. Chernikov
c597432e22 route(8): convert to netlink
This change converts all kernel rtsock interactions in route(8)
 to Netlink.

Based on the WITHOUT_NETLINK_SUPPORT src.conf(5) variable, route(8)
 now fully operates either via Netlink or via rtsock/sysctl.
The default (compile-time) is Netlink.

The output for route delete/add/get/flush is targeted to be exactly
 the same (apart from some error handling cases).
The output for the route monitor has been changed to improve
 readability and support netlink models.

Other behaviour changes:
* exact prefix lookup (route -n get a.b.c.d/e) is not yet supported.
* route monitor does not show the change originator yet.

Differential Revision:	https://reviews.freebsd.org/D39007
2023-03-26 11:06:56 +00:00
Gordon Bergling
328ebd4680 devd.conf.5: Fix a typo in the manual page
- s/deteted/detected/

MFC after:	5 days
2023-03-26 09:43:58 +02:00
Kristof Provost
0ab2c92234 ifconfig: free memory allocated by getaddrinfo()
Reported by:	emaste, Coverity
Sponsored by:	Rubicon Communications, LLC (Netgate)
2023-03-24 08:08:19 +01:00
Jose Luis Duran
4630a3252a ping: Fix an uninitialized variable
The variable oicmp, which holds the original ("quoted packet") ICMP
packet in a structured way, did not have a copy of the original ICMP
packet obtained from the raw data.

The code was accidentally removed in 20b4130314. Bring it back.

Reported by:	Coverity Scan, cy
Reviewed by:	cy
CID:		1506960 (UNINIT)
Fixes:		20b4130314
MFC after:	1 week
Differential Revision:	https://reviews.freebsd.org/D39233
2023-03-23 21:58:28 -07:00
Bjoern A. Zeeb
e091be417a ifconfig: ifieee80211: print bssid name
In certain setups (e.g., autonomous APs) it is extremly helpful to have
a way to map the BSSIDs to names for both normal status output as well
as the scan list.  This often allows a quicker overview than remembering
(or manually looking up) BSSIDs.
Call ether_ntohost() on the bssid and consult /etc/ethers
and print "(name)" after the bssid for the status output and "(name)"
at the end of the line after the IE list.

MFC after:	10 days
Reviewed by:	adrian, cy
Differential Revision: https://reviews.freebsd.org/D39192
2023-03-23 00:15:15 +00:00
Kirk McKusick
e5d0d1c5fb Rewrite function definitions with identifier lists.
A few functions snuck in with K&R style definitions.

Also add some missing memory frees.

MFC after:    1 week
2023-03-22 15:58:18 -07:00
Kristof Provost
b1a4ccdd83 carp: document peer/peer6 and mcast/mcast6 in the relevant man pages
Sponsored by:	Rubicon Communications, LLC ("Netgate")
Differential Revision:	https://reviews.freebsd.org/D38943
2023-03-20 14:37:10 +01:00
Kristof Provost
137818006d carp: support unicast
Allow users to configure the address to send carp messages to. This
allows carp to be used in unicast mode, which is useful in certain
virtual configurations (e.g. AWS, VMWare ESXi, ...)

Reviewed by:	melifaro
Sponsored by:	Rubicon Communications, LLC ("Netgate")
Differential Revision:	https://reviews.freebsd.org/D38940
2023-03-20 14:37:09 +01:00
Kristof Provost
40e0435964 carp: add netlink interface
Allow carp configuration information to be supplied and retrieved via
netlink.

Reviewed by:	melifaro
Sponsored by:	Rubicon Communications, LLC ("Netgate")
Differential Revision:	https://reviews.freebsd.org/D39048
2023-03-20 10:52:27 +01:00
Jose Luis Duran
ea6d169266 ping: Avoid reporting negative time statistics
Display a warning when the time goes back.

PR:		192417
Reviewed by:	markj
MFC after:	1 week
Differential Revision:	https://reviews.freebsd.org/D38480
2023-03-19 12:24:06 -04:00
Jose Luis Duran
076b718d9e ping tests: Add tests for IP header options
The function pr_pack() prints out a packet, if the IP packet contains
options, these are printed as well.

Test the functionality fixed in
70960bb86a.

Reviewed by:	markj
MFC after:	1 week
Differential Revision:	https://reviews.freebsd.org/D38470
2023-03-19 12:23:44 -04:00
Jose Luis Duran
1dc1f6bd31 ping: Remove pr_retip()
Ping used to provide some sort of packet sniffing capabilities, this was
in an era where hubs were used and tcpdump wasn't invented.

pr_iph() is a function that prints the IP header of the packet.

pr_retip() is essentially a wrapper function to pr_iph(), that also
displays the source and destination ports of a TCP or UDP packet.

After ef9e6dc7ee some of this
functionality was almost removed, to only display packets sent by us
(26+ years ago).

At this point, reaching this code path was only possible by doctoring
the original packet.

After 46d7b45a26 this code path can never
be reached.

Remove the code.

Reviewed by:	markj
MFC after:	1 week
Differential Revision:	https://reviews.freebsd.org/D38475
2023-03-19 12:23:22 -04:00
Jose Luis Duran
20b4130314 ping: Print the IP options of the original packet
When an ICMP packet contains an IP packet in its payload, and that
original IP packet contains options, these options were not displayed
accordingly in pr_iph().

pr_iph() is a function that prints the original "quoted packet" IP
header, with only an IP struct as an argument.  The IP struct does not
contain IP options, and it is not guaranteed that the options will be
contiguous in memory to the IP struct after
d9cacf605e.

Pass the raw ICMP data along with the IP struct, in order to print the
options, if any.

Reviewed by:	markj
MFC after:	1 week
Differential Revision:	https://reviews.freebsd.org/D38469
2023-03-19 12:23:06 -04:00
Jose Luis Duran
491263d7a6 ping: Avoid magic numbers
The sizeof(struct ip) is 20.
The sizeof(struct in_addr) is 4.

No functional change intended.

Reviewed by:	asomers, markj
MFC after:	1 week
Differential Revision:	https://reviews.freebsd.org/D39125
2023-03-17 09:24:44 -04:00
Jose Luis Duran
6d33121337 ping: Remove ifndef icmp_data guards
Early versions of <netinet/ip_icmp.h> [1] did not have icmp_data
defined, but FreeBSD has always had.  Remove these guards.

NetBSD [2] and OpenBSD [3] have already removed them.

[1]: https://www.tuhs.org/cgi-bin/utree.pl?file=4.2BSD/usr/src/sys/netinet/ip_icmp.h
[2]: 203dfd3486
[3]: d83449c83c

Reviewed by:	markj
MFC after:	1 week
2023-03-14 11:58:03 -04:00
Jose Luis Duran
9185854d19 ping: Fix the display of Flags/Fragment Offset
In the IP header, Flags + Fragment Offset is a 16-bit field.

Use ntohs() instead of ntohl(), otherwise the Flags/Fragment Offset
values may not display correctly.

Before (DF set)

    Vr HL TOS  Len   ID Flg  off TTL Pro  cks      Src      Dst
     4  5  00 0054 0001   0 0000  40  01 b6a4 192.0.2.1  192.0.2.2

After (DF set)

    Vr HL TOS  Len   ID Flg  off TTL Pro  cks      Src      Dst
     4  5  00 0054 0001   2 0000  40  01 b6a4 192.0.2.1  192.0.2.2

Reviewed by:	markj
MFC after:	1 week
Differential Revision:	https://reviews.freebsd.org/D38479
2023-03-14 11:58:02 -04:00
Jose Luis Duran
f32d6f745d ping6: Use errx to avoid appending a specious error message
Reviewed by:	asomers, markj
MFC after:	1 week
Differential Revision:	https://reviews.freebsd.org/D38418
2023-03-14 11:58:02 -04:00
Gordon Bergling
21f2681828 route.8: Don't reference an external command in EXAMPLES
It is better to mention the externel command for showing
the routing table as using an explicit command.

PR:	231579
Suggested by:	karels
Reviewed by:	karles, gbe
MFC after:	3 days
Differential Revision:	https://reviews.freebsd.org/D39075
2023-03-14 14:55:28 +01:00
Alexander Motin
20dc2c4d11 nvmecontrol: Fix default ns create parameters.
Instead of passing 0xff's for all unset parameters, prefer reasonable
defaults.  It is much easier to use it this was without specs in hand.

MFC after:	1 week
2023-03-09 10:19:00 -05:00
Kirk McKusick
129ea078cd FFS/UFS snapshots: improve documentation for removal (deletion) and unlinking.
Clarification of the size of the snapshot file.

Suggested by: Matteo Riondato
PR:           266358
MFC after:    2 weeks
Differential Revision: https://reviews.freebsd.org/D38817
2023-03-07 22:03:00 -08:00
Kirk McKusick
52f9710412 Correct several bugs in fsck_ffs(8) triggered by corrupted filesystems.
If a directory entry has an illegal inode number (less than zero
or greater than the last inode in the filesystem) the entry is removed.
If a directory '.' or '..' entry had an illegal inode number they
were being removed. Since fsck_ffs knows what the correct value is
for these two entries fix them rather deleting them.

Add much more extensive cylinder group checks and use them to be
more careful about rebuilding a cylinder group.

Check for out-of-range block numbers before trying to free them.

When a directory is deleted also remove its cache entry created
in pass1 so that later passes do not try to operate on a deleted
directory.

Check for ctime(3) returning NULL before trying to use its return.

When freeing a  directory inode, do not try to interpret it as a
directory.

Reserve space in the inostatlist to have room to allocate a
lost+found directory.

If an invalid block number is found past the end of an inode simply
remove it rather than clearing and removing the inode.

Modernize the inoinfo structure to use queue(3) LIST rather than a
handrolled linked list implementation.

Reported by:  Bob Prohaska, John-Mark Gurney, and Mark Millard
Tested by:    Peter Holm
Reviewed by:  Peter Holm
MFC after:    2 weeks
Sponsored by: The FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D38668
2023-03-07 15:14:47 -08:00
Kirk McKusick
7741a5c4dc FFS/UFS snapshots: improve documentation for removal (deletion) and unlinking.
Minor clarification.
2023-03-06 21:45:41 -08:00
Kristof Provost
1be25bdb73 pfctl: remove set but unused variable
In pfctl_show_ifaces() `i` is set, but never used. Remove it.

Sponsored by:	Rubicon Communications, LLC ("Netgate")
2023-03-06 19:22:35 +01:00
Kajetan Staszkiewicz
9f1beeaed4 pfctl: fix superblock printf format mismatch
It is impossible to compile pfctl with OPT_DEBUG due to integer width mismatch:

	/usr/home/kajetan.staszkiewicz/freebsd.git/sbin/pfctl/pfctl_optimize.c:1479:9: error: format specifies type 'unsigned int' but the argument has type 'unsigned long' [-Werror,-Wformat]
					    i - pf_rule_desc[closest].prf_off--- pfctl_optimize.o ---
	^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
	/usr/home/kajetan.staszkiewicz/freebsd.git/sbin/pfctl/pfctl_optimize.c:52:44: note: expanded from macro 'DEBUG'
		printf("%s: " str "\n", __FUNCTION__ , ## v)
			      ~~~                         ^
	1 error generated.

Reviewed by:	kp
Obtained from:	OpenBSD (pfctl_optimize.c 1.15)
Differential Revision:	https://reviews.freebsd.org/D38918
2023-03-06 19:22:35 +01:00
Alexander V. Chernikov
e2dc8d789f dhclient: do not add 0.0.0.0 interface alias.
Subscribers: imp

Differential Revision: https://reviews.freebsd.org/D38908
2023-03-06 15:08:09 +00:00
Kirk McKusick
528d8e55c8 FFS/UFS snapshots: improve documentation.
This update provides a more detailed description of FFS/UFS snapshots
and adds links to useful man pages.

Requested by: Graham Perrin
Submitted by: darius-dons.net.au
Reviewed by:  Ravi Pokala
PR:           266358
MFC after:    2 weeks
Differential Revision: https://reviews.freebsd.org/D38817
2023-03-05 21:38:57 -08:00
Kristof Provost
f5b204adf4 ifconfig: remove unused variable
In printgroup() 'cnt' is set, but never read. Remove it.

Sponsored by:	Rubicon Communications, LLC ("Netgate")
2023-03-04 11:19:12 +01:00
Kyle Evans
0c42886449 sysctl: tests: fix a couple issues
The function that sets test case metadata is actually named ${tc}_head
rather than ${tc}, so add the suffix.

While we're here, hook the tests up to the infrastructure so that they
do get run.

Sponsored by:	Klara, Inc.
2023-03-01 14:38:46 -06:00
Poul-Henning Kamp
996606792f Add deprecation notice to the gbde(8) program, scheduled to be removed in FreeBSD 15.0. 2023-02-28 21:39:06 +00:00
Gordon Bergling
6dbfbe6e11 route.8: Fix mandoc warnings
- skipping end of block that is not open: Oc
- no blank before trailing delimiter
- remove useless TN macros
- remove commented out reference for esis(4)

MFC after:	5 days
Differential Revision:	https://reviews.freebsd.org/D38783
2023-02-26 14:33:58 +01:00
Gordon Bergling
b06338167d route.8: Add information about ROUTE_MPATH and FIB_ALGO
Since the kernel options ROUTE_MPATH and FIB_ALGO are enabled
per default for a while, it's good to have some user facing
documetation about the general functionality of multipath
routing and fib lookup algorithms.

Reviewed by:	pauamma, Jose Luis Duran <jlduran at gmail dot com>
MFC after:	5 days
Differential Revision:	https://reviews.freebsd.org/D38783
2023-02-26 14:15:34 +01:00
Cy Schubert
70960bb86a ping: Fix unsigned integer underflow resuling in a ping -R segfault
ping -R (F_RROUTE) will loop at ping.c:1381 until it segfaults or
the unsigned int hlen happens to be less than the size of an IP header:

slippy$ ping -R 192.168.0.101
PING 192.168.0.101 (192.168.0.101): 56 data bytes
64 bytes from 192.168.0.101: icmp_seq=0 ttl=63 time=1.081 ms
RR: 	192.168.0.1
	192.168.0.101
	192.168.0.101
	10.1.1.254
	10.1.1.91
unknown option bb
unknown option 32
unknown option 6
...
unknown option 96
unknown option 2d
Segmentation fault

The reason for this is while looping through loose source routing (LSRR)
and strict source routing (SSRR), hlen will become smaller than the IP
header. It may even become negative. This should terminate the loop.
However, when hlen is unsigned, an integer underflow occurs becoming a
large number causing the loop to continue virtually forever until hlen
is either by chance smaller than the lenghth of an IP header or it
segfaults.

Reviewed by:	asomers
Fixes:		46d7b45a26
MFC after:	3 days
Differential Revision:	https://reviews.freebsd.org/D38744
2023-02-24 06:50:53 -08:00
Mina Galić
7e2af4f90b veriexec(4): Fix a compiler error
When building WITH_BEARSSL=1 veriexec(4) failes to compile.
So update the function prototype so that veriexec(4)
compiles again.

Reported by:	gbe
Reviewed by:	mjg, gbe
Approved by:	mjg
Pull Request:	https://github.com/freebsd/freebsd-src/pull/657
2023-02-23 12:14:41 +01:00
Jose Luis Duran
5b8af90fe3 ping: Add ATF-Python tests
ping(8) is an old utility, which has received many changes and updates through the years.
Some of these changes may have introduced small bugs, in part due to the lack of tests.
Attempt to remedy the current situation by introducing a way to easily add tests.

Differential Revision: https://reviews.freebsd.org/D38053
2023-02-20 10:34:33 +00:00
Alexander V. Chernikov
3d360ca49c Revert "ping: Add ATF-Python tests"
This reverts commit 0343e90f39.
2023-02-20 10:34:09 +00:00
Alexander V. Chernikov
0343e90f39 ping: Add ATF-Python tests
ping(8) is an old utility, which has received many changes and updates through the years.
Some of these changes may have introduced small bugs, in part due to the lack of tests.
Attempt to remedy the current situation by introducing a way to easily add tests.

Differential Revision: https://reviews.freebsd.org/D38053
2023-02-20 10:31:38 +00:00
Konstantin Belousov
5942b4b6fd sys/param.h: Add _WANT_P_OSREL
Use it instead of defining IN_RTLD by base sources that want P_OSREL_
defines in userspace, but are not rtld.
This allows to remove abuse of IN_RTLD from userspace.

Reviewed by:	dchagin, markj, imp
Sponsored by:	The FreeBSD Foundation
MFC after:	1 week
Differential revision:	https://reviews.freebsd.org/D38585
2023-02-15 02:43:18 +02:00
Kyle Evans
8d78a0d331 md5: fix *sum -c with missing files
If we fail to open one of the files in the file listing, we still need
to advance `rec` along with `argv` so that the checksum we're checking
against lines up with the file we're hashing.

Tests added both for the -c flag, as well as the -b and -t modes of
the *sum programs.

PR:		267722
Reviewed by:	emaste (earlier version)
MFC after:	3 days
Differential Revision:	https://reviews.freebsd.org/D37374
2023-02-13 00:32:38 -06:00