netfilter: nftables: introduce table ownership
Subsystems (2)
Pablo Neira Ayuso
maintainerPATCH 1/1 netfilter: nftables: introduce table ownership
A userspace daemon like firewalld might need to monitor for netlink updates to detect its ruleset removal by the (global) flush ruleset command to ensure ruleset persistence. This adds extra complexity from userspace and, for some little time, the firewall policy is not in place.
This patch adds the NFT_MSG_SETOWNER netlink command which allows a userspace program to own the table that creates in exclusivity.
Tables that are owned...
- can only be updated and removed by the owner, non-owners hit EPERM if they try to update it or remove it.
- are destroyed when the owner send the NFT_MSG_UNSETOWNER command, or the netlink socket is closed or the process is gone (implicit netlink socket closure).
- are skipped by the global flush ruleset command.
- are listed in the global ruleset.
The userspace process that sends the new NFT_MSG_SETOWNER command need to leave open the netlink socket.
The NFTA_TABLE_OWNER netlink attribute specifies the netlink port ID to identify the owner.
--- include/net/netfilter/nf_tables.h | 1 + include/uapi/linux/netfilter/nf_tables.h | 15 ++ net/netfilter/nf_tables_api.c | 235 +++++++++++++++++++---- 3 files changed, 210 insertions(+), 41 deletions(-)
include/net/netfilter/nf_tables.h +1 -0
@@ -1104,6 +1104,7 @@ struct nft_table { u16 family:6, flags:8, genmask:2; +u32 nlpid;char *name;u16 udlen;u8 *udata;
include/uapi/linux/netfilter/nf_tables.h +15 -0
@@ -97,6 +97,8 @@ enum nft_verdicts {* @NFT_MSG_NEWFLOWTABLE: add new flow table (enum nft_flowtable_attributes) * @NFT_MSG_GETFLOWTABLE: get flow table (enum nft_flowtable_attributes) * @NFT_MSG_DELFLOWTABLE: delete flow table (enum nft_flowtable_attributes) +* @NFT_MSG_SETOWNER: set ruleset owner (enum nft_owner_attributes) +* @NFT_MSG_UNSETOWNER: unset ruleset owner (enum nft_owner_attributes) */ enum nf_tables_msg_types {NFT_MSG_NEWTABLE ,
@@ -124,6 +126,8 @@ enum nf_tables_msg_types {NFT_MSG_NEWFLOWTABLE ,NFT_MSG_GETFLOWTABLE ,NFT_MSG_DELFLOWTABLE , +NFT_MSG_SETOWNER , +NFT_MSG_UNSETOWNER , NFT_MSG_MAX, };
@@ -173,6 +177,7 @@ enum nft_table_flags {* @NFTA_TABLE_FLAGS: bitmask of enum nft_table_flags (NLA_U32) * @NFTA_TABLE_USE: number of chains in this table (NLA_U32) * @NFTA_TABLE_USERDATA: user data (NLA_BINARY) +* @NFTA_TABLE_OWNER: owner of this table through netlink portID (NLA_U32) */ enum nft_table_attributes {NFTA_TABLE_UNSPEC ,
@@ -182,6 +187,7 @@ enum nft_table_attributes {NFTA_TABLE_HANDLE ,NFTA_TABLE_PAD ,NFTA_TABLE_USERDATA , +NFTA_TABLE_OWNER , __NFTA_TABLE_MAX };#define NFTA_TABLE_MAX (__NFTA_TABLE_MAX - 1)
@@ -1483,6 +1489,15 @@ enum nft_gen_attributes { };#define NFTA_GEN_MAX (__NFTA_GEN_MAX - 1) +/** +* enum nft_owner_attributes - nf_tables netlink ownership +*/ +enum nft_owner_attributes { +NFTA_OWNER_UNSPEC , + __NFTA_OWNER_MAX +}; +#define NFTA_OWNER_MAX (__NFTA_OWNER_MAX - 1) +/* * enum nft_fib_attributes - nf_tables fib expression netlink attributes *
net/netfilter/nf_tables_api.c +194 -41
491 lines not on this page · raw message
Signature · 1 line
2.20.1