Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 7 Jan 1999 07:50:20 +0100 (MET)
From:      Milan Kopacka <mkop5230@ss1000.ms.mff.cuni.cz>
To:        freebsd-hackers@FreeBSD.ORG
Cc:        Konference o transparentni proxy <tpc-l@freebsd.cz>
Subject:   Specifying local IP in connect()
Message-ID:  <Pine.SGI.3.96.990106230659.10874B-100000@beta.ms.mff.cuni.cz>
In-Reply-To: <199901062115.OAA27539@usr08.primenet.com>

next in thread | previous in thread | raw e-mail | index | archive | help

Hi,

for our school project I need to design and implement TCP/IP's connect()
extension, which allows me to specify the local IP adress of TCP
connection. 

The connect() call takes as an argument pointer to struct sockaddr_in ,
which is defined as follows: 

struct sockaddr_in {
        u_char  sin_len;
        u_char  sin_family;
        u_short sin_port;
        struct  in_addr sin_addr;
        char    sin_zero[8];
};

Here are 8 unused bytes, which can be easily used to extend connect() 
capabilites to specify both remote and local IP adresses. 

Such as: (the names are just for example, the idea is important here)

struct sockaddr_in_connect_ext {
        u_char  sin_len;
        u_char  sin_family;
        u_short sin_port;
        struct  in_addr sin_addr;
        struct  in_addr local_addr; /* local IP */
        char sin_pad[4];            /* 4 bytes left */
};

The memory holding former sin_zero field remains there deep enough, so I
can in tcp_connect() kernel routine easily use specified local IP to be
assigned to connection. 

The second thing I need to do is to allow incoming packets for these
connections to be received and add some "goto ours"  to ip_input() kernel
routine. "Local" IP's which have not yet anything to do with our machine
must not be forgotten. :) 

So the application has now a way to act like IP a.b.c.d while still
being able to communicate with machine a.b.c.d. 

Now I see I have to explain our project goal. The project consists of
implementing a fully transparent www proxy cache. Such a thing needs to
catch connections going to www servers like proxy server. It also needs
to initiate connections to www servers under the client IP adress.
This can't be done without help of a router. 

Think about a situation like that.

   (client machines)
      |
      |
   ( router)----(transparent proxy)
      |
      |
   (WWW servers)
                               
Situation: client initiates the connection, router redirects it to proxy,
proxy (acting like client) opens connection to WWW server and makes the
rest of caching work. Proxy needs to communicate with both the servers
under client's IP and with client under server's IP.

However, this is impossible without the change (or improvement :) of
TCP/IP on proxy machine, like that above.

Please tell me

* about the chance of thing like this to get into FreeBSD kernel
* if somebody ever uses sin_zero to do some other work
* any other ideas

Thanks,

  Milan Kopacka

--
<Milan.Kopacka@st.mff.cuni.cz>




To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-hackers" in the body of the message



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?Pine.SGI.3.96.990106230659.10874B-100000>