Skip to contentSkip to conversation

execution context in netfilter hooks.

DISCUSSION Giacomo 4 participants 4 messages Dec 11, 2005 – Dec 13, 2005 netfilter

lore
Share & tools
lore

Giacomo

author
#0 lore raw

Good morning, i would like to know exactly the context of execution of code registered with netfilter hooks.
As far as I understood, the context is that of a softirq, inside a
bottom half. Correct me if i'm wrong..

But is it concerned with tasklets?

Is execution serialized? In other words, if packet A fr instance is received from the net, and then packet
B immediately, is packet A processed entirely before packet B? Or code can be executed in parallel
for packet A and B?

Moreover: interrupts are enabled in such context, aren't they? And that means that also a
software timer can interrupt a routine being executed in bottom half.

But software timers run with sw interrupts disabled, so a timeout handler for instance cannot
be interrupted by a routine managing reception of a packet arrived on the wire.

It is not clear to me the concurrency to which structures are subject, also in an uniprocessor system:
in_irq(), in_softirq(), in_interrupt() functions return different values also if positioned at the same place in the code... is there a mean (function) to know if sofware/hw interrupts are enabled in a portion of code?

Thanks a lot for any suggestion or any indication to understand how things are really.

Giacomo.

#1 lore raw
Quoted 5 lines · Giacomo

Good morning, i would like to know exactly the context of execution of code registered with netfilter hooks.

As far as I understood, the context is that of a softirq, inside a
bottom half. Correct me if i'm wrong..

'bottom half' context doesn't really exist anymore in 2.6.x, so it's softirq. But that's only true for forwarded packets. locally-generated packets at LOCAL_OUT are in 'kernel on behalf of process' context.

Quoted 1 line

But is it concerned with tasklets?

what do you mean by "is it concerned" ?

Quoted 4 lines

Is execution serialized? In other words, if packet A fr instance is received from the net, and then packet B immediately, is packet A processed entirely before packet B? Or code can be executed in parallel for packet A and B?

on multiple cpu's it's fully parallel, so yes, packet A will execute the same netfilter hook (plus attached code) on CPU1 where packet B will run on CPU2.

On a single CPU, Packet B will be put onto a queue (by the hardirq handler of the network driver) until packet A's softirq processing has finished. Then packet B will enter softirq context and pulled from that queue.

Quoted 3 lines

Moreover: interrupts are enabled in such context, aren't they? And that means that also a software timer can interrupt a routine being executed in bottom half.

software timers dont interrupt softirq context. (neither did the interrupt bottom half context, when it still existed). you seem to be confused about the kernel contexts and their interaction.

Quoted 3 lines

But software timers run with sw interrupts disabled, so a timeout handler for instance cannot be interrupted by a routine managing reception of a packet arrived on the wire.

I think you should read some general information on how softirq and hardirq processing work. This is not really netfilter related.

Signature · 5 lines
- Harald Welte <[email protected]>                 http://netfilter.org/
============================================================================
  "Fragmentation is like classful addressing -- an interesting early
   architectural error that shows how much experimentation was going
   on while IP was being designed."                    -- Paul Vixie
#2 lore raw

A last question:

you said LOCAL_OUT is on behalf of process, so it is in process
context -> can be interrupted by timer -> the reason why code crashed! If so, the question would be finally clear!

LOCAL_INPUT instead should be softirq, shouldn't it? Just like FORWARD... so timers don't cause interruption..

Thanks a lot very much!

Giacomo.

2005/12/12, Harald Welte <[email protected]>:

Quoted 44 lines · Giacomo
Quoted 5 lines

Good morning, i would like to know exactly the context of execution of code registered with netfilter hooks.

As far as I understood, the context is that of a softirq, inside a
bottom half. Correct me if i'm wrong..

'bottom half' context doesn't really exist anymore in 2.6.x, so it's softirq. But that's only true for forwarded packets. locally-generated packets at LOCAL_OUT are in 'kernel on behalf of process' context.

Quoted 1 line

But is it concerned with tasklets?

what do you mean by "is it concerned" ?

Quoted 4 lines

Is execution serialized? In other words, if packet A fr instance is received from the net, and then packet B immediately, is packet A processed entirely before packet B? Or code can be executed in parallel for packet A and B?

on multiple cpu's it's fully parallel, so yes, packet A will execute the same netfilter hook (plus attached code) on CPU1 where packet B will run on CPU2.

On a single CPU, Packet B will be put onto a queue (by the hardirq handler of the network driver) until packet A's softirq processing has finished. Then packet B will enter softirq context and pulled from that queue.

Quoted 3 lines

Moreover: interrupts are enabled in such context, aren't they? And that means that also a software timer can interrupt a routine being executed in bottom half.

software timers dont interrupt softirq context. (neither did the interrupt bottom half context, when it still existed). you seem to be confused about the kernel contexts and their interaction.

Quoted 3 lines

But software timers run with sw interrupts disabled, so a timeout handler for instance cannot be interrupted by a routine managing reception of a packet arrived on the wire.

I think you should read some general information on how softirq and hardirq processing work. This is not really netfilter related.

Quoted 9 lines

--
- Harald Welte <[email protected]> http://netfilter.org/
============================================================================
"Fragmentation is like classful addressing -- an interesting early
architectural error that shows how much experimentation was going
on while IP was being designed." -- Paul Vixie

--

Giacomo S.
http://www.giacomos.it

- - - - - - - - - - - - - - - - - - - - - -

Running IPFIRE-wall on debian GNU/Linux
http://www.giacomos.it/ipfire
http://www.debian.org

mailto:
[email protected]
[email protected]
[email protected]

- - - - - - - - - - - - - - - - - - - - - -

#3 lore raw
Quoted 5 lines · Giacomo

A last question:

you said LOCAL_OUT is on behalf of process, so it is in process
context -> can be interrupted by timer -> the reason why code crashed! If so, the question would be finally clear!

Some packets traversing LOCAL_OUT can be in process context, those can be interrupted by timers or whatever interrupt handling. But some others can be in interrupt context because of retransmissions and other issues. So, the affirmation: "packets in LOCAL_OUT are in process context" is bogus.

Moreover, you must also worry about preemption, eg. if preemption is enabled one packet traversing LOCAL_OUT can be preempted by other one from a process that has more priority. Although it is not recommended to enable preemption in a server, you'll have to make your code preemption-safe.

BTW, some people enable preemption in their firewalls because they don't fully understand the concept. IMO, a firewall won't gain any advanges from preemption since most of the work will come from interrupt context.

Quoted 2 lines

LOCAL_INPUT instead should be softirq, shouldn't it? Just like FORWARD... so timers don't cause interruption..

That's it.

Signature · 1 line
Pablo