Skip to content

Commit 797d498

Browse files
committed
netfilter: nfnetlink: pass struct nfnl_info to rcu callbacks
Update rcu callbacks to use the nfnl_info structure. Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
1 parent a655536 commit 797d498

5 files changed

Lines changed: 107 additions & 120 deletions

File tree

‎include/linux/netfilter/nfnetlink.h‎

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,8 @@ struct nfnl_info {
1717
struct nfnl_callback {
1818
int (*call)(struct sk_buff *skb, const struct nfnl_info *info,
1919
const struct nlattr * const cda[]);
20-
int (*call_rcu)(struct net *net, struct sock *nl, struct sk_buff *skb,
21-
const struct nlmsghdr *nlh,
22-
const struct nlattr * const cda[],
23-
struct netlink_ext_ack *extack);
20+
int (*call_rcu)(struct sk_buff *skb, const struct nfnl_info *info,
21+
const struct nlattr * const cda[]);
2422
int (*call_batch)(struct net *net, struct sock *nl, struct sk_buff *skb,
2523
const struct nlmsghdr *nlh,
2624
const struct nlattr * const cda[],

‎net/netfilter/nf_tables_api.c‎

Lines changed: 75 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -858,25 +858,25 @@ static int nft_netlink_dump_start_rcu(struct sock *nlsk, struct sk_buff *skb,
858858
}
859859

860860
/* called with rcu_read_lock held */
861-
static int nf_tables_gettable(struct net *net, struct sock *nlsk,
862-
struct sk_buff *skb, const struct nlmsghdr *nlh,
863-
const struct nlattr * const nla[],
864-
struct netlink_ext_ack *extack)
861+
static int nf_tables_gettable(struct sk_buff *skb, const struct nfnl_info *info,
862+
const struct nlattr * const nla[])
865863
{
866-
const struct nfgenmsg *nfmsg = nlmsg_data(nlh);
867-
u8 genmask = nft_genmask_cur(net);
864+
const struct nfgenmsg *nfmsg = nlmsg_data(info->nlh);
865+
struct netlink_ext_ack *extack = info->extack;
866+
u8 genmask = nft_genmask_cur(info->net);
867+
int family = nfmsg->nfgen_family;
868868
const struct nft_table *table;
869+
struct net *net = info->net;
869870
struct sk_buff *skb2;
870-
int family = nfmsg->nfgen_family;
871871
int err;
872872

873-
if (nlh->nlmsg_flags & NLM_F_DUMP) {
873+
if (info->nlh->nlmsg_flags & NLM_F_DUMP) {
874874
struct netlink_dump_control c = {
875875
.dump = nf_tables_dump_tables,
876876
.module = THIS_MODULE,
877877
};
878878

879-
return nft_netlink_dump_start_rcu(nlsk, skb, nlh, &c);
879+
return nft_netlink_dump_start_rcu(info->sk, skb, info->nlh, &c);
880880
}
881881

882882
table = nft_table_lookup(net, nla[NFTA_TABLE_NAME], family, genmask, 0);
@@ -890,8 +890,8 @@ static int nf_tables_gettable(struct net *net, struct sock *nlsk,
890890
return -ENOMEM;
891891

892892
err = nf_tables_fill_table_info(skb2, net, NETLINK_CB(skb).portid,
893-
nlh->nlmsg_seq, NFT_MSG_NEWTABLE, 0,
894-
family, table);
893+
info->nlh->nlmsg_seq, NFT_MSG_NEWTABLE,
894+
0, family, table);
895895
if (err < 0)
896896
goto err_fill_table_info;
897897

@@ -1623,26 +1623,26 @@ static int nf_tables_dump_chains(struct sk_buff *skb,
16231623
}
16241624

16251625
/* called with rcu_read_lock held */
1626-
static int nf_tables_getchain(struct net *net, struct sock *nlsk,
1627-
struct sk_buff *skb, const struct nlmsghdr *nlh,
1628-
const struct nlattr * const nla[],
1629-
struct netlink_ext_ack *extack)
1626+
static int nf_tables_getchain(struct sk_buff *skb, const struct nfnl_info *info,
1627+
const struct nlattr * const nla[])
16301628
{
1631-
const struct nfgenmsg *nfmsg = nlmsg_data(nlh);
1632-
u8 genmask = nft_genmask_cur(net);
1629+
const struct nfgenmsg *nfmsg = nlmsg_data(info->nlh);
1630+
struct netlink_ext_ack *extack = info->extack;
1631+
u8 genmask = nft_genmask_cur(info->net);
1632+
int family = nfmsg->nfgen_family;
16331633
const struct nft_chain *chain;
1634+
struct net *net = info->net;
16341635
struct nft_table *table;
16351636
struct sk_buff *skb2;
1636-
int family = nfmsg->nfgen_family;
16371637
int err;
16381638

1639-
if (nlh->nlmsg_flags & NLM_F_DUMP) {
1639+
if (info->nlh->nlmsg_flags & NLM_F_DUMP) {
16401640
struct netlink_dump_control c = {
16411641
.dump = nf_tables_dump_chains,
16421642
.module = THIS_MODULE,
16431643
};
16441644

1645-
return nft_netlink_dump_start_rcu(nlsk, skb, nlh, &c);
1645+
return nft_netlink_dump_start_rcu(info->sk, skb, info->nlh, &c);
16461646
}
16471647

16481648
table = nft_table_lookup(net, nla[NFTA_CHAIN_TABLE], family, genmask, 0);
@@ -1662,8 +1662,8 @@ static int nf_tables_getchain(struct net *net, struct sock *nlsk,
16621662
return -ENOMEM;
16631663

16641664
err = nf_tables_fill_chain_info(skb2, net, NETLINK_CB(skb).portid,
1665-
nlh->nlmsg_seq, NFT_MSG_NEWCHAIN, 0,
1666-
family, table, chain);
1665+
info->nlh->nlmsg_seq, NFT_MSG_NEWCHAIN,
1666+
0, family, table, chain);
16671667
if (err < 0)
16681668
goto err_fill_chain_info;
16691669

@@ -3076,21 +3076,21 @@ static int nf_tables_dump_rules_done(struct netlink_callback *cb)
30763076
}
30773077

30783078
/* called with rcu_read_lock held */
3079-
static int nf_tables_getrule(struct net *net, struct sock *nlsk,
3080-
struct sk_buff *skb, const struct nlmsghdr *nlh,
3081-
const struct nlattr * const nla[],
3082-
struct netlink_ext_ack *extack)
3079+
static int nf_tables_getrule(struct sk_buff *skb, const struct nfnl_info *info,
3080+
const struct nlattr * const nla[])
30833081
{
3084-
const struct nfgenmsg *nfmsg = nlmsg_data(nlh);
3085-
u8 genmask = nft_genmask_cur(net);
3082+
const struct nfgenmsg *nfmsg = nlmsg_data(info->nlh);
3083+
struct netlink_ext_ack *extack = info->extack;
3084+
u8 genmask = nft_genmask_cur(info->net);
3085+
int family = nfmsg->nfgen_family;
30863086
const struct nft_chain *chain;
30873087
const struct nft_rule *rule;
3088+
struct net *net = info->net;
30883089
struct nft_table *table;
30893090
struct sk_buff *skb2;
3090-
int family = nfmsg->nfgen_family;
30913091
int err;
30923092

3093-
if (nlh->nlmsg_flags & NLM_F_DUMP) {
3093+
if (info->nlh->nlmsg_flags & NLM_F_DUMP) {
30943094
struct netlink_dump_control c = {
30953095
.start= nf_tables_dump_rules_start,
30963096
.dump = nf_tables_dump_rules,
@@ -3099,7 +3099,7 @@ static int nf_tables_getrule(struct net *net, struct sock *nlsk,
30993099
.data = (void *)nla,
31003100
};
31013101

3102-
return nft_netlink_dump_start_rcu(nlsk, skb, nlh, &c);
3102+
return nft_netlink_dump_start_rcu(info->sk, skb, info->nlh, &c);
31033103
}
31043104

31053105
table = nft_table_lookup(net, nla[NFTA_RULE_TABLE], family, genmask, 0);
@@ -3125,7 +3125,7 @@ static int nf_tables_getrule(struct net *net, struct sock *nlsk,
31253125
return -ENOMEM;
31263126

31273127
err = nf_tables_fill_rule_info(skb2, net, NETLINK_CB(skb).portid,
3128-
nlh->nlmsg_seq, NFT_MSG_NEWRULE, 0,
3128+
info->nlh->nlmsg_seq, NFT_MSG_NEWRULE, 0,
31293129
family, table, chain, rule, NULL);
31303130
if (err < 0)
31313131
goto err_fill_rule_info;
@@ -4045,25 +4045,25 @@ static int nf_tables_dump_sets_done(struct netlink_callback *cb)
40454045
}
40464046

40474047
/* called with rcu_read_lock held */
4048-
static int nf_tables_getset(struct net *net, struct sock *nlsk,
4049-
struct sk_buff *skb, const struct nlmsghdr *nlh,
4050-
const struct nlattr * const nla[],
4051-
struct netlink_ext_ack *extack)
4048+
static int nf_tables_getset(struct sk_buff *skb, const struct nfnl_info *info,
4049+
const struct nlattr * const nla[])
40524050
{
4053-
u8 genmask = nft_genmask_cur(net);
4051+
const struct nfgenmsg *nfmsg = nlmsg_data(info->nlh);
4052+
struct netlink_ext_ack *extack = info->extack;
4053+
u8 genmask = nft_genmask_cur(info->net);
4054+
struct net *net = info->net;
40544055
const struct nft_set *set;
4055-
struct nft_ctx ctx;
40564056
struct sk_buff *skb2;
4057-
const struct nfgenmsg *nfmsg = nlmsg_data(nlh);
4057+
struct nft_ctx ctx;
40584058
int err;
40594059

40604060
/* Verify existence before starting dump */
4061-
err = nft_ctx_init_from_setattr(&ctx, net, skb, nlh, nla, extack,
4061+
err = nft_ctx_init_from_setattr(&ctx, net, skb, info->nlh, nla, extack,
40624062
genmask, 0);
40634063
if (err < 0)
40644064
return err;
40654065

4066-
if (nlh->nlmsg_flags & NLM_F_DUMP) {
4066+
if (info->nlh->nlmsg_flags & NLM_F_DUMP) {
40674067
struct netlink_dump_control c = {
40684068
.start = nf_tables_dump_sets_start,
40694069
.dump = nf_tables_dump_sets,
@@ -4072,7 +4072,7 @@ static int nf_tables_getset(struct net *net, struct sock *nlsk,
40724072
.module = THIS_MODULE,
40734073
};
40744074

4075-
return nft_netlink_dump_start_rcu(nlsk, skb, nlh, &c);
4075+
return nft_netlink_dump_start_rcu(info->sk, skb, info->nlh, &c);
40764076
}
40774077

40784078
/* Only accept unspec with dump */
@@ -5063,18 +5063,19 @@ static int nft_get_set_elem(struct nft_ctx *ctx, struct nft_set *set,
50635063
}
50645064

50655065
/* called with rcu_read_lock held */
5066-
static int nf_tables_getsetelem(struct net *net, struct sock *nlsk,
5067-
struct sk_buff *skb, const struct nlmsghdr *nlh,
5068-
const struct nlattr * const nla[],
5069-
struct netlink_ext_ack *extack)
5066+
static int nf_tables_getsetelem(struct sk_buff *skb,
5067+
const struct nfnl_info *info,
5068+
const struct nlattr * const nla[])
50705069
{
5071-
u8 genmask = nft_genmask_cur(net);
5070+
struct netlink_ext_ack *extack = info->extack;
5071+
u8 genmask = nft_genmask_cur(info->net);
5072+
struct net *net = info->net;
50725073
struct nft_set *set;
50735074
struct nlattr *attr;
50745075
struct nft_ctx ctx;
50755076
int rem, err = 0;
50765077

5077-
err = nft_ctx_init_from_elemattr(&ctx, net, skb, nlh, nla, extack,
5078+
err = nft_ctx_init_from_elemattr(&ctx, net, skb, info->nlh, nla, extack,
50785079
genmask, NETLINK_CB(skb).portid);
50795080
if (err < 0)
50805081
return err;
@@ -5083,7 +5084,7 @@ static int nf_tables_getsetelem(struct net *net, struct sock *nlsk,
50835084
if (IS_ERR(set))
50845085
return PTR_ERR(set);
50855086

5086-
if (nlh->nlmsg_flags & NLM_F_DUMP) {
5087+
if (info->nlh->nlmsg_flags & NLM_F_DUMP) {
50875088
struct netlink_dump_control c = {
50885089
.start = nf_tables_dump_set_start,
50895090
.dump = nf_tables_dump_set,
@@ -5096,7 +5097,7 @@ static int nf_tables_getsetelem(struct net *net, struct sock *nlsk,
50965097
};
50975098

50985099
c.data = &dump_ctx;
5099-
return nft_netlink_dump_start_rcu(nlsk, skb, nlh, &c);
5100+
return nft_netlink_dump_start_rcu(info->sk, skb, info->nlh, &c);
51005101
}
51015102

51025103
if (!nla[NFTA_SET_ELEM_LIST_ELEMENTS])
@@ -6416,22 +6417,22 @@ static int nf_tables_dump_obj_done(struct netlink_callback *cb)
64166417
}
64176418

64186419
/* called with rcu_read_lock held */
6419-
static int nf_tables_getobj(struct net *net, struct sock *nlsk,
6420-
struct sk_buff *skb, const struct nlmsghdr *nlh,
6421-
const struct nlattr * const nla[],
6422-
struct netlink_ext_ack *extack)
6420+
static int nf_tables_getobj(struct sk_buff *skb, const struct nfnl_info *info,
6421+
const struct nlattr * const nla[])
64236422
{
6424-
const struct nfgenmsg *nfmsg = nlmsg_data(nlh);
6425-
u8 genmask = nft_genmask_cur(net);
6423+
const struct nfgenmsg *nfmsg = nlmsg_data(info->nlh);
6424+
struct netlink_ext_ack *extack = info->extack;
6425+
u8 genmask = nft_genmask_cur(info->net);
64266426
int family = nfmsg->nfgen_family;
64276427
const struct nft_table *table;
6428+
struct net *net = info->net;
64286429
struct nft_object *obj;
64296430
struct sk_buff *skb2;
64306431
bool reset = false;
64316432
u32 objtype;
64326433
int err;
64336434

6434-
if (nlh->nlmsg_flags & NLM_F_DUMP) {
6435+
if (info->nlh->nlmsg_flags & NLM_F_DUMP) {
64356436
struct netlink_dump_control c = {
64366437
.start = nf_tables_dump_obj_start,
64376438
.dump = nf_tables_dump_obj,
@@ -6440,7 +6441,7 @@ static int nf_tables_getobj(struct net *net, struct sock *nlsk,
64406441
.data = (void *)nla,
64416442
};
64426443

6443-
return nft_netlink_dump_start_rcu(nlsk, skb, nlh, &c);
6444+
return nft_netlink_dump_start_rcu(info->sk, skb, info->nlh, &c);
64446445
}
64456446

64466447
if (!nla[NFTA_OBJ_NAME] ||
@@ -6464,7 +6465,7 @@ static int nf_tables_getobj(struct net *net, struct sock *nlsk,
64646465
if (!skb2)
64656466
return -ENOMEM;
64666467

6467-
if (NFNL_MSG_TYPE(nlh->nlmsg_type) == NFT_MSG_GETOBJ_RESET)
6468+
if (NFNL_MSG_TYPE(info->nlh->nlmsg_type) == NFT_MSG_GETOBJ_RESET)
64686469
reset = true;
64696470

64706471
if (reset) {
@@ -6483,7 +6484,7 @@ static int nf_tables_getobj(struct net *net, struct sock *nlsk,
64836484
}
64846485

64856486
err = nf_tables_fill_obj_info(skb2, net, NETLINK_CB(skb).portid,
6486-
nlh->nlmsg_seq, NFT_MSG_NEWOBJ, 0,
6487+
info->nlh->nlmsg_seq, NFT_MSG_NEWOBJ, 0,
64876488
family, table, obj, reset);
64886489
if (err < 0)
64896490
goto err_fill_obj_info;
@@ -7320,21 +7321,20 @@ static int nf_tables_dump_flowtable_done(struct netlink_callback *cb)
73207321
}
73217322

73227323
/* called with rcu_read_lock held */
7323-
static int nf_tables_getflowtable(struct net *net, struct sock *nlsk,
7324-
struct sk_buff *skb,
7325-
const struct nlmsghdr *nlh,
7326-
const struct nlattr * const nla[],
7327-
struct netlink_ext_ack *extack)
7324+
static int nf_tables_getflowtable(struct sk_buff *skb,
7325+
const struct nfnl_info *info,
7326+
const struct nlattr * const nla[])
73287327
{
7329-
const struct nfgenmsg *nfmsg = nlmsg_data(nlh);
7330-
u8 genmask = nft_genmask_cur(net);
7328+
const struct nfgenmsg *nfmsg = nlmsg_data(info->nlh);
7329+
u8 genmask = nft_genmask_cur(info->net);
73317330
int family = nfmsg->nfgen_family;
73327331
struct nft_flowtable *flowtable;
73337332
const struct nft_table *table;
7333+
struct net *net = info->net;
73347334
struct sk_buff *skb2;
73357335
int err;
73367336

7337-
if (nlh->nlmsg_flags & NLM_F_DUMP) {
7337+
if (info->nlh->nlmsg_flags & NLM_F_DUMP) {
73387338
struct netlink_dump_control c = {
73397339
.start = nf_tables_dump_flowtable_start,
73407340
.dump = nf_tables_dump_flowtable,
@@ -7343,7 +7343,7 @@ static int nf_tables_getflowtable(struct net *net, struct sock *nlsk,
73437343
.data = (void *)nla,
73447344
};
73457345

7346-
return nft_netlink_dump_start_rcu(nlsk, skb, nlh, &c);
7346+
return nft_netlink_dump_start_rcu(info->sk, skb, info->nlh, &c);
73477347
}
73487348

73497349
if (!nla[NFTA_FLOWTABLE_NAME])
@@ -7364,7 +7364,7 @@ static int nf_tables_getflowtable(struct net *net, struct sock *nlsk,
73647364
return -ENOMEM;
73657365

73667366
err = nf_tables_fill_flowtable_info(skb2, net, NETLINK_CB(skb).portid,
7367-
nlh->nlmsg_seq,
7367+
info->nlh->nlmsg_seq,
73687368
NFT_MSG_NEWFLOWTABLE, 0, family,
73697369
flowtable, &flowtable->hook_list);
73707370
if (err < 0)
@@ -7526,10 +7526,8 @@ static void nf_tables_gen_notify(struct net *net, struct sk_buff *skb,
75267526
-ENOBUFS);
75277527
}
75287528

7529-
static int nf_tables_getgen(struct net *net, struct sock *nlsk,
7530-
struct sk_buff *skb, const struct nlmsghdr *nlh,
7531-
const struct nlattr * const nla[],
7532-
struct netlink_ext_ack *extack)
7529+
static int nf_tables_getgen(struct sk_buff *skb, const struct nfnl_info *info,
7530+
const struct nlattr * const nla[])
75337531
{
75347532
struct sk_buff *skb2;
75357533
int err;
@@ -7538,12 +7536,12 @@ static int nf_tables_getgen(struct net *net, struct sock *nlsk,
75387536
if (skb2 == NULL)
75397537
return -ENOMEM;
75407538

7541-
err = nf_tables_fill_gen_info(skb2, net, NETLINK_CB(skb).portid,
7542-
nlh->nlmsg_seq);
7539+
err = nf_tables_fill_gen_info(skb2, info->net, NETLINK_CB(skb).portid,
7540+
info->nlh->nlmsg_seq);
75437541
if (err < 0)
75447542
goto err_fill_gen_info;
75457543

7546-
return nfnetlink_unicast(skb2, net, NETLINK_CB(skb).portid);
7544+
return nfnetlink_unicast(skb2, info->net, NETLINK_CB(skb).portid);
75477545

75487546
err_fill_gen_info:
75497547
kfree_skb(skb2);

‎net/netfilter/nfnetlink.c‎

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -274,9 +274,8 @@ static int nfnetlink_rcv_msg(struct sk_buff *skb, struct nlmsghdr *nlh,
274274
}
275275

276276
if (nc->call_rcu) {
277-
err = nc->call_rcu(net, nfnlnet->nfnl, skb, nlh,
278-
(const struct nlattr **)cda,
279-
extack);
277+
err = nc->call_rcu(skb, &info,
278+
(const struct nlattr **)cda);
280279
rcu_read_unlock();
281280
} else {
282281
rcu_read_unlock();

0 commit comments

Comments
 (0)