From: Pablo Neira Ayuso <pablo@netfilter.org>
To: netfilter-devel@vger.kernel.org
Cc: davem@davemloft.net, netdev@vger.kernel.org
Subject: [PATCH 06/12] netfilter: nft_ct: add notrack support
Date: Tue, 1 Nov 2016 22:26:27 +0100 [thread overview]
Message-ID: <1478035593-1362-7-git-send-email-pablo@netfilter.org> (raw)
In-Reply-To: <1478035593-1362-1-git-send-email-pablo@netfilter.org>
This patch adds notrack support.
I decided to add a new expression, given that this doesn't fit into the
existing set operation. Notrack doesn't need a source register, and an
hypothetical NFT_CT_NOTRACK key makes no sense since matching the
untracked state is done through NFT_CT_STATE.
I'm placing this new notrack expression into nft_ct.c, I think a single
module is too much.
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
---
net/netfilter/nft_ct.c | 50 +++++++++++++++++++++++++++++++++++++++++++++++++-
1 file changed, 49 insertions(+), 1 deletion(-)
diff --git a/net/netfilter/nft_ct.c b/net/netfilter/nft_ct.c
index d7b0d171172a..6837348c8993 100644
--- a/net/netfilter/nft_ct.c
+++ b/net/netfilter/nft_ct.c
@@ -1,5 +1,6 @@
/*
* Copyright (c) 2008-2009 Patrick McHardy <kaber@trash.net>
+ * Copyright (c) 2016 Pablo Neira Ayuso <pablo@netfilter.org>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
@@ -518,15 +519,61 @@ static struct nft_expr_type nft_ct_type __read_mostly = {
.owner = THIS_MODULE,
};
+static void nft_notrack_eval(const struct nft_expr *expr,
+ struct nft_regs *regs,
+ const struct nft_pktinfo *pkt)
+{
+ struct sk_buff *skb = pkt->skb;
+ enum ip_conntrack_info ctinfo;
+ struct nf_conn *ct;
+
+ ct = nf_ct_get(pkt->skb, &ctinfo);
+ /* Previously seen (loopback or untracked)? Ignore. */
+ if (ct)
+ return;
+
+ ct = nf_ct_untracked_get();
+ atomic_inc(&ct->ct_general.use);
+ skb->nfct = &ct->ct_general;
+ skb->nfctinfo = IP_CT_NEW;
+}
+
+static struct nft_expr_type nft_notrack_type;
+static const struct nft_expr_ops nft_notrack_ops = {
+ .type = &nft_notrack_type,
+ .size = NFT_EXPR_SIZE(0),
+ .eval = nft_notrack_eval,
+};
+
+static struct nft_expr_type nft_notrack_type __read_mostly = {
+ .name = "notrack",
+ .ops = &nft_notrack_ops,
+ .owner = THIS_MODULE,
+};
+
static int __init nft_ct_module_init(void)
{
+ int err;
+
BUILD_BUG_ON(NF_CT_LABELS_MAX_SIZE > NFT_REG_SIZE);
- return nft_register_expr(&nft_ct_type);
+ err = nft_register_expr(&nft_ct_type);
+ if (err < 0)
+ return err;
+
+ err = nft_register_expr(&nft_notrack_type);
+ if (err < 0)
+ goto err1;
+
+ return 0;
+err1:
+ nft_unregister_expr(&nft_ct_type);
+ return err;
}
static void __exit nft_ct_module_exit(void)
{
+ nft_unregister_expr(&nft_notrack_type);
nft_unregister_expr(&nft_ct_type);
}
@@ -536,3 +583,4 @@ module_exit(nft_ct_module_exit);
MODULE_LICENSE("GPL");
MODULE_AUTHOR("Patrick McHardy <kaber@trash.net>");
MODULE_ALIAS_NFT_EXPR("ct");
+MODULE_ALIAS_NFT_EXPR("notrack");
--
2.1.4
next prev parent reply other threads:[~2016-11-01 21:26 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-11-01 21:26 [PATCH 00/12] Netfilter updates for net-next Pablo Neira Ayuso
2016-11-01 21:26 ` [PATCH 01/12] netfilter: xt_multiport: Use switch case instead of multiple condition checks Pablo Neira Ayuso
2016-11-01 21:26 ` [PATCH 02/12] netfilter: nfnetlink_log: Use GFP_NOWARN for skb allocation Pablo Neira Ayuso
2016-11-01 21:26 ` [PATCH 03/12] netfilter: nf_tables: allow expressions to return STOLEN Pablo Neira Ayuso
2016-11-01 21:26 ` [PATCH 04/12] netfilter: nft_numgen: start round robin from zero Pablo Neira Ayuso
2016-11-01 21:26 ` [PATCH 05/12] netfilter: nft_meta: permit pkttype mangling in ip/ip6 prerouting Pablo Neira Ayuso
2016-11-01 21:26 ` Pablo Neira Ayuso [this message]
2016-11-01 21:26 ` [PATCH 07/12] netfilter: nf_tables: add fib expression Pablo Neira Ayuso
2016-11-01 21:26 ` [PATCH 08/12] netfilter: nf_log: add packet logging for netdev family Pablo Neira Ayuso
2016-11-01 21:26 ` [PATCH 09/12] netfilter: move socket lookup infrastructure to nf_socket_ipv{4,6}.c Pablo Neira Ayuso
2016-11-01 21:26 ` [PATCH 10/12] netfilter: nf_tables: introduce routing expression Pablo Neira Ayuso
2016-11-01 21:26 ` [PATCH 11/12] netfilter: nf_tables: remove useless U8_MAX validation Pablo Neira Ayuso
2016-11-01 21:26 ` [PATCH 12/12] netfilter: nf_queue: place volatile data in own cacheline Pablo Neira Ayuso
2016-11-02 18:59 ` [PATCH 00/12] Netfilter updates for net-next 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=1478035593-1362-7-git-send-email-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).