Skip to contentSkip to conversation

Information missing in new thread after REDIRECT of iptables

DISCUSSION Grace Li 1 participant 1 message Apr 16, 2004 netfilter

lore
Share & tools
lore

Grace Li

author
#0 lore raw

Hi,

Thanks for the hint on establishing multiple connections. Now I am able to handle packets targeted for different ports when they all directed to the same local port. A new problem occurs when I pass the file descriptor (fd=accept(server_socket, (struct sockaddr *)&server_ssin, &len)) got from the socket connect function to a new thread, and when I try to read the destination addr and port from this descriptor (getsockopt (fd, SOL_IP, SO_ORIGINAL_DST, (struct sockaddr*)&addr, &len_t );) . The result I got is:
Original Destination IP is 0.0.0.0
Destination Port is 0

Any idea? I am still able to read correct data from this file descriptor, just getsockopt does not work, the error returned was "Invalid argument".

Thanks,

Grace

Quoted 32 lines

From: Balazs Scheidler <[email protected]>
To: Grace Li <[email protected]>
Subject: Re: How to get original destination port after REDIRECT ofiptables?
Date: Thu, 15 Apr 2004 09:51:23 +0200

2004-04-14, sze keltez�ssel 23:17-kor Grace Li ezt �rta:

Quoted 3 lines

Hi folks,

I have know that using REDIRECT option of iptables could redirect

traffic to

Quoted 1 line

a specified remote port to another local port, for example iptables -t

nat

Quoted 1 line

-A PREROUTING -i eth0 -p tcp --dport 1888 -j REDIRECT --to-port 2000 .

The

Quoted 1 line

original destination IP address is not changed, and could be obtained

from

Quoted 1 line

getsockopt call with specifiying SO_ORIGINAL_DST ( e.g. getsockopt

(client,

Quoted 3 lines

SOL_IP, SO_ORIGINAL_DST, (struct sockaddr*)&addr, &len_t );) .

What I want to do is that for every incoming packets to ether net

interface,

Quoted 1 line

I want to direct to one spcific port, instead of dedirecting traffic

from

Quoted 1 line

one port to another port. In another words, I want to do multi-port

match

Quoted 1 line

one port instead of one to one port match. Could anybody suggest if it

is

Quoted 1 line

doable? If yes, how could the application that listens to the

re-directed

Quoted 1 line

port knows the original destination port?

Quoted 10 lines

Conntrack differentiates between multiple connections based on the peer address/port. As this needs to be specified to the SO_ORIGINAL_DST lookup there's no problem in finding out both the original address and port.

--
Bazsi
PGP info: KeyID 9AF8D0A9 Fingerprint CD27 CFB0 802C 0944 9CFD 804E C82C 8EB1

_________________________________________________________________
MSN Premium with Virus Guard and Firewall* from McAfee� Security : 2 months FREE* http://join.msn.com/?pgmarket=en-ca&page=byoa/prem&xAPID=1994&DI=1034&SU=http://hotmail.com/enca&HL=Market_MSNIS_Taglines