datapath: Account for rename to vlan_insert_tag_set_proto()
[cascardo/ovs.git] / datapath / actions.c
index c3f9427..9a49cd5 100644 (file)
 #include <net/ipv6.h>
 #include <net/checksum.h>
 #include <net/dsfield.h>
+#include <net/mpls.h>
 #include <net/sctp/checksum.h>
 
 #include "datapath.h"
 #include "gso.h"
-#include "mpls.h"
 #include "vlan.h"
 #include "vport.h"
 
@@ -62,7 +62,8 @@ struct action_fifo {
 
 static struct action_fifo __percpu *action_fifos;
 #define EXEC_ACTIONS_LEVEL_LIMIT 4   /* limit used to detect packet
-                                       looping by the network stack */
+                                     * looping by the network stack
+                                     */
 static DEFINE_PER_CPU(int, exec_actions_level);
 
 static void action_fifo_init(struct action_fifo *fifo)
@@ -71,7 +72,7 @@ static void action_fifo_init(struct action_fifo *fifo)
        fifo->tail = 0;
 }
 
-static bool action_fifo_is_empty(struct action_fifo *fifo)
+static bool action_fifo_is_empty(const struct action_fifo *fifo)
 {
        return (fifo->head == fifo->tail);
 }
@@ -94,7 +95,7 @@ static struct deferred_action *action_fifo_put(struct action_fifo *fifo)
 
 /* Return queue entry if fifo is not full */
 static struct deferred_action *add_deferred_actions(struct sk_buff *skb,
-                                                   struct sw_flow_key *key,
+                                                   const struct sw_flow_key *key,
                                                    const struct nlattr *attr)
 {
        struct action_fifo *fifo;
@@ -116,7 +117,7 @@ static void invalidate_flow_key(struct sw_flow_key *key)
        key->eth.type = htons(0);
 }
 
-static bool is_flow_key_valid(struct sw_flow_key *key)
+static bool is_flow_key_valid(const struct sw_flow_key *key)
 {
        return !!key->eth.type;
 }
@@ -132,25 +133,16 @@ static int make_writable(struct sk_buff *skb, int write_len)
        return pskb_expand_head(skb, 0, 0, GFP_ATOMIC);
 }
 
