359-v4.18-netfilter-nf_flow_table-track-flow-tables-in-nf_flow.patch 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. From: Felix Fietkau <nbd@nbd.name>
  2. Date: Tue, 20 Feb 2018 14:08:14 +0100
  3. Subject: [PATCH] netfilter: nf_flow_table: track flow tables in nf_flow_table
  4. directly
  5. Avoids having nf_flow_table depend on nftables (useful for future
  6. iptables backport work)
  7. Signed-off-by: Felix Fietkau <nbd@nbd.name>
  8. ---
  9. --- a/include/net/netfilter/nf_flow_table.h
  10. +++ b/include/net/netfilter/nf_flow_table.h
  11. @@ -21,6 +21,7 @@ struct nf_flowtable_type {
  12. };
  13. struct nf_flowtable {
  14. + struct list_head list;
  15. struct rhashtable rhashtable;
  16. const struct nf_flowtable_type *type;
  17. struct delayed_work gc_work;
  18. --- a/include/net/netfilter/nf_tables.h
  19. +++ b/include/net/netfilter/nf_tables.h
  20. @@ -1099,9 +1099,6 @@ struct nft_flowtable {
  21. struct nft_flowtable *nf_tables_flowtable_lookup(const struct nft_table *table,
  22. const struct nlattr *nla,
  23. u8 genmask);
  24. -void nft_flow_table_iterate(struct net *net,
  25. - void (*iter)(struct nf_flowtable *flowtable, void *data),
  26. - void *data);
  27. void nft_register_flowtable_type(struct nf_flowtable_type *type);
  28. void nft_unregister_flowtable_type(struct nf_flowtable_type *type);
  29. --- a/net/netfilter/nf_flow_table_core.c
  30. +++ b/net/netfilter/nf_flow_table_core.c
  31. @@ -18,6 +18,9 @@ struct flow_offload_entry {
  32. struct rcu_head rcu_head;
  33. };
  34. +static DEFINE_MUTEX(flowtable_lock);
  35. +static LIST_HEAD(flowtables);
  36. +
  37. static void
  38. flow_offload_fill_dir(struct flow_offload *flow, struct nf_conn *ct,
  39. struct nf_flow_route *route,
  40. @@ -410,6 +413,10 @@ int nf_flow_table_init(struct nf_flowtab
  41. queue_delayed_work(system_power_efficient_wq,
  42. &flowtable->gc_work, HZ);
  43. + mutex_lock(&flowtable_lock);
  44. + list_add(&flowtable->list, &flowtables);
  45. + mutex_unlock(&flowtable_lock);
  46. +
  47. return 0;
  48. }
  49. EXPORT_SYMBOL_GPL(nf_flow_table_init);
  50. @@ -425,20 +432,28 @@ static void nf_flow_table_do_cleanup(str
  51. }
  52. static void nf_flow_table_iterate_cleanup(struct nf_flowtable *flowtable,
  53. - void *data)
  54. + struct net_device *dev)
  55. {
  56. - nf_flow_table_iterate(flowtable, nf_flow_table_do_cleanup, data);
  57. + nf_flow_table_iterate(flowtable, nf_flow_table_do_cleanup, dev);
  58. flush_delayed_work(&flowtable->gc_work);
  59. }
  60. void nf_flow_table_cleanup(struct net *net, struct net_device *dev)
  61. {
  62. - nft_flow_table_iterate(net, nf_flow_table_iterate_cleanup, dev);
  63. + struct nf_flowtable *flowtable;
  64. +
  65. + mutex_lock(&flowtable_lock);
  66. + list_for_each_entry(flowtable, &flowtables, list)
  67. + nf_flow_table_iterate_cleanup(flowtable, dev);
  68. + mutex_unlock(&flowtable_lock);
  69. }
  70. EXPORT_SYMBOL_GPL(nf_flow_table_cleanup);
  71. void nf_flow_table_free(struct nf_flowtable *flow_table)
  72. {
  73. + mutex_lock(&flowtable_lock);
  74. + list_del(&flow_table->list);
  75. + mutex_unlock(&flowtable_lock);
  76. cancel_delayed_work_sync(&flow_table->gc_work);
  77. nf_flow_table_iterate(flow_table, nf_flow_table_do_cleanup, NULL);
  78. WARN_ON(!nf_flow_offload_gc_step(flow_table));
  79. --- a/net/netfilter/nf_tables_api.c
  80. +++ b/net/netfilter/nf_tables_api.c
  81. @@ -5019,23 +5019,6 @@ static const struct nf_flowtable_type *n
  82. return ERR_PTR(-ENOENT);
  83. }
  84. -void nft_flow_table_iterate(struct net *net,
  85. - void (*iter)(struct nf_flowtable *flowtable, void *data),
  86. - void *data)
  87. -{
  88. - struct nft_flowtable *flowtable;
  89. - const struct nft_table *table;
  90. -
  91. - nfnl_lock(NFNL_SUBSYS_NFTABLES);
  92. - list_for_each_entry(table, &net->nft.tables, list) {
  93. - list_for_each_entry(flowtable, &table->flowtables, list) {
  94. - iter(&flowtable->data, data);
  95. - }
  96. - }
  97. - nfnl_unlock(NFNL_SUBSYS_NFTABLES);
  98. -}
  99. -EXPORT_SYMBOL_GPL(nft_flow_table_iterate);
  100. -
  101. static void nft_unregister_flowtable_net_hooks(struct net *net,
  102. struct nft_flowtable *flowtable)
  103. {