datapath: Clean-up previous undefined symbol commit
[sliver-openvswitch.git] / datapath / flow.c
index 4dc9488..a9c7422 100644 (file)
@@ -7,12 +7,14 @@
  */
 
 #include "flow.h"
+#include "datapath.h"
 #include <linux/netdevice.h>
 #include <linux/etherdevice.h>
 #include <linux/if_ether.h>
 #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>
 #include <linux/tcp.h>
 #include <linux/udp.h>
 #include <linux/icmp.h>
+#include <net/inet_ecn.h>
 #include <net/ip.h>
 
 #include "compat.h"
 
 struct kmem_cache *flow_cache;
+static unsigned int hash_seed;
 
 struct arp_eth_header
 {
@@ -88,14 +92,8 @@ static inline int icmphdr_ok(struct sk_buff *skb)
 #define TCP_FLAGS_OFFSET 13
 #define TCP_FLAG_MASK 0x3f
 
-static inline struct ovs_tcphdr *ovs_tcp_hdr(const struct sk_buff *skb)
-{
-       return (struct ovs_tcphdr *)skb_transport_header(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)) {
@@ -107,12 +105,12 @@ void flow_used(struct sw_flow *flow, struct sk_buff *skb)
                }
        }
 
-       spin_lock_irqsave(&flow->lock, flags);
-       getnstimeofday(&flow->used);
+       spin_lock_bh(&flow->lock);
+       flow->used = jiffies;
        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)
@@ -133,7 +131,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;
@@ -141,6 +139,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)
 {
@@ -200,8 +204,9 @@ int flow_extract(struct sk_buff *skb, u16 in_port, struct odp_flow_key *key)
        int nh_ofs;
 
        memset(key, 0, sizeof *key);
-       key->dl_vlan = htons(ODP_VLAN_NONE);
+       key->tun_id = OVS_CB(skb)->tun_id;
        key->in_port = in_port;
+       key->dl_vlan = htons(ODP_VLAN_NONE);
 
        if (skb->len < sizeof *eth)
                return 0;
@@ -231,7 +236,7 @@ int flow_extract(struct sk_buff *skb, u16 in_port, struct odp_flow_key *key)
                struct vlan_hdr *vh = (struct vlan_hdr*)(skb->data + nh_ofs);
                key->dl_type = vh->h_vlan_encapsulated_proto;
                key->dl_vlan = vh->h_vlan_TCI & htons(VLAN_VID_MASK);
-               key->dl_vlan_pcp = (ntohs(vh->h_vlan_TCI) & 0xe000) >> 13;
+               key->dl_vlan_pcp = (ntohs(vh->h_vlan_TCI) & VLAN_PCP_MASK) >> VLAN_PCP_SHIFT;
                nh_ofs += sizeof(struct vlan_hdr);
        }
        memcpy(key->dl_src, eth->h_source, ETH_ALEN);
@@ -244,7 +249,7 @@ int flow_extract(struct sk_buff *skb, u16 in_port, struct odp_flow_key *key)
                int th_ofs = nh_ofs + nh->ihl * 4;
                key->nw_src = nh->saddr;
                key->nw_dst = nh->daddr;
-               key->nw_tos = nh->tos & 0xfc;
+               key->nw_tos = nh->tos & ~INET_ECN_MASK;
                key->nw_proto = nh->protocol;
                skb_set_transport_header(skb, th_ofs);
 
@@ -295,7 +300,7 @@ int flow_extract(struct sk_buff *skb, u16 in_port, struct odp_flow_key *key)
 
                arp = (struct arp_eth_header *)skb_network_header(skb);
 
-               if (arp->ar_hrd == htons(1)
+               if (arp->ar_hrd == htons(ARPHRD_ETHER)
                                && arp->ar_pro == htons(ETH_P_IP)
                                && arp->ar_hln == ETH_ALEN
                                && arp->ar_pln == 4) {
@@ -317,6 +322,24 @@ int flow_extract(struct sk_buff *skb, u16 in_port, struct odp_flow_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 odp_flow_key *key)
+{
+       return jhash2((u32*)key, sizeof *key / sizeof(u32), hash_seed);
+}
+
+int flow_cmp(const struct tbl_node *node, void *key2_)
+{
+       const struct odp_flow_key *key1 = &flow_cast(node)->key;
+       const struct odp_flow_key *key2 = key2_;
+
+       return !memcmp(key1, key2, sizeof(struct odp_flow_key));
+}
+
 /* Initializes the flow module.
  * Returns zero if successful or a negative error code. */
 int flow_init(void)
@@ -326,6 +349,8 @@ int flow_init(void)
        if (flow_cache == NULL)
                return -ENOMEM;
 
+       get_random_bytes(&hash_seed, sizeof hash_seed);
+
        return 0;
 }