1c9422999SThomas Gleixner /* SPDX-License-Identifier: GPL-2.0-only */ 2e6445719SPravin B Shelar /* 3e6445719SPravin B Shelar * Copyright (c) 2007-2013 Nicira, Inc. 4e6445719SPravin B Shelar */ 5e6445719SPravin B Shelar 6e6445719SPravin B Shelar #ifndef FLOW_TABLE_H 7e6445719SPravin B Shelar #define FLOW_TABLE_H 1 8e6445719SPravin B Shelar 9e6445719SPravin B Shelar #include <linux/kernel.h> 10e6445719SPravin B Shelar #include <linux/netlink.h> 11e6445719SPravin B Shelar #include <linux/openvswitch.h> 12e6445719SPravin B Shelar #include <linux/spinlock.h> 13e6445719SPravin B Shelar #include <linux/types.h> 14e6445719SPravin B Shelar #include <linux/rcupdate.h> 15e6445719SPravin B Shelar #include <linux/if_ether.h> 16e6445719SPravin B Shelar #include <linux/in6.h> 17e6445719SPravin B Shelar #include <linux/jiffies.h> 18e6445719SPravin B Shelar #include <linux/time.h> 19e6445719SPravin B Shelar 20e6445719SPravin B Shelar #include <net/inet_ecn.h> 21e6445719SPravin B Shelar #include <net/ip_tunnels.h> 22e6445719SPravin B Shelar 23e6445719SPravin B Shelar #include "flow.h" 24e6445719SPravin B Shelar 2504b7d136STonghao Zhang struct mask_cache_entry { 2604b7d136STonghao Zhang u32 skb_hash; 2704b7d136STonghao Zhang u32 mask_index; 2804b7d136STonghao Zhang }; 2904b7d136STonghao Zhang 30*9bf24f59SEelco Chaudron struct mask_cache { 31*9bf24f59SEelco Chaudron struct rcu_head rcu; 32*9bf24f59SEelco Chaudron u32 cache_size; /* Must be ^2 value. */ 33*9bf24f59SEelco Chaudron struct mask_cache_entry __percpu *mask_cache; 34*9bf24f59SEelco Chaudron }; 35*9bf24f59SEelco Chaudron 36eac87c41SEelco Chaudron struct mask_count { 37eac87c41SEelco Chaudron int index; 38eac87c41SEelco Chaudron u64 counter; 39eac87c41SEelco Chaudron }; 40eac87c41SEelco Chaudron 414bc63b1bSTonghao Zhang struct mask_array { 424bc63b1bSTonghao Zhang struct rcu_head rcu; 434bc63b1bSTonghao Zhang int count, max; 44eac87c41SEelco Chaudron u64 __percpu *masks_usage_cntr; 45eac87c41SEelco Chaudron u64 *masks_usage_zero_cntr; 46eac87c41SEelco Chaudron struct u64_stats_sync syncp; 474bc63b1bSTonghao Zhang struct sw_flow_mask __rcu *masks[]; 484bc63b1bSTonghao Zhang }; 494bc63b1bSTonghao Zhang 50b637e498SPravin B Shelar struct table_instance { 51ee9c5e67SKent Overstreet struct hlist_head *buckets; 52b637e498SPravin B Shelar unsigned int n_buckets; 53e6445719SPravin B Shelar struct rcu_head rcu; 54e6445719SPravin B Shelar int node_ver; 55e6445719SPravin B Shelar u32 hash_seed; 56e6445719SPravin B Shelar bool keep_flows; 57e6445719SPravin B Shelar }; 58e6445719SPravin B Shelar 59b637e498SPravin B Shelar struct flow_table { 60b637e498SPravin B Shelar struct table_instance __rcu *ti; 6174ed7ab9SJoe Stringer struct table_instance __rcu *ufid_ti; 62*9bf24f59SEelco Chaudron struct mask_cache __rcu *mask_cache; 634bc63b1bSTonghao Zhang struct mask_array __rcu *mask_array; 64b637e498SPravin B Shelar unsigned long last_rehash; 65b637e498SPravin B Shelar unsigned int count; 6674ed7ab9SJoe Stringer unsigned int ufid_count; 67b637e498SPravin B Shelar }; 68b637e498SPravin B Shelar 6963e7959cSJarno Rajahalme extern struct kmem_cache *flow_stats_cache; 7063e7959cSJarno Rajahalme 71e6445719SPravin B Shelar int ovs_flow_init(void); 72e6445719SPravin B Shelar void ovs_flow_exit(void); 73e6445719SPravin B Shelar 7423dabf88SJarno Rajahalme struct sw_flow *ovs_flow_alloc(void); 75e6445719SPravin B Shelar void ovs_flow_free(struct sw_flow *, bool deferred); 76e6445719SPravin B Shelar 77b637e498SPravin B Shelar int ovs_flow_tbl_init(struct flow_table *); 7812eb18f7SThomas Graf int ovs_flow_tbl_count(const struct flow_table *table); 799b996e54SPravin B Shelar void ovs_flow_tbl_destroy(struct flow_table *table); 80b637e498SPravin B Shelar int ovs_flow_tbl_flush(struct flow_table *flow_table); 81e6445719SPravin B Shelar 82618ed0c8SPravin B Shelar int ovs_flow_tbl_insert(struct flow_table *table, struct sw_flow *flow, 8312eb18f7SThomas Graf const struct sw_flow_mask *mask); 84e6445719SPravin B Shelar void ovs_flow_tbl_remove(struct flow_table *table, struct sw_flow *flow); 851bd7116fSAndy Zhou int ovs_flow_tbl_num_masks(const struct flow_table *table); 86*9bf24f59SEelco Chaudron u32 ovs_flow_tbl_masks_cache_size(const struct flow_table *table); 87*9bf24f59SEelco Chaudron int ovs_flow_tbl_masks_cache_resize(struct flow_table *table, u32 size); 88b637e498SPravin B Shelar struct sw_flow *ovs_flow_tbl_dump_next(struct table_instance *table, 89e6445719SPravin B Shelar u32 *bucket, u32 *idx); 905bb50632SAndy Zhou struct sw_flow *ovs_flow_tbl_lookup_stats(struct flow_table *, 911bd7116fSAndy Zhou const struct sw_flow_key *, 9204b7d136STonghao Zhang u32 skb_hash, 939d2f627bSEelco Chaudron u32 *n_mask_hit, 949d2f627bSEelco Chaudron u32 *n_cache_hit); 955bb50632SAndy Zhou struct sw_flow *ovs_flow_tbl_lookup(struct flow_table *, 965bb50632SAndy Zhou const struct sw_flow_key *); 974a46b24eSAlex Wang struct sw_flow *ovs_flow_tbl_lookup_exact(struct flow_table *tbl, 9812eb18f7SThomas Graf const struct sw_flow_match *match); 9974ed7ab9SJoe Stringer struct sw_flow *ovs_flow_tbl_lookup_ufid(struct flow_table *, 10074ed7ab9SJoe Stringer const struct sw_flow_id *); 10174ed7ab9SJoe Stringer 10274ed7ab9SJoe Stringer bool ovs_flow_cmp(const struct sw_flow *, const struct sw_flow_match *); 103e6445719SPravin B Shelar 104e6445719SPravin B Shelar void ovs_flow_mask_key(struct sw_flow_key *dst, const struct sw_flow_key *src, 105ae5f2fb1SJesse Gross bool full, const struct sw_flow_mask *mask); 106eac87c41SEelco Chaudron 107eac87c41SEelco Chaudron void ovs_flow_masks_rebalance(struct flow_table *table); 108eac87c41SEelco Chaudron 109e6445719SPravin B Shelar #endif /* flow_table.h */ 110