Effective way of putting 2 tcp-connections together

Effective way of putting 2 tcp-connections together

Post by Marek Zawadzk » Sat, 03 Nov 2001 08:06:50



Hello,

This is actually a programming problem, but comp.os.linux.networking is
always so helpful...

I have a pair of tcp-connections (sockets s1/s2):

[A] <==> ---tcp_s1-- [ HOST ] --tcp_s2---  <==> [B]

So I am managing 2 connections to allow communication between A and B.
They must be able to read/write to each other at the same time.

How should I arrange my read/write loop at [HOST] to forward data back and
forth efficiently? Also, in the future [HOST] may be doing this between
multiple host (so it'll be a center "hub", take this under consideration
when presenting some thoughts (pseudo code'd be appreciated).

Thanks very much!

-marek

 
 
 

Effective way of putting 2 tcp-connections together

Post by Chris Friese » Sat, 03 Nov 2001 10:10:58



> Hello,

> This is actually a programming problem, but comp.os.linux.networking is
> always so helpful...

> I have a pair of tcp-connections (sockets s1/s2):

> [A] <==> ---tcp_s1-- [ HOST ] --tcp_s2---  <==> [B]

> So I am managing 2 connections to allow communication between A and B.
> They must be able to read/write to each other at the same time.

> How should I arrange my read/write loop at [HOST] to forward data back and
> forth efficiently? Also, in the future [HOST] may be doing this between
> multiple host (so it'll be a center "hub", take this under consideration
> when presenting some thoughts (pseudo code'd be appreciated).

Use select().

The program would be something like:

add registration socket to readable set
while 1
   copy readable set to working set
   select on working set
   if select returns -1 then print error message and continue
   if select returns 0 then continue

   if registration socket is member of working set
       handle registration of new client (including adding it to readable set)
   loop through data sockets
       if socket is member of working set
          send packet out to all other sockets
   continue

This allows you to have a single loop in your program and handle dynamic
registration without having to go multithreaded.

Chris

 
 
 

1. Trying to put together full-featured net stuff.

I'm trying to put together my machine with full featured net stuff, by
which I mean:

 * Shadow password support in ftpd/rlogind/rexecd
 * ~root/.rhosts honoured (yes I know it can be a security hole but it
   should be _my_ decision. Maybe a switch in inetd.conf?).
 * TCP wrappers
 * BOOTP client and server
 * tftpd with a default directory other than /
 * DES encryped {telnet,rlogin,rsh}{,d}
 * Full KerberosIV
 * rexec command

I think I've got most of the way - it's a lot of effort and perhaps
something that should not be repeated. Of course such a package could
not be put on a US ftp site but perhaps we should have it in the UK.

My real reason for posting: Am I re-inventing the wheel? Is there
anything I've missed?

BTW My reason for this is to allow me to:

* Take a Linux notebook to a remote point on capus plug it in to any
socket (with prior agreement of the net admins) and to have it come up
with the correct IP address for the subnet on which it finds itself.

* Get a secure terminal session back to a Linux box on my subnet.

* Connect to other machines (of a sensative nature) on my subnet
  without worrying about people snooping.

While I'm at it I would also like:
 * No -D security hole in smail
 * No -f security hole in login
--

 .  _\\__[oo       from       | Phones: +44 121 471 3789 (home)

.  l___\\    /~~) /~~[  /   [ | PGP-fp: D7 03 2A 4B D8 3A 05 37
 # ll  l\\  ~~~~ ~   ~ ~    ~ |         A1 93 FE EA BE E3 2A 91

2. a problem about fork

3. anyone put together a VPN for linux?

4. ftp and telnet access: RH7.1

5. Anybody put together anything to handle nat'l security logging?

6. SUN hanging

7. input needed on putting together a new system

8. Xconfig problems with ATI Ultra+

9. Anyone want to review an Apache module I put together?

10. Putting together a linux box

11. putting things together

12. Will MS ever put together a real OS

13. put broken wmtp's together ?