リバースプロキシ環境下での利用について

SoftEther VPN に関するご質問はこのフォーラムにお気軽にご投稿ください。
Post Reply
crow31415
Posts: 3
Joined: Sat Mar 06, 2021 8:22 pm

リバースプロキシ環境下での利用について

Post by crow31415 » Sat Mar 06, 2021 9:47 pm

単一のサーバーマシン(VPS)上の443番ポートにて、Webサーバー(nginx)とSoftEther Serverを共存させたいと考えています。
この実現方法として、eth0の443番ポートをリバースプロキシに割り当て、SNIによりホスト名に基づいてWebサーバーやSoftEther Serverに転送するという方式を考えています。

流れとしては以下のようになります。
なお、SoftEther Serverには5555番ポートを割り当てています。

リバースプロキシ不使用
(SoftEther Client) --[internet]-- eth0:5555(SoftEther Server)

リバースプロキシ使用
(SoftEther Client) --[internet]-- eth0:443(Reverse Proxy) --[localhost]-- lo:5555(SoftEther Server)


さて、この際、リバースプロキシを使用しない場合であれば接続に成功するのですが、リバースプロキシを介した接続の場合、一旦接続には成功するものの、DHCP割り当ての前にエラーが発生し、切断されてしまいます。


動作環境は以下のとおりです。

クライアント
  • SoftEther VPN4.0 (Ver 4.34, Build 9745)
  • Windows 10 Pro
サーバー
  • SoftEther VPN Server (64 bit) Version 4.34 Build 9745
  • CentOS7
  • sslh (リバースプロキシ / nginxのTCPプロキシでも同様の症状が発生)


出力されるエラー内容として、クライアント側では、エラー13

Code: Select all

エラー13: VPN セッションの通信がタイムアウトしました。クライアントから VPN Server への接続が切断された可能性があります。
が表示されますが、サーバー側のログを確認したところ、Code11

Code: Select all

terminated by the cause "The VPN session has been deleted. It is possible that either the administrator disconnected the session or the connection from the client to the VPN Server has been disconnected." (code 11).
により切断された後に再度接続を試行し、そちらではCode13

Code: Select all

terminated by the cause "Time-out occurred during VPN session communication. It is possible the connection from the client to the VPN Server has been disconnected." (code 13).
で切断されている模様です。


サーバーにてtcpdumpを実行し、パケットを調査したところ、SoftEther Serverからリバースプロキシに向けて[FIN, ACK]のTCPパケットが送信されているとことが確認できました。
[FIN, ACK]のTCPパケットは、リバースプロキシを介さずに接続した場合には発生しませんでした。


次のような対策も行いましたが、状況に変化はありませんでした。
  • サーバー: firewalldの無効化
  • サーバー: SELinuxの無効化
  • SoftEther Client: SSL暗号化の無効化
  • SoftEther Server: SecureNATの無効化
  • SoftEther Server: 仮想DHCPサーバーの無効化
  • リバースプロキシ: SNIによるホスト名判定をせず、全てのパケットをSoftEther Serverに転送

サーバーログは次のとおりです。
なお、ホスト名やIPアドレスなどは一部加工しております。

リバースプロキシ使用

Code: Select all

