162306a36Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0-only */ 262306a36Sopenharmony_ci/* 362306a36Sopenharmony_ci * Copyright (c) 2007-2013 Nicira, Inc. 462306a36Sopenharmony_ci */ 562306a36Sopenharmony_ci 662306a36Sopenharmony_ci#ifndef FLOW_TABLE_H 762306a36Sopenharmony_ci#define FLOW_TABLE_H 1 862306a36Sopenharmony_ci 962306a36Sopenharmony_ci#include <linux/kernel.h> 1062306a36Sopenharmony_ci#include <linux/netlink.h> 1162306a36Sopenharmony_ci#include <linux/openvswitch.h> 1262306a36Sopenharmony_ci#include <linux/spinlock.h> 1362306a36Sopenharmony_ci#include <linux/types.h> 1462306a36Sopenharmony_ci#include <linux/rcupdate.h> 1562306a36Sopenharmony_ci#include <linux/if_ether.h> 1662306a36Sopenharmony_ci#include <linux/in6.h> 1762306a36Sopenharmony_ci#include <linux/jiffies.h> 1862306a36Sopenharmony_ci#include <linux/time.h> 1962306a36Sopenharmony_ci 2062306a36Sopenharmony_ci#include <net/inet_ecn.h> 2162306a36Sopenharmony_ci#include <net/ip_tunnels.h> 2262306a36Sopenharmony_ci 2362306a36Sopenharmony_ci#include "flow.h" 2462306a36Sopenharmony_ci 2562306a36Sopenharmony_cistruct mask_cache_entry { 2662306a36Sopenharmony_ci u32 skb_hash; 2762306a36Sopenharmony_ci u32 mask_index; 2862306a36Sopenharmony_ci}; 2962306a36Sopenharmony_ci 3062306a36Sopenharmony_cistruct mask_cache { 3162306a36Sopenharmony_ci struct rcu_head rcu; 3262306a36Sopenharmony_ci u32 cache_size; /* Must be ^2 value. */ 3362306a36Sopenharmony_ci struct mask_cache_entry __percpu *mask_cache; 3462306a36Sopenharmony_ci}; 3562306a36Sopenharmony_ci 3662306a36Sopenharmony_cistruct mask_count { 3762306a36Sopenharmony_ci int index; 3862306a36Sopenharmony_ci u64 counter; 3962306a36Sopenharmony_ci}; 4062306a36Sopenharmony_ci 4162306a36Sopenharmony_cistruct mask_array_stats { 4262306a36Sopenharmony_ci struct u64_stats_sync syncp; 4362306a36Sopenharmony_ci u64 usage_cntrs[]; 4462306a36Sopenharmony_ci}; 4562306a36Sopenharmony_ci 4662306a36Sopenharmony_cistruct mask_array { 4762306a36Sopenharmony_ci struct rcu_head rcu; 4862306a36Sopenharmony_ci int count, max; 4962306a36Sopenharmony_ci struct mask_array_stats __percpu *masks_usage_stats; 5062306a36Sopenharmony_ci u64 *masks_usage_zero_cntr; 5162306a36Sopenharmony_ci struct sw_flow_mask __rcu *masks[]; 5262306a36Sopenharmony_ci}; 5362306a36Sopenharmony_ci 5462306a36Sopenharmony_cistruct table_instance { 5562306a36Sopenharmony_ci struct hlist_head *buckets; 5662306a36Sopenharmony_ci unsigned int n_buckets; 5762306a36Sopenharmony_ci struct rcu_head rcu; 5862306a36Sopenharmony_ci int node_ver; 5962306a36Sopenharmony_ci u32 hash_seed; 6062306a36Sopenharmony_ci}; 6162306a36Sopenharmony_ci 6262306a36Sopenharmony_cistruct flow_table { 6362306a36Sopenharmony_ci struct table_instance __rcu *ti; 6462306a36Sopenharmony_ci struct table_instance __rcu *ufid_ti; 6562306a36Sopenharmony_ci struct mask_cache __rcu *mask_cache; 6662306a36Sopenharmony_ci struct mask_array __rcu *mask_array; 6762306a36Sopenharmony_ci unsigned long last_rehash; 6862306a36Sopenharmony_ci unsigned int count; 6962306a36Sopenharmony_ci unsigned int ufid_count; 7062306a36Sopenharmony_ci}; 7162306a36Sopenharmony_ci 7262306a36Sopenharmony_ciextern struct kmem_cache *flow_stats_cache; 7362306a36Sopenharmony_ci 7462306a36Sopenharmony_ciint ovs_flow_init(void); 7562306a36Sopenharmony_civoid ovs_flow_exit(void); 7662306a36Sopenharmony_ci 7762306a36Sopenharmony_cistruct sw_flow *ovs_flow_alloc(void); 7862306a36Sopenharmony_civoid ovs_flow_free(struct sw_flow *, bool deferred); 7962306a36Sopenharmony_ci 8062306a36Sopenharmony_ciint ovs_flow_tbl_init(struct flow_table *); 8162306a36Sopenharmony_ciint ovs_flow_tbl_count(const struct flow_table *table); 8262306a36Sopenharmony_civoid ovs_flow_tbl_destroy(struct flow_table *table); 8362306a36Sopenharmony_ciint ovs_flow_tbl_flush(struct flow_table *flow_table); 8462306a36Sopenharmony_ci 8562306a36Sopenharmony_ciint ovs_flow_tbl_insert(struct flow_table *table, struct sw_flow *flow, 8662306a36Sopenharmony_ci const struct sw_flow_mask *mask); 8762306a36Sopenharmony_civoid ovs_flow_tbl_remove(struct flow_table *table, struct sw_flow *flow); 8862306a36Sopenharmony_ciint ovs_flow_tbl_num_masks(const struct flow_table *table); 8962306a36Sopenharmony_ciu32 ovs_flow_tbl_masks_cache_size(const struct flow_table *table); 9062306a36Sopenharmony_ciint ovs_flow_tbl_masks_cache_resize(struct flow_table *table, u32 size); 9162306a36Sopenharmony_cistruct sw_flow *ovs_flow_tbl_dump_next(struct table_instance *table, 9262306a36Sopenharmony_ci u32 *bucket, u32 *idx); 9362306a36Sopenharmony_cistruct sw_flow *ovs_flow_tbl_lookup_stats(struct flow_table *, 9462306a36Sopenharmony_ci const struct sw_flow_key *, 9562306a36Sopenharmony_ci u32 skb_hash, 9662306a36Sopenharmony_ci u32 *n_mask_hit, 9762306a36Sopenharmony_ci u32 *n_cache_hit); 9862306a36Sopenharmony_cistruct sw_flow *ovs_flow_tbl_lookup(struct flow_table *, 9962306a36Sopenharmony_ci const struct sw_flow_key *); 10062306a36Sopenharmony_cistruct sw_flow *ovs_flow_tbl_lookup_exact(struct flow_table *tbl, 10162306a36Sopenharmony_ci const struct sw_flow_match *match); 10262306a36Sopenharmony_cistruct sw_flow *ovs_flow_tbl_lookup_ufid(struct flow_table *, 10362306a36Sopenharmony_ci const struct sw_flow_id *); 10462306a36Sopenharmony_ci 10562306a36Sopenharmony_cibool ovs_flow_cmp(const struct sw_flow *, const struct sw_flow_match *); 10662306a36Sopenharmony_ci 10762306a36Sopenharmony_civoid ovs_flow_mask_key(struct sw_flow_key *dst, const struct sw_flow_key *src, 10862306a36Sopenharmony_ci bool full, const struct sw_flow_mask *mask); 10962306a36Sopenharmony_ci 11062306a36Sopenharmony_civoid ovs_flow_masks_rebalance(struct flow_table *table); 11162306a36Sopenharmony_civoid table_instance_flow_flush(struct flow_table *table, 11262306a36Sopenharmony_ci struct table_instance *ti, 11362306a36Sopenharmony_ci struct table_instance *ufid_ti); 11462306a36Sopenharmony_ci 11562306a36Sopenharmony_ci#endif /* flow_table.h */ 116