@@ -2759,7 +2759,7 @@ static const struct nla_policy nft_expr_policy[NFTA_EXPR_MAX + 1] = {
2759
2759
};
2760
2760
2761
2761
static int nf_tables_fill_expr_info (struct sk_buff * skb ,
2762
- const struct nft_expr * expr )
2762
+ const struct nft_expr * expr , bool reset )
2763
2763
{
2764
2764
if (nla_put_string (skb , NFTA_EXPR_NAME , expr -> ops -> type -> name ))
2765
2765
goto nla_put_failure ;
@@ -2769,7 +2769,7 @@ static int nf_tables_fill_expr_info(struct sk_buff *skb,
2769
2769
NFTA_EXPR_DATA );
2770
2770
if (data == NULL )
2771
2771
goto nla_put_failure ;
2772
- if (expr -> ops -> dump (skb , expr , false ) < 0 )
2772
+ if (expr -> ops -> dump (skb , expr , reset ) < 0 )
2773
2773
goto nla_put_failure ;
2774
2774
nla_nest_end (skb , data );
2775
2775
}
@@ -2781,14 +2781,14 @@ static int nf_tables_fill_expr_info(struct sk_buff *skb,
2781
2781
};
2782
2782
2783
2783
int nft_expr_dump (struct sk_buff * skb , unsigned int attr ,
2784
- const struct nft_expr * expr )
2784
+ const struct nft_expr * expr , bool reset )
2785
2785
{
2786
2786
struct nlattr * nest ;
2787
2787
2788
2788
nest = nla_nest_start_noflag (skb , attr );
2789
2789
if (!nest )
2790
2790
goto nla_put_failure ;
2791
- if (nf_tables_fill_expr_info (skb , expr ) < 0 )
2791
+ if (nf_tables_fill_expr_info (skb , expr , reset ) < 0 )
2792
2792
goto nla_put_failure ;
2793
2793
nla_nest_end (skb , nest );
2794
2794
return 0 ;
@@ -3034,7 +3034,8 @@ static int nf_tables_fill_rule_info(struct sk_buff *skb, struct net *net,
3034
3034
u32 flags , int family ,
3035
3035
const struct nft_table * table ,
3036
3036
const struct nft_chain * chain ,
3037
- const struct nft_rule * rule , u64 handle )
3037
+ const struct nft_rule * rule , u64 handle ,
3038
+ bool reset )
3038
3039
{
3039
3040
struct nlmsghdr * nlh ;
3040
3041
const struct nft_expr * expr , * next ;
@@ -3067,7 +3068,7 @@ static int nf_tables_fill_rule_info(struct sk_buff *skb, struct net *net,
3067
3068
if (list == NULL )
3068
3069
goto nla_put_failure ;
3069
3070
nft_rule_for_each_expr (expr , next , rule ) {
3070
- if (nft_expr_dump (skb , NFTA_LIST_ELEM , expr ) < 0 )
3071
+ if (nft_expr_dump (skb , NFTA_LIST_ELEM , expr , reset ) < 0 )
3071
3072
goto nla_put_failure ;
3072
3073
}
3073
3074
nla_nest_end (skb , list );
@@ -3118,7 +3119,7 @@ static void nf_tables_rule_notify(const struct nft_ctx *ctx,
3118
3119
3119
3120
err = nf_tables_fill_rule_info (skb , ctx -> net , ctx -> portid , ctx -> seq ,
3120
3121
event , flags , ctx -> family , ctx -> table ,
3121
- ctx -> chain , rule , handle );
3122
+ ctx -> chain , rule , handle , false );
3122
3123
if (err < 0 ) {
3123
3124
kfree_skb (skb );
3124
3125
goto err ;
@@ -3139,7 +3140,8 @@ static int __nf_tables_dump_rules(struct sk_buff *skb,
3139
3140
unsigned int * idx ,
3140
3141
struct netlink_callback * cb ,
3141
3142
const struct nft_table * table ,
3142
- const struct nft_chain * chain )
3143
+ const struct nft_chain * chain ,
3144
+ bool reset )
3143
3145
{
3144
3146
struct net * net = sock_net (skb -> sk );
3145
3147
const struct nft_rule * rule , * prule ;
@@ -3166,7 +3168,7 @@ static int __nf_tables_dump_rules(struct sk_buff *skb,
3166
3168
NFT_MSG_NEWRULE ,
3167
3169
NLM_F_MULTI | NLM_F_APPEND ,
3168
3170
table -> family ,
3169
- table , chain , rule , handle ) < 0 )
3171
+ table , chain , rule , handle , reset ) < 0 )
3170
3172
return 1 ;
3171
3173
3172
3174
nl_dump_check_consistent (cb , nlmsg_hdr (skb ));
@@ -3189,6 +3191,10 @@ static int nf_tables_dump_rules(struct sk_buff *skb,
3189
3191
struct net * net = sock_net (skb -> sk );
3190
3192
int family = nfmsg -> nfgen_family ;
3191
3193
struct nftables_pernet * nft_net ;
3194
+ bool reset = false;
3195
+
3196
+ if (NFNL_MSG_TYPE (cb -> nlh -> nlmsg_type ) == NFT_MSG_GETRULE_RESET )
3197
+ reset = true;
3192
3198
3193
3199
rcu_read_lock ();
3194
3200
nft_net = nft_pernet (net );
@@ -3213,14 +3219,15 @@ static int nf_tables_dump_rules(struct sk_buff *skb,
3213
3219
if (!nft_is_active (net , chain ))
3214
3220
continue ;
3215
3221
__nf_tables_dump_rules (skb , & idx ,
3216
- cb , table , chain );
3222
+ cb , table , chain , reset );
3217
3223
break ;
3218
3224
}
3219
3225
goto done ;
3220
3226
}
3221
3227
3222
3228
list_for_each_entry_rcu (chain , & table -> chains , list ) {
3223
- if (__nf_tables_dump_rules (skb , & idx , cb , table , chain ))
3229
+ if (__nf_tables_dump_rules (skb , & idx ,
3230
+ cb , table , chain , reset ))
3224
3231
goto done ;
3225
3232
}
3226
3233
@@ -3291,6 +3298,7 @@ static int nf_tables_getrule(struct sk_buff *skb, const struct nfnl_info *info,
3291
3298
struct net * net = info -> net ;
3292
3299
struct nft_table * table ;
3293
3300
struct sk_buff * skb2 ;
3301
+ bool reset = false;
3294
3302
int err ;
3295
3303
3296
3304
if (info -> nlh -> nlmsg_flags & NLM_F_DUMP ) {
@@ -3327,9 +3335,12 @@ static int nf_tables_getrule(struct sk_buff *skb, const struct nfnl_info *info,
3327
3335
if (!skb2 )
3328
3336
return - ENOMEM ;
3329
3337
3338
+ if (NFNL_MSG_TYPE (info -> nlh -> nlmsg_type ) == NFT_MSG_GETRULE_RESET )
3339
+ reset = true;
3340
+
3330
3341
err = nf_tables_fill_rule_info (skb2 , net , NETLINK_CB (skb ).portid ,
3331
3342
info -> nlh -> nlmsg_seq , NFT_MSG_NEWRULE , 0 ,
3332
- family , table , chain , rule , 0 );
3343
+ family , table , chain , rule , 0 , reset );
3333
3344
if (err < 0 )
3334
3345
goto err_fill_rule_info ;
3335
3346
@@ -4104,7 +4115,7 @@ static int nf_tables_fill_set(struct sk_buff *skb, const struct nft_ctx *ctx,
4104
4115
4105
4116
if (set -> num_exprs == 1 ) {
4106
4117
nest = nla_nest_start_noflag (skb , NFTA_SET_EXPR );
4107
- if (nf_tables_fill_expr_info (skb , set -> exprs [0 ]) < 0 )
4118
+ if (nf_tables_fill_expr_info (skb , set -> exprs [0 ], false ) < 0 )
4108
4119
goto nla_put_failure ;
4109
4120
4110
4121
nla_nest_end (skb , nest );
@@ -4115,7 +4126,7 @@ static int nf_tables_fill_set(struct sk_buff *skb, const struct nft_ctx *ctx,
4115
4126
4116
4127
for (i = 0 ; i < set -> num_exprs ; i ++ ) {
4117
4128
if (nft_expr_dump (skb , NFTA_LIST_ELEM ,
4118
- set -> exprs [i ]) < 0 )
4129
+ set -> exprs [i ], false ) < 0 )
4119
4130
goto nla_put_failure ;
4120
4131
}
4121
4132
nla_nest_end (skb , nest );
@@ -4946,7 +4957,7 @@ static int nft_set_elem_expr_dump(struct sk_buff *skb,
4946
4957
4947
4958
if (num_exprs == 1 ) {
4948
4959
expr = nft_setelem_expr_at (elem_expr , 0 );
4949
- if (nft_expr_dump (skb , NFTA_SET_ELEM_EXPR , expr ) < 0 )
4960
+ if (nft_expr_dump (skb , NFTA_SET_ELEM_EXPR , expr , false ) < 0 )
4950
4961
return -1 ;
4951
4962
4952
4963
return 0 ;
@@ -4957,7 +4968,7 @@ static int nft_set_elem_expr_dump(struct sk_buff *skb,
4957
4968
4958
4969
nft_setelem_expr_foreach (expr , elem_expr , size ) {
4959
4970
expr = nft_setelem_expr_at (elem_expr , size );
4960
- if (nft_expr_dump (skb , NFTA_LIST_ELEM , expr ) < 0 )
4971
+ if (nft_expr_dump (skb , NFTA_LIST_ELEM , expr , false ) < 0 )
4961
4972
goto nla_put_failure ;
4962
4973
}
4963
4974
nla_nest_end (skb , nest );
@@ -8311,6 +8322,12 @@ static const struct nfnl_callback nf_tables_cb[NFT_MSG_MAX] = {
8311
8322
.attr_count = NFTA_RULE_MAX ,
8312
8323
.policy = nft_rule_policy ,
8313
8324
},
8325
+ [NFT_MSG_GETRULE_RESET ] = {
8326
+ .call = nf_tables_getrule ,
8327
+ .type = NFNL_CB_RCU ,
8328
+ .attr_count = NFTA_RULE_MAX ,
8329
+ .policy = nft_rule_policy ,
8330
+ },
8314
8331
[NFT_MSG_DELRULE ] = {
8315
8332
.call = nf_tables_delrule ,
8316
8333
.type = NFNL_CB_BATCH ,
0 commit comments