Kernelnewbies Digest, Vol 79, Issue 18

wiktoria.lewicka wiktoria.lewicka at vp.pl
Wed Jun 21 06:35:54 EDT 2017


Thank you all, I make some changes in my code, but its still not work. When my module is loading and loading I have a problems with connection with Internet- is it a matter of configuration?
My changes:

#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/init.h>
#include <linux/netdevice.h>
#include <linux/string.h>
#define DEV_NAME "my_dev\n"

struct net_device my_netdev;

int init_mdev(struct net_device *dev);

struct net_device_ops nops = {
  .ndo_init = init_mdev,
  /*.ndo_uninit = unin_mdev,*/
};

static int __init init_dev(void)
{
  /*my_netdev.netdev_ops = &nops;*/
  int result;
  if(!(netdev_boot_setup_check(&my_netdev))){
    printk(KERN_ERR "NETDEV: setup error");
    return 0;
  }
  strcpy(my_netdev.name, DEV_NAME);
  if((result = register_netdev(&my_netdev)))
    printk(KERN_ERR "NETDEV: Error registering device");
  printk("NETDEV: Device registered successfully");
  return 0;
}

static void __exit remove_dev(void)
{
  unregister_netdev(&my_netdev);
}
int init_mdev(struct net_device *dev)
{
  printk("INIT");
  return 0;
}
module_init(init_dev);
module_exit(remove_dev);


W dniu 2017-06-20 18:00:02 użytkownik  <kernelnewbies-request at kernelnewbies.org> napisał:
> Send Kernelnewbies mailing list submissions to
> 	kernelnewbies at kernelnewbies.org
> 
> To subscribe or unsubscribe via the World Wide Web, visit
> 	https://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies
> or, via email, send a message with subject or body 'help' to
> 	kernelnewbies-request at kernelnewbies.org
> 
> You can reach the person managing the list at
> 	kernelnewbies-owner at kernelnewbies.org
> 
> When replying, please edit your Subject line so it is more specific
> than "Re: Contents of Kernelnewbies digest..."
> 
> 
> Today's Topics:
> 
>    1. My network device don't work (wiktoria.lewicka)
>    2. Re: My network device don't work (Stan Drozd)
>    3. Re: My network device don't work (Greg KH)
> 
> 
> ----------------------------------------------------------------------
> 
> Message: 1
> Date: Tue, 20 Jun 2017 14:32:31 +0200
> From: "wiktoria.lewicka" <wiktoria.lewicka at vp.pl>
> Subject: My network device don't work
> To: "kernelnewbies at kernelnewbies.org"
> 	<kernelnewbies at kernelnewbies.org>
> Message-ID:
> 	<186270325-26e3212af6540c227a34d3cd3b5e0c56 at pmq3v.m5r2.onet>
> Content-Type: text/plain; charset="utf-8"
> 
> Hello.
> I write simple network device, but its don't work. Module is loading, loading, loading...
> Code:
> 
> #include <linux/kernel.h>
> #include <linux/module.h>
> #include <linux/init.h>
> #include <linux/netdevice.h>
> #include <linux/string.h>
> #define DEV_NAME "chwdp"
> 
> struct net_device my_netdev;
> 
> int init_my_net_dev(struct net_device *dev);
> 
> struct net_device_ops nops = {
>   .ndo_init = init_my_net_dev,
>   //.ndo_uninit = uninit_my_net_dev,
> };
> 
> static int __init init_dev(void)
> {
>   //my_netdev.netdev_ops = &nops;
>   int result;
>   if((netdev_boot_setup_check(&my_netdev))){
>     printk(KERN_ERR "NETDEV: setup error");
>     return 0;
>   }
>   strncpy(my_netdev.name, DEV_NAME, 5);
>   if((result = register_netdev(&my_netdev)))
>     printk(KERN_ERR "NETDEV: Error registering device");
>   printk("NETDEV: Device registered successfully");
>   return 0;
> }
> 
> static void __exit remove_dev(void)
> {
>   unregister_netdev(&my_netdev);
> }
> int init_my_net_dev(struct net_device *dev)
> {
>   printk("INIT");
>   return 0;
> }
> module_init(init_dev);
> module_exit(remove_dev);
> 
> 
> 
> 
> ------------------------------
> 
> Message: 2
> Date: Tue, 20 Jun 2017 15:31:29 +0200
> From: Stan Drozd <drozdziak1 at gmail.com>
> Subject: Re: My network device don't work
> To: "wiktoria.lewicka" <wiktoria.lewicka at vp.pl>
> Cc: kernelnewbies at kernelnewbies.org
> Message-ID: <20170620133128.GB1233 at gmail.com>
> Content-Type: text/plain; charset=us-ascii
> 
> On Tue, Jun 20, 2017 at 02:32:31PM +0200, wiktoria.lewicka wrote:
> > Hello.
> > I write simple network device, but its don't work. Module is loading, loading, loading...
> > Code:
> > [...]
> Hello,
> "strncpy(my_netdev.name, DEV_NAME, 5)" only copies the 5 chars in "chwdp" without the null byte. You could bump it to 6
> or maybe change 5 to IFNAMSIZ (the net_device.name's size) and then change the last byte to '\0' manually
> 
> 
> 
> ------------------------------
> 
> Message: 3
> Date: Tue, 20 Jun 2017 22:12:34 +0800
> From: Greg KH <greg at kroah.com>
> Subject: Re: My network device don't work
> To: "wiktoria.lewicka" <wiktoria.lewicka at vp.pl>
> Cc: "kernelnewbies at kernelnewbies.org"
> 	<kernelnewbies at kernelnewbies.org>
> Message-ID: <20170620141234.GA2599 at kroah.com>
> Content-Type: text/plain; charset=us-ascii
> 
> On Tue, Jun 20, 2017 at 02:32:31PM +0200, wiktoria.lewicka wrote:
> > Hello.
> > I write simple network device, but its don't work. Module is loading, loading, loading...
> > Code:
> > 
> > #include <linux/kernel.h>
> > #include <linux/module.h>
> > #include <linux/init.h>
> > #include <linux/netdevice.h>
> > #include <linux/string.h>
> > #define DEV_NAME "chwdp"
> > 
> > struct net_device my_netdev;
> > 
> > int init_my_net_dev(struct net_device *dev);
> > 
> > struct net_device_ops nops = {
> >   .ndo_init = init_my_net_dev,
> >   //.ndo_uninit = uninit_my_net_dev,
> > };
> > 
> > static int __init init_dev(void)
> > {
> >   //my_netdev.netdev_ops = &nops;
> >   int result;
> >   if((netdev_boot_setup_check(&my_netdev))){
> >     printk(KERN_ERR "NETDEV: setup error");
> >     return 0;
> 
> Why are you returning success if there was an error?
> 
> And always try to use proper kernel coding style when writing kernel
> code if you expect/want someone else to read it :)
> 
> thanks,
> 
> greg k-h
> 
> 
> 
> ------------------------------
> 
> _______________________________________________
> Kernelnewbies mailing list
> Kernelnewbies at kernelnewbies.org
> https://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies
> 
> 
> End of Kernelnewbies Digest, Vol 79, Issue 18
> *********************************************
> 






More information about the Kernelnewbies mailing list