netfilter-devel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* NFQUEUE parallelization
@ 2015-09-24 19:56 Eugene Strulyov
  2015-09-24 20:48 ` Florian Westphal
  0 siblings, 1 reply; 4+ messages in thread
From: Eugene Strulyov @ 2015-09-24 19:56 UTC (permalink / raw)
  To: netfilter-devel

Hi,

I am implementing a custom filter using the libnetfilter_queue
library. Performance is important, so I am looking at ways to
parallelize it. The options I see are as follows:

- single queue, multiple threads
- multiple queues, multiple threads
- multiple queues, multiple processes (1 per queue)

Which of these options would be most effective?

The guide I found here
https://home.regit.org/netfilter-en/using-nfqueue-and-libnetfilter_queue/
says "the nfq_set_verdict2 and nfq_handle_packet function needs to be
protected by lock mechanism." Does that mean that there can be at most
2 threads per queue?

When using multiple queues, is it valid to call nfq_open() multiple
times in the same process? When I do that I get negative numbers for
peer portid. Is this normal?

$ sudo cat /proc/net/netfilter/nfnetlink_queue
  100  27790     0 2 65531     0     0        0  1
  101  -4585     0 2 65531     0     0        0  1
  102  -4586     0 2 65531     0     0        0  1
  103  -4587     0 2 65531     0     0        0  1

Also, how exactly does --queue-balance work? All packets seem to be
directed to one particular queue.

thanks,

Eugene

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: NFQUEUE parallelization
  2015-09-24 19:56 NFQUEUE parallelization Eugene Strulyov
@ 2015-09-24 20:48 ` Florian Westphal
  2015-09-24 21:55   ` Eugene Strulyov
  0 siblings, 1 reply; 4+ messages in thread
From: Florian Westphal @ 2015-09-24 20:48 UTC (permalink / raw)
  To: Eugene Strulyov; +Cc: netfilter-devel

Eugene Strulyov <eugene.strulyov@gmail.com> wrote:
> When using multiple queues, is it valid to call nfq_open() multiple
> times in the same process?

Yes.

> When I do that I get negative numbers for
> peer portid. Is this normal?

> $ sudo cat /proc/net/netfilter/nfnetlink_queue
>   100  27790     0 2 65531     0     0        0  1
>   101  -4585     0 2 65531     0     0        0  1

The proc formatter in nfnetlink_queue uses %d instead of %u.
It was fixed a few months back.

> Also, how exactly does --queue-balance work? All packets seem to be
> directed to one particular queue.

Hash over ipv4/ipv6 source & dst addresses.

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: NFQUEUE parallelization
  2015-09-24 20:48 ` Florian Westphal
@ 2015-09-24 21:55   ` Eugene Strulyov
  2015-09-24 22:18     ` Florian Westphal
  0 siblings, 1 reply; 4+ messages in thread
From: Eugene Strulyov @ 2015-09-24 21:55 UTC (permalink / raw)
  To: Florian Westphal; +Cc: netfilter-devel

Thanks for your reply.

So with regards to parallelization, I need to use multiple queues, correct?

Also, with --queue-balance, will the same (src_ip, dst_ip) pair always
map to the same queue? If yes, I can make each queue handler a
separate process.

thanks,

Eugene



On Thu, Sep 24, 2015 at 1:48 PM, Florian Westphal <fw@strlen.de> wrote:
> Eugene Strulyov <eugene.strulyov@gmail.com> wrote:
>> When using multiple queues, is it valid to call nfq_open() multiple
>> times in the same process?
>
> Yes.
>
>> When I do that I get negative numbers for
>> peer portid. Is this normal?
>
>> $ sudo cat /proc/net/netfilter/nfnetlink_queue
>>   100  27790     0 2 65531     0     0        0  1
>>   101  -4585     0 2 65531     0     0        0  1
>
> The proc formatter in nfnetlink_queue uses %d instead of %u.
> It was fixed a few months back.
>
>> Also, how exactly does --queue-balance work? All packets seem to be
>> directed to one particular queue.
>
> Hash over ipv4/ipv6 source & dst addresses.

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: NFQUEUE parallelization
  2015-09-24 21:55   ` Eugene Strulyov
@ 2015-09-24 22:18     ` Florian Westphal
  0 siblings, 0 replies; 4+ messages in thread
From: Florian Westphal @ 2015-09-24 22:18 UTC (permalink / raw)
  To: Eugene Strulyov, g; +Cc: Florian Westphal, netfilter-devel

Eugene Strulyov <eugene.strulyov@gmail.com> wrote:

Please don't top post.

> Thanks for your reply.
> 
> So with regards to parallelization, I need to use multiple queues, correct?

Not necessarily, but it avoids contention for a (single) queue.

> Also, with --queue-balance, will the same (src_ip, dst_ip) pair always
> map to the same queue?

Yes, all saddr,daddr [and replies] get into same queue.

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2015-09-24 22:18 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-09-24 19:56 NFQUEUE parallelization Eugene Strulyov
2015-09-24 20:48 ` Florian Westphal
2015-09-24 21:55   ` Eugene Strulyov
2015-09-24 22:18     ` Florian Westphal

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).