lkml.org 
[lkml]   [2003]   [Jan]   [6]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
Date
From
Subjectdummy ethernet driver

Hi,
I have a VAX simulator running on my PC which uses pcap to send/recv
packets, however these packets are never seen on the local machine when
using a real ethernet device (everyone else on the network sees them), now
I only really want the local machine to see them not the network so I
decided I might get away with using loopback, however the simulator
configures its own IP and loopback isn't useful for this as the sim starts
arping and we don't do any arp on loopback.

so I turned to the dummy device but it isn't really a dummy Ethernet
device but rather a useless one :-), so I patched the dummy so it had an
address (hardcoded) is broadcast and loops back packets to itself...

the patch is attached.. is there any reason why the dummy device doesn't
want to do this stuff? I'm just submitting the patch as a request for
comments on why this isn't done anyway in the dummy?

Dave.

--
David Airlie, Software Engineer
http://www.skynet.ie/~airlied / airlied@skynet.ie
pam_smb / Linux DecStation / Linux VAX / ILUG person

--- /usr/src/linux/drivers/net/dummy.c 2001-10-01 05:26:06.000000000 +1000
+++ ./dummy.c 2003-01-06 17:06:44.000000000 +1100
@@ -35,6 +35,7 @@
#include <linux/kernel.h>
#include <linux/netdevice.h>
#include <linux/init.h>
+#include <linux/etherdevice.h>

static int dummy_xmit(struct sk_buff *skb, struct net_device *dev);
static struct net_device_stats *dummy_get_stats(struct net_device *dev);
@@ -53,6 +54,7 @@

static int __init dummy_init(struct net_device *dev)
{
+ unsigned char myaddr[]="123456";
/* Initialize the device structure. */

dev->priv = kmalloc(sizeof(struct net_device_stats), GFP_KERNEL);
@@ -60,6 +62,7 @@
return -ENOMEM;
memset(dev->priv, 0, sizeof(struct net_device_stats));

+ memcpy(dev->dev_addr, myaddr, 6);
dev->get_stats = dummy_get_stats;
dev->hard_start_xmit = dummy_xmit;
dev->set_multicast_list = set_multicast_list;
@@ -70,7 +73,8 @@
/* Fill in device structure with ethernet-generic values. */
ether_setup(dev);
dev->tx_queue_len = 0;
- dev->flags |= IFF_NOARP;
+/* dev->flags |= IFF_NOARP; */
+ dev->flags |= IFF_BROADCAST;
dev->flags &= ~IFF_MULTICAST;

return 0;
@@ -82,8 +86,28 @@

stats->tx_packets++;
stats->tx_bytes+=skb->len;
+
+ if(atomic_read(&skb->users) != 1)
+ {
+ struct sk_buff *skb2=skb;
+ skb=skb_clone(skb, GFP_ATOMIC); /* Clone the buffer */
+ if(skb==NULL) {
+ dev_kfree_skb(skb2);
+ return 0;
+ }
+ dev_kfree_skb(skb2);
+ }
+ else
+ skb_orphan(skb);
+
+ skb->protocol=eth_type_trans(skb,dev);
+ skb->dev=dev;
+
+ skb->ip_summed = CHECKSUM_UNNECESSARY;
+ dev->last_rx = jiffies;
+
+ netif_rx(skb);

- dev_kfree_skb(skb);
return 0;
}
\
 
 \ /
  Last update: 2005-03-22 13:32    [W:0.051 / U:4.456 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site