From nobody Mon Apr 18 09:16:39 2022 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 DCAF211E0C6E; Mon, 18 Apr 2022 09:16:39 +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 4KhhBv5qhZz4vKN; Mon, 18 Apr 2022 09:16:39 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1650273399; 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=Wr1ZYYrf0/3jKFHBgZ4Seg9PZCFZCzFDAVApR3AxosY=; b=RUwkhAe9F8/29+vns/zGj3LOgrlUS2OQ6F2j/ptWc5F3s+tH67JQ1iNFehG/pq1VZS12Qd WgwGrKNyYbaupZBK16Jpmp9lQ12sxXPQw2RxaPIx6DAf885yLGYKpwJ/MfxhJ83WEi6RTn 7gX7TCCshs97bx6PZgaG6SAwkchbY/PNsxE653XtGjytv51Uk9CxRKR09MNla6oKWFL2Lk tq49n+5ig1KeheccitbruX7Ck3pcEm4X52FTt1Ob/Lxtuc9nL/rOHD+rO/MCd44fcYRAmU SlFSa+uAg1GyjYnjuY+7lFA4RAZeKtD6ENoE9lfcvJ+7FKfYuj7Y3Egt9xlzmg== 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 A42347CBD; Mon, 18 Apr 2022 09:16:39 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 23I9GdGh092226; Mon, 18 Apr 2022 09:16:39 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 23I9Gdcc092225; Mon, 18 Apr 2022 09:16:39 GMT (envelope-from git) Date: Mon, 18 Apr 2022 09:16:39 GMT Message-Id: <202204180916.23I9Gdcc092225@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: "Andrey V. Elsukov" Subject: git: 836f54302e3f - stable/13 - ipfw: fix matching and setting DSCP value for IPv6 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: ae X-Git-Repository: src X-Git-Refname: refs/heads/stable/13 X-Git-Reftype: branch X-Git-Commit: 836f54302e3f7d8812aaf84778e7cc175a8ce5ad Auto-Submitted: auto-generated ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1650273399; 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=Wr1ZYYrf0/3jKFHBgZ4Seg9PZCFZCzFDAVApR3AxosY=; b=Uo6hRNg94+kVRSvfPduXlWRdGhSFELZoXb6LfSrZYUpYblHvCOYmuBfj7fmaePYlum3Gic Bj6XoL8uJfN4yFLylfWyNHbL/qQd3FkMIcmv5ajtQiTPHxJMX8Hgp6wwb6GfmTQfqu6435 MIc8pHW7ceVB2o2TFgUDc9REOxtb1Z0puZBd8QkGVapkLA6Na4ZyUzipKBtLdYDzjeHy5N rYyzDMyDf4nvn4UPSOiY0PmXF9qiZanWQBPJb+pgHj0Ynt+FHn5qx2+lK9kcqft1+u9cOk gcNIEotpvkjJEhPSOXH8szOyaxOv9IasKvE9+rRpmmnlSGCYxi24kU7bEg6qDg== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1650273399; a=rsa-sha256; cv=none; b=ryO3PFGh9dhAGCLCbVuHniP6xha1Kp2T8g9VI8ZbR7zz01bFsK6tHMJN91g3aonG9UGQhN dugmZaYUXOZ8/VSf3Nzh24gpL3Vv97GDH5lXP5S/c/x8Lj9Y+CBlM9gol+pcICH8AZQUbA bhaK8pJ5g4sciU3C3XKWoFRU/nleYIki9b9NA2ihXq4JlxnxcxSD9PGyrbf21jxUiaxDSd ClNXu+wIavzPFNU62dmSMwVXKuTcPF+WyjkHlazK+o/BCvVI2YUoKmp9W7/Ll3n/dx26wm idq9/A9rZ4uYnfkQVkepOK7zwJao9CKaisDtJEhueXsE8IKIKoDBizAatqoqSw== ARC-Authentication-Results: i=1; mx1.freebsd.org; none X-ThisMailContainsUnwantedMimeParts: N The branch stable/13 has been updated by ae: URL: https://cgit.FreeBSD.org/src/commit/?id=836f54302e3f7d8812aaf84778e7cc175a8ce5ad commit 836f54302e3f7d8812aaf84778e7cc175a8ce5ad Author: Andrey V. Elsukov AuthorDate: 2022-04-06 18:43:50 +0000 Commit: Andrey V. Elsukov CommitDate: 2022-04-18 09:15:46 +0000 ipfw: fix matching and setting DSCP value for IPv6 Matching for DSCP codes has used incorrect bits. Use IPV6_DSCP() macro for matching opcodes to fix this. Also this leads to always use value from a mbuf instead of cached value. Previously different opcodes have used both cached in f_id value and stored in the mbuf, and it did not always work after setdscp action, since cached value was not updated. Update IPv6 flowid value cached in the f_id.flow_id6 when we do modification of DSCP value in O_SETDSCP opcode, it may be used by external modules. Also added logging support for O_SETDSCP opcode. Reviewed by: kp Differential Revision: https://reviews.freebsd.org/D34807 (cherry picked from commit 4763c0aa68a7147258922a33a8401f1f2067ba49) --- sys/netpfil/ipfw/ip_fw2.c | 27 ++++++++++++--------------- sys/netpfil/ipfw/ip_fw_log.c | 7 +++++-- 2 files changed, 17 insertions(+), 17 deletions(-) diff --git a/sys/netpfil/ipfw/ip_fw2.c b/sys/netpfil/ipfw/ip_fw2.c index bcf775009d25..7775b519270f 100644 --- a/sys/netpfil/ipfw/ip_fw2.c +++ b/sys/netpfil/ipfw/ip_fw2.c @@ -2064,11 +2064,9 @@ do { \ else if (vidx == 6 /* dscp */) { if (is_ipv4) key = ip->ip_tos >> 2; - else { - key = args->f_id.flow_id6; - key = (key & 0x0f) << 2 | - (key & 0xf000) >> 14; - } + else + key = IPV6_DSCP( + (struct ip6_hdr *)ip) >> 2; key &= 0x3f; } else if (vidx == 2 /* dst-port */ || vidx == 3 /* src-port */) { @@ -2328,11 +2326,9 @@ do { \ if (is_ipv4) x = ip->ip_tos >> 2; else if (is_ipv6) { - uint8_t *v; - v = &((struct ip6_hdr *)ip)->ip6_vfc; - x = (*v & 0x0F) << 2; - v++; - x |= *v >> 6; + x = IPV6_DSCP( + (struct ip6_hdr *)ip) >> 2; + x &= 0x3f; } else break; @@ -3139,12 +3135,13 @@ do { \ ip->ip_sum = cksum_adjust(ip->ip_sum, old, *(uint16_t *)ip); } else if (is_ipv6) { - uint8_t *v; + /* update cached value */ + args->f_id.flow_id6 = + ntohl(*(uint32_t *)ip) & ~0x0FC00000; + args->f_id.flow_id6 |= code << 22; - v = &((struct ip6_hdr *)ip)->ip6_vfc; - *v = (*v & 0xF0) | (code >> 2); - v++; - *v = (*v & 0x3F) | ((code & 0x03) << 6); + *((uint32_t *)ip) = + htonl(args->f_id.flow_id6); } else break; diff --git a/sys/netpfil/ipfw/ip_fw_log.c b/sys/netpfil/ipfw/ip_fw_log.c index 78412b5db702..969823ebf86f 100644 --- a/sys/netpfil/ipfw/ip_fw_log.c +++ b/sys/netpfil/ipfw/ip_fw_log.c @@ -156,8 +156,7 @@ ipfw_log(struct ip_fw_chain *chain, struct ip_fw *f, u_int hlen, altq->qid); cmd += F_LEN(cmd); } - if (cmd->opcode == O_PROB || cmd->opcode == O_TAG || - cmd->opcode == O_SETDSCP) + if (cmd->opcode == O_PROB || cmd->opcode == O_TAG) cmd += F_LEN(cmd); action = action2; @@ -202,6 +201,10 @@ ipfw_log(struct ip_fw_chain *chain, struct ip_fw *f, u_int hlen, snprintf(SNPARGS(action2, 0), "Tee %d", TARG(cmd->arg1, divert)); break; + case O_SETDSCP: + snprintf(SNPARGS(action2, 0), "SetDscp %d", + TARG(cmd->arg1, dscp) & 0x3F); + break; case O_SETFIB: snprintf(SNPARGS(action2, 0), "SetFib %d", TARG(cmd->arg1, fib) & 0x7FFF);