Skip to contentSkip to conversation

clone packet with new destination address

DISCUSSION Stephen Clark 3 participants 16 messages Oct 22, 2010 – Nov 2, 2010 netfilter

lore
Share & tools
lore
#0 lore raw

Hello,

Problem:
I have a two monitoring servers behind a a linux firewall, one is primary and one is backup. In the field we have units sending udp informational packet to the primary server. On the linux firewall I would like to copy this packet and change the destination address of the copied packet to point to the backup server. Is there a way to do this without writing any code?

NOTE:
Currently the firewall is FreeBSD and we accomplish this rather easily using ipfw along with natd, but we want to move to linux for our firewall.

Thanks for any ideas,
Steve

Signature · 5 lines
"They that give up essential liberty to obtain temporary safety,
deserve neither liberty nor safety."  (Ben Franklin)

"The course of history shows that as a government grows, liberty
decreases."  (Thomas Jefferson)
#1 lore raw
Quoted 12 lines · Stephen Clark

Hello,

Problem:
I have a two monitoring servers behind a a linux firewall, one is primary and one is backup.
In the field we have units sending udp informational packet to the primary server. On the
linux firewall I would like to copy this packet and change the destination address of the copied
packet to point to the backup server. Is there a way to do this without writing any code?

Quoted 4 lines

NOTE:
Currently the firewall is FreeBSD and we accomplish this rather easily using ipfw along with natd, but we want to move to linux for our firewall.

I think you can use tc action mirred to mirror the packets to a fake NIC device ifb, and use tc action nat to dnat the packets received from ifb.

Signature · 2 lines
Regards,
Changli Gao([email protected])
#2 lore raw
Quoted 13 lines · Changli Gao
Quoted 12 lines · Stephen Clark

Hello,

Problem:
I have a two monitoring servers behind a a linux firewall, one is primary and one is backup.
In the field we have units sending udp informational packet to the primary server. On the
linux firewall I would like to copy this packet and change the destination address of the copied
packet to point to the backup server. Is there a way to do this without writing any code?

Quoted 9 lines
Quoted 4 lines

NOTE:
Currently the firewall is FreeBSD and we accomplish this rather easily using ipfw along with natd, but we want to move to linux for our firewall.

I think you can use tc action mirred to mirror the packets to a fake NIC device ifb, and use tc action nat to dnat the packets received from ifb.

Oh, iptables can also do it. Please see iptables target TEE and RAWNAT in xtables-addons. http://xtables-addons.sourceforge.net/

Signature · 2 lines
Regards,
Changli Gao([email protected])
#3 lore raw
Quoted 21 lines · Changli Gao
Quoted 19 lines · Changli Gao
Quoted 17 lines · Stephen Clark

Hello,

Problem:
I have a two monitoring servers behind a a linux firewall, one is primary and one is backup.
In the field we have units sending udp informational packet to the primary server. On the
linux firewall I would like to copy this packet and change the destination address of the copied
packet to point to the backup server. Is there a way to do this without writing any code?

NOTE:
Currently the firewall is FreeBSD and we accomplish this rather easily using ipfw along with natd, but we want to move to linux for our firewall.

Quoted 9 lines
Quoted 5 lines

I think you can use tc action mirred to mirror the packets to a fake NIC device ifb, and use tc action nat to dnat the packets received from ifb.

Oh, iptables can also do it. Please see iptables target TEE and RAWNAT in xtables-addons. http://xtables-addons.sourceforge.net/

Not to seem dumb - but I tried xtables TEE without any success. Could you provide a detailed example?

Thanks,
Steve

Signature · 5 lines
"They that give up essential liberty to obtain temporary safety,
deserve neither liberty nor safety."  (Ben Franklin)

"The course of history shows that as a government grows, liberty
decreases."  (Thomas Jefferson)
#4 lore raw
In reply to Changli Gao
Quoted 21 lines · Changli Gao
Quoted 19 lines · Changli Gao
Quoted 17 lines · Stephen Clark

Hello,

Problem:
I have a two monitoring servers behind a a linux firewall, one is primary and one is backup.
In the field we have units sending udp informational packet to the primary server. On the
linux firewall I would like to copy this packet and change the destination address of the copied
packet to point to the backup server. Is there a way to do this without writing any code?

NOTE:
Currently the firewall is FreeBSD and we accomplish this rather easily using ipfw along with natd, but we want to move to linux for our firewall.

Quoted 9 lines
Quoted 5 lines

I think you can use tc action mirred to mirror the packets to a fake NIC device ifb, and use tc action nat to dnat the packets received from ifb.

Oh, iptables can also do it. Please see iptables target TEE and RAWNAT in xtables-addons. http://xtables-addons.sourceforge.net/

In testing this it looks like, to me anyhow, that the cloned packet gets sent to the new gw with the original destination address, so now the destination address has to get fixed up on the gw, this seems pretty kludgy to me. Why can't the cloned packet simply have its destination address replaced with the new destination address? This seems to me like it would make a lot more sense, instead of having to make changes to the packet on two different systems.

