X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=datapath%2Fflow.c;h=bf50e94cd47fc19a941f3c3408a8e53e01d85822;hb=79903dd171cd7bdbb52710b98dbaa5de1537de87;hp=3b95e3bbcc135c03abca0ae9e3714f3a895be5c2;hpb=f5e86186f3ca8cd66a1a5a923417fb60af154447;p=sliver-openvswitch.git diff --git a/datapath/flow.c b/datapath/flow.c index 3b95e3bbc..bf50e94cd 100644 --- a/datapath/flow.c +++ b/datapath/flow.c @@ -14,6 +14,7 @@ #include #include #include +#include #include #include #include @@ -25,11 +26,13 @@ #include #include #include +#include #include #include "compat.h" struct kmem_cache *flow_cache; +static unsigned int hash_seed; struct arp_eth_header { @@ -96,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)) { @@ -108,12 +110,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); + 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) @@ -134,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; @@ -142,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) { @@ -201,8 +209,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; @@ -318,6 +327,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) @@ -327,6 +354,8 @@ int flow_init(void) if (flow_cache == NULL) return -ENOMEM; + get_random_bytes(&hash_seed, sizeof hash_seed); + return 0; }