From nobody Sat Mar 22 23:40:45 2025 X-Original-To: dev-commits-src-main@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 4ZKwmZ2v9pz5rQ3Q; Sat, 22 Mar 2025 23:40:46 +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 "R10" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4ZKwmY5smjz3lT8; Sat, 22 Mar 2025 23:40:45 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1742686845; 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=6hEHBRTAXsudeSi9BT3yi8qNbO1T9Z4GwLoLZJ87XrI=; b=JVXql3nzbv9q03GzfMAd3jx0PxhFhf+I+zjCPQAebfSzho2S59DoeI6qK/U80ahfwWZArj dnk0vPxMb57NTmPJKCC+fQZbP6t4OMOpfC3RBmVhQKse3kZoIWh56YD68H7qqwc+FOvAnX 95V5/BwQOuiiq9O2ALBiU5dQGmucBNwVRze7yaj8lc92JseIBQ8GLya2Zm1tGBhq6ptRBM IM5Pkh6dksylGrHrNiRnqLa4NT0/DlmiXC/HPHtb5pAP0mWni8l/4D97l2Is8i6HyrmszK ySONUZBwdfnVkba08ob0y20VChdfPHLOhE3370dgGIGdtPzmt9AXiT0C1fEhCw== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1742686845; a=rsa-sha256; cv=none; b=xZrIglnhKgr2/x+R2IQcRJvSiZbL+qYDPAp7/LwTAGjgCR5qaUhXWjiSmkJkhbwsjNwg/T 2JVzzOQip8Avy07ktOY9DEFLEmnFOizikdaBm1+QEyEx5w4a9KiUnOA/tn7tkwc8YM0wo7 f56TuAY6DGMli8UiW8ydJd74pFnlmP0Lqwl6yq5TRjGOhcUyPzN/nqL16NGTyKlO7UHjyr bxuE/la7EzGIjvpB5jMixKMGhs/TAISIVtHalVmRBG6q1K/qjmeaCr7RsUv8EzyyXDqpYb Nn2cG31TJxg8K0igwBGXt/6tIrT9+9J0oS+P0DAUnwMynhvBUcpkxKnnJO+mCw== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1742686845; 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=6hEHBRTAXsudeSi9BT3yi8qNbO1T9Z4GwLoLZJ87XrI=; b=nTFvJWH2mzvG+LZM5Gbm1BHftInh8z/7UduoolBwgLUifpB9if4IRoDuZnUwehphtibqay iPbXny8pkv4fctLcn61ExHzGW2xTA9u7IMyaq0wGc58MTCkdf/YjYpPfZD95x7rBiniKJX 8hYWZexQts+GS5OsyXYLMxX1UeZOE/mecOK774IXShTHRgwg7nlSYWvOnuMP7BmkvPiH2o lzc7+NSu9gqZv0uPe56OD8aw7luMVLueS87YNu9E96rAlNe+lTAgM5R7Hp5TNHi3gE+Ixl x1yw8FkCMVC4GU1ifeQ3I32BrnMVaVA9it7Ce4Xshm64Mp0Zgq/3Qw2s5h1CjQ== 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 4ZKwmY5Gsvzk2V; Sat, 22 Mar 2025 23:40:45 +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 52MNejvF071184; Sat, 22 Mar 2025 23:40:45 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 52MNejaK071181; Sat, 22 Mar 2025 23:40:45 GMT (envelope-from git) Date: Sat, 22 Mar 2025 23:40:45 GMT Message-Id: <202503222340.52MNejaK071181@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Gleb Smirnoff Subject: git: baad45c9c120 - main - inpcb: push multicast case local address selection logic into in_pcbladdr() List-Id: Commit messages for the main branch of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-main List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-main@freebsd.org Sender: owner-dev-commits-src-main@FreeBSD.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: glebius X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: baad45c9c12028964acd0b58096f3aaa0fb22859 Auto-Submitted: auto-generated The branch main has been updated by glebius: URL: https://cgit.FreeBSD.org/src/commit/?id=baad45c9c12028964acd0b58096f3aaa0fb22859 commit baad45c9c12028964acd0b58096f3aaa0fb22859 Author: Gleb Smirnoff AuthorDate: 2025-03-22 23:37:37 +0000 Commit: Gleb Smirnoff CommitDate: 2025-03-22 23:37:37 +0000 inpcb: push multicast case local address selection logic into in_pcbladdr() When destination is multicast and inpcb has multicast options configured, we use completely different logic than in a normal case. Before this change, in in_pcbconnect() we would run in_pcbladdr() and then just ignore its results and run the multicast case block, that would override any earlier selection or failure. Let's embed the case in in_pcbladdr() and also check it earlier. Also, 69c05f428714 switched UDP unconnected sendto(2) to use in_pcbladdr() instead of in_pcbconnect_setup() and due to that lost the multicast case. Reviewed by: markj Differential Revision: https://reviews.freebsd.org/D49435 Fixes: 69c05f42871406b4b2b2dac00a268d1da0cacd3e --- sys/netinet/in_pcb.c | 44 +++++++++++++++++++++----------------------- 1 file changed, 21 insertions(+), 23 deletions(-) diff --git a/sys/netinet/in_pcb.c b/sys/netinet/in_pcb.c index 9a49353f1538..3774f73a7a8f 100644 --- a/sys/netinet/in_pcb.c +++ b/sys/netinet/in_pcb.c @@ -1127,29 +1127,6 @@ in_pcbconnect(struct inpcb *inp, struct sockaddr_in *sin, struct ucred *cred) if (in_nullhost(inp->inp_laddr)) { error = in_pcbladdr(inp, &faddr, &laddr, cred); - /* - * If the destination address is multicast and an outgoing - * interface has been set as a multicast option, prefer the - * address of that interface as our source address. - */ - if (IN_MULTICAST(ntohl(sin->sin_addr.s_addr)) && - inp->inp_moptions != NULL && - inp->inp_moptions->imo_multicast_ifp != NULL) { - struct ifnet *ifp = - inp->inp_moptions->imo_multicast_ifp; - struct in_ifaddr *ia; - - CK_STAILQ_FOREACH(ia, &V_in_ifaddrhead, ia_link) { - if (ia->ia_ifp == ifp && - prison_check_ip4(cred, - &ia->ia_addr.sin_addr) == 0) - break; - } - if (ia == NULL) - return (EADDRNOTAVAIL); - laddr = ia->ia_addr.sin_addr; - error = 0; - } if (error) return (error); } else @@ -1231,6 +1208,27 @@ in_pcbladdr(const struct inpcb *inp, struct in_addr *faddr, if (!prison_saddrsel_ip4(cred, laddr)) return (0); + /* + * If the destination address is multicast and an outgoing + * interface has been set as a multicast option, prefer the + * address of that interface as our source address. + */ + if (IN_MULTICAST(ntohl(faddr->s_addr)) && inp->inp_moptions != NULL && + inp->inp_moptions->imo_multicast_ifp != NULL) { + struct ifnet *ifp = inp->inp_moptions->imo_multicast_ifp; + struct in_ifaddr *ia; + + CK_STAILQ_FOREACH(ia, &V_in_ifaddrhead, ia_link) { + if (ia->ia_ifp == ifp && + prison_check_ip4(cred, &ia->ia_addr.sin_addr) == 0) + break; + } + if (ia == NULL) + return (EADDRNOTAVAIL); + *laddr = ia->ia_addr.sin_addr; + return (0); + } + error = 0; nh = NULL;