title: Sending queued packets with NFQUEUE?
body: <p>I'm using <code>libnetfilter_queue</code> and <code>iptables</code> with the <code>NFQUEUE</code> target to store incoming packets in three different queues with <code>--queue-num x</code>.</p>
  
  <p>I successfully create the three queues with <code>libnetfilter_queue</code>functions, bind them, listen to them and read from them as follows:</p>
  
  <pre><code>/* given 'h' as a handler of one of my three queues */
  fd = nfq_fd(h);
  while ((rv = recv(fd, buf, sizeof(buf), 0)) &amp;&amp; rv &gt;= 0) {
      nfq_handle_packet(h, buf, rv);
  }
  </code></pre>
  
  <p>The callback function, triggered with <code>nfq_handle_packet</code>, has the <code>nfq_set_verdict(qh, id, NF_ACCEPT, 0, NULL);</code> command where it sends the packet as soon it has been processed.
  The problem is: I <em>don't</em> want every packet to be sent right away, since I need to store them in a custom struct  (written below).</p>
  
  <p>So I came across a potential solution: I may call <code>NF_DROP</code> verdict instead of <code>NF_ACCEPT</code> on every packet I want to queue (so it won't be immediately sent away), store it in my custom struct and then (sooner or later) re-inject it at my need.</p>
  
  <p>Sounds great, but the situation is: <em>I don't know how to re-inject my queued packets at my pleasure from my userspace application</em>. Is correct to use <code>nfq_set_verdict</code> again at a same point of my code, but with <code>NF_ACCEPT</code> verdict? Or should I open a socket (maybe a raw one)?</p>
  
  <p>This is my custom struct</p>
  
  <pre><code>struct List {
      int queue;
      int pktsize;
      unsigned char *buffer;
      struct nfq_q_handle *qh;
      struct nfqnl_msg_packet_hdr *hdr;
      struct List *next;
  };
  </code></pre>
  
  <p>representing a packet caught with the rule above.</p>
  
  <p>These are my queues where to store packets.</p>
  
  <pre><code>struct List *List0 = NULL;  // low priority
  struct List *List1 = NULL;  // medium priority
  struct List *List2 = NULL;  // high priority
  </code></pre>
  
  <p>I have <code>Ubuntu 14.04 3.13.0-57-generic</code>.</p>
  
  <p>Any suggestions would be appreciated.</p>