SNAT and IP ID -> what can be mangled by routers?
A message that is not in the archive (sent off-list or not yet received): 20030502222622.31281.56108.Mailman@kashyyyk
This question reminds me of something I've been wondering about. It seems to me that some parts of an IP packet can be arbitrarily changed by the forwarding infrastructure.
The TOS field seems like one good example. When I send a packet to my ISP it can (I believe, or at least should be allowed to) change the TOS field as it wishes to influence where and when that packet is forwarded. What arrives at the ultimate destination need not bear any resemblance to what I sent.
The possible danger I see from this is that, after the TOS is altered, some router might decide to send me an ICMP reply saying that it could not forward this packet. This means that when I receive that reply I should NOT expect the TOS field in the reply (I mean the one in the ICMP content part containing the beginning of the packet as it was received at that router) to be the same as the one I sent. Clearly I should expect the TTL to also be different. Perhaps I should also not expect, e.g., the IP ID field to be the same? If I can rely on the ID field to be the same then it becomes an expensive proposition to mangle IDs at the firewall since you have to be able to UNmangle the ICMP replies, which requires possibly a lot of memory.
The linux source appears to me to identify icmp packets only by source and destination IP addresses and ports (and something else I don't quite understand - arrival interface? Can someone explain this?). So if the TOS or ID were mangled on the way to the router sending the reply this would have no effect, I believe. (Any other opinions?)
The real question:
Are there any standards that indicate what parts of the ICMP reply the recipient can count on to be the same as the packet originally sent? If so, which are they and what do they say?
Quoted 4 lines · Don Cohen
This question reminds me of something I've been wondering about. It seems to me that some parts of an IP packet can be arbitrarily changed by the forwarding infrastructure.
yes.
Quoted 5 lines
The TOS field seems like one good example. When I send a packet to my ISP it can (I believe, or at least should be allowed to) change the TOS field as it wishes to influence where and when that packet is forwarded. What arrives at the ultimate destination need not bear any resemblance to what I sent.
indeed. However, the TOS bits have never been used in any larger scope larger than a particular site, since their interpretation changed three times over the years...
Quoted 3 lines
The possible danger I see from this is that, after the TOS is altered, some router might decide to send me an ICMP reply saying that it could not forward this packet.
I don't think this would be a valid operation. Of course you can
configure a packet filter to do so - but I don't think you will find any valid RFC telling you that this is a valid means of operation for the TOS bits. Of course the packet can get a lower priority, probably dropped by some queuing mechanism - but send an ICMP back ?
Quoted 4 lines
This means that when I receive that reply I should NOT expect the TOS field in the reply (I mean the one in the ICMP content part containing the beginning of the packet as it was received at that router) to be the same as the one I sent.
yes.
Quoted 1 line
Clearly I should expect the TTL to also be different.
sure.
Quoted 5 lines
Perhaps I should also not expect, e.g., the IP ID field to be the same? If I can rely on the ID field to be the same then it becomes an expensive proposition to mangle IDs at the firewall since you have to be able to UNmangle the ICMP replies, which requires possibly a lot of memory.
Interesting issue. But IMHO you should not make assumptions on the IP ID field. The IP ID field has a single purpose: fragment reassembly at the destination.
Quoted 6 lines
The linux source appears to me to identify icmp packets only by source and destination IP addresses and ports (and something else I don't quite understand - arrival interface? Can someone explain this?).
So if the TOS or ID were mangled on the way to the router sending the reply this would have no effect, I believe. (Any other opinions?)
At least not to the linux (and any other sane) TCP/IP stack.
Quoted 4 lines
The real question:
Are there any standards that indicate what parts of the ICMP reply the recipient can count on to be the same as the packet originally sent? If so, which are they and what do they say?
I've re-read the respective RFC's (1122,792,1812,...) and I didn't come up with a clear answer. The closest we get is:
"The returned IP header (and user data) MUST be identical to that which was received, except that the router is not required to undo any modifications to the IP header that are normally performed in forwarding that were performed before the error was detected (e.g., decrementing the TTL, or updating options)."
An IP ID change is certainly nothing 'normally performed in forwarding'.
Signature · 5 lines
- Harald Welte <[email protected]> http://www.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
(finally a reply!)
Quoted 11 lines
Quoted 2 lines
It seems to me that some parts of an IP packet can be arbitrarily changed by the forwarding infrastructure.
yes.
Quoted 5 lines
The TOS field seems like one good example. When I send a packet to my ISP it can (I believe, or at least should be allowed to) change the TOS field as it wishes to influence where and when that packet is forwarded. What arrives at the ultimate destination need not bear any resemblance to what I sent.
indeed. However, the TOS bits have never been used in any larger scope larger than a particular site, since their interpretation changed three times over the years...
It has changed, but I think it has always been used in a larger scope. Originally I think it was not supposed to be changed and the entire forwarding path was meant to use it. Now I think it's allowed to be changed anywhere and any place can use it. Certainly the diffserve per-hop-behaviors do use it throughout the forwarding infrastructure.
Quoted 8 lines
Quoted 3 lines
The possible danger I see from this is that, after the TOS is altered, some router might decide to send me an ICMP reply saying that it could not forward this packet.
I don't think this would be a valid operation. Of course you can
configure a packet filter to do so - but I don't think you will find any valid RFC telling you that this is a valid means of operation for the TOS bits. Of course the packet can get a lower priority, probably dropped by some queuing mechanism - but send an ICMP back ?
You must have misunderstood me. I imagine that I send a packet with TOS=13 and DF bit set. My ISP immediately changes TOS to 3 and forwards it. Later on in the path some router has a small MTU and is required to drop the packet. It then sends me back an ICMP about dropping the packet due to DF and this reply contains a header with TOS=3.
Quoted 11 lines
Quoted 4 lines
This means that when I receive that reply I should NOT expect the TOS field in the reply (I mean the one in the ICMP content part containing the beginning of the packet as it was received at that router) to be the same as the one I sent.
yes.
Quoted 5 lines
Perhaps I should also not expect, e.g., the IP ID field to be the same? If I can rely on the ID field to be the same then it becomes an expensive proposition to mangle IDs at the firewall since you have to be able to UNmangle the ICMP replies, which requires possibly a lot of memory.
It now occurs to me that it could also take a lot of memory to do this ID mangling in the first place. You effectively have to defragment. Then if you want to unmangle you have to remember the mapping until you're sure no ICMP replies for that packet can return.
Quoted 3 lines
Interesting issue. But IMHO you should not make assumptions on the IP ID field. The IP ID field has a single purpose: fragment reassembly at the destination.
Who should not assume what?
The firewall implementer should not assume that the OS at the end point will NOT compare the ID it sent with the ID it received? Then the firewall must unmangle the ID, which is expensive. Or the implementer of the OS at the end point should not assume that that ID it receives will be the same as the one it sent?
Your second sentence, about the single purpose of the ID, suggests that you take the second view. Of course, this is the view that's better for you, the firewall implementer. I like that view because it's better for me too. It allows me to use that ID for other things that were never intended by the spec without having to worry about unmangling them (which would be even harder for what I have in mind than for a firewall).
Quoted 3 lines
Quoted 2 lines
So if the TOS or ID were mangled on the way to the router sending the reply this would have no effect, I believe. (Any other opinions?)
At least not to the linux (and any other sane) TCP/IP stack.
Things would be much simpler if we could assume sanity.
Quoted 8 lines
Quoted 4 lines
The real question:
Are there any standards that indicate what parts of the ICMP reply the recipient can count on to be the same as the packet originally sent? If so, which are they and what do they say?I've re-read the respective RFC's (1122,792,1812,...) and I didn't come up with a clear answer. The closest we get is:
Quoted 7 lines
"The returned IP header (and user data) MUST be identical to that which was received, except that the router is not required to undo any modifications to the IP header that are normally performed in forwarding that were performed before the error was detected (e.g., decrementing the TTL, or updating options)."
An IP ID change is certainly nothing 'normally performed in forwarding'.
But this means what was received by the router, right?
Not necessarily the same that was sent by the originator of the packet. So the question remains about which fields can be changed along the forwarding path.
Quoted 1 line · Don Cohen
(finally a reply!)
;)
Quoted 3 lines
It has changed, but I think it has always been used in a larger scope. Originally I think it was not supposed to be changed and the entire forwarding path was meant to use it.
Yes, but this 'original' use must date back >10 years or something.
Quoted 3 lines
Now I think it's allowed to be changed anywhere and any place can use it. Certainly the diffserve per-hop-behaviors do use it throughout the forwarding infrastructure.
exactly. This is, why - strictly speaking - there is no TOS anymore. There's just DSCP and ECN.
But now, depending of the time of implementation of your hosts and routers along the forwarding path, every device will use a different interpretation. that's why it's unusable outside a site-local scope where you know your equipment.
Quoted 8 lines
Quoted 8 lines
Quoted 3 lines
The possible danger I see from this is that, after the TOS is altered, some router might decide to send me an ICMP reply saying that it could not forward this packet.
I don't think this would be a valid operation. Of course you can
configure a packet filter to do so - but I don't think you will find any valid RFC telling you that this is a valid means of operation for the TOS bits. Of course the packet can get a lower priority, probably dropped by some queuing mechanism - but send an ICMP back ?
Quoted 6 lines
You must have misunderstood me. I imagine that I send a packet with TOS=13 and DF bit set. My ISP immediately changes TOS to 3 and forwards it. Later on in the path some router has a small MTU and is required to drop the packet. It then sends me back an ICMP about dropping the packet due to DF and this reply contains a header with TOS=3.
I see. Yes. But in the TOS case, I assume that the quoted sentence from my last email really does apply. If TOS is something
Quoted 9 lines
Quoted 5 lines
Quoted 5 lines
Perhaps I should also not expect, e.g., the IP ID field to be the same? If I can rely on the ID field to be the same then it becomes an expensive proposition to mangle IDs at the firewall since you have to be able to UNmangle the ICMP replies, which requires possibly a lot of memory.
It now occurs to me that it could also take a lot of memory to do this ID mangling in the first place. You effectively have to defragment. Then if you want to unmangle you have to remember the mapping until you're sure no ICMP replies for that packet can return.
Talking about the netfilter case: If you do conntrack, we defragment (and possibly refragment) anyway. So unless we want to be able to un-mangle the IPID, there is no additional memory consumption.
Quoted 5 lines
Quoted 3 lines
Interesting issue. But IMHO you should not make assumptions on the IP ID field. The IP ID field has a single purpose: fragment reassembly at the destination.
Who should not assume what?
I thought nobody than the receiver should make assumptions on the IP ID field, since it has a sole purpose...
Quoted 2 lines
Or the implementer of the OS at the end point should not assume that that ID it receives will be the same as the one it sent?
I think this is my personal view (of the perfect world). However, I would imagine that there is some strange IP stack that does compare the IPID, thus
Quoted 1 line
Things would be much simpler if we could assume sanity.
yes. But then, who expects some implementor of an IP stack, possibly a decade ago, think about firewalls/NAT devices that could possibly want to mangle the IP ID?
Quoted 10 lines
Quoted 7 lines
"The returned IP header (and user data) MUST be identical to that which was received, except that the router is not required to undo any modifications to the IP header that are normally performed in forwarding that were performed before the error was detected (e.g., decrementing the TTL, or updating options)."
An IP ID change is certainly nothing 'normally performed in forwarding'.
But this means what was received by the router, right?
Not necessarily the same that was sent by the originator of the packet.
Yes, but if every router doesn't do any modifications, that are not normally performed in forwarding, it should be the same packet.
Quoted 2 lines
So the question remains about which fields can be changed along the forwarding path.
And I doubt you will find a satisfying answer...
Signature · 5 lines
- Harald Welte <[email protected]> http://www.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