Commit Graph

872 Commits

Author SHA1 Message Date
Warner Losh
b2c76c41be Remove $FreeBSD$: one-line nroff pattern
Remove /^\.\\"\s*\$FreeBSD\$$\n/
2023-08-16 11:55:15 -06:00
Warner Losh
d0b2dbfa0e Remove $FreeBSD$: one-line sh pattern
Remove /^\s*#[#!]?\s*\$FreeBSD\$.*$\n/
2023-08-16 11:55:03 -06:00
Warner Losh
1d386b48a5 Remove $FreeBSD$: one-line .c pattern
Remove /^[\s*]*__FBSDID\("\$FreeBSD\$"\);?\s*\n/
2023-08-16 11:54:42 -06:00
Warner Losh
2a63c3be15 Remove $FreeBSD$: one-line .c comment pattern
Remove /^/[*/]\s*\$FreeBSD\$.*\n/
2023-08-16 11:54:29 -06:00
Warner Losh
b3e7694832 Remove $FreeBSD$: two-line .h pattern
Remove /^\s*\*\n \*\s+\$FreeBSD\$$\n/
2023-08-16 11:54:16 -06:00
Navdeep Parhar
a29916a6f8 ifconfig_netlink.c: whitespace cleanup.
No functional change.
2023-07-20 10:54:56 -07:00
Navdeep Parhar
88284368fa ifconfig: Shift unsigned value to avoid UB.
Reported by:	kib@
2023-07-20 10:54:56 -07:00
Navdeep Parhar
47b1fef6fb ifconfig: Fix the display of capabilities in the netlink based code.
The capabilities in if_capabilities2/if_capenable2 are reported in the
second 32b and were not being displayed correctly.  v does not need to
be advanced because v[i / 32] is the correct 32b value already.

Sponsored by:	Chelsio Communications

Reviewed by:	kib@
Differential Revision:	https://reviews.freebsd.org/D41107
2023-07-20 10:26:18 -07:00
Luiz Amaral
6fc7fc2dbb pfsync: transport over IPv6
Implement pfsync over IPv6.

Submitted by:	Luiz Amaral <email@luiz.eng.br>
Submitted by:	Naman Sood <naman@freebsdfoundation.org>
Reviewed by:	kp
Sponsored by:	InnoGames GmbH
Differential Revision:	https://reviews.freebsd.org/D40102
2023-07-13 08:09:42 +02:00
Mateusz Guzik
cea9f49f82 ping: low-effort fix to make it compilable without inet 2023-07-05 10:02:32 +00:00
Alfonso Gregory
21c32cebf8 ifconfig: skip calling fnmatch once the result no longer matters
Because fnmatch has no side effects, we can safely avoid calling fnmatch
if the end result does not matter anyway (the compiler cannot see this,
so it calls fnmatch in the event it has side-effects).

Reviewed by: imp
Pull Request: https://github.com/freebsd/freebsd-src/pull/747
2023-06-27 16:28:44 -06:00
Ed Maste
c079bcbc60 ifconfig: consistently sort set/clear commands
Sponsored by:	The FreeBSD Foundation
2023-06-25 16:09:26 -04:00
Koichiro Iwao
9aca30d878 ifconfig.8: Document limitation of groupname
Approved by:		kp
MFC after:		1 week
Differential Revision:	https://reviews.freebsd.org/D40645
2023-06-20 23:08:04 +09:00
John Baldwin
f19ae3633b ifconfig: Pacify a sign comparison warning in regdomain_sort.
Both ic_flags values are unsigned (uint32_t), so cast them to a signed
int to generate a signed result.  Both ic_req values are also
unsigned, but since they are uint16_t, they are implicitly promited to
int before the subtraction.

Reported by:	GCC -Wsign-compare
Reviewed by:	emaste
Differential Revision:	https://reviews.freebsd.org/D40610
2023-06-19 10:38:18 -07:00
John Baldwin
a3b1138778 ifconfig: Consistently use uint32_t for wireless channel flags.
Reported by:	GCC -Wsign-compare
Reviewed by:	emaste
Differential Revision:	https://reviews.freebsd.org/D40609
2023-06-19 10:38:07 -07:00
John Baldwin
08992b2078 ifconfig: Avoid issues with trying to negate unsigned values.
The if_flags and if_cap fields hold a bitmask of flags.  If a flag is
the MSB of the field, then the logic in setifflags and setifcap which
uses a < 0 check does the wrong thing (it tries to clear the flag
rather than setting it).  Also, trying to use -<FOO> doesn't actually
work as the result is a nop.  To fix, stop overloading setifcap and
setifflags and instead add new dedicated action functions clearifcap
and clearifflags for clearing a flag.  The value passed in the
argument to the command is now always the raw flag.

