From nobody Mon Aug 25 22:43:22 2025 X-Original-To: dev-commits-src-all@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4c9m6L6Dx9z65mCP; Mon, 25 Aug 2025 22:43:22 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R12" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4c9m6L59rKz3Xkp; Mon, 25 Aug 2025 22:43:22 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1756161802; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=3XJJyTrr/aEgjDMLITD2biDpQicv05c7SY8U8pCCeWQ=; b=sMVv0Mx3gJGeFEy9VeljdoBDLf2beCJ1oM8FPetlh9xgYGwXu83ohIA7qvi1Omqit/27yL s6pOw1GO7QBa2J+r/mbIWkIk1BhIp/aR8Vuh66Im73Ej1hr1xzYAbcraji1fIIz++nz0Nc D7OMYrCO+NWfTSEoo0hse1imE3MMWZcefInjpPMXvlxg7HrHGfdDotlsDb07Vx+8GbKkYk gvOQsKwWziJj6cHzpdSsneR3FUUfQo0UaAJfRyqlns6FQoJOsIWhGoQ6zQpoCLz/muXsg3 Kv84WXKH38B8yvsyAwwCnKfXnP1K1Zx2VevOwyuJZFyjnfMR8blwkyz06epqSw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1756161802; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=3XJJyTrr/aEgjDMLITD2biDpQicv05c7SY8U8pCCeWQ=; b=jnuwZRGFONlxYQK8Iwke7N6Ad+DG2oZGBSFIQzP6uOtIVi/WY/ivbNSyrjk8lLnr/ABg1Q LiVgsOZnE5pZhXNXUOcEC2azD4DONP9IJ05cqKgSQ8sTQGIXYJdr0tTkfoJzptkZ4FU3Zr yQCpuEI2ahnkBnYNDEgBxJFW1qozu1v+pdwZ/+2r5OeNezX+oORatrSWjJpHBfP0op7Zkl Eg0t/wuHekbWhXHXO3PomqpeU6V2cobzVn7XHZDtfEXNXUvwKuZUxnHDkC6LbbSDett+Py 8cTJMvMhVTD274l9kfaX7ULpzhEiQzQ9QOHjoHNrjaXQF6DYm7L7xaJVGrEk1A== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1756161802; a=rsa-sha256; cv=none; b=KOfkmlKAS++B+4kbl8GeTv09DjPY9toilkMJx1VHPa5pwsFown45zXUI8qknvAhXeuHLqH Mz46qCy7K+sHcFx6dWsG4cdv286jnnrxwB8lLBRQ5W7GB8C2Vj54KpnH1YNk53EDgx1t3S ++NSn+hslDP9zDEdWIdrw/8vu+lsPMX0BMyeJUwQyCtOzWGmHlEMpd3CGWujUwqDwbHGnb jWwqDCEMdYCjQrJIqLSehWKdnhH5jpUSyVLh+RYPtDn8DnfFXSzVi7TP8KSl+O7K7SxBVq x+LeXBx5ft0jPB4ImU2OLeZ6mPAhnwrZ+YbrGK8xTHaKp4w2kj0HO8bfi9TRfQ== ARC-Authentication-Results: i=1; mx1.freebsd.org; none Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4c9m6L4lDxz17k0; Mon, 25 Aug 2025 22:43:22 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.18.1/8.18.1) with ESMTP id 57PMhM6M081962; Mon, 25 Aug 2025 22:43:22 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 57PMhM6Z081959; Mon, 25 Aug 2025 22:43:22 GMT (envelope-from git) Date: Mon, 25 Aug 2025 22:43:22 GMT Message-Id: <202508252243.57PMhM6Z081959@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Aymeric Wibo Subject: git: 431856c868de - main - netlink: Bypass refcounting when setting promiscuity List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-all@freebsd.org Sender: owner-dev-commits-src-all@FreeBSD.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: obiwac X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 431856c868de12d7af127cdf7e9aeb1b99d0ac99 Auto-Submitted: auto-generated The branch main has been updated by obiwac: URL: https://cgit.FreeBSD.org/src/commit/?id=431856c868de12d7af127cdf7e9aeb1b99d0ac99 commit 431856c868de12d7af127cdf7e9aeb1b99d0ac99 Author: Aymeric Wibo AuthorDate: 2025-08-25 22:40:16 +0000 Commit: Aymeric Wibo CommitDate: 2025-08-25 22:40:17 +0000 netlink: Bypass refcounting when setting promiscuity When asking for IFF_PROMISC when modifying interfaces with netlink, set permanent flag instead (IFF_PPROMISC) as netlink interface modification has no way of doing promiscuity reference counting through ifpromisc(). We can't do reference counting because every netlink interface modification necessarily either sets or unsets IFF_PROMISC in ifi_flags, and ifi_change is usually set to 0xFFFFFFFF. This logic was the same between this and SIOCSIFFLAGS, so factor out if_setppromisc() function. Reviewed by: melifaro, saheed, kp, mckusick (mentor) Approved by: melifaro, saheed, mckusick (mentor) Sponsored by: The FreeBSD Foundation Differential Revision: https://reviews.freebsd.org/D52056 --- sys/net/if.c | 37 +++++++++++++++++++++++++++---------- sys/net/if_var.h | 1 + sys/netlink/route/iface_drivers.c | 17 ++++++++++------- 3 files changed, 38 insertions(+), 17 deletions(-) diff --git a/sys/net/if.c b/sys/net/if.c index 79c883fd4a0a..202be4794f6e 100644 --- a/sys/net/if.c +++ b/sys/net/if.c @@ -2589,16 +2589,7 @@ ifhwioctl(u_long cmd, struct ifnet *ifp, caddr_t data, struct thread *td) * flip. They require special handling because in-kernel * consumers may indepdently toggle them. */ - if ((ifp->if_flags ^ new_flags) & IFF_PPROMISC) { - if (new_flags & IFF_PPROMISC) - ifp->if_flags |= IFF_PROMISC; - else if (ifp->if_pcount == 0) - ifp->if_flags &= ~IFF_PROMISC; - if (log_promisc_mode_change) - if_printf(ifp, "permanently promiscuous mode %s\n", - ((new_flags & IFF_PPROMISC) ? - "enabled" : "disabled")); - } + if_setppromisc(ifp, new_flags & IFF_PPROMISC); if ((ifp->if_flags ^ new_flags) & IFF_PALLMULTI) { if (new_flags & IFF_PALLMULTI) ifp->if_flags |= IFF_ALLMULTI; @@ -4456,6 +4447,32 @@ if_getmtu_family(const if_t ifp, int family) return (ifp->if_mtu); } +void +if_setppromisc(if_t ifp, bool ppromisc) +{ + int new_flags; + + if (ppromisc) + new_flags = ifp->if_flags | IFF_PPROMISC; + else + new_flags = ifp->if_flags & ~IFF_PPROMISC; + if ((ifp->if_flags ^ new_flags) & IFF_PPROMISC) { + if (new_flags & IFF_PPROMISC) + new_flags |= IFF_PROMISC; + /* + * Only unset IFF_PROMISC if there are no more consumers of + * promiscuity, i.e. the ifp->if_pcount refcount is 0. + */ + else if (ifp->if_pcount == 0) + new_flags &= ~IFF_PROMISC; + if (log_promisc_mode_change) + if_printf(ifp, "permanently promiscuous mode %s\n", + ((new_flags & IFF_PPROMISC) ? + "enabled" : "disabled")); + } + ifp->if_flags = new_flags; +} + /* * Methods for drivers to access interface unicast and multicast * link level addresses. Driver shall not know 'struct ifaddr' neither diff --git a/sys/net/if_var.h b/sys/net/if_var.h index 08435e7bd5f6..f2df612b19c1 100644 --- a/sys/net/if_var.h +++ b/sys/net/if_var.h @@ -622,6 +622,7 @@ int if_setmtu(if_t ifp, int mtu); int if_getmtu(const if_t ifp); int if_getmtu_family(const if_t ifp, int family); void if_notifymtu(if_t ifp); +void if_setppromisc(const if_t ifp, bool ppromisc); int if_setflagbits(if_t ifp, int set, int clear); int if_setflags(if_t ifp, int flags); int if_getflags(const if_t ifp); diff --git a/sys/netlink/route/iface_drivers.c b/sys/netlink/route/iface_drivers.c index 2a75e6abb2d0..4f1540740ead 100644 --- a/sys/netlink/route/iface_drivers.c +++ b/sys/netlink/route/iface_drivers.c @@ -105,13 +105,16 @@ _nl_modify_ifp_generic(struct ifnet *ifp, struct nl_parsed_link *lattrs, } } - if (lattrs->ifi_change & IFF_PROMISC) { - error = ifpromisc(ifp, lattrs->ifi_flags & IFF_PROMISC); - if (error != 0) { - nlmsg_report_err_msg(npt, "unable to set promisc"); - return (error); - } - } + if ((lattrs->ifi_change & IFF_PROMISC) != 0 || + lattrs->ifi_change == 0) + /* + * When asking for IFF_PROMISC, set permanent flag instead + * (IFF_PPROMISC) as we have no way of doing promiscuity + * reference counting through ifpromisc(). Every call to this + * function either sets or unsets IFF_PROMISC, and ifi_change + * is usually set to 0xFFFFFFFF. + */ + if_setppromisc(ifp, (lattrs->ifi_flags & IFF_PROMISC) != 0); if (lattrs->ifla_address != NULL) { if (nlp_has_priv(npt->nlp, PRIV_NET_SETIFMAC)) {