All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH]: drop packet without verdict from nfqueue after timeout
@ 2009-03-23 18:48 Kuzin Andrey
  2009-03-23 19:18 ` Patrick McHardy
  0 siblings, 1 reply; 6+ messages in thread
From: Kuzin Andrey @ 2009-03-23 18:48 UTC (permalink / raw)
  To: netfilter-devel

This is patch for problem with stucked packets in nf_queue if
something going wrong in userspace program. Automatically drop packets
without any verdict after timeout defined by NFQNL_TIMEOUT_ENTRY_DROP.

Who may create patch for menu config for this feature ?


diff --git a/net/netfilter/nfnetlink_queue.c b/net/netfilter/nfnetlink_queue.c
index 8c86011..74fc322 100644
--- a/net/netfilter/nfnetlink_queue.c
+++ b/net/netfilter/nfnetlink_queue.c
@@ -169,17 +169,29 @@ __enqueue_entry(struct nfqnl_instance *queue, struct nf_queue_entry *entry)
        queue->queue_total++;
 }

+#define NFQNL_TIMEOUT_ENTRY_DROP 30
+
 static struct nf_queue_entry *
 find_dequeue_entry(struct nfqnl_instance *queue, unsigned int id)
 {
-       struct nf_queue_entry *entry = NULL, *i;
+       struct nf_queue_entry *entry = NULL, *next, *i;
+       ktime_t kt = ktime_get_real();

        spin_lock_bh(&queue->lock);

-       list_for_each_entry(i, &queue->queue_list, list) {
+       list_for_each_entry_safe(i, next, &queue->queue_list, list) {
                if (i->id == id) {
                        entry = i;
                        break;
+                } else {
+                       struct timeval tv = ktime_to_timeval(ktime_sub(kt, i->skb->tstamp));
+                       if (tv.tv_sec > NFQNL_TIMEOUT_ENTRY_DROP) {
+                               printk(KERN_ERR "nf_queue: drop timeouted packet "
+                                       "(queue_num=%u seq_id=%u)\n", queue->queue_num, i->id);
+                               list_del(&i->list);
+                               queue->queue_total--;
+                               nf_reinject(i, NF_DROP);
+                       }
                }
        }


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

* Re: [PATCH]: drop packet without verdict from nfqueue after timeout
  2009-03-23 18:48 [PATCH]: drop packet without verdict from nfqueue after timeout Kuzin Andrey
@ 2009-03-23 19:18 ` Patrick McHardy
  2009-03-23 22:05   ` Eric Leblond
  0 siblings, 1 reply; 6+ messages in thread
From: Patrick McHardy @ 2009-03-23 19:18 UTC (permalink / raw)
  To: Kuzin Andrey; +Cc: netfilter-devel

Kuzin Andrey wrote:
> This is patch for problem with stucked packets in nf_queue if
> something going wrong in userspace program. Automatically drop packets
> without any verdict after timeout defined by NFQNL_TIMEOUT_ENTRY_DROP.

I don't want to add per-packet timeouts. The number one problem cause
I've seen in userspace programs so far has been "missed" packets by
incorrect application logic/error handling. These applications usually
continue to send verdicts, they just miss some packets, which accumulate
in the queue until it is full.

There's a very easy and cheap way to handle this. The packets have
sequence numbers and userspace should issues verdicts in ascending
order anyways to avoid reordering. Just add something that will drop
everything in the queue up to the sequence number contained in the
netlink message. And if you want to make it seem like something that
isn't just meant to work around buggy application behaviour, you can
use the same mechanism to add verdict batching :)


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

* Re: [PATCH]: drop packet without verdict from nfqueue after timeout
  2009-03-23 19:18 ` Patrick McHardy
@ 2009-03-23 22:05   ` Eric Leblond
  2009-03-23 22:15     ` Patrick McHardy
  2009-03-24  3:17     ` Kuzin Andrey
  0 siblings, 2 replies; 6+ messages in thread
From: Eric Leblond @ 2009-03-23 22:05 UTC (permalink / raw)
  To: Patrick McHardy; +Cc: Kuzin Andrey, netfilter-devel

[-- Attachment #1: Type: text/plain, Size: 1374 bytes --]

Hi,

Le lundi 23 mars 2009 à 20:18 +0100, Patrick McHardy a écrit :
> Kuzin Andrey wrote:
> > This is patch for problem with stucked packets in nf_queue if
> > something going wrong in userspace program. Automatically drop packets
> > without any verdict after timeout defined by NFQNL_TIMEOUT_ENTRY_DROP.
> 
> There's a very easy and cheap way to handle this. The packets have
> sequence numbers and userspace should issues verdicts in ascending
> order anyways to avoid reordering. Just add something that will drop
> everything in the queue up to the sequence number contained in the
> netlink message.

I don't think the described mechanism is generic enough to be a default
behaviour. It should be useful for projects like snort-inline but it
will really a problem for software like NuFW which are asynchronous by
design.

In NuFW, packet authentication is triggered by a user message (signing
of packet is done is userspace). Thus the ordering of the answer depends
of the ordering of user messages. As NuFW authenticate packet at network
scale (there is thus plenty of users), it is not possible to assume that
the answer will be ordered.

Thus, even if it could be useful, this mechanism should only be
activated by an explicit userspace query. 

BR,
-- 
Eric Leblond <eric@inl.fr>
INL: http://www.inl.fr/
NuFW: http://www.nufw.org/

[-- Attachment #2: Ceci est une partie de message numériquement signée --]
[-- Type: application/pgp-signature, Size: 189 bytes --]

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

* Re: [PATCH]: drop packet without verdict from nfqueue after timeout
  2009-03-23 22:05   ` Eric Leblond
