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