All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH nf-next, v2 1/3] netfilter: xt_TEE: always allocate private area
@ 2015-06-18 18:13 Pablo Neira Ayuso
  2015-06-18 18:13 ` =?y?q?=5BPATCH=20nf-next=2C=20v2=202/3=5D=20netfilter=3A=20move=20generic=20TEE=20code=20from=20xtables=20to=20nf=5Ftee=5Fipv=7B4=2C6=7D=20modules?= Pablo Neira Ayuso
  2015-06-18 18:13 ` [PATCH nf-next, v2 3/3] netfilter: nf_tables: add nft_tee expression Pablo Neira Ayuso
  0 siblings, 2 replies; 3+ messages in thread
From: Pablo Neira Ayuso @ 2015-06-18 18:13 UTC (permalink / raw)
  To: netfilter-devel; +Cc: kaber, arturo.borrero.glez

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


^ permalink raw reply related	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2015-06-18 18:08 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-06-18 18:13 [PATCH nf-next, v2 1/3] netfilter: xt_TEE: always allocate private area Pablo Neira Ayuso
2015-06-18 18:13 ` =?y?q?=5BPATCH=20nf-next=2C=20v2=202/3=5D=20netfilter=3A=20move=20generic=20TEE=20code=20from=20xtables=20to=20nf=5Ftee=5Fipv=7B4=2C6=7D=20modules?= Pablo Neira Ayuso
2015-06-18 18:13 ` [PATCH nf-next, v2 3/3] netfilter: nf_tables: add nft_tee expression Pablo Neira Ayuso

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.