git: a8aaed141731 - stable/13 - ifconfig(8): Don't set network interface capabilities when there is no change.

From: Hans Petter Selasky <hselasky_at_FreeBSD.org>
Date: Fri, 07 Jan 2022 13:30:49 UTC
The branch stable/13 has been updated by hselasky:

URL: https://cgit.FreeBSD.org/src/commit/?id=a8aaed141731d895b63b239c3a63a9052142ee41

commit a8aaed141731d895b63b239c3a63a9052142ee41
Author:     Hans Petter Selasky <hselasky@FreeBSD.org>
AuthorDate: 2021-11-09 21:07:43 +0000
Commit:     Hans Petter Selasky <hselasky@FreeBSD.org>
CommitDate: 2022-01-07 13:11:32 +0000

    ifconfig(8): Don't set network interface capabilities when there is no change.
    
    A quick grep through the kernel code shows network drivers compute the
    changed bits of network capabilities after a SIOCSIFCAP IOCTL(2) by
    using the bitwise exclusive or operation. When the set capabilities
    are equal to the already read capabilities, no action will be taken.
    
    Let ifconfig(8) predict this case and skip the SIOCSIFCAP IOCTL(2)
    system call.
    
    Discussed with: kib@ (revert change in case of issues)
    Sponsored by:   NVIDIA Networking
    
    (cherry picked from commit ad8f078f66e51212cdccd91fe8b22fb81235018e)
---
 sbin/ifconfig/ifconfig.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/sbin/ifconfig/ifconfig.c b/sbin/ifconfig/ifconfig.c
index 0423b3593504..9e7d38d4c2a4 100644
--- a/sbin/ifconfig/ifconfig.c
+++ b/sbin/ifconfig/ifconfig.c
@@ -1243,6 +1243,9 @@ setifcap(const char *vname, int value, int s, const struct afswtch *afp)
 	} else
 		flags |= value;
 	flags &= ifr.ifr_reqcap;
+	/* Check for no change in capabilities. */
+	if (ifr.ifr_curcap == flags)
+		return;
 	ifr.ifr_reqcap = flags;
 	if (ioctl(s, SIOCSIFCAP, (caddr_t)&ifr) < 0)
 		Perror(vname);