Skip to content

Commit 75dd48e

Browse files
Phil Sutterummakynes
authored andcommitted
netfilter: nf_tables: Support RULE_ID reference in new rule
To allow for a batch to contain rules in arbitrary ordering, introduce NFTA_RULE_POSITION_ID attribute which works just like NFTA_RULE_POSITION but contains the ID of another rule within the same batch. This helps iptables-nft-restore handling dumps with mixed insert/append commands correctly. Note that NFTA_RULE_POSITION takes precedence over NFTA_RULE_POSITION_ID, so if the former is present, the latter is ignored. Signed-off-by: Phil Sutter <phil@nwl.cc> Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
1 parent 8e2f311 commit 75dd48e

2 files changed

Lines changed: 11 additions & 0 deletions

File tree

‎include/uapi/linux/netfilter/nf_tables.h‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,7 @@ enum nft_chain_attributes {
219219
* @NFTA_RULE_POSITION: numeric handle of the previous rule (NLA_U64)
220220
* @NFTA_RULE_USERDATA: user data (NLA_BINARY, NFT_USERDATA_MAXLEN)
221221
* @NFTA_RULE_ID: uniquely identifies a rule in a transaction (NLA_U32)
222+
* @NFTA_RULE_POSITION_ID: transaction unique identifier of the previous rule (NLA_U32)
222223
*/
223224
enum nft_rule_attributes {
224225
NFTA_RULE_UNSPEC,
@@ -231,6 +232,7 @@ enum nft_rule_attributes {
231232
NFTA_RULE_USERDATA,
232233
NFTA_RULE_PAD,
233234
NFTA_RULE_ID,
235+
NFTA_RULE_POSITION_ID,
234236
__NFTA_RULE_MAX
235237
};
236238
#define NFTA_RULE_MAX (__NFTA_RULE_MAX - 1)

‎net/netfilter/nf_tables_api.c‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2610,6 +2610,9 @@ static int nft_table_validate(struct net *net, const struct nft_table *table)
26102610
return 0;
26112611
}
26122612

2613+
static struct nft_rule *nft_rule_lookup_byid(const struct net *net,
2614+
const struct nlattr *nla);
2615+
26132616
#define NFT_RULE_MAXEXPRS 128
26142617

26152618
static int nf_tables_newrule(struct net *net, struct sock *nlsk,
@@ -2679,6 +2682,12 @@ static int nf_tables_newrule(struct net *net, struct sock *nlsk,
26792682
NL_SET_BAD_ATTR(extack, nla[NFTA_RULE_POSITION]);
26802683
return PTR_ERR(old_rule);
26812684
}
2685+
} else if (nla[NFTA_RULE_POSITION_ID]) {
2686+
old_rule = nft_rule_lookup_byid(net, nla[NFTA_RULE_POSITION_ID]);
2687+
if (IS_ERR(old_rule)) {
2688+
NL_SET_BAD_ATTR(extack, nla[NFTA_RULE_POSITION_ID]);
2689+
return PTR_ERR(old_rule);
2690+
}
26822691
}
26832692
}
26842693

0 commit comments

Comments
 (0)