title: passing packets from IP layer to device driver
body: <p>I am trying to pass a sk_buff packet from IP layer of the protocol stack to a device driver which I have created and registered. The code for the device driver is as follows :</p>
  
  <pre><code>    #include&lt;linux/module.h&gt;
      #include&lt;linux/netdevice.h&gt;
      #include&lt;linux/kernel.h&gt;
      #include&lt;linux/skbuff.h&gt;
      #include&lt;linux/pci.h&gt;
      #include&lt;linux/interrupt.h&gt;
      struct net_device *my_dev;
      static netdev_tx_t veth_xmit(struct sk_buff *skb, struct net_device *dev)
      {
             printk(KERN_INFO "I got a packet");    
             return NETDEV_TX_OK;
      }
      static int veth_open(struct net_device *dev)
      {
  
                    memcpy(dev-&gt;dev_addr, "\0ABCD0", ETH_ALEN);
                    netif_start_queue(dev);
  
                    return 0;
      }
  
  
      int veth_close(struct net_device *dev)
      {
             printk("releasing mydev\n");
             netif_stop_queue(dev);
             return 0;
      }
  
      int veth_dev_init(struct net_device *dev)
      {
             printk("initialising\n");
             return 0;
      }
  
      static struct net_device_ops veth_ops = {
  
       .ndo_init         = veth_dev_init,
       .ndo_open         = veth_open,
       .ndo_stop         = veth_close,
       .ndo_start_xmit   = veth_xmit,
  
         };
     int veth_init()
     {
     int ret,i;
     my_dev = alloc_netdev(sizeof(struct net_device), "my_dev", ether_setup);
     if (my_dev == NULL)
      return -ENOMEM; 
     my_dev-&gt;netdev_ops = &amp;veth_ops;
         register_netdev(my_dev);
         return 0;
     }
     void veth_exit()
     {
      unregister_netdev(my_dev);
      free_netdev(my_dev);
     }
  
     module_init(veth_init);
     module_exit(veth_exit);
  </code></pre>
  
  <p>then after loading this module and using "ifconfig " to assign IP address to it, I have tried to pass a packet using dev_queue_xmit() function. the code is as fllows:</p>
  
  <pre><code>   struct sk_buff *skb;
     void generate_send()
     {
     skb=alloc_skb(skb,2);
     skb-&gt;data[0]='m';//just to check
         skb-&gt;dev="my_dev";
         dev_queue_xmit(skb);
     }
     static int testing_init(void)
     {
     //time=4;    
     generate_send();
  
     return 0;    
     }
     static void testing_exit(void)
     {
  printk(KERN_INFO "Goodbye, world 2\n");
     }
     module_init(testing_init);
     module_exit(testing_exit);
  </code></pre>
  
  <p>but the packet is not getting passed and when I am trying to load this testing module the system shows fatal error and terminate the process. Can you suggest me a good approach to solve this?</p>