Skip to contentSkip to conversation

Netfilter updates for net-next

PATCH In review Pablo Neira Ayuso 2 participants 12 messages Oct 20, 2018

Subsystems (3)
lore
Share & tools
lore

Pablo Neira Ayuso

author maintainer
#0 lore raw

cover Netfilter updates for net-next

Hi David,

The following patchset contains Netfilter updates for your net-next tree:

1) Use lockdep_is_held() in ipset_dereference_protected(), from Lance Roy.

2) Remove unused variable in cttimeout, from YueHaibing.

3) Add ttl option for nft_osf, from Fernando Fernandez Mancera.

4) Use xfrm family to deal with IPv6-in-IPv4 packets from nft_xfrm, from Florian Westphal.

5) Simplify xt_osf_match_packet().

6) Missing ct helper alias definition in snmp_trap helper, from Taehee Yoo.

7) Remove unnecessary parameter in nf_flow_table_cleanup(), from Taehee Yoo.

8) Remove unused variable definitions in nft_{dup,fwd}, from Weongyo Jeong.

9) Remove empty net/netfilter/nfnetlink_log.h file, from Taehee Yoo.

10) Revert xt_quota updates remain option due to problems in the listing path for 32-bit arches, from Maze.

You can pull these changes from:

git://git.kernel.org/pub/scm/linux/kernel/git/pablo/nf-next.git

Thanks.

----------------------------------------------------------------

The following changes since commit b187191577629b5358acf4e234809ee8d441ceb4:

cxgb4: Add thermal zone support (2018-10-09 11:16:28 -0700)

are available in the git repository at:

git://git.kernel.org/pub/scm/linux/kernel/git/pablo/nf-next.git HEAD

for you to fetch changes up to af510ebd8913bee016492832f532ed919b51c09c:

Revert "netfilter: xt_quota: fix the behavior of xt_quota module" (2018-10-19 14:00:34 +0200)

----------------------------------------------------------------
Fernando Fernandez Mancera (1):
netfilter: nft_osf: Add ttl option support

Florian Westphal (1):
netfilter: nft_xfrm: use state family, not hook one

Lance Roy (1):
netfilter: Replace spin_is_locked() with lockdep

Pablo Neira Ayuso (2):
netfilter: xt_osf: simplify xt_osf_match_packet() Revert "netfilter: xt_quota: fix the behavior of xt_quota module"

Taehee Yoo (3):
netfilter: nf_nat_snmp_basic: add missing helper alias name
netfilter: nf_flow_table: remove unnecessary parameter of nf_flow_table_cleanup()
netfilter: nfnetlink_log: remove empty nfnetlink_log.h header file

Weongyo Jeong (1):
netfilter: remove two unused variables.

YueHaibing (1):
netfilter: cttimeout: remove set but not used variable 'l3num'

 include/linux/netfilter/nfnetlink_osf.h     |  3 +-
 include/net/netfilter/nf_flow_table.h       |  2 +-
 include/net/netfilter/nfnetlink_log.h       |  1 -
 include/uapi/linux/netfilter/nf_tables.h    |  7 ++++
 include/uapi/linux/netfilter/xt_quota.h     |  8 ++---
 net/ipv4/netfilter/nf_nat_snmp_basic_main.c |  1 +
 net/netfilter/ipset/ip_set_hash_gen.h       |  2 +-
 net/netfilter/nf_flow_table_core.c          |  2 +-
 net/netfilter/nfnetlink_cttimeout.c         |  2 --
 net/netfilter/nfnetlink_osf.c               | 46 +++++++++++-------------
 net/netfilter/nft_dup_netdev.c              |  2 --
 net/netfilter/nft_flow_offload.c            |  2 +-
 net/netfilter/nft_fwd_netdev.c              |  4 ---
 net/netfilter/nft_osf.c                     | 15 +++++++-
 net/netfilter/nft_xfrm.c                    | 11 +++---
 net/netfilter/xt_osf.c                      |  8 +----
 net/netfilter/xt_quota.c                    | 55 +++++++++++++++++------------
 17 files changed, 92 insertions(+), 79 deletions(-)
 delete mode 100644 include/net/netfilter/nfnetlink_log.h
