datapath: Simplify vport_send() error handling.
authorPravin B Shelar <pshelar@nicira.com>
Mon, 22 Dec 2014 12:53:02 +0000 (04:53 -0800)
committerPravin B Shelar <pshelar@nicira.com>
Wed, 24 Dec 2014 00:36:49 +0000 (16:36 -0800)
Today vport-send has complex error handling because it involves
freeing skb and updating stats depending on return value from
vport send implementation.
This can be simplified by delegating responsibility of freeing
skb to the vport implementation for all cases. So that
vport-send needs just update stats.

Signed-off-by: Pravin B Shelar <pshelar@nicira.com>
Acked-by: Jesse Gross <jesse@nicira.com>
datapath/linux/compat/vxlan.c
datapath/vport-geneve.c
datapath/vport-gre.c
datapath/vport-lisp.c
datapath/vport-vxlan.c
datapath/vport.c

index b9fd8ba..0389b28 100644 (file)
@@ -187,8 +187,10 @@ int vxlan_xmit_skb(struct vxlan_sock *vs,
 
        /* Need space for new headers (invalidates iph ptr) */
        err = skb_cow_head(skb, min_headroom);
-       if (unlikely(err))
+       if (unlikely(err)) {
+               kfree_skb(skb);
                return err;
+       }
 
        if (vlan_tx_tag_present(skb)) {
                if (unlikely(!__vlan_put_tag(skb,
@@ -219,7 +221,7 @@ int vxlan_xmit_skb(struct vxlan_sock *vs,
 
        skb = handle_offloads(skb);
        if (IS_ERR(skb))
-               return 0;
+               return PTR_ERR(skb);
 
        return iptunnel_xmit(vs->sock->sk, rt, skb, src, dst, IPPROTO_UDP,
                             tos, ttl, df, false);
index a65dcb6..d54101e 100644 (file)
@@ -368,8 +368,10 @@ static int geneve_send(struct vport *vport, struct sk_buff *skb)
        int sent_len;
        int err;
 
-       if (unlikely(!OVS_CB(skb)->egress_tun_info))
-               return -EINVAL;
+       if (unlikely(!OVS_CB(skb)->egress_tun_info)) {
+               err = -EINVAL;
+               goto error;
+       }
 
        tun_key = &OVS_CB(skb)->egress_tun_info->tunnel;
 
@@ -406,6 +408,7 @@ static int geneve_send(struct vport *vport, struct sk_buff *skb)
                                             skb->vlan_proto,
                                             vlan_tx_tag_get(skb)))) {
                        err = -ENOMEM;
+                       skb = NULL;
                        goto err_free_rt;
                }
                vlan_set_tci(skb, 0);
@@ -422,7 +425,8 @@ static int geneve_send(struct vport *vport, struct sk_buff *skb)
        /* Offloading */
        skb = handle_offloads(skb);
        if (IS_ERR(skb)) {
-               err = 0;
+               err = PTR_ERR(skb);
+               skb = NULL;
                goto err_free_rt;
        }
 
@@ -439,6 +443,7 @@ static int geneve_send(struct vport *vport, struct sk_buff *skb)
 err_free_rt:
        ip_rt_put(rt);
 error:
+       kfree_skb(skb);
        return err;
 }
 
index 41c025d..daf7fc3 100644 (file)
@@ -72,7 +72,7 @@ static struct sk_buff *__build_header(struct sk_buff *skb,
        tun_key = &OVS_CB(skb)->egress_tun_info->tunnel;
        skb = gre_handle_offloads(skb, !!(tun_key->tun_flags & TUNNEL_CSUM));
        if (IS_ERR(skb))
-               return NULL;
+               return skb;
 
        tpi.flags = filter_tnl_flags(tun_key->tun_flags) | gre64_flag;
 
@@ -179,6 +179,7 @@ static int __send(struct vport *vport, struct sk_buff *skb,
                                             skb->vlan_proto,
                                             vlan_tx_tag_get(skb)))) {
                        err = -ENOMEM;
+                       skb = NULL;
                        goto err_free_rt;
                }
                vlan_set_tci(skb, 0);
@@ -186,8 +187,9 @@ static int __send(struct vport *vport, struct sk_buff *skb,
 
        /* Push Tunnel header. */
        skb = __build_header(skb, tunnel_hlen, seq, gre64_flag);
-       if (unlikely(!skb)) {
-               err = 0;
+       if (IS_ERR(skb)) {
+               err = PTR_ERR(skb);
+               skb = NULL;
                goto err_free_rt;
        }
 
@@ -201,6 +203,7 @@ static int __send(struct vport *vport, struct sk_buff *skb,
 err_free_rt:
        ip_rt_put(rt);
 error:
+       kfree_skb(skb);
        return err;
 }
 
@@ -286,8 +289,10 @@ static int gre_send(struct vport *vport, struct sk_buff *skb)
 {
        int hlen;
 
-       if (unlikely(!OVS_CB(skb)->egress_tun_info))
+       if (unlikely(!OVS_CB(skb)->egress_tun_info)) {
+               kfree_skb(skb);
                return -EINVAL;
+       }
 
        hlen = ip_gre_calc_hlen(OVS_CB(skb)->egress_tun_info->tunnel.tun_flags);
 
@@ -370,8 +375,10 @@ static int gre64_send(struct vport *vport, struct sk_buff *skb)
                   GRE_HEADER_SECTION;          /* GRE SEQ */
        __be32 seq;
 
-       if (unlikely(!OVS_CB(skb)->egress_tun_info))
+       if (unlikely(!OVS_CB(skb)->egress_tun_info)) {
+               kfree_skb(skb);
                return -EINVAL;
+       }
 
        if (OVS_CB(skb)->egress_tun_info->tunnel.tun_flags & TUNNEL_CSUM)
                hlen += GRE_HEADER_SECTION;
index 04f11ac..db4d06f 100644 (file)
@@ -449,15 +449,17 @@ static int lisp_send(struct vport *vport, struct sk_buff *skb)
        int sent_len;
        int err;
 
-       if (unlikely(!OVS_CB(skb)->egress_tun_info))
-               return -EINVAL;
+       if (unlikely(!OVS_CB(skb)->egress_tun_info)) {
+               err = -EINVAL;
+               goto error;
+       }
 
        tun_key = &OVS_CB(skb)->egress_tun_info->tunnel;
 
        if (skb->protocol != htons(ETH_P_IP) &&
            skb->protocol != htons(ETH_P_IPV6)) {
-               kfree_skb(skb);
-               return 0;
+               err = 0;
+               goto error;
        }
 
        /* Route lookup */
@@ -500,7 +502,8 @@ static int lisp_send(struct vport *vport, struct sk_buff *skb)
        /* Offloading */
        skb = handle_offloads(skb);
        if (IS_ERR(skb)) {
-               err = 0;
+               err = PTR_ERR(skb);
+               skb = NULL;
                goto err_free_rt;
        }
 
@@ -517,6 +520,7 @@ static int lisp_send(struct vport *vport, struct sk_buff *skb)
 err_free_rt:
        ip_rt_put(rt);
 error:
+       kfree_skb(skb);
        return err;
 }
 
index 8689853..81347f2 100644 (file)
@@ -182,7 +182,9 @@ static int vxlan_tnl_send(struct vport *vport, struct sk_buff *skb)
                             htonl(be64_to_cpu(tun_key->tun_id) << 8));
        if (err < 0)
                ip_rt_put(rt);
+       return err;
 error:
+       kfree_skb(skb);
        return err;
 }
 
index 274e47f..e3f495e 100644 (file)
@@ -492,9 +492,9 @@ int ovs_vport_send(struct vport *vport, struct sk_buff *skb)
                u64_stats_update_end(&stats->syncp);
        } else if (sent < 0) {
                ovs_vport_record_error(vport, VPORT_E_TX_ERROR);
-               kfree_skb(skb);
-       } else
+       } else {
                ovs_vport_record_error(vport, VPORT_E_TX_DROPPED);
+       }
 
        return sent;
 }