Skip to content

Commit bea303f

Browse files
fix: connection approval cannot exceed mtu size (#3564)
This PR resolves the issue where a `NetworkConfig.ConnectionData` that caused the `ConnectionRequestMessage` to exceed the transport's MTU size would result in a buffer overflow error by updating `ConnectionRequestMessage` to use the `ReliableFragmentedSequenced` pipeline as opposed to the `ReliableSequenced` pipeline. [MTTB-1467](https://jira.unity3d.com/browse/MTTB-1467) ## Changelog - Fixed: issue where NetworkConfig.ConnectionData could cause the ConnectionRequestMessage to exceed the transport's MTU size and would result in a buffer overflow error. ## Testing and Documentation - Includes modifications to `ConnectionApprovalTests` integration tests to use a > MTU size `NetworkConfig.ConnectionData`. - No documentation changes or additions were necessary. ## Backport This needs to be back ported to the v1.x branch.
1 parent 98b2b9f commit bea303f

File tree

3 files changed

+11
-6
lines changed

3 files changed

+11
-6
lines changed

com.unity.netcode.gameobjects/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ Additional documentation and release notes are available at [Multiplayer Documen
1717

1818
### Fixed
1919

20+
- Fixed issue where NetworkConfig.ConnectionData could cause the ConnectionRequestMessage to exceed the transport's MTU size and would result in a buffer overflow error. (#3564)
2021
- Fixed regression issue in v2.x where `NetworkObject.GetNetworkBehaviourAtOrderIndex` was converted from public to internal. (#3541)
2122
- Fixed ensuring OnValueChanged callback is still triggered on the authority when a collection changes and then reverts to the previous value in the same frame. (#3539)
2223
- Fixed synchronizing the destroyGameObject parameter to clients for InScenePlaced network objects. (#3514)

com.unity.netcode.gameobjects/Runtime/Connection/NetworkConnectionManager.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -635,7 +635,7 @@ private void SendConnectionRequest()
635635
}
636636
}
637637

638-
SendMessage(ref message, NetworkDelivery.ReliableSequenced, NetworkManager.ServerClientId);
638+
SendMessage(ref message, NetworkDelivery.ReliableFragmentedSequenced, NetworkManager.ServerClientId);
639639
message.MessageVersions.Dispose();
640640
}
641641

com.unity.netcode.gameobjects/Tests/Runtime/ConnectionApproval.cs

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ public enum PlayerCreation
2222
Prefab,
2323
PrefabHash,
2424
NoPlayer,
25-
FailValidation
25+
FailValidation,
2626
}
2727
private PlayerCreation m_PlayerCreation;
2828
private bool m_ClientDisconnectReasonValidated;
@@ -38,7 +38,7 @@ public ConnectionApprovalTests(PlayerCreation playerCreation)
3838

3939
protected override int NumberOfClients => 1;
4040

41-
private Guid m_ValidationToken;
41+
private string m_ValidationToken;
4242

4343
protected override bool ShouldCheckForSpawnedPlayers()
4444
{
@@ -56,8 +56,13 @@ protected override void OnServerAndClientsCreated()
5656
m_ClientDisconnectReasonValidated = false;
5757
m_BypassConnectionTimeout = m_PlayerCreation == PlayerCreation.FailValidation;
5858
m_Validated.Clear();
59-
m_ValidationToken = Guid.NewGuid();
60-
var validationToken = Encoding.UTF8.GetBytes(m_ValidationToken.ToString());
59+
m_ValidationToken = string.Empty;
60+
// Exceed the expected MTU size
61+
while (m_ValidationToken.Length < 2000)
62+
{
63+
m_ValidationToken += Guid.NewGuid().ToString();
64+
}
65+
var validationToken = Encoding.UTF8.GetBytes(m_ValidationToken);
6166
m_ServerNetworkManager.ConnectionApprovalCallback = NetworkManagerObject_ConnectionApprovalCallback;
6267
m_ServerNetworkManager.NetworkConfig.PlayerPrefab = m_PlayerCreation == PlayerCreation.Prefab ? m_PlayerPrefab : null;
6368
if (m_PlayerCreation == PlayerCreation.PrefabHash)
@@ -66,7 +71,6 @@ protected override void OnServerAndClientsCreated()
6671
}
6772
m_ServerNetworkManager.NetworkConfig.ConnectionApproval = true;
6873
m_ServerNetworkManager.NetworkConfig.ConnectionData = validationToken;
69-
7074
foreach (var client in m_ClientNetworkManagers)
7175
{
7276
client.NetworkConfig.PlayerPrefab = m_PlayerCreation == PlayerCreation.Prefab ? m_PlayerPrefab : null;

0 commit comments

Comments
 (0)