Skip to contentSkip to conversation

mnl: consistency checks across several netlink dumps

PATCH New Pablo Neira Ayuso 1 participant 1 message Sep 9, 2014 netfilter

lore
Share & tools
lore

Pablo Neira Ayuso

author maintainer
#0 lore raw

PATCH 1/1 mnl: consistency checks across several netlink dumps

Obtain the generation ID before dumping the object lists. Then, check for generation ID updates when dumping the several lists that this needs. In case of interference, nft has to remove the stale objects and retry from scratch.

---
 include/linux/netfilter/nf_tables.h |    2 ++
 include/mnl.h                       |    1 +
 include/netlink.h                   |    1 +
 src/main.c                          |    1 +
 src/mnl.c                           |   51 +++++++++++++++++++++++++++++++++++
 src/netlink.c                       |    5 ++++
 6 files changed, 61 insertions(+)
include/linux/netfilter/nf_tables.h +2 -0
index e8b9d19..9f11558 100644
@@ -50,6 +50,7 @@ enum nft_verdicts {
  * @NFT_MSG_NEWSETELEM: create a new set element (enum nft_set_elem_attributes)
  * @NFT_MSG_GETSETELEM: get a set element (enum nft_set_elem_attributes)
  * @NFT_MSG_DELSETELEM: delete a set element (enum nft_set_elem_attributes)
+ * @NFT_MSG_GENID: get the rule-set generation ID (no attributes)
  */
 enum nf_tables_msg_types {
 	NFT_MSG_NEWTABLE,
@@ -67,6 +68,7 @@ enum nf_tables_msg_types {
 	NFT_MSG_NEWSETELEM,
 	NFT_MSG_GETSETELEM,
 	NFT_MSG_DELSETELEM,
+	NFT_MSG_GENID,
 	NFT_MSG_MAX,
 };
 
include/mnl.h +1 -0
index ed5a718..03d1876 100644
@@ -6,6 +6,7 @@
 struct mnl_socket;
 
 uint32_t mnl_seqnum_alloc(void);
+void mnl_genid_get(struct mnl_socket *nf_sock);
 
 struct mnl_err {
 	struct list_head	head;
include/netlink.h +1 -0
index f611452..7f99370 100644
@@ -139,6 +139,7 @@ extern void netlink_dump_set(struct nft_set *nls);
 extern int netlink_batch_send(struct list_head *err_list);
 
 extern void netlink_restart(void);
+extern void netlink_genid_get(void);
 extern void netlink_abi_error(void) __noreturn;
 extern int netlink_io_error(struct netlink_ctx *ctx,
 			    const struct location *loc, const char *fmt, ...);
src/main.c +1 -0
index 04a98e3..2685b0d 100644
@@ -173,6 +173,7 @@ static int nft_netlink(struct parser_state *state, struct list_head *msgs)
 	bool batch_supported = netlink_batch_supported();
 	int ret = 0;
 
+	netlink_genid_get();
 	mnl_batch_init();
 
 	batch_seqnum = mnl_batch_begin();
src/mnl.c +51 -0

93 lines not on this page · raw message

src/netlink.c +5 -0
index 7d3e71f..06c97e8 100644
@@ -75,6 +75,11 @@ void netlink_restart(void)
 	netlink_open_sock();
 }
 
+void netlink_genid_get(void)
+{
+	mnl_genid_get(nf_sock);
+}
+
 static void netlink_open_mon_sock(void)
 {
 	nf_mon_sock = nfsock_open();
Signature · 1 line
1.7.10.4