2021-03-07 05:11:34.118 On the TCP Listener (Port 5555), a Client (IP address 127.0.0.1, Host name "localhost", Port number 58788) has connected.
2021-03-07 05:11:34.118 For the client (IP address: 127.0.0.1, host name: "localhost", port number: 58788), connection "CID-2262" has been created.
2021-03-07 05:11:34.210 SSL communication for connection "CID-2262" has been started. The encryption algorithm name is "TLS_AES_256_GCM_SHA384".
2021-03-07 05:11:34.311 [HUB "VPN"] The connection "CID-2262" (IP address: 127.0.0.1, Host name: localhost, Port number: 58788, Client name: "SoftEther VPN Client", Version: 4.34, Build: 9745) is attempting to connect to the Virtual Hub. The auth type provided is "Password authentication" and the user name is "hoge".
2021-03-07 05:11:34.311 [HUB "VPN"] Connection "CID-2262": Successfully authenticated as user "hoge".
2021-03-07 05:11:34.311 [HUB "VPN"] Connection "CID-2262": The new session "SID-HOGE-73" has been created. (IP address: 127.0.0.1, Port number: 58788, Physical underlying protocol: "Standard TCP/IP (IPv4)")
2021-03-07 05:11:34.311 [HUB "VPN"] Session "SID-HOGE-73": The parameter has been set. Max number of TCP connections: 2, Use of encryption: Yes, Use of compression: No, Use of Half duplex communication: No, Timeout: 20 seconds.
2021-03-07 05:11:34.311 [HUB "VPN"] Session "SID-HOGE-73": VPN Client details: (Client product name: "SoftEther VPN Client", Client version: 434, Client build number: 9745, Server product name: "SoftEther VPN Server (64 bit)", Server version: 434, Server build number: 9745, Client OS name: "Windows 10", Client OS version: "Build 19042, Multiprocessor Free (19041.vb_release.191206-1406)", Client product ID: "--", Client host name: "fuga", Client IP address: "192.168.0.1", Client port number: 57485, Server host name: "server.example.com", Server IP address: "200.0.0.1", Server port number: 443, Proxy host name: "", Proxy IP address: "0.0.0.0", Proxy port number: 0, Virtual Hub name: "VPN", Client unique ID: "CCA8662036FAEA684BA8E93D408684C8")
2021-03-07 05:11:34.563 [HUB "VPN"] Session "SID-HOGE-73": The session has been terminated. The statistical information is as follows: Total outgoing data size: 149 bytes, Total incoming data size: 1774 bytes.
2021-03-07 05:11:34.593 Connection "CID-2262" terminated by the cause "The VPN session has been deleted. It is possible that either the administrator disconnected the session or the connection from the client to the VPN Server has been disconnected." (code 11).
2021-03-07 05:11:34.593 Connection "CID-2262" has been terminated.
2021-03-07 05:11:34.593 The connection with the client (IP address 127.0.0.1, Port number 58788) has been disconnected.
2021-03-07 05:11:35.773 On the TCP Listener (Port 5555), a Client (IP address 127.0.0.1, Host name "localhost", Port number 58790) has connected.
2021-03-07 05:11:35.773 For the client (IP address: 127.0.0.1, host name: "localhost", port number: 58790), connection "CID-2263" has been created.
2021-03-07 05:11:35.853 SSL communication for connection "CID-2263" has been started. The encryption algorithm name is "TLS_AES_256_GCM_SHA384".
2021-03-07 05:11:36.004 Connection "CID-2263" terminated by the cause "Time-out occurred during VPN session communication. It is possible the connection from the client to the VPN Server has been disconnected." (code 13).
2021-03-07 05:11:36.004 Connection "CID-2263" has been terminated.
2021-03-07 05:11:36.004 The connection with the client (IP address 127.0.0.1, Port number 58790) has been disconnected.
リバースプロキシ不使用時(手動で切断)

Code: Select all

