From 503f35d0bd433376e5d990797c95d706787d456b Mon Sep 17 00:00:00 2001 From: Thadeu Lima de Souza Cascardo Date: Mon, 24 May 2010 04:02:04 -0400 Subject: [PATCH 1/1] Added very basic ethernet device. --- Makefile | 13 ++++++++++ ndeth.c | 76 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 89 insertions(+) create mode 100644 Makefile create mode 100644 ndeth.c diff --git a/Makefile b/Makefile new file mode 100644 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 index 0000000..ec6be59 --- /dev/null +++ b/ndeth.c @@ -0,0 +1,76 @@ +/* + * Copyright (C) 2010 Thadeu Lima de Souza Cascardo + * + * 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 +#include +#include + +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); -- 2.20.1