]> git.karo-electronics.de Git - linux-beck.git/commitdiff
veth: move loopback logic to common location
authorArnd Bergmann <arnd@arndb.de>
Thu, 26 Nov 2009 06:07:08 +0000 (06:07 +0000)
committerDavid S. Miller <davem@davemloft.net>
Thu, 26 Nov 2009 23:52:58 +0000 (15:52 -0800)
The veth driver contains code to forward an skb
from the start_xmit function of one network
device into the receive path of another device.

Moving that code into a common location lets us
reuse the code for direct forwarding of data
between macvlan ports, and possibly in other
drivers.

Signed-off-by: Arnd Bergmann <arnd@arndb.de>
Acked-by: Patrick McHardy <kaber@trash.net>
Signed-off-by: David S. Miller <davem@davemloft.net>
drivers/net/veth.c
include/linux/netdevice.h
net/core/dev.c

index 2d657f2314cbdd2db4fb0243d82181c93358cca7..6c4b5a2d7877d3f4f50925cad8b61e0cc803b9da 100644 (file)
@@ -155,8 +155,6 @@ static netdev_tx_t veth_xmit(struct sk_buff *skb, struct net_device *dev)
        struct veth_net_stats *stats, *rcv_stats;
        int length, cpu;
 
-       skb_orphan(skb);
-
        priv = netdev_priv(dev);
        rcv = priv->peer;
        rcv_priv = netdev_priv(rcv);
@@ -168,20 +166,12 @@ static netdev_tx_t veth_xmit(struct sk_buff *skb, struct net_device *dev)
        if (!(rcv->flags & IFF_UP))
                goto tx_drop;
 
-       if (skb->len > (rcv->mtu + MTU_PAD))
-               goto rx_drop;
-
-        skb->tstamp.tv64 = 0;
-       skb->pkt_type = PACKET_HOST;
-       skb->protocol = eth_type_trans(skb, rcv);
        if (dev->features & NETIF_F_NO_CSUM)
                skb->ip_summed = rcv_priv->ip_summed;
 
-       skb->mark = 0;
-       secpath_reset(skb);
-       nf_reset(skb);
-
-       length = skb->len;
+       length = skb->len + ETH_HLEN;
+       if (dev_forward_skb(rcv, skb) != NET_RX_SUCCESS)
+               goto rx_drop;
 
        stats->tx_bytes += length;
        stats->tx_packets++;
@@ -189,7 +179,6 @@ static netdev_tx_t veth_xmit(struct sk_buff *skb, struct net_device *dev)
        rcv_stats->rx_bytes += length;
        rcv_stats->rx_packets++;
 
-       netif_rx(skb);
        return NETDEV_TX_OK;
 
 tx_drop:
index 97873e31661c29ef289ee0616090be24e514f54d..9428793775a022ca6ba9b194bac1ee827e08557c 100644 (file)
@@ -1562,6 +1562,8 @@ extern int                dev_set_mac_address(struct net_device *,
 extern int             dev_hard_start_xmit(struct sk_buff *skb,
                                            struct net_device *dev,
                                            struct netdev_queue *txq);
+extern int             dev_forward_skb(struct net_device *dev,
+                                       struct sk_buff *skb);
 
 extern int             netdev_budget;
 
index e65af6041415f2875d7a418273af67978ad973e8..7775e8b48debd6f3d045993d008b10f8311833b3 100644 (file)
 #include <net/dst.h>
 #include <net/pkt_sched.h>
 #include <net/checksum.h>
+#include <net/xfrm.h>
 #include <linux/highmem.h>
 #include <linux/init.h>
 #include <linux/kmod.h>
@@ -1419,6 +1420,45 @@ static inline void net_timestamp(struct sk_buff *skb)
                skb->tstamp.tv64 = 0;
 }
 
+/**
+ * dev_forward_skb - loopback an skb to another netif
+ *
+ * @dev: destination network device
+ * @skb: buffer to forward
+ *
+ * return values:
+ *     NET_RX_SUCCESS  (no congestion)
+ *     NET_RX_DROP     (packet was dropped)
+ *
+ * dev_forward_skb can be used for injecting an skb from the
+ * start_xmit function of one device into the receive queue
+ * of another device.
+ *
+ * The receiving device may be in another namespace, so
+ * we have to clear all information in the skb that could
+ * impact namespace isolation.
+ */
+int dev_forward_skb(struct net_device *dev, struct sk_buff *skb)
+{
+       skb_orphan(skb);
+
+       if (!(dev->flags & IFF_UP))
+               return NET_RX_DROP;
+
+       if (skb->len > (dev->mtu + dev->hard_header_len))
+               return NET_RX_DROP;
+
+       skb_dst_drop(skb);
+       skb->tstamp.tv64 = 0;
+       skb->pkt_type = PACKET_HOST;
+       skb->protocol = eth_type_trans(skb, dev);
+       skb->mark = 0;
+       secpath_reset(skb);
+       nf_reset(skb);
+       return netif_rx(skb);
+}
+EXPORT_SYMBOL_GPL(dev_forward_skb);
+
 /*
  *     Support routine. Sends outgoing frames to any network
  *     taps currently in use.