wlcore: sdio: Fix crash on wlcore_probe_of when failing to parse/map irq
[deliverable/linux.git] / net / openvswitch / actions.c
index 879185fe183fd0ffa2bf037725faf0a8eb5f166a..1ecbd7715f6d973d1dd60b33791482949aa3a589 100644 (file)
@@ -137,11 +137,23 @@ static bool is_flow_key_valid(const struct sw_flow_key *key)
        return !!key->eth.type;
 }
 
+static void update_ethertype(struct sk_buff *skb, struct ethhdr *hdr,
+                            __be16 ethertype)
+{
+       if (skb->ip_summed == CHECKSUM_COMPLETE) {
+               __be16 diff[] = { ~(hdr->h_proto), ethertype };
+
+               skb->csum = ~csum_partial((char *)diff, sizeof(diff),
+                                       ~skb->csum);
+       }
+
+       hdr->h_proto = ethertype;
+}
+
 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)
@@ -160,9 +172,7 @@ static int push_mpls(struct sk_buff *skb, struct sw_flow_key *key,
 
        skb_postpush_rcsum(skb, new_mpls_lse, MPLS_HLEN);
 
-       hdr = eth_hdr(skb);
-       hdr->h_proto = mpls->mpls_ethertype;
-
+       update_ethertype(skb, eth_hdr(skb), mpls->mpls_ethertype);
        if (!skb->inner_protocol)
                skb_set_inner_protocol(skb, skb->protocol);
        skb->protocol = mpls->mpls_ethertype;
@@ -193,7 +203,7 @@ static int pop_mpls(struct sk_buff *skb, struct sw_flow_key *key,
         * field correctly in the presence of VLAN tags.
         */
        hdr = (struct ethhdr *)(skb_mpls_header(skb) - ETH_HLEN);
-       hdr->h_proto = ethertype;
+       update_ethertype(skb, hdr, ethertype);
        if (eth_p_mpls(skb->protocol))
                skb->protocol = ethertype;
 
@@ -740,6 +750,14 @@ static void do_output(struct datapath *dp, struct sk_buff *skb, int out_port,
 
        if (likely(vport)) {
                u16 mru = OVS_CB(skb)->mru;
+               u32 cutlen = OVS_CB(skb)->cutlen;
+
+               if (unlikely(cutlen > 0)) {
+                       if (skb->len - cutlen > ETH_HLEN)
+                               pskb_trim(skb, skb->len - cutlen);
+                       else
+                               pskb_trim(skb, ETH_HLEN);
+               }
 
                if (likely(!mru || (skb->len <= mru + ETH_HLEN))) {
                        ovs_vport_send(vport, skb);
@@ -765,7 +783,8 @@ 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,
-                           const struct nlattr *actions, int actions_len)
+                           const struct nlattr *actions, int actions_len,
+                           uint32_t cutlen)
 {
        struct dp_upcall_info upcall;
        const struct nlattr *a;
@@ -812,7 +831,7 @@ static int output_userspace(struct datapath *dp, struct sk_buff *skb,
                } /* End of switch. */
        }
 
-       return ovs_dp_upcall(dp, skb, key, &upcall);
+       return ovs_dp_upcall(dp, skb, key, &upcall, cutlen);
 }
 
 static int sample(struct datapath *dp, struct sk_buff *skb,
@@ -822,6 +841,7 @@ static int sample(struct datapath *dp, struct sk_buff *skb,
        const struct nlattr *acts_list = NULL;
        const struct nlattr *a;
        int rem;
+       u32 cutlen = 0;
 
        for (a = nla_data(attr), rem = nla_len(attr); rem > 0;
                 a = nla_next(a, &rem)) {
@@ -848,13 +868,24 @@ static int sample(struct datapath *dp, struct sk_buff *skb,
                return 0;
 
        /* The only known usage of sample action is having a single user-space
+        * action, or having a truncate action followed by a single user-space
         * action. Treat this usage as a special case.
         * The output_userspace() should clone the skb to be sent to the
         * user space. This skb will be consumed by its caller.
         */
+       if (unlikely(nla_type(a) == OVS_ACTION_ATTR_TRUNC)) {
+               struct ovs_action_trunc *trunc = nla_data(a);
+
+               if (skb->len > trunc->max_len)
+                       cutlen = skb->len - trunc->max_len;
+
+               a = nla_next(a, &rem);
+       }
+
        if (likely(nla_type(a) == OVS_ACTION_ATTR_USERSPACE &&
                   nla_is_last(a, rem)))
-               return output_userspace(dp, skb, key, a, actions, actions_len);
+               return output_userspace(dp, skb, key, a, actions,
+                                       actions_len, cutlen);
 
        skb = skb_clone(skb, GFP_ATOMIC);
        if (!skb)
@@ -1041,6 +1072,7 @@ static int do_execute_actions(struct datapath *dp, struct sk_buff *skb,
                        if (out_skb)
                                do_output(dp, out_skb, prev_port, key);
 
+                       OVS_CB(skb)->cutlen = 0;
                        prev_port = -1;
                }
 
@@ -1049,8 +1081,18 @@ static int do_execute_actions(struct datapath *dp, struct sk_buff *skb,
                        prev_port = nla_get_u32(a);
                        break;
 
+               case OVS_ACTION_ATTR_TRUNC: {
+                       struct ovs_action_trunc *trunc = nla_data(a);
+
+                       if (skb->len > trunc->max_len)
+                               OVS_CB(skb)->cutlen = skb->len - trunc->max_len;
+                       break;
+               }
+
                case OVS_ACTION_ATTR_USERSPACE:
-                       output_userspace(dp, skb, key, a, attr, len);
+                       output_userspace(dp, skb, key, a, attr,
+                                                    len, OVS_CB(skb)->cutlen);
+                       OVS_CB(skb)->cutlen = 0;
                        break;
 
                case OVS_ACTION_ATTR_HASH:
This page took 0.029658 seconds and 5 git commands to generate.