This was reported by a GCC warning after raising WARNS:

sbin/ifconfig/ifconfig.c:2061:33: error: integer overflow in expression '-2147483648' of type 'int' results in '-2147483648' [-Werror=overflow]
 2061 |         DEF_CMD("-txtlsrtlmt",  -IFCAP_TXTLS_RTLMT,     setifcap),
      |                                 ^

Reviewed by:	emaste
Differential Revision:	https://reviews.freebsd.org/D40608
2023-06-19 10:37:52 -07:00
Ed Maste
e77b2ea427 ifconfig: set boolean to true rather than incrementing
GCC warns about "increment of a boolean expression."

Reported by:	amd64-gcc12 Cirrus-CI run
Sponsored by:	The FreeBSD Foundation
2023-06-19 11:02:38 -04:00
Alexander V. Chernikov
c344eff910 netlink: dump interface capabilities with other interface data.
This change exports interface capabilities using the standard
Netlink attribute type, bitset, and switches `ifconfig(8)` to use
it when displaying interface data.
Bitset comes in two representations. The first one is "compact",
where the bits are exported via two arrays - "mask" listing the
"valid" bits and "values, providing the values for those bits.
The second one is more verbose, listing each bit as a separate item,
with its name, id and value. The latter option is handy when submitting
update requests.

The support for setting capabilities will be added in the upcoming diffs.

Differential Revision: https://reviews.freebsd.org/D40331
2023-06-16 15:33:49 +00:00
Alexander V. Chernikov
0fcc603a07 ifconfig: fix armv6 build 2023-06-16 08:23:50 +00:00
Alexander V. Chernikov
a3930cd46c ifconfig: use default (more rigid) WARNS level.
It helps catch more errors at compile time.

Reviewed by:	kp
Differential Revision: https://reviews.freebsd.org/D40536
MFC after:	2 weeks
2023-06-16 07:19:22 +00:00
Alexander V. Chernikov
f414f37e38 ifconfig: remove global 'ifr' usage from ifmedia.c & remove 'ifr'.
Reviewed by:	kp
Differential Revision: https://reviews.freebsd.org/D40535
MFC after:	2 weeks
2023-06-16 07:19:21 +00:00
Alexander V. Chernikov
7fa282e616 ifconfig: remove (most of) the usages of global 'struct ifreq ifr'.
It is hard to reason about the contents of 'ifr' at any given time
as nearly every function sets random fields or pointers in this
structure.
Use local on-stack clean 'struct ifreq' for each function instead.

Reviewed by: kp
Differential Revision: https://reviews.freebsd.org/D40534
MFC after:	2 weeks
2023-06-16 07:19:21 +00:00
Alexander V. Chernikov
52ff888318 ifconfig: fix ifconfig crash when compiled w/WITHOUT_NETLINK.
Properly update the recently-introduced `ctx->ifname` when iterating
over interfaces.

Reported by:	Gary Jennejohn <garyj@gmx.de>
MFC after:	2 weeks
2023-06-14 10:37:07 +00:00
Alexander V. Chernikov
3927d0fb37 ifconfig: fix -Wunused warnings
MFC after:	2 weeks
2023-06-14 09:16:09 +00:00
Alexander V. Chernikov
a6094f844a ifconfig: remove 'newaddr' global variable
Differential Revision: https://reviews.freebsd.org/D40441
MFC after:	2 weeks
2023-06-14 09:16:09 +00:00
Alexander V. Chernikov
bbad5525fa ifconfig: start ifconfig context from main()
Differential Revision: https://reviews.freebsd.org/D40440
MFC after:	2 weeks
2023-06-14 09:15:58 +00:00
Alexander V. Chernikov
d61064229f ifconfig: fix comparison in printmimo().
Differential Revision: https://reviews.freebsd.org/D40301
MFC after:	2 weeks
2023-06-14 07:39:06 +00:00
Trond Endrestol
d77ca41f77 ifconfig(8): add the dotted format for MAC addresses.
MFC after:	2 weeks
PR:	261572
2023-06-13 06:40:15 +00:00
Alexander V. Chernikov
ea73ff9752 ifconfig: remove global_args variable.
This variable was temporarily introduced in the beginning of the
code cleanup. Use on-stack instance in main() instead.

