From nobody Tue Dec 17 10:07:46 2024 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 4YCCDL6PTwz5h0cN; Tue, 17 Dec 2024 10:07: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 4YCCDL533Lz49j8; Tue, 17 Dec 2024 10:07:46 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1734430066; 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=XfciJfgeNg/9GtQ+XR5CPPewP3LcdN7gMq6L+rQyZuY=; b=b+Ek196cpFOw+4N/o0KL7oV91CUS6yaKCGVl139KjFzVTVLnSwOF9iyI4wkvVcu1D6fJFH k1ujTNr4MC/xTkFA+2dh/P6Tg7WjUx7+7zqqBskQ3FKJ4rbZgJh9ZRrO2hfcK+IKZqjcV1 r13wZXeDe2E+TDUHEu36WUrZ6UG0djwPQUY5/qMnxd2M3GNfKGYaat5KRSqm9Bab2nzPiR 642AMkf/36eXNuzy3yPIR8OgSk1D+ugIC67FXbuUocJQ5DtQVarEu6l1HCdJPXvavZUSz9 UKAe5C+HA33fhKwhwphvbUUF1fYhnJeCP5pdPgBTTcKkAynORMXVsdRavqvUIQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1734430066; 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=XfciJfgeNg/9GtQ+XR5CPPewP3LcdN7gMq6L+rQyZuY=; b=WlamiNMGETdhONo8hvkvtlm04pYQsjRa4Yb9tpHrdMegyCepgr6yFf6wH6ss3o5pt6Paz8 iaZXN6bL6wEMCieEvGbJY3e8u5J8iErflFrtjyLNBTeZeQm0yhGc5OCioFUdXuD+kdBJOf olewQwptc7h5glVZ6+UUhOZY3QwIXuOk0zXbo/+sx/paxoWYmymrBXOFc/zPAGXzUGhTKj ApO4nn3lkiQnoEr3RMNA4E3pVuzuJB71ogLiZDP9jJFTN5UGzUSCX+fWlmON5t+v3vy2z/ Q1aX894vaCuFXy2lscOAKG/7E5esY+NyDtJsQuZv1DT7P6XHJjDXNGRbu7uB0Q== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1734430066; a=rsa-sha256; cv=none; b=QpvjlcpHl9EU0iL04vY+M1zjqgm3R8R4uIsYQyZUCuO10UaljbY6ImTulF9PK8f6v1Nf4i wJSRFWdfwgVWnQhFu2/ySBd3syoIPntiqHiXLh1c0XPKCthwTcB3OKjs/Yb9jakISLC5xf bey502bJ/yHR14hM8LOxeDm7If0Dwzp0xjWAVmzG8EyJK41kQ7OXHje6Mg/sUoGA8BXjLr BwHhHAh/zMLmSi8wjoKsNiBNIcuiwHQgJK2/emxAvArIzpErMLcPZaFaiNgn+gJxCd/070 4ynaN76uHLIPNAbWWBkKvCUE1zo362h4s1uwq15oSztNBeVPQw9GvHmL3Rb45w== 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 4YCCDL47sjzJvY; Tue, 17 Dec 2024 10:07:46 +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 4BHA7kLg023524; Tue, 17 Dec 2024 10:07:46 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 4BHA7kpe023521; Tue, 17 Dec 2024 10:07:46 GMT (envelope-from git) Date: Tue, 17 Dec 2024 10:07:46 GMT Message-Id: <202412171007.4BHA7kpe023521@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Kristof Provost Subject: git: d89a5d853e2b - main - pf: support nat64 for SCTP 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: kp X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: d89a5d853e2bd86490268b55ecdc7e77fefc4ba9 Auto-Submitted: auto-generated The branch main has been updated by kp: URL: https://cgit.FreeBSD.org/src/commit/?id=d89a5d853e2bd86490268b55ecdc7e77fefc4ba9 commit d89a5d853e2bd86490268b55ecdc7e77fefc4ba9 Author: Kristof Provost AuthorDate: 2024-11-07 14:05:49 +0000 Commit: Kristof Provost CommitDate: 2024-12-17 10:07:13 +0000 pf: support nat64 for SCTP Sponsored by: Rubicon Communications, LLC ("Netgate") Differential Revision: https://reviews.freebsd.org/D47789 --- sys/netpfil/pf/pf.c | 88 +++++++++++++++++++++++++++++++++++++++++------------ 1 file changed, 69 insertions(+), 19 deletions(-) diff --git a/sys/netpfil/pf/pf.c b/sys/netpfil/pf/pf.c index 36bb0e1975fa..234cbc0854be 100644 --- a/sys/netpfil/pf/pf.c +++ b/sys/netpfil/pf/pf.c @@ -6265,6 +6265,21 @@ pf_translate(struct pf_pdesc *pd, struct pf_addr *saddr, u_int16_t sport, } break; + case IPPROTO_SCTP: { + uint16_t checksum = 0; + if (afto || *pd->sport != sport) { + pf_change_ap(pd->m, pd->src, pd->sport, pd->ip_sum, &checksum, + saddr, sport, 1, pd->af, pd->naf); + rewrite = 1; + } + if (afto || *pd->dport != dport) { + pf_change_ap(pd->m, pd->dst, pd->dport, pd->ip_sum, &checksum, + daddr, dport, 1, pd->af, pd->naf); + rewrite = 1; + } + break; + } + #ifdef INET case IPPROTO_ICMP: /* pf_translate() is also used when logging invalid packets */ @@ -7047,6 +7062,33 @@ pf_test_state_udp(struct pf_kstate **state, struct pf_pdesc *pd) return (action); } +static int +pf_sctp_track(struct pf_kstate *state, struct pf_pdesc *pd, + u_short *reason) +{ + struct pf_state_peer *src; + if (pd->dir == state->direction) { + if (PF_REVERSED_KEY(state->key, pd->af)) + src = &state->dst; + else + src = &state->src; + } else { + if (PF_REVERSED_KEY(state->key, pd->af)) + src = &state->src; + else + src = &state->dst; + } + + if (src->scrub != NULL) { + if (src->scrub->pfss_v_tag == 0) + src->scrub->pfss_v_tag = pd->hdr.sctp.v_tag; + else if (src->scrub->pfss_v_tag != pd->hdr.sctp.v_tag) + return (PF_DROP); + } + + return (PF_PASS); +} + static int pf_test_state_sctp(struct pf_kstate **state, struct pf_pdesc *pd, u_short *reason) @@ -7123,37 +7165,45 @@ pf_test_state_sctp(struct pf_kstate **state, struct pf_pdesc *pd, (*state)->timeout = PFTM_SCTP_CLOSED; } - if (src->scrub != NULL) { - if (src->scrub->pfss_v_tag == 0) { - src->scrub->pfss_v_tag = pd->hdr.sctp.v_tag; - } else if (src->scrub->pfss_v_tag != pd->hdr.sctp.v_tag) - return (PF_DROP); - } + if (pf_sctp_track(*state, pd, reason) != PF_PASS) + return (PF_DROP); (*state)->expire = pf_get_uptime(); /* translate source/destination address, if necessary */ if ((*state)->key[PF_SK_WIRE] != (*state)->key[PF_SK_STACK]) { uint16_t checksum = 0; - struct pf_state_key *nk = (*state)->key[pd->didx]; + struct pf_state_key *nk; + int afto, sidx, didx; - if (pd->af != nk->af) { - /* XXX No nat64 for SCTP for now. */ - return (PF_DROP); - } + if (PF_REVERSED_KEY((*state)->key, pd->af)) + nk = (*state)->key[pd->sidx]; + else + nk = (*state)->key[pd->didx]; - if (PF_ANEQ(pd->src, &nk->addr[pd->sidx], pd->af) || - nk->port[pd->sidx] != pd->hdr.sctp.src_port) { + afto = pd->af != nk->af; + sidx = afto ? pd->didx : pd->sidx; + didx = afto ? pd->sidx : pd->didx; + + if (afto || PF_ANEQ(pd->src, &nk->addr[sidx], pd->af) || + nk->port[sidx] != pd->hdr.sctp.src_port) { pf_change_ap(pd->m, pd->src, &pd->hdr.sctp.src_port, - pd->ip_sum, &checksum, &nk->addr[pd->sidx], - nk->port[pd->sidx], 1, pd->af, pd->naf); + pd->ip_sum, &checksum, &nk->addr[sidx], + nk->port[sidx], 1, pd->af, pd->naf); } - if (PF_ANEQ(pd->dst, &nk->addr[pd->didx], pd->af) || - nk->port[pd->didx] != pd->hdr.sctp.dest_port) { + if (afto || PF_ANEQ(pd->dst, &nk->addr[didx], pd->af) || + nk->port[didx] != pd->hdr.sctp.dest_port) { pf_change_ap(pd->m, pd->dst, &pd->hdr.sctp.dest_port, - pd->ip_sum, &checksum, &nk->addr[pd->didx], - nk->port[pd->didx], 1, pd->af, pd->naf); + pd->ip_sum, &checksum, &nk->addr[didx], + nk->port[didx], 1, pd->af, pd->naf); + } + + if (afto) { + PF_ACPY(&pd->nsaddr, &nk->addr[sidx], nk->af); + PF_ACPY(&pd->ndaddr, &nk->addr[didx], nk->af); + pd->naf = nk->af; + return (PF_AFRT); } }