Openvpn disconnection and Its Solution-confirm

Source: Internet
Author: User
This article is very short, with the aim of confirm the messy "openvpn uncertain disconnection Problem and Its Solution". If you think I am a little embarrassed, you must take a look at the last section. Fortunately, csdn is for every article. Article The directory is automatically added. You can directly jump to the last section.
1. Control CHannel

The control channel controls the SSL handshake, key negotiation, and re-negotiation of openvpn. Therefore, its robustness directly affects whether the tunnel can be established successfully. Therefore, the optimized burst retransmit directly affects the establishment of tunnels in harsh network environments, making it easier to establish tunnels. Once the window is full due to ack disorder/loss, re-upload the packet with the smallest Id immediately and expect to receive the ACK extension window!
Principles:If your packet loss occurs, I resend the packet loss rate multiple times. Although this method is selfish, it is selfish to survive in harsh environments.
Effect:Because the data volume of the control channel is limited, it is effective to display the modification in extreme ways, that is, to set the following parameters:
Ping: Set to 5 seconds, as short as possible, but not too short
Ping-restart: Set to 120 seconds, and try to open the distance from Ping. The two parameters will not be disconnected due to ping-Restart. In this way, all the problems will be concentrated on the control channel.
Reneg-sec: Set it to 2, that is, two seconds for key re-negotiation
Hand-window: Set it to 15, that is, if the handshake on the SSL channel fails, the key re-negotiation is closed within 15 seconds.
Tran-window: Set it to 5, that is, if the tunnel fails in the hand-window, the tunnel is disconnected for 5 seconds. This parameter is optional.

The retry version and standard version test show that in extreme cases, the standard version almost fails instantly, but the retry version is much better.
2. Data Tunnel

When data passes through the tunnel, Timer always resets. When there is no data, timer resets the peer end by sending ping through the data channel. If no reset is available for the timer whose Ping-Restart expires, the tunnel is disconnected. Therefore, it is easier to disconnect without tunnel data! Note: As long as the tunnel is established and the key negotiation is good, the control channel is basically idle except for re-negotiation or push. Therefore, the factors that affect the disconnection after the tunnel is connected are ping and Ping-restart.
3. Relationship between environments with high Packet Loss Rate

Once the packet loss rate is high and tunnel data does not pass through, the data channel will rely entirely on Ping. If Ping-Restart is too short and Ping packet loss occurs in harsh environments, the tunnel will be disconnected, at this time, a new tunnel will be created, because it is already in a bad environment, and the packet loss rate is very high. Ack is easy to be out of order/lost, And openvpn will not be re-transmitted immediately when the window is full, therefore, tunnels cannot be established for a long time. Therefore, the disconnection of the data channel reflects the deterioration of the network environment, which affects the handshake and negotiation of the next control channel. Therefore, the openvpn disconnection issue should be addressed in a two-pronged manner, the first step is to lengthen the distance between Ping and Ping-Restart (but not pan ping), and the second step is to modify the re-transmission scheduling logic of openvpn like the problem of inexplicable disconnection of openvpn and its solution.
4.ProgramLimit

Programmers often want to solve the problem with wishful thinking! The extreme situation is that TCP ensures transmission, so even if the network cable is cut off, the programmer still hopes (and only hopes) to write something mysterious.CodeTo connect to the network, you still want to find that packet loss or disconnection occurs because your code is not well written. But for the network engineer, it is the opposite. No matter what the application is, it is show, check the network cable... sometimes it is actually socket blocking. In fact, there is also a limit to the openvpn disconnection problem, that is, the network is really disconnected, and the packet loss rate is really too large. What should we do? We can only break the line. This cannot be solved. What we can do is to minimize the loss and tell the user what happened and let the user know, although the network is disconnected, openvpn is still working hard.
5. Do not modify the openvpn disconnection prevention Solution

In any case, openvpn is also a mature code that has passed many tests. Although its retransmission scheduling is not timely, it will be re-transmitted after all! If there is a major problemCommunityModified. In addition, it should be noted that, in most cases, the data packets and ack of the control channel are not lost, but delayed arrival. In this way, it can be solved simply by extending the timeout time. Fortunately, openvpn provides many timeout settings:
A. Increase the Ping and Ping-Restart differences to ensure that ping is not easily disconnected because Ping is not received;
B. extend hand-window to reserve enough time for key negotiation of the control channel;
C. Extend the tran-window parameter so that you can try reneg at the end of the process when you find that you want to disconnect the tunnel. This parameter must be greater than reneg-sec!
...

6. Everything I do is superfluous,...

In fact, when I look back at the code, I find that the changes I made to openvpn have already been implemented, but I have studied the parameter configuration of openvpn to a certain extent, so I made changes on my own. For me, I can find the idea and design a schedule interface:

 
Voidreliable_schedule_id (struct reliable * Rel, time_t timeout, packet_id_type ID );

I am very pleased, but I have re-implemented what has already been implemented and rebuilt the wheel! This is a typical behavior of most junior and intermediate programmers!
Let's take a look at the following configuration parameters:
-- TLS-Timeout n
Packet retransmit timeout on TLS control channel if no acknowledgment from remote within n seconds (default = 2 ).
When openvpn sends a control packet to its peer, it will receive CT to receive an acknowledgement within n seconds or
It will retransmit the packet, subject to a TCP-like Exponential Backoff Algorithm. This parameter only applies
To control channel packets. Data Channel packets (which carry encrypted tunnel data) are never acknowledged,
Sequenced, or retransmitted by openvpn because the higher level network protocols running on top of the tunnel
Such as TCP expect CT this role to be left to them.

The default value is 2 seconds. If you want to enable dense retransmission, set it to 1. Although this parameter brings about a global Retransmission timeout configuration, I believe the network will solve the congestion problem. By comparison, my modifications only target the packet with the smallest ID, that is, the packet that only retransmits the packets that impede window pushing, which may be more reasonable, however, the TLS-Timeout provided by openvpn is enough to solve the problem of unordered loss of existing ack. To reject perfection and tolerate imperfection, this is the key to success! To be perfect, the code will be filled with a lot of so-called tips.
It took a lot of time to think about how to modify the openvpn code, but it turned out to be code rollback!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.