Skip to contentSkip to conversation

netfilter: nf_tables: attach net_device to basechain

PATCH Superseded Pablo Neira Ayuso 1 participant 1 message Jun 12, 2015

Subsystems (2)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Pablo Neira Ayuso

author maintainer
#0 lore raw

PATCH 1/1 netfilter: nf_tables: attach net_device to basechain

The device is part of the hook configuration, so instead of a global configuration per table, set it to each of the basechain that we create.

This patch reworks ebddf1a8d78a ("netfilter: nf_tables: allow to bind table to net_device").

---
@Patrick: I found another problem regarding the net_device pointer that I keep in struct nft_basechain: dev_hold() doesn't increase the module refcount so one could remove the net_device driver, which will keep us looping on:

unregister_netdevice: waiting for eth0 to become free. Usage count = 1

I think we can store the ifname instead and subscribe to netdev events, if the interface goes down, we unregister the existing hooks. Then, if it comes back up, we register them back again.

The idea is to pass the devname to the nf hook core, it takes care of this.

 include/net/netfilter/nf_tables.h        |    2 -
 include/uapi/linux/netfilter/nf_tables.h |    4 +-
 net/netfilter/nf_tables_api.c            |   76 +++++++++++++++---------------
 3 files changed, 41 insertions(+), 41 deletions(-)
include/net/netfilter/nf_tables.h +0 -2
index 3d6f48c..8d9c307 100644
@@ -819,7 +819,6 @@ unsigned int nft_do_chain(struct nft_pktinfo *pkt,
  *	@use: number of chain references to this table
  *	@flags: table flag (see enum nft_table_flags)
  *	@name: name of the table
- *	@dev: this table is bound to this device (if any)
  */
 struct nft_table {
 	struct list_head		list;
@@ -829,7 +828,6 @@ struct nft_table {
 	u32				use;
 	u16				flags;
 	char				name[NFT_TABLE_MAXNAMELEN];
-	struct net_device		*dev;
 };
 
 enum nft_af_flags {
include/uapi/linux/netfilter/nf_tables.h +2 -2
index 17db26c..d02d7d2 100644
@@ -122,11 +122,13 @@ enum nft_list_attributes {
  *
  * @NFTA_HOOK_HOOKNUM: netfilter hook number (NLA_U32)
  * @NFTA_HOOK_PRIORITY: netfilter hook priority (NLA_U32)
+ * @NFTA_HOOK_DEV: netdevice name (NLA_STRING)
  */
 enum nft_hook_attributes {
 	NFTA_HOOK_UNSPEC,
 	NFTA_HOOK_HOOKNUM,
 	NFTA_HOOK_PRIORITY,
+	NFTA_HOOK_DEV,
 	__NFTA_HOOK_MAX
 };
 #define NFTA_HOOK_MAX		(__NFTA_HOOK_MAX - 1)
@@ -146,14 +148,12 @@ enum nft_table_flags {
  * @NFTA_TABLE_NAME: name of the table (NLA_STRING)
  * @NFTA_TABLE_FLAGS: bitmask of enum nft_table_flags (NLA_U32)
  * @NFTA_TABLE_USE: number of chains in this table (NLA_U32)
- * @NFTA_TABLE_DEV: net device name (NLA_STRING)
  */
 enum nft_table_attributes {
 	NFTA_TABLE_UNSPEC,
 	NFTA_TABLE_NAME,
 	NFTA_TABLE_FLAGS,
 	NFTA_TABLE_USE,
-	NFTA_TABLE_DEV,
 	__NFTA_TABLE_MAX
 };
 #define NFTA_TABLE_MAX		(__NFTA_TABLE_MAX - 1)
net/netfilter/nf_tables_api.c +39 -37

175 lines not on this page · raw message

Signature · 1 line
1.7.10.4