Reviewed By: kp
Differential Revision: https://reviews.freebsd.org/D40439
MFC after:	2 weeks
2023-06-13 06:25:16 +00:00
Alexander V. Chernikov
85e0016a97 ifconfig: remove global 'name' variable.
Consistenly use newly-added 'ctx->ifname' as the name of the current
target interface.

Reviewed By: kp
Differential Revision: https://reviews.freebsd.org/D40438
MFC after:	2 weeks
2023-06-13 06:22:41 +00:00
Alexander V. Chernikov
c6f0602f23 ifconfig: pass if_ctx instead of socket to the tunnel handlers.
This is a pre-requisite for the global 'name' variable removal.

Reviewed By: kp
Differential Revision: https://reviews.freebsd.org/D40432
MFC after:	2 weeks
2023-06-13 06:20:00 +00:00
Alexander V. Chernikov
4106282ec4 ifconfig: remove global 'printifname' variable.
This variable was used to print the created interface name in the
atexit(3) handler. The interface name was calculated in the
ifclonecreate() by matching old & new names.

This change alter the implementation the following way:
1) the function responsible for the interface creation (ifcreate_ioctl)
 updates all necessary state internally. This removes the need for the
 name manipulation hack in wlan_create().
2) As atexit(3) handler does not accept any parameters, explicitly store
 the name to print in the ifname_to_print variable read by the atexit(3)
 handler.

Reviewed By: kp
Differential Revision: https://reviews.freebsd.org/D40431
MFC after:	2 weeks
2023-06-13 06:18:10 +00:00
Alexander V. Chernikov
c6885dbda7 ifconfig: eliminate global 'verbose' and 'printkey' variables
Reviewed By: kp
Differential Revision: https://reviews.freebsd.org/D40427
MFC after:	2 weeks
2023-06-13 06:16:14 +00:00
Alexander V. Chernikov
74b4261161 ifconfig: add if_ctx argument to the generic and ifclone callbacks.
This is the continuation of the ifconfig cleanup work. This change is
a pre-requsite for the next changes removing some of the global variables.
It will also help in implementing functionality via Netlink instead of ioctl.
No functional changes intended.
* vxlan_cb() was removed as it contained no code
* ioctl_ifcreate() was renamed to ifcreate_ioctl() to follow the other
netlink/ioctl function naming. Netlink and ioctl provide _different_
interfaces and it's not possible to have a unified interface object
that can be filled by either netlink or ioctl implementations. With that
in mind, I'm leaning more to the function_<nl|ioctl> postfix pattern,
than doing ioctl_ or netlink_ prefix.

Reviewed By: kp
Differential Revision: https://reviews.freebsd.org/D40426
MFC after:	2 weeks
2023-06-13 06:10:56 +00:00
Elyes Haouas
b66b2c4d9b ifconfig: Fix typos
Signed-off-by: Elyes Haouas <ehaouas@noos.fr>
Reviewed by: imp
Pull Request: https://github.com/freebsd/freebsd-src/pull/653
2023-06-01 20:33:40 -06:00
Alexander V. Chernikov
0c2beef72d ifconfig: fix warnings #2
Fix all -Wparameter-unused and cast alignment

Differential Revision: https://reviews.freebsd.org/D40303
MFC after:	2 weeks
2023-06-01 11:54:25 +00:00
Kajetan Staszkiewicz
4bf98559d9 pf: make contents of struct pfsync_state configurable
Make struct pfsync_state contents configurable by sending out new
versions of the structure in separate subheader actions. Both old and
new version of struct pfsync_state can be understood, so replication of
states from a system running an older kernel is possible. The version
being sent out is configured using ifconfig pfsync0 … version XXXX. The
version is an user-friendly string - 1301 stands for FreeBSD 13.1 (I
have checked synchronization against a host running 13.1), 1400 stands
for 14.0.

A host running an older kernel will just ignore the messages and count
them as "packets discarded for bad action".

Reviewed by:	kp
Sponsored by:	InnoGames GmbH
Differential Revision:	https://reviews.freebsd.org/D39392
2023-05-30 14:28:56 +02:00
Alexander V. Chernikov
6d204407ec ifconfig: fix ifconfig IFX inet[6] ADDR -alias
Internally, inet and inet6 family handlers store state for
 address addition and deletion separately, as, for example,
 "ifconfig lo0 inet 127.0.0.2/32" triggers a) deletion of the
 first interface address and b) addition of a new one.
