Added very basic ethernet device.
authorThadeu Lima de Souza Cascardo <cascardo@holoscopio.com>
Mon, 24 May 2010 08:02:04 +0000 (04:02 -0400)
committerThadeu Lima de Souza Cascardo <cascardo@holoscopio.com>
Mon, 24 May 2010 08:02:04 +0000 (04:02 -0400)
Makefile [new file with mode: 0644]
ndeth.c [new file with mode: 0644]

diff --git a/Makefile b/Makefile
new file mode 100644 (file)
index 0000000..4b124b0
--- /dev/null
+++ b/Makefile
@@ -0,0 +1,13 @@
+ifneq ($(KERNELRELEASE),)
+       obj-m := ndeth.o
+else
+       KERNELDIR ?= /lib/modules/`uname -r`/build
+       PWD = `pwd`
+
+default:
+       make -C $(KERNELDIR) M=$(PWD) modules
+
+clean:
+       make -C $(KERNELDIR) M=$(PWD) clean
+
+endif
diff --git a/ndeth.c b/ndeth.c
new file mode 100644 (file)
index 0000000..ec6be59
--- /dev/null
+++ b/ndeth.c
@@ -0,0 +1,76 @@
+/*
+ *  Copyright (C) 2010  Thadeu Lima de Souza Cascardo <cascardo@holoscopio.com>
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License along
+ *  with this program; if not, write to the Free Software Foundation, Inc.,
+ *  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+
+#include <linux/module.h>
+#include <linux/netdevice.h>
+#include <linux/etherdevice.h>
+
+MODULE_LICENSE("GPL");
+
+static int ndeth_open(struct net_device *dev)
+{
+       printk(KERN_DEBUG "ndeth open\n");
+       return 0;
+}
+
+static int ndeth_stop(struct net_device *dev)
+{
+       printk(KERN_DEBUG "ndeth stop\n");
+       return 0;
+}
+
+static int ndeth_tx(struct sk_buff *skb, struct net_device *dev)
+{
+       dev_kfree_skb(skb);
+       return NETDEV_TX_OK;
+}
+
+static const struct net_device_ops ndeth_ops = {
+       .ndo_open = ndeth_open,
+       .ndo_stop = ndeth_stop,
+       .ndo_start_xmit = ndeth_tx,
+};
+
+struct net_device *ndeth;
+
+static __init int ndeth_init(void)
+{
+       int r = -ENOMEM;
+       ndeth = alloc_etherdev(0);
+       if (!ndeth)
+               goto out;
+       ndeth->netdev_ops = &ndeth_ops;
+       r = register_netdev(ndeth);
+       if (r)
+               goto reg_out;
+       return 0;
+reg_out:
+       free_netdev(ndeth);
+out:
+       return r;
+}
+
+static __exit void ndeth_exit(void)
+{
+       unregister_netdev(ndeth);
+       free_netdev(ndeth);
+}
+
+module_init(ndeth_init);
+module_exit(ndeth_exit);