flow_table.h 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. /* SPDX-License-Identifier: GPL-2.0-only */
  2. /*
  3. * Copyright (c) 2007-2013 Nicira, Inc.
  4. */
  5. #ifndef FLOW_TABLE_H
  6. #define FLOW_TABLE_H 1
  7. #include <linux/kernel.h>
  8. #include <linux/netlink.h>
  9. #include <linux/openvswitch.h>
  10. #include <linux/spinlock.h>
  11. #include <linux/types.h>
  12. #include <linux/rcupdate.h>
  13. #include <linux/if_ether.h>
  14. #include <linux/in6.h>
  15. #include <linux/jiffies.h>
  16. #include <linux/time.h>
  17. #include <net/inet_ecn.h>
  18. #include <net/ip_tunnels.h>
  19. #include "flow.h"
  20. struct mask_cache_entry {
  21. u32 skb_hash;
  22. u32 mask_index;
  23. };
  24. struct mask_cache {
  25. struct rcu_head rcu;
  26. u32 cache_size; /* Must be ^2 value. */
  27. struct mask_cache_entry __percpu *mask_cache;
  28. };
  29. struct mask_count {
  30. int index;
  31. u64 counter;
  32. };
  33. struct mask_array_stats {
  34. struct u64_stats_sync syncp;
  35. u64 usage_cntrs[];
  36. };
  37. struct mask_array {
  38. struct rcu_head rcu;
  39. int count, max;
  40. struct mask_array_stats __percpu *masks_usage_stats;
  41. u64 *masks_usage_zero_cntr;
  42. struct sw_flow_mask __rcu *masks[];
  43. };
  44. struct table_instance {
  45. struct hlist_head *buckets;
  46. unsigned int n_buckets;
  47. struct rcu_head rcu;
  48. int node_ver;
  49. u32 hash_seed;
  50. };
  51. struct flow_table {
  52. struct table_instance __rcu *ti;
  53. struct table_instance __rcu *ufid_ti;
  54. struct mask_cache __rcu *mask_cache;
  55. struct mask_array __rcu *mask_array;
  56. unsigned long last_rehash;
  57. unsigned int count;
  58. unsigned int ufid_count;
  59. };
  60. extern struct kmem_cache *flow_stats_cache;
  61. int ovs_flow_init(void);
  62. void ovs_flow_exit(void);
  63. struct sw_flow *ovs_flow_alloc(void);
  64. void ovs_flow_free(struct sw_flow *, bool deferred);
  65. int ovs_flow_tbl_init(struct flow_table *);
  66. int ovs_flow_tbl_count(const struct flow_table *table);
  67. void ovs_flow_tbl_destroy(struct flow_table *table);
  68. int ovs_flow_tbl_flush(struct flow_table *flow_table);
  69. int ovs_flow_tbl_insert(struct flow_table *table, struct sw_flow *flow,
  70. const struct sw_flow_mask *mask);
  71. void ovs_flow_tbl_remove(struct flow_table *table, struct sw_flow *flow);
  72. int ovs_flow_tbl_num_masks(const struct flow_table *table);
  73. u32 ovs_flow_tbl_masks_cache_size(const struct flow_table *table);
  74. int ovs_flow_tbl_masks_cache_resize(struct flow_table *table, u32 size);
  75. struct sw_flow *ovs_flow_tbl_dump_next(struct table_instance *table,
  76. u32 *bucket, u32 *idx);
  77. struct sw_flow *ovs_flow_tbl_lookup_stats(struct flow_table *,
  78. const struct sw_flow_key *,
  79. u32 skb_hash,
  80. u32 *n_mask_hit,
  81. u32 *n_cache_hit);
  82. struct sw_flow *ovs_flow_tbl_lookup(struct flow_table *,
  83. const struct sw_flow_key *);
  84. struct sw_flow *ovs_flow_tbl_lookup_exact(struct flow_table *tbl,
  85. const struct sw_flow_match *match);
  86. struct sw_flow *ovs_flow_tbl_lookup_ufid(struct flow_table *,
  87. const struct sw_flow_id *);
  88. bool ovs_flow_cmp(const struct sw_flow *, const struct sw_flow_match *);
  89. void ovs_flow_mask_key(struct sw_flow_key *dst, const struct sw_flow_key *src,
  90. bool full, const struct sw_flow_mask *mask);
  91. void ovs_flow_masks_rebalance(struct flow_table *table);
  92. void table_instance_flow_flush(struct flow_table *table,
  93. struct table_instance *ti,
  94. struct table_instance *ufid_ti);
  95. #endif /* flow_table.h */