@ 2009-03-23 22:15     ` Patrick McHardy
  2009-03-24  5:23       ` Re[2]: " Kuzin Andrey
  2009-03-24  3:17     ` Kuzin Andrey
  1 sibling, 1 reply; 6+ messages in thread
From: Patrick McHardy @ 2009-03-23 22:15 UTC (permalink / raw)
  To: Eric Leblond; +Cc: Kuzin Andrey, netfilter-devel

Eric Leblond wrote:
>> There's a very easy and cheap way to handle this. The packets have
>> sequence numbers and userspace should issues verdicts in ascending
>> order anyways to avoid reordering. Just add something that will drop
>> everything in the queue up to the sequence number contained in the
>> netlink message.
>>     
>
> I don't think the described mechanism is generic enough to be a default
> behaviour. It should be useful for projects like snort-inline but it
> will really a problem for software like NuFW which are asynchronous by
> design.
>
> In NuFW, packet authentication is triggered by a user message (signing
> of packet is done is userspace). Thus the ordering of the answer depends
> of the ordering of user messages. As NuFW authenticate packet at network
> scale (there is thus plenty of users), it is not possible to assume that
> the answer will be ordered.
>
> Thus, even if it could be useful, this mechanism should only be
> activated by an explicit userspace query. 

Good point. The in-sequence handling is also only necessary per flow,
so this definitely would need to be enabled explicitly.


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

* Re[2]: [PATCH]: drop packet without verdict from nfqueue after timeout
  2009-03-23 22:05   ` Eric Leblond
  2009-03-23 22:15     ` Patrick McHardy
@ 2009-03-24  3:17     ` Kuzin Andrey
  1 sibling, 0 replies; 6+ messages in thread
From: Kuzin Andrey @ 2009-03-24  3:17 UTC (permalink / raw)
  To: netfilter-devel

EL> I don't think the described mechanism is generic enough to be a default
EL> behaviour. It should be useful for projects like snort-inline but it
EL> will really a problem for software like NuFW which are asynchronous by
EL> design.
EL> In NuFW, packet authentication is triggered by a user message (signing
EL> of packet is done is userspace). Thus the ordering of the answer depends
EL> of the ordering of user messages. As NuFW authenticate packet at network
EL> scale (there is thus plenty of users), it is not possible to assume that
EL> the answer will be ordered.
EL> Thus, even if it could be useful, this mechanism should only be
EL> activated by an explicit userspace query. 

Indeed. I use nfqueue for traffic accounting on network gateway. And
as i describe in previous letters after _several tens of millions_ packets
every time i have one or more such packets without verdict.
I can't find any errors in userspace, and i think that Patrick way
may be don't work for catching problem place, earlier i try to use
nfqnl_test example program (easier can't be imagine) for verdict
sending, and some packets don't get verdicts. May be errors take place
in kernel on high load bandwidths due to some SMP/RCU bugs, skbuf
or hardware drivers bugs (forcedeth for example is not so perfect
driver because write by reverse engineering way).
So this patch for me can automatically erase any delays on gateway
due to trash queue fills. I think this feature need to be realize as
menu config options (for people who really need this).




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

* Re[2]: [PATCH]: drop packet without verdict from nfqueue after timeout
  2009-03-23 22:15     ` Patrick McHardy
@ 2009-03-24  5:23       ` Kuzin Andrey
  0 siblings, 0 replies; 6+ messages in thread
From: Kuzin Andrey @ 2009-03-24  5:23 UTC (permalink / raw)
  To: netfilter-devel

>> Thus, even if it could be useful, this mechanism should only be
>> activated by an explicit userspace query. 

PM> Good point. The in-sequence handling is also only necessary per flow,
PM> so this definitely would need to be enabled explicitly.

I fully agree with you, but do this changes it not so easy for me as for you.
I'am newbie in kernel programming. And i think would be better if this
changes will be made by library/kernel maintainer with his experience, point
of view, programming style and other cool stuff.


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

end of thread, other threads:[~2009-03-24  5:22 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-03-23 18:48 [PATCH]: drop packet without verdict from nfqueue after timeout Kuzin Andrey
2009-03-23 19:18 ` Patrick McHardy
2009-03-23 22:05   ` Eric Leblond
2009-03-23 22:15     ` Patrick McHardy
2009-03-24  5:23       ` Re[2]: " Kuzin Andrey
2009-03-24  3:17     ` Kuzin Andrey

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.