Skip to contentSkip to conversation

Urgent question: changing src|dst IP w/ ipq fails

DISCUSSION Michael Gundlach 2 participants 3 messages Feb 18, 2003 netfilter

lore
Share & tools
lore
#0 lore raw

Hi all,

I had a neat idea a few days ago and am rushing under a deadline (tomorrow morning, Feb 19) to get it working. Any help would be greatly appreciated.

I have a machine A sending packets to machine C, and machine B is a linux bridge running ipq between them on the network. B is catching all packets between A and C, looking at them, and reinjecting them. This works just fine, and A and C can talk happily together without knowing that the bridge B is between them.

Now I wish to modify the source or destination addresses of these packets before reinjecting them. Modifying the source or destination *port* and reinjecting the packet works fine - the destination computer (running tcpdump) sees a packet from the source, using the new source or destination port that ipq put in.

However, modifying the source or destination *IP* does not work. When IPQ changes a A->D packet to be A->C, C never gets the packet. When IPQ changes a A->C packet to be D->C, C will *eventually* (after 20+ seconds) get a packet claiming to come from D. Running tcpdump on the bridge B, I see a TCP SYN packet come in from A->C, and 20 seconds later or so a TCP SYN packet D->C (the reinjected packet); but only, say, 2 out of 3 of the A->C packets get successfully retransmitted as D->C.

Any idea what I am doing wrong? I am recalculating IP and TCP checksums OK, I know that. A colleague thinks perhaps I have to set up a new route in the kernel-level code when I modify the destination IP, but I don't think so - since ipq is a user-level interface. Also, that wouldn't solve the source-IP-modification problem.

I am using a version of netfilter 1.6a that is patched to work with a bridging kernel.

Thanks in advance - and *please* post back soon :) Even if it's past the morning of Feb 19th, I still need to figure this out.
Michael Gundlach

#1 lore raw

Hi again everyone,

After mailing the list I found something on the netfilter archives saying that the FORWARD chain is traversed after kernel routing decisions have been made. Is this the (unfortunate) answer I was looking for - that if I get a packet on the FORWARD chain I can't change its destination, or routing fails and the packet is dropped?

Thanks
Michael

Quoted 33 lines · Michael Gundlach

I have a machine A sending packets to machine C, and machine B is a linux bridge running ipq between them on the network. B is catching all packets between A and C, looking at them, and reinjecting them. This works just fine, and A and C can talk happily together without knowing that the bridge B is between them.

Now I wish to modify the source or destination addresses of these packets before reinjecting them. Modifying the source or destination *port* and reinjecting the packet works fine - the destination computer (running tcpdump) sees a packet from the source, using the new source or destination port that ipq put in.

However, modifying the source or destination *IP* does not work. When IPQ changes a A->D packet to be A->C, C never gets the packet. When IPQ changes a A->C packet to be D->C, C will *eventually* (after 20+ seconds) get a packet claiming to come from D. Running tcpdump on the bridge B, I see a TCP SYN packet come in from A->C, and 20 seconds later or so a TCP SYN packet D->C (the reinjected packet); but only, say, 2 out of 3 of the A->C packets get successfully retransmitted as D->C.

Any idea what I am doing wrong? I am recalculating IP and TCP checksums OK, I know that. A colleague thinks perhaps I have to set up a new route in the kernel-level code when I modify the destination IP, but I don't think so - since ipq is a user-level interface. Also, that wouldn't solve the source-IP-modification problem.

I am using a version of netfilter 1.6a that is patched to work with a bridging kernel.

Thanks in advance - and *please* post back soon :) Even if it's past the morning of Feb 19th, I still need to figure this out.
Michael Gundlach

#2 lore raw

This is correct. Once the packet hits the mangle table on the forward hook it's already been routed and so you can no longer change the destination. Routing takes place straight after PREROUTE.

----- Original Message -----
From: "Michael Gundlach" <[email protected]>
To: <[email protected]>
Sent: Wednesday, February 19, 2003 9:53 AM
Subject: Re: Urgent question: changing src|dst IP w/ ipq fails

Quoted 8 lines

Hi again everyone,

After mailing the list I found something on the netfilter archives saying that the FORWARD chain is traversed after kernel routing decisions have been made. Is this the (unfortunate) answer I was looking for - that if I get a packet on the FORWARD chain I can't change its destination, or routing fails and the packet is dropped?

Quoted 6 lines

Thanks
Michael

Quoted 1 line · Michael Gundlach

I have a machine A sending packets to machine C, and machine B is a

linux

Quoted 1 line
Quoted 1 line

bridge running ipq between them on the network. B is catching all

packets

Quoted 2 lines
Quoted 2 lines

between A and C, looking at them, and reinjecting them. This works just fine, and A and C can talk happily together without knowing that the

bridge

Quoted 9 lines
Quoted 9 lines

B is between them.

Now I wish to modify the source or destination addresses of these packets before reinjecting them. Modifying the source or destination *port* and reinjecting the packet works fine - the destination computer (running tcpdump) sees a packet from the source, using the new source or destination port that ipq put in.

However, modifying the source or destination *IP* does not work. When

IPQ

Quoted 1 line
Quoted 1 line

changes a A->D packet to be A->C, C never gets the packet. When IPQ

changes

Quoted 2 lines
Quoted 2 lines

a A->C packet to be D->C, C will *eventually* (after 20+ seconds) get a packet claiming to come from D. Running tcpdump on the bridge B, I see

a

Quoted 2 lines
Quoted 2 lines

TCP SYN packet come in from A->C, and 20 seconds later or so a TCP SYN packet D->C (the reinjected packet); but only, say, 2 out of 3 of the

A->C

Quoted 3 lines
Quoted 3 lines

packets get successfully retransmitted as D->C.

Any idea what I am doing wrong? I am recalculating IP and TCP checksums

OK,

Quoted 2 lines
Quoted 2 lines

I know that. A colleague thinks perhaps I have to set up a new route in the kernel-level code when I modify the destination IP, but I don't

think

Quoted 7 lines
Quoted 7 lines

so - since ipq is a user-level interface. Also, that wouldn't solve the source-IP-modification problem.

I am using a version of netfilter 1.6a that is patched to work with a bridging kernel.

Thanks in advance - and *please* post back soon :) Even if it's past

the

Quoted 5 lines
Quoted 3 lines

morning of Feb 19th, I still need to figure this out. Michael Gundlach