-/* The end of the mac header.
- *
- * For non-MPLS skbs this will correspond to the network header.
- * For MPLS skbs it will be before the network_header as the MPLS
- * label stack lies between the end of the mac header and the network
- * header. That is, for MPLS skbs the end of the mac header
- * is the top of the MPLS label stack.
- */
-static unsigned char *mac_header_end(const struct sk_buff *skb)
-{
-       return skb_mac_header(skb) + skb->mac_len;
-}
-
 static int push_mpls(struct sk_buff *skb, struct sw_flow_key *key,
                     const struct ovs_action_push_mpls *mpls)
 {
        __be32 *new_mpls_lse;
        struct ethhdr *hdr;
 
+       /* Networking stack do not allow simultaneous Tunnel and MPLS GSO. */
+       if (skb_encapsulation(skb))
+               return -ENOTSUPP;
+
        if (skb_cow_head(skb, MPLS_HLEN) < 0)
                return -ENOMEM;
 
@@ -159,7 +151,7 @@ static int push_mpls(struct sk_buff *skb, struct sw_flow_key *key,
                skb->mac_len);
        skb_reset_mac_header(skb);
 
-       new_mpls_lse = (__be32 *)mac_header_end(skb);
+       new_mpls_lse = (__be32 *)skb_mpls_header(skb);
        *new_mpls_lse = mpls->mpls_lse;
 
        if (skb->ip_summed == CHECKSUM_COMPLETE)
@@ -171,6 +163,7 @@ static int push_mpls(struct sk_buff *skb, struct sw_flow_key *key,
        if (!ovs_skb_get_inner_protocol(skb))
                ovs_skb_set_inner_protocol(skb, skb->protocol);
        skb->protocol = mpls->mpls_ethertype;
+
        invalidate_flow_key(key);
        return 0;
 }
@@ -187,7 +180,7 @@ static int pop_mpls(struct sk_buff *skb, struct sw_flow_key *key,
 
        if (skb->ip_summed == CHECKSUM_COMPLETE)
                skb->csum = csum_sub(skb->csum,
-                                    csum_partial(mac_header_end(skb),
+                                    csum_partial(skb_mpls_header(skb),
                                                  MPLS_HLEN, 0));
 
        memmove(skb_mac_header(skb) + MPLS_HLEN, skb_mac_header(skb),
@@ -196,13 +189,14 @@ static int pop_mpls(struct sk_buff *skb, struct sw_flow_key *key,
        __skb_pull(skb, MPLS_HLEN);
        skb_reset_mac_header(skb);
 
-       /* mac_header_end() is used to locate the ethertype
+       /* skb_mpls_header() is used to locate the ethertype
         * field correctly in the presence of VLAN tags.
         */
-       hdr = (struct ethhdr *)(mac_header_end(skb) - ETH_HLEN);
+       hdr = (struct ethhdr *)(skb_mpls_header(skb) - ETH_HLEN);
        hdr->h_proto = ethertype;
        if (eth_p_mpls(skb->protocol))
                skb->protocol = ethertype;
+
        invalidate_flow_key(key);
        return 0;
 }
@@ -210,13 +204,14 @@ static int pop_mpls(struct sk_buff *skb, struct sw_flow_key *key,
 static int set_mpls(struct sk_buff *skb, struct sw_flow_key *key,
                    const __be32 *mpls_lse)
 {
-       __be32 *stack = (__be32 *)mac_header_end(skb);
+       __be32 *stack;
        int err;
 
        err = make_writable(skb, skb->mac_len + MPLS_HLEN);
        if (unlikely(err))
                return err;
 
+       stack = (__be32 *)skb_mpls_header(skb);
        if (skb->ip_summed == CHECKSUM_COMPLETE) {
                __be32 diff[] = { ~(*stack), *mpls_lse };
                skb->csum = ~csum_partial((char *)diff, sizeof(diff),
@@ -297,9 +292,8 @@ static int push_vlan(struct sk_buff *skb, struct sw_flow_key *key,
                /* push down current VLAN tag */
                current_tag = vlan_tx_tag_get(skb);
 
-               if (!__vlan_put_tag(skb, skb->vlan_proto, current_tag))
+               if (!vlan_insert_tag_set_proto(skb, skb->vlan_proto, current_tag))
                        return -ENOMEM;
-
                /* Update mac_len for subsequent MPLS actions */
                skb->mac_len += VLAN_HLEN;
 
@@ -481,7 +475,7 @@ static int set_ipv6(struct sk_buff *skb, struct sw_flow_key *key,
 
        if (memcmp(ipv6_key->ipv6_dst, daddr, sizeof(ipv6_key->ipv6_dst))) {
                unsigned int offset = 0;
-               int flags = OVS_IP6T_FH_F_SKIP_RH;
+               int flags = IP6_FH_F_SKIP_RH;
                bool recalc_csum = true;
 
                if (ipv6_ext_hdr(nh->nexthdr))
@@ -628,10 +622,10 @@ static void do_output(struct datapath *dp, struct sk_buff *skb, int out_port)
 static int output_userspace(struct datapath *dp, struct sk_buff *skb,
                            struct sw_flow_key *key, const struct nlattr *attr)
 {
+       struct ovs_tunnel_info info;
        struct dp_upcall_info upcall;
        const struct nlattr *a;
        int rem;
-       struct ovs_tunnel_info info;
 
        upcall.cmd = OVS_PACKET_CMD_ACTION;
        upcall.userdata = NULL;
@@ -671,11 +665,6 @@ static int output_userspace(struct datapath *dp, struct sk_buff *skb,
        return ovs_dp_upcall(dp, skb, key, &upcall);
 }
 
-static bool last_action(const struct nlattr *a, int rem)
-{
-       return a->nla_len == rem;
-}
-
 static int sample(struct datapath *dp, struct sk_buff *skb,
                  struct sw_flow_key *key, const struct nlattr *attr)
 {
@@ -710,7 +699,7 @@ static int sample(struct datapath *dp, struct sk_buff *skb,
         * user space. This skb will be consumed by its caller.
         */
        if (likely(nla_type(a) == OVS_ACTION_ATTR_USERSPACE &&
-                  last_action(a, rem)))
+                  nla_is_last(a, rem)))
                return output_userspace(dp, skb, key, a);
 
        skb = skb_clone(skb, GFP_ATOMIC);
@@ -796,7 +785,8 @@ static int execute_set_action(struct sk_buff *skb, struct sw_flow_key *key,
 }
 
 static int execute_recirc(struct datapath *dp, struct sk_buff *skb,
-                         struct sw_flow_key *key, const struct nlattr *a, int rem)
+                         struct sw_flow_key *key,
+                         const struct nlattr *a, int rem)
 {
        struct deferred_action *da;
 
@@ -806,11 +796,10 @@ static int execute_recirc(struct datapath *dp, struct sk_buff *skb,
                err = ovs_flow_key_update(skb, key);
                if (err)
                        return err;
-
        }
        BUG_ON(!is_flow_key_valid(key));
 
-       if (!last_action(a, rem)) {
+       if (!nla_is_last(a, rem)) {
                /* Recirc action is the not the last action
                 * of the action list, need to clone the skb.
                 */
@@ -897,7 +886,7 @@ static int do_execute_actions(struct datapath *dp, struct sk_buff *skb,
 
                case OVS_ACTION_ATTR_RECIRC:
                        err = execute_recirc(dp, skb, key, a, rem);
-                       if (last_action(a, rem)) {
+                       if (nla_is_last(a, rem)) {
                                /* If this is the last action, the skb has
                                 * been consumed or freed.
                                 * Return immediately.
@@ -941,13 +930,14 @@ static void process_deferred_actions(struct datapath *dp)
        do {
                struct deferred_action *da = action_fifo_get(fifo);
                struct sk_buff *skb = da->skb;
+               struct sw_flow_key *key = &da->pkt_key;
                const struct nlattr *actions = da->actions;
 
                if (actions)
-                       do_execute_actions(dp, skb, &da->pkt_key, actions,
+                       do_execute_actions(dp, skb, key, actions,
                                           nla_len(actions));
                else
-                       ovs_dp_process_packet(skb, &da->pkt_key);
+                       ovs_dp_process_packet(skb, key);
        } while (!action_fifo_is_empty(fifo));
 
        /* Reset FIFO for the next packet.  */
@@ -956,7 +946,8 @@ static void process_deferred_actions(struct datapath *dp)
 
 /* Execute a list of actions against 'skb'. */
 int ovs_execute_actions(struct datapath *dp, struct sk_buff *skb,
-                       struct sw_flow_key *key, struct sw_flow_actions *acts)
+                       const struct sw_flow_actions *acts,
+                       struct sw_flow_key *key)
 {
        int level = this_cpu_read(exec_actions_level);
        int err;
@@ -971,8 +962,8 @@ int ovs_execute_actions(struct datapath *dp, struct sk_buff *skb,
        }
 
        this_cpu_inc(exec_actions_level);
-
-       err = do_execute_actions(dp, skb, key, acts->actions, acts->actions_len);
+       err = do_execute_actions(dp, skb, key,
+                                acts->actions, acts->actions_len);
 
        if (!level)
                process_deferred_actions(dp);