Merge "master" into "wdp".
[sliver-openvswitch.git] / datapath / flow.c
index d75e7a8..7265350 100644 (file)
@@ -14,6 +14,7 @@
 #include <linux/if_vlan.h>
 #include <net/llc_pdu.h>
 #include <linux/kernel.h>
+#include <linux/jhash.h>
 #include <linux/jiffies.h>
 #include <linux/llc.h>
 #include <linux/module.h>
@@ -31,6 +32,7 @@
 #include "compat.h"
 
 struct kmem_cache *flow_cache;
+static unsigned int hash_seed;
 
 struct arp_eth_header
 {
@@ -97,7 +99,6 @@ static inline struct ovs_tcphdr *ovs_tcp_hdr(const struct sk_buff *skb)
 
 void flow_used(struct sw_flow *flow, struct sk_buff *skb)
 {
-       unsigned long flags;
        u8 tcp_flags = 0;
 
        if (flow->key.dl_type == htons(ETH_P_IP) && iphdr_ok(skb)) {
@@ -109,12 +110,12 @@ void flow_used(struct sw_flow *flow, struct sk_buff *skb)
                }
        }
 
-       spin_lock_irqsave(&flow->lock, flags);
+       spin_lock_bh(&flow->lock);
        getnstimeofday(&flow->used);
        flow->packet_count++;
        flow->byte_count += skb->len;
        flow->tcp_flags |= tcp_flags;
-       spin_unlock_irqrestore(&flow->lock, flags);
+       spin_unlock_bh(&flow->lock);
 }
 
 struct sw_flow_actions *flow_actions_alloc(size_t n_actions)
@@ -135,7 +136,7 @@ struct sw_flow_actions *flow_actions_alloc(size_t n_actions)
 
 
 /* Frees 'flow' immediately. */
-void flow_free(struct sw_flow *flow)
+static void flow_free(struct sw_flow *flow)
 {
        if (unlikely(!flow))
                return;
@@ -143,6 +144,12 @@ void flow_free(struct sw_flow *flow)
        kmem_cache_free(flow_cache, flow);
 }
 
+void flow_free_tbl(struct tbl_node *node)
+{
+       struct sw_flow *flow = flow_cast(node);
+       flow_free(flow);
+}
+
 /* RCU callback used by flow_deferred_free. */
 static void rcu_free_flow_callback(struct rcu_head *rcu)
 {
@@ -202,7 +209,9 @@ int flow_extract(struct sk_buff *skb, u16 in_port, struct xflow_key *key)
        int nh_ofs;
 
        memset(key, 0, sizeof *key);
+       key->tun_id = OVS_CB(skb)->tun_id;
        key->in_port = in_port;
+       key->dl_tci = htons(0);
 
        if (skb->len < sizeof *eth)
                return 0;
@@ -317,6 +326,24 @@ int flow_extract(struct sk_buff *skb, u16 in_port, struct xflow_key *key)
        return retval;
 }
 
+struct sw_flow *flow_cast(const struct tbl_node *node)
+{
+       return container_of(node, struct sw_flow, tbl_node);
+}
+
+u32 flow_hash(const struct xflow_key *key)
+{
+       return jhash2((u32*)key, sizeof *key / sizeof(u32), hash_seed);
+}
+
+int flow_cmp(const struct tbl_node *node, void *key2_)
+{
+       const struct xflow_key *key1 = &flow_cast(node)->key;
+       const struct xflow_key *key2 = key2_;
+
+       return !memcmp(key1, key2, sizeof(struct xflow_key));
+}
+
 /* Initializes the flow module.
  * Returns zero if successful or a negative error code. */
 int flow_init(void)
@@ -326,6 +353,8 @@ int flow_init(void)
        if (flow_cache == NULL)
                return -ENOMEM;
 
+       get_random_bytes(&hash_seed, sizeof hash_seed);
+
        return 0;
 }