Skip to contentSkip to conversation

Netfilter updates for net-next

PATCH In review Pablo Neira Ayuso 4 participants 16 messages Jun 19, 2015 – Jun 22, 2015

Subsystems (8)
lore
Share & tools
lore

Pablo Neira Ayuso

author maintainer
#0 lore raw

cover Netfilter updates for net-next

Hi David,

The following patchset contains a final Netfilter pull request for net-next 4.2. This mostly addresses some fallout from the previous pull request, small netns updates and a couple of new features for nfnetlink_log and the socket match that didn't get in time for the previous pull request. More specifically they are:

1) Add security context information to nfnetlink_queue, from Roman Kubiak.

2) Add support to restore the sk_mark into skb->mark through xt_socket, from Harout Hedeshian.

3) Force alignment of 16 bytes of per cpu xt_counters, from Eric Dumazet.

4) Rename br_netfilter.c to br_netfilter_hooks.c to prepare split of IPv6 code into a separated file.

5) Move the IPv6 code in br_netfilter into a separated file.

6) Remove unused RCV_SKB_FAIL() in nfnetlink_queue and nfetlink_log, from Eric Biederman.

7) Two liner to simplify netns logic in em_ipset_match().

8) Add missing includes to net/net_namespace.h to avoid compilation problems that result from not including linux/netfilter.h in netns headers.

9) Use a forward declaration instead of including linux/proc_fs.h from netns/netfilter.h

10) Add a new linux/netfilter_defs.h to replace the linux/netfilter.h inclusion in netns headers.

11) Remove spurious netfilter.h file included in the net tree, also from Eric Biederman.

12) Fix x_tables compilation warnings on 32 bits platforms that resulted from recent changes in x_tables counters, from Florian Westphal.

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 89d256bb69f2596c3a31ac51466eac9e1791c388:

bpf: disallow bpf tc programs access current->pid,uid (2015-06-15 20:51:20 -0700)

are available in the git repository at:

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

for you to fetch changes up to dcb8f5c8139ef945cdfd55900fae265c4dbefc02:

netfilter: xtables: fix warnings on 32bit platforms (2015-06-18 21:14:33 +0200)

----------------------------------------------------------------
Eric Dumazet (1):
netfilter: x_tables: align per cpu xt_counter

Eric W Biederman (1):
netfilter: Remove spurios included of netfilter.h

Eric W. Biederman (2):
netfilter: Kill unused copies of RCV_SKB_FAIL
net: sched: Simplify em_ipset_match

Florian Westphal (1):
netfilter: xtables: fix warnings on 32bit platforms

Harout Hedeshian (1):
netfilter: xt_socket: add XT_SOCKET_RESTORESKMARK flag

Pablo Neira Ayuso (5):
netfilter: bridge: rename br_netfilter.c to br_netfilter_hooks.c
netfilter: bridge: split ipv6 code into separated file
net: include missing headers in net/net_namespace.h
netfilter: use forward declaration instead of including linux/proc_fs.h
netfilter: don't pull include/linux/netfilter.h from netns headers

Roman Kubiak (1):
netfilter: nfnetlink_queue: add security context information

 drivers/net/hamradio/bpqether.c                    |    1 -
 drivers/net/ppp/pptp.c                             |    2 -
 drivers/net/wan/lapbether.c                        |    1 -
 include/linux/netfilter.h                          |    6 +-
 include/linux/netfilter/x_tables.h                 |   14 +-
 include/linux/netfilter_defs.h                     |    9 +
 include/net/net_namespace.h                        |    2 +
 include/net/netfilter/br_netfilter.h               |   60 +++++
 include/net/netns/netfilter.h                      |    4 +-
 include/net/netns/x_tables.h                       |    2 +-
 include/uapi/linux/netfilter.h                     |    3 +-
 include/uapi/linux/netfilter/nfnetlink_queue.h     |    4 +-
 include/uapi/linux/netfilter/xt_socket.h           |    8 +
 net/ax25/af_ax25.c                                 |    1 -
 net/ax25/ax25_in.c                                 |    1 -
 net/ax25/ax25_ip.c                                 |    1 -
 net/ax25/ax25_out.c                                |    1 -
 net/ax25/ax25_uid.c                                |    1 -
 net/bridge/Makefile                                |    2 +
 .../{br_netfilter.c => br_netfilter_hooks.c}       |  248 +-------------------
 net/bridge/br_netfilter_ipv6.c                     |  245 +++++++++++++++++++
 net/ipv6/output_core.c                             |    1 +
 net/netfilter/nf_synproxy_core.c                   |    1 +
 net/netfilter/nfnetlink_log.c                      |    2 -
 net/netfilter/nfnetlink_queue_core.c               |   37 ++-
 net/netfilter/xt_socket.c                          |   59 ++++-
 net/netrom/nr_route.c                              |    1 -
 net/rose/rose_link.c                               |    1 -
 net/rose/rose_route.c                              |    1 -
 net/sched/em_ipset.c                               |    4 +-
 security/selinux/xfrm.c                            |    3 -
 31 files changed, 444 insertions(+), 282 deletions(-)
 create mode 100644 include/linux/netfilter_defs.h
 rename net/bridge/{br_netfilter.c => br_netfilter_hooks.c} (82%)
 create mode 100644 net/bridge/br_netfilter_ipv6.c

