/*
* Distributed under the terms of the GNU GPL version 2.
- * Copyright (c) 2007, 2008, 2009 Nicira Networks.
+ * Copyright (c) 2007, 2008, 2009, 2010 Nicira Networks.
*
* Significant portions of this file may be copied from parts of the Linux
* kernel, by Linus Torvalds and others.
*/
#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
{
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)) {
}
}
- spin_lock_irqsave(&flow->lock, flags);
- getnstimeofday(&flow->used);
+ spin_lock_bh(&flow->lock);
+ ktime_get_ts(&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)
/* Frees 'flow' immediately. */
-void flow_free(struct sw_flow *flow)
+static void flow_free(struct sw_flow *flow)
{
if (unlikely(!flow))
return;
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)
{
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;
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) & VLAN_PCP_MASK) >> VLAN_PCP_SHIFT;
nh_ofs += sizeof(struct vlan_hdr);
}
memcpy(key->dl_src, eth->h_source, ETH_ALEN);
int th_ofs = nh_ofs + nh->ihl * 4;
key->nw_src = nh->saddr;
key->nw_dst = nh->daddr;
+ key->nw_tos = nh->tos & ~INET_ECN_MASK;
key->nw_proto = nh->protocol;
skb_set_transport_header(skb, th_ofs);
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) {
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)
if (flow_cache == NULL)
return -ENOMEM;
+ get_random_bytes(&hash_seed, sizeof hash_seed);
+
return 0;
}