2021-03-07 05:15:34.122 On the TCP Listener (Port 5555), a Client (IP address 100.0.0.1, Host name "client.example.com", Port number 25143) has connected.
2021-03-07 05:15:34.122 For the client (IP address: 100.0.0.1, host name: "client.example.com", port number: 25143), connection "CID-2264" has been created.
2021-03-07 05:15:34.172 SSL communication for connection "CID-2264" has been started. The encryption algorithm name is "TLS_AES_256_GCM_SHA384".
2021-03-07 05:15:34.253 [HUB "VPN"] The connection "CID-2264" (IP address: 100.0.0.1, Host name: client.example.com, Port number: 25143, Client name: "SoftEther VPN Client", Version: 4.34, Build: 9745) is attempting to connect to the Virtual Hub. The auth type provided is "Password authentication" and the user name is "hoge".
2021-03-07 05:15:34.253 [HUB "VPN"] Connection "CID-2264": Successfully authenticated as user "hoge".
2021-03-07 05:15:34.253 [HUB "VPN"] Connection "CID-2264": The new session "SID-HOGE-74" has been created. (IP address: 100.0.0.1, Port number: 25143, Physical underlying protocol: "Standard TCP/IP (IPv4)")
2021-03-07 05:15:34.253 [HUB "VPN"] Session "SID-HOGE-74": The parameter has been set. Max number of TCP connections: 2, Use of encryption: Yes, Use of compression: No, Use of Half duplex communication: No, Timeout: 20 seconds.
2021-03-07 05:15:34.253 [HUB "VPN"] Session "SID-HOGE-74": VPN Client details: (Client product name: "SoftEther VPN Client", Client version: 434, Client build number: 9745, Server product name: "SoftEther VPN Server (64 bit)", Server version: 434, Server build number: 9745, Client OS name: "Windows 10", Client OS version: "Build 19042, Multiprocessor Free (19041.vb_release.191206-1406)", Client product ID: "--", Client host name: "fuga", Client IP address: "192.168.0.1", Client port number: 58971, Server host name: "server.example.com", Server IP address: "200.0.0.1", Server port number: 5555, Proxy host name: "", Proxy IP address: "0.0.0.0", Proxy port number: 0, Virtual Hub name: "VPN", Client unique ID: "CCA8662036FAEA684BA8E93D408684C8")
2021-03-07 05:15:34.515 [HUB "VPN"] SecureNAT: The DHCP entry 11 has been created. MAC address: 5E-48-67-62-84-48, IP address: 172.20.1.1, host name: fuga, expiration span: 7200 seconds
2021-03-07 05:15:34.515 [HUB "VPN"] Session "SID-SECURENAT-33": The DHCP server of host "5E-AC-7F-23-9F-89" (172.20.0.1) on this session allocated, for host "SID-HOGE-74" on another session "5E-48-67-62-84-48", the new IP address 172.20.1.1.
2021-03-07 05:15:34.636 [HUB "VPN"] SecureNAT: The UDP session 697 has been created. Connection source 172.20.1.1:58419, Connection destination 172.20.0.1:53
2021-03-07 05:15:35.513 On the TCP Listener (Port 5555), a Client (IP address 100.0.0.1, Host name "client.example.com", Port number 24886) has connected.
2021-03-07 05:15:35.513 For the client (IP address: 100.0.0.1, host name: "client.example.com", port number: 24886), connection "CID-2265" has been created.
2021-03-07 05:15:35.554 SSL communication for connection "CID-2265" has been started. The encryption algorithm name is "TLS_AES_256_GCM_SHA384".
2021-03-07 05:15:35.584 Connection "CID-2265" has been terminated.
2021-03-07 05:16:04.520 [HUB "VPN"] Session "SID-HOGE-74": The session has been terminated. The statistical information is as follows: Total outgoing data size: 67399 bytes, Total incoming data size: 103401 bytes.
2021-03-07 05:16:04.550 Connection "CID-2264" terminated by the cause "The VPN session has been deleted. It is possible that either the administrator disconnected the session or the connection from the client to the VPN Server has been disconnected." (code 11).
2021-03-07 05:16:04.550 Connection "CID-2264" has been terminated.
2021-03-07 05:16:04.550 The connection with the client (IP address 100.0.0.1, Port number 25143) has been disconnected.

不足している情報などがあればお申し付けください。

ご助力のほど、何卒宜しくお願い致します。

crow31415
Posts: 3
Joined: Sat Mar 06, 2021 8:22 pm

Re: リバースプロキシ環境下での利用について

Post by crow31415 » Tue Mar 09, 2021 8:30 pm

テンプレートの記載を失念しておりました。

遅ればせながら、以下に記載させていただきます。



1. オペレーティングシステムの名前および CPU ビット

Code: Select all

CentOS Linux release 7.9.2009 (Core)
x86_64

2. "ifconfig -a" (UNIX) または "ipconfig /all" (Windows) の結果

IPアドレス/MACアドレスの一部を伏せております

Code: Select all

docker0: flags=4355<UP,BROADCAST,PROMISC,MULTICAST>  mtu 1500
        inet 172.17.0.1  netmask 255.255.0.0  broadcast 172.17.255.255
        ether 02:42:83:69:99:07  txqueuelen 0  (Ethernet)
        RX packets 0  bytes 0 (0.0 B)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 0  bytes 0 (0.0 B)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

