335-v4.16-netfilter-nf_tables-add-single-table-list-for-all-fa.patch 43 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450
  1. From: Pablo Neira Ayuso <pablo@netfilter.org>
  2. Date: Tue, 9 Jan 2018 02:38:03 +0100
  3. Subject: [PATCH] netfilter: nf_tables: add single table list for all families
  4. Place all existing user defined tables in struct net *, instead of
  5. having one list per family. This saves us from one level of indentation
  6. in netlink dump functions.
  7. Place pointer to struct nft_af_info in struct nft_table temporarily, as
  8. we still need this to put back reference module reference counter on
  9. table removal.
  10. This patch comes in preparation for the removal of struct nft_af_info.
  11. Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
  12. ---
  13. --- a/include/net/netfilter/nf_tables.h
  14. +++ b/include/net/netfilter/nf_tables.h
  15. @@ -145,22 +145,22 @@ static inline void nft_data_debug(const
  16. * struct nft_ctx - nf_tables rule/set context
  17. *
  18. * @net: net namespace
  19. - * @afi: address family info
  20. * @table: the table the chain is contained in
  21. * @chain: the chain the rule is contained in
  22. * @nla: netlink attributes
  23. * @portid: netlink portID of the original message
  24. * @seq: netlink sequence number
  25. + * @family: protocol family
  26. * @report: notify via unicast netlink message
  27. */
  28. struct nft_ctx {
  29. struct net *net;
  30. - struct nft_af_info *afi;
  31. struct nft_table *table;
  32. struct nft_chain *chain;
  33. const struct nlattr * const *nla;
  34. u32 portid;
  35. u32 seq;
  36. + u8 family;
  37. bool report;
  38. };
  39. @@ -947,6 +947,7 @@ unsigned int nft_do_chain(struct nft_pkt
  40. * @use: number of chain references to this table
  41. * @flags: table flag (see enum nft_table_flags)
  42. * @genmask: generation mask
  43. + * @afinfo: address family info
  44. * @name: name of the table
  45. */
  46. struct nft_table {
  47. @@ -959,6 +960,7 @@ struct nft_table {
  48. u32 use;
  49. u16 flags:14,
  50. genmask:2;
  51. + struct nft_af_info *afi;
  52. char *name;
  53. };
  54. @@ -968,13 +970,11 @@ struct nft_table {
  55. * @list: used internally
  56. * @family: address family
  57. * @owner: module owner
  58. - * @tables: used internally
  59. */
  60. struct nft_af_info {
  61. struct list_head list;
  62. int family;
  63. struct module *owner;
  64. - struct list_head tables;
  65. };
  66. int nft_register_afinfo(struct net *, struct nft_af_info *);
  67. --- a/include/net/netns/nftables.h
  68. +++ b/include/net/netns/nftables.h
  69. @@ -8,6 +8,7 @@ struct nft_af_info;
  70. struct netns_nftables {
  71. struct list_head af_info;
  72. + struct list_head tables;
  73. struct list_head commit_list;
  74. struct nft_af_info *ipv4;
  75. struct nft_af_info *ipv6;
  76. --- a/net/netfilter/nf_tables_api.c
  77. +++ b/net/netfilter/nf_tables_api.c
  78. @@ -37,7 +37,6 @@ static LIST_HEAD(nf_tables_flowtables);
  79. */
  80. int nft_register_afinfo(struct net *net, struct nft_af_info *afi)
  81. {
  82. - INIT_LIST_HEAD(&afi->tables);
  83. nfnl_lock(NFNL_SUBSYS_NFTABLES);
  84. list_add_tail_rcu(&afi->list, &net->nft.af_info);
  85. nfnl_unlock(NFNL_SUBSYS_NFTABLES);
  86. @@ -99,13 +98,13 @@ static void nft_ctx_init(struct nft_ctx
  87. struct net *net,
  88. const struct sk_buff *skb,
  89. const struct nlmsghdr *nlh,
  90. - struct nft_af_info *afi,
  91. + u8 family,
  92. struct nft_table *table,
  93. struct nft_chain *chain,
  94. const struct nlattr * const *nla)
  95. {
  96. ctx->net = net;
  97. - ctx->afi = afi;
  98. + ctx->family = family;
  99. ctx->table = table;
  100. ctx->chain = chain;
  101. ctx->nla = nla;
  102. @@ -429,30 +428,31 @@ static int nft_delflowtable(struct nft_c
  103. * Tables
  104. */
  105. -static struct nft_table *nft_table_lookup(const struct nft_af_info *afi,
  106. +static struct nft_table *nft_table_lookup(const struct net *net,
  107. const struct nlattr *nla,
  108. - u8 genmask)
  109. + u8 family, u8 genmask)
  110. {
  111. struct nft_table *table;
  112. - list_for_each_entry(table, &afi->tables, list) {
  113. + list_for_each_entry(table, &net->nft.tables, list) {
  114. if (!nla_strcmp(nla, table->name) &&
  115. + table->afi->family == family &&
  116. nft_active_genmask(table, genmask))
  117. return table;
  118. }
  119. return NULL;
  120. }
  121. -static struct nft_table *nf_tables_table_lookup(const struct nft_af_info *afi,
  122. +static struct nft_table *nf_tables_table_lookup(const struct net *net,
  123. const struct nlattr *nla,
  124. - u8 genmask)
  125. + u8 family, u8 genmask)
  126. {
  127. struct nft_table *table;
  128. if (nla == NULL)
  129. return ERR_PTR(-EINVAL);
  130. - table = nft_table_lookup(afi, nla, genmask);
  131. + table = nft_table_lookup(net, nla, family, genmask);
  132. if (table != NULL)
  133. return table;
  134. @@ -551,7 +551,7 @@ static void nf_tables_table_notify(const
  135. goto err;
  136. err = nf_tables_fill_table_info(skb, ctx->net, ctx->portid, ctx->seq,
  137. - event, 0, ctx->afi->family, ctx->table);
  138. + event, 0, ctx->family, ctx->table);
  139. if (err < 0) {
  140. kfree_skb(skb);
  141. goto err;
  142. @@ -568,7 +568,6 @@ static int nf_tables_dump_tables(struct
  143. struct netlink_callback *cb)
  144. {
  145. const struct nfgenmsg *nfmsg = nlmsg_data(cb->nlh);
  146. - const struct nft_af_info *afi;
  147. const struct nft_table *table;
  148. unsigned int idx = 0, s_idx = cb->args[0];
  149. struct net *net = sock_net(skb->sk);
  150. @@ -577,30 +576,27 @@ static int nf_tables_dump_tables(struct
  151. rcu_read_lock();
  152. cb->seq = net->nft.base_seq;
  153. - list_for_each_entry_rcu(afi, &net->nft.af_info, list) {
  154. - if (family != NFPROTO_UNSPEC && family != afi->family)
  155. + list_for_each_entry_rcu(table, &net->nft.tables, list) {
  156. + if (family != NFPROTO_UNSPEC && family != table->afi->family)
  157. continue;
  158. - list_for_each_entry_rcu(table, &afi->tables, list) {
  159. - if (idx < s_idx)
  160. - goto cont;
  161. - if (idx > s_idx)
  162. - memset(&cb->args[1], 0,
  163. - sizeof(cb->args) - sizeof(cb->args[0]));
  164. - if (!nft_is_active(net, table))
  165. - continue;
  166. - if (nf_tables_fill_table_info(skb, net,
  167. - NETLINK_CB(cb->skb).portid,
  168. - cb->nlh->nlmsg_seq,
  169. - NFT_MSG_NEWTABLE,
  170. - NLM_F_MULTI,
  171. - afi->family, table) < 0)
  172. - goto done;
  173. + if (idx < s_idx)
  174. + goto cont;
  175. + if (idx > s_idx)
  176. + memset(&cb->args[1], 0,
  177. + sizeof(cb->args) - sizeof(cb->args[0]));
  178. + if (!nft_is_active(net, table))
  179. + continue;
  180. + if (nf_tables_fill_table_info(skb, net,
  181. + NETLINK_CB(cb->skb).portid,
  182. + cb->nlh->nlmsg_seq,
  183. + NFT_MSG_NEWTABLE, NLM_F_MULTI,
  184. + table->afi->family, table) < 0)
  185. + goto done;
  186. - nl_dump_check_consistent(cb, nlmsg_hdr(skb));
  187. + nl_dump_check_consistent(cb, nlmsg_hdr(skb));
  188. cont:
  189. - idx++;
  190. - }
  191. + idx++;
  192. }
  193. done:
  194. rcu_read_unlock();
  195. @@ -632,7 +628,8 @@ static int nf_tables_gettable(struct net
  196. if (IS_ERR(afi))
  197. return PTR_ERR(afi);
  198. - table = nf_tables_table_lookup(afi, nla[NFTA_TABLE_NAME], genmask);
  199. + table = nf_tables_table_lookup(net, nla[NFTA_TABLE_NAME], afi->family,
  200. + genmask);
  201. if (IS_ERR(table))
  202. return PTR_ERR(table);
  203. @@ -763,7 +760,7 @@ static int nf_tables_newtable(struct net
  204. return PTR_ERR(afi);
  205. name = nla[NFTA_TABLE_NAME];
  206. - table = nf_tables_table_lookup(afi, name, genmask);
  207. + table = nf_tables_table_lookup(net, name, afi->family, genmask);
  208. if (IS_ERR(table)) {
  209. if (PTR_ERR(table) != -ENOENT)
  210. return PTR_ERR(table);
  211. @@ -773,7 +770,7 @@ static int nf_tables_newtable(struct net
  212. if (nlh->nlmsg_flags & NLM_F_REPLACE)
  213. return -EOPNOTSUPP;
  214. - nft_ctx_init(&ctx, net, skb, nlh, afi, table, NULL, nla);
  215. + nft_ctx_init(&ctx, net, skb, nlh, afi->family, table, NULL, nla);
  216. return nf_tables_updtable(&ctx);
  217. }
  218. @@ -800,14 +797,15 @@ static int nf_tables_newtable(struct net
  219. INIT_LIST_HEAD(&table->sets);
  220. INIT_LIST_HEAD(&table->objects);
  221. INIT_LIST_HEAD(&table->flowtables);
  222. + table->afi = afi;
  223. table->flags = flags;
  224. - nft_ctx_init(&ctx, net, skb, nlh, afi, table, NULL, nla);
  225. + nft_ctx_init(&ctx, net, skb, nlh, afi->family, table, NULL, nla);
  226. err = nft_trans_table_add(&ctx, NFT_MSG_NEWTABLE);
  227. if (err < 0)
  228. goto err4;
  229. - list_add_tail_rcu(&table->list, &afi->tables);
  230. + list_add_tail_rcu(&table->list, &net->nft.tables);
  231. return 0;
  232. err4:
  233. kfree(table->name);
  234. @@ -881,30 +879,28 @@ out:
  235. static int nft_flush(struct nft_ctx *ctx, int family)
  236. {
  237. - struct nft_af_info *afi;
  238. struct nft_table *table, *nt;
  239. const struct nlattr * const *nla = ctx->nla;
  240. int err = 0;
  241. - list_for_each_entry(afi, &ctx->net->nft.af_info, list) {
  242. - if (family != AF_UNSPEC && afi->family != family)
  243. + list_for_each_entry_safe(table, nt, &ctx->net->nft.tables, list) {
  244. + if (family != AF_UNSPEC && table->afi->family != family)
  245. continue;
  246. - ctx->afi = afi;
  247. - list_for_each_entry_safe(table, nt, &afi->tables, list) {
  248. - if (!nft_is_active_next(ctx->net, table))
  249. - continue;
  250. + ctx->family = table->afi->family;
  251. - if (nla[NFTA_TABLE_NAME] &&
  252. - nla_strcmp(nla[NFTA_TABLE_NAME], table->name) != 0)
  253. - continue;
  254. + if (!nft_is_active_next(ctx->net, table))
  255. + continue;
  256. - ctx->table = table;
  257. + if (nla[NFTA_TABLE_NAME] &&
  258. + nla_strcmp(nla[NFTA_TABLE_NAME], table->name) != 0)
  259. + continue;
  260. - err = nft_flush_table(ctx);
  261. - if (err < 0)
  262. - goto out;
  263. - }
  264. + ctx->table = table;
  265. +
  266. + err = nft_flush_table(ctx);
  267. + if (err < 0)
  268. + goto out;
  269. }
  270. out:
  271. return err;
  272. @@ -922,7 +918,7 @@ static int nf_tables_deltable(struct net
  273. int family = nfmsg->nfgen_family;
  274. struct nft_ctx ctx;
  275. - nft_ctx_init(&ctx, net, skb, nlh, NULL, NULL, NULL, nla);
  276. + nft_ctx_init(&ctx, net, skb, nlh, 0, NULL, NULL, nla);
  277. if (family == AF_UNSPEC || nla[NFTA_TABLE_NAME] == NULL)
  278. return nft_flush(&ctx, family);
  279. @@ -930,7 +926,8 @@ static int nf_tables_deltable(struct net
  280. if (IS_ERR(afi))
  281. return PTR_ERR(afi);
  282. - table = nf_tables_table_lookup(afi, nla[NFTA_TABLE_NAME], genmask);
  283. + table = nf_tables_table_lookup(net, nla[NFTA_TABLE_NAME], afi->family,
  284. + genmask);
  285. if (IS_ERR(table))
  286. return PTR_ERR(table);
  287. @@ -938,7 +935,7 @@ static int nf_tables_deltable(struct net
  288. table->use > 0)
  289. return -EBUSY;
  290. - ctx.afi = afi;
  291. + ctx.family = afi->family;
  292. ctx.table = table;
  293. return nft_flush_table(&ctx);
  294. @@ -950,7 +947,7 @@ static void nf_tables_table_destroy(stru
  295. kfree(ctx->table->name);
  296. kfree(ctx->table);
  297. - module_put(ctx->afi->owner);
  298. + module_put(ctx->table->afi->owner);
  299. }
  300. int nft_register_chain_type(const struct nf_chain_type *ctype)
  301. @@ -1151,7 +1148,7 @@ static void nf_tables_chain_notify(const
  302. goto err;
  303. err = nf_tables_fill_chain_info(skb, ctx->net, ctx->portid, ctx->seq,
  304. - event, 0, ctx->afi->family, ctx->table,
  305. + event, 0, ctx->family, ctx->table,
  306. ctx->chain);
  307. if (err < 0) {
  308. kfree_skb(skb);
  309. @@ -1169,7 +1166,6 @@ static int nf_tables_dump_chains(struct
  310. struct netlink_callback *cb)
  311. {
  312. const struct nfgenmsg *nfmsg = nlmsg_data(cb->nlh);
  313. - const struct nft_af_info *afi;
  314. const struct nft_table *table;
  315. const struct nft_chain *chain;
  316. unsigned int idx = 0, s_idx = cb->args[0];
  317. @@ -1179,31 +1175,30 @@ static int nf_tables_dump_chains(struct
  318. rcu_read_lock();
  319. cb->seq = net->nft.base_seq;
  320. - list_for_each_entry_rcu(afi, &net->nft.af_info, list) {
  321. - if (family != NFPROTO_UNSPEC && family != afi->family)
  322. + list_for_each_entry_rcu(table, &net->nft.tables, list) {
  323. + if (family != NFPROTO_UNSPEC && family != table->afi->family)
  324. continue;
  325. - list_for_each_entry_rcu(table, &afi->tables, list) {
  326. - list_for_each_entry_rcu(chain, &table->chains, list) {
  327. - if (idx < s_idx)
  328. - goto cont;
  329. - if (idx > s_idx)
  330. - memset(&cb->args[1], 0,
  331. - sizeof(cb->args) - sizeof(cb->args[0]));
  332. - if (!nft_is_active(net, chain))
  333. - continue;
  334. - if (nf_tables_fill_chain_info(skb, net,
  335. - NETLINK_CB(cb->skb).portid,
  336. - cb->nlh->nlmsg_seq,
  337. - NFT_MSG_NEWCHAIN,
  338. - NLM_F_MULTI,
  339. - afi->family, table, chain) < 0)
  340. - goto done;
  341. + list_for_each_entry_rcu(chain, &table->chains, list) {
  342. + if (idx < s_idx)
  343. + goto cont;
  344. + if (idx > s_idx)
  345. + memset(&cb->args[1], 0,
  346. + sizeof(cb->args) - sizeof(cb->args[0]));
  347. + if (!nft_is_active(net, chain))
  348. + continue;
  349. + if (nf_tables_fill_chain_info(skb, net,
  350. + NETLINK_CB(cb->skb).portid,
  351. + cb->nlh->nlmsg_seq,
  352. + NFT_MSG_NEWCHAIN,
  353. + NLM_F_MULTI,
  354. + table->afi->family, table,
  355. + chain) < 0)
  356. + goto done;
  357. - nl_dump_check_consistent(cb, nlmsg_hdr(skb));
  358. + nl_dump_check_consistent(cb, nlmsg_hdr(skb));
  359. cont:
  360. - idx++;
  361. - }
  362. + idx++;
  363. }
  364. }
  365. done:
  366. @@ -1237,7 +1232,8 @@ static int nf_tables_getchain(struct net
  367. if (IS_ERR(afi))
  368. return PTR_ERR(afi);
  369. - table = nf_tables_table_lookup(afi, nla[NFTA_CHAIN_TABLE], genmask);
  370. + table = nf_tables_table_lookup(net, nla[NFTA_CHAIN_TABLE], afi->family,
  371. + genmask);
  372. if (IS_ERR(table))
  373. return PTR_ERR(table);
  374. @@ -1347,8 +1343,8 @@ struct nft_chain_hook {
  375. static int nft_chain_parse_hook(struct net *net,
  376. const struct nlattr * const nla[],
  377. - struct nft_af_info *afi,
  378. - struct nft_chain_hook *hook, bool create)
  379. + struct nft_chain_hook *hook, u8 family,
  380. + bool create)
  381. {
  382. struct nlattr *ha[NFTA_HOOK_MAX + 1];
  383. const struct nf_chain_type *type;
  384. @@ -1367,10 +1363,10 @@ static int nft_chain_parse_hook(struct n
  385. hook->num = ntohl(nla_get_be32(ha[NFTA_HOOK_HOOKNUM]));
  386. hook->priority = ntohl(nla_get_be32(ha[NFTA_HOOK_PRIORITY]));
  387. - type = chain_type[afi->family][NFT_CHAIN_T_DEFAULT];
  388. + type = chain_type[family][NFT_CHAIN_T_DEFAULT];
  389. if (nla[NFTA_CHAIN_TYPE]) {
  390. type = nf_tables_chain_type_lookup(nla[NFTA_CHAIN_TYPE],
  391. - afi->family, create);
  392. + family, create);
  393. if (IS_ERR(type))
  394. return PTR_ERR(type);
  395. }
  396. @@ -1382,7 +1378,7 @@ static int nft_chain_parse_hook(struct n
  397. hook->type = type;
  398. hook->dev = NULL;
  399. - if (afi->family == NFPROTO_NETDEV) {
  400. + if (family == NFPROTO_NETDEV) {
  401. char ifname[IFNAMSIZ];
  402. if (!ha[NFTA_HOOK_DEV]) {
  403. @@ -1417,7 +1413,6 @@ static int nf_tables_addchain(struct nft
  404. {
  405. const struct nlattr * const *nla = ctx->nla;
  406. struct nft_table *table = ctx->table;
  407. - struct nft_af_info *afi = ctx->afi;
  408. struct nft_base_chain *basechain;
  409. struct nft_stats __percpu *stats;
  410. struct net *net = ctx->net;
  411. @@ -1431,7 +1426,7 @@ static int nf_tables_addchain(struct nft
  412. struct nft_chain_hook hook;
  413. struct nf_hook_ops *ops;
  414. - err = nft_chain_parse_hook(net, nla, afi, &hook, create);
  415. + err = nft_chain_parse_hook(net, nla, &hook, family, create);
  416. if (err < 0)
  417. return err;
  418. @@ -1523,7 +1518,7 @@ static int nf_tables_updchain(struct nft
  419. if (!nft_is_base_chain(chain))
  420. return -EBUSY;
  421. - err = nft_chain_parse_hook(ctx->net, nla, ctx->afi, &hook,
  422. + err = nft_chain_parse_hook(ctx->net, nla, &hook, ctx->family,
  423. create);
  424. if (err < 0)
  425. return err;
  426. @@ -1633,7 +1628,8 @@ static int nf_tables_newchain(struct net
  427. if (IS_ERR(afi))
  428. return PTR_ERR(afi);
  429. - table = nf_tables_table_lookup(afi, nla[NFTA_CHAIN_TABLE], genmask);
  430. + table = nf_tables_table_lookup(net, nla[NFTA_CHAIN_TABLE], afi->family,
  431. + genmask);
  432. if (IS_ERR(table))
  433. return PTR_ERR(table);
  434. @@ -1673,7 +1669,7 @@ static int nf_tables_newchain(struct net
  435. }
  436. }
  437. - nft_ctx_init(&ctx, net, skb, nlh, afi, table, chain, nla);
  438. + nft_ctx_init(&ctx, net, skb, nlh, afi->family, table, chain, nla);
  439. if (chain != NULL) {
  440. if (nlh->nlmsg_flags & NLM_F_EXCL)
  441. @@ -1707,7 +1703,8 @@ static int nf_tables_delchain(struct net
  442. if (IS_ERR(afi))
  443. return PTR_ERR(afi);
  444. - table = nf_tables_table_lookup(afi, nla[NFTA_CHAIN_TABLE], genmask);
  445. + table = nf_tables_table_lookup(net, nla[NFTA_CHAIN_TABLE], afi->family,
  446. + genmask);
  447. if (IS_ERR(table))
  448. return PTR_ERR(table);
  449. @@ -1719,7 +1716,7 @@ static int nf_tables_delchain(struct net
  450. chain->use > 0)
  451. return -EBUSY;
  452. - nft_ctx_init(&ctx, net, skb, nlh, afi, table, chain, nla);
  453. + nft_ctx_init(&ctx, net, skb, nlh, afi->family, table, chain, nla);
  454. use = chain->use;
  455. list_for_each_entry(rule, &chain->rules, list) {
  456. @@ -1887,7 +1884,7 @@ static int nf_tables_expr_parse(const st
  457. if (err < 0)
  458. return err;
  459. - type = nft_expr_type_get(ctx->afi->family, tb[NFTA_EXPR_NAME]);
  460. + type = nft_expr_type_get(ctx->family, tb[NFTA_EXPR_NAME]);
  461. if (IS_ERR(type))
  462. return PTR_ERR(type);
  463. @@ -2115,7 +2112,7 @@ static void nf_tables_rule_notify(const
  464. goto err;
  465. err = nf_tables_fill_rule_info(skb, ctx->net, ctx->portid, ctx->seq,
  466. - event, 0, ctx->afi->family, ctx->table,
  467. + event, 0, ctx->family, ctx->table,
  468. ctx->chain, rule);
  469. if (err < 0) {
  470. kfree_skb(skb);
  471. @@ -2139,7 +2136,6 @@ static int nf_tables_dump_rules(struct s
  472. {
  473. const struct nfgenmsg *nfmsg = nlmsg_data(cb->nlh);
  474. const struct nft_rule_dump_ctx *ctx = cb->data;
  475. - const struct nft_af_info *afi;
  476. const struct nft_table *table;
  477. const struct nft_chain *chain;
  478. const struct nft_rule *rule;
  479. @@ -2150,39 +2146,37 @@ static int nf_tables_dump_rules(struct s
  480. rcu_read_lock();
  481. cb->seq = net->nft.base_seq;
  482. - list_for_each_entry_rcu(afi, &net->nft.af_info, list) {
  483. - if (family != NFPROTO_UNSPEC && family != afi->family)
  484. + list_for_each_entry_rcu(table, &net->nft.tables, list) {
  485. + if (family != NFPROTO_UNSPEC && family != table->afi->family)
  486. + continue;
  487. +
  488. + if (ctx && ctx->table && strcmp(ctx->table, table->name) != 0)
  489. continue;
  490. - list_for_each_entry_rcu(table, &afi->tables, list) {
  491. - if (ctx && ctx->table &&
  492. - strcmp(ctx->table, table->name) != 0)
  493. + list_for_each_entry_rcu(chain, &table->chains, list) {
  494. + if (ctx && ctx->chain &&
  495. + strcmp(ctx->chain, chain->name) != 0)
  496. continue;
  497. - list_for_each_entry_rcu(chain, &table->chains, list) {
  498. - if (ctx && ctx->chain &&
  499. - strcmp(ctx->chain, chain->name) != 0)
  500. - continue;
  501. -
  502. - list_for_each_entry_rcu(rule, &chain->rules, list) {
  503. - if (!nft_is_active(net, rule))
  504. - goto cont;
  505. - if (idx < s_idx)
  506. - goto cont;
  507. - if (idx > s_idx)
  508. - memset(&cb->args[1], 0,
  509. - sizeof(cb->args) - sizeof(cb->args[0]));
  510. - if (nf_tables_fill_rule_info(skb, net, NETLINK_CB(cb->skb).portid,
  511. - cb->nlh->nlmsg_seq,
  512. - NFT_MSG_NEWRULE,
  513. - NLM_F_MULTI | NLM_F_APPEND,
  514. - afi->family, table, chain, rule) < 0)
  515. - goto done;
  516. + list_for_each_entry_rcu(rule, &chain->rules, list) {
  517. + if (!nft_is_active(net, rule))
  518. + goto cont;
  519. + if (idx < s_idx)
  520. + goto cont;
  521. + if (idx > s_idx)
  522. + memset(&cb->args[1], 0,
  523. + sizeof(cb->args) - sizeof(cb->args[0]));
  524. + if (nf_tables_fill_rule_info(skb, net, NETLINK_CB(cb->skb).portid,
  525. + cb->nlh->nlmsg_seq,
  526. + NFT_MSG_NEWRULE,
  527. + NLM_F_MULTI | NLM_F_APPEND,
  528. + table->afi->family,
  529. + table, chain, rule) < 0)
  530. + goto done;
  531. - nl_dump_check_consistent(cb, nlmsg_hdr(skb));
  532. + nl_dump_check_consistent(cb, nlmsg_hdr(skb));
  533. cont:
  534. - idx++;
  535. - }
  536. + idx++;
  537. }
  538. }
  539. }
  540. @@ -2260,7 +2254,8 @@ static int nf_tables_getrule(struct net
  541. if (IS_ERR(afi))
  542. return PTR_ERR(afi);
  543. - table = nf_tables_table_lookup(afi, nla[NFTA_RULE_TABLE], genmask);
  544. + table = nf_tables_table_lookup(net, nla[NFTA_RULE_TABLE], afi->family,
  545. + genmask);
  546. if (IS_ERR(table))
  547. return PTR_ERR(table);
  548. @@ -2345,7 +2340,8 @@ static int nf_tables_newrule(struct net
  549. if (IS_ERR(afi))
  550. return PTR_ERR(afi);
  551. - table = nf_tables_table_lookup(afi, nla[NFTA_RULE_TABLE], genmask);
  552. + table = nf_tables_table_lookup(net, nla[NFTA_RULE_TABLE], afi->family,
  553. + genmask);
  554. if (IS_ERR(table))
  555. return PTR_ERR(table);
  556. @@ -2384,7 +2380,7 @@ static int nf_tables_newrule(struct net
  557. return PTR_ERR(old_rule);
  558. }
  559. - nft_ctx_init(&ctx, net, skb, nlh, afi, table, chain, nla);
  560. + nft_ctx_init(&ctx, net, skb, nlh, afi->family, table, chain, nla);
  561. n = 0;
  562. size = 0;
  563. @@ -2517,7 +2513,8 @@ static int nf_tables_delrule(struct net
  564. if (IS_ERR(afi))
  565. return PTR_ERR(afi);
  566. - table = nf_tables_table_lookup(afi, nla[NFTA_RULE_TABLE], genmask);
  567. + table = nf_tables_table_lookup(net, nla[NFTA_RULE_TABLE], afi->family,
  568. + genmask);
  569. if (IS_ERR(table))
  570. return PTR_ERR(table);
  571. @@ -2528,7 +2525,7 @@ static int nf_tables_delrule(struct net
  572. return PTR_ERR(chain);
  573. }
  574. - nft_ctx_init(&ctx, net, skb, nlh, afi, table, chain, nla);
  575. + nft_ctx_init(&ctx, net, skb, nlh, afi->family, table, chain, nla);
  576. if (chain) {
  577. if (nla[NFTA_RULE_HANDLE]) {
  578. @@ -2726,13 +2723,13 @@ static int nft_ctx_init_from_setattr(str
  579. if (afi == NULL)
  580. return -EAFNOSUPPORT;
  581. - table = nf_tables_table_lookup(afi, nla[NFTA_SET_TABLE],
  582. - genmask);
  583. + table = nf_tables_table_lookup(net, nla[NFTA_SET_TABLE],
  584. + afi->family, genmask);
  585. if (IS_ERR(table))
  586. return PTR_ERR(table);
  587. }
  588. - nft_ctx_init(ctx, net, skb, nlh, afi, table, NULL, nla);
  589. + nft_ctx_init(ctx, net, skb, nlh, afi->family, table, NULL, nla);
  590. return 0;
  591. }
  592. @@ -2860,7 +2857,7 @@ static int nf_tables_fill_set(struct sk_
  593. goto nla_put_failure;
  594. nfmsg = nlmsg_data(nlh);
  595. - nfmsg->nfgen_family = ctx->afi->family;
  596. + nfmsg->nfgen_family = ctx->family;
  597. nfmsg->version = NFNETLINK_V0;
  598. nfmsg->res_id = htons(ctx->net->nft.base_seq & 0xffff);
  599. @@ -2953,10 +2950,8 @@ static int nf_tables_dump_sets(struct sk
  600. {
  601. const struct nft_set *set;
  602. unsigned int idx, s_idx = cb->args[0];
  603. - struct nft_af_info *afi;
  604. struct nft_table *table, *cur_table = (struct nft_table *)cb->args[2];
  605. struct net *net = sock_net(skb->sk);
  606. - int cur_family = cb->args[3];
  607. struct nft_ctx *ctx = cb->data, ctx_set;
  608. if (cb->args[1])
  609. @@ -2965,51 +2960,44 @@ static int nf_tables_dump_sets(struct sk
  610. rcu_read_lock();
  611. cb->seq = net->nft.base_seq;
  612. - list_for_each_entry_rcu(afi, &net->nft.af_info, list) {
  613. - if (ctx->afi && ctx->afi != afi)
  614. + list_for_each_entry_rcu(table, &net->nft.tables, list) {
  615. + if (ctx->family != NFPROTO_UNSPEC &&
  616. + ctx->family != table->afi->family)
  617. continue;
  618. - if (cur_family) {
  619. - if (afi->family != cur_family)
  620. - continue;
  621. + if (ctx->table && ctx->table != table)
  622. + continue;
  623. - cur_family = 0;
  624. - }
  625. - list_for_each_entry_rcu(table, &afi->tables, list) {
  626. - if (ctx->table && ctx->table != table)
  627. + if (cur_table) {
  628. + if (cur_table != table)
  629. continue;
  630. - if (cur_table) {
  631. - if (cur_table != table)
  632. - continue;
  633. + cur_table = NULL;
  634. + }
  635. + idx = 0;
  636. + list_for_each_entry_rcu(set, &table->sets, list) {
  637. + if (idx < s_idx)
  638. + goto cont;
  639. + if (!nft_is_active(net, set))
  640. + goto cont;
  641. - cur_table = NULL;
  642. + ctx_set = *ctx;
  643. + ctx_set.table = table;
  644. + ctx_set.family = table->afi->family;
  645. +
  646. + if (nf_tables_fill_set(skb, &ctx_set, set,
  647. + NFT_MSG_NEWSET,
  648. + NLM_F_MULTI) < 0) {
  649. + cb->args[0] = idx;
  650. + cb->args[2] = (unsigned long) table;
  651. + goto done;
  652. }
  653. - idx = 0;
  654. - list_for_each_entry_rcu(set, &table->sets, list) {
  655. - if (idx < s_idx)
  656. - goto cont;
  657. - if (!nft_is_active(net, set))
  658. - goto cont;
  659. -
  660. - ctx_set = *ctx;
  661. - ctx_set.table = table;
  662. - ctx_set.afi = afi;
  663. - if (nf_tables_fill_set(skb, &ctx_set, set,
  664. - NFT_MSG_NEWSET,
  665. - NLM_F_MULTI) < 0) {
  666. - cb->args[0] = idx;
  667. - cb->args[2] = (unsigned long) table;
  668. - cb->args[3] = afi->family;
  669. - goto done;
  670. - }
  671. - nl_dump_check_consistent(cb, nlmsg_hdr(skb));
  672. + nl_dump_check_consistent(cb, nlmsg_hdr(skb));
  673. cont:
  674. - idx++;
  675. - }
  676. - if (s_idx)
  677. - s_idx = 0;
  678. + idx++;
  679. }
  680. + if (s_idx)
  681. + s_idx = 0;
  682. }
  683. cb->args[1] = 1;
  684. done:
  685. @@ -3222,11 +3210,12 @@ static int nf_tables_newset(struct net *
  686. if (IS_ERR(afi))
  687. return PTR_ERR(afi);
  688. - table = nf_tables_table_lookup(afi, nla[NFTA_SET_TABLE], genmask);
  689. + table = nf_tables_table_lookup(net, nla[NFTA_SET_TABLE], afi->family,
  690. + genmask);
  691. if (IS_ERR(table))
  692. return PTR_ERR(table);
  693. - nft_ctx_init(&ctx, net, skb, nlh, afi, table, NULL, nla);
  694. + nft_ctx_init(&ctx, net, skb, nlh, afi->family, table, NULL, nla);
  695. set = nf_tables_set_lookup(table, nla[NFTA_SET_NAME], genmask);
  696. if (IS_ERR(set)) {
  697. @@ -3495,12 +3484,12 @@ static int nft_ctx_init_from_elemattr(st
  698. if (IS_ERR(afi))
  699. return PTR_ERR(afi);
  700. - table = nf_tables_table_lookup(afi, nla[NFTA_SET_ELEM_LIST_TABLE],
  701. - genmask);
  702. + table = nf_tables_table_lookup(net, nla[NFTA_SET_ELEM_LIST_TABLE],
  703. + afi->family, genmask);
  704. if (IS_ERR(table))
  705. return PTR_ERR(table);
  706. - nft_ctx_init(ctx, net, skb, nlh, afi, table, NULL, nla);
  707. + nft_ctx_init(ctx, net, skb, nlh, afi->family, table, NULL, nla);
  708. return 0;
  709. }
  710. @@ -3605,7 +3594,6 @@ static int nf_tables_dump_set(struct sk_
  711. {
  712. struct nft_set_dump_ctx *dump_ctx = cb->data;
  713. struct net *net = sock_net(skb->sk);
  714. - struct nft_af_info *afi;
  715. struct nft_table *table;
  716. struct nft_set *set;
  717. struct nft_set_dump_args args;
  718. @@ -3617,21 +3605,19 @@ static int nf_tables_dump_set(struct sk_
  719. int event;
  720. rcu_read_lock();
  721. - list_for_each_entry_rcu(afi, &net->nft.af_info, list) {
  722. - if (afi != dump_ctx->ctx.afi)
  723. + list_for_each_entry_rcu(table, &net->nft.tables, list) {
  724. + if (dump_ctx->ctx.family != NFPROTO_UNSPEC &&
  725. + dump_ctx->ctx.family != table->afi->family)
  726. continue;
  727. - list_for_each_entry_rcu(table, &afi->tables, list) {
  728. - if (table != dump_ctx->ctx.table)
  729. - continue;
  730. + if (table != dump_ctx->ctx.table)
  731. + continue;
  732. - list_for_each_entry_rcu(set, &table->sets, list) {
  733. - if (set == dump_ctx->set) {
  734. - set_found = true;
  735. - break;
  736. - }
  737. + list_for_each_entry_rcu(set, &table->sets, list) {
  738. + if (set == dump_ctx->set) {
  739. + set_found = true;
  740. + break;
  741. }
  742. - break;
  743. }
  744. break;
  745. }
  746. @@ -3651,7 +3637,7 @@ static int nf_tables_dump_set(struct sk_
  747. goto nla_put_failure;
  748. nfmsg = nlmsg_data(nlh);
  749. - nfmsg->nfgen_family = afi->family;
  750. + nfmsg->nfgen_family = table->afi->family;
  751. nfmsg->version = NFNETLINK_V0;
  752. nfmsg->res_id = htons(net->nft.base_seq & 0xffff);
  753. @@ -3753,7 +3739,7 @@ static int nf_tables_fill_setelem_info(s
  754. goto nla_put_failure;
  755. nfmsg = nlmsg_data(nlh);
  756. - nfmsg->nfgen_family = ctx->afi->family;
  757. + nfmsg->nfgen_family = ctx->family;
  758. nfmsg->version = NFNETLINK_V0;
  759. nfmsg->res_id = htons(ctx->net->nft.base_seq & 0xffff);
  760. @@ -4003,7 +3989,7 @@ static int nft_add_set_elem(struct nft_c
  761. list_for_each_entry(binding, &set->bindings, list) {
  762. struct nft_ctx bind_ctx = {
  763. .net = ctx->net,
  764. - .afi = ctx->afi,
  765. + .family = ctx->family,
  766. .table = ctx->table,
  767. .chain = (struct nft_chain *)binding->chain,
  768. };
  769. @@ -4555,7 +4541,8 @@ static int nf_tables_newobj(struct net *
  770. if (IS_ERR(afi))
  771. return PTR_ERR(afi);
  772. - table = nf_tables_table_lookup(afi, nla[NFTA_OBJ_TABLE], genmask);
  773. + table = nf_tables_table_lookup(net, nla[NFTA_OBJ_TABLE], afi->family,
  774. + genmask);
  775. if (IS_ERR(table))
  776. return PTR_ERR(table);
  777. @@ -4573,7 +4560,7 @@ static int nf_tables_newobj(struct net *
  778. return 0;
  779. }
  780. - nft_ctx_init(&ctx, net, skb, nlh, afi, table, NULL, nla);
  781. + nft_ctx_init(&ctx, net, skb, nlh, afi->family, table, NULL, nla);
  782. type = nft_obj_type_get(objtype);
  783. if (IS_ERR(type))
  784. @@ -4650,7 +4637,6 @@ struct nft_obj_filter {
  785. static int nf_tables_dump_obj(struct sk_buff *skb, struct netlink_callback *cb)
  786. {
  787. const struct nfgenmsg *nfmsg = nlmsg_data(cb->nlh);
  788. - const struct nft_af_info *afi;
  789. const struct nft_table *table;
  790. unsigned int idx = 0, s_idx = cb->args[0];
  791. struct nft_obj_filter *filter = cb->data;
  792. @@ -4665,38 +4651,37 @@ static int nf_tables_dump_obj(struct sk_
  793. rcu_read_lock();
  794. cb->seq = net->nft.base_seq;
  795. - list_for_each_entry_rcu(afi, &net->nft.af_info, list) {
  796. - if (family != NFPROTO_UNSPEC && family != afi->family)
  797. + list_for_each_entry_rcu(table, &net->nft.tables, list) {
  798. + if (family != NFPROTO_UNSPEC && family != table->afi->family)
  799. continue;
  800. - list_for_each_entry_rcu(table, &afi->tables, list) {
  801. - list_for_each_entry_rcu(obj, &table->objects, list) {
  802. - if (!nft_is_active(net, obj))
  803. - goto cont;
  804. - if (idx < s_idx)
  805. - goto cont;
  806. - if (idx > s_idx)
  807. - memset(&cb->args[1], 0,
  808. - sizeof(cb->args) - sizeof(cb->args[0]));
  809. - if (filter && filter->table &&
  810. - strcmp(filter->table, table->name))
  811. - goto cont;
  812. - if (filter &&
  813. - filter->type != NFT_OBJECT_UNSPEC &&
  814. - obj->ops->type->type != filter->type)
  815. - goto cont;
  816. + list_for_each_entry_rcu(obj, &table->objects, list) {
  817. + if (!nft_is_active(net, obj))
  818. + goto cont;
  819. + if (idx < s_idx)
  820. + goto cont;
  821. + if (idx > s_idx)
  822. + memset(&cb->args[1], 0,
  823. + sizeof(cb->args) - sizeof(cb->args[0]));
  824. + if (filter && filter->table &&
  825. + strcmp(filter->table, table->name))
  826. + goto cont;
  827. + if (filter &&
  828. + filter->type != NFT_OBJECT_UNSPEC &&
  829. + obj->ops->type->type != filter->type)
  830. + goto cont;
  831. - if (nf_tables_fill_obj_info(skb, net, NETLINK_CB(cb->skb).portid,
  832. - cb->nlh->nlmsg_seq,
  833. - NFT_MSG_NEWOBJ,
  834. - NLM_F_MULTI | NLM_F_APPEND,
  835. - afi->family, table, obj, reset) < 0)
  836. - goto done;
  837. + if (nf_tables_fill_obj_info(skb, net, NETLINK_CB(cb->skb).portid,
  838. + cb->nlh->nlmsg_seq,
  839. + NFT_MSG_NEWOBJ,
  840. + NLM_F_MULTI | NLM_F_APPEND,
  841. + table->afi->family, table,
  842. + obj, reset) < 0)
  843. + goto done;
  844. - nl_dump_check_consistent(cb, nlmsg_hdr(skb));
  845. + nl_dump_check_consistent(cb, nlmsg_hdr(skb));
  846. cont:
  847. - idx++;
  848. - }
  849. + idx++;
  850. }
  851. }
  852. done:
  853. @@ -4783,7 +4768,8 @@ static int nf_tables_getobj(struct net *
  854. if (IS_ERR(afi))
  855. return PTR_ERR(afi);
  856. - table = nf_tables_table_lookup(afi, nla[NFTA_OBJ_TABLE], genmask);
  857. + table = nf_tables_table_lookup(net, nla[NFTA_OBJ_TABLE], afi->family,
  858. + genmask);
  859. if (IS_ERR(table))
  860. return PTR_ERR(table);
  861. @@ -4843,7 +4829,8 @@ static int nf_tables_delobj(struct net *
  862. if (IS_ERR(afi))
  863. return PTR_ERR(afi);
  864. - table = nf_tables_table_lookup(afi, nla[NFTA_OBJ_TABLE], genmask);
  865. + table = nf_tables_table_lookup(net, nla[NFTA_OBJ_TABLE], afi->family,
  866. + genmask);
  867. if (IS_ERR(table))
  868. return PTR_ERR(table);
  869. @@ -4854,7 +4841,7 @@ static int nf_tables_delobj(struct net *
  870. if (obj->use > 0)
  871. return -EBUSY;
  872. - nft_ctx_init(&ctx, net, skb, nlh, afi, table, NULL, nla);
  873. + nft_ctx_init(&ctx, net, skb, nlh, afi->family, table, NULL, nla);
  874. return nft_delobj(&ctx, obj);
  875. }
  876. @@ -4892,7 +4879,7 @@ static void nf_tables_obj_notify(const s
  877. struct nft_object *obj, int event)
  878. {
  879. nft_obj_notify(ctx->net, ctx->table, obj, ctx->portid, ctx->seq, event,
  880. - ctx->afi->family, ctx->report, GFP_KERNEL);
  881. + ctx->family, ctx->report, GFP_KERNEL);
  882. }
  883. /*
  884. @@ -5082,7 +5069,7 @@ void nft_flow_table_iterate(struct net *
  885. rcu_read_lock();
  886. list_for_each_entry_rcu(afi, &net->nft.af_info, list) {
  887. - list_for_each_entry_rcu(table, &afi->tables, list) {
  888. + list_for_each_entry_rcu(table, &net->nft.tables, list) {
  889. list_for_each_entry_rcu(flowtable, &table->flowtables, list) {
  890. iter(&flowtable->data, data);
  891. }
  892. @@ -5130,7 +5117,8 @@ static int nf_tables_newflowtable(struct
  893. if (IS_ERR(afi))
  894. return PTR_ERR(afi);
  895. - table = nf_tables_table_lookup(afi, nla[NFTA_FLOWTABLE_TABLE], genmask);
  896. + table = nf_tables_table_lookup(net, nla[NFTA_FLOWTABLE_TABLE],
  897. + afi->family, genmask);
  898. if (IS_ERR(table))
  899. return PTR_ERR(table);
  900. @@ -5147,7 +5135,7 @@ static int nf_tables_newflowtable(struct
  901. return 0;
  902. }
  903. - nft_ctx_init(&ctx, net, skb, nlh, afi, table, NULL, nla);
  904. + nft_ctx_init(&ctx, net, skb, nlh, afi->family, table, NULL, nla);
  905. flowtable = kzalloc(sizeof(*flowtable), GFP_KERNEL);
  906. if (!flowtable)
  907. @@ -5228,7 +5216,8 @@ static int nf_tables_delflowtable(struct
  908. if (IS_ERR(afi))
  909. return PTR_ERR(afi);
  910. - table = nf_tables_table_lookup(afi, nla[NFTA_FLOWTABLE_TABLE], genmask);
  911. + table = nf_tables_table_lookup(net, nla[NFTA_FLOWTABLE_TABLE],
  912. + afi->family, genmask);
  913. if (IS_ERR(table))
  914. return PTR_ERR(table);
  915. @@ -5239,7 +5228,7 @@ static int nf_tables_delflowtable(struct
  916. if (flowtable->use > 0)
  917. return -EBUSY;
  918. - nft_ctx_init(&ctx, net, skb, nlh, afi, table, NULL, nla);
  919. + nft_ctx_init(&ctx, net, skb, nlh, afi->family, table, NULL, nla);
  920. return nft_delflowtable(&ctx, flowtable);
  921. }
  922. @@ -5308,40 +5297,37 @@ static int nf_tables_dump_flowtable(stru
  923. struct net *net = sock_net(skb->sk);
  924. int family = nfmsg->nfgen_family;
  925. struct nft_flowtable *flowtable;
  926. - const struct nft_af_info *afi;
  927. const struct nft_table *table;
  928. rcu_read_lock();
  929. cb->seq = net->nft.base_seq;
  930. - list_for_each_entry_rcu(afi, &net->nft.af_info, list) {
  931. - if (family != NFPROTO_UNSPEC && family != afi->family)
  932. + list_for_each_entry_rcu(table, &net->nft.tables, list) {
  933. + if (family != NFPROTO_UNSPEC && family != table->afi->family)
  934. continue;
  935. - list_for_each_entry_rcu(table, &afi->tables, list) {
  936. - list_for_each_entry_rcu(flowtable, &table->flowtables, list) {
  937. - if (!nft_is_active(net, flowtable))
  938. - goto cont;
  939. - if (idx < s_idx)
  940. - goto cont;
  941. - if (idx > s_idx)
  942. - memset(&cb->args[1], 0,
  943. - sizeof(cb->args) - sizeof(cb->args[0]));
  944. - if (filter && filter->table[0] &&
  945. - strcmp(filter->table, table->name))
  946. - goto cont;
  947. + list_for_each_entry_rcu(flowtable, &table->flowtables, list) {
  948. + if (!nft_is_active(net, flowtable))
  949. + goto cont;
  950. + if (idx < s_idx)
  951. + goto cont;
  952. + if (idx > s_idx)
  953. + memset(&cb->args[1], 0,
  954. + sizeof(cb->args) - sizeof(cb->args[0]));
  955. + if (filter && filter->table &&
  956. + strcmp(filter->table, table->name))
  957. + goto cont;
  958. - if (nf_tables_fill_flowtable_info(skb, net, NETLINK_CB(cb->skb).portid,
  959. - cb->nlh->nlmsg_seq,
  960. - NFT_MSG_NEWFLOWTABLE,
  961. - NLM_F_MULTI | NLM_F_APPEND,
  962. - afi->family, flowtable) < 0)
  963. - goto done;
  964. + if (nf_tables_fill_flowtable_info(skb, net, NETLINK_CB(cb->skb).portid,
  965. + cb->nlh->nlmsg_seq,
  966. + NFT_MSG_NEWFLOWTABLE,
  967. + NLM_F_MULTI | NLM_F_APPEND,
  968. + table->afi->family, flowtable) < 0)
  969. + goto done;
  970. - nl_dump_check_consistent(cb, nlmsg_hdr(skb));
  971. + nl_dump_check_consistent(cb, nlmsg_hdr(skb));
  972. cont:
  973. - idx++;
  974. - }
  975. + idx++;
  976. }
  977. }
  978. done:
  979. @@ -5426,7 +5412,8 @@ static int nf_tables_getflowtable(struct
  980. if (IS_ERR(afi))
  981. return PTR_ERR(afi);
  982. - table = nf_tables_table_lookup(afi, nla[NFTA_FLOWTABLE_TABLE], genmask);
  983. + table = nf_tables_table_lookup(net, nla[NFTA_FLOWTABLE_TABLE],
  984. + afi->family, genmask);
  985. if (IS_ERR(table))
  986. return PTR_ERR(table);
  987. @@ -5469,7 +5456,7 @@ static void nf_tables_flowtable_notify(s
  988. err = nf_tables_fill_flowtable_info(skb, ctx->net, ctx->portid,
  989. ctx->seq, event, 0,
  990. - ctx->afi->family, flowtable);
  991. + ctx->family, flowtable);
  992. if (err < 0) {
  993. kfree_skb(skb);
  994. goto err;
  995. @@ -5547,17 +5534,14 @@ static int nf_tables_flowtable_event(str
  996. struct net_device *dev = netdev_notifier_info_to_dev(ptr);
  997. struct nft_flowtable *flowtable;
  998. struct nft_table *table;
  999. - struct nft_af_info *afi;
  1000. if (event != NETDEV_UNREGISTER)
  1001. return 0;
  1002. nfnl_lock(NFNL_SUBSYS_NFTABLES);
  1003. - list_for_each_entry(afi, &dev_net(dev)->nft.af_info, list) {
  1004. - list_for_each_entry(table, &afi->tables, list) {
  1005. - list_for_each_entry(flowtable, &table->flowtables, list) {
  1006. - nft_flowtable_event(event, dev, flowtable);
  1007. - }
  1008. + list_for_each_entry(table, &dev_net(dev)->nft.tables, list) {
  1009. + list_for_each_entry(flowtable, &table->flowtables, list) {
  1010. + nft_flowtable_event(event, dev, flowtable);
  1011. }
  1012. }
  1013. nfnl_unlock(NFNL_SUBSYS_NFTABLES);
  1014. @@ -6583,6 +6567,7 @@ EXPORT_SYMBOL_GPL(nft_data_dump);
  1015. static int __net_init nf_tables_init_net(struct net *net)
  1016. {
  1017. INIT_LIST_HEAD(&net->nft.af_info);
  1018. + INIT_LIST_HEAD(&net->nft.tables);
  1019. INIT_LIST_HEAD(&net->nft.commit_list);
  1020. net->nft.base_seq = 1;
  1021. return 0;
  1022. @@ -6619,10 +6604,10 @@ static void __nft_release_afinfo(struct
  1023. struct nft_set *set, *ns;
  1024. struct nft_ctx ctx = {
  1025. .net = net,
  1026. - .afi = afi,
  1027. + .family = afi->family,
  1028. };
  1029. - list_for_each_entry_safe(table, nt, &afi->tables, list) {
  1030. + list_for_each_entry_safe(table, nt, &net->nft.tables, list) {
  1031. list_for_each_entry(chain, &table->chains, list)
  1032. nf_tables_unregister_hook(net, table, chain);
  1033. list_for_each_entry(flowtable, &table->flowtables, list)
  1034. --- a/net/netfilter/nf_tables_netdev.c
  1035. +++ b/net/netfilter/nf_tables_netdev.c
  1036. @@ -107,7 +107,6 @@ static int nf_tables_netdev_event(struct
  1037. unsigned long event, void *ptr)
  1038. {
  1039. struct net_device *dev = netdev_notifier_info_to_dev(ptr);
  1040. - struct nft_af_info *afi;
  1041. struct nft_table *table;
  1042. struct nft_chain *chain, *nr;
  1043. struct nft_ctx ctx = {
  1044. @@ -119,20 +118,18 @@ static int nf_tables_netdev_event(struct
  1045. return NOTIFY_DONE;
  1046. nfnl_lock(NFNL_SUBSYS_NFTABLES);
  1047. - list_for_each_entry(afi, &dev_net(dev)->nft.af_info, list) {
  1048. - ctx.afi = afi;
  1049. - if (afi->family != NFPROTO_NETDEV)
  1050. + list_for_each_entry(table, &ctx.net->nft.tables, list) {
  1051. + if (table->afi->family != NFPROTO_NETDEV)
  1052. continue;
  1053. - list_for_each_entry(table, &afi->tables, list) {
  1054. - ctx.table = table;
  1055. - list_for_each_entry_safe(chain, nr, &table->chains, list) {
  1056. - if (!nft_is_base_chain(chain))
  1057. - continue;
  1058. + ctx.family = table->afi->family;
  1059. + ctx.table = table;
  1060. + list_for_each_entry_safe(chain, nr, &table->chains, list) {
  1061. + if (!nft_is_base_chain(chain))
  1062. + continue;
  1063. - ctx.chain = chain;
  1064. - nft_netdev_event(event, dev, &ctx);
  1065. - }
  1066. + ctx.chain = chain;
  1067. + nft_netdev_event(event, dev, &ctx);
  1068. }
  1069. }
  1070. nfnl_unlock(NFNL_SUBSYS_NFTABLES);
  1071. --- a/net/netfilter/nft_compat.c
  1072. +++ b/net/netfilter/nft_compat.c
  1073. @@ -161,7 +161,7 @@ nft_target_set_tgchk_param(struct xt_tgc
  1074. {
  1075. par->net = ctx->net;
  1076. par->table = ctx->table->name;
  1077. - switch (ctx->afi->family) {
  1078. + switch (ctx->family) {
  1079. case AF_INET:
  1080. entry->e4.ip.proto = proto;
  1081. entry->e4.ip.invflags = inv ? IPT_INV_PROTO : 0;
  1082. @@ -192,7 +192,7 @@ nft_target_set_tgchk_param(struct xt_tgc
  1083. } else {
  1084. par->hook_mask = 0;
  1085. }
  1086. - par->family = ctx->afi->family;
  1087. + par->family = ctx->family;
  1088. par->nft_compat = true;
  1089. }
  1090. @@ -283,7 +283,7 @@ nft_target_destroy(const struct nft_ctx
  1091. par.net = ctx->net;
  1092. par.target = target;
  1093. par.targinfo = info;
  1094. - par.family = ctx->afi->family;
  1095. + par.family = ctx->family;
  1096. if (par.target->destroy != NULL)
  1097. par.target->destroy(&par);
  1098. @@ -409,7 +409,7 @@ nft_match_set_mtchk_param(struct xt_mtch
  1099. {
  1100. par->net = ctx->net;
  1101. par->table = ctx->table->name;
  1102. - switch (ctx->afi->family) {
  1103. + switch (ctx->family) {
  1104. case AF_INET:
  1105. entry->e4.ip.proto = proto;
  1106. entry->e4.ip.invflags = inv ? IPT_INV_PROTO : 0;
  1107. @@ -440,7 +440,7 @@ nft_match_set_mtchk_param(struct xt_mtch
  1108. } else {
  1109. par->hook_mask = 0;
  1110. }
  1111. - par->family = ctx->afi->family;
  1112. + par->family = ctx->family;
  1113. par->nft_compat = true;
  1114. }
  1115. @@ -523,7 +523,7 @@ __nft_match_destroy(const struct nft_ctx
  1116. par.net = ctx->net;
  1117. par.match = match;
  1118. par.matchinfo = info;
  1119. - par.family = ctx->afi->family;
  1120. + par.family = ctx->family;
  1121. if (par.match->destroy != NULL)
  1122. par.match->destroy(&par);
  1123. @@ -754,7 +754,7 @@ nft_match_select_ops(const struct nft_ct
  1124. mt_name = nla_data(tb[NFTA_MATCH_NAME]);
  1125. rev = ntohl(nla_get_be32(tb[NFTA_MATCH_REV]));
  1126. - family = ctx->afi->family;
  1127. + family = ctx->family;
  1128. /* Re-use the existing match if it's already loaded. */
  1129. list_for_each_entry(nft_match, &nft_match_list, head) {
  1130. @@ -845,7 +845,7 @@ nft_target_select_ops(const struct nft_c
  1131. tg_name = nla_data(tb[NFTA_TARGET_NAME]);
  1132. rev = ntohl(nla_get_be32(tb[NFTA_TARGET_REV]));
  1133. - family = ctx->afi->family;
  1134. + family = ctx->family;
  1135. if (strcmp(tg_name, XT_ERROR_TARGET) == 0 ||
  1136. strcmp(tg_name, XT_STANDARD_TARGET) == 0 ||
  1137. --- a/net/netfilter/nft_ct.c
  1138. +++ b/net/netfilter/nft_ct.c
  1139. @@ -405,7 +405,7 @@ static int nft_ct_get_init(const struct
  1140. if (tb[NFTA_CT_DIRECTION] == NULL)
  1141. return -EINVAL;
  1142. - switch (ctx->afi->family) {
  1143. + switch (ctx->family) {
  1144. case NFPROTO_IPV4:
  1145. len = FIELD_SIZEOF(struct nf_conntrack_tuple,
  1146. src.u3.ip);
  1147. @@ -456,7 +456,7 @@ static int nft_ct_get_init(const struct
  1148. if (err < 0)
  1149. return err;
  1150. - err = nf_ct_netns_get(ctx->net, ctx->afi->family);
  1151. + err = nf_ct_netns_get(ctx->net, ctx->family);
  1152. if (err < 0)
  1153. return err;
  1154. @@ -550,7 +550,7 @@ static int nft_ct_set_init(const struct
  1155. if (err < 0)
  1156. goto err1;
  1157. - err = nf_ct_netns_get(ctx->net, ctx->afi->family);
  1158. + err = nf_ct_netns_get(ctx->net, ctx->family);
  1159. if (err < 0)
  1160. goto err1;
  1161. @@ -564,7 +564,7 @@ err1:
  1162. static void nft_ct_get_destroy(const struct nft_ctx *ctx,
  1163. const struct nft_expr *expr)
  1164. {
  1165. - nf_ct_netns_put(ctx->net, ctx->afi->family);
  1166. + nf_ct_netns_put(ctx->net, ctx->family);
  1167. }
  1168. static void nft_ct_set_destroy(const struct nft_ctx *ctx,
  1169. @@ -573,7 +573,7 @@ static void nft_ct_set_destroy(const str
  1170. struct nft_ct *priv = nft_expr_priv(expr);
  1171. __nft_ct_set_destroy(ctx, priv);
  1172. - nf_ct_netns_put(ctx->net, ctx->afi->family);
  1173. + nf_ct_netns_put(ctx->net, ctx->family);
  1174. }
  1175. static int nft_ct_get_dump(struct sk_buff *skb, const struct nft_expr *expr)
  1176. @@ -734,7 +734,7 @@ static int nft_ct_helper_obj_init(const
  1177. struct nft_ct_helper_obj *priv = nft_obj_data(obj);
  1178. struct nf_conntrack_helper *help4, *help6;
  1179. char name[NF_CT_HELPER_NAME_LEN];
  1180. - int family = ctx->afi->family;
  1181. + int family = ctx->family;
  1182. if (!tb[NFTA_CT_HELPER_NAME] || !tb[NFTA_CT_HELPER_L4PROTO])
  1183. return -EINVAL;
  1184. @@ -753,14 +753,14 @@ static int nft_ct_helper_obj_init(const
  1185. switch (family) {
  1186. case NFPROTO_IPV4:
  1187. - if (ctx->afi->family == NFPROTO_IPV6)
  1188. + if (ctx->family == NFPROTO_IPV6)
  1189. return -EINVAL;
  1190. help4 = nf_conntrack_helper_try_module_get(name, family,
  1191. priv->l4proto);
  1192. break;
  1193. case NFPROTO_IPV6:
  1194. - if (ctx->afi->family == NFPROTO_IPV4)
  1195. + if (ctx->family == NFPROTO_IPV4)
  1196. return -EINVAL;
  1197. help6 = nf_conntrack_helper_try_module_get(name, family,
  1198. --- a/net/netfilter/nft_flow_offload.c
  1199. +++ b/net/netfilter/nft_flow_offload.c
  1200. @@ -151,7 +151,7 @@ static int nft_flow_offload_init(const s
  1201. priv->flowtable = flowtable;
  1202. flowtable->use++;
  1203. - return nf_ct_netns_get(ctx->net, ctx->afi->family);
  1204. + return nf_ct_netns_get(ctx->net, ctx->family);
  1205. }
  1206. static void nft_flow_offload_destroy(const struct nft_ctx *ctx,
  1207. @@ -160,7 +160,7 @@ static void nft_flow_offload_destroy(con
  1208. struct nft_flow_offload *priv = nft_expr_priv(expr);
  1209. priv->flowtable->use--;
  1210. - nf_ct_netns_put(ctx->net, ctx->afi->family);
  1211. + nf_ct_netns_put(ctx->net, ctx->family);
  1212. }
  1213. static int nft_flow_offload_dump(struct sk_buff *skb, const struct nft_expr *expr)
  1214. --- a/net/netfilter/nft_log.c
  1215. +++ b/net/netfilter/nft_log.c
  1216. @@ -112,7 +112,7 @@ static int nft_log_init(const struct nft
  1217. break;
  1218. }
  1219. - err = nf_logger_find_get(ctx->afi->family, li->type);
  1220. + err = nf_logger_find_get(ctx->family, li->type);
  1221. if (err < 0)
  1222. goto err1;
  1223. @@ -133,7 +133,7 @@ static void nft_log_destroy(const struct
  1224. if (priv->prefix != nft_log_null_prefix)
  1225. kfree(priv->prefix);
  1226. - nf_logger_put(ctx->afi->family, li->type);
  1227. + nf_logger_put(ctx->family, li->type);
  1228. }
  1229. static int nft_log_dump(struct sk_buff *skb, const struct nft_expr *expr)
  1230. --- a/net/netfilter/nft_masq.c
  1231. +++ b/net/netfilter/nft_masq.c
  1232. @@ -73,7 +73,7 @@ int nft_masq_init(const struct nft_ctx *
  1233. }
  1234. }
  1235. - return nf_ct_netns_get(ctx->net, ctx->afi->family);
  1236. + return nf_ct_netns_get(ctx->net, ctx->family);
  1237. }
  1238. EXPORT_SYMBOL_GPL(nft_masq_init);
  1239. --- a/net/netfilter/nft_meta.c
  1240. +++ b/net/netfilter/nft_meta.c
  1241. @@ -341,7 +341,7 @@ static int nft_meta_get_validate(const s
  1242. if (priv->key != NFT_META_SECPATH)
  1243. return 0;
  1244. - switch (ctx->afi->family) {
  1245. + switch (ctx->family) {
  1246. case NFPROTO_NETDEV:
  1247. hooks = 1 << NF_NETDEV_INGRESS;
  1248. break;
  1249. @@ -372,7 +372,7 @@ int nft_meta_set_validate(const struct n
  1250. if (priv->key != NFT_META_PKTTYPE)
  1251. return 0;
  1252. - switch (ctx->afi->family) {
  1253. + switch (ctx->family) {
  1254. case NFPROTO_BRIDGE:
  1255. hooks = 1 << NF_BR_PRE_ROUTING;
  1256. break;
  1257. --- a/net/netfilter/nft_nat.c
  1258. +++ b/net/netfilter/nft_nat.c
  1259. @@ -142,7 +142,7 @@ static int nft_nat_init(const struct nft
  1260. return -EINVAL;
  1261. family = ntohl(nla_get_be32(tb[NFTA_NAT_FAMILY]));
  1262. - if (family != ctx->afi->family)
  1263. + if (family != ctx->family)
  1264. return -EOPNOTSUPP;
  1265. switch (family) {
  1266. --- a/net/netfilter/nft_redir.c
  1267. +++ b/net/netfilter/nft_redir.c
  1268. @@ -75,7 +75,7 @@ int nft_redir_init(const struct nft_ctx
  1269. return -EINVAL;
  1270. }
  1271. - return nf_ct_netns_get(ctx->net, ctx->afi->family);
  1272. + return nf_ct_netns_get(ctx->net, ctx->family);
  1273. }
  1274. EXPORT_SYMBOL_GPL(nft_redir_init);