@@ -89,14 +89,15 @@ nf_tables_afinfo_lookup(struct net *net, int family, bool autoload)
89
89
}
90
90
91
91
static void nft_ctx_init (struct nft_ctx * ctx ,
92
+ struct net * net ,
92
93
const struct sk_buff * skb ,
93
94
const struct nlmsghdr * nlh ,
94
95
struct nft_af_info * afi ,
95
96
struct nft_table * table ,
96
97
struct nft_chain * chain ,
97
98
const struct nlattr * const * nla )
98
99
{
99
- ctx -> net = sock_net ( skb -> sk ) ;
100
+ ctx -> net = net ;
100
101
ctx -> afi = afi ;
101
102
ctx -> table = table ;
102
103
ctx -> chain = chain ;
@@ -672,15 +673,14 @@ static int nf_tables_updtable(struct nft_ctx *ctx)
672
673
return ret ;
673
674
}
674
675
675
- static int nf_tables_newtable (struct sock * nlsk , struct sk_buff * skb ,
676
- const struct nlmsghdr * nlh ,
676
+ static int nf_tables_newtable (struct net * net , struct sock * nlsk ,
677
+ struct sk_buff * skb , const struct nlmsghdr * nlh ,
677
678
const struct nlattr * const nla [])
678
679
{
679
680
const struct nfgenmsg * nfmsg = nlmsg_data (nlh );
680
681
const struct nlattr * name ;
681
682
struct nft_af_info * afi ;
682
683
struct nft_table * table ;
683
- struct net * net = sock_net (skb -> sk );
684
684
int family = nfmsg -> nfgen_family ;
685
685
u32 flags = 0 ;
686
686
struct nft_ctx ctx ;
@@ -706,7 +706,7 @@ static int nf_tables_newtable(struct sock *nlsk, struct sk_buff *skb,
706
706
if (nlh -> nlmsg_flags & NLM_F_REPLACE )
707
707
return - EOPNOTSUPP ;
708
708
709
- nft_ctx_init (& ctx , skb , nlh , afi , table , NULL , nla );
709
+ nft_ctx_init (& ctx , net , skb , nlh , afi , table , NULL , nla );
710
710
return nf_tables_updtable (& ctx );
711
711
}
712
712
@@ -730,7 +730,7 @@ static int nf_tables_newtable(struct sock *nlsk, struct sk_buff *skb,
730
730
INIT_LIST_HEAD (& table -> sets );
731
731
table -> flags = flags ;
732
732
733
- nft_ctx_init (& ctx , skb , nlh , afi , table , NULL , nla );
733
+ nft_ctx_init (& ctx , net , skb , nlh , afi , table , NULL , nla );
734
734
err = nft_trans_table_add (& ctx , NFT_MSG_NEWTABLE );
735
735
if (err < 0 )
736
736
goto err3 ;
@@ -810,18 +810,17 @@ static int nft_flush(struct nft_ctx *ctx, int family)
810
810
return err ;
811
811
}
812
812
813
- static int nf_tables_deltable (struct sock * nlsk , struct sk_buff * skb ,
814
- const struct nlmsghdr * nlh ,
813
+ static int nf_tables_deltable (struct net * net , struct sock * nlsk ,
814
+ struct sk_buff * skb , const struct nlmsghdr * nlh ,
815
815
const struct nlattr * const nla [])
816
816
{
817
817
const struct nfgenmsg * nfmsg = nlmsg_data (nlh );
818
818
struct nft_af_info * afi ;
819
819
struct nft_table * table ;
820
- struct net * net = sock_net (skb -> sk );
821
820
int family = nfmsg -> nfgen_family ;
822
821
struct nft_ctx ctx ;
823
822
824
- nft_ctx_init (& ctx , skb , nlh , NULL , NULL , NULL , nla );
823
+ nft_ctx_init (& ctx , net , skb , nlh , NULL , NULL , NULL , nla );
825
824
if (family == AF_UNSPEC || nla [NFTA_TABLE_NAME ] == NULL )
826
825
return nft_flush (& ctx , family );
827
826
@@ -1221,8 +1220,8 @@ static void nf_tables_chain_destroy(struct nft_chain *chain)
1221
1220
}
1222
1221
}
1223
1222
1224
- static int nf_tables_newchain (struct sock * nlsk , struct sk_buff * skb ,
1225
- const struct nlmsghdr * nlh ,
1223
+ static int nf_tables_newchain (struct net * net , struct sock * nlsk ,
1224
+ struct sk_buff * skb , const struct nlmsghdr * nlh ,
1226
1225
const struct nlattr * const nla [])
1227
1226
{
1228
1227
const struct nfgenmsg * nfmsg = nlmsg_data (nlh );
@@ -1232,7 +1231,6 @@ static int nf_tables_newchain(struct sock *nlsk, struct sk_buff *skb,
1232
1231
struct nft_chain * chain ;
1233
1232
struct nft_base_chain * basechain = NULL ;
1234
1233
struct nlattr * ha [NFTA_HOOK_MAX + 1 ];
1235
- struct net * net = sock_net (skb -> sk );
1236
1234
int family = nfmsg -> nfgen_family ;
1237
1235
struct net_device * dev = NULL ;
1238
1236
u8 policy = NF_ACCEPT ;
@@ -1313,7 +1311,7 @@ static int nf_tables_newchain(struct sock *nlsk, struct sk_buff *skb,
1313
1311
return PTR_ERR (stats );
1314
1312
}
1315
1313
1316
- nft_ctx_init (& ctx , skb , nlh , afi , table , chain , nla );
1314
+ nft_ctx_init (& ctx , net , skb , nlh , afi , table , chain , nla );
1317
1315
trans = nft_trans_alloc (& ctx , NFT_MSG_NEWCHAIN ,
1318
1316
sizeof (struct nft_trans_chain ));
1319
1317
if (trans == NULL ) {
@@ -1461,7 +1459,7 @@ static int nf_tables_newchain(struct sock *nlsk, struct sk_buff *skb,
1461
1459
if (err < 0 )
1462
1460
goto err1 ;
1463
1461
1464
- nft_ctx_init (& ctx , skb , nlh , afi , table , chain , nla );
1462
+ nft_ctx_init (& ctx , net , skb , nlh , afi , table , chain , nla );
1465
1463
err = nft_trans_chain_add (& ctx , NFT_MSG_NEWCHAIN );
1466
1464
if (err < 0 )
1467
1465
goto err2 ;
@@ -1476,15 +1474,14 @@ static int nf_tables_newchain(struct sock *nlsk, struct sk_buff *skb,
1476
1474
return err ;
1477
1475
}
1478
1476
1479
- static int nf_tables_delchain (struct sock * nlsk , struct sk_buff * skb ,
1480
- const struct nlmsghdr * nlh ,
1477
+ static int nf_tables_delchain (struct net * net , struct sock * nlsk ,
1478
+ struct sk_buff * skb , const struct nlmsghdr * nlh ,
1481
1479
const struct nlattr * const nla [])
1482
1480
{
1483
1481
const struct nfgenmsg * nfmsg = nlmsg_data (nlh );
1484
1482
struct nft_af_info * afi ;
1485
1483
struct nft_table * table ;
1486
1484
struct nft_chain * chain ;
1487
- struct net * net = sock_net (skb -> sk );
1488
1485
int family = nfmsg -> nfgen_family ;
1489
1486
struct nft_ctx ctx ;
1490
1487
@@ -1506,7 +1503,7 @@ static int nf_tables_delchain(struct sock *nlsk, struct sk_buff *skb,
1506
1503
if (chain -> use > 0 )
1507
1504
return - EBUSY ;
1508
1505
1509
- nft_ctx_init (& ctx , skb , nlh , afi , table , chain , nla );
1506
+ nft_ctx_init (& ctx , net , skb , nlh , afi , table , chain , nla );
1510
1507
1511
1508
return nft_delchain (& ctx );
1512
1509
}
@@ -2010,13 +2007,12 @@ static void nf_tables_rule_destroy(const struct nft_ctx *ctx,
2010
2007
2011
2008
static struct nft_expr_info * info ;
2012
2009
2013
- static int nf_tables_newrule (struct sock * nlsk , struct sk_buff * skb ,
2014
- const struct nlmsghdr * nlh ,
2010
+ static int nf_tables_newrule (struct net * net , struct sock * nlsk ,
2011
+ struct sk_buff * skb , const struct nlmsghdr * nlh ,
2015
2012
const struct nlattr * const nla [])
2016
2013
{
2017
2014
const struct nfgenmsg * nfmsg = nlmsg_data (nlh );
2018
2015
struct nft_af_info * afi ;
2019
- struct net * net = sock_net (skb -> sk );
2020
2016
struct nft_table * table ;
2021
2017
struct nft_chain * chain ;
2022
2018
struct nft_rule * rule , * old_rule = NULL ;
@@ -2075,7 +2071,7 @@ static int nf_tables_newrule(struct sock *nlsk, struct sk_buff *skb,
2075
2071
return PTR_ERR (old_rule );
2076
2072
}
2077
2073
2078
- nft_ctx_init (& ctx , skb , nlh , afi , table , chain , nla );
2074
+ nft_ctx_init (& ctx , net , skb , nlh , afi , table , chain , nla );
2079
2075
2080
2076
n = 0 ;
2081
2077
size = 0 ;
@@ -2176,13 +2172,12 @@ static int nf_tables_newrule(struct sock *nlsk, struct sk_buff *skb,
2176
2172
return err ;
2177
2173
}
2178
2174
2179
- static int nf_tables_delrule (struct sock * nlsk , struct sk_buff * skb ,
2180
- const struct nlmsghdr * nlh ,
2175
+ static int nf_tables_delrule (struct net * net , struct sock * nlsk ,
2176
+ struct sk_buff * skb , const struct nlmsghdr * nlh ,
2181
2177
const struct nlattr * const nla [])
2182
2178
{
2183
2179
const struct nfgenmsg * nfmsg = nlmsg_data (nlh );
2184
2180
struct nft_af_info * afi ;
2185
- struct net * net = sock_net (skb -> sk );
2186
2181
struct nft_table * table ;
2187
2182
struct nft_chain * chain = NULL ;
2188
2183
struct nft_rule * rule ;
@@ -2205,7 +2200,7 @@ static int nf_tables_delrule(struct sock *nlsk, struct sk_buff *skb,
2205
2200
return PTR_ERR (chain );
2206
2201
}
2207
2202
2208
- nft_ctx_init (& ctx , skb , nlh , afi , table , chain , nla );
2203
+ nft_ctx_init (& ctx , net , skb , nlh , afi , table , chain , nla );
2209
2204
2210
2205
if (chain ) {
2211
2206
if (nla [NFTA_RULE_HANDLE ]) {
@@ -2344,12 +2339,11 @@ static const struct nla_policy nft_set_desc_policy[NFTA_SET_DESC_MAX + 1] = {
2344
2339
[NFTA_SET_DESC_SIZE ] = { .type = NLA_U32 },
2345
2340
};
2346
2341
2347
- static int nft_ctx_init_from_setattr (struct nft_ctx * ctx ,
2342
+ static int nft_ctx_init_from_setattr (struct nft_ctx * ctx , struct net * net ,
2348
2343
const struct sk_buff * skb ,
2349
2344
const struct nlmsghdr * nlh ,
2350
2345
const struct nlattr * const nla [])
2351
2346
{
2352
- struct net * net = sock_net (skb -> sk );
2353
2347
const struct nfgenmsg * nfmsg = nlmsg_data (nlh );
2354
2348
struct nft_af_info * afi = NULL ;
2355
2349
struct nft_table * table = NULL ;
@@ -2371,7 +2365,7 @@ static int nft_ctx_init_from_setattr(struct nft_ctx *ctx,
2371
2365
return - ENOENT ;
2372
2366
}
2373
2367
2374
- nft_ctx_init (ctx , skb , nlh , afi , table , NULL , nla );
2368
+ nft_ctx_init (ctx , net , skb , nlh , afi , table , NULL , nla );
2375
2369
return 0 ;
2376
2370
}
2377
2371
@@ -2623,14 +2617,15 @@ static int nf_tables_getset(struct sock *nlsk, struct sk_buff *skb,
2623
2617
const struct nlmsghdr * nlh ,
2624
2618
const struct nlattr * const nla [])
2625
2619
{
2620
+ struct net * net = sock_net (skb -> sk );
2626
2621
const struct nft_set * set ;
2627
2622
struct nft_ctx ctx ;
2628
2623
struct sk_buff * skb2 ;
2629
2624
const struct nfgenmsg * nfmsg = nlmsg_data (nlh );
2630
2625
int err ;
2631
2626
2632
2627
/* Verify existence before starting dump */
2633
- err = nft_ctx_init_from_setattr (& ctx , skb , nlh , nla );
2628
+ err = nft_ctx_init_from_setattr (& ctx , net , skb , nlh , nla );
2634
2629
if (err < 0 )
2635
2630
return err ;
2636
2631
@@ -2693,14 +2688,13 @@ static int nf_tables_set_desc_parse(const struct nft_ctx *ctx,
2693
2688
return 0 ;
2694
2689
}
2695
2690
2696
- static int nf_tables_newset (struct sock * nlsk , struct sk_buff * skb ,
2697
- const struct nlmsghdr * nlh ,
2691
+ static int nf_tables_newset (struct net * net , struct sock * nlsk ,
2692
+ struct sk_buff * skb , const struct nlmsghdr * nlh ,
2698
2693
const struct nlattr * const nla [])
2699
2694
{
2700
2695
const struct nfgenmsg * nfmsg = nlmsg_data (nlh );
2701
2696
const struct nft_set_ops * ops ;
2702
2697
struct nft_af_info * afi ;
2703
- struct net * net = sock_net (skb -> sk );
2704
2698
struct nft_table * table ;
2705
2699
struct nft_set * set ;
2706
2700
struct nft_ctx ctx ;
@@ -2798,7 +2792,7 @@ static int nf_tables_newset(struct sock *nlsk, struct sk_buff *skb,
2798
2792
if (IS_ERR (table ))
2799
2793
return PTR_ERR (table );
2800
2794
2801
- nft_ctx_init (& ctx , skb , nlh , afi , table , NULL , nla );
2795
+ nft_ctx_init (& ctx , net , skb , nlh , afi , table , NULL , nla );
2802
2796
2803
2797
set = nf_tables_set_lookup (table , nla [NFTA_SET_NAME ]);
2804
2798
if (IS_ERR (set )) {
@@ -2882,8 +2876,8 @@ static void nf_tables_set_destroy(const struct nft_ctx *ctx, struct nft_set *set
2882
2876
nft_set_destroy (set );
2883
2877
}
2884
2878
2885
- static int nf_tables_delset (struct sock * nlsk , struct sk_buff * skb ,
2886
- const struct nlmsghdr * nlh ,
2879
+ static int nf_tables_delset (struct net * net , struct sock * nlsk ,
2880
+ struct sk_buff * skb , const struct nlmsghdr * nlh ,
2887
2881
const struct nlattr * const nla [])
2888
2882
{
2889
2883
const struct nfgenmsg * nfmsg = nlmsg_data (nlh );
@@ -2896,7 +2890,7 @@ static int nf_tables_delset(struct sock *nlsk, struct sk_buff *skb,
2896
2890
if (nla [NFTA_SET_TABLE ] == NULL )
2897
2891
return - EINVAL ;
2898
2892
2899
- err = nft_ctx_init_from_setattr (& ctx , skb , nlh , nla );
2893
+ err = nft_ctx_init_from_setattr (& ctx , net , skb , nlh , nla );
2900
2894
if (err < 0 )
2901
2895
return err ;
2902
2896
@@ -3024,7 +3018,7 @@ static const struct nla_policy nft_set_elem_list_policy[NFTA_SET_ELEM_LIST_MAX +
3024
3018
[NFTA_SET_ELEM_LIST_SET_ID ] = { .type = NLA_U32 },
3025
3019
};
3026
3020
3027
- static int nft_ctx_init_from_elemattr (struct nft_ctx * ctx ,
3021
+ static int nft_ctx_init_from_elemattr (struct nft_ctx * ctx , struct net * net ,
3028
3022
const struct sk_buff * skb ,
3029
3023
const struct nlmsghdr * nlh ,
3030
3024
const struct nlattr * const nla [],
@@ -3033,7 +3027,6 @@ static int nft_ctx_init_from_elemattr(struct nft_ctx *ctx,
3033
3027
const struct nfgenmsg * nfmsg = nlmsg_data (nlh );
3034
3028
struct nft_af_info * afi ;
3035
3029
struct nft_table * table ;
3036
- struct net * net = sock_net (skb -> sk );
3037
3030
3038
3031
afi = nf_tables_afinfo_lookup (net , nfmsg -> nfgen_family , false);
3039
3032
if (IS_ERR (afi ))
@@ -3045,7 +3038,7 @@ static int nft_ctx_init_from_elemattr(struct nft_ctx *ctx,
3045
3038
if (!trans && (table -> flags & NFT_TABLE_INACTIVE ))
3046
3039
return - ENOENT ;
3047
3040
3048
- nft_ctx_init (ctx , skb , nlh , afi , table , NULL , nla );
3041
+ nft_ctx_init (ctx , net , skb , nlh , afi , table , NULL , nla );
3049
3042
return 0 ;
3050
3043
}
3051
3044
@@ -3135,6 +3128,7 @@ static int nf_tables_dump_setelem(const struct nft_ctx *ctx,
3135
3128
3136
3129
static int nf_tables_dump_set (struct sk_buff * skb , struct netlink_callback * cb )
3137
3130
{
3131
+ struct net * net = sock_net (skb -> sk );
3138
3132
const struct nft_set * set ;
3139
3133
struct nft_set_dump_args args ;
3140
3134
struct nft_ctx ctx ;
@@ -3150,8 +3144,8 @@ static int nf_tables_dump_set(struct sk_buff *skb, struct netlink_callback *cb)
3150
3144
if (err < 0 )
3151
3145
return err ;
3152
3146
3153
- err = nft_ctx_init_from_elemattr (& ctx , cb -> skb , cb -> nlh , ( void * ) nla ,
3154
- false);
3147
+ err = nft_ctx_init_from_elemattr (& ctx , net , cb -> skb , cb -> nlh ,
3148
+ ( void * ) nla , false);
3155
3149
if (err < 0 )
3156
3150
return err ;
3157
3151
@@ -3212,11 +3206,12 @@ static int nf_tables_getsetelem(struct sock *nlsk, struct sk_buff *skb,
3212
3206
const struct nlmsghdr * nlh ,
3213
3207
const struct nlattr * const nla [])
3214
3208
{
3209
+ struct net * net = sock_net (skb -> sk );
3215
3210
const struct nft_set * set ;
3216
3211
struct nft_ctx ctx ;
3217
3212
int err ;
3218
3213
3219
- err = nft_ctx_init_from_elemattr (& ctx , skb , nlh , nla , false);
3214
+ err = nft_ctx_init_from_elemattr (& ctx , net , skb , nlh , nla , false);
3220
3215
if (err < 0 )
3221
3216
return err ;
3222
3217
@@ -3528,11 +3523,10 @@ static int nft_add_set_elem(struct nft_ctx *ctx, struct nft_set *set,
3528
3523
return err ;
3529
3524
}
3530
3525
3531
- static int nf_tables_newsetelem (struct sock * nlsk , struct sk_buff * skb ,
3532
- const struct nlmsghdr * nlh ,
3526
+ static int nf_tables_newsetelem (struct net * net , struct sock * nlsk ,
3527
+ struct sk_buff * skb , const struct nlmsghdr * nlh ,
3533
3528
const struct nlattr * const nla [])
3534
3529
{
3535
- struct net * net = sock_net (skb -> sk );
3536
3530
const struct nlattr * attr ;
3537
3531
struct nft_set * set ;
3538
3532
struct nft_ctx ctx ;
@@ -3541,7 +3535,7 @@ static int nf_tables_newsetelem(struct sock *nlsk, struct sk_buff *skb,
3541
3535
if (nla [NFTA_SET_ELEM_LIST_ELEMENTS ] == NULL )
3542
3536
return - EINVAL ;
3543
3537
3544
- err = nft_ctx_init_from_elemattr (& ctx , skb , nlh , nla , true);
3538
+ err = nft_ctx_init_from_elemattr (& ctx , net , skb , nlh , nla , true);
3545
3539
if (err < 0 )
3546
3540
return err ;
3547
3541
@@ -3623,8 +3617,8 @@ static int nft_del_setelem(struct nft_ctx *ctx, struct nft_set *set,
3623
3617
return err ;
3624
3618
}
3625
3619
3626
- static int nf_tables_delsetelem (struct sock * nlsk , struct sk_buff * skb ,
3627
- const struct nlmsghdr * nlh ,
3620
+ static int nf_tables_delsetelem (struct net * net , struct sock * nlsk ,
3621
+ struct sk_buff * skb , const struct nlmsghdr * nlh ,
3628
3622
const struct nlattr * const nla [])
3629
3623
{
3630
3624
const struct nlattr * attr ;
@@ -3635,7 +3629,7 @@ static int nf_tables_delsetelem(struct sock *nlsk, struct sk_buff *skb,
3635
3629
if (nla [NFTA_SET_ELEM_LIST_ELEMENTS ] == NULL )
3636
3630
return - EINVAL ;
3637
3631
3638
- err = nft_ctx_init_from_elemattr (& ctx , skb , nlh , nla , false);
3632
+ err = nft_ctx_init_from_elemattr (& ctx , net , skb , nlh , nla , false);
3639
3633
if (err < 0 )
3640
3634
return err ;
3641
3635
0 commit comments