Disable Don't Fragment for StreamConnection

This commit is contained in:
Florian Märkl 2019-08-20 17:56:24 +02:00
commit 5b705e9176
No known key found for this signature in database
GPG key ID: 125BC8A5A6A1E857
4 changed files with 18 additions and 11 deletions

View file

@ -116,6 +116,7 @@ typedef struct chiaki_takion_connect_info_t
ChiakiLog *log;
struct sockaddr *sa;
size_t sa_len;
bool ip_dontfrag;
ChiakiTakionCallback cb;
void *cb_user;
bool enable_crypt;

View file

@ -151,6 +151,7 @@ CHIAKI_EXPORT ChiakiErrorCode chiaki_senkusha_run(ChiakiSenkusha *senkusha, uint
memcpy(takion_info.sa, session->connect_info.host_addrinfo_selected->ai_addr, takion_info.sa_len);
err = set_port(takion_info.sa, htons(SENKUSHA_PORT));
assert(err == CHIAKI_ERR_SUCCESS);
takion_info.ip_dontfrag = true;
takion_info.enable_crypt = false;
takion_info.protocol_version = 7;

View file

@ -142,6 +142,7 @@ CHIAKI_EXPORT ChiakiErrorCode chiaki_stream_connection_run(ChiakiStreamConnectio
memcpy(takion_info.sa, session->connect_info.host_addrinfo_selected->ai_addr, takion_info.sa_len);
err = set_port(takion_info.sa, htons(STREAM_CONNECTION_PORT));
assert(err == CHIAKI_ERR_SUCCESS);
takion_info.ip_dontfrag = false;
takion_info.enable_crypt = true;
takion_info.protocol_version = 9;

View file

@ -245,23 +245,27 @@ CHIAKI_EXPORT ChiakiErrorCode chiaki_takion_connect(ChiakiTakion *takion, Chiaki
goto error_sock;
}
if(info->ip_dontfrag)
{
#if __APPLE__
CHIAKI_LOGW(takion->log, "Don't fragment is not supported on macOS, MTU values may be incorrect.");
CHIAKI_LOGW(takion->log, "Don't fragment is not supported on macOS, MTU values may be incorrect.");
#else
#if defined(_WIN32)
const DWORD dontfragment_val = 1;
r = setsockopt(takion->sock, IPPROTO_IP, IP_DONTFRAGMENT, (const void *)&dontfragment_val, sizeof(dontfragment_val));
const DWORD dontfragment_val = 1;
r = setsockopt(takion->sock, IPPROTO_IP, IP_DONTFRAGMENT, (const void *)&dontfragment_val, sizeof(dontfragment_val));
#else
const int mtu_discover_val = IP_PMTUDISC_DO;
r = setsockopt(takion->sock, IPPROTO_IP, IP_MTU_DISCOVER, (const void *)&mtu_discover_val, sizeof(mtu_discover_val));
const int mtu_discover_val = IP_PMTUDISC_DO;
r = setsockopt(takion->sock, IPPROTO_IP, IP_MTU_DISCOVER, (const void *) &mtu_discover_val, sizeof(mtu_discover_val));
#endif
if(r < 0)
{
CHIAKI_LOGE(takion->log, "Takion failed to setsockopt IP_MTU_DISCOVER: %s", strerror(errno));
ret = CHIAKI_ERR_NETWORK;
goto error_sock;
}
CHIAKI_LOGI(takion->log, "Takion enabled Don't Fragment Bit");
#endif
if(r < 0)
{
CHIAKI_LOGE(takion->log, "Takion failed to setsockopt IP_MTU_DISCOVER: %s", strerror(errno));
ret = CHIAKI_ERR_NETWORK;
goto error_sock;
}
#endif
r = connect(takion->sock, info->sa, info->sa_len);
if(r < 0)