Hi everyone,

I am using Kubuntu 9.0.4 with kernel version 2.6.28. I want to register a virtual network device with custom ioctl. But register_netdev(struct net_device) is giving me a segmentation fault. Here is the code i have written.

#ifndef __KERNEL__
# define __KERNEL__
#ifndef MODULE
# define MODULE

#include <linux/module.h>
#include <linux/sched.h>
#include <linux/kernel.h>
#include <linux/slab.h>
#include <linux/types.h>
#include <linux/interrupt.h>
#include <linux/netdevice.h>
#include <linux/device.h>
#include <linux/ip.h>
#include <linux/tcp.h>
#include <linux/skbuff.h>
#include <linux/errno.h>
#include <linux/blkdev.h>
#include <linux/init.h>
#include <linux/cdev.h>
#include <asm/uaccess.h>
#include <linux/netlink.h>

struct shaper_dev_priv {
int shaper_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
printk("-----INSIDE SHAPER IOCTL-----\n");
return 0;
void shaper_init_dev(struct net_device *dev) {
dev->do_ioctl = shaper_ioctl;
printk("IOCTL IS SET NOW!!!\n");
static void __exit cleanup(void)

static int __init enter_module(void)
int result;
struct net_device *allocate_virtual_device;
printk("ENTERED MODULE\n");
allocate_virtual_device = alloc_netdev(sizeof(struct shaper_dev_priv),
"shaper%d", shaper_init_dev);
result = register_netdev(&allocate_virtual_device);
if (result) {
printk(KERN_ERR "Shaper: can't register netdevice");
return result;
return 0;


The idea here is to create a virtual network device with custom ioctl and to use netfilter for implementing pre-routing and post-routing logic to shape the incoming and outgoing traffic at a gateway. But register_netdev() function is throwing segmentation fault with follwoting error. (taken from /var/log/messages).

[ 2260.676155] ENTERED MODULE
[ 2260.676161] IOCTL IS SET NOW!!!
[ 2260.676180] *pde = 00000000
[ 2260.676189] Dumping ftrace buffer:
[ 2260.676192] (ftrace buffer empty)
[ 2260.676193] Modules linked in: shaperKernelModule(P+) ppdev bridge stp bnep input_polldev lp parport joydev snd_hda_intel snd_pcm_oss snd_mixer_oss snd_pcm snd_seq_dummy snd_seq_oss snd_seq_midi snd_rawmidi uvcvideo snd_seq_midi_event compat_ioctl32 snd_seq videodev snd_timer snd_seq_device mmc_block ieee80211_crypt_tkip psmouse v4l1_compat intel_agp agpgart dcdbas wl(P) snd soundcore ricoh_mmc sdhci_pci sdhci serio_raw pcspkr ieee80211_crypt snd_page_alloc video iTCO_wdt iTCO_vendor_support output usb_storage ohci1394 b44 ssb ieee1394 mii fbcon tileblit font bitblit softcursor
[ 2260.676236] Pid: 6057, comm: insmod Tainted: P (2.6.28-11-generic #42-Ubuntu) Inspiron 1720
[ 2260.676238] EIP: 0060:[<00000005>] EFLAGS: 00010206 CPU: 0
[ 2260.676240] EIP is at 0x5
[ 2260.676242] EAX: f5693e1c EBX: 00000000 ECX: f567e000 EDX: 00000005
[ 2260.676244] ESI: f5693e1c EDI: 00000000 EBP: f5693e00 ESP: f5693de4
[ 2260.676246] DS: 007b ES: 007b FS: 00d8 GS: 0033 SS: 0068
[ 2260.676251] c0433502 00000000 f5693df8 c0501a4b 00000000 f5693e1c 00000000 f5693e10
[ 2260.676354] ---[ end trace acd4930e949e27cd ]---
[ 2260.679029] INSIDE MAIN HOOK!!!
[ 2260.877094] INSIDE MAIN HOOK!!!
[ 2261.270720] INSIDE MAIN HOOK!!!
[ 2261.730925] INSIDE MAIN HOOK!!!
[ 2261.731195] INSIDE MAIN HOOK!!!

This error is reproducable. Every thing seems to be ok in the code, but I dont know why I am getting this fault, am I missing out on some thing? Is there any thing extra I should do in the code? Please help me out....