What is the difference between tcp/tcp-server/tcp-client?

This forum is for admins who are looking to build or expand their OpenVPN setup.

Moderators: TinCanTech, TinCanTech, TinCanTech, TinCanTech, TinCanTech, TinCanTech

Forum rules
Please use the [oconf] BB tag for openvpn Configurations. See viewtopic.php?f=30&t=21589 for an example.
Post Reply
zespri
OpenVpn Newbie
Posts: 5
Joined: Fri Oct 08, 2010 6:30 pm

What is the difference between tcp/tcp-server/tcp-client?

Post by zespri » Fri Oct 08, 2010 6:33 pm

Hello all,

What is the difference between proto tcp/tcp-server/tcp-client?

Cheers,
Andrew

User avatar
krzee
Forum Team
Posts: 728
Joined: Fri Aug 29, 2008 5:42 pm

Re: What is the difference between tcp/tcp-server/tcp-client

Post by krzee » Fri Oct 08, 2010 7:44 pm

im surprised to find this is not really covered in the manual...
my understanding of it is that tcp-server/tcp-client are for ptp operation (in openvpn 1 ptp was the only mode available)
of course they can be used still in client/server mode, but also proto tcp can be used there, because each side already knows who should act as the server/client for the tcp session.

from the manual:
For TCP operation, one peer must use --proto tcp-server and the other must use --proto tcp-client. A peer started with tcp-server will wait indefinitely for an incoming connection.

notice it says peer... as in ptp mode there is no server or client, only peers.

looks like you found something that should be explained better in the manual, I will show this thread to those with permissions to update the manual :)

zespri
OpenVpn Newbie
Posts: 5
Joined: Fri Oct 08, 2010 6:30 pm

Re: What is the difference between tcp/tcp-server/tcp-client

Post by zespri » Sun Oct 10, 2010 8:53 pm

Thank you for your reply. It seems that the reason why manual is silent about the "tcp" option is because it's not really an option. If you try and use it you'll get a error that you should specify tcp-client or tcp-server instead.

User avatar
dazo
OpenVPN Inc.
Posts: 155
Joined: Mon Jan 11, 2010 10:14 am
Location: dazo :: #openvpn-devel @ libera.chat

Re: What is the difference between tcp/tcp-server/tcp-client

Post by dazo » Mon Oct 11, 2010 11:23 pm

I've checked the code path for the sanity check of --proto {tcp,tcp-server,tcp-client}. It is correct that normally --proto tcp will not be accepted at all. Even the source code is a bit vauge on what it expects or should allow. It looks like OpenVPN once allowed --proto tcp to be used in conjunction with --inetd. However, there's now a pretty explicit check before the more forgiving code which now will block this. So with --inetd you now must use --proto tcp-server. And in all other scenarios you need to use either --proto tcp-server or --proto tcp-client.

To briefly explain the reason why a --proto tcp implementation won't work while --proto udp does, is related to how TCP and UDP connections are established. TCP connections requires listen() to be called on the server side, while UDP connections do not need that at all. On the client side, TCP clients need to use connect() while UDP does not. This makes it necessarily to distinguish between TCP client and server - to know how to establish the network socket. While the UDP client/server on the other hand are much more similar when creating the network socket.

Having that said, it should theoretically be possible to distinguish the server/client mode based on other options used in conjunction with a --proto tcp option. But to make that logic work out will require some effort.

An update: I forgot to mention that while I've done this code review based on traditional client/server with multiple clients to one server ... there are other code paths related to --mode p2p, which changes some of the code path. So that might give quite a different challenge to automatic client/server detection for a TCP mode.

zespri
OpenVpn Newbie
Posts: 5
Joined: Fri Oct 08, 2010 6:30 pm

Re: What is the difference between tcp/tcp-server/tcp-client

Post by zespri » Wed Oct 13, 2010 8:48 am

Thank you for your research, this is most useful information.

Andrew.

Post Reply