Signature · 5 lines
"They that give up essential liberty to obtain temporary safety,
deserve neither liberty nor safety."  (Ben Franklin)

"The course of history shows that as a government grows, liberty
decreases."  (Thomas Jefferson)
#5 lore raw
Quoted 9 lines · Stephen Clark
Quoted 3 lines

Oh, iptables can also do it. Please see iptables target TEE and RAWNAT in xtables-addons. http://xtables-addons.sourceforge.net/

In testing this it looks like, to me anyhow, that the cloned packet gets sent to the new gw with the original destination address, so now the destination address has to get fixed up on the gw, this seems pretty kludgy to me. Why can't the cloned packet simply have its destination address replaced with the new destination address?

Because that would incur a loss of information (namely, the destination address).

Quoted 2 lines

This seems to me like it would make a lot more sense, instead of having to make changes to the packet on two different systems.

You can do the changes on a single machine if you want to.

#6 lore raw
Quoted 11 lines · Jan Engelhardt
Quoted 9 lines · Stephen Clark
Quoted 3 lines

Oh, iptables can also do it. Please see iptables target TEE and RAWNAT in xtables-addons. http://xtables-addons.sourceforge.net/

In testing this it looks like, to me anyhow, that the cloned packet gets sent to the new gw with the original destination address, so now the destination address has to get fixed up on the gw, this seems pretty kludgy to me. Why can't the cloned packet simply have its destination address replaced with the new destination address?

Quoted 10 lines

Because that would incur a loss of information (namely, the destination address).

Quoted 3 lines

This seems to me like it would make a lot more sense, instead of having to make changes to the packet on two different systems.

You can do the changes on a single machine if you want to.

I am not sure on how to go about doing that, looking at the code for TEE it looks like the cloned packet bypasses any of the remaining iptables chains. So where would I change the destination address? Also if I am mistaken and it does hit one of the remaining iptables chains how do I tell it is not the original but the cloned packet I want to change to the new destination address?

Anyway thanks for your response.

Signature · 5 lines
"They that give up essential liberty to obtain temporary safety,
deserve neither liberty nor safety."  (Ben Franklin)

"The course of history shows that as a government grows, liberty
decreases."  (Thomas Jefferson)
#7 lore raw
Quoted 4 lines · Stephen Clark

I am not sure on how to go about doing that, looking at the code for TEE it looks
like the cloned packet bypasses any of the remaining iptables chains.

It isn't true. The cloned packet only bypasses the iptables rule where it is generated.

Quoted 8 lines

So
where
would I change the destination address? Also if I am mistaken and it does hit
one of the remaining iptables chains how do I tell it is not the original but the
cloned packet I want to change to the new destination address?

I think you can use the RAWSNAT xtables-addon to change the destination address. Since the new skb is attached to untracked ct, you can use match conntrack --ctstate UNTRACKED to filter it out.

Signature · 2 lines
Regards,
Changli Gao([email protected])
#8 lore raw
Quoted 18 lines · Changli Gao
Quoted 4 lines · Stephen Clark

I am not sure on how to go about doing that, looking at the code for TEE it looks
like the cloned packet bypasses any of the remaining iptables chains.

It isn't true. The cloned packet only bypasses the iptables rule where it is generated.

Quoted 8 lines

So
where
would I change the destination address? Also if I am mistaken and it does hit
one of the remaining iptables chains how do I tell it is not the original but the
cloned packet I want to change to the new destination address?

Quoted 4 lines

I think you can use the RAWSNAT xtables-addon to change the destination address. Since the new skb is attached to untracked ct, you can use match conntrack --ctstate UNTRACKED to filter it out.

s/SNAT/DNAT/g .

Signature · 2 lines
Regards,
Changli Gao([email protected])
#9 lore raw
In reply to Changli Gao
Quoted 19 lines · Changli Gao
Quoted 4 lines · Stephen Clark

I am not sure on how to go about doing that, looking at the code for TEE it looks
like the cloned packet bypasses any of the remaining iptables chains.

It isn't true. The cloned packet only bypasses the iptables rule where it is generated.

Quoted 9 lines

So
where
would I change the destination address? Also if I am mistaken and it does hit
one of the remaining iptables chains how do I tell it is not the original but the
cloned packet I want to change to the new destination address?

Quoted 5 lines

I think you can use the RAWSNAT xtables-addon to change the destination address. Since the new skb is attached to untracked ct, you can use match conntrack --ctstate UNTRACKED to filter it out.

Hi Changli,

Thank you very much for the reply, But wouldn't it be RAWDNAT since I want to change the destination address?

Steve

Signature · 5 lines
"They that give up essential liberty to obtain temporary safety,
deserve neither liberty nor safety."  (Ben Franklin)

"The course of history shows that as a government grows, liberty
decreases."  (Thomas Jefferson)
#11 lore raw
In reply to Stephen Clark
Quoted 10 lines · Stephen Clark
Quoted 5 lines · Jan Engelhardt
Quoted 3 lines

This seems to me like it would make a lot more sense, instead of having to make changes to the packet on two different systems.

You can do the changes on a single machine if you want to.