eth0: flags=4419<UP,BROADCAST,RUNNING,PROMISC,MULTICAST>  mtu 1500
        inet xxx.xxx.58.102  netmask 255.255.254.0  broadcast xxx.xxx.59.255
        inet6 xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:58:102  prefixlen 64  scopeid 0x0<global>
        inet6 fe80::9ea3:baff:fe06:cc9e  prefixlen 64  scopeid 0x20<link>
        ether 9c:a3:ba:xx:xx:xx  txqueuelen 1000  (Ethernet)
        RX packets 3454  bytes 224819 (219.5 KiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 490  bytes 66099 (64.5 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

eth1: flags=4419<UP,BROADCAST,RUNNING,PROMISC,MULTICAST>  mtu 1500
        ether 9c:a3:ba:xx:xx:xx  txqueuelen 1000  (Ethernet)
        RX packets 0  bytes 0 (0.0 B)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 3  bytes 1029 (1.0 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

eth2: flags=4419<UP,BROADCAST,RUNNING,PROMISC,MULTICAST>  mtu 1500
        ether 9c:a3:ba:xx:xx:xx  txqueuelen 1000  (Ethernet)
        RX packets 0  bytes 0 (0.0 B)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 3  bytes 1029 (1.0 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

lo: flags=73<UP,LOOPBACK,RUNNING>  mtu 65536
        inet 127.0.0.1  netmask 255.0.0.0
        inet6 ::1  prefixlen 128  scopeid 0x10<host>
        loop  txqueuelen 1000  (Local Loopback)
        RX packets 8  bytes 672 (672.0 B)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 8  bytes 672 (672.0 B)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

3. "uname -a" (UNIX) または "systeminfo" (Windows) の結果

ホスト名をexample.comに置き換えております

Code: Select all

Linux example.com 3.10.0-1160.15.2.el7.x86_64 #1 SMP Wed Feb 3 15:06:38 UTC 2021 x86_64 x86_64 x86_64 GNU/Linux

4. SoftEther VPN のビルド番号

Version 4.34 Build 9745 (English)


5. どの SoftEther VPN のコンポーネントを使用していますか?

VPN Server


6. VPN サーバーとインターネットとの間に NAT やファイアウォールデバイスはありますか?
(もし NAT またはファイアウォールがある場合、VPN サーバーの TCP リスナポートに対して TCP ポートを開く必要があります。)

存在しますが、TCP443番、TCP5555番ともに開放しております。

マシン側でもファイアウォールを設定しておりますが、同様にTCP443番、TCP5555番ともに開放しております。

トピック名称のとおり、同一マシンでプロキシを使用しております。
443番ポートからは、当該ホスト名に対する接続であればローカルホストの5555番ポートへ転送しております。


7. SecureNAT 機能を使用していますか?
(もしそうであれば、代わりにローカルブリッジを使用するべきです。
SecureNAT のパフォーマンスはローカルブリッジよりも低下します。
また、SecureNAT は多量の CPU 時間を消費します。
SecureNAT は大変限られた状況でのみしか使用してはなりません。)
詳しくは http://ja.softether.org/4-docs/1-manual ... B.E9.A0.85

VPS上での動作のため、使用しております。
ただし、SecureNAT機能を無効化した場合であっても状況に変化はありませんでした。


8. 現在の vpn_server.config または vpn_bridge.config ファイルの内容を投稿に添付してください。
(秘密情報がこれらのファイルに含まれている場合はその部分を除去しても差し支えありません)
vpn_server.config.txt
You do not have the required permissions to view the files attached to this post.

eddiewu
Posts: 286
Joined: Wed Nov 25, 2020 9:10 am

Re: リバースプロキシ環境下での利用について

Post by eddiewu » Wed Mar 10, 2021 7:00 am

あくまで推測ですが、リバースプロキシの転送先を127.0.0.1:5555から[実際のIPアドレスかホスト名]:5555に変更してみていただければ何か変わりはあるのかなと考えています。

cedar
Site Admin
Posts: 2066
Joined: Sat Mar 09, 2013 5:37 am

Re: リバースプロキシ環境下での利用について

Post by cedar » Wed Mar 10, 2021 10:11 am

プロキシのログには、エラーの記録は無かったでしょうか。

crow31415
Posts: 3
Joined: Sat Mar 06, 2021 8:22 pm

Re: リバースプロキシ環境下での利用について

Post by crow31415 » Wed Mar 10, 2021 12:17 pm

eddiewu様 cedar様 ご回答ありがとうございます。
eddiewu wrote:
Wed Mar 10, 2021 7:00 am
あくまで推測ですが、リバースプロキシの転送先を127.0.0.1:5555から[実際のIPアドレスかホスト名]:5555に変更してみていただければ何か変わりはあるのかなと考えています。
ご指摘いただいたとおり、リバースプロキシの転送先を127.0.0.1:5555から[実際のIPアドレス]:5555に変更したところ、正常に動作致しました。
重ねて御礼申し上げます。

なお、この際のログは下記の通りです。

Code: Select all

2021-03-10 21:00:32.333 On the TCP Listener (Port 5555), a Client (IP address xxx.xxx.58.102, Host name "server.example.com", Port number 58066) has connected.
2021-03-10 21:00:32.333 For the client (IP address: xxx.xxx.58.102, host name: "server.example.com", port number: 58066), connection "CID-154" has been created.
2021-03-10 21:00:32.404 SSL communication for connection "CID-154" has been started. The encryption algorithm name is "TLS_AES_256_GCM_SHA384".
2021-03-10 21:00:32.525 [HUB "VPN"] The connection "CID-154" (IP address: xxx.xxx.58.102, Host name: server.example.com, Port number: 58066, Client name: "SoftEther VPN Client", Version: 4.34, Build: 9745) is attempting to connect to the Virtual Hub. The auth type provided is "Password authentication" and the user name is "hoge".
2021-03-10 21:00:32.525 [HUB "VPN"] Connection "CID-154": Successfully authenticated as user "hoge".
2021-03-10 21:00:32.525 [HUB "VPN"] Connection "CID-154": The new session "SID-HOGE-18" has been created. (IP address: xxx.xxx.58.102, Port number: 58066, Physical underlying protocol: "Standard TCP/IP (IPv4)")
2021-03-10 21:00:32.525 [HUB "VPN"] Session "SID-HOGE-18": The parameter has been set. Max number of TCP connections: 2, Use of encryption: Yes, Use of compression: No, Use of Half duplex communication: No, Timeout: 20 seconds.
2021-03-10 21:00:32.525 [HUB "VPN"] Session "SID-HOGE-18": VPN Client details: (Client product name: "SoftEther VPN Client", Client version: 434, Client build number: 9745, Server product name: "SoftEther VPN Server (64 bit)", Server version: 434, Server build number: 9745, Client OS name: "Windows 10", Client OS version: "Build 19042, Multiprocessor Free (19041.vb_release.191206-1406)", Client product ID: "--", Client host name: "maple", Client IP address: "192.168.xxx.xxx", Client port number: 58731, Server host name: "vpnserver.example.com", Server IP address: "xxx.xxx.58.102", Server port number: 443, Proxy host name: "", Proxy IP address: "0.0.0.0", Proxy port number: 0, Virtual Hub name: "VPN", Client unique ID: "CCA8662036FAEA684BA8E93D408684C8")
2021-03-10 21:00:32.868 [HUB "VPN"] SecureNAT: The DHCP entry 10 has been created. MAC address: 5E-48-67-62-84-48, IP address: 172.20.1.1, host name: maple, expiration span: 7200 seconds
2021-03-10 21:00:32.868 [HUB "VPN"] Session "SID-SECURENAT-4": The DHCP server of host "5E-AC-7F-23-9F-89" (172.20.0.1) on this session allocated, for host "SID-HOGE-18" on another session "5E-48-67-62-84-48", the new IP address 172.20.1.1.
2021-03-10 21:00:33.817 On the TCP Listener (Port 5555), a Client (IP address xxx.xxx.58.102, Host name "server.example.com", Port number 58068) has connected.
2021-03-10 21:00:33.817 For the client (IP address: xxx.xxx.58.102, host name: "server.example.com", port number: 58068), connection "CID-155" has been created.
2021-03-10 21:00:33.909 SSL communication for connection "CID-155" has been started. The encryption algorithm name is "TLS_AES_256_GCM_SHA384".
2021-03-10 21:00:33.949 [HUB "VPN"] SecureNAT: The TCP session 712 has been created. Connection source 172.20.1.1:58876, Connection destination 13.107.42.12:443
2021-03-10 21:00:33.999 Connection "CID-155" has been terminated.
2021-03-10 21:00:55.179 [HUB "VPN"] Session "SID-HOGE-18": The session has been terminated. The statistical information is as follows: Total outgoing data size: 22451 bytes, Total incoming data size: 32467 bytes.
2021-03-10 21:00:55.209 Connection "CID-154" terminated by the cause "The VPN session has been deleted. It is possible that either the administrator disconnected the session or the connection from the client to the VPN Server has been disconnected." (code 11).
2021-03-10 21:00:55.209 Connection "CID-154" has been terminated.
2021-03-10 21:00:55.209 The connection with the client (IP address xxx.xxx.58.102, Port number 58066) has been disconnected.
locahostに関連する挙動の差異としては、クライアント側のSSL暗号化設定について、
「localhost」(接続元と同じホスト) 上で動作している VPN Server に対して接続する場合は、SSL 暗号化は不要ですので、このチェックボックスは自動的に解除されます。
というものが在ることは存じておりましたが、SSL暗号化設定を無効化した場合であっても状況に変化がなかったため、無関係なものと思い込んでおりました。

後学のため、転送先をlocalhostから実際のIPアドレスに変更することで変化があると推測なされた理由などがあれば、ご教示いただけましたら幸いです。

cedar wrote:
Wed Mar 10, 2021 10:11 am
プロキシのログには、エラーの記録は無かったでしょうか。
プロキシのログの記載を失念しておりました。
失礼致しました。

localhostに転送した場合の、プロキシをverboseで実行した際のログは以下の通りでした。

Code: Select all

accepted fd 5
**** writing deferred on fd -1
probing for ssh: PROBE_NEXT
probing for http: PROBE_NEXT
probing for tls: PROBE_NEXT
matching [vpnserver.example.com] with [vpnserver.example.com]
probing for tls: PROBE_MATCH
connecting to localhost:personal-agent family 2 len 16
tls:connection from client.example.com:13096 to server.example.com:https forwarded from localhost:47398 to localhost:personal-agent
flushing deferred data to fd 3
client socket closed
connection closed down
accepted fd 5
**** writing deferred on fd -1
probing for ssh: PROBE_NEXT
probing for http: PROBE_NEXT
probing for tls: PROBE_NEXT
matching [vpnserver.example.com] with [vpnserver.example.com]
probing for tls: PROBE_MATCH
connecting to localhost:personal-agent family 2 len 16
tls:connection from client.example.com:12713 to server.example.com:https forwarded from localhost:47400 to localhost:personal-agent
flushing deferred data to fd 3
server socket closed
connection closed down
また、eddiewu様よりご指摘いただいた通り実際のIPアドレスに変更した場合、同様に取得したログは以下の通りでした。
なお、セッションが確立した後、セッションを手動で切断するまでの間にはログが発生しませんでした。
セッションを切断した際に末尾4行(Close関連)が発生した形となります。

Code: Select all

accepted fd 5
**** writing deferred on fd -1
probing for ssh: PROBE_NEXT
probing for http: PROBE_NEXT
probing for tls: PROBE_NEXT
matching [vpnserver.example.com] with [vpnserver.example.com]
probing for tls: PROBE_MATCH
connecting to server.example.com:personal-agent family 2 len 16
tls:connection from client.example.com:59939 to server.example.com:https forwarded from server.example.com:58032 to server.example.com:personal-agent
flushing deferred data to fd 3
accepted fd 5
**** writing deferred on fd -1
probing for ssh: PROBE_NEXT
probing for http: PROBE_NEXT
probing for tls: PROBE_NEXT
matching [vpnserver.example.com] with [vpnserver.example.com]
probing for tls: PROBE_MATCH
connecting to server.example.com:personal-agent family 2 len 16
tls:connection from client.example.com:60047 to server.example.com:https forwarded from server.example.com:58034 to server.example.com:personal-agent
flushing deferred data to fd 3
server socket closed
connection closed down
server socket closed
connection closed down

結論と致しましては、eddiewu様よりご指摘いただいたとおり、リバースプロキシの転送先を127.0.0.1:5555から[実際のIPアドレス]:5555に変更したところ、正常に動作致しました。
しかし、このように変更することで解決する理由について今ひとつ理解できておりませんので、この点について引き続き調査を行いたいと考えております。
localhostと実際のIPアドレスの差異について、何か情報がございましたらご教示いただければ幸いです。

今後とも宜しくお願い致します。

eddiewu
Posts: 286
Joined: Wed Nov 25, 2020 9:10 am

Re: リバースプロキシ環境下での利用について

Post by eddiewu » Sun Mar 21, 2021 3:04 pm

crow31415 wrote:
Wed Mar 10, 2021 12:17 pm
結論と致しましては、eddiewu様よりご指摘いただいたとおり、リバースプロキシの転送先を127.0.0.1:5555から[実際のIPアドレス]:5555に変更したところ、正常に動作致しました。
しかし、このように変更することで解決する理由について今ひとつ理解できておりませんので、この点について引き続き調査を行いたいと考えております。
localhostと実際のIPアドレスの差異について、何か情報がございましたらご教示いただければ幸いです。

今後とも宜しくお願い致します。
原因を究明しましたので、ご報告いたします。UDP高速化機能の不具合です。
サーバー側がUDPソケットをオープンする際、接続のローカルIPを使用しています:

Code: Select all

(Protocol.c)
	// Initialize the UDP acceleration function
	s->UdpAccel = NewUdpAccel(c->Cedar, (c->FirstSock->IsRUDPSocket ? NULL : &c->FirstSock->LocalIP), false, c->FirstSock->IsRUDPSocket, no_nat_t);
	                                                                                  ↑ココ

Code: Select all

(UdpAccel.c)
UDP_ACCEL *NewUdpAccel(CEDAR *cedar, IP *ip, bool client_mode, bool random_port, bool no_nat_t)
{
	...
	for (i = UDP_SERVER_PORT_LOWER;i <= UDP_SERVER_PORT_HIGHER;i++)
	{
		if (IsIntInList(cedar->UdpPortList, i) == false)
		{
			s = NewUDPEx3(i, ip); ←ココ
				if (s != NULL)
			{
				is_in_cedar_port_list = true;
				break;
			}
		}
	}
しかしUDPの送信先は接続のリモートIP(localhost)ではなく、クライアントが提示したものなので、パニックを起こしてしまいました。
(127.0.0.1 -> 192.168.x.x は✖です)

Code: Select all

(UdpAccel.c)
                                    ↓ココ
	r = SendTo(a->UdpSock, &a->YourIp, a->YourPort, tmp, size);
	if (r == 0 && a->UdpSock->IgnoreSendErr == false)
	{
		fatal_error = true;
		Debug("Error: SendTo: %r %u %u\n", &a->YourIp, a->YourPort, size);
		WHERE;
	}

cedar
Site Admin
Posts: 2066
Joined: Sat Mar 09, 2013 5:37 am

Re: リバースプロキシ環境下での利用について

Post by cedar » Mon Mar 22, 2021 8:52 am

手元の環境で再現を試みたのですが、うまくいきませんでした。
127.0.0.1 から経路の存在しないプライベートIPアドレスにパケットを送ろうとすると sendto で WSAENETUNREACH か WSAEADDRNOTAVAIL が帰ってくるのですが、SendToEx で これらのエラーは無視するようになっているようです。

https://github.com/SoftEtherVPN/SoftEth ... k.c#L12146

eddiewu
Posts: 286
Joined: Wed Nov 25, 2020 9:10 am

Re: リバースプロキシ環境下での利用について

Post by eddiewu » Mon Mar 22, 2021 1:29 pm

cedar wrote:
Mon Mar 22, 2021 8:52 am
手元の環境で再現を試みたのですが、うまくいきませんでした。
127.0.0.1 から経路の存在しないプライベートIPアドレスにパケットを送ろうとすると sendto で WSAENETUNREACH か WSAEADDRNOTAVAIL が帰ってくるのですが、SendToEx で これらのエラーは無視するようになっているようです。
Windowsで検証されたんですか?こちらはDebianで無事再現しましたので、debugログを添付いたします。

Code: Select all

Accepted.
Connection CID-1 Inserted to Cedar.
LOG: On the TCP Listener (Port 5555), a Client (IP address 127.0.0.1, Host name "localhost", Port number 53452) has connected.
ConnectionAccept()
LOG: For the client (IP address: 127.0.0.1, host name: "localhost", port number: 53452), connection "CID-1" has been created.
Accept()
StartSSL()
SSL connected with TLSv1.3
LOG: SSL communication for connection "CID-1" has been started. The encryption algorithm name is "TLS_AES_256_GCM_SHA384".
Downloading Signature...
Uploading Hello...
Auth...
Login...
Username = test, HubName = DEFAULT
use_udp_acceleration_client = 1
use_hmac_on_udp_acceleration = 1
LOG: [HUB "DEFAULT"] The connection "CID-1" (IP address: 127.0.0.1, Host name: localhost, Port number: 53452, Client name: "SoftEther VPN Client", Version: 4.34, Build: 9745) is attempting to connect to the Virtual Hub. The auth type provided is "Password authentication" and the user name is "test".
LOG: [HUB "DEFAULT"] Connection "CID-1": Successfully authenticated as user "test".
Connection CID-1 Deleted from Cedar.
Session SID-TEST-2 Inserted to DEFAULT.
UseUdpAcceleration = 1
UseHMacOnUdpAcceleration = 1
UdpAccelerationVersion = 0
Udp Accel My Port = 40000
UdpAccelInitServer: ver=2, client_ip=172.20.10.2, client_port=54612, server_cookie=2458817696, client_cookie=2654946928
LOG: [HUB "DEFAULT"] Connection "CID-1": The new session "SID-TEST-2" has been created. (IP address: 127.0.0.1, Port number: 53452, Physical underlying protocol: "Standard TCP/IP (IPv4)")
LOG: [HUB "DEFAULT"] Session "SID-TEST-2": The parameter has been set. Max number of TCP connections: 4, Use of encryption: Yes, Use of compression: No, Use of Half duplex communication: No, Timeout: 20 seconds.
LOG: [HUB "DEFAULT"] Session "SID-TEST-2": VPN Client details: (Client product name: "SoftEther VPN Client", Client version: 434, Client build number: 9745, Server product name: "SoftEther VPN Server (64 bit) (Open Source)", Server version: 434, Server build number: 9745, Client OS name: "Windows 10", Client OS version: "Build 19042, Multiprocessor Free (19041.vb_release.191206-1406)", Client product ID: "--", Client host name: "DESKTOP-FFFFFFF", Client IP address: "172.20.10.2", Client port number: 61721, Server host name: "example.com", Server IP address: "100.1.1.1", Server port number: 443, Proxy host name: "", Proxy IP address: "0.0.0.0", Proxy port number: 0, Virtual Hub name: "DEFAULT", Client unique ID: "53E7BA8EC0CF49D987F5E606C14C7205")
SessionMain()
SessionMain: SID-TEST-2
NAT-T IP Address Resolved: xc.x4.servers.nat-traversal.softether-network.net. = 130.158.6.111
Error: SendTo: 172.20.10.2 54612 61  ←ココ
src/Cedar/UdpAccel.c: 606
src/Cedar/UdpAccel.c: 656
Session SID-TEST-2 Finishing...
Session SID-TEST-2 was Deleted from DEFAULT.

cedar
Site Admin
Posts: 2066
Joined: Sat Mar 09, 2013 5:37 am

Re: リバースプロキシ環境下での利用について

Post by cedar » Tue Mar 23, 2021 3:50 am

Linux と Windows では、UDP/IP スタックの動作が異なるため、Linux でのエラーは別に対処する必要があります。
Linux では、無視するエラーはこの行で定義されています。

if (errno == ECONNREFUSED || errno == ECONNRESET || errno == EMSGSIZE || errno == ENOBUFS || errno == ENOMEM || errno == EINTR)

https://github.com/SoftEtherVPN/SoftEth ... k.c#L12228

この範囲外のエラーが返されていると思われますが、if 文のあとに Debug(”SendTo Error; %u\n", errno); など挿入してエラーコードを確認していただくことは可能でしょうか。

eddiewu
Posts: 286
Joined: Wed Nov 25, 2020 9:10 am

Re: リバースプロキシ環境下での利用について

Post by eddiewu » Tue Mar 23, 2021 8:22 am

もちろんです。エラーコードは22 (EINVAL)でした。

Code: Select all

SendTo Error; 22
Error: SendTo: 172.20.0.42 51528 51
src/Cedar/UdpAccel.c: 606
src/Cedar/UdpAccel.c: 656
SendTo Error; 22
Session SID-TEST-2 Finishing...
Session SID-TEST-2 was Deleted from DEFAULT.
追記:
errno == EINVAL をif条件に加えると、思うどおり無視されるようになりました。

cedar
Site Admin
Posts: 2066
Joined: Sat Mar 09, 2013 5:37 am

Re: リバースプロキシ環境下での利用について

Post by cedar » Tue Mar 23, 2021 9:22 am

ありがとうございます。
おそらくそれは有効な修正と思われますので、お手元に環境があれば GitHub に Pull Request を送ってもらえるでしょうか。
難しいようであれば、私が送信しても構いません。

eddiewu
Posts: 286
Joined: Wed Nov 25, 2020 9:10 am

Re: リバースプロキシ環境下での利用について

Post by eddiewu » Tue Mar 23, 2021 10:14 am

わかりました。やってみます。
Unstableの方ですよね?

cedar
Site Admin
Posts: 2066
Joined: Sat Mar 09, 2013 5:37 am

Re: リバースプロキシ環境下での利用について

Post by cedar » Tue Mar 23, 2021 10:40 am

はい。開発版の方に送ってみてください。
https://github.com/SoftEtherVPN/SoftEtherVPN

eddiewu
Posts: 286
Joined: Wed Nov 25, 2020 9:10 am

Re: リバースプロキシ環境下での利用について

Post by eddiewu » Tue Mar 23, 2021 12:59 pm


cedar
Site Admin
Posts: 2066
Joined: Sat Mar 09, 2013 5:37 am

Re: リバースプロキシ環境下での利用について

Post by cedar » Wed Mar 24, 2021 2:26 am

確認いたしました。
ご協力ありがとうございます。

Post Reply