The current logic behind handling "-alias" being the last argument
 is to copy the address from "addition" state to the "deletion"
 state. It is done by the generic ifconfig code, which explicitly
 typecasts opaque handler state pointers to "struct ifreq", which
 doesn't work in the Netlink case.

Fix this by introducing family-specific "af_copyaddr" handler,
 which removes the peeking & typecasting logic from the generic code.

Reported by:	otis
Tested by:	otis
2023-05-25 15:03:35 +00:00
Alexander V. Chernikov
4bf44dd73b ifconfig: switch IPv4/IPv6 address manipulations to Netlink.
Differential Revision: https://reviews.freebsd.org/D40182
2023-05-25 12:22:18 +00:00
Alexander V. Chernikov
12cfa3c1bd ifconfig: fix interface address ordering with Netlink. 2023-05-24 15:34:21 +00:00
Alexander V. Chernikov
6e3a9d7f2c ifconfig: introduce ifconfig_context to store current global state.
The structure consists of all current context - arguments,
open sockets, current family and so on.

Pass this structure as a first argument to most of the af_ menthods.
This allows to propagate and update shared data without using
 global variables.

The diff is pretty large, but de-facto mechanical. All changes
 except the structure setup in ifconfig[_netlink].c are one-line
 mechanical changes.

Reviewed by:	kp
Differential Revision: https://reviews.freebsd.org/D40239
MFC after:	2 weeks
2023-05-24 10:40:34 +00:00
Alexander V. Chernikov
44cd85d42e ifconfig: cleanup warnings #1
Cleanup compiler warnings in preparation to set Wextra and remove WARNS?=2

Differential Revision: https://reviews.freebsd.org/D40238
MFC after:	2 weeks
2023-05-24 10:40:34 +00:00
Yan Ka Chiu
7e49aa86a2
ifconfig(8): Teach ifconfig to attach and run itself in a jail
Add -j <jail> flag to ifconfig to allow ifconfig to attach and run inside a
jail. This allow parent to configure network interfaces of its children
even if ifconfig is not available in child's tree (e.g. Linux Jails)

Reviewed by:	emaste, khng, melifaro
Event:		Kitchener-Waterloo Hackathon 202305
MFC after:	1 week
Differential Revision:	https://reviews.freebsd.org/D40213
2023-05-23 16:39:22 -04:00
Alexander V. Chernikov
26056fa8d3 Revert "ifconfig: switch IPv4/IPv6 address manipulations to Netlink"
Revert the change as 2 non-expected issues have been reported.

This reverts commit 54418f79fd.
2023-05-22 15:17:57 +00:00
Alexander V. Chernikov
454d72ec40 Revert "ifconfig: Fix the build"
This reverts commit 5b8ce85e1a.
2023-05-22 15:17:45 +00:00
Mark Johnston
5b8ce85e1a ifconfig: Fix the build
Fix indentation in warn_nomask() while here.

Fixes:	54418f79fd ("ifconfig: switch IPv4/IPv6 address manipulations to Netlink")
2023-05-22 10:53:38 -04:00
Alexander V. Chernikov
54418f79fd ifconfig: switch IPv4/IPv6 address manipulations to Netlink
Subscribers: imp

Differential Revision: https://reviews.freebsd.org/D40182
2023-05-22 13:45:33 +00:00
Alexander V. Chernikov
63ad5ce733 ifconfig: simplify ifconfig() by factoring out ifa add/del logic
Reviewed by:	kp
MFC after:	2 weeks
Differential Revision: https://reviews.freebsd.org/D40180
2023-05-21 09:42:11 +00:00
Alexander V. Chernikov
197bff385e ifconfig: split argument parsing
Simplify main() by factoring out argument parsing code.

Reviewed by:	kp
MFC after:	2 weeks
Differential Revision: https://reviews.freebsd.org/D40179
2023-05-21 09:42:11 +00:00
Alexander V. Chernikov
a72b78905a ifconfig: simplify carp vhid setup.
Currently carp implementation peeks into the opaque 'afp->af_addreq'
 buffer, assumes it knows the af-specific layout and assigns vhid
 directly.
Simplify the code and remove abstraction leak by introducing per-afp
 callback for setting vhid.
This change is a pre-requisite to set addresses via Netlink,
 as Netlink implementiation uses different structure layout.

Reviewed by:	kp
Differential Revision: https://reviews.freebsd.org/D40160
MFC after:	2 weeks
2023-05-20 09:49:15 +00:00