libipq and ip_queue
Could someone please enlighten me about the _limitations_ of libipq and ip_queue. Please let me explain what I mean my limitations. I am developing a concept firewall (a combination of an IDS and a firewall) for my undergrad final semester project. This means I would have to develop my own packet mangling and fire-walling code. Though kernel space fire-walling has all the speed/efficiency advantages, for reasons such as development time, I inferred that ip_queue & user space development would be better (am I right?). However I had some doubts if I can do all that netfilter can do at the kernel level with ip_queue and libipq (especially NAT).
<snip from the Netfilter Hacking Guide>
"Using the libipq library and the `ip_queue' module, almost anything which can be done inside the kernel can now be done in userspace"
</snip>
Marking the words *almost anything*, I had my doubts and thought that the devel list would be the best place to get further information.
Thank you for your time people.
Signature · 2 lines
CCK./ "Passion and gradualness" -- Pavlov.
Quoted 2 lines · Chandrakanth Chereddi
Marking the words *almost anything*, I had my doubts and thought that the devel list would be the best place to get further information.
There is a few limitations to ip_queue, but probably nothing major for your application.
ipqueue provides you access to the IP packet and payload, but does not give you access to the complete MAC header of the packet, only the destination MAC address.
You can modify the packet payload including IP header, but you can not modify the nfmark, routing or other skb fields outside the packet payload. I think there was a patch floating around to extend ipq with the ability to set the nfmark if needed some time ago (many months).
In addition, packet mangling via ip_queue or in fact any netfilter hook outside the same does not work well together with netfilter conntrack or NAT so be careful if you plan on using any of these features.
Regards
Henrik
Quoted 4 lines · Henrik Nordstrom
Quoted 2 lines · Chandrakanth Chereddi
Marking the words *almost anything*, I had my doubts and thought that the devel list would be the best place to get further information.
Thank you for your reply Henrik.
Quoted 3 lines
ipqueue provides you access to the IP packet and payload, but does not give you access to the complete MAC header of the packet, only the destination MAC address.
I don't think I will need any Layer 2 filtering, so this should not cause any problem.
Quoted 4 lines
You can modify the packet payload including IP header, but you can not modify the nfmark, routing or other skb fields outside the packet payload. I think there was a patch floating around to extend ipq with the ability to set the nfmark if needed some time ago (many months).
nfmark and the contrack entries are not of much concern, cause they are specific netfilter headers. But, could you probably tell me what the routing entries will stop me from doing - Mirroring?, Masquerading? I mean, how often does netfilter have to modify routing entries and under what circumstances. (Yes, I am newbie to the netfilter arch.)
Quoted 3 lines
In addition, packet mangling via
ip_queueor in fact any netfilter hook outside the same does not work well together with netfilter conntrack or NAT so be careful if you plan on using any of these features.
I do want to implement NAT, but in the userspace, (can this be done!!!). I don't plan to depend on netfilter for anything more than getting a packet from kernel space to user space and delivering it back to take the appt. action. I am guessing that this will not cause any problem, cause all traffic is either firewalled or mangled only through my application/
And one last question, can I set the "policy" on a chain to "QUEUE", I wasn't successful in doing that on my machine though.
Once again, thanks Henrik and the Netfilter development team.
Signature · 2 lines
CCK./ "Passion and gradualness" -- Pavlov.
Quoted 2 lines · Chandrakanth Chereddi
And one last question, can I set the "policy" on a chain to "QUEUE", I wasn't successful in doing that on my machine though.
If it's through libiptc that you are trying to do this, the TC_SET_POLICY() function makes a check for 'ACCEPT' and 'DROP' and invalidates any other policy.
The method ip_fw_chk() in ipfwadm_core too checks the policies and goes with FW_BLOCK if it doesn't have any idea about the policy. May be you can tinker with the code here.
But the easiest thing that a newbie like me'd do is append a rule at the end of the chain with what ever target is needed :)
Regards,
Vijaya Chandra Vupputuri,
Tachyon Technologies.
Quoted 3 lines · Chandrakanth Chereddi
nfmark and the contrack entries are not of much concern, cause they are specific netfilter headers. But, could you probably tell me what the routing entries will stop me from doing - Mirroring?, Masquerading?
You can do everything, as long as you do not need to change how the packet is routed if the packet you are looking at has already got it's route calculated.
For the fine details on when routes are calculated in relation to the netfilter hooks see the netfilter hacking howto.
nfmark is not netfilter specific. It is a means whereby netfilter can provide hints to other parts of the kernel about how this packet should be processed. Both routing and tc have directives to make use of the nfmark in the decision process.
Quoted 2 lines
mean, how often does netfilter have to modify routing entries and under what circumstances. (Yes, I am newbie to the netfilter arch.)
The routing is primarily modified as part of NAT, to have the packets rerouted according to the packet headers after NAT. For forwarded packets this is rarely needed but in cases where NAT is applied to locally generated traffic there is cases where the packet will be routed even before it exists (first packet of a unbound session). See the smallprint in the netfilter hacking howto for the fine details.
Quoted 1 line
I do want to implement NAT, but in the userspace, (can this be done!!!).
Ok.
As long as you do not plan on using the conntrack or NAT kernel parts of Netfilter you are fine, or at least unless the re-routing restrictions bite you.
What I am saying is that if you are doing NAT or similar packet mangling in userspace then the conntrack or NAT functions of netfilter must not be used.
Quoted 2 lines
And one last question, can I set the "policy" on a chain to "QUEUE", I wasn't successful in doing that on my machine though.
Never tried, but I do not see any reason why this should not be possible. QUEUE is a builtin target primitive in netfilter. But it seems you are right, the iptables command does not accept QUEUE as policy.
Available options:
* use a single iptables rule with QUEUE target instead of having it as a
policy.
* or modify the iptables command to accept QUEUE as a valid policy,
* or write your own netfilter hook returning QUEUE as verdict, avoiding
the need of iptables entirely.
Regards
Henrik