author maintainer
#1 lore raw

PATCH 1/10 netfilter: Replace spin_is_locked() with lockdep

From: Lance Roy <[email protected]>

lockdep_assert_held() is better suited to checking locking requirements, since it won't get confused when someone else holds the lock. This is also a step towards possibly removing spin_is_locked().

---
 net/netfilter/ipset/ip_set_hash_gen.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
net/netfilter/ipset/ip_set_hash_gen.h +1 -1
index 8a33dac4e805..e287da68d5fa 100644
@@ -15,7 +15,7 @@
 
 #define __ipset_dereference_protected(p, c)	rcu_dereference_protected(p, c)
 #define ipset_dereference_protected(p, set) \
-	__ipset_dereference_protected(p, spin_is_locked(&(set)->lock))
+	__ipset_dereference_protected(p, lockdep_is_held(&(set)->lock))
 
 #define rcu_dereference_bh_nfnl(p)	rcu_dereference_bh_check(p, 1)
 
Signature · 1 line
2.11.0
author maintainer
#2 lore raw

PATCH 2/10 netfilter: cttimeout: remove set but not used variable 'l3num'

In reply to Pablo Neira Ayuso

From: YueHaibing <[email protected]>

Fixes gcc '-Wunused-but-set-variable' warning:

net/netfilter/nfnetlink_cttimeout.c: In function 'cttimeout_default_set':
net/netfilter/nfnetlink_cttimeout.c:353:8: warning:
variable 'l3num' set but not used [-Wunused-but-set-variable]

It not used any more after
commit dd2934a95701 ("netfilter: conntrack: remove l3->l4 mapping information")

---
 net/netfilter/nfnetlink_cttimeout.c | 2 --
 1 file changed, 2 deletions(-)
net/netfilter/nfnetlink_cttimeout.c +0 -2
index b48545b84ce8..e7a50af1b3d6 100644
@@ -350,7 +350,6 @@ static int cttimeout_default_set(struct net *net, struct sock *ctnl,
 				 struct netlink_ext_ack *extack)
 {
 	const struct nf_conntrack_l4proto *l4proto;
-	__u16 l3num;
 	__u8 l4num;
 	int ret;
 
@@ -359,7 +358,6 @@ static int cttimeout_default_set(struct net *net, struct sock *ctnl,
 	    !cda[CTA_TIMEOUT_DATA])
 		return -EINVAL;
 
-	l3num = ntohs(nla_get_be16(cda[CTA_TIMEOUT_L3PROTO]));
 	l4num = nla_get_u8(cda[CTA_TIMEOUT_L4PROTO]);
 	l4proto = nf_ct_l4proto_find_get(l4num);
 
Signature · 1 line
2.11.0
author maintainer
#3 lore raw

PATCH 3/10 netfilter: nft_osf: Add ttl option support

In reply to Pablo Neira Ayuso

From: Fernando Fernandez Mancera <[email protected]>

Add ttl option support to the nftables "osf" expression.

---
 include/linux/netfilter/nfnetlink_osf.h  |  3 ++-
 include/uapi/linux/netfilter/nf_tables.h |  7 +++++
 net/netfilter/nfnetlink_osf.c            | 46 +++++++++++++++-----------------
 net/netfilter/nft_osf.c                  | 15 ++++++++++-
 4 files changed, 44 insertions(+), 27 deletions(-)
include/linux/netfilter/nfnetlink_osf.h +2 -1
index ecf7dab81e9e..c6000046c966 100644
@@ -27,6 +27,7 @@ bool nf_osf_match(const struct sk_buff *skb, u_int8_t family,
 		  const struct list_head *nf_osf_fingers);
 
 const char *nf_osf_find(const struct sk_buff *skb,
-                        const struct list_head *nf_osf_fingers);
+			const struct list_head *nf_osf_fingers,
+			const int ttl_check);
 
 #endif /* _NFOSF_H */
