640-netfilter-nf_flow_table-add-hardware-offload-support.patch 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565
  1. From: Pablo Neira Ayuso <pablo@netfilter.org>
  2. Date: Thu, 11 Jan 2018 16:32:00 +0100
  3. Subject: [PATCH] netfilter: nf_flow_table: add hardware offload support
  4. This patch adds the infrastructure to offload flows to hardware, in case
  5. the nic/switch comes with built-in flow tables capabilities.
  6. If the hardware comes with no hardware flow tables or they have
  7. limitations in terms of features, the existing infrastructure falls back
  8. to the software flow table implementation.
  9. The software flow table garbage collector skips entries that resides in
  10. the hardware, so the hardware will be responsible for releasing this
  11. flow table entry too via flow_offload_dead().
  12. Hardware configuration, either to add or to delete entries, is done from
  13. the hardware offload workqueue, to ensure this is done from user context
  14. given that we may sleep when grabbing the mdio mutex.
  15. Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
  16. ---
  17. create mode 100644 net/netfilter/nf_flow_table_hw.c
  18. --- a/include/linux/netdevice.h
  19. +++ b/include/linux/netdevice.h
  20. @@ -826,6 +826,13 @@ struct xfrmdev_ops {
  21. };
  22. #endif
  23. +struct flow_offload;
  24. +
  25. +enum flow_offload_type {
  26. + FLOW_OFFLOAD_ADD = 0,
  27. + FLOW_OFFLOAD_DEL,
  28. +};
  29. +
  30. /*
  31. * This structure defines the management hooks for network devices.
  32. * The following hooks can be defined; unless noted otherwise, they are
  33. @@ -1057,6 +1064,10 @@ struct xfrmdev_ops {
  34. * int (*ndo_bridge_dellink)(struct net_device *dev, struct nlmsghdr *nlh,
  35. * u16 flags);
  36. *
  37. + * int (*ndo_flow_offload)(enum flow_offload_type type,
  38. + * struct flow_offload *flow);
  39. + * Adds/deletes flow entry to/from net device flowtable.
  40. + *
  41. * int (*ndo_change_carrier)(struct net_device *dev, bool new_carrier);
  42. * Called to change device carrier. Soft-devices (like dummy, team, etc)
  43. * which do not represent real hardware may define this to allow their
  44. @@ -1281,6 +1292,8 @@ struct net_device_ops {
  45. int (*ndo_bridge_dellink)(struct net_device *dev,
  46. struct nlmsghdr *nlh,
  47. u16 flags);
  48. + int (*ndo_flow_offload)(enum flow_offload_type type,
  49. + struct flow_offload *flow);
  50. int (*ndo_change_carrier)(struct net_device *dev,
  51. bool new_carrier);
  52. int (*ndo_get_phys_port_id)(struct net_device *dev,
  53. --- a/include/net/netfilter/nf_flow_table.h
  54. +++ b/include/net/netfilter/nf_flow_table.h
  55. @@ -20,11 +20,17 @@ struct nf_flowtable_type {
  56. struct module *owner;
  57. };
  58. +enum nf_flowtable_flags {
  59. + NF_FLOWTABLE_F_HW = 0x1,
  60. +};
  61. +
  62. struct nf_flowtable {
  63. struct list_head list;
  64. struct rhashtable rhashtable;
  65. const struct nf_flowtable_type *type;
  66. + u32 flags;
  67. struct delayed_work gc_work;
  68. + possible_net_t ft_net;
  69. };
  70. enum flow_offload_tuple_dir {
  71. @@ -69,6 +75,7 @@ struct flow_offload_tuple_rhash {
  72. #define FLOW_OFFLOAD_DNAT 0x2
  73. #define FLOW_OFFLOAD_DYING 0x4
  74. #define FLOW_OFFLOAD_TEARDOWN 0x8
  75. +#define FLOW_OFFLOAD_HW 0x10
  76. struct flow_offload {
  77. struct flow_offload_tuple_rhash tuplehash[FLOW_OFFLOAD_DIR_MAX];
  78. @@ -125,6 +132,22 @@ unsigned int nf_flow_offload_ip_hook(voi
  79. unsigned int nf_flow_offload_ipv6_hook(void *priv, struct sk_buff *skb,
  80. const struct nf_hook_state *state);
  81. +void nf_flow_offload_hw_add(struct net *net, struct flow_offload *flow,
  82. + struct nf_conn *ct);
  83. +void nf_flow_offload_hw_del(struct net *net, struct flow_offload *flow);
  84. +
  85. +struct nf_flow_table_hw {
  86. + struct module *owner;
  87. + void (*add)(struct net *net, struct flow_offload *flow,
  88. + struct nf_conn *ct);
  89. + void (*del)(struct net *net, struct flow_offload *flow);
  90. +};
  91. +
  92. +int nf_flow_table_hw_register(const struct nf_flow_table_hw *offload);
  93. +void nf_flow_table_hw_unregister(const struct nf_flow_table_hw *offload);
  94. +
  95. +extern struct work_struct nf_flow_offload_hw_work;
  96. +
  97. #define MODULE_ALIAS_NF_FLOWTABLE(family) \
  98. MODULE_ALIAS("nf-flowtable-" __stringify(family))
  99. --- a/include/uapi/linux/netfilter/nf_tables.h
  100. +++ b/include/uapi/linux/netfilter/nf_tables.h
  101. @@ -1341,6 +1341,7 @@ enum nft_object_attributes {
  102. * @NFTA_FLOWTABLE_HOOK: netfilter hook configuration(NLA_U32)
  103. * @NFTA_FLOWTABLE_USE: number of references to this flow table (NLA_U32)
  104. * @NFTA_FLOWTABLE_HANDLE: object handle (NLA_U64)
  105. + * @NFTA_FLOWTABLE_FLAGS: flags (NLA_U32)
  106. */
  107. enum nft_flowtable_attributes {
  108. NFTA_FLOWTABLE_UNSPEC,
  109. @@ -1350,6 +1351,7 @@ enum nft_flowtable_attributes {
  110. NFTA_FLOWTABLE_USE,
  111. NFTA_FLOWTABLE_HANDLE,
  112. NFTA_FLOWTABLE_PAD,
  113. + NFTA_FLOWTABLE_FLAGS,
  114. __NFTA_FLOWTABLE_MAX
  115. };
  116. #define NFTA_FLOWTABLE_MAX (__NFTA_FLOWTABLE_MAX - 1)
  117. --- a/net/netfilter/Kconfig
  118. +++ b/net/netfilter/Kconfig
  119. @@ -692,6 +692,15 @@ config NF_FLOW_TABLE
  120. To compile it as a module, choose M here.
  121. +config NF_FLOW_TABLE_HW
  122. + tristate "Netfilter flow table hardware offload module"
  123. + depends on NF_FLOW_TABLE
  124. + help
  125. + This option adds hardware offload support for the flow table core
  126. + infrastructure.
  127. +
  128. + To compile it as a module, choose M here.
  129. +
  130. config NETFILTER_XTABLES
  131. tristate "Netfilter Xtables support (required for ip_tables)"
  132. default m if NETFILTER_ADVANCED=n
  133. --- a/net/netfilter/Makefile
  134. +++ b/net/netfilter/Makefile
  135. @@ -116,6 +116,7 @@ obj-$(CONFIG_NF_FLOW_TABLE) += nf_flow_t
  136. nf_flow_table-objs := nf_flow_table_core.o nf_flow_table_ip.o
  137. obj-$(CONFIG_NF_FLOW_TABLE_INET) += nf_flow_table_inet.o
  138. +obj-$(CONFIG_NF_FLOW_TABLE_HW) += nf_flow_table_hw.o
  139. # generic X tables
  140. obj-$(CONFIG_NETFILTER_XTABLES) += x_tables.o xt_tcpudp.o
  141. --- a/net/netfilter/nf_flow_table_core.c
  142. +++ b/net/netfilter/nf_flow_table_core.c
  143. @@ -219,10 +219,16 @@ int flow_offload_add(struct nf_flowtable
  144. }
  145. EXPORT_SYMBOL_GPL(flow_offload_add);
  146. +static inline bool nf_flow_in_hw(const struct flow_offload *flow)
  147. +{
  148. + return flow->flags & FLOW_OFFLOAD_HW;
  149. +}
  150. +
  151. static void flow_offload_del(struct nf_flowtable *flow_table,
  152. struct flow_offload *flow)
  153. {
  154. struct flow_offload_entry *e;
  155. + struct net *net = read_pnet(&flow_table->ft_net);
  156. rhashtable_remove_fast(&flow_table->rhashtable,
  157. &flow->tuplehash[FLOW_OFFLOAD_DIR_ORIGINAL].node,
  158. @@ -237,6 +243,9 @@ static void flow_offload_del(struct nf_f
  159. if (!(flow->flags & FLOW_OFFLOAD_TEARDOWN))
  160. flow_offload_fixup_ct_state(e->ct);
  161. + if (nf_flow_in_hw(flow))
  162. + nf_flow_offload_hw_del(net, flow);
  163. +
  164. flow_offload_free(flow);
  165. }
  166. @@ -350,6 +359,9 @@ static int nf_flow_offload_gc_step(struc
  167. if (!teardown)
  168. nf_ct_offload_timeout(flow);
  169. + if (nf_flow_in_hw(flow) && !teardown)
  170. + continue;
  171. +
  172. if (nf_flow_has_expired(flow) || teardown)
  173. flow_offload_del(flow_table, flow);
  174. }
  175. @@ -485,10 +497,43 @@ int nf_flow_dnat_port(const struct flow_
  176. }
  177. EXPORT_SYMBOL_GPL(nf_flow_dnat_port);
  178. +static const struct nf_flow_table_hw __rcu *nf_flow_table_hw_hook __read_mostly;
  179. +
  180. +static int nf_flow_offload_hw_init(struct nf_flowtable *flow_table)
  181. +{
  182. + const struct nf_flow_table_hw *offload;
  183. +
  184. + if (!rcu_access_pointer(nf_flow_table_hw_hook))
  185. + request_module("nf-flow-table-hw");
  186. +
  187. + rcu_read_lock();
  188. + offload = rcu_dereference(nf_flow_table_hw_hook);
  189. + if (!offload)
  190. + goto err_no_hw_offload;
  191. +
  192. + if (!try_module_get(offload->owner))
  193. + goto err_no_hw_offload;
  194. +
  195. + rcu_read_unlock();
  196. +
  197. + return 0;
  198. +
  199. +err_no_hw_offload:
  200. + rcu_read_unlock();
  201. +
  202. + return -EOPNOTSUPP;
  203. +}
  204. +
  205. int nf_flow_table_init(struct nf_flowtable *flowtable)
  206. {
  207. int err;
  208. + if (flowtable->flags & NF_FLOWTABLE_F_HW) {
  209. + err = nf_flow_offload_hw_init(flowtable);
  210. + if (err)
  211. + return err;
  212. + }
  213. +
  214. INIT_DEFERRABLE_WORK(&flowtable->gc_work, nf_flow_offload_work_gc);
  215. err = rhashtable_init(&flowtable->rhashtable,
  216. @@ -526,6 +571,8 @@ static void nf_flow_table_iterate_cleanu
  217. {
  218. nf_flow_table_iterate(flowtable, nf_flow_table_do_cleanup, dev);
  219. flush_delayed_work(&flowtable->gc_work);
  220. + if (flowtable->flags & NF_FLOWTABLE_F_HW)
  221. + flush_work(&nf_flow_offload_hw_work);
  222. }
  223. void nf_flow_table_cleanup(struct net *net, struct net_device *dev)
  224. @@ -539,6 +586,26 @@ void nf_flow_table_cleanup(struct net *n
  225. }
  226. EXPORT_SYMBOL_GPL(nf_flow_table_cleanup);
  227. +struct work_struct nf_flow_offload_hw_work;
  228. +EXPORT_SYMBOL_GPL(nf_flow_offload_hw_work);
  229. +
  230. +/* Give the hardware workqueue the chance to remove entries from hardware.*/
  231. +static void nf_flow_offload_hw_free(struct nf_flowtable *flowtable)
  232. +{
  233. + const struct nf_flow_table_hw *offload;
  234. +
  235. + flush_work(&nf_flow_offload_hw_work);
  236. +
  237. + rcu_read_lock();
  238. + offload = rcu_dereference(nf_flow_table_hw_hook);
  239. + if (!offload) {
  240. + rcu_read_unlock();
  241. + return;
  242. + }
  243. + module_put(offload->owner);
  244. + rcu_read_unlock();
  245. +}
  246. +
  247. void nf_flow_table_free(struct nf_flowtable *flow_table)
  248. {
  249. mutex_lock(&flowtable_lock);
  250. @@ -548,9 +615,58 @@ void nf_flow_table_free(struct nf_flowta
  251. nf_flow_table_iterate(flow_table, nf_flow_table_do_cleanup, NULL);
  252. WARN_ON(!nf_flow_offload_gc_step(flow_table));
  253. rhashtable_destroy(&flow_table->rhashtable);
  254. + if (flow_table->flags & NF_FLOWTABLE_F_HW)
  255. + nf_flow_offload_hw_free(flow_table);
  256. }
  257. EXPORT_SYMBOL_GPL(nf_flow_table_free);
  258. +/* Must be called from user context. */
  259. +void nf_flow_offload_hw_add(struct net *net, struct flow_offload *flow,
  260. + struct nf_conn *ct)
  261. +{
  262. + const struct nf_flow_table_hw *offload;
  263. +
  264. + rcu_read_lock();
  265. + offload = rcu_dereference(nf_flow_table_hw_hook);
  266. + if (offload)
  267. + offload->add(net, flow, ct);
  268. + rcu_read_unlock();
  269. +}
  270. +EXPORT_SYMBOL_GPL(nf_flow_offload_hw_add);
  271. +
  272. +/* Must be called from user context. */
  273. +void nf_flow_offload_hw_del(struct net *net, struct flow_offload *flow)
  274. +{
  275. + const struct nf_flow_table_hw *offload;
  276. +
  277. + rcu_read_lock();
  278. + offload = rcu_dereference(nf_flow_table_hw_hook);
  279. + if (offload)
  280. + offload->del(net, flow);
  281. + rcu_read_unlock();
  282. +}
  283. +EXPORT_SYMBOL_GPL(nf_flow_offload_hw_del);
  284. +
  285. +int nf_flow_table_hw_register(const struct nf_flow_table_hw *offload)
  286. +{
  287. + if (rcu_access_pointer(nf_flow_table_hw_hook))
  288. + return -EBUSY;
  289. +
  290. + rcu_assign_pointer(nf_flow_table_hw_hook, offload);
  291. +
  292. + return 0;
  293. +}
  294. +EXPORT_SYMBOL_GPL(nf_flow_table_hw_register);
  295. +
  296. +void nf_flow_table_hw_unregister(const struct nf_flow_table_hw *offload)
  297. +{
  298. + WARN_ON(rcu_access_pointer(nf_flow_table_hw_hook) != offload);
  299. + rcu_assign_pointer(nf_flow_table_hw_hook, NULL);
  300. +
  301. + synchronize_rcu();
  302. +}
  303. +EXPORT_SYMBOL_GPL(nf_flow_table_hw_unregister);
  304. +
  305. static int nf_flow_table_netdev_event(struct notifier_block *this,
  306. unsigned long event, void *ptr)
  307. {
  308. --- /dev/null
  309. +++ b/net/netfilter/nf_flow_table_hw.c
  310. @@ -0,0 +1,169 @@
  311. +#include <linux/kernel.h>
  312. +#include <linux/init.h>
  313. +#include <linux/module.h>
  314. +#include <linux/netfilter.h>
  315. +#include <linux/rhashtable.h>
  316. +#include <linux/netdevice.h>
  317. +#include <net/netfilter/nf_flow_table.h>
  318. +#include <net/netfilter/nf_conntrack.h>
  319. +#include <net/netfilter/nf_conntrack_core.h>
  320. +#include <net/netfilter/nf_conntrack_tuple.h>
  321. +
  322. +static DEFINE_SPINLOCK(flow_offload_hw_pending_list_lock);
  323. +static LIST_HEAD(flow_offload_hw_pending_list);
  324. +
  325. +static DEFINE_MUTEX(nf_flow_offload_hw_mutex);
  326. +
  327. +struct flow_offload_hw {
  328. + struct list_head list;
  329. + enum flow_offload_type type;
  330. + struct flow_offload *flow;
  331. + struct nf_conn *ct;
  332. + possible_net_t flow_hw_net;
  333. +};
  334. +
  335. +static int do_flow_offload_hw(struct net *net, struct flow_offload *flow,
  336. + int type)
  337. +{
  338. + struct net_device *indev;
  339. + int ret, ifindex;
  340. +
  341. + ifindex = flow->tuplehash[FLOW_OFFLOAD_DIR_ORIGINAL].tuple.iifidx;
  342. + indev = dev_get_by_index(net, ifindex);
  343. + if (WARN_ON(!indev))
  344. + return 0;
  345. +
  346. + mutex_lock(&nf_flow_offload_hw_mutex);
  347. + ret = indev->netdev_ops->ndo_flow_offload(type, flow);
  348. + mutex_unlock(&nf_flow_offload_hw_mutex);
  349. +
  350. + dev_put(indev);
  351. +
  352. + return ret;
  353. +}
  354. +
  355. +static void flow_offload_hw_work_add(struct flow_offload_hw *offload)
  356. +{
  357. + struct net *net;
  358. + int ret;
  359. +
  360. + if (nf_ct_is_dying(offload->ct))
  361. + return;
  362. +
  363. + net = read_pnet(&offload->flow_hw_net);
  364. + ret = do_flow_offload_hw(net, offload->flow, FLOW_OFFLOAD_ADD);
  365. + if (ret >= 0)
  366. + offload->flow->flags |= FLOW_OFFLOAD_HW;
  367. +}
  368. +
  369. +static void flow_offload_hw_work_del(struct flow_offload_hw *offload)
  370. +{
  371. + struct net *net = read_pnet(&offload->flow_hw_net);
  372. +
  373. + do_flow_offload_hw(net, offload->flow, FLOW_OFFLOAD_DEL);
  374. +}
  375. +
  376. +static void flow_offload_hw_work(struct work_struct *work)
  377. +{
  378. + struct flow_offload_hw *offload, *next;
  379. + LIST_HEAD(hw_offload_pending);
  380. +
  381. + spin_lock_bh(&flow_offload_hw_pending_list_lock);
  382. + list_replace_init(&flow_offload_hw_pending_list, &hw_offload_pending);
  383. + spin_unlock_bh(&flow_offload_hw_pending_list_lock);
  384. +
  385. + list_for_each_entry_safe(offload, next, &hw_offload_pending, list) {
  386. + switch (offload->type) {
  387. + case FLOW_OFFLOAD_ADD:
  388. + flow_offload_hw_work_add(offload);
  389. + break;
  390. + case FLOW_OFFLOAD_DEL:
  391. + flow_offload_hw_work_del(offload);
  392. + break;
  393. + }
  394. + if (offload->ct)
  395. + nf_conntrack_put(&offload->ct->ct_general);
  396. + list_del(&offload->list);
  397. + kfree(offload);
  398. + }
  399. +}
  400. +
  401. +static void flow_offload_queue_work(struct flow_offload_hw *offload)
  402. +{
  403. + spin_lock_bh(&flow_offload_hw_pending_list_lock);
  404. + list_add_tail(&offload->list, &flow_offload_hw_pending_list);
  405. + spin_unlock_bh(&flow_offload_hw_pending_list_lock);
  406. +
  407. + schedule_work(&nf_flow_offload_hw_work);
  408. +}
  409. +
  410. +static void flow_offload_hw_add(struct net *net, struct flow_offload *flow,
  411. + struct nf_conn *ct)
  412. +{
  413. + struct flow_offload_hw *offload;
  414. +
  415. + offload = kmalloc(sizeof(struct flow_offload_hw), GFP_ATOMIC);
  416. + if (!offload)
  417. + return;
  418. +
  419. + nf_conntrack_get(&ct->ct_general);
  420. + offload->type = FLOW_OFFLOAD_ADD;
  421. + offload->ct = ct;
  422. + offload->flow = flow;
  423. + write_pnet(&offload->flow_hw_net, net);
  424. +
  425. + flow_offload_queue_work(offload);
  426. +}
  427. +
  428. +static void flow_offload_hw_del(struct net *net, struct flow_offload *flow)
  429. +{
  430. + struct flow_offload_hw *offload;
  431. +
  432. + offload = kmalloc(sizeof(struct flow_offload_hw), GFP_ATOMIC);
  433. + if (!offload)
  434. + return;
  435. +
  436. + offload->type = FLOW_OFFLOAD_DEL;
  437. + offload->ct = NULL;
  438. + offload->flow = flow;
  439. + write_pnet(&offload->flow_hw_net, net);
  440. +
  441. + flow_offload_queue_work(offload);
  442. +}
  443. +
  444. +static const struct nf_flow_table_hw flow_offload_hw = {
  445. + .add = flow_offload_hw_add,
  446. + .del = flow_offload_hw_del,
  447. + .owner = THIS_MODULE,
  448. +};
  449. +
  450. +static int __init nf_flow_table_hw_module_init(void)
  451. +{
  452. + INIT_WORK(&nf_flow_offload_hw_work, flow_offload_hw_work);
  453. + nf_flow_table_hw_register(&flow_offload_hw);
  454. +
  455. + return 0;
  456. +}
  457. +
  458. +static void __exit nf_flow_table_hw_module_exit(void)
  459. +{
  460. + struct flow_offload_hw *offload, *next;
  461. + LIST_HEAD(hw_offload_pending);
  462. +
  463. + nf_flow_table_hw_unregister(&flow_offload_hw);
  464. + cancel_work_sync(&nf_flow_offload_hw_work);
  465. +
  466. + list_for_each_entry_safe(offload, next, &hw_offload_pending, list) {
  467. + if (offload->ct)
  468. + nf_conntrack_put(&offload->ct->ct_general);
  469. + list_del(&offload->list);
  470. + kfree(offload);
  471. + }
  472. +}
  473. +
  474. +module_init(nf_flow_table_hw_module_init);
  475. +module_exit(nf_flow_table_hw_module_exit);
  476. +
  477. +MODULE_LICENSE("GPL");
  478. +MODULE_AUTHOR("Pablo Neira Ayuso <pablo@netfilter.org>");
  479. +MODULE_ALIAS("nf-flow-table-hw");
  480. --- a/net/netfilter/nf_tables_api.c
  481. +++ b/net/netfilter/nf_tables_api.c
  482. @@ -4962,6 +4962,14 @@ static int nf_tables_flowtable_parse_hoo
  483. if (err < 0)
  484. goto err1;
  485. + for (i = 0; i < n; i++) {
  486. + if (flowtable->data.flags & NF_FLOWTABLE_F_HW &&
  487. + !dev_array[i]->netdev_ops->ndo_flow_offload) {
  488. + err = -EOPNOTSUPP;
  489. + goto err1;
  490. + }
  491. + }
  492. +
  493. ops = kzalloc(sizeof(struct nf_hook_ops) * n, GFP_KERNEL);
  494. if (!ops) {
  495. err = -ENOMEM;
  496. @@ -5092,10 +5100,19 @@ static int nf_tables_newflowtable(struct
  497. }
  498. flowtable->data.type = type;
  499. + write_pnet(&flowtable->data.ft_net, net);
  500. +
  501. err = type->init(&flowtable->data);
  502. if (err < 0)
  503. goto err3;
  504. + if (nla[NFTA_FLOWTABLE_FLAGS]) {
  505. + flowtable->data.flags =
  506. + ntohl(nla_get_be32(nla[NFTA_FLOWTABLE_FLAGS]));
  507. + if (flowtable->data.flags & ~NF_FLOWTABLE_F_HW)
  508. + goto err4;
  509. + }
  510. +
  511. err = nf_tables_flowtable_parse_hook(&ctx, nla[NFTA_FLOWTABLE_HOOK],
  512. flowtable);
  513. if (err < 0)
  514. @@ -5193,7 +5210,8 @@ static int nf_tables_fill_flowtable_info
  515. nla_put_string(skb, NFTA_FLOWTABLE_NAME, flowtable->name) ||
  516. nla_put_be32(skb, NFTA_FLOWTABLE_USE, htonl(flowtable->use)) ||
  517. nla_put_be64(skb, NFTA_FLOWTABLE_HANDLE, cpu_to_be64(flowtable->handle),
  518. - NFTA_FLOWTABLE_PAD))
  519. + NFTA_FLOWTABLE_PAD) ||
  520. + nla_put_be32(skb, NFTA_FLOWTABLE_FLAGS, htonl(flowtable->data.flags)))
  521. goto nla_put_failure;
  522. nest = nla_nest_start(skb, NFTA_FLOWTABLE_HOOK);
  523. --- a/net/netfilter/nft_flow_offload.c
  524. +++ b/net/netfilter/nft_flow_offload.c
  525. @@ -110,6 +110,9 @@ static void nft_flow_offload_eval(const
  526. if (ret < 0)
  527. goto err_flow_add;
  528. + if (flowtable->flags & NF_FLOWTABLE_F_HW)
  529. + nf_flow_offload_hw_add(nft_net(pkt), flow, ct);
  530. +
  531. return;
  532. err_flow_add: