aboutsummaryrefslogtreecommitdiffstats
path: root/net/core/dev.c
diff options
context:
space:
mode:
authorArnd Bergmann <arnd@arndb.de>2009-11-26 01:07:08 -0500
committerDavid S. Miller <davem@davemloft.net>2009-11-26 18:52:58 -0500
commit445409602c09219767c06497c0dc2285eac244ed (patch)
tree5cfbd6d94f737107f3e6356fca2457ab3a66bb44 /net/core/dev.c
parent1bda8aa86b89d4c9b668000127ff87172f2daa10 (diff)
veth: move loopback logic to common location
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>
Diffstat (limited to 'net/core/dev.c')
-rw-r--r--net/core/dev.c40
1 files changed, 40 insertions, 0 deletions
diff --git a/net/core/dev.c b/net/core/dev.c
index e65af604141..7775e8b48de 100644
--- a/net/core/dev.c
+++ b/net/core/dev.c
@@ -105,6 +105,7 @@
105#include <net/dst.h> 105#include <net/dst.h>
106#include <net/pkt_sched.h> 106#include <net/pkt_sched.h>
107#include <net/checksum.h> 107#include <net/checksum.h>
108#include <net/xfrm.h>
108#include <linux/highmem.h> 109#include <linux/highmem.h>
109#include <linux/init.h> 110#include <linux/init.h>
110#include <linux/kmod.h> 111#include <linux/kmod.h>
@@ -1419,6 +1420,45 @@ static inline void net_timestamp(struct sk_buff *skb)
1419 skb->tstamp.tv64 = 0; 1420 skb->tstamp.tv64 = 0;
1420} 1421}
1421 1422
1423/**
1424 * dev_forward_skb - loopback an skb to another netif
1425 *
1426 * @dev: destination network device
1427 * @skb: buffer to forward
1428 *
1429 * return values:
1430 * NET_RX_SUCCESS (no congestion)
1431 * NET_RX_DROP (packet was dropped)
1432 *
1433 * dev_forward_skb can be used for injecting an skb from the
1434 * start_xmit function of one device into the receive queue
1435 * of another device.
1436 *
1437 * The receiving device may be in another namespace, so
1438 * we have to clear all information in the skb that could
1439 * impact namespace isolation.
1440 */
1441int dev_forward_skb(struct net_device *dev, struct sk_buff *skb)
1442{
1443 skb_orphan(skb);
1444
1445 if (!(dev->flags & IFF_UP))
1446 return NET_RX_DROP;
1447
1448 if (skb->len > (dev->mtu + dev->hard_header_len))
1449 return NET_RX_DROP;
1450
1451 skb_dst_drop(skb);
1452 skb->tstamp.tv64 = 0;
1453 skb->pkt_type = PACKET_HOST;
1454 skb->protocol = eth_type_trans(skb, dev);
1455 skb->mark = 0;
1456 secpath_reset(skb);
1457 nf_reset(skb);
1458 return netif_rx(skb);
1459}
1460EXPORT_SYMBOL_GPL(dev_forward_skb);
1461
1422/* 1462/*
1423 * Support routine. Sends outgoing frames to any network 1463 * Support routine. Sends outgoing frames to any network
1424 * taps currently in use. 1464 * taps currently in use.