Welcome to Linux Forums! With a comprehensive Linux Forum, information on various types of Linux software and many Linux Reviews articles, we have all the knowledge you need a click away, or accessible via our knowledgeable members.
Find the answer to your Linux question:
New to Linux Forums? Register here for free!
    Linux Forums > GNU Linux Zone > The Linux Kernel > Unable to register a virtual network device in kernel 2.6.28

Forgot Password?
 The Linux Kernel   Compiling, theory, programming or other discussion about the linux kernel

Site Navigation
Linux Articles
Linux Forums
Linux Downloads
Linux Hosting
Free Magazines
Job Board
IRC Chat
RSS Feeds


Linux Forum Topics
Linux Forums
Your Distro
Linux Resources
GNU Linux Zone
The Community
Reply
 
Thread Tools Display Modes
Old 10-15-2009   #1 (permalink)
Just Joined!
 
Join Date: Oct 2009
Posts: 1
Unhappy Unable to register a virtual network device in kernel 2.6.28

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.

<code>
#ifndef __KERNEL__
# define __KERNEL__
#endif
#ifndef MODULE
# define MODULE
#endif

#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) {
printk("GOING TO INITIALIZE DEVICE\n");
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");
cleanup();
return result;
}
return 0;
}

module_init(enter_module);
module_exit(cleanup);
</code>

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).

Errors:
[ 2260.676155] ENTERED MODULE
[ 2260.676160] GOING TO INITIALIZE DEVICE
[ 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....
srudeepk is offline  


Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off

Free Magazines
Run Your Own Web Server Using Linux & Apache - Free 191 Page Preview
Learn about everything you'll need to build and maintain your Linux servers, and to deploy Web applications to them.
subscribe
Open Source Security Myths Dispelled
Dispel the five major myths surrounding Open Source Security and gain the tools necessary to make a truly informed decision for your IT organization
subscribe
InformationWeek
InformationWeek is the only newsweekly you'll need to stay on top of the latest developments in information technology.
subscribe



All times are GMT. The time now is 02:09 PM.






© 2000 - 2009 - All Rights Reserved - Property of  MAS Media

Content Relevant URLs by vBSEO 3.3.0 RC2