netfilter-devel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Pablo Neira Ayuso <pablo@netfilter.org>
To: netfilter-devel@vger.kernel.org
Cc: kaber@trash.net, arturo.borrero.glez@gmail.com
Subject: [PATCH nf-next 2/4] netfilter: xt_TEE: always allocate private area
Date: Fri, 12 Jun 2015 13:59:36 +0200	[thread overview]
Message-ID: <1434110378-6284-1-git-send-email-pablo@netfilter.org> (raw)

This simplifies the integration with nf_tables at the cost of consuming little
extra memory per rule, and I don't expect many rules using TEE in a ruleset.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
---
 net/netfilter/xt_TEE.c |   40 ++++++++++++++++++++++++----------------
 1 file changed, 24 insertions(+), 16 deletions(-)

diff --git a/net/netfilter/xt_TEE.c b/net/netfilter/xt_TEE.c
index a747eb4..189ad13 100644
--- a/net/netfilter/xt_TEE.c
+++ b/net/netfilter/xt_TEE.c
@@ -53,6 +53,11 @@ static struct net *pick_net(struct sk_buff *skb)
 	return &init_net;
 }
 
+static inline bool tee_has_notifier(const struct xt_tee_tginfo *info)
+{
+	return info->priv->notifier.notifier_call != NULL;
+}
+
 static bool
 tee_tg_route4(struct sk_buff *skb, const struct xt_tee_tginfo *info)
 {
@@ -62,7 +67,7 @@ tee_tg_route4(struct sk_buff *skb, const struct xt_tee_tginfo *info)
 	struct flowi4 fl4;
 
 	memset(&fl4, 0, sizeof(fl4));
-	if (info->priv) {
+	if (tee_has_notifier(info)) {
 		if (info->priv->oif == -1)
 			return false;
 		fl4.flowi4_oif = info->priv->oif;
@@ -144,7 +149,7 @@ tee_tg_route6(struct sk_buff *skb, const struct xt_tee_tginfo *info)
 	struct flowi6 fl6;
 
 	memset(&fl6, 0, sizeof(fl6));
-	if (info->priv) {
+	if (tee_has_notifier(info)) {
 		if (info->priv->oif == -1)
 			return false;
 		fl6.flowi6_oif = info->priv->oif;
@@ -235,34 +240,37 @@ static int tee_tg_check(const struct xt_tgchk_param *par)
 		   sizeof(tee_zero_address)) == 0)
 		return -EINVAL;
 
+	priv = kzalloc(sizeof(*priv), GFP_KERNEL);
+	if (priv == NULL)
+		return -ENOMEM;
+
+	priv->tginfo	= info;
+	priv->oif	= -1;
+
 	if (info->oif[0]) {
 		if (info->oif[sizeof(info->oif)-1] != '\0')
-			return -EINVAL;
-
-		priv = kzalloc(sizeof(*priv), GFP_KERNEL);
-		if (priv == NULL)
-			return -ENOMEM;
+			goto err1;
 
-		priv->tginfo  = info;
-		priv->oif     = -1;
 		priv->notifier.notifier_call = tee_netdev_event;
-		info->priv    = priv;
-
 		register_netdevice_notifier(&priv->notifier);
-	} else
-		info->priv = NULL;
+	}
+
+	info->priv	= priv;
 
 	return 0;
+err1:
+	kfree(priv);
+	return -EINVAL;
 }
 
 static void tee_tg_destroy(const struct xt_tgdtor_param *par)
 {
 	struct xt_tee_tginfo *info = par->targinfo;
 
-	if (info->priv) {
+	if (tee_has_notifier(info))
 		unregister_netdevice_notifier(&info->priv->notifier);
-		kfree(info->priv);
-	}
+
+	kfree(info->priv);
 }
 
 static struct xt_target tee_tg_reg[] __read_mostly = {
-- 
1.7.10.4


             reply	other threads:[~2015-06-12 11:54 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-06-12 11:59 Pablo Neira Ayuso [this message]
2015-06-12 11:59 ` =?y?q?=5BPATCH=20nf-next=203/4=5D=20netfilter=3A=20move=20generic=20TEE=20code=20from=20xtables=20to=20nf=5Ftee=5Fipv=7B4=2C6=7D=20modules?= Pablo Neira Ayuso
2015-06-16 16:33   ` [PATCH nf-next 3/4] netfilter: move generic TEE code from xtables to nf_tee_ipv{4,6} modules Pablo Neira Ayuso
2015-06-16 16:37     ` Pablo Neira Ayuso
2015-06-17  6:05       ` Patrick McHardy
2015-06-12 11:59 ` [PATCH nf-next 4/4] netfilter: nf_tables: add nft_tee expression Pablo Neira Ayuso

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=1434110378-6284-1-git-send-email-pablo@netfilter.org \
    --to=pablo@netfilter.org \
    --cc=arturo.borrero.glez@gmail.com \
    --cc=kaber@trash.net \
    --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).