datapath: Disable LRO from userspace instead of the kernel.
[sliver-openvswitch.git] / datapath / vport-netdev.c
index 3bab666..d1e61bb 100644 (file)
@@ -6,6 +6,8 @@
  * kernel, by Linus Torvalds and others.
  */
 
+#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
+
 #include <linux/if_arp.h>
 #include <linux/if_bridge.h>
 #include <linux/if_vlan.h>
@@ -158,7 +160,9 @@ static struct vport *netdev_create(const struct vport_parms *parms)
                goto error_put;
 
        dev_set_promiscuity(netdev_vport->dev, 1);
+#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,24)
        dev_disable_lro(netdev_vport->dev);
+#endif
        netdev_vport->dev->priv_flags |= IFF_OVS_DATAPATH;
 
        return vport;
@@ -281,15 +285,27 @@ static void netdev_port_receive(struct vport *vport, struct sk_buff *skb)
        if (unlikely(!skb))
                return;
 
-       skb_warn_if_lro(skb);
-
        skb_push(skb, ETH_HLEN);
-       compute_ip_summed(skb, false);
+
+       if (unlikely(compute_ip_summed(skb, false))) {
+               kfree_skb(skb);
+               return;
+       }
        vlan_copy_skb_tci(skb);
 
        vport_receive(vport, skb);
 }
 
+static inline unsigned packet_length(const struct sk_buff *skb)
+{
+       unsigned length = skb->len - ETH_HLEN;
+
+       if (skb->protocol == htons(ETH_P_8021Q))
+               length -= VLAN_HLEN;
+
+       return length;
+}
+
 static bool dev_supports_vlan_tx(struct net_device *dev)
 {
 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,37)
@@ -306,25 +322,29 @@ static bool dev_supports_vlan_tx(struct net_device *dev)
 static int netdev_send(struct vport *vport, struct sk_buff *skb)
 {
        struct netdev_vport *netdev_vport = netdev_vport_priv(vport);
+       int mtu = netdev_vport->dev->mtu;
        int len;
 
+       if (unlikely(packet_length(skb) > mtu && !skb_is_gso(skb))) {
+               if (net_ratelimit())
+                       pr_warn("%s: dropped over-mtu packet: %d > %d\n",
+                               dp_name(vport->dp), packet_length(skb), mtu);
+               goto error;
+       }
+
+       if (unlikely(skb_warn_if_lro(skb)))
+               goto error;
+
        skb->dev = netdev_vport->dev;
-       forward_ip_summed(skb);
+       forward_ip_summed(skb, true);
 
        if (vlan_tx_tag_present(skb) && !dev_supports_vlan_tx(skb->dev)) {
-               int err;
                int features = 0;
 
 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,26)
                features = skb->dev->features & skb->dev->vlan_features;
 #endif
 
-               err = vswitch_skb_checksum_setup(skb);
-               if (unlikely(err)) {
-                       kfree_skb(skb);
-                       return 0;
-               }
-
                if (!vlan_tso)
                        features &= ~(NETIF_F_TSO | NETIF_F_TSO6 |
                                      NETIF_F_UFO | NETIF_F_FSO);
@@ -346,10 +366,12 @@ static int netdev_send(struct vport *vport, struct sk_buff *skb)
                                goto tag;
                        }
 
-                       kfree_skb(skb);
-                       skb = nskb;
-                       if (IS_ERR(skb))
+                       if (IS_ERR(nskb)) {
+                               kfree_skb(skb);
                                return 0;
+                       }
+                       consume_skb(skb);
+                       skb = nskb;
 
                        len = 0;
                        do {
@@ -380,6 +402,11 @@ tag:
        dev_queue_xmit(skb);
 
        return len;
+
+error:
+       kfree_skb(skb);
+       vport_record_error(vport, VPORT_E_TX_DROPPED);
+       return 0;
 }
 
 /* Returns null if this device is not attached to a datapath. */
@@ -400,7 +427,7 @@ struct vport *netdev_get_vport(struct net_device *dev)
 }
 
 const struct vport_ops netdev_vport_ops = {
-       .type           = ODP_VPORT_TYPE_NETDEV,
+       .type           = OVS_VPORT_TYPE_NETDEV,
        .flags          = (VPORT_F_REQUIRED |
                          (USE_VPORT_STATS ? VPORT_F_GEN_STATS : 0)),
        .init           = netdev_init,