LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 07-18-2011, 05:54 AM   #1
MirkoBanchi
LQ Newbie
 
Registered: Jul 2011
Posts: 2

Rep: Reputation: Disabled
Which is the correct way to register a new net_device?


Hi all, i'm trying to register a new net_device in linux...i can alloc and register it correctly and ifconfig shows it. The problem arrives when i try to put the interface up:

ifconfig my_dev up

A kernel freeze occurs...the problem is present only on x86 machines and i can't figure out the reason...on a pcc machine all works well. The code is very simple:

Code:
static struct net_device *my_dev;

static int veth_dev_init(struct net_device *dev);
static int veth_open(struct net_device *dev);
static int veth_close(struct net_device *dev);
static int veth_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd);

static struct veth_priv
{
   ...
};

static struct net_device_ops veth_ops =
{
  .ndo_init = veth_dev_init,
  .ndo_open = veth_open,
  .ndo_stop = veth_close,
  .ndo_do_ioctl = veth_ioctl
};

static int __init veth_init()
{
  my_dev = alloc_netdev(sizeof(struct veth_priv), "my_dev", ether_setup);
  if (my_dev == NULL)
    return -ENOMEM;

  my_dev->netdev_ops = &veth_ops;

  register_netdev(my_dev);
  return 0;
}

static void __exit veth_exit()
{
  unregister_netdev(my_dev);
  free_netdev(my_dev);
}

module_init(veth_init);
module_exit(veth_exit);
The first four functions veth_dev_init, veth_open, veth_close and veth_ioctl simply return 0. Maybe is there a missing field in veth_ops structure?

Thank you all
 
Old 07-18-2011, 06:04 AM   #2
jschiwal
LQ Guru
 
Registered: Aug 2001
Location: Fargo, ND
Distribution: SuSE AMD64
Posts: 15,733

Rep: Reputation: 682Reputation: 682Reputation: 682Reputation: 682Reputation: 682Reputation: 682
Moved: This thread is more suitable in Programming and has been moved accordingly to help your thread/question get the exposure it deserves.
 
  


Reply



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 Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
net_device priv pointer is missing in newer kernel AustinMarton Linux - Kernel 0 11-25-2009 02:39 PM
compiling cisco-vpn gives "error: struct net_device has no..." under kernel 2.6.31 jadi19 Linux - Networking 3 10-04-2009 12:40 AM
how to access private pointer of struct net_device??? raklo Linux - Kernel 1 02-24-2007 12:34 AM
Linux struct net_device mousars Programming 5 02-15-2006 12:41 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 03:14 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration