From: Pablo Neira Ayuso <pablo@netfilter.org>
To: netfilter-devel@vger.kernel.org
Cc: davem@davemloft.net, netdev@vger.kernel.org
Subject: [PATCH 04/12] netfilter: xt_connmark: Add bit mapping for bit-shift operation.
Date: Mon, 23 Apr 2018 19:57:06 +0200 [thread overview]
Message-ID: <20180423175714.9794-5-pablo@netfilter.org> (raw)
In-Reply-To: <20180423175714.9794-1-pablo@netfilter.org>
From: Jack Ma <jack.ma@alliedtelesis.co.nz>
With the addition of bit-shift operations, we are able to shift
ct/skbmark based on user requirements. However, this change might also
cause the most left/right hand- side mark to be accidentially lost
during shift operations.
This patch adds the ability to 'grep' certain bits based on ctmask or
nfmask out of the original mark. Then, apply shift operations to achieve
a new mapping between ctmark and skb->mark.
For example: If someone would like save the fourth F bits of ctmark
0xFFF(F)000F into the seventh hexadecimal (0) skb->mark 0xABC000(0)E.
new_targetmark = (ctmark & ctmask) >> 12;
(new) skb->mark = (skb->mark &~nfmask) ^
new_targetmark;
This will preserve the other bits that are not related to this
operation.
Fixes: 472a73e00757 ("netfilter: xt_conntrack: Support bit-shifting for CONNMARK & MARK targets.")
Reviewed-by: Florian Westphal <fw@strlen.de>
Signed-off-by: Jack Ma <jack.ma@alliedtelesis.co.nz>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
---
net/netfilter/xt_connmark.c | 19 +++++++++++--------
1 file changed, 11 insertions(+), 8 deletions(-)
diff --git a/net/netfilter/xt_connmark.c b/net/netfilter/xt_connmark.c
index 773da82190dc..4b424e6caf3e 100644
--- a/net/netfilter/xt_connmark.c
+++ b/net/netfilter/xt_connmark.c
@@ -41,6 +41,7 @@ connmark_tg_shift(struct sk_buff *skb,
u8 shift_bits, u8 shift_dir)
{
enum ip_conntrack_info ctinfo;
+ u_int32_t new_targetmark;
struct nf_conn *ct;
u_int32_t newmark;
@@ -61,24 +62,26 @@ connmark_tg_shift(struct sk_buff *skb,
}
break;
case XT_CONNMARK_SAVE:
- newmark = (ct->mark & ~info->ctmask) ^
- (skb->mark & info->nfmask);
+ new_targetmark = (skb->mark & info->nfmask);
if (shift_dir == D_SHIFT_RIGHT)
- newmark >>= shift_bits;
+ new_targetmark >>= shift_bits;
else
- newmark <<= shift_bits;
+ new_targetmark <<= shift_bits;
+ newmark = (ct->mark & ~info->ctmask) ^
+ new_targetmark;
if (ct->mark != newmark) {
ct->mark = newmark;
nf_conntrack_event_cache(IPCT_MARK, ct);
}
break;
case XT_CONNMARK_RESTORE:
- newmark = (skb->mark & ~info->nfmask) ^
- (ct->mark & info->ctmask);
+ new_targetmark = (ct->mark & info->ctmask);
if (shift_dir == D_SHIFT_RIGHT)
- newmark >>= shift_bits;
+ new_targetmark >>= shift_bits;
else
- newmark <<= shift_bits;
+ new_targetmark <<= shift_bits;
+ newmark = (skb->mark & ~info->nfmask) ^
+ new_targetmark;
skb->mark = newmark;
break;
}
--
2.11.0
next prev parent reply other threads:[~2018-04-23 17:57 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-04-23 17:57 [PATCH 00/12] Netfilter/IPVS fixes for net Pablo Neira Ayuso
2018-04-23 17:57 ` [PATCH 01/12] netfilter: nf_conntrack_sip: allow duplicate SDP expectations Pablo Neira Ayuso
2018-04-23 17:57 ` [PATCH 02/12] ipvs: fix rtnl_lock lockups caused by start_sync_thread Pablo Neira Ayuso
2018-04-23 17:57 ` [PATCH 03/12] netfilter: ebtables: don't attempt to allocate 0-sized compat array Pablo Neira Ayuso
2018-04-24 8:55 ` Sergei Shtylyov
2018-04-23 17:57 ` Pablo Neira Ayuso [this message]
2018-04-23 17:57 ` [PATCH 05/12] netfilter: conntrack: silent a memory leak warning Pablo Neira Ayuso
2018-04-23 17:57 ` [PATCH 06/12] netfilter: fix CONFIG_NF_REJECT_IPV6=m link error Pablo Neira Ayuso
2018-04-23 17:57 ` [PATCH 07/12] netfilter: nf_tables: can't fail after linking rule into active rule list Pablo Neira Ayuso
2018-04-23 17:57 ` [PATCH 08/12] netfilter: nf_tables: free set name in error path Pablo Neira Ayuso
2018-04-23 17:57 ` [PATCH 09/12] netfilter: conntrack: include kmemleak.h for kmemleak_not_leak() Pablo Neira Ayuso
2018-04-23 17:57 ` [PATCH 10/12] netfilter: nf_tables: NAT chain and extensions require NF_TABLES Pablo Neira Ayuso
2018-04-23 17:57 ` [PATCH 11/12] netfilter: nf_tables: fix out-of-bounds in nft_chain_commit_update Pablo Neira Ayuso
2018-04-23 17:57 ` [PATCH 12/12] netfilter: xt_connmark: do not cast xt_connmark_tginfo1 to xt_connmark_tginfo2 Pablo Neira Ayuso
2018-04-23 20:22 ` [PATCH 00/12] Netfilter/IPVS fixes for net David Miller
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20180423175714.9794-5-pablo@netfilter.org \
--to=pablo@netfilter.org \
--cc=davem@davemloft.net \
--cc=netdev@vger.kernel.org \
--cc=netfilter-devel@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).