--
To unsubscribe from this list: send the line "unsubscribe netfilter-devel" in

author maintainer
#1 lore raw

PATCH 1/12 netfilter: nfnetlink_queue: add security context information

From: Roman Kubiak <[email protected]>

This patch adds an additional attribute when sending packet information via netlink in netfilter_queue module. It will send additional security context data, so that userspace applications can verify this context against their own security databases.

---
 include/uapi/linux/netfilter/nfnetlink_queue.h |    4 ++-
 net/netfilter/nfnetlink_queue_core.c           |   35 +++++++++++++++++++++++-
 2 files changed, 37 insertions(+), 2 deletions(-)
include/uapi/linux/netfilter/nfnetlink_queue.h +3 -1
index 8dd819e..b67a853 100644
@@ -49,6 +49,7 @@ enum nfqnl_attr_type {
 	NFQA_EXP,			/* nf_conntrack_netlink.h */
 	NFQA_UID,			/* __u32 sk uid */
 	NFQA_GID,			/* __u32 sk gid */
+	NFQA_SECCTX,			/* security context string */
 
 	__NFQA_MAX
 };
@@ -102,7 +103,8 @@ enum nfqnl_attr_config {
 #define NFQA_CFG_F_CONNTRACK			(1 << 1)
 #define NFQA_CFG_F_GSO				(1 << 2)
 #define NFQA_CFG_F_UID_GID			(1 << 3)
-#define NFQA_CFG_F_MAX				(1 << 4)
+#define NFQA_CFG_F_SECCTX			(1 << 4)
+#define NFQA_CFG_F_MAX				(1 << 5)
 
 /* flags for NFQA_SKB_INFO */
 /* packet appears to have wrong checksums, but they are ok */
net/netfilter/nfnetlink_queue_core.c +34 -1
index 22a5ac7..6eccf0f 100644
@@ -278,6 +278,23 @@ nla_put_failure:
 	return -1;
 }
 
