Routing decision?
Hi
In paragraph 6.2 of the iptables-tutorial the following is said:
"The OUTPUT chain is used for altering locally generated packets (i.e., on the firewall) before they get to the routing decision.
But in paragraph 3.1, the "Traversing of tables and chains" diagram, we see the "Routing decision" is listed after the "Local process" and BEFORE! the packet goes to the output chain.
So which one is right? Does the routing decision take place after or before the packet travels through the output chain?
Regards
Signature · 15 lines
Wim Ceulemans R&D Engineer Secure Internet Communication with aXs Guard Able NV Leuvensesteenweg 282 - B-3190 Boortmeerbeek - Belgium Phone: + 32 15 50.44.00 - Fax: + 32 15 50.44.09 E-mail: [email protected] -- Security check on this e-mail has been done by aXs GUARD (http://www.axsguard.com)
Quoted 3 lines · Wim Ceulemans
In paragraph 6.2 of the iptables-tutorial the following is said:
"The OUTPUT chain is used for altering locally generated packets (i.e., on the firewall) before they get to the routing decision.
Yes.
Quoted 6 lines
But in paragraph 3.1, the "Traversing of tables and chains" diagram, we see the "Routing decision" is listed after the "Local process" and BEFORE! the packet goes to the output chain.
So which one is right? Does the routing decision take place after or before the packet travels through the output chain?
Both, depending on the situation.
if the local endpoint of the socket sending the packet is bound then routing occurs after OUTPUT.
If the local endpoint of the socket is NOT bound then routing occurs before OUTPUT to assign the source address.
Regards
Henrik
Henrik
Thanks for your answer.
If I understand correct, if the local endpoint of the socket is not bound, then:
1. The routing decision is taken, and the source IP address is assigned to the IP address of the interface through which the packet would leave the firewall.
2. The packet travels through the OUTPUT chain and does not pass the routing decision anymore, because the routing decision was already taken before going to the OUTPUT
chain.
Is there any specific reason why the packet doesn't pass the routing decision the second time?
Regards
Wim
Quoted 33 lines · Henrik Nordstrom
Quoted 4 lines · Wim Ceulemans
In paragraph 6.2 of the iptables-tutorial the following is said:
"The OUTPUT chain is used for altering locally generated packets (i.e., on the firewall) before they get to the routing decision.Yes.
Quoted 6 lines
But in paragraph 3.1, the "Traversing of tables and chains" diagram, we see the "Routing decision" is listed after the "Local process" and BEFORE! the packet goes to the output chain.
So which one is right? Does the routing decision take place after or before the packet travels through the output chain?
Both, depending on the situation.
if the local endpoint of the socket sending the packet is bound then routing occurs after OUTPUT.
If the local endpoint of the socket is NOT bound then routing occurs before OUTPUT to assign the source address.
Regards
Henrik
Signature · 15 lines
Wim Ceulemans R&D Engineer Secure Internet Communication with aXs Guard Able NV Leuvensesteenweg 282 - B-3190 Boortmeerbeek - Belgium Phone: + 32 15 50.44.00 - Fax: + 32 15 50.44.09 E-mail: [email protected] -- Security check on this e-mail has been done by aXs GUARD (http://www.axsguard.com)
Quoted 5 lines · Wim Ceulemans
If I understand correct, if the local endpoint of the socket is not bound, then:
1. The routing decision is taken, and the source IP address is assigned to the IP address of the interface
through which the packet would leave the firewall.
Yes. Or to be more precise to the source IP address of the route by which the packet would leave the host, or interface address if no route source address is defined in the routing table.
Quoted 4 lines
2. The packet travels through the OUTPUT chain and does not pass the routing decision anymore, because
the routing decision was already taken before going to the OUTPUT
chain.
Yes.
However on the next packet of the connection (assuming it is a TCP connection) the situation is the reverse. The local endpoint of the socket is now bound and there is no need for a routing decision during packet construction as the source IP address is already know. So now routing occurs after OUTPUT like it logically should be.
Quoted 2 lines
Is there any specific reason why the packet doesn't pass the routing decision the second time?
Why should it if the routing has already been called once?
iptables does route the packet a second time if you mangle or NAT the packet.
Regards
Henrik
Quoted 30 lines · Henrik Nordstrom
Quoted 5 lines · Wim Ceulemans
If I understand correct, if the local endpoint of the socket is not bound, then:
1. The routing decision is taken, and the source IP address is assigned to the IP address of the interface through which the packet would leave the firewall.Yes. Or to be more precise to the source IP address of the route by which the packet would leave the host, or interface address if no route source address is defined in the routing table.
Quoted 5 lines
2. The packet travels through the OUTPUT chain and does not pass the routing decision anymore, because the routing decision was already taken before going to the OUTPUT
chain.Yes.
However on the next packet of the connection (assuming it is a TCP connection) the situation is the reverse. The local endpoint of the socket is now bound and there is no need for a routing decision during packet construction as the source IP address is already know. So now routing occurs after OUTPUT like it logically should be.
Quoted 6 lines
Quoted 3 lines
Is there any specific reason why the packet doesn't pass the routing decision the second time?
Why should it if the routing has already been called once?
Here's why: if you want to mark packets in the OUTPUT chain that are http traffic, based on the destination port. And then based on that mark send the packets to another routing table added with the ip command.
Quoted 10 lines
iptables does route the packet a second time if you mangle or NAT the packet.
Regards
Henrik
Signature · 15 lines
Wim Ceulemans R&D Engineer Secure Internet Communication with aXs Guard Able NV Leuvensesteenweg 282 - B-3190 Boortmeerbeek - Belgium Phone: + 32 15 50.44.00 - Fax: + 32 15 50.44.09 E-mail: [email protected] -- Security check on this e-mail has been done by aXs GUARD (http://www.axsguard.com)
Quoted 6 lines · Wim Ceulemans
Quoted 1 line
Why should it if the routing has already been called once?
Here's why: if you want to mark packets in the OUTPUT chain that are http traffic, based
on the destination port. And then based on that mark send the packets to another routing table
added with the ip command.
See below...
Quoted 2 lines
Quoted 2 lines
iptables does route the packet a second time if you mangle or NAT the packet.
If the packet is altered in any way (mangling or NATing), then routing is called again, because the change(s) can change routing decision. Marking as you mentionned, but also TOS or source address can be routing keys.
Signature · 2 lines
http://www.netexit.com/~sid/ PGP KeyID: 157E98EE FingerPrint: FA62226DA9E72FA8AECAA240008B480E157E98EE
Quoted 3 lines · Wim Ceulemans
Here's why: if you want to mark packets in the OUTPUT chain that are http traffic, based on the destination port. And then based on that mark send the packets to another routing table added with the ip command.
Then do so. iptables will make the needed re-routing of the packet when the nfmark is modified.
But you can't use this to select the source IP address as this has already been done and must be done before the packet is constructed (and sent to iptables), however you can use NAT to rewrite the source IP address if not assigned suitably or alternaively (preferred) have the application use a suitable source IP address to begin with.
Regards
Henrik
Quoted 34 lines · Henrik Nordstrom
Quoted 5 lines · Wim Ceulemans
If I understand correct, if the local endpoint of the socket is not bound, then:
1. The routing decision is taken, and the source IP address is assigned to the IP address of the interface through which the packet would leave the firewall.Yes. Or to be more precise to the source IP address of the route by which the packet would leave the host, or interface address if no route source address is defined in the routing table.
Quoted 5 lines
2. The packet travels through the OUTPUT chain and does not pass the routing decision anymore, because the routing decision was already taken before going to the OUTPUT
chain.Yes.
However on the next packet of the connection (assuming it is a TCP connection) the situation is the reverse. The local endpoint of the socket is now bound and there is no need for a routing decision during packet construction as the source IP address is already know. So now routing occurs after OUTPUT like it logically should be.
Quoted 3 lines
Is there any specific reason why the packet doesn't pass the routing decision the second time?
Quoted 11 lines
Why should it if the routing has already been called once?
iptables does route the packet a second time if you mangle or NAT the packet.
Regards
Henrik
Henrik
Sorry to come back to this problem.
Wouldn't the firewall be more predictable if the routing decision was always taken after the packet travels through the OUTPUT chain, even if it was a packet originating from an unbound socket? In that way the diagram in the netfilter tutorial would be true in all cases, and also if advanced routing with the ip command is used, it would work with all packets (originating from bound or unbound sockets).
Of course for packets originating from unbound sockets this would lead to the fact that the routing decision code is gone through twice, but the first time only for determining the source address, and the second time to be able to re-route the packet to another interface (based on marks set in the output chain).
Regards
Wim
Signature · 15 lines
Wim Ceulemans R&D Engineer Secure Internet Communication with aXs Guard Able NV Leuvensesteenweg 282 - B-3190 Boortmeerbeek - Belgium Phone: + 32 15 50.44.00 - Fax: + 32 15 50.44.09 E-mail: [email protected] -- Security check on this e-mail has been done by aXs GUARD (http://www.axsguard.com)
Quoted 6 lines · Wim Ceulemans
Wouldn't the firewall be more predictable if the routing decision was always taken after the packet travels through the OUTPUT chain, even if it was a packet originating from an unbound socket? In that way the diagram in the netfilter tutorial would be true in all cases, and also if advanced routing with the ip command is used, it would work with all packets (originating from bound or unbound sockets).
The routing takes place before OUTPUT on unbound sockets as it is the routing table who decides the source IP address to use if the socket is unbound, and it is impossible to create the packet without having the source address.
Quoted 5 lines
Of course for packets originating from unbound sockets this would lead to the fact that the routing decision code is gone through twice, but the first time only for determining the source address, and the second time to be able to re-route the packet to another interface (based on marks set in the output chain).
Yes, and this is what happens when it is needed.
The kernel uses routing before output to find the source IP address.
Then when iptables changes the packet in such manner that the routing may change it calls the routing again, but only if the packet is modified by iptables.
If there is no changes in the packet details iptables does not call routing again as it can be assumed the result will be the same as in the first call.
Regards
Henrik
Quoted 19 lines · Henrik Nordstrom
Quoted 4 lines · Wim Ceulemans
Wouldn't the firewall be more predictable if the routing decision was always taken after the packet travels through the OUTPUT chain, even if it was a packet originating from an unbound socket? In that way the diagram in the netfilter tutorial would be true in all cases, and also if advanced routing with the ip command is used, it would work with all packets (originating from bound or unbound sockets).
The routing takes place before OUTPUT on unbound sockets as it is the routing table who decides the source IP address to use if the socket is unbound, and it is impossible to create the packet without having the source address.
Quoted 3 lines
Of course for packets originating from unbound sockets this would lead to the fact that the routing decision code is gone through twice, but the first time only for determining the source address, and the second time to be able to re-route the packet to another interface (based on marks set in the output chain).
Yes, and this is what happens when it is needed.
Quoted 11 lines
The kernel uses routing before output to find the source IP address.
Then when iptables changes the packet in such manner that the routing may change it calls the routing again, but only if the packet is modified by iptables.
If there is no changes in the packet details iptables does not call routing again as it can be assumed the result will be the same as in the first call.
Regards
Henrik
Henrik
Ok, but the problem is that setting a mark on the packet isn't considered as a change to the packet, since marks only live in the kernel and have no effect on the packet.
So, if I want to re-route the packet later on because for example it is an http packet (destination port is 80, 1080 or 8080) then I have to change something in the packet just to be able to re-route it. But I don't want to change something in the packet, I just want to re-route it to another interface based on the mark.
Do you have an idea how we could do this without using unbound packets?
Thanks and Regards
Wim
Signature · 15 lines
Wim Ceulemans R&D Engineer Secure Internet Communication with aXs Guard Able NV Leuvensesteenweg 282 - B-3190 Boortmeerbeek - Belgium Phone: + 32 15 50.44.00 - Fax: + 32 15 50.44.09 E-mail: [email protected] -- Security check on this e-mail has been done by aXs GUARD (http://www.axsguard.com)
Quoted 3 lines · Wim Ceulemans
Ok, but the problem is that setting a mark on the packet isn't considered as a change to the packet, since marks only live in the kernel and have no effect on the packet.
Changing marks are considered a change in the packet in this context.
If mangle OUTPUT changes any of Source IP, Destination IP, ToS or nfmark then the packet is automatically rerouted by iptables.
Regards
Henrik
Ok, thanks Henrik, we will try the mark in the mangle table.
Regards
Wim
Quoted 19 lines · Henrik Nordstrom
Quoted 4 lines · Wim Ceulemans
Ok, but the problem is that setting a mark on the packet isn't considered as a change to the packet, since marks only live in the kernel and have no effect on the packet.
Changing marks are considered a change in the packet in this context.
If mangle OUTPUT changes any of Source IP, Destination IP, ToS or nfmark then the packet is automatically rerouted by iptables.
Regards
Henrik
Signature · 15 lines
Wim Ceulemans R&D Engineer Secure Internet Communication with aXs Guard Able NV Leuvensesteenweg 282 - B-3190 Boortmeerbeek - Belgium Phone: + 32 15 50.44.00 - Fax: + 32 15 50.44.09 E-mail: [email protected] -- Security check on this e-mail has been done by aXs GUARD (http://www.axsguard.com)