From nobody Mon Oct 02 09:33:27 2023 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 4RzbNm2nXsz4vrH3; Mon, 2 Oct 2023 09:33:28 +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 "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4RzbNm25Jvz4Sbh; Mon, 2 Oct 2023 09:33:28 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1696239208; 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=tMLM5N8tWc43jfTTtwMvD464GBxC5A1uWMf81zWjsso=; b=d6Far1a6xqVJ5hVr72dweJ4nDoQ5tErJV4ZRJRNJXPZK4oiNHLA6TKZqWSgqnK0nutc/nf bvInb45Mr0hjVhpE7kwsrvWDY/YM+daP6n7A7Xar6HREXOAWF/03JTK4k7kvim1GcDYWZl lxbn5/Q42wtj68BNJuPWIWexQPFdS5ozQmDWvddD7RpWKGkkBR0KanQC65ljkGPzeZvnoC oZuvmYPyZj0TS+y8RY6f3SrYNG+vF9QW8Uo+6z8HdH46tx7dYSGCjHRYw0ohvaeLT31kKO P4tv/eQRlIUFx6YhjDO3P8S2eO8StDlu+Oxo+DnhIHgX3Y9TLfF9bNSebpZ0hA== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1696239208; a=rsa-sha256; cv=none; b=V2FfcjktF5/y+8VLfUSrM5PEPa78UI3IMdicqtoQ+9tIpuDRytM28q1Omt18ePt/Fw8NLk bFiFQGCTIQjgVM1UfPQBDQgzNB0uhWR3IOpuXyo6fns1XBbT6YCRmHvC7pNoJRUcvQKKfA Kn32TorHH8HJSvf5LOATM2lm9DWuddm/b99MYVQ3cHsLvganXX8gisdynlbAJ9mZlHC9d7 SEc2FbmHA3OZDfcT0/NVXcKrqJ+AoQOm9G+5+3z3A8qrg7mFbfZ99JxUusY39CFnAplWfM p22VeUUpphEWUvBzJ/0Et5dwmrRBtacTSIff8iNvXa21GnUc0e+3KEzu3N6Yfg== 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=1696239208; 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=tMLM5N8tWc43jfTTtwMvD464GBxC5A1uWMf81zWjsso=; b=ONLZs4ImMPKFRspsPmFEz9wTrvjUpvvJ18vklj60zB9vAQVK1DvKDkTTwJYTsApr7mqwfS 90Dvauws7Z0VlRBlypsc6Bb30CepFSRYokWsGUSGqMd42uUaO+Lg+NlOF2XCs/jxmxQb14 lPQS1CqkLmj+OD3ZNRMExQixwUVbgoOTSfHidsjephOGmPks0V5UqgIYGcVhzuBl1EQVk2 H9Za+B4+SM2nXM0YHpXidYW5sk12xBhtn3kK1YnkVHbkO8URcksa6BeXPn8ByQDSL2tzEl coXGQScCG3CVpDew4ik/CGzN9Bg5TE8hu7uDLnTSxmbRiZosObl1ii0AqAmEaQ== 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 4RzbNm0cj6z16CD; Mon, 2 Oct 2023 09:33:28 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.17.1/8.17.1) with ESMTP id 3929XRWu003226; Mon, 2 Oct 2023 09:33:27 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 3929XRhc003217; Mon, 2 Oct 2023 09:33:27 GMT (envelope-from git) Date: Mon, 2 Oct 2023 09:33:27 GMT Message-Id: <202310020933.3929XRhc003217@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Kristof Provost Subject: git: 95f44dd698b0 - stable/13 - pf: mark removed connections within a multihome association as shutting down 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: Sender: owner-dev-commits-src-all@freebsd.org X-BeenThere: dev-commits-src-all@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: kp X-Git-Repository: src X-Git-Refname: refs/heads/stable/13 X-Git-Reftype: branch X-Git-Commit: 95f44dd698b0439b51788951f840b501651ecebf Auto-Submitted: auto-generated The branch stable/13 has been updated by kp: URL: https://cgit.FreeBSD.org/src/commit/?id=95f44dd698b0439b51788951f840b501651ecebf commit 95f44dd698b0439b51788951f840b501651ecebf Author: Kristof Provost AuthorDate: 2023-09-05 16:30:42 +0000 Commit: Kristof Provost CommitDate: 2023-10-02 08:51:44 +0000 pf: mark removed connections within a multihome association as shutting down Parse IP removal in ASCONF chunks, find the affected state(s) and mark them as shutting down. This will cause them to time out according to PFTM_TCP_CLOSING timeouts, rather than waiting for the established session timeout. MFC after: 3 weeks Sponsored by: Orange Business Services (cherry picked from commit 4d3af82f78961180149e8a579b481dc382f76eef) --- sys/net/pfvar.h | 1 + sys/netpfil/pf/pf.c | 87 ++++++++++++++++++++++++++++++++++++++++++++--------- 2 files changed, 73 insertions(+), 15 deletions(-) diff --git a/sys/net/pfvar.h b/sys/net/pfvar.h index 3cb093ba8b02..9c6f5bccae02 100644 --- a/sys/net/pfvar.h +++ b/sys/net/pfvar.h @@ -1348,6 +1348,7 @@ struct pf_sctp_multihome_job { struct pf_addr src; struct pf_addr dst; struct mbuf *m; + int op; }; #endif diff --git a/sys/netpfil/pf/pf.c b/sys/netpfil/pf/pf.c index be4fa4273972..55942fcf4338 100644 --- a/sys/netpfil/pf/pf.c +++ b/sys/netpfil/pf/pf.c @@ -5355,17 +5355,57 @@ pf_sctp_multihome_delayed(struct pf_pdesc *pd, int off, struct pfi_kkif *kif, PF_RULES_RLOCK_TRACKER; TAILQ_FOREACH_SAFE(j, &pd->sctp_multihome_jobs, next, tmp) { - PF_RULES_RLOCK(); - j->pd.sctp_flags |= PFDESC_SCTP_ADD_IP; - action = pf_test_rule(&r, &sm, pd->dir, kif, - j->m, off, &j->pd, &ra, &rs, NULL); - PF_RULES_RUNLOCK(); - SDT_PROBE4(pf, sctp, multihome, test, kif, r, j->m, action); - if (sm) { - /* Inherit v_tag values. */ - sm->src.scrub->pfss_v_tag = s->src.scrub->pfss_flags; - sm->dst.scrub->pfss_v_tag = s->dst.scrub->pfss_flags; - PF_STATE_UNLOCK(sm); + switch (j->op) { + case SCTP_ADD_IP_ADDRESS: { + j->pd.sctp_flags |= PFDESC_SCTP_ADD_IP; + PF_RULES_RLOCK(); + action = pf_test_rule(&r, &sm, pd->dir, kif, + j->m, off, &j->pd, &ra, &rs, NULL); + PF_RULES_RUNLOCK(); + SDT_PROBE4(pf, sctp, multihome, test, kif, r, j->m, action); + if (sm) { + /* Inherit v_tag values. */ + sm->src.scrub->pfss_v_tag = s->src.scrub->pfss_flags; + sm->dst.scrub->pfss_v_tag = s->dst.scrub->pfss_flags; + PF_STATE_UNLOCK(sm); + } + break; + } + case SCTP_DEL_IP_ADDRESS: { + struct pf_state_key_cmp key; + uint8_t psrc; + + bzero(&key, sizeof(key)); + key.af = j->pd.af; + key.proto = IPPROTO_SCTP; + if (j->pd.dir == PF_IN) { /* wire side, straight */ + PF_ACPY(&key.addr[0], j->pd.src, key.af); + PF_ACPY(&key.addr[1], j->pd.dst, key.af); + key.port[0] = j->pd.hdr.sctp.src_port; + key.port[1] = j->pd.hdr.sctp.dest_port; + } else { /* stack side, reverse */ + PF_ACPY(&key.addr[1], j->pd.src, key.af); + PF_ACPY(&key.addr[0], j->pd.dst, key.af); + key.port[1] = j->pd.hdr.sctp.src_port; + key.port[0] = j->pd.hdr.sctp.dest_port; + } + + sm = pf_find_state(kif, &key, j->pd.dir); + if (sm != NULL) { + PF_STATE_LOCK_ASSERT(sm); + if (j->pd.dir == sm->direction) { + psrc = PF_PEER_SRC; + } else { + psrc = PF_PEER_DST; + } + pf_set_protostate(sm, psrc, SCTP_SHUTDOWN_PENDING); + sm->timeout = PFTM_TCP_CLOSING; + PF_STATE_UNLOCK(sm); + } + break; + default: + panic("Unknown op %#x", j->op); + } } free(j, M_PFTEMP); @@ -5374,7 +5414,7 @@ pf_sctp_multihome_delayed(struct pf_pdesc *pd, int off, struct pfi_kkif *kif, static int pf_multihome_scan(struct mbuf *m, int start, int len, struct pf_pdesc *pd, - struct pfi_kkif *kif) + struct pfi_kkif *kif, int op) { int off = 0; struct pf_sctp_multihome_job *job; @@ -5436,6 +5476,7 @@ pf_multihome_scan(struct mbuf *m, int start, int len, struct pf_pdesc *pd, memcpy(&job->dst, pd->dst, sizeof(job->dst)); job->pd.dst = &job->dst; job->m = m; + job->op = op; TAILQ_INSERT_TAIL(&pd->sctp_multihome_jobs, job, next); break; @@ -5466,6 +5507,7 @@ pf_multihome_scan(struct mbuf *m, int start, int len, struct pf_pdesc *pd, memcpy(&job->dst, pd->dst, sizeof(job->dst)); job->pd.dst = &job->dst; job->m = m; + job->op = op; TAILQ_INSERT_TAIL(&pd->sctp_multihome_jobs, job, next); break; @@ -5480,7 +5522,22 @@ pf_multihome_scan(struct mbuf *m, int start, int len, struct pf_pdesc *pd, return (PF_DROP); ret = pf_multihome_scan(m, start + off + sizeof(ah), - ntohs(ah.ph.param_length) - sizeof(ah), pd, kif); + ntohs(ah.ph.param_length) - sizeof(ah), pd, kif, + SCTP_ADD_IP_ADDRESS); + if (ret != PF_PASS) + return (ret); + break; + } + case SCTP_DEL_IP_ADDRESS: { + int ret; + struct sctp_asconf_paramhdr ah; + + if (!pf_pull_hdr(m, start + off, &ah, sizeof(ah), + NULL, NULL, pd->af)) + return (PF_DROP); + ret = pf_multihome_scan(m, start + off + sizeof(ah), + ntohs(ah.ph.param_length) - sizeof(ah), pd, kif, + SCTP_DEL_IP_ADDRESS); if (ret != PF_PASS) return (ret); break; @@ -5502,7 +5559,7 @@ pf_multihome_scan_init(struct mbuf *m, int start, int len, struct pf_pdesc *pd, start += sizeof(struct sctp_init_chunk); len -= sizeof(struct sctp_init_chunk); - return (pf_multihome_scan(m, start, len, pd, kif)); + return (pf_multihome_scan(m, start, len, pd, kif, SCTP_ADD_IP_ADDRESS)); } int @@ -5512,7 +5569,7 @@ pf_multihome_scan_asconf(struct mbuf *m, int start, int len, start += sizeof(struct sctp_asconf_chunk); len -= sizeof(struct sctp_asconf_chunk); - return (pf_multihome_scan(m, start, len, pd, kif)); + return (pf_multihome_scan(m, start, len, pd, kif, SCTP_ADD_IP_ADDRESS)); } static int