datapath: Add support for lwtunnel
[cascardo/ovs.git] / datapath / flow.c
index 69b13b3..3375d7b 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2007-2014 Nicira, Inc.
+ * Copyright (c) 2007-2015 Nicira, Inc.
  *
  * This program is free software; you can redistribute it and/or
  * modify it under the terms of version 2 of the GNU General Public
@@ -48,7 +48,7 @@
 #include "datapath.h"
 #include "flow.h"
 #include "flow_netlink.h"
-
+#include "vport.h"
 #include "vlan.h"
 
 u64 ovs_flow_used_time(unsigned long flow_jiffies)
@@ -71,6 +71,7 @@ void ovs_flow_stats_update(struct sw_flow *flow, __be16 tcp_flags,
 {
        struct flow_stats *stats;
        int node = numa_node_id();
+       int len = skb->len + (skb_vlan_tag_present(skb) ? VLAN_HLEN : 0);
 
        stats = rcu_dereference(flow->stats[node]);
 
@@ -100,13 +101,15 @@ void ovs_flow_stats_update(struct sw_flow *flow, __be16 tcp_flags,
 
                                new_stats =
                                        kmem_cache_alloc_node(flow_stats_cache,
-                                                             GFP_THISNODE |
+                                                              GFP_NOWAIT |
+                                                              __GFP_THISNODE |
+                                                              __GFP_NOWARN |
                                                              __GFP_NOMEMALLOC,
                                                              node);
                                if (likely(new_stats)) {
                                        new_stats->used = jiffies;
                                        new_stats->packet_count = 1;
-                                       new_stats->byte_count = skb->len;
+                                       new_stats->byte_count = len;
                                        new_stats->tcp_flags = tcp_flags;
                                        spin_lock_init(&new_stats->lock);
 
@@ -121,7 +124,7 @@ void ovs_flow_stats_update(struct sw_flow *flow, __be16 tcp_flags,
 
        stats->used = jiffies;
        stats->packet_count++;
-       stats->byte_count += skb->len;
+       stats->byte_count += len;
        stats->tcp_flags |= tcp_flags;
 unlock:
        spin_unlock(&stats->lock);
@@ -330,7 +333,7 @@ static __be16 parse_ethertype(struct sk_buff *skb)
        proto = *(__be16 *) skb->data;
        __skb_pull(skb, sizeof(__be16));
 
-       if (ntohs(proto) >= ETH_P_802_3_MIN)
+       if (eth_proto_is_802_3(proto))
                return proto;
 
        if (skb->len < sizeof(struct llc_snap_hdr))
@@ -347,7 +350,7 @@ static __be16 parse_ethertype(struct sk_buff *skb)
 
        __skb_pull(skb, sizeof(struct llc_snap_hdr));
 
-       if (ntohs(llc->ethertype) >= ETH_P_802_3_MIN)
+       if (eth_proto_is_802_3(llc->ethertype))
                return llc->ethertype;
 
        return htons(ETH_P_802_2);
@@ -472,7 +475,7 @@ static int key_extract(struct sk_buff *skb, struct sw_flow_key *key)
         */
 
        key->eth.tci = 0;
-       if (vlan_tx_tag_present(skb))
+       if (skb_vlan_tag_present(skb))
                key->eth.tci = htons(vlan_get_tci(skb));
        else if (eth->h_proto == htons(ETH_P_8021Q))
                if (unlikely(parse_vlan(skb, key)))
@@ -681,19 +684,21 @@ int ovs_flow_key_update(struct sk_buff *skb, struct sw_flow_key *key)
        return key_extract(skb, key);
 }
 
-int ovs_flow_key_extract(const struct ovs_tunnel_info *tun_info,
+int ovs_flow_key_extract(const struct ip_tunnel_info *tun_info,
                         struct sk_buff *skb, struct sw_flow_key *key)
 {
        /* Extract metadata from packet. */
        if (tun_info) {
-               memcpy(&key->tun_key, &tun_info->tunnel, sizeof(key->tun_key));
+               if (ip_tunnel_info_af(tun_info) != AF_INET)
+                       return -EINVAL;
 
+               memcpy(&key->tun_key, &tun_info->key, sizeof(key->tun_key));
                BUILD_BUG_ON(((1 << (sizeof(tun_info->options_len) * 8)) - 1) >
                             sizeof(key->tun_opts));
 
-               if (tun_info->options) {
-                       memcpy(GENEVE_OPTS(key, tun_info->options_len),
-                              tun_info->options, tun_info->options_len);
+               if (tun_info->options_len) {
+                       ip_tunnel_info_opts_get(TUN_METADATA_OPTS(key, tun_info->options_len),
+                                               tun_info);
                        key->tun_opts_len = tun_info->options_len;
                } else {
                        key->tun_opts_len = 0;