I am not sure on how to go about doing that, looking at the code for TEE it looks like the cloned packet bypasses any of the remaining iptables chains. So where would I change the destination address?

Right. You need a kernel >= 2.6.35 (xt_TEE is included) for cloned packets to go through the tables again.

Quoted 3 lines

Also if I am mistaken and it does hit one of the remaining iptables chains how do I tell it is not the original but the cloned packet I want to change to the new destination address?

Good question. Given the possibilities I think an extra route towards the logging server that specifies a realm value, that is then matchable in -A OUTPUT -m realm, is in order.

#10 lore raw
In reply to Changli Gao
Quoted 8 lines · Changli Gao
Quoted 4 lines · Stephen Clark

I am not sure on how to go about doing that, looking at the code for TEE it looks
like the cloned packet bypasses any of the remaining iptables chains.

It isn't true. The cloned packet only bypasses the iptables rule where it is generated.

That isn't true either. The cloned packet starts its travel in OUTPUT, not where it left off.

Quoted 3 lines

I think you can use the RAWSNAT xtables-addon to change the destination address. Since the new skb is attached to untracked ct, you can use match conntrack --ctstate UNTRACKED to filter it out.

That may still give false positives if there is other NOTRACK traffic.

#12 lore raw
In reply to Jan Engelhardt
Quoted 19 lines · Jan Engelhardt
Quoted 6 lines · Stephen Clark
Quoted 4 lines · Jan Engelhardt
Quoted 4 lines

This seems to me like it would make a lot more sense, instead of having to make changes to the packet on two different systems.

Quoted 7 lines
Quoted 2 lines

You can do the changes on a single machine if you want to.

I am not sure on how to go about doing that, looking at the code for TEE it looks like the cloned packet bypasses any of the remaining iptables chains. So where would I change the destination address?

Right. You need a kernel>= 2.6.35 (xt_TEE is included) for cloned packets to go through the tables again.

Quoted 9 lines
Quoted 4 lines

Also if I am mistaken and it does hit one of the remaining iptables chains how do I tell it is not the original but the cloned packet I want to change to the new destination address?

Good question. Given the possibilities I think an extra route towards the logging server that specifies a realm value, that is then matchable in -A OUTPUT -m realm, is in order.

Hmm...,

Sounds like maybe an easier way to do this is to use libipq and the QUEUE target to select the packets of interest - then make a copy of the packet in userspace and use a raw socket to send the copy with the new destination address on its way.

Does this sound reasonable?

Signature · 5 lines
"They that give up essential liberty to obtain temporary safety,
deserve neither liberty nor safety."  (Ben Franklin)

"The course of history shows that as a government grows, liberty
decreases."  (Thomas Jefferson)
#13 lore raw
Quoted 9 lines · Stephen Clark
Quoted 9 lines
Quoted 5 lines

Also if I am mistaken and it does hit one of the remaining iptables chains how do I tell it is not the original but the cloned packet I want to change to the new destination address?

Good question. Given the possibilities I think an extra route towards the logging server that specifies a realm value, that is then matchable in -A OUTPUT -m realm, is in order.

Quoted 8 lines

Hmm...,

Sounds like maybe an easier way to do this is to use libipq and the QUEUE target to select the packets of interest - then make a copy of the packet in userspace and use a raw socket to send the copy with the new destination address on its way.

Does this sound reasonable?

The roundtrip over userspace sounds unnecessarily imperformant.

#14 lore raw
Quoted 16 lines · Jan Engelhardt
Quoted 14 lines · Stephen Clark
Quoted 12 lines
Quoted 7 lines

Also if I am mistaken and it does hit one of the remaining iptables chains how do I tell it is not the original but the cloned packet I want to change to the new destination address?

Good question. Given the possibilities I think an extra route towards the logging server that specifies a realm value, that is then matchable in -A OUTPUT -m realm, is in order.

Hmm...,

Quoted 10 lines
Quoted 7 lines

Sounds like maybe an easier way to do this is to use libipq and the QUEUE target to select the packets of interest - then make a copy of the packet in userspace and use a raw socket to send the copy with the new destination address on its way.

Does this sound reasonable?

The roundtrip over userspace sounds unnecessarily imperformant.

I would agree but it keeps me from being dependent on a particular kernel version and we are only concerned with less than 10 packets per second.

Signature · 5 lines
"They that give up essential liberty to obtain temporary safety,
deserve neither liberty nor safety."  (Ben Franklin)

"The course of history shows that as a government grows, liberty
decreases."  (Thomas Jefferson)
#15 lore raw
In reply to Stephen Clark
Quoted 11 lines · Stephen Clark

Hmm...,

Sounds like maybe an easier way to do this is to use libipq and the QUEUE target to
select the packets of interest - then make a copy of the packet in userspace and
use a raw socket to send the copy with the new destination address on its way.

Does this sound reasonable?

Oh, I think NFLOG will be better, or libpcap & libnet, if you want to implement this function in user space, because it doesn't delay the original packets as NFQUEUE does.

Signature · 2 lines
Regards,
Changli Gao([email protected])