@@ -995,11 +995,14 @@ nf_tables_chain_type_lookup(struct net *net, const struct nlattr *nla,
995
995
return ERR_PTR (- ENOENT );
996
996
}
997
997
998
- static __be16 nft_base_seq (const struct net * net )
998
+ static unsigned int nft_base_seq (const struct net * net )
999
999
{
1000
- struct nftables_pernet * nft_net = nft_pernet (net );
1000
+ return READ_ONCE (net -> nft .base_seq );
1001
+ }
1001
1002
1002
- return htons (nft_net -> base_seq & 0xffff );
1003
+ static __be16 nft_base_seq_be16 (const struct net * net )
1004
+ {
1005
+ return htons (nft_base_seq (net ) & 0xffff );
1003
1006
}
1004
1007
1005
1008
static const struct nla_policy nft_table_policy [NFTA_TABLE_MAX + 1 ] = {
@@ -1019,7 +1022,7 @@ static int nf_tables_fill_table_info(struct sk_buff *skb, struct net *net,
1019
1022
1020
1023
nlh = nfnl_msg_put (skb , portid , seq ,
1021
1024
nfnl_msg_type (NFNL_SUBSYS_NFTABLES , event ),
1022
- flags , family , NFNETLINK_V0 , nft_base_seq (net ));
1025
+ flags , family , NFNETLINK_V0 , nft_base_seq_be16 (net ));
1023
1026
if (!nlh )
1024
1027
goto nla_put_failure ;
1025
1028
@@ -1112,7 +1115,7 @@ static int nf_tables_dump_tables(struct sk_buff *skb,
1112
1115
1113
1116
rcu_read_lock ();
1114
1117
nft_net = nft_pernet (net );
1115
- cb -> seq = READ_ONCE ( nft_net -> base_seq );
1118
+ cb -> seq = nft_base_seq ( net );
1116
1119
1117
1120
list_for_each_entry_rcu (table , & nft_net -> tables , list ) {
1118
1121
if (family != NFPROTO_UNSPEC && family != table -> family )
@@ -1880,7 +1883,7 @@ static int nf_tables_fill_chain_info(struct sk_buff *skb, struct net *net,
1880
1883
1881
1884
nlh = nfnl_msg_put (skb , portid , seq ,
1882
1885
nfnl_msg_type (NFNL_SUBSYS_NFTABLES , event ),
1883
- flags , family , NFNETLINK_V0 , nft_base_seq (net ));
1886
+ flags , family , NFNETLINK_V0 , nft_base_seq_be16 (net ));
1884
1887
if (!nlh )
1885
1888
goto nla_put_failure ;
1886
1889
@@ -1983,7 +1986,7 @@ static int nf_tables_dump_chains(struct sk_buff *skb,
1983
1986
1984
1987
rcu_read_lock ();
1985
1988
nft_net = nft_pernet (net );
1986
- cb -> seq = READ_ONCE ( nft_net -> base_seq );
1989
+ cb -> seq = nft_base_seq ( net );
1987
1990
1988
1991
list_for_each_entry_rcu (table , & nft_net -> tables , list ) {
1989
1992
if (family != NFPROTO_UNSPEC && family != table -> family )
@@ -3480,7 +3483,7 @@ static int nf_tables_fill_rule_info(struct sk_buff *skb, struct net *net,
3480
3483
u16 type = nfnl_msg_type (NFNL_SUBSYS_NFTABLES , event );
3481
3484
3482
3485
nlh = nfnl_msg_put (skb , portid , seq , type , flags , family , NFNETLINK_V0 ,
3483
- nft_base_seq (net ));
3486
+ nft_base_seq_be16 (net ));
3484
3487
if (!nlh )
3485
3488
goto nla_put_failure ;
3486
3489
@@ -3648,7 +3651,7 @@ static int nf_tables_dump_rules(struct sk_buff *skb,
3648
3651
3649
3652
rcu_read_lock ();
3650
3653
nft_net = nft_pernet (net );
3651
- cb -> seq = READ_ONCE ( nft_net -> base_seq );
3654
+ cb -> seq = nft_base_seq ( net );
3652
3655
3653
3656
list_for_each_entry_rcu (table , & nft_net -> tables , list ) {
3654
3657
if (family != NFPROTO_UNSPEC && family != table -> family )
@@ -3859,7 +3862,7 @@ static int nf_tables_getrule_reset(struct sk_buff *skb,
3859
3862
buf = kasprintf (GFP_ATOMIC , "%.*s:%u" ,
3860
3863
nla_len (nla [NFTA_RULE_TABLE ]),
3861
3864
(char * )nla_data (nla [NFTA_RULE_TABLE ]),
3862
- nft_net -> base_seq );
3865
+ nft_base_seq ( net ) );
3863
3866
audit_log_nfcfg (buf , info -> nfmsg -> nfgen_family , 1 ,
3864
3867
AUDIT_NFT_OP_RULE_RESET , GFP_ATOMIC );
3865
3868
kfree (buf );
@@ -4670,7 +4673,7 @@ static int nf_tables_fill_set(struct sk_buff *skb, const struct nft_ctx *ctx,
4670
4673
nlh = nfnl_msg_put (skb , portid , seq ,
4671
4674
nfnl_msg_type (NFNL_SUBSYS_NFTABLES , event ),
4672
4675
flags , ctx -> family , NFNETLINK_V0 ,
4673
- nft_base_seq (ctx -> net ));
4676
+ nft_base_seq_be16 (ctx -> net ));
4674
4677
if (!nlh )
4675
4678
goto nla_put_failure ;
4676
4679
@@ -4812,7 +4815,7 @@ static int nf_tables_dump_sets(struct sk_buff *skb, struct netlink_callback *cb)
4812
4815
4813
4816
rcu_read_lock ();
4814
4817
nft_net = nft_pernet (net );
4815
- cb -> seq = READ_ONCE ( nft_net -> base_seq );
4818
+ cb -> seq = nft_base_seq ( net );
4816
4819
4817
4820
list_for_each_entry_rcu (table , & nft_net -> tables , list ) {
4818
4821
if (ctx -> family != NFPROTO_UNSPEC &&
@@ -5988,7 +5991,7 @@ static int nf_tables_dump_set(struct sk_buff *skb, struct netlink_callback *cb)
5988
5991
5989
5992
rcu_read_lock ();
5990
5993
nft_net = nft_pernet (net );
5991
- cb -> seq = READ_ONCE ( nft_net -> base_seq );
5994
+ cb -> seq = nft_base_seq ( net );
5992
5995
5993
5996
list_for_each_entry_rcu (table , & nft_net -> tables , list ) {
5994
5997
if (dump_ctx -> ctx .family != NFPROTO_UNSPEC &&
@@ -6017,7 +6020,7 @@ static int nf_tables_dump_set(struct sk_buff *skb, struct netlink_callback *cb)
6017
6020
seq = cb -> nlh -> nlmsg_seq ;
6018
6021
6019
6022
nlh = nfnl_msg_put (skb , portid , seq , event , NLM_F_MULTI ,
6020
- table -> family , NFNETLINK_V0 , nft_base_seq (net ));
6023
+ table -> family , NFNETLINK_V0 , nft_base_seq_be16 (net ));
6021
6024
if (!nlh )
6022
6025
goto nla_put_failure ;
6023
6026
@@ -6110,7 +6113,7 @@ static int nf_tables_fill_setelem_info(struct sk_buff *skb,
6110
6113
6111
6114
event = nfnl_msg_type (NFNL_SUBSYS_NFTABLES , event );
6112
6115
nlh = nfnl_msg_put (skb , portid , seq , event , flags , ctx -> family ,
6113
- NFNETLINK_V0 , nft_base_seq (ctx -> net ));
6116
+ NFNETLINK_V0 , nft_base_seq_be16 (ctx -> net ));
6114
6117
if (!nlh )
6115
6118
goto nla_put_failure ;
6116
6119
@@ -6409,7 +6412,7 @@ static int nf_tables_getsetelem_reset(struct sk_buff *skb,
6409
6412
}
6410
6413
nelems ++ ;
6411
6414
}
6412
- audit_log_nft_set_reset (dump_ctx .ctx .table , nft_net -> base_seq , nelems );
6415
+ audit_log_nft_set_reset (dump_ctx .ctx .table , nft_base_seq ( info -> net ) , nelems );
6413
6416
6414
6417
out_unlock :
6415
6418
rcu_read_unlock ();
@@ -8012,7 +8015,7 @@ static int nf_tables_fill_obj_info(struct sk_buff *skb, struct net *net,
8012
8015
8013
8016
nlh = nfnl_msg_put (skb , portid , seq ,
8014
8017
nfnl_msg_type (NFNL_SUBSYS_NFTABLES , event ),
8015
- flags , family , NFNETLINK_V0 , nft_base_seq (net ));
8018
+ flags , family , NFNETLINK_V0 , nft_base_seq_be16 (net ));
8016
8019
if (!nlh )
8017
8020
goto nla_put_failure ;
8018
8021
@@ -8077,7 +8080,7 @@ static int nf_tables_dump_obj(struct sk_buff *skb, struct netlink_callback *cb)
8077
8080
8078
8081
rcu_read_lock ();
8079
8082
nft_net = nft_pernet (net );
8080
- cb -> seq = READ_ONCE ( nft_net -> base_seq );
8083
+ cb -> seq = nft_base_seq ( net );
8081
8084
8082
8085
list_for_each_entry_rcu (table , & nft_net -> tables , list ) {
8083
8086
if (family != NFPROTO_UNSPEC && family != table -> family )
@@ -8111,7 +8114,7 @@ static int nf_tables_dump_obj(struct sk_buff *skb, struct netlink_callback *cb)
8111
8114
idx ++ ;
8112
8115
}
8113
8116
if (ctx -> reset && entries )
8114
- audit_log_obj_reset (table , nft_net -> base_seq , entries );
8117
+ audit_log_obj_reset (table , nft_base_seq ( net ) , entries );
8115
8118
if (rc < 0 )
8116
8119
break ;
8117
8120
}
@@ -8280,7 +8283,7 @@ static int nf_tables_getobj_reset(struct sk_buff *skb,
8280
8283
buf = kasprintf (GFP_ATOMIC , "%.*s:%u" ,
8281
8284
nla_len (nla [NFTA_OBJ_TABLE ]),
8282
8285
(char * )nla_data (nla [NFTA_OBJ_TABLE ]),
8283
- nft_net -> base_seq );
8286
+ nft_base_seq ( net ) );
8284
8287
audit_log_nfcfg (buf , info -> nfmsg -> nfgen_family , 1 ,
8285
8288
AUDIT_NFT_OP_OBJ_RESET , GFP_ATOMIC );
8286
8289
kfree (buf );
@@ -8385,9 +8388,8 @@ void nft_obj_notify(struct net *net, const struct nft_table *table,
8385
8388
struct nft_object * obj , u32 portid , u32 seq , int event ,
8386
8389
u16 flags , int family , int report , gfp_t gfp )
8387
8390
{
8388
- struct nftables_pernet * nft_net = nft_pernet (net );
8389
8391
char * buf = kasprintf (gfp , "%s:%u" ,
8390
- table -> name , nft_net -> base_seq );
8392
+ table -> name , nft_base_seq ( net ) );
8391
8393
8392
8394
audit_log_nfcfg (buf ,
8393
8395
family ,
@@ -9036,7 +9038,7 @@ static int nf_tables_fill_flowtable_info(struct sk_buff *skb, struct net *net,
9036
9038
9037
9039
nlh = nfnl_msg_put (skb , portid , seq ,
9038
9040
nfnl_msg_type (NFNL_SUBSYS_NFTABLES , event ),
9039
- flags , family , NFNETLINK_V0 , nft_base_seq (net ));
9041
+ flags , family , NFNETLINK_V0 , nft_base_seq_be16 (net ));
9040
9042
if (!nlh )
9041
9043
goto nla_put_failure ;
9042
9044
@@ -9104,7 +9106,7 @@ static int nf_tables_dump_flowtable(struct sk_buff *skb,
9104
9106
9105
9107
rcu_read_lock ();
9106
9108
nft_net = nft_pernet (net );
9107
- cb -> seq = READ_ONCE ( nft_net -> base_seq );
9109
+ cb -> seq = nft_base_seq ( net );
9108
9110
9109
9111
list_for_each_entry_rcu (table , & nft_net -> tables , list ) {
9110
9112
if (family != NFPROTO_UNSPEC && family != table -> family )
@@ -9289,17 +9291,16 @@ static void nf_tables_flowtable_destroy(struct nft_flowtable *flowtable)
9289
9291
static int nf_tables_fill_gen_info (struct sk_buff * skb , struct net * net ,
9290
9292
u32 portid , u32 seq )
9291
9293
{
9292
- struct nftables_pernet * nft_net = nft_pernet (net );
9293
9294
struct nlmsghdr * nlh ;
9294
9295
char buf [TASK_COMM_LEN ];
9295
9296
int event = nfnl_msg_type (NFNL_SUBSYS_NFTABLES , NFT_MSG_NEWGEN );
9296
9297
9297
9298
nlh = nfnl_msg_put (skb , portid , seq , event , 0 , AF_UNSPEC ,
9298
- NFNETLINK_V0 , nft_base_seq (net ));
9299
+ NFNETLINK_V0 , nft_base_seq_be16 (net ));
9299
9300
if (!nlh )
9300
9301
goto nla_put_failure ;
9301
9302
9302
- if (nla_put_be32 (skb , NFTA_GEN_ID , htonl (nft_net -> base_seq )) ||
9303
+ if (nla_put_be32 (skb , NFTA_GEN_ID , htonl (nft_base_seq ( net ) )) ||
9303
9304
nla_put_be32 (skb , NFTA_GEN_PROC_PID , htonl (task_pid_nr (current ))) ||
9304
9305
nla_put_string (skb , NFTA_GEN_PROC_NAME , get_task_comm (buf , current )))
9305
9306
goto nla_put_failure ;
@@ -10462,11 +10463,11 @@ static int nf_tables_commit(struct net *net, struct sk_buff *skb)
10462
10463
* Bump generation counter, invalidate any dump in progress.
10463
10464
* Cannot fail after this point.
10464
10465
*/
10465
- base_seq = READ_ONCE ( nft_net -> base_seq );
10466
+ base_seq = nft_base_seq ( net );
10466
10467
while (++ base_seq == 0 )
10467
10468
;
10468
10469
10469
- WRITE_ONCE (nft_net -> base_seq , base_seq );
10470
+ WRITE_ONCE (net -> nft . base_seq , base_seq );
10470
10471
10471
10472
gc_seq = nft_gc_seq_begin (nft_net );
10472
10473
@@ -10698,7 +10699,7 @@ static int nf_tables_commit(struct net *net, struct sk_buff *skb)
10698
10699
10699
10700
nft_commit_notify (net , NETLINK_CB (skb ).portid );
10700
10701
nf_tables_gen_notify (net , skb , NFT_MSG_NEWGEN );
10701
- nf_tables_commit_audit_log (& adl , nft_net -> base_seq );
10702
+ nf_tables_commit_audit_log (& adl , nft_base_seq ( net ) );
10702
10703
10703
10704
nft_gc_seq_end (nft_net , gc_seq );
10704
10705
nft_net -> validate_state = NFT_VALIDATE_SKIP ;
@@ -11032,7 +11033,7 @@ static bool nf_tables_valid_genid(struct net *net, u32 genid)
11032
11033
mutex_lock (& nft_net -> commit_mutex );
11033
11034
nft_net -> tstamp = get_jiffies_64 ();
11034
11035
11035
- genid_ok = genid == 0 || nft_net -> base_seq == genid ;
11036
+ genid_ok = genid == 0 || nft_base_seq ( net ) == genid ;
11036
11037
if (!genid_ok )
11037
11038
mutex_unlock (& nft_net -> commit_mutex );
11038
11039
@@ -11710,7 +11711,7 @@ static int __net_init nf_tables_init_net(struct net *net)
11710
11711
INIT_LIST_HEAD (& nft_net -> module_list );
11711
11712
INIT_LIST_HEAD (& nft_net -> notify_list );
11712
11713
mutex_init (& nft_net -> commit_mutex );
11713
- nft_net -> base_seq = 1 ;
11714
+ net -> nft . base_seq = 1 ;
11714
11715
nft_net -> gc_seq = 0 ;
11715
11716
nft_net -> validate_state = NFT_VALIDATE_SKIP ;
11716
11717
INIT_WORK (& nft_net -> destroy_work , nf_tables_trans_destroy_work );
0 commit comments