@@ -2153,6 +2153,22 @@ static int nf_tables_updchain(struct nft_ctx *ctx, u8 genmask, u8 policy,
2153
2153
return err ;
2154
2154
}
2155
2155
2156
+ static struct nft_chain * nft_chain_lookup_byid (const struct net * net ,
2157
+ const struct nlattr * nla )
2158
+ {
2159
+ u32 id = ntohl (nla_get_be32 (nla ));
2160
+ struct nft_trans * trans ;
2161
+
2162
+ list_for_each_entry (trans , & net -> nft .commit_list , list ) {
2163
+ struct nft_chain * chain = trans -> ctx .chain ;
2164
+
2165
+ if (trans -> msg_type == NFT_MSG_NEWCHAIN &&
2166
+ id == nft_trans_chain_id (trans ))
2167
+ return chain ;
2168
+ }
2169
+ return ERR_PTR (- ENOENT );
2170
+ }
2171
+
2156
2172
static int nf_tables_newchain (struct net * net , struct sock * nlsk ,
2157
2173
struct sk_buff * skb , const struct nlmsghdr * nlh ,
2158
2174
const struct nlattr * const nla [],
@@ -2633,6 +2649,7 @@ static const struct nla_policy nft_rule_policy[NFTA_RULE_MAX + 1] = {
2633
2649
.len = NFT_USERDATA_MAXLEN },
2634
2650
[NFTA_RULE_ID ] = { .type = NLA_U32 },
2635
2651
[NFTA_RULE_POSITION_ID ] = { .type = NLA_U32 },
2652
+ [NFTA_RULE_CHAIN_ID ] = { .type = NLA_U32 },
2636
2653
};
2637
2654
2638
2655
static int nf_tables_fill_rule_info (struct sk_buff * skb , struct net * net ,
@@ -3039,10 +3056,21 @@ static int nf_tables_newrule(struct net *net, struct sock *nlsk,
3039
3056
return PTR_ERR (table );
3040
3057
}
3041
3058
3042
- chain = nft_chain_lookup (net , table , nla [NFTA_RULE_CHAIN ], genmask );
3043
- if (IS_ERR (chain )) {
3044
- NL_SET_BAD_ATTR (extack , nla [NFTA_RULE_CHAIN ]);
3045
- return PTR_ERR (chain );
3059
+ if (nla [NFTA_RULE_CHAIN ]) {
3060
+ chain = nft_chain_lookup (net , table , nla [NFTA_RULE_CHAIN ],
3061
+ genmask );
3062
+ if (IS_ERR (chain )) {
3063
+ NL_SET_BAD_ATTR (extack , nla [NFTA_RULE_CHAIN ]);
3064
+ return PTR_ERR (chain );
3065
+ }
3066
+ } else if (nla [NFTA_RULE_CHAIN_ID ]) {
3067
+ chain = nft_chain_lookup_byid (net , nla [NFTA_RULE_CHAIN_ID ]);
3068
+ if (IS_ERR (chain )) {
3069
+ NL_SET_BAD_ATTR (extack , nla [NFTA_RULE_CHAIN_ID ]);
3070
+ return PTR_ERR (chain );
3071
+ }
3072
+ } else {
3073
+ return - EINVAL ;
3046
3074
}
3047
3075
3048
3076
if (nla [NFTA_RULE_HANDLE ]) {
0 commit comments