flow_offload.h 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744
  1. #ifndef _NET_FLOW_OFFLOAD_H
  2. #define _NET_FLOW_OFFLOAD_H
  3. #include <linux/kernel.h>
  4. #include <linux/list.h>
  5. #include <linux/netlink.h>
  6. #include <net/flow_dissector.h>
  7. struct flow_match {
  8. struct flow_dissector *dissector;
  9. void *mask;
  10. void *key;
  11. };
  12. struct flow_match_meta {
  13. struct flow_dissector_key_meta *key, *mask;
  14. };
  15. struct flow_match_basic {
  16. struct flow_dissector_key_basic *key, *mask;
  17. };
  18. struct flow_match_control {
  19. struct flow_dissector_key_control *key, *mask;
  20. };
  21. struct flow_match_eth_addrs {
  22. struct flow_dissector_key_eth_addrs *key, *mask;
  23. };
  24. struct flow_match_vlan {
  25. struct flow_dissector_key_vlan *key, *mask;
  26. };
  27. struct flow_match_arp {
  28. struct flow_dissector_key_arp *key, *mask;
  29. };
  30. struct flow_match_ipv4_addrs {
  31. struct flow_dissector_key_ipv4_addrs *key, *mask;
  32. };
  33. struct flow_match_ipv6_addrs {
  34. struct flow_dissector_key_ipv6_addrs *key, *mask;
  35. };
  36. struct flow_match_ip {
  37. struct flow_dissector_key_ip *key, *mask;
  38. };
  39. struct flow_match_ports {
  40. struct flow_dissector_key_ports *key, *mask;
  41. };
  42. struct flow_match_ports_range {
  43. struct flow_dissector_key_ports_range *key, *mask;
  44. };
  45. struct flow_match_icmp {
  46. struct flow_dissector_key_icmp *key, *mask;
  47. };
  48. struct flow_match_tcp {
  49. struct flow_dissector_key_tcp *key, *mask;
  50. };
  51. struct flow_match_ipsec {
  52. struct flow_dissector_key_ipsec *key, *mask;
  53. };
  54. struct flow_match_mpls {
  55. struct flow_dissector_key_mpls *key, *mask;
  56. };
  57. struct flow_match_enc_keyid {
  58. struct flow_dissector_key_keyid *key, *mask;
  59. };
  60. struct flow_match_enc_opts {
  61. struct flow_dissector_key_enc_opts *key, *mask;
  62. };
  63. struct flow_match_ct {
  64. struct flow_dissector_key_ct *key, *mask;
  65. };
  66. struct flow_match_pppoe {
  67. struct flow_dissector_key_pppoe *key, *mask;
  68. };
  69. struct flow_match_l2tpv3 {
  70. struct flow_dissector_key_l2tpv3 *key, *mask;
  71. };
  72. struct flow_rule;
  73. void flow_rule_match_meta(const struct flow_rule *rule,
  74. struct flow_match_meta *out);
  75. void flow_rule_match_basic(const struct flow_rule *rule,
  76. struct flow_match_basic *out);
  77. void flow_rule_match_control(const struct flow_rule *rule,
  78. struct flow_match_control *out);
  79. void flow_rule_match_eth_addrs(const struct flow_rule *rule,
  80. struct flow_match_eth_addrs *out);
  81. void flow_rule_match_vlan(const struct flow_rule *rule,
  82. struct flow_match_vlan *out);
  83. void flow_rule_match_cvlan(const struct flow_rule *rule,
  84. struct flow_match_vlan *out);
  85. void flow_rule_match_arp(const struct flow_rule *rule,
  86. struct flow_match_arp *out);
  87. void flow_rule_match_ipv4_addrs(const struct flow_rule *rule,
  88. struct flow_match_ipv4_addrs *out);
  89. void flow_rule_match_ipv6_addrs(const struct flow_rule *rule,
  90. struct flow_match_ipv6_addrs *out);
  91. void flow_rule_match_ip(const struct flow_rule *rule,
  92. struct flow_match_ip *out);
  93. void flow_rule_match_ports(const struct flow_rule *rule,
  94. struct flow_match_ports *out);
  95. void flow_rule_match_ports_range(const struct flow_rule *rule,
  96. struct flow_match_ports_range *out);
  97. void flow_rule_match_tcp(const struct flow_rule *rule,
  98. struct flow_match_tcp *out);
  99. void flow_rule_match_ipsec(const struct flow_rule *rule,
  100. struct flow_match_ipsec *out);
  101. void flow_rule_match_icmp(const struct flow_rule *rule,
  102. struct flow_match_icmp *out);
  103. void flow_rule_match_mpls(const struct flow_rule *rule,
  104. struct flow_match_mpls *out);
  105. void flow_rule_match_enc_control(const struct flow_rule *rule,
  106. struct flow_match_control *out);
  107. void flow_rule_match_enc_ipv4_addrs(const struct flow_rule *rule,
  108. struct flow_match_ipv4_addrs *out);
  109. void flow_rule_match_enc_ipv6_addrs(const struct flow_rule *rule,
  110. struct flow_match_ipv6_addrs *out);
  111. void flow_rule_match_enc_ip(const struct flow_rule *rule,
  112. struct flow_match_ip *out);
  113. void flow_rule_match_enc_ports(const struct flow_rule *rule,
  114. struct flow_match_ports *out);
  115. void flow_rule_match_enc_keyid(const struct flow_rule *rule,
  116. struct flow_match_enc_keyid *out);
  117. void flow_rule_match_enc_opts(const struct flow_rule *rule,
  118. struct flow_match_enc_opts *out);
  119. void flow_rule_match_ct(const struct flow_rule *rule,
  120. struct flow_match_ct *out);
  121. void flow_rule_match_pppoe(const struct flow_rule *rule,
  122. struct flow_match_pppoe *out);
  123. void flow_rule_match_l2tpv3(const struct flow_rule *rule,
  124. struct flow_match_l2tpv3 *out);
  125. enum flow_action_id {
  126. FLOW_ACTION_ACCEPT = 0,
  127. FLOW_ACTION_DROP,
  128. FLOW_ACTION_TRAP,
  129. FLOW_ACTION_GOTO,
  130. FLOW_ACTION_REDIRECT,
  131. FLOW_ACTION_MIRRED,
  132. FLOW_ACTION_REDIRECT_INGRESS,
  133. FLOW_ACTION_MIRRED_INGRESS,
  134. FLOW_ACTION_VLAN_PUSH,
  135. FLOW_ACTION_VLAN_POP,
  136. FLOW_ACTION_VLAN_MANGLE,
  137. FLOW_ACTION_TUNNEL_ENCAP,
  138. FLOW_ACTION_TUNNEL_DECAP,
  139. FLOW_ACTION_MANGLE,
  140. FLOW_ACTION_ADD,
  141. FLOW_ACTION_CSUM,
  142. FLOW_ACTION_MARK,
  143. FLOW_ACTION_PTYPE,
  144. FLOW_ACTION_PRIORITY,
  145. FLOW_ACTION_RX_QUEUE_MAPPING,
  146. FLOW_ACTION_WAKE,
  147. FLOW_ACTION_QUEUE,
  148. FLOW_ACTION_SAMPLE,
  149. FLOW_ACTION_POLICE,
  150. FLOW_ACTION_CT,
  151. FLOW_ACTION_CT_METADATA,
  152. FLOW_ACTION_MPLS_PUSH,
  153. FLOW_ACTION_MPLS_POP,
  154. FLOW_ACTION_MPLS_MANGLE,
  155. FLOW_ACTION_GATE,
  156. FLOW_ACTION_PPPOE_PUSH,
  157. FLOW_ACTION_JUMP,
  158. FLOW_ACTION_PIPE,
  159. FLOW_ACTION_VLAN_PUSH_ETH,
  160. FLOW_ACTION_VLAN_POP_ETH,
  161. FLOW_ACTION_CONTINUE,
  162. NUM_FLOW_ACTIONS,
  163. };
  164. /* This is mirroring enum pedit_header_type definition for easy mapping between
  165. * tc pedit action. Legacy TCA_PEDIT_KEY_EX_HDR_TYPE_NETWORK is mapped to
  166. * FLOW_ACT_MANGLE_UNSPEC, which is supported by no driver.
  167. */
  168. enum flow_action_mangle_base {
  169. FLOW_ACT_MANGLE_UNSPEC = 0,
  170. FLOW_ACT_MANGLE_HDR_TYPE_ETH,
  171. FLOW_ACT_MANGLE_HDR_TYPE_IP4,
  172. FLOW_ACT_MANGLE_HDR_TYPE_IP6,
  173. FLOW_ACT_MANGLE_HDR_TYPE_TCP,
  174. FLOW_ACT_MANGLE_HDR_TYPE_UDP,
  175. };
  176. enum flow_action_hw_stats_bit {
  177. FLOW_ACTION_HW_STATS_IMMEDIATE_BIT,
  178. FLOW_ACTION_HW_STATS_DELAYED_BIT,
  179. FLOW_ACTION_HW_STATS_DISABLED_BIT,
  180. FLOW_ACTION_HW_STATS_NUM_BITS
  181. };
  182. enum flow_action_hw_stats {
  183. FLOW_ACTION_HW_STATS_IMMEDIATE =
  184. BIT(FLOW_ACTION_HW_STATS_IMMEDIATE_BIT),
  185. FLOW_ACTION_HW_STATS_DELAYED = BIT(FLOW_ACTION_HW_STATS_DELAYED_BIT),
  186. FLOW_ACTION_HW_STATS_ANY = FLOW_ACTION_HW_STATS_IMMEDIATE |
  187. FLOW_ACTION_HW_STATS_DELAYED,
  188. FLOW_ACTION_HW_STATS_DISABLED =
  189. BIT(FLOW_ACTION_HW_STATS_DISABLED_BIT),
  190. FLOW_ACTION_HW_STATS_DONT_CARE = BIT(FLOW_ACTION_HW_STATS_NUM_BITS) - 1,
  191. };
  192. typedef void (*action_destr)(void *priv);
  193. struct flow_action_cookie {
  194. u32 cookie_len;
  195. u8 cookie[];
  196. };
  197. struct flow_action_cookie *flow_action_cookie_create(void *data,
  198. unsigned int len,
  199. gfp_t gfp);
  200. void flow_action_cookie_destroy(struct flow_action_cookie *cookie);
  201. struct flow_action_entry {
  202. enum flow_action_id id;
  203. u32 hw_index;
  204. unsigned long cookie;
  205. u64 miss_cookie;
  206. enum flow_action_hw_stats hw_stats;
  207. action_destr destructor;
  208. void *destructor_priv;
  209. union {
  210. u32 chain_index; /* FLOW_ACTION_GOTO */
  211. struct net_device *dev; /* FLOW_ACTION_REDIRECT */
  212. struct { /* FLOW_ACTION_VLAN */
  213. u16 vid;
  214. __be16 proto;
  215. u8 prio;
  216. } vlan;
  217. struct { /* FLOW_ACTION_VLAN_PUSH_ETH */
  218. unsigned char dst[ETH_ALEN];
  219. unsigned char src[ETH_ALEN];
  220. } vlan_push_eth;
  221. struct { /* FLOW_ACTION_MANGLE */
  222. /* FLOW_ACTION_ADD */
  223. enum flow_action_mangle_base htype;
  224. u32 offset;
  225. u32 mask;
  226. u32 val;
  227. } mangle;
  228. struct ip_tunnel_info *tunnel; /* FLOW_ACTION_TUNNEL_ENCAP */
  229. u32 csum_flags; /* FLOW_ACTION_CSUM */
  230. u32 mark; /* FLOW_ACTION_MARK */
  231. u16 ptype; /* FLOW_ACTION_PTYPE */
  232. u16 rx_queue; /* FLOW_ACTION_RX_QUEUE_MAPPING */
  233. u32 priority; /* FLOW_ACTION_PRIORITY */
  234. struct { /* FLOW_ACTION_QUEUE */
  235. u32 ctx;
  236. u32 index;
  237. u8 vf;
  238. } queue;
  239. struct { /* FLOW_ACTION_SAMPLE */
  240. struct psample_group *psample_group;
  241. u32 rate;
  242. u32 trunc_size;
  243. bool truncate;
  244. } sample;
  245. struct { /* FLOW_ACTION_POLICE */
  246. u32 burst;
  247. u64 rate_bytes_ps;
  248. u64 peakrate_bytes_ps;
  249. u32 avrate;
  250. u16 overhead;
  251. u64 burst_pkt;
  252. u64 rate_pkt_ps;
  253. u32 mtu;
  254. struct {
  255. enum flow_action_id act_id;
  256. u32 extval;
  257. } exceed, notexceed;
  258. } police;
  259. struct { /* FLOW_ACTION_CT */
  260. int action;
  261. u16 zone;
  262. struct nf_flowtable *flow_table;
  263. } ct;
  264. struct {
  265. unsigned long cookie;
  266. u32 mark;
  267. u32 labels[4];
  268. bool orig_dir;
  269. } ct_metadata;
  270. struct { /* FLOW_ACTION_MPLS_PUSH */
  271. u32 label;
  272. __be16 proto;
  273. u8 tc;
  274. u8 bos;
  275. u8 ttl;
  276. } mpls_push;
  277. struct { /* FLOW_ACTION_MPLS_POP */
  278. __be16 proto;
  279. } mpls_pop;
  280. struct { /* FLOW_ACTION_MPLS_MANGLE */
  281. u32 label;
  282. u8 tc;
  283. u8 bos;
  284. u8 ttl;
  285. } mpls_mangle;
  286. struct {
  287. s32 prio;
  288. u64 basetime;
  289. u64 cycletime;
  290. u64 cycletimeext;
  291. u32 num_entries;
  292. struct action_gate_entry *entries;
  293. } gate;
  294. struct { /* FLOW_ACTION_PPPOE_PUSH */
  295. u16 sid;
  296. } pppoe;
  297. };
  298. struct flow_action_cookie *user_cookie; /* user defined action cookie */
  299. };
  300. struct flow_action {
  301. unsigned int num_entries;
  302. struct flow_action_entry entries[] __counted_by(num_entries);
  303. };
  304. static inline bool flow_action_has_entries(const struct flow_action *action)
  305. {
  306. return action->num_entries;
  307. }
  308. /**
  309. * flow_offload_has_one_action() - check if exactly one action is present
  310. * @action: tc filter flow offload action
  311. *
  312. * Return: true if exactly one action is present.
  313. */
  314. static inline bool flow_offload_has_one_action(const struct flow_action *action)
  315. {
  316. return action->num_entries == 1;
  317. }
  318. static inline bool flow_action_is_last_entry(const struct flow_action *action,
  319. const struct flow_action_entry *entry)
  320. {
  321. return entry == &action->entries[action->num_entries - 1];
  322. }
  323. #define flow_action_for_each(__i, __act, __actions) \
  324. for (__i = 0, __act = &(__actions)->entries[0]; \
  325. __i < (__actions)->num_entries; \
  326. __act = &(__actions)->entries[++__i])
  327. static inline bool
  328. flow_action_mixed_hw_stats_check(const struct flow_action *action,
  329. struct netlink_ext_ack *extack)
  330. {
  331. const struct flow_action_entry *action_entry;
  332. u8 last_hw_stats;
  333. int i;
  334. if (flow_offload_has_one_action(action))
  335. return true;
  336. flow_action_for_each(i, action_entry, action) {
  337. if (i && action_entry->hw_stats != last_hw_stats) {
  338. NL_SET_ERR_MSG_MOD(extack, "Mixing HW stats types for actions is not supported");
  339. return false;
  340. }
  341. last_hw_stats = action_entry->hw_stats;
  342. }
  343. return true;
  344. }
  345. static inline const struct flow_action_entry *
  346. flow_action_first_entry_get(const struct flow_action *action)
  347. {
  348. WARN_ON(!flow_action_has_entries(action));
  349. return &action->entries[0];
  350. }
  351. static inline bool
  352. __flow_action_hw_stats_check(const struct flow_action *action,
  353. struct netlink_ext_ack *extack,
  354. bool check_allow_bit,
  355. enum flow_action_hw_stats_bit allow_bit)
  356. {
  357. const struct flow_action_entry *action_entry;
  358. if (!flow_action_has_entries(action))
  359. return true;
  360. if (!flow_action_mixed_hw_stats_check(action, extack))
  361. return false;
  362. action_entry = flow_action_first_entry_get(action);
  363. /* Zero is not a legal value for hw_stats, catch anyone passing it */
  364. WARN_ON_ONCE(!action_entry->hw_stats);
  365. if (!check_allow_bit &&
  366. ~action_entry->hw_stats & FLOW_ACTION_HW_STATS_ANY) {
  367. NL_SET_ERR_MSG_MOD(extack, "Driver supports only default HW stats type \"any\"");
  368. return false;
  369. } else if (check_allow_bit &&
  370. !(action_entry->hw_stats & BIT(allow_bit))) {
  371. NL_SET_ERR_MSG_MOD(extack, "Driver does not support selected HW stats type");
  372. return false;
  373. }
  374. return true;
  375. }
  376. static inline bool
  377. flow_action_hw_stats_check(const struct flow_action *action,
  378. struct netlink_ext_ack *extack,
  379. enum flow_action_hw_stats_bit allow_bit)
  380. {
  381. return __flow_action_hw_stats_check(action, extack, true, allow_bit);
  382. }
  383. static inline bool
  384. flow_action_basic_hw_stats_check(const struct flow_action *action,
  385. struct netlink_ext_ack *extack)
  386. {
  387. return __flow_action_hw_stats_check(action, extack, false, 0);
  388. }
  389. struct flow_rule {
  390. struct flow_match match;
  391. struct flow_action action;
  392. };
  393. struct flow_rule *flow_rule_alloc(unsigned int num_actions);
  394. static inline bool flow_rule_match_key(const struct flow_rule *rule,
  395. enum flow_dissector_key_id key)
  396. {
  397. return dissector_uses_key(rule->match.dissector, key);
  398. }
  399. /**
  400. * flow_rule_is_supp_control_flags() - check for supported control flags
  401. * @supp_flags: control flags supported by driver
  402. * @ctrl_flags: control flags present in rule
  403. * @extack: The netlink extended ACK for reporting errors.
  404. *
  405. * Return: true if only supported control flags are set, false otherwise.
  406. */
  407. static inline bool flow_rule_is_supp_control_flags(const u32 supp_flags,
  408. const u32 ctrl_flags,
  409. struct netlink_ext_ack *extack)
  410. {
  411. if (likely((ctrl_flags & ~supp_flags) == 0))
  412. return true;
  413. NL_SET_ERR_MSG_FMT_MOD(extack,
  414. "Unsupported match on control.flags %#x",
  415. ctrl_flags);
  416. return false;
  417. }
  418. /**
  419. * flow_rule_is_supp_enc_control_flags() - check for supported control flags
  420. * @supp_enc_flags: encapsulation control flags supported by driver
  421. * @enc_ctrl_flags: encapsulation control flags present in rule
  422. * @extack: The netlink extended ACK for reporting errors.
  423. *
  424. * Return: true if only supported control flags are set, false otherwise.
  425. */
  426. static inline bool flow_rule_is_supp_enc_control_flags(const u32 supp_enc_flags,
  427. const u32 enc_ctrl_flags,
  428. struct netlink_ext_ack *extack)
  429. {
  430. if (likely((enc_ctrl_flags & ~supp_enc_flags) == 0))
  431. return true;
  432. NL_SET_ERR_MSG_FMT_MOD(extack,
  433. "Unsupported match on enc_control.flags %#x",
  434. enc_ctrl_flags);
  435. return false;
  436. }
  437. /**
  438. * flow_rule_has_control_flags() - check for presence of any control flags
  439. * @ctrl_flags: control flags present in rule
  440. * @extack: The netlink extended ACK for reporting errors.
  441. *
  442. * Return: true if control flags are set, false otherwise.
  443. */
  444. static inline bool flow_rule_has_control_flags(const u32 ctrl_flags,
  445. struct netlink_ext_ack *extack)
  446. {
  447. return !flow_rule_is_supp_control_flags(0, ctrl_flags, extack);
  448. }
  449. /**
  450. * flow_rule_has_enc_control_flags() - check for presence of any control flags
  451. * @enc_ctrl_flags: encapsulation control flags present in rule
  452. * @extack: The netlink extended ACK for reporting errors.
  453. *
  454. * Return: true if control flags are set, false otherwise.
  455. */
  456. static inline bool flow_rule_has_enc_control_flags(const u32 enc_ctrl_flags,
  457. struct netlink_ext_ack *extack)
  458. {
  459. return !flow_rule_is_supp_enc_control_flags(0, enc_ctrl_flags, extack);
  460. }
  461. /**
  462. * flow_rule_match_has_control_flags() - match and check for any control flags
  463. * @rule: The flow_rule under evaluation.
  464. * @extack: The netlink extended ACK for reporting errors.
  465. *
  466. * Return: true if control flags are set, false otherwise.
  467. */
  468. static inline bool flow_rule_match_has_control_flags(struct flow_rule *rule,
  469. struct netlink_ext_ack *extack)
  470. {
  471. struct flow_match_control match;
  472. if (!flow_rule_match_key(rule, FLOW_DISSECTOR_KEY_CONTROL))
  473. return false;
  474. flow_rule_match_control(rule, &match);
  475. return flow_rule_has_control_flags(match.mask->flags, extack);
  476. }
  477. struct flow_stats {
  478. u64 pkts;
  479. u64 bytes;
  480. u64 drops;
  481. u64 lastused;
  482. enum flow_action_hw_stats used_hw_stats;
  483. bool used_hw_stats_valid;
  484. };
  485. static inline void flow_stats_update(struct flow_stats *flow_stats,
  486. u64 bytes, u64 pkts,
  487. u64 drops, u64 lastused,
  488. enum flow_action_hw_stats used_hw_stats)
  489. {
  490. flow_stats->pkts += pkts;
  491. flow_stats->bytes += bytes;
  492. flow_stats->drops += drops;
  493. flow_stats->lastused = max_t(u64, flow_stats->lastused, lastused);
  494. /* The driver should pass value with a maximum of one bit set.
  495. * Passing FLOW_ACTION_HW_STATS_ANY is invalid.
  496. */
  497. WARN_ON(used_hw_stats == FLOW_ACTION_HW_STATS_ANY);
  498. flow_stats->used_hw_stats |= used_hw_stats;
  499. flow_stats->used_hw_stats_valid = true;
  500. }
  501. enum flow_block_command {
  502. FLOW_BLOCK_BIND,
  503. FLOW_BLOCK_UNBIND,
  504. };
  505. enum flow_block_binder_type {
  506. FLOW_BLOCK_BINDER_TYPE_UNSPEC,
  507. FLOW_BLOCK_BINDER_TYPE_CLSACT_INGRESS,
  508. FLOW_BLOCK_BINDER_TYPE_CLSACT_EGRESS,
  509. FLOW_BLOCK_BINDER_TYPE_RED_EARLY_DROP,
  510. FLOW_BLOCK_BINDER_TYPE_RED_MARK,
  511. };
  512. struct flow_block {
  513. struct list_head cb_list;
  514. };
  515. struct netlink_ext_ack;
  516. struct flow_block_offload {
  517. enum flow_block_command command;
  518. enum flow_block_binder_type binder_type;
  519. bool block_shared;
  520. bool unlocked_driver_cb;
  521. struct net *net;
  522. struct flow_block *block;
  523. struct list_head cb_list;
  524. struct list_head *driver_block_list;
  525. struct netlink_ext_ack *extack;
  526. struct Qdisc *sch;
  527. struct list_head *cb_list_head;
  528. };
  529. enum tc_setup_type;
  530. typedef int flow_setup_cb_t(enum tc_setup_type type, void *type_data,
  531. void *cb_priv);
  532. struct flow_block_cb;
  533. struct flow_block_indr {
  534. struct list_head list;
  535. struct net_device *dev;
  536. struct Qdisc *sch;
  537. enum flow_block_binder_type binder_type;
  538. void *data;
  539. void *cb_priv;
  540. void (*cleanup)(struct flow_block_cb *block_cb);
  541. };
  542. struct flow_block_cb {
  543. struct list_head driver_list;
  544. struct list_head list;
  545. flow_setup_cb_t *cb;
  546. void *cb_ident;
  547. void *cb_priv;
  548. void (*release)(void *cb_priv);
  549. struct flow_block_indr indr;
  550. unsigned int refcnt;
  551. };
  552. struct flow_block_cb *flow_block_cb_alloc(flow_setup_cb_t *cb,
  553. void *cb_ident, void *cb_priv,
  554. void (*release)(void *cb_priv));
  555. struct flow_block_cb *flow_indr_block_cb_alloc(flow_setup_cb_t *cb,
  556. void *cb_ident, void *cb_priv,
  557. void (*release)(void *cb_priv),
  558. struct flow_block_offload *bo,
  559. struct net_device *dev,
  560. struct Qdisc *sch, void *data,
  561. void *indr_cb_priv,
  562. void (*cleanup)(struct flow_block_cb *block_cb));
  563. void flow_block_cb_free(struct flow_block_cb *block_cb);
  564. struct flow_block_cb *flow_block_cb_lookup(struct flow_block *block,
  565. flow_setup_cb_t *cb, void *cb_ident);
  566. void *flow_block_cb_priv(struct flow_block_cb *block_cb);
  567. void flow_block_cb_incref(struct flow_block_cb *block_cb);
  568. unsigned int flow_block_cb_decref(struct flow_block_cb *block_cb);
  569. static inline void flow_block_cb_add(struct flow_block_cb *block_cb,
  570. struct flow_block_offload *offload)
  571. {
  572. list_add_tail(&block_cb->list, &offload->cb_list);
  573. }
  574. static inline void flow_block_cb_remove(struct flow_block_cb *block_cb,
  575. struct flow_block_offload *offload)
  576. {
  577. list_move(&block_cb->list, &offload->cb_list);
  578. }
  579. static inline void flow_indr_block_cb_remove(struct flow_block_cb *block_cb,
  580. struct flow_block_offload *offload)
  581. {
  582. list_del(&block_cb->indr.list);
  583. list_move(&block_cb->list, &offload->cb_list);
  584. }
  585. bool flow_block_cb_is_busy(flow_setup_cb_t *cb, void *cb_ident,
  586. struct list_head *driver_block_list);
  587. int flow_block_cb_setup_simple(struct flow_block_offload *f,
  588. struct list_head *driver_list,
  589. flow_setup_cb_t *cb,
  590. void *cb_ident, void *cb_priv, bool ingress_only);
  591. enum flow_cls_command {
  592. FLOW_CLS_REPLACE,
  593. FLOW_CLS_DESTROY,
  594. FLOW_CLS_STATS,
  595. FLOW_CLS_TMPLT_CREATE,
  596. FLOW_CLS_TMPLT_DESTROY,
  597. };
  598. struct flow_cls_common_offload {
  599. u32 chain_index;
  600. __be16 protocol;
  601. u32 prio;
  602. struct netlink_ext_ack *extack;
  603. };
  604. struct flow_cls_offload {
  605. struct flow_cls_common_offload common;
  606. enum flow_cls_command command;
  607. bool use_act_stats;
  608. unsigned long cookie;
  609. struct flow_rule *rule;
  610. struct flow_stats stats;
  611. u32 classid;
  612. };
  613. enum offload_act_command {
  614. FLOW_ACT_REPLACE,
  615. FLOW_ACT_DESTROY,
  616. FLOW_ACT_STATS,
  617. };
  618. struct flow_offload_action {
  619. struct netlink_ext_ack *extack; /* NULL in FLOW_ACT_STATS process*/
  620. enum offload_act_command command;
  621. enum flow_action_id id;
  622. u32 index;
  623. unsigned long cookie;
  624. struct flow_stats stats;
  625. struct flow_action action;
  626. };
  627. struct flow_offload_action *offload_action_alloc(unsigned int num_actions);
  628. static inline struct flow_rule *
  629. flow_cls_offload_flow_rule(struct flow_cls_offload *flow_cmd)
  630. {
  631. return flow_cmd->rule;
  632. }
  633. static inline void flow_block_init(struct flow_block *flow_block)
  634. {
  635. INIT_LIST_HEAD(&flow_block->cb_list);
  636. }
  637. typedef int flow_indr_block_bind_cb_t(struct net_device *dev, struct Qdisc *sch, void *cb_priv,
  638. enum tc_setup_type type, void *type_data,
  639. void *data,
  640. void (*cleanup)(struct flow_block_cb *block_cb));
  641. int flow_indr_dev_register(flow_indr_block_bind_cb_t *cb, void *cb_priv);
  642. void flow_indr_dev_unregister(flow_indr_block_bind_cb_t *cb, void *cb_priv,
  643. void (*release)(void *cb_priv));
  644. int flow_indr_dev_setup_offload(struct net_device *dev, struct Qdisc *sch,
  645. enum tc_setup_type type, void *data,
  646. struct flow_block_offload *bo,
  647. void (*cleanup)(struct flow_block_cb *block_cb));
  648. bool flow_indr_dev_exists(void);
  649. #endif /* _NET_FLOW_OFFLOAD_H */