title: How to filter and intercept Linux packets by using net_dev_add() API?
body: <p>I'm writing ethernet network driver for linux. I want to receive packets, edit and resend them.
  I know how to edit the packet in <code>packet_interceptor</code> function, but how can I drop incoming packets in this function??</p>
  
  <pre><code>#include &lt;linux/netdevice.h&gt;
  #include &lt;linux/skbuff.h&gt;
  #include &lt;linux/ip.h&gt;
  #include &lt;net/sock.h&gt;
  
  struct packet_type my_proto;
  
  int packet_interceptor(struct sk_buff *skb,
      struct net_device *dev,
      struct packet_type *pt,
      struct net_device *orig_dev) {
  
      // I dont want certain packets go to upper in net_devices for further processing.
      // How can I drop sk_buff here?!
  
    return 0;
  }
  
  static int hello_init( void ) {
      printk(KERN_INFO "Hello, world!\n");
  
      my_proto.type = htons(ETH_P_ALL);
      my_proto.dev = NULL;
      my_proto.func = packet_interceptor;
  
      dev_add_pack(&amp;my_proto);
      return 0;
  }    
  
  static void hello_exit(void) {
    dev_remove_pack(&amp;my_proto);
    printk(KERN_INFO "Bye, world\n");
  }
  
  module_init(hello_init);
  module_exit(hello_exit);
  </code></pre>