+static u32 nfqnl_get_sk_secctx(struct sk_buff *skb, char **secdata)
+{
+	u32 seclen = 0;
+#if IS_ENABLED(CONFIG_NETWORK_SECMARK)
+	if (!skb || !sk_fullsock(skb->sk))
+		return 0;
+
+	read_lock_bh(&skb->sk->sk_callback_lock);
+
+	if (skb->secmark)
+		security_secid_to_secctx(skb->secmark, secdata, &seclen);
+
+	read_unlock_bh(&skb->sk->sk_callback_lock);
+#endif
+	return seclen;
+}
+
 static struct sk_buff *
 nfqnl_build_packet_message(struct net *net, struct nfqnl_instance *queue,
 			   struct nf_queue_entry *entry,
@@ -297,6 +314,8 @@ nfqnl_build_packet_message(struct net *net, struct nfqnl_instance *queue,
 	struct nf_conn *ct = NULL;
 	enum ip_conntrack_info uninitialized_var(ctinfo);
 	bool csum_verify;
+	char *secdata = NULL;
+	u32 seclen = 0;
 
 	size =    nlmsg_total_size(sizeof(struct nfgenmsg))
 		+ nla_total_size(sizeof(struct nfqnl_msg_packet_hdr))
@@ -352,6 +371,12 @@ nfqnl_build_packet_message(struct net *net, struct nfqnl_instance *queue,
 			+ nla_total_size(sizeof(u_int32_t)));	/* gid */
 	}
 
+	if ((queue->flags & NFQA_CFG_F_SECCTX) && entskb->sk) {
+		seclen = nfqnl_get_sk_secctx(entskb, &secdata);
+		if (seclen)
+			size += nla_total_size(seclen);
+	}
+
 	skb = nfnetlink_alloc_skb(net, size, queue->peer_portid,
 				  GFP_ATOMIC);
 	if (!skb) {
@@ -479,6 +504,9 @@ nfqnl_build_packet_message(struct net *net, struct nfqnl_instance *queue,
 	    nfqnl_put_sk_uidgid(skb, entskb->sk) < 0)
 		goto nla_put_failure;
 
+	if (seclen && nla_put(skb, NFQA_SECCTX, seclen, secdata))
+		goto nla_put_failure;
+
 	if (ct && nfqnl_ct_put(skb, ct, ctinfo) < 0)
 		goto nla_put_failure;
 
@@ -1142,7 +1170,12 @@ nfqnl_recv_config(struct sock *ctnl, struct sk_buff *skb,
 			ret = -EOPNOTSUPP;
 			goto err_out_unlock;
 		}
-
+#if !IS_ENABLED(CONFIG_NETWORK_SECMARK)
+		if (flags & mask & NFQA_CFG_F_SECCTX) {
+			ret = -EOPNOTSUPP;
+			goto err_out_unlock;
+		}
+#endif
 		spin_lock_bh(&queue->lock);
 		queue->flags &= ~mask;
 		queue->flags |= flags & mask;
Signature · 4 lines
1.7.10.4

--
To unsubscribe from this list: send the line "unsubscribe netfilter-devel" in
author maintainer
#2 lore raw

PATCH 2/12 netfilter: xt_socket: add XT_SOCKET_RESTORESKMARK flag

In reply to Pablo Neira Ayuso

From: Harout Hedeshian <[email protected]>

xt_socket is useful for matching sockets with IP_TRANSPARENT and taking some action on the matching packets. However, it lacks the ability to match only a small subset of transparent sockets.

Suppose there are 2 applications, each with its own set of transparent sockets. The first application wants all matching packets dropped, while the second application wants them forwarded somewhere else.

Add the ability to retore the skb->mark from the sk_mark. The mark is only restored if a matching socket is found and the transparent / nowildcard conditions are satisfied.

Now the 2 hypothetical applications can differentiate their sockets based on a mark value set with SO_MARK.

iptables -t mangle -I PREROUTING -m socket --transparent \
--restore-skmark -j action
iptables -t mangle -A action -m mark --mark 10 -j action2 iptables -t mangle -A action -m mark --mark 11 -j action3

---
 include/uapi/linux/netfilter/xt_socket.h |    8 ++++
 net/netfilter/xt_socket.c                |   59 +++++++++++++++++++++++++++---
 2 files changed, 61 insertions(+), 6 deletions(-)
include/uapi/linux/netfilter/xt_socket.h +8 -0
index 6315e2a..87644f8 100644
@@ -6,6 +6,7 @@
 enum {
 	XT_SOCKET_TRANSPARENT = 1 << 0,
 	XT_SOCKET_NOWILDCARD = 1 << 1,
+	XT_SOCKET_RESTORESKMARK = 1 << 2,
 };
 
 struct xt_socket_mtinfo1 {
@@ -18,4 +19,11 @@ struct xt_socket_mtinfo2 {
 };
 #define XT_SOCKET_FLAGS_V2 (XT_SOCKET_TRANSPARENT | XT_SOCKET_NOWILDCARD)
 
+struct xt_socket_mtinfo3 {
+	__u8 flags;
+};
+#define XT_SOCKET_FLAGS_V3 (XT_SOCKET_TRANSPARENT \
+			   | XT_SOCKET_NOWILDCARD \
+			   | XT_SOCKET_RESTORESKMARK)
+
 #endif /* _XT_SOCKET_H */
net/netfilter/xt_socket.c +53 -6

127 lines not on this page · raw message

Signature · 1 line
1.7.10.4
author maintainer
#3 lore raw

PATCH 3/12 netfilter: x_tables: align per cpu xt_counter

In reply to Pablo Neira Ayuso

From: Eric Dumazet <[email protected]>

Let's force a 16 bytes alignment on xt_counter percpu allocations, so that bytes and packets sit in same cache line.

xt_counter being exported to user space, we cannot add __align(16) on the structure itself.

---
 include/linux/netfilter/x_tables.h |    6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
include/linux/netfilter/x_tables.h +4 -2
index 95693c4..1c97a22 100644
@@ -356,7 +356,8 @@ static inline unsigned long ifname_compare_aligned(const char *_a,
  * so nothing needs to be done there.
  *
  * xt_percpu_counter_alloc returns the address of the percpu
- * counter, or 0 on !SMP.
+ * counter, or 0 on !SMP. We force an alignment of 16 bytes
+ * so that bytes/packets share a common cache line.
  *
  * Hence caller must use IS_ERR_VALUE to check for error, this
  * allows us to return 0 for single core systems without forcing
@@ -365,7 +366,8 @@ static inline unsigned long ifname_compare_aligned(const char *_a,
 static inline u64 xt_percpu_counter_alloc(void)
 {
 	if (nr_cpu_ids > 1) {
-		void __percpu *res = alloc_percpu(struct xt_counters);
+		void __percpu *res = __alloc_percpu(sizeof(struct xt_counters),
+						    sizeof(struct xt_counters));
 
 		if (res == NULL)
 			return (u64) -ENOMEM;
Signature · 4 lines
1.7.10.4

--
To unsubscribe from this list: send the line "unsubscribe netfilter-devel" in
author maintainer
#6 lore raw

PATCH 4/12 netfilter: bridge: rename br_netfilter.c to br_netfilter_hooks.c

In reply to Pablo Neira Ayuso

To prepare separation of the IPv6 code into different file.

---
 net/bridge/Makefile                                 |    1 +
 net/bridge/{br_netfilter.c => br_netfilter_hooks.c} |    0
 2 files changed, 1 insertion(+)
 rename net/bridge/{br_netfilter.c => br_netfilter_hooks.c} (100%)
net/bridge/Makefile +1 -0
index fd7ee03..c52577a 100644
@@ -12,6 +12,7 @@ bridge-$(CONFIG_SYSFS) += br_sysfs_if.o br_sysfs_br.o
 
 bridge-$(subst m,y,$(CONFIG_BRIDGE_NETFILTER)) += br_nf_core.o
 
+br_netfilter-y := br_netfilter_hooks.o
 obj-$(CONFIG_BRIDGE_NETFILTER) += br_netfilter.o
 
 bridge-$(CONFIG_BRIDGE_IGMP_SNOOPING) += br_multicast.o br_mdb.o
net/bridge/br_netfilter_hooks.c renamed from net/bridge/br_netfilter.c +0 -0
similarity index 100%
rename from net/bridge/br_netfilter.c
rename to net/bridge/br_netfilter_hooks.c
Signature · 4 lines
1.7.10.4

--
To unsubscribe from this list: send the line "unsubscribe netfilter-devel" in
author maintainer
#7 lore raw

PATCH 5/12 netfilter: bridge: split ipv6 code into separated file

In reply to Pablo Neira Ayuso

Resolve compilation breakage when CONFIG_IPV6 is not set by moving the IPv6 code into a separated br_netfilter_ipv6.c file.

Fixes efb6de9b4ba0 ("netfilter: bridge: forward IPv6 fragmented packets")
---
 include/net/netfilter/br_netfilter.h |   60 ++++++++
 net/bridge/Makefile                  |    1 +
 net/bridge/br_netfilter_hooks.c      |  248 ++--------------------------------
 net/bridge/br_netfilter_ipv6.c       |  245 +++++++++++++++++++++++++++++++++
 4 files changed, 315 insertions(+), 239 deletions(-)
 create mode 100644 net/bridge/br_netfilter_ipv6.c
include/net/netfilter/br_netfilter.h +60 -0
index 2aa6048..bab824b 100644
@@ -1,6 +1,66 @@
 #ifndef _BR_NETFILTER_H_
 #define _BR_NETFILTER_H_
 
+#include "../../../net/bridge/br_private.h"
+
+static inline struct nf_bridge_info *nf_bridge_alloc(struct sk_buff *skb)
+{
+	skb->nf_bridge = kzalloc(sizeof(struct nf_bridge_info), GFP_ATOMIC);
+
+	if (likely(skb->nf_bridge))
+		atomic_set(&(skb->nf_bridge->use), 1);
+
+	return skb->nf_bridge;
+}
+
+void nf_bridge_update_protocol(struct sk_buff *skb);
+
+static inline struct nf_bridge_info *
+nf_bridge_info_get(const struct sk_buff *skb)
+{
+	return skb->nf_bridge;
+}
+
+unsigned int nf_bridge_encap_header_len(const struct sk_buff *skb);
+
+static inline void nf_bridge_push_encap_header(struct sk_buff *skb)
+{
+	unsigned int len = nf_bridge_encap_header_len(skb);
+
+	skb_push(skb, len);
+	skb->network_header -= len;
+}
+
+int br_nf_pre_routing_finish_bridge(struct sock *sk, struct sk_buff *skb);
+
+static inline struct rtable *bridge_parent_rtable(const struct net_device *dev)
+{
+	struct net_bridge_port *port;
+
+	port = br_port_get_rcu(dev);
+	return port ? &port->br->fake_rtable : NULL;
+}
+
+struct net_device *setup_pre_routing(struct sk_buff *skb);
 void br_netfilter_enable(void);
 
+#if IS_ENABLED(CONFIG_IPV6)
+int br_validate_ipv6(struct sk_buff *skb);
+unsigned int br_nf_pre_routing_ipv6(const struct nf_hook_ops *ops,
+				    struct sk_buff *skb,
+				    const struct nf_hook_state *state);
+#else
+static inline int br_validate_ipv6(struct sk_buff *skb)
+{
+	return -1;
+}
+
+static inline unsigned int
+br_nf_pre_routing_ipv6(const struct nf_hook_ops *ops, struct sk_buff *skb,
+		       const struct nf_hook_state *state)
+{
+	return NF_DROP;
+}
+#endif
+
 #endif /* _BR_NETFILTER_H_ */
net/bridge/Makefile +1 -0
index c52577a..a1cda5d 100644
@@ -13,6 +13,7 @@ bridge-$(CONFIG_SYSFS) += br_sysfs_if.o br_sysfs_br.o
 bridge-$(subst m,y,$(CONFIG_BRIDGE_NETFILTER)) += br_nf_core.o
 
 br_netfilter-y := br_netfilter_hooks.o
+br_netfilter-$(subst m,y,$(CONFIG_IPV6)) += br_netfilter_ipv6.o
 obj-$(CONFIG_BRIDGE_NETFILTER) += br_netfilter.o
 
 bridge-$(CONFIG_BRIDGE_IGMP_SNOOPING) += br_multicast.o br_mdb.o
net/bridge/br_netfilter_hooks.c +9 -239

315 lines not on this page · raw message

net/bridge/br_netfilter_ipv6.c new file +245 -0

245 lines not on this page · raw message

Signature · 1 line
1.7.10.4
author maintainer
#8 lore raw

PATCH 6/12 netfilter: Kill unused copies of RCV_SKB_FAIL

In reply to Pablo Neira Ayuso

From: "Eric W. Biederman" <[email protected]>

This appears to have been a dead macro in both nfnetlink_log.c and nfnetlink_queue_core.c since these pieces of code were added in 2005.

---
 net/netfilter/nfnetlink_log.c        |    2 --
 net/netfilter/nfnetlink_queue_core.c |    2 --
 2 files changed, 4 deletions(-)
net/netfilter/nfnetlink_log.c +0 -2
index 4ef1fae..4670821 100644
@@ -598,8 +598,6 @@ nla_put_failure:
 	return -1;
 }
 
-#define RCV_SKB_FAIL(err) do { netlink_ack(skb, nlh, (err)); return; } while (0)
-
 static struct nf_loginfo default_loginfo = {
 	.type =		NF_LOG_TYPE_ULOG,
 	.u = {
net/netfilter/nfnetlink_queue_core.c +0 -2
index 6eccf0f..e26a46e 100644
@@ -834,8 +834,6 @@ nfqnl_dev_drop(struct net *net, int ifindex)
 	rcu_read_unlock();
 }
 
-#define RCV_SKB_FAIL(err) do { netlink_ack(skb, nlh, (err)); return; } while (0)
-
 static int
 nfqnl_rcv_dev_event(struct notifier_block *this,
 		    unsigned long event, void *ptr)
Signature · 1 line
1.7.10.4
author maintainer
#9 lore raw

PATCH 7/12 net: sched: Simplify em_ipset_match

In reply to Pablo Neira Ayuso

From: "Eric W. Biederman" <[email protected]>

em->net is always set and always available, use it in preference to dev_net(skb->dev).

---
 net/sched/em_ipset.c |    4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
net/sched/em_ipset.c +2 -2
index a3d79c8..df0328b 100644
@@ -92,8 +92,8 @@ static int em_ipset_match(struct sk_buff *skb, struct tcf_ematch *em,
 
 	rcu_read_lock();
 
-	if (dev && skb->skb_iif)
-		indev = dev_get_by_index_rcu(dev_net(dev), skb->skb_iif);
+	if (skb->skb_iif)
+		indev = dev_get_by_index_rcu(em->net, skb->skb_iif);
 
 	acpar.in      = indev ? indev : dev;
 	acpar.out     = dev;
Signature · 4 lines
1.7.10.4

--
To unsubscribe from this list: send the line "unsubscribe netfilter-devel" in
author maintainer
#10 lore raw

PATCH 8/12 net: include missing headers in net/net_namespace.h

In reply to Pablo Neira Ayuso

Include linux/idr.h and linux/skbuff.h since they are required by objects that are declared in the net structure.

 struct net {
	...
	struct idr		netns_ids;
	...
	struct sk_buff_head	wext_nlevents;
	...
---
 include/net/net_namespace.h |    2 ++
 1 file changed, 2 insertions(+)
include/net/net_namespace.h +2 -0
index 72eb237..e951453 100644
@@ -28,6 +28,8 @@
 #include <net/netns/xfrm.h>
 #include <net/netns/mpls.h>
 #include <linux/ns_common.h>
+#include <linux/idr.h>
+#include <linux/skbuff.h>
 
 struct user_namespace;
 struct proc_dir_entry;
Signature · 1 line
1.7.10.4
author maintainer
#12 lore raw

PATCH 10/12 netfilter: don't pull include/linux/netfilter.h from netns headers

In reply to Pablo Neira Ayuso

This pulls the full hook netfilter definitions from all those that include net_namespace.h.

Instead let's just include the bare minimum required in the new linux/netfilter_defs.h file, and use it from the netfilter netns header files.

I also needed to include in.h and in6.h from linux/netfilter.h otherwise we hit this compilation error:

In file included from include/linux/netfilter_defs.h:4:0,
from include/net/netns/netfilter.h:4,
from include/net/net_namespace.h:22,
from include/linux/netdevice.h:43,
from net/netfilter/nfnetlink_queue_core.c:23:
include/uapi/linux/netfilter.h:76:17: error: field ‘in’ has incomplete type struct in_addr in;

And also explicit include linux/netfilter.h in several spots.

---
 include/linux/netfilter.h      |    6 ++----
 include/linux/netfilter_defs.h |    9 +++++++++
 include/net/netns/netfilter.h  |    2 +-
 include/net/netns/x_tables.h   |    2 +-
 include/uapi/linux/netfilter.h |    3 ++-
 net/ipv6/output_core.c         |    1 +
 6 files changed, 16 insertions(+), 7 deletions(-)
 create mode 100644 include/linux/netfilter_defs.h
include/linux/netfilter.h +2 -4
index f5ff5d1..00050df 100644
@@ -10,7 +10,8 @@
 #include <linux/wait.h>
 #include <linux/list.h>
 #include <linux/static_key.h>
-#include <uapi/linux/netfilter.h>
+#include <linux/netfilter_defs.h>
+
 #ifdef CONFIG_NETFILTER
 static inline int NF_DROP_GETERR(int verdict)
 {
@@ -38,9 +39,6 @@ static inline void nf_inet_addr_mask(const union nf_inet_addr *a1,
 
 int netfilter_init(void);
 
-/* Largest hook number + 1 */
-#define NF_MAX_HOOKS 8
-
 struct sk_buff;
 
 struct nf_hook_ops;
include/linux/netfilter_defs.h new file +9 -0
new file mode 100644
index 0000000..d3a7f85
@@ -0,0 +1,9 @@
+#ifndef __LINUX_NETFILTER_CORE_H_
+#define __LINUX_NETFILTER_CORE_H_
+
+#include <uapi/linux/netfilter.h>
+
+/* Largest hook number + 1, see uapi/linux/netfilter_decnet.h */
+#define NF_MAX_HOOKS 8
+
+#endif
include/net/netns/netfilter.h +1 -1
index cf25b5e..532e4ba 100644
@@ -1,7 +1,7 @@
 #ifndef __NETNS_NETFILTER_H
 #define __NETNS_NETFILTER_H
 
-#include <linux/netfilter.h>
+#include <linux/netfilter_defs.h>
 
 struct proc_dir_entry;
 struct nf_logger;
include/net/netns/x_tables.h +1 -1
index 4d6597a..c8a7681 100644
@@ -2,7 +2,7 @@
 #define __NETNS_X_TABLES_H
 
 #include <linux/list.h>
-#include <linux/netfilter.h>
+#include <linux/netfilter_defs.h>
 
 struct ebt_table;
 
include/uapi/linux/netfilter.h +2 -1
index 177027c..d93f949 100644
@@ -4,7 +4,8 @@
 #include <linux/types.h>
 #include <linux/compiler.h>
 #include <linux/sysctl.h>
-
+#include <linux/in.h>
+#include <linux/in6.h>
 
 /* Responses from hook functions. */
 #define NF_DROP 0
net/ipv6/output_core.c +1 -0
index 21678ac..928a0fb 100644
@@ -8,6 +8,7 @@
 #include <net/ip6_fib.h>
 #include <net/addrconf.h>
 #include <net/secure_seq.h>
+#include <linux/netfilter.h>
 
 static u32 __ipv6_select_ident(struct net *net, u32 hashrnd,
 			       const struct in6_addr *dst,
Signature · 1 line
1.7.10.4
author maintainer
#13 lore raw

PATCH 11/12 netfilter: Remove spurios included of netfilter.h

In reply to Pablo Neira Ayuso

From: Eric W Biederman <[email protected]>

While testing my netfilter changes I noticed several files where recompiling unncessarily because they unncessarily included netfilter.h.

---
 drivers/net/hamradio/bpqether.c |    1 -
 drivers/net/ppp/pptp.c          |    2 --
 drivers/net/wan/lapbether.c     |    1 -
 net/ax25/af_ax25.c              |    1 -
 net/ax25/ax25_in.c              |    1 -
 net/ax25/ax25_ip.c              |    1 -
 net/ax25/ax25_out.c             |    1 -
 net/ax25/ax25_uid.c             |    1 -
 net/netrom/nr_route.c           |    1 -
 net/rose/rose_link.c            |    1 -
 net/rose/rose_route.c           |    1 -
 security/selinux/xfrm.c         |    3 ---
 12 files changed, 15 deletions(-)
drivers/net/hamradio/bpqether.c +0 -1
index 63ff08a..7856b6c 100644
@@ -76,7 +76,6 @@
 #include <linux/proc_fs.h>
 #include <linux/seq_file.h>
 #include <linux/stat.h>
-#include <linux/netfilter.h>
 #include <linux/module.h>
 #include <linux/init.h>
 #include <linux/rtnetlink.h>
drivers/net/ppp/pptp.c +0 -2
index 14839bc..686f37d 100644
@@ -28,8 +28,6 @@
 #include <linux/file.h>
 #include <linux/in.h>
 #include <linux/ip.h>
-#include <linux/netfilter.h>
-#include <linux/netfilter_ipv4.h>
 #include <linux/rcupdate.h>
 #include <linux/spinlock.h>
 
drivers/net/wan/lapbether.c +0 -1
index 2f5eda8..6676607 100644
@@ -40,7 +40,6 @@
 #include <linux/interrupt.h>
 #include <linux/notifier.h>
 #include <linux/stat.h>
-#include <linux/netfilter.h>
 #include <linux/module.h>
 #include <linux/lapb.h>
 #include <linux/init.h>
net/ax25/af_ax25.c +0 -1
index 4273533..9c891d0 100644
@@ -40,7 +40,6 @@
 #include <linux/notifier.h>
 #include <linux/proc_fs.h>
 #include <linux/stat.h>
-#include <linux/netfilter.h>
 #include <linux/sysctl.h>
 #include <linux/init.h>
 #include <linux/spinlock.h>
net/ax25/ax25_in.c +0 -1
index 7ed8ab7..29a3687 100644
@@ -23,7 +23,6 @@
 #include <linux/inet.h>
 #include <linux/netdevice.h>
 #include <linux/skbuff.h>
-#include <linux/netfilter.h>
 #include <net/sock.h>
 #include <net/tcp_states.h>
 #include <asm/uaccess.h>
net/ax25/ax25_ip.c +0 -1
index 7c646bb..b563a3f 100644
@@ -31,7 +31,6 @@
 #include <linux/notifier.h>
 #include <linux/proc_fs.h>
 #include <linux/stat.h>
-#include <linux/netfilter.h>
 #include <linux/sysctl.h>
 #include <net/ip.h>
 #include <net/arp.h>
net/ax25/ax25_out.c +0 -1
index be2acab..8ddd41b 100644
@@ -24,7 +24,6 @@
 #include <linux/inet.h>
 #include <linux/netdevice.h>
 #include <linux/skbuff.h>
-#include <linux/netfilter.h>
 #include <net/sock.h>
 #include <asm/uaccess.h>
 #include <linux/fcntl.h>
net/ax25/ax25_uid.c +0 -1
index 71c4bad..4ad2fb7 100644
@@ -34,7 +34,6 @@
 #include <linux/proc_fs.h>
 #include <linux/seq_file.h>
 #include <linux/stat.h>
-#include <linux/netfilter.h>
 #include <linux/sysctl.h>
 #include <linux/export.h>
 #include <net/ip.h>
net/netrom/nr_route.c +0 -1
index 96b64d2..d72a4f1 100644
@@ -31,7 +31,6 @@
 #include <linux/mm.h>
 #include <linux/interrupt.h>
 #include <linux/notifier.h>
-#include <linux/netfilter.h>
 #include <linux/init.h>
 #include <linux/spinlock.h>
 #include <net/netrom.h>
net/rose/rose_link.c +0 -1
index e873d7d..c76638c 100644
@@ -25,7 +25,6 @@
 #include <linux/fcntl.h>
 #include <linux/mm.h>
 #include <linux/interrupt.h>
-#include <linux/netfilter.h>
 #include <net/rose.h>
 
 static void rose_ftimer_expiry(unsigned long);
net/rose/rose_route.c +0 -1
index 40148932..0fc76d8 100644
@@ -31,7 +31,6 @@
 #include <linux/mm.h>
 #include <linux/interrupt.h>
 #include <linux/notifier.h>
-#include <linux/netfilter.h>
 #include <linux/init.h>
 #include <net/rose.h>
 #include <linux/seq_file.h>
security/selinux/xfrm.c +0 -3
index 98b0426..56e354f 100644
@@ -35,9 +35,6 @@
 #include <linux/init.h>
 #include <linux/security.h>
 #include <linux/types.h>
-#include <linux/netfilter.h>
-#include <linux/netfilter_ipv4.h>
-#include <linux/netfilter_ipv6.h>
 #include <linux/slab.h>
 #include <linux/ip.h>
 #include <linux/tcp.h>
Signature · 1 line
1.7.10.4
author maintainer
#14 lore raw

PATCH 12/12 netfilter: xtables: fix warnings on 32bit platforms

In reply to Pablo Neira Ayuso

From: Florian Westphal <[email protected]>

On 32bit archs gcc complains due to cast from void* to u64. Add intermediate casts to long to silence these warnings.

include/linux/netfilter/x_tables.h:376:10: warning: cast from pointer to integer of different size [-Wpointer-to-int-cast] include/linux/netfilter/x_tables.h:384:15: warning: cast to pointer from integer of different size [-Wint-to-pointer-cast] include/linux/netfilter/x_tables.h:391:23: warning: cast to pointer from integer of different size [-Wint-to-pointer-cast] include/linux/netfilter/x_tables.h:400:22: warning: cast to pointer from integer of different size [-Wint-to-pointer-cast]

Fixes 71ae0dff02d756e ("netfilter: xtables: use percpu rule counters")
---
 include/linux/netfilter/x_tables.h |    8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
include/linux/netfilter/x_tables.h +4 -4
index 1c97a22..286098a 100644
@@ -372,7 +372,7 @@ static inline u64 xt_percpu_counter_alloc(void)
 		if (res == NULL)
 			return (u64) -ENOMEM;
 
-		return (__force u64) res;
+		return (u64) (__force unsigned long) res;
 	}
 
 	return 0;
@@ -380,14 +380,14 @@ static inline u64 xt_percpu_counter_alloc(void)
 static inline void xt_percpu_counter_free(u64 pcnt)
 {
 	if (nr_cpu_ids > 1)
-		free_percpu((void __percpu *) pcnt);
+		free_percpu((void __percpu *) (unsigned long) pcnt);
 }
 
 static inline struct xt_counters *
 xt_get_this_cpu_counter(struct xt_counters *cnt)
 {
 	if (nr_cpu_ids > 1)
-		return this_cpu_ptr((void __percpu *) cnt->pcnt);
+		return this_cpu_ptr((void __percpu *) (unsigned long) cnt->pcnt);
 
 	return cnt;
 }
@@ -396,7 +396,7 @@ static inline struct xt_counters *
 xt_get_per_cpu_counter(struct xt_counters *cnt, unsigned int cpu)
 {
 	if (nr_cpu_ids > 1)
-		return per_cpu_ptr((void __percpu *) cnt->pcnt, cpu);
+		return per_cpu_ptr((void __percpu *) (unsigned long) cnt->pcnt, cpu);
 
 	return cnt;
 }
Signature · 1 line
1.7.10.4
author maintainer
#11 lore raw

PATCH 9/12 netfilter: use forward declaration instead of including linux/proc_fs.h

In reply to Pablo Neira Ayuso

We don't need to pull the full definitions in that file, a simple forward declaration is enough.

Moreover, include linux/procfs.h from nf_synproxy_core, otherwise this hits a compilation error due to missing declarations, ie.

net/netfilter/nf_synproxy_core.c: In function ‘synproxy_proc_init’:
net/netfilter/nf_synproxy_core.c:326:2: error: implicit declaration of function ‘proc_create’ [-Werror=implicit-function-declaration]
if (!proc_create("synproxy", S_IRUGO, net->proc_net_stat,
^

---
 include/net/netns/netfilter.h    |    2 +-
 net/netfilter/nf_synproxy_core.c |    1 +
 2 files changed, 2 insertions(+), 1 deletion(-)
include/net/netns/netfilter.h +1 -1
index 8874002..cf25b5e 100644
@@ -1,9 +1,9 @@
 #ifndef __NETNS_NETFILTER_H
 #define __NETNS_NETFILTER_H
 
-#include <linux/proc_fs.h>
 #include <linux/netfilter.h>
 
+struct proc_dir_entry;
 struct nf_logger;
 
 struct netns_nf {
net/netfilter/nf_synproxy_core.c +1 -0
index 52e20c9..789feea 100644
@@ -11,6 +11,7 @@
 #include <asm/unaligned.h>
 #include <net/tcp.h>
 #include <net/netns/generic.h>
+#include <linux/proc_fs.h>
 
 #include <linux/netfilter_ipv4/ip_tables.h>
 #include <linux/netfilter/x_tables.h>
Signature · 1 line
1.7.10.4
maintainer
#15 lore raw
In reply to Pablo Neira Ayuso

From: Pablo Neira Ayuso <[email protected]>
Date: Fri, 19 Jun 2015 19:17:37 +0200

Quoted 5 lines

The following patchset contains a final Netfilter pull request for net-next 4.2. This mostly addresses some fallout from the previous pull request, small netns updates and a couple of new features for nfnetlink_log and the socket match that didn't get in time for the previous pull request. More specifically they are:

...

Quoted 3 lines

You can pull these changes from:

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

Pulled, thanks a lot Pablo.
--
To unsubscribe from this list: send the line "unsubscribe netfilter-devel" in

#4 lore raw

RE: [PATCH 03/12] netfilter: x_tables: align per cpu xt_counter

In reply to Pablo Neira Ayuso

From: Pablo Neira Ayuso

Quoted 8 lines

Sent: 19 June 2015 18:18
From: Eric Dumazet <[email protected]>

Let's force a 16 bytes alignment on xt_counter percpu allocations, so that bytes and packets sit in same cache line.

xt_counter being exported to user space, we cannot add __align(16) on the structure itself.

You could allocate a wrapper structure that contains xt_counter and is itself marked __align(16).

David

#5 lore raw

Re: [PATCH 03/12] netfilter: x_tables: align per cpu xt_counter

Quoted 4 lines · David Laight

From: Pablo Neira Ayuso

Quoted 3 lines

Sent: 19 June 2015 18:18
From: Eric Dumazet <[email protected]>

Quoted 8 lines
Quoted 5 lines

Let's force a 16 bytes alignment on xt_counter percpu allocations, so that bytes and packets sit in same cache line.

xt_counter being exported to user space, we cannot add __align(16) on the structure itself.

You could allocate a wrapper structure that contains xt_counter and is itself marked __align(16).

Sure. I took one solution, out of multiple ones.

--
To unsubscribe from this list: send the line "unsubscribe netfilter-devel" in