flow_offload.h 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747
  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_police {
  202. u32 burst;
  203. u64 rate_bytes_ps;
  204. u64 peakrate_bytes_ps;
  205. u32 avrate;
  206. u16 overhead;
  207. u64 burst_pkt;
  208. u64 rate_pkt_ps;
  209. u32 mtu;
  210. struct {
  211. enum flow_action_id act_id;
  212. u32 extval;
  213. } exceed, notexceed;
  214. };
  215. struct flow_action_entry {
  216. enum flow_action_id id;
  217. u32 hw_index;
  218. unsigned long cookie;
  219. u64 miss_cookie;
  220. enum flow_action_hw_stats hw_stats;
  221. action_destr destructor;
  222. void *destructor_priv;
  223. union {
  224. u32 chain_index; /* FLOW_ACTION_GOTO */
  225. struct net_device *dev; /* FLOW_ACTION_REDIRECT */
  226. struct { /* FLOW_ACTION_VLAN */
  227. u16 vid;
  228. __be16 proto;
  229. u8 prio;
  230. } vlan;
  231. struct { /* FLOW_ACTION_VLAN_PUSH_ETH */
  232. unsigned char dst[ETH_ALEN];
  233. unsigned char src[ETH_ALEN];
  234. } vlan_push_eth;
  235. struct { /* FLOW_ACTION_MANGLE */
  236. /* FLOW_ACTION_ADD */
  237. enum flow_action_mangle_base htype;
  238. u32 offset;
  239. u32 mask;
  240. u32 val;
  241. } mangle;
  242. struct ip_tunnel_info *tunnel; /* FLOW_ACTION_TUNNEL_ENCAP */
  243. u32 csum_flags; /* FLOW_ACTION_CSUM */
  244. u32 mark; /* FLOW_ACTION_MARK */
  245. u16 ptype; /* FLOW_ACTION_PTYPE */
  246. u16 rx_queue; /* FLOW_ACTION_RX_QUEUE_MAPPING */
  247. u32 priority; /* FLOW_ACTION_PRIORITY */
  248. struct { /* FLOW_ACTION_QUEUE */
  249. u32 ctx;
  250. u32 index;
  251. u8 vf;
  252. } queue;
  253. struct { /* FLOW_ACTION_SAMPLE */
  254. struct psample_group *psample_group;
  255. u32 rate;
  256. u32 trunc_size;
  257. bool truncate;
  258. } sample;
  259. struct flow_action_police police; /* FLOW_ACTION_POLICE */
  260. struct { /* FLOW_ACTION_CT */
  261. int action;
  262. u16 zone;
  263. struct nf_flowtable *flow_table;
  264. } ct;
  265. struct {
  266. unsigned long cookie;
  267. u32 mark;
  268. u32 labels[4];
  269. bool orig_dir;
  270. } ct_metadata;
  271. struct { /* FLOW_ACTION_MPLS_PUSH */
  272. u32 label;
  273. __be16 proto;
  274. u8 tc;
  275. u8 bos;
  276. u8 ttl;
  277. } mpls_push;
  278. struct { /* FLOW_ACTION_MPLS_POP */
  279. __be16 proto;
  280. } mpls_pop;
  281. struct { /* FLOW_ACTION_MPLS_MANGLE */
  282. u32 label;
  283. u8 tc;
  284. u8 bos;
  285. u8 ttl;
  286. } mpls_mangle;
  287. struct {
  288. s32 prio;
  289. u64 basetime;
  290. u64 cycletime;
  291. u64 cycletimeext;
  292. u32 num_entries;
  293. struct action_gate_entry *entries;
  294. } gate;
  295. struct { /* FLOW_ACTION_PPPOE_PUSH */
  296. u16 sid;
  297. } pppoe;
  298. };
  299. struct flow_action_cookie *user_cookie; /* user defined action cookie */
  300. };
  301. struct flow_action {
  302. unsigned int num_entries;
  303. struct flow_action_entry entries[] __counted_by(num_entries);
  304. };
  305. static inline bool flow_action_has_entries(const struct flow_action *action)
  306. {
  307. return action->num_entries;
  308. }
  309. /**
  310. * flow_offload_has_one_action() - check if exactly one action is present
  311. * @action: tc filter flow offload action
  312. *
  313. * Return: true if exactly one action is present.
  314. */
  315. static inline bool flow_offload_has_one_action(const struct flow_action *action)
  316. {
  317. return action->num_entries == 1;
  318. }
  319. static inline bool flow_action_is_last_entry(const struct flow_action *action,
  320. const struct flow_action_entry *entry)
  321. {
  322. return entry == &action->entries[action->num_entries - 1];
  323. }
  324. #define flow_action_for_each(__i, __act, __actions) \
  325. for (__i = 0, __act = &(__actions)->entries[0]; \
  326. __i < (__actions)->num_entries; \
  327. __act = &(__actions)->entries[++__i])
  328. static inline bool
  329. flow_action_mixed_hw_stats_check(const struct flow_action *action,
  330. struct netlink_ext_ack *extack)
  331. {
  332. const struct flow_action_entry *action_entry;
  333. u8 last_hw_stats;
  334. int i;
  335. if (flow_offload_has_one_action(action))
  336. return true;
  337. flow_action_for_each(i, action_entry, action) {
  338. if (i && action_entry->hw_stats != last_hw_stats) {
  339. NL_SET_ERR_MSG_MOD(extack, "Mixing HW stats types for actions is not supported");
  340. return false;
  341. }
  342. last_hw_stats = action_entry->hw_stats;
  343. }
  344. return true;
  345. }
  346. static inline const struct flow_action_entry *
  347. flow_action_first_entry_get(const struct flow_action *action)
  348. {
  349. WARN_ON(!flow_action_has_entries(action));
  350. return &action->entries[0];
  351. }
  352. static inline bool
  353. __flow_action_hw_stats_check(const struct flow_action *action,
  354. struct netlink_ext_ack *extack,
  355. bool check_allow_bit,
  356. enum flow_action_hw_stats_bit allow_bit)
  357. {
  358. const struct flow_action_entry *action_entry;
  359. if (!flow_action_has_entries(action))
  360. return true;
  361. if (!flow_action_mixed_hw_stats_check(action, extack))
  362. return false;
  363. action_entry = flow_action_first_entry_get(action);
  364. /* Zero is not a legal value for hw_stats, catch anyone passing it */
  365. WARN_ON_ONCE(!action_entry->hw_stats);
  366. if (!check_allow_bit &&
  367. ~action_entry->hw_stats & FLOW_ACTION_HW_STATS_ANY) {
  368. NL_SET_ERR_MSG_MOD(extack, "Driver supports only default HW stats type \"any\"");
  369. return false;
  370. } else if (check_allow_bit &&
  371. !(action_entry->hw_stats & BIT(allow_bit))) {
  372. NL_SET_ERR_MSG_MOD(extack, "Driver does not support selected HW stats type");
  373. return false;
  374. }
  375. return true;
  376. }
  377. static inline bool
  378. flow_action_hw_stats_check(const struct flow_action *action,
  379. struct netlink_ext_ack *extack,
  380. enum flow_action_hw_stats_bit allow_bit)
  381. {
  382. return __flow_action_hw_stats_check(action, extack, true, allow_bit);
  383. }
  384. static inline bool
  385. flow_action_basic_hw_stats_check(const struct flow_action *action,
  386. struct netlink_ext_ack *extack)
  387. {
  388. return __flow_action_hw_stats_check(action, extack, false, 0);
  389. }
  390. struct flow_rule {
  391. struct flow_match match;
  392. struct flow_action action;
  393. };
  394. struct flow_rule *flow_rule_alloc(unsigned int num_actions);
  395. static inline bool flow_rule_match_key(const struct flow_rule *rule,
  396. enum flow_dissector_key_id key)
  397. {
  398. return dissector_uses_key(rule->match.dissector, key);
  399. }
  400. /**
  401. * flow_rule_is_supp_control_flags() - check for supported control flags
  402. * @supp_flags: control flags supported by driver
  403. * @ctrl_flags: control flags present in rule
  404. * @extack: The netlink extended ACK for reporting errors.
  405. *
  406. * Return: true if only supported control flags are set, false otherwise.
  407. */
  408. static inline bool flow_rule_is_supp_control_flags(const u32 supp_flags,
  409. const u32 ctrl_flags,
  410. struct netlink_ext_ack *extack)
  411. {
  412. if (likely((ctrl_flags & ~supp_flags) == 0))
  413. return true;
  414. NL_SET_ERR_MSG_FMT_MOD(extack,
  415. "Unsupported match on control.flags %#x",
  416. ctrl_flags);
  417. return false;
  418. }
  419. /**
  420. * flow_rule_is_supp_enc_control_flags() - check for supported control flags
  421. * @supp_enc_flags: encapsulation control flags supported by driver
  422. * @enc_ctrl_flags: encapsulation control flags present in rule
  423. * @extack: The netlink extended ACK for reporting errors.
  424. *
  425. * Return: true if only supported control flags are set, false otherwise.
  426. */
  427. static inline bool flow_rule_is_supp_enc_control_flags(const u32 supp_enc_flags,
  428. const u32 enc_ctrl_flags,
  429. struct netlink_ext_ack *extack)
  430. {
  431. if (likely((enc_ctrl_flags & ~supp_enc_flags) == 0))
  432. return true;
  433. NL_SET_ERR_MSG_FMT_MOD(extack,
  434. "Unsupported match on enc_control.flags %#x",
  435. enc_ctrl_flags);
  436. return false;
  437. }
  438. /**
  439. * flow_rule_has_control_flags() - check for presence of any control flags
  440. * @ctrl_flags: control flags present in rule
  441. * @extack: The netlink extended ACK for reporting errors.
  442. *
  443. * Return: true if control flags are set, false otherwise.
  444. */
  445. static inline bool flow_rule_has_control_flags(const u32 ctrl_flags,
  446. struct netlink_ext_ack *extack)
  447. {
  448. return !flow_rule_is_supp_control_flags(0, ctrl_flags, extack);
  449. }
  450. /**
  451. * flow_rule_has_enc_control_flags() - check for presence of any control flags
  452. * @enc_ctrl_flags: encapsulation control flags present in rule
  453. * @extack: The netlink extended ACK for reporting errors.
  454. *
  455. * Return: true if control flags are set, false otherwise.
  456. */
  457. static inline bool flow_rule_has_enc_control_flags(const u32 enc_ctrl_flags,
  458. struct netlink_ext_ack *extack)
  459. {
  460. return !flow_rule_is_supp_enc_control_flags(0, enc_ctrl_flags, extack);
  461. }
  462. /**
  463. * flow_rule_match_has_control_flags() - match and check for any control flags
  464. * @rule: The flow_rule under evaluation.
  465. * @extack: The netlink extended ACK for reporting errors.
  466. *
  467. * Return: true if control flags are set, false otherwise.
  468. */
  469. static inline bool flow_rule_match_has_control_flags(const struct flow_rule *rule,
  470. struct netlink_ext_ack *extack)
  471. {
  472. struct flow_match_control match;
  473. if (!flow_rule_match_key(rule, FLOW_DISSECTOR_KEY_CONTROL))
  474. return false;
  475. flow_rule_match_control(rule, &match);
  476. return flow_rule_has_control_flags(match.mask->flags, extack);
  477. }
  478. struct flow_stats {
  479. u64 pkts;
  480. u64 bytes;
  481. u64 drops;
  482. u64 lastused;
  483. enum flow_action_hw_stats used_hw_stats;
  484. bool used_hw_stats_valid;
  485. };
  486. static inline void flow_stats_update(struct flow_stats *flow_stats,
  487. u64 bytes, u64 pkts,
  488. u64 drops, u64 lastused,
  489. enum flow_action_hw_stats used_hw_stats)
  490. {
  491. flow_stats->pkts += pkts;
  492. flow_stats->bytes += bytes;
  493. flow_stats->drops += drops;
  494. flow_stats->lastused = max_t(u64, flow_stats->lastused, lastused);
  495. /* The driver should pass value with a maximum of one bit set.
  496. * Passing FLOW_ACTION_HW_STATS_ANY is invalid.
  497. */
  498. WARN_ON(used_hw_stats == FLOW_ACTION_HW_STATS_ANY);
  499. flow_stats->used_hw_stats |= used_hw_stats;
  500. flow_stats->used_hw_stats_valid = true;
  501. }
  502. enum flow_block_command {
  503. FLOW_BLOCK_BIND,
  504. FLOW_BLOCK_UNBIND,
  505. };
  506. enum flow_block_binder_type {
  507. FLOW_BLOCK_BINDER_TYPE_UNSPEC,
  508. FLOW_BLOCK_BINDER_TYPE_CLSACT_INGRESS,
  509. FLOW_BLOCK_BINDER_TYPE_CLSACT_EGRESS,
  510. FLOW_BLOCK_BINDER_TYPE_RED_EARLY_DROP,
  511. FLOW_BLOCK_BINDER_TYPE_RED_MARK,
  512. };
  513. struct flow_block {
  514. struct list_head cb_list;
  515. };
  516. struct netlink_ext_ack;
  517. struct flow_block_offload {
  518. enum flow_block_command command;
  519. enum flow_block_binder_type binder_type;
  520. bool block_shared;
  521. bool unlocked_driver_cb;
  522. struct net *net;
  523. struct flow_block *block;
  524. struct list_head cb_list;
  525. struct list_head *driver_block_list;
  526. struct netlink_ext_ack *extack;
  527. struct Qdisc *sch;
  528. struct list_head *cb_list_head;
  529. };
  530. enum tc_setup_type;
  531. typedef int flow_setup_cb_t(enum tc_setup_type type, void *type_data,
  532. void *cb_priv);
  533. struct flow_block_cb;
  534. struct flow_block_indr {
  535. struct list_head list;
  536. struct net_device *dev;
  537. struct Qdisc *sch;
  538. enum flow_block_binder_type binder_type;
  539. void *data;
  540. void *cb_priv;
  541. void (*cleanup)(struct flow_block_cb *block_cb);
  542. };
  543. struct flow_block_cb {
  544. struct list_head driver_list;
  545. struct list_head list;
  546. flow_setup_cb_t *cb;
  547. void *cb_ident;
  548. void *cb_priv;
  549. void (*release)(void *cb_priv);
  550. struct flow_block_indr indr;
  551. unsigned int refcnt;
  552. };
  553. struct flow_block_cb *flow_block_cb_alloc(flow_setup_cb_t *cb,
  554. void *cb_ident, void *cb_priv,
  555. void (*release)(void *cb_priv));
  556. struct flow_block_cb *flow_indr_block_cb_alloc(flow_setup_cb_t *cb,
  557. void *cb_ident, void *cb_priv,
  558. void (*release)(void *cb_priv),
  559. struct flow_block_offload *bo,
  560. struct net_device *dev,
  561. struct Qdisc *sch, void *data,
  562. void *indr_cb_priv,
  563. void (*cleanup)(struct flow_block_cb *block_cb));
  564. void flow_block_cb_free(struct flow_block_cb *block_cb);
  565. struct flow_block_cb *flow_block_cb_lookup(struct flow_block *block,
  566. flow_setup_cb_t *cb, void *cb_ident);
  567. void *flow_block_cb_priv(struct flow_block_cb *block_cb);
  568. void flow_block_cb_incref(struct flow_block_cb *block_cb);
  569. unsigned int flow_block_cb_decref(struct flow_block_cb *block_cb);
  570. static inline void flow_block_cb_add(struct flow_block_cb *block_cb,
  571. struct flow_block_offload *offload)
  572. {
  573. list_add_tail(&block_cb->list, &offload->cb_list);
  574. }
  575. static inline void flow_block_cb_remove(struct flow_block_cb *block_cb,
  576. struct flow_block_offload *offload)
  577. {
  578. list_move(&block_cb->list, &offload->cb_list);
  579. }
  580. static inline void flow_indr_block_cb_remove(struct flow_block_cb *block_cb,
  581. struct flow_block_offload *offload)
  582. {
  583. list_del(&block_cb->indr.list);
  584. list_move(&block_cb->list, &offload->cb_list);
  585. }
  586. bool flow_block_cb_is_busy(flow_setup_cb_t *cb, void *cb_ident,
  587. struct list_head *driver_block_list);
  588. int flow_block_cb_setup_simple(struct flow_block_offload *f,
  589. struct list_head *driver_list,
  590. flow_setup_cb_t *cb,
  591. void *cb_ident, void *cb_priv, bool ingress_only);
  592. enum flow_cls_command {
  593. FLOW_CLS_REPLACE,
  594. FLOW_CLS_DESTROY,
  595. FLOW_CLS_STATS,
  596. FLOW_CLS_TMPLT_CREATE,
  597. FLOW_CLS_TMPLT_DESTROY,
  598. };
  599. struct flow_cls_common_offload {
  600. u32 chain_index;
  601. __be16 protocol;
  602. u32 prio;
  603. bool skip_sw;
  604. struct netlink_ext_ack *extack;
  605. };
  606. struct flow_cls_offload {
  607. struct flow_cls_common_offload common;
  608. enum flow_cls_command command;
  609. bool use_act_stats;
  610. unsigned long cookie;
  611. struct flow_rule *rule;
  612. struct flow_stats stats;
  613. u32 classid;
  614. };
  615. enum offload_act_command {
  616. FLOW_ACT_REPLACE,
  617. FLOW_ACT_DESTROY,
  618. FLOW_ACT_STATS,
  619. };
  620. struct flow_offload_action {
  621. struct netlink_ext_ack *extack; /* NULL in FLOW_ACT_STATS process*/
  622. enum offload_act_command command;
  623. enum flow_action_id id;
  624. u32 index;
  625. unsigned long cookie;
  626. struct flow_stats stats;
  627. struct flow_action action;
  628. };
  629. struct flow_offload_action *offload_action_alloc(unsigned int num_actions);
  630. static inline struct flow_rule *
  631. flow_cls_offload_flow_rule(const struct flow_cls_offload *flow_cmd)
  632. {
  633. return flow_cmd->rule;
  634. }
  635. static inline void flow_block_init(struct flow_block *flow_block)
  636. {
  637. INIT_LIST_HEAD(&flow_block->cb_list);
  638. }
  639. typedef int flow_indr_block_bind_cb_t(struct net_device *dev, struct Qdisc *sch, void *cb_priv,
  640. enum tc_setup_type type, void *type_data,
  641. void *data,
  642. void (*cleanup)(struct flow_block_cb *block_cb));
  643. int flow_indr_dev_register(flow_indr_block_bind_cb_t *cb, void *cb_priv);
  644. void flow_indr_dev_unregister(flow_indr_block_bind_cb_t *cb, void *cb_priv,
  645. void (*release)(void *cb_priv));
  646. int flow_indr_dev_setup_offload(struct net_device *dev, struct Qdisc *sch,
  647. enum tc_setup_type type, void *data,
  648. struct flow_block_offload *bo,
  649. void (*cleanup)(struct flow_block_cb *block_cb));
  650. bool flow_indr_dev_exists(void);
  651. #endif /* _NET_FLOW_OFFLOAD_H */