include/uapi/linux/netfilter/nf_tables.h +7 -0
index 5444e76870bb..579974b0bf0d 100644
@@ -1511,9 +1511,16 @@ enum nft_flowtable_hook_attributes {
 };
 #define NFTA_FLOWTABLE_HOOK_MAX	(__NFTA_FLOWTABLE_HOOK_MAX - 1)
 
+/**
+ * enum nft_osf_attributes - nftables osf expression netlink attributes
+ *
+ * @NFTA_OSF_DREG: destination register (NLA_U32: nft_registers)
+ * @NFTA_OSF_TTL: Value of the TTL osf option (NLA_U8)
+ */
 enum nft_osf_attributes {
 	NFTA_OSF_UNSPEC,
 	NFTA_OSF_DREG,
+	NFTA_OSF_TTL,
 	__NFTA_OSF_MAX,
 };
 #define NFTA_OSF_MAX (__NFTA_OSF_MAX - 1)
net/netfilter/nfnetlink_osf.c +21 -25

74 lines not on this page · raw message

net/netfilter/nft_osf.c +14 -1
index a35fb59ace73..0b452fd470c4 100644
@@ -6,10 +6,12 @@
 
 struct nft_osf {
 	enum nft_registers	dreg:8;
+	u8			ttl;
 };
 
 static const struct nla_policy nft_osf_policy[NFTA_OSF_MAX + 1] = {
 	[NFTA_OSF_DREG]		= { .type = NLA_U32 },
+	[NFTA_OSF_TTL]		= { .type = NLA_U8 },
 };
 
 static void nft_osf_eval(const struct nft_expr *expr, struct nft_regs *regs,
@@ -33,7 +35,7 @@ static void nft_osf_eval(const struct nft_expr *expr, struct nft_regs *regs,
 		return;
 	}
 
-	os_name = nf_osf_find(skb, nf_osf_fingers);
+	os_name = nf_osf_find(skb, nf_osf_fingers, priv->ttl);
 	if (!os_name)
 		strncpy((char *)dest, "unknown", NFT_OSF_MAXGENRELEN);
 	else
@@ -46,6 +48,14 @@ static int nft_osf_init(const struct nft_ctx *ctx,
 {
 	struct nft_osf *priv = nft_expr_priv(expr);
 	int err;
+	u8 ttl;
+
+	if (nla_get_u8(tb[NFTA_OSF_TTL])) {
+		ttl = nla_get_u8(tb[NFTA_OSF_TTL]);
+		if (ttl > 2)
+			return -EINVAL;
+		priv->ttl = ttl;
+	}
 
 	priv->dreg = nft_parse_register(tb[NFTA_OSF_DREG]);
 	err = nft_validate_register_store(ctx, priv->dreg, NULL,
@@ -60,6 +70,9 @@ static int nft_osf_dump(struct sk_buff *skb, const struct nft_expr *expr)
 {
 	const struct nft_osf *priv = nft_expr_priv(expr);
 
+	if (nla_put_u8(skb, NFTA_OSF_TTL, priv->ttl))
+		goto nla_put_failure;
+
 	if (nft_dump_register(skb, NFTA_OSF_DREG, priv->dreg))
 		goto nla_put_failure;
 
Signature · 1 line
2.11.0
author maintainer
#4 lore raw

PATCH 4/10 netfilter: nft_xfrm: use state family, not hook one

In reply to Pablo Neira Ayuso

From: Florian Westphal <[email protected]>

Eyal says:
doesn't the use of nft_pf(pkt) in this context limit the matching of encapsulated packets to the same family?

IIUC when an e.g. IPv6-in-IPv4 packet is matched, the nft_pf(pkt) will be the decapsulated packet family - IPv6 - whereas the state may be IPv4. So this check would not allow matching the 'underlay' address in such cases.

I know this was a limitation in xt_policy. but is this intentional in this matcher? or is it possible to use state->props.family when validating the match instead of nft_pf(pkt)?

Userspace already tells us which address family it expects to match, so we can just use the real state family rather than the hook family. so change it as suggested above.

Fixes 6c47260250fc6 ("netfilter: nf_tables: add xfrm expression")
---
 net/netfilter/nft_xfrm.c | 11 ++++++-----
 1 file changed, 6 insertions(+), 5 deletions(-)
net/netfilter/nft_xfrm.c +6 -5
index 3cf71a2e375b..5322609f7662 100644
@@ -118,12 +118,13 @@ static bool xfrm_state_addr_ok(enum nft_xfrm_keys k, u8 family, u8 mode)
 
 static void nft_xfrm_state_get_key(const struct nft_xfrm *priv,
 				   struct nft_regs *regs,
-				   const struct xfrm_state *state,
-				   u8 family)
+				   const struct xfrm_state *state)
 {
 	u32 *dest = &regs->data[priv->dreg];
 
-	if (!xfrm_state_addr_ok(priv->key, family, state->props.mode)) {
+	if (!xfrm_state_addr_ok(priv->key,
+				state->props.family,
+				state->props.mode)) {
 		regs->verdict.code = NFT_BREAK;
 		return;
 	}
@@ -169,7 +170,7 @@ static void nft_xfrm_get_eval_in(const struct nft_xfrm *priv,
 	}
 
 	state = sp->xvec[priv->spnum];
-	nft_xfrm_state_get_key(priv, regs, state, nft_pf(pkt));
+	nft_xfrm_state_get_key(priv, regs, state);
 }
 
 static void nft_xfrm_get_eval_out(const struct nft_xfrm *priv,
@@ -184,7 +185,7 @@ static void nft_xfrm_get_eval_out(const struct nft_xfrm *priv,
 		if (i < priv->spnum)
 			continue;
 
-		nft_xfrm_state_get_key(priv, regs, dst->xfrm, nft_pf(pkt));
+		nft_xfrm_state_get_key(priv, regs, dst->xfrm);
 		return;
 	}
 
Signature · 1 line
2.11.0
author maintainer
#5 lore raw

PATCH 5/10 netfilter: xt_osf: simplify xt_osf_match_packet()

In reply to Pablo Neira Ayuso

info area in match is always available, and remove unneeded variables.

---
 net/netfilter/xt_osf.c | 8 +-------
 1 file changed, 1 insertion(+), 7 deletions(-)
net/netfilter/xt_osf.c +1 -7
index bf7bba80e24c..7a103553d10d 100644
@@ -40,14 +40,8 @@
 static bool
 xt_osf_match_packet(const struct sk_buff *skb, struct xt_action_param *p)
 {
-	const struct xt_osf_info *info = p->matchinfo;
-	struct net *net = xt_net(p);
-
-	if (!info)
-		return false;
-
 	return nf_osf_match(skb, xt_family(p), xt_hooknum(p), xt_in(p),
-			    xt_out(p), info, net, nf_osf_fingers);
+			    xt_out(p), p->matchinfo, xt_net(p), nf_osf_fingers);
 }
 
 static struct xt_match xt_osf_match = {
Signature · 1 line
2.11.0
author maintainer
#6 lore raw

PATCH 6/10 netfilter: nf_nat_snmp_basic: add missing helper alias name

In reply to Pablo Neira Ayuso

From: Taehee Yoo <[email protected]>

In order to upload helper module automatically, helper alias name is needed. so that MODULE_ALIAS_NFCT_HELPER() should be added. And unlike other nat helper modules, the nf_nat_snmp_basic can be used independently.
helper name is "snmp_trap" so that alias name will be "nfct-helper-snmp_trap" by MODULE_ALIAS_NFCT_HELPER(snmp_trap)

test command:
%iptables -t raw -I PREROUTING -p udp -j CT --helper snmp_trap %lsmod | grep nf_nat_snmp_basic

We can see nf_nat_snmp_basic module is uploaded automatically.

---
 net/ipv4/netfilter/nf_nat_snmp_basic_main.c | 1 +
 1 file changed, 1 insertion(+)
net/ipv4/netfilter/nf_nat_snmp_basic_main.c +1 -0
index ac110c1d55b5..a0aa13bcabda 100644
@@ -60,6 +60,7 @@ MODULE_LICENSE("GPL");
 MODULE_AUTHOR("James Morris <[email protected]>");
 MODULE_DESCRIPTION("Basic SNMP Application Layer Gateway");
 MODULE_ALIAS("ip_nat_snmp_basic");
+MODULE_ALIAS_NFCT_HELPER("snmp_trap");
 
 #define SNMP_PORT 161
 #define SNMP_TRAP_PORT 162
Signature · 1 line
2.11.0
author maintainer
#7 lore raw

PATCH 7/10 netfilter: nf_flow_table: remove unnecessary parameter of nf_flow_table_cleanup()

In reply to Pablo Neira Ayuso

From: Taehee Yoo <[email protected]>

parameter net of nf_flow_table_cleanup() is not used. So that it can be removed.

---
 include/net/netfilter/nf_flow_table.h | 2 +-
 net/netfilter/nf_flow_table_core.c    | 2 +-
 net/netfilter/nft_flow_offload.c      | 2 +-
 3 files changed, 3 insertions(+), 3 deletions(-)
include/net/netfilter/nf_flow_table.h +1 -1
index 0e355f4a3d76..77e2761d4f2f 100644
@@ -99,7 +99,7 @@ int nf_flow_table_iterate(struct nf_flowtable *flow_table,
 			  void (*iter)(struct flow_offload *flow, void *data),
 			  void *data);
 
-void nf_flow_table_cleanup(struct net *net, struct net_device *dev);
+void nf_flow_table_cleanup(struct net_device *dev);
 
 int nf_flow_table_init(struct nf_flowtable *flow_table);
 void nf_flow_table_free(struct nf_flowtable *flow_table);
net/netfilter/nf_flow_table_core.c +1 -1
index 185c633b6872..a3cc2ef8a48a 100644
@@ -483,7 +483,7 @@ static void nf_flow_table_iterate_cleanup(struct nf_flowtable *flowtable,
 	flush_delayed_work(&flowtable->gc_work);
 }
 
-void nf_flow_table_cleanup(struct net *net, struct net_device *dev)
+void nf_flow_table_cleanup(struct net_device *dev)
 {
 	struct nf_flowtable *flowtable;
 
net/netfilter/nft_flow_offload.c +1 -1
index d6bab8c3cbb0..e82d9a966c45 100644
@@ -201,7 +201,7 @@ static int flow_offload_netdev_event(struct notifier_block *this,
 	if (event != NETDEV_DOWN)
 		return NOTIFY_DONE;
 
-	nf_flow_table_cleanup(dev_net(dev), dev);
+	nf_flow_table_cleanup(dev);
 
 	return NOTIFY_DONE;
 }
Signature · 1 line
2.11.0
author maintainer
#8 lore raw

PATCH 8/10 netfilter: remove two unused variables.

In reply to Pablo Neira Ayuso

From: Weongyo Jeong <[email protected]>

nft_dup_netdev_ingress_ops and nft_fwd_netdev_ingress_ops variables are no longer used at the code.

---
 net/netfilter/nft_dup_netdev.c | 2 --
 net/netfilter/nft_fwd_netdev.c | 4 ----
 2 files changed, 6 deletions(-)
net/netfilter/nft_dup_netdev.c +0 -2
index 2cc1e0ef56e8..15cc62b293d6 100644
@@ -46,8 +46,6 @@ static int nft_dup_netdev_init(const struct nft_ctx *ctx,
 	return nft_validate_register_load(priv->sreg_dev, sizeof(int));
 }
 
-static const struct nft_expr_ops nft_dup_netdev_ingress_ops;
-
 static int nft_dup_netdev_dump(struct sk_buff *skb, const struct nft_expr *expr)
 {
 	struct nft_dup_netdev *priv = nft_expr_priv(expr);
net/netfilter/nft_fwd_netdev.c +0 -4
index 8abb9891cdf2..d7694e7255a0 100644
@@ -53,8 +53,6 @@ static int nft_fwd_netdev_init(const struct nft_ctx *ctx,
 	return nft_validate_register_load(priv->sreg_dev, sizeof(int));
 }
 
-static const struct nft_expr_ops nft_fwd_netdev_ingress_ops;
-
 static int nft_fwd_netdev_dump(struct sk_buff *skb, const struct nft_expr *expr)
 {
 	struct nft_fwd_netdev *priv = nft_expr_priv(expr);
@@ -169,8 +167,6 @@ static int nft_fwd_neigh_init(const struct nft_ctx *ctx,
 	return nft_validate_register_load(priv->sreg_addr, addr_len);
 }
 
-static const struct nft_expr_ops nft_fwd_netdev_ingress_ops;
-
 static int nft_fwd_neigh_dump(struct sk_buff *skb, const struct nft_expr *expr)
 {
 	struct nft_fwd_neigh *priv = nft_expr_priv(expr);
Signature · 1 line
2.11.0
author maintainer
#9 lore raw

PATCH 9/10 netfilter: nfnetlink_log: remove empty nfnetlink_log.h header file

In reply to Pablo Neira Ayuso

From: Taehee Yoo <[email protected]>

/include/net/netfilter/nfnetlink_log.h file is empty. so that it can be removed.

---
 include/net/netfilter/nfnetlink_log.h | 1 -
 1 file changed, 1 deletion(-)
 delete mode 100644 include/net/netfilter/nfnetlink_log.h
include/net/netfilter/nfnetlink_log.h deleted +0 -1
deleted file mode 100644
index ea32a7d3cf1b..000000000000
@@ -1 +0,0 @@
-/* SPDX-License-Identifier: GPL-2.0 */
Signature · 1 line
2.11.0
author maintainer
#10 lore raw

PATCH 10/10 Revert "netfilter: xt_quota: fix the behavior of xt_quota module"

In reply to Pablo Neira Ayuso

This reverts commit e9837e55b0200da544a095a1fca36efd7fd3ba30.

When talking to Maze and Chenbo, we agreed to keep this back by now due to problems in the ruleset listing path with 32-bit arches.

---
 include/uapi/linux/netfilter/xt_quota.h |  8 ++---
 net/netfilter/xt_quota.c                | 55 ++++++++++++++++++++-------------
 2 files changed, 36 insertions(+), 27 deletions(-)
include/uapi/linux/netfilter/xt_quota.h +3 -5
index d72fd52adbba..f3ba5d9e58b6 100644
@@ -15,11 +15,9 @@ struct xt_quota_info {
 	__u32 flags;
 	__u32 pad;
 	__aligned_u64 quota;
-#ifdef __KERNEL__
-	atomic64_t counter;
-#else
-	__aligned_u64 remain;
-#endif
+
+	/* Used internally by the kernel */
+	struct xt_quota_priv	*master;
 };
 
 #endif /* _XT_QUOTA_H */
net/netfilter/xt_quota.c +33 -22

87 lines not on this page · raw message

Signature · 1 line
2.11.0
maintainer
#11 lore raw
In reply to Pablo Neira Ayuso

From: Pablo Neira Ayuso <[email protected]>
Date: Sat, 20 Oct 2018 11:43:07 +0200

Quoted 19 lines

The following patchset contains Netfilter updates for your net-next tree:

1) Use lockdep_is_held() in ipset_dereference_protected(), from Lance Roy.

2) Remove unused variable in cttimeout, from YueHaibing.

3) Add ttl option for nft_osf, from Fernando Fernandez Mancera.

4) Use xfrm family to deal with IPv6-in-IPv4 packets from nft_xfrm, from Florian Westphal.

5) Simplify xt_osf_match_packet().

6) Missing ct helper alias definition in snmp_trap helper, from Taehee Yoo.

7) Remove unnecessary parameter in nf_flow_table_cleanup(), from Taehee Yoo.

8) Remove unused variable definitions in nft_{dup,fwd}, from Weongyo Jeong.

Quoted 8 lines

9) Remove empty net/netfilter/nfnetlink_log.h file, from Taehee Yoo.

10) Revert xt_quota updates remain option due to problems in the listing path for 32-bit arches, from Maze.

You can pull these changes from:

git://git.kernel.org/pub/scm/linux/kernel/git/pablo/nf-next.git

Pulled, thanks.