Microsoft MVP성태의 닷넷 이야기
글쓴 사람
정성태 (techsharer at outlook.com)
홈페이지
첨부 파일
 

(시리즈 글이 8개 있습니다.)
개발 환경 구성: 533. Wireshark + C#으로 확인하는 TCP 통신의 MSS(Maximum Segment Size) - 리눅스 환경
; https://www.sysnet.pe.kr/2/0/12527

개발 환경 구성: 534. Wireshark + C#으로 확인하는 TCP 통신의 MSS(Maximum Segment Size) - 윈도우 환경
; https://www.sysnet.pe.kr/2/0/12528

개발 환경 구성: 535. Wireshark + C#으로 확인하는 TCP 통신의 MIN RTO
; https://www.sysnet.pe.kr/2/0/12529

개발 환경 구성: 536. Wireshark + C#으로 확인하는 TCP 통신의 Receive Window
; https://www.sysnet.pe.kr/2/0/12530

개발 환경 구성: 538. Wireshark + C#으로 확인하는 ReceiveBufferSize(SO_RCVBUF), SendBufferSize(SO_SNDBUF)
; https://www.sysnet.pe.kr/2/0/12532

개발 환경 구성: 539. Wireshark + C/C++로 확인하는 TCP 연결에서의 shutdown 동작
; https://www.sysnet.pe.kr/2/0/12533

개발 환경 구성: 540. Wireshark + C/C++로 확인하는 TCP 연결에서의 closesocket 동작
; https://www.sysnet.pe.kr/2/0/12534

개발 환경 구성: 541.  Wireshark로 확인하는 LSO(Large Send Offload), RSC(Receive Segment Coalescing) 옵션
; https://www.sysnet.pe.kr/2/0/12535




Wireshark + C#으로 확인하는 TCP 통신의 MSS(Maximum Segment Size) - 윈도우 환경

지난 글에서 살펴 본,

이더넷(Ethernet) 환경의 TCP 통신에서 MSS(Maximum Segment Size) 확인
; https://www.sysnet.pe.kr/2/0/12521

Wireshark + C#으로 확인하는 TCP 통신의 MSS(Maximum Segment Size) - 리눅스 환경
; https://www.sysnet.pe.kr/2/0/12527

몇몇 실습을 윈도우 환경에서도 해보겠습니다. 우선 MTU 값은 netsh 명령어를 이용해 확인할 수 있습니다.

C:\Users\kevin> netsh interface ipv4 show interfaces

Idx     Met         MTU          State                Name
---  ----------  ----------  ------------  ---------------------------
  1          75  4294967295  connected     Loopback Pseudo-Interface 1
  6          25        1500  disconnected  Local Area Connection
 15          10        1500  connected     Ethernet 3


C:\Users\kevin> netsh interface ipv4 show interfaces 15

Interface Ethernet 3 Parameters
----------------------------------------------
IfLuid                             : ethernet_32774
IfIndex                            : 15
State                              : connected
Metric                             : 10
Link MTU                           : 1500 bytes
Reachable Time                     : 32000 ms
Base Reachable Time                : 30000 ms
Retransmission Interval            : 1000 ms
DAD Transmits                      : 3
Site Prefix Length                 : 64
Site Id                            : 1
Forwarding                         : disabled
Advertising                        : disabled
Neighbor Discovery                 : enabled
Neighbor Unreachability Detection  : enabled
Router Discovery                   : dhcp
Managed Address Configuration      : enabled
Other Stateful Configuration       : enabled
Weak Host Sends                    : disabled
Weak Host Receives                 : disabled
Use Automatic Metric               : enabled
Ignore Default Routes              : disabled
Advertised Router Lifetime         : 1800 seconds
Advertise Default Route            : disabled
Current Hop Limit                  : 0
Force ARPND Wake up patterns       : disabled
Directed MAC Wake up patterns      : disabled
ECN capability                     : application

IP MTU 값이 1500이므로, IP Header == 20, TCP Header == 20인 일반적인 상황이라면 MSS는 1460이 될 것입니다. 실제로 ping 테스트를 (리눅스와는 옵션을 약간 다르게 조정해서) 이렇게 실행할 수 있습니다.

C:\temp> ping www.microsoft.com -l 1473 -f -n 1

Pinging e13678.dscb.akamaiedge.net [23.212.13.232] with 1473 bytes of data:
Packet needs to be fragmented but DF set.

Ping statistics for 23.212.13.232:
    Packets: Sent = 1, Received = 0, Lost = 1 (100% loss),

C:\temp> ping www.microsoft.com -l 1472 -f -n 1

Pinging e13678.dscb.akamaiedge.net [23.212.13.232] with 1472 bytes of data:
Reply from 23.212.13.232: bytes=1472 time=4ms TTL=56

Ping statistics for 23.212.13.232:
    Packets: Sent = 1, Received = 1, Lost = 0 (0% loss),
Approximate round trip times in milli-seconds:
    Minimum = 4ms, Maximum = 4ms, Average = 4ms

보다시피 리눅스에서와 동일하게 ICMP 8바이트를 제외한 1472 바이트가 하나의 패킷에 전달되는 것을 확인할 수 있습니다.




지난 글의 클라이언트/서버 C# 코드를 이번에는 Azure VM(Windows Server 2016)을 서버로, 물리 PC에 설치한 Windows 10을 클라이언트로 테스트하면 연결 시 다음과 같은 3-way handshake를 확인할 수 있습니다.

[...clnt_ip...]  [...azure_svr_ip..]  TCP 66  2406 → 15000 [SYN] Seq=0 Win=64240 Len=0 MSS=1460 WS=256 SACK_PERM=1
[...azure_svr_ip..]  [...clnt_ip...]  TCP 66  15000 → 2406 [SYN, ACK] Seq=0 Ack=1 Win=8192 Len=0 MSS=1440 WS=256 SACK_PERM=1
[...clnt_ip...]  [...azure_svr_ip..]  TCP 54  2406 → 15000 [ACK] Seq=1 Ack=1 Win=263424 Len=0

보는 바와 같이 클라이언트에서 서버로 전송할 때는 MSS=1460이고, 서버에서 클라이언트로 보낼 때는 1440이라고 나옵니다. 서버가 왜 1440을 보냈는지 이유는 알 수 없으나, 어쨌든 이렇게 되면 협상에 따라 MSS=1440으로 결정됩니다.

참고로, IPv6의 경우 IP 헤더가 40바이트이기 때문에 1460으로 나올 수 있습니다. 그 외에, IP-in-IP 터널링에서도 발생할 수도 있고, 혹은 options가 20바이트를 점유하는 경우에도 발생할 수 있습니다.




그런데, 재미있는 점이 하나 있습니다. 리눅스 환경에서는 MSS 크기에 맞게 서버로 패킷이 전송되는 반면, 윈도우의 경우에는 MSS 크기를 무시하고 전송한다는 점입니다. 가령, 리눅스에서 12,960 바이트를 전송하면 다음과 같이 정확히 9개의 패킷(1448 * 8 + 1376)으로 나눠 전달이 되는 것을 확인할 수 있습니다.

"..clnt_ip...","...serverip...","TCP","1514","32990  >  15000 [ACK] Seq=1 Ack=1 Win=64256 Len=1448 TSval=3494193047 TSecr=1743410262"
"..clnt_ip...","...serverip...","TCP","1514","32990  >  15000 [ACK] Seq=1449 Ack=1 Win=64256 Len=1448 TSval=3494193047 TSecr=1743410262"
"..clnt_ip...","...serverip...","TCP","1514","32990  >  15000 [ACK] Seq=2897 Ack=1 Win=64256 Len=1448 TSval=3494193047 TSecr=1743410262"
"..clnt_ip...","...serverip...","TCP","1514","32990  >  15000 [ACK] Seq=4345 Ack=1 Win=64256 Len=1448 TSval=3494193047 TSecr=1743410262"
"..clnt_ip...","...serverip...","TCP","1514","32990  >  15000 [PSH, ACK] Seq=5793 Ack=1 Win=64256 Len=1448 TSval=3494193047 TSecr=1743410262"
"..clnt_ip...","...serverip...","TCP","1514","32990  >  15000 [ACK] Seq=7241 Ack=1 Win=64256 Len=1448 TSval=3494193047 TSecr=1743410262"
"..clnt_ip...","...serverip...","TCP","1514","32990  >  15000 [ACK] Seq=8689 Ack=1 Win=64256 Len=1448 TSval=3494193047 TSecr=1743410262"
"..clnt_ip...","...serverip...","TCP","1514","32990  >  15000 [ACK] Seq=10137 Ack=1 Win=64256 Len=1448 TSval=3494193047 TSecr=1743410262"
"..clnt_ip...","...serverip...","TCP","1442","32990  >  15000 [PSH, ACK] Seq=11585 Ack=1 Win=64256 Len=1376 TSval=3494193047 TSecr=1743410262"
"...serverip...","..clnt_ip...","TCP","66","15000  >  32990 [ACK] Seq=1 Ack=7241 Win=56576 Len=0 TSval=1743507109 TSecr=3494193047"
"...serverip...","..clnt_ip...","TCP","66","15000  >  32990 [ACK] Seq=1 Ack=12961 Win=56576 Len=0 TSval=1743507109 TSecr=3494193047"

반면, 아래는 Window 10 Client에서 Windows Server 2016 Azure VM Server에 12,960 바이트를 send한 경우인데,

..client_ip...  ..server_ip..   TCP 7254    31894 → 15000 [ACK] Seq=1 Ack=1 Win=263424 Len=7200
..server_ip..  ..client_ip...  TCP 60  15000 → 31894 [ACK] Seq=1 Ack=2881 Win=262656 Len=0
..server_ip..  ..client_ip...  TCP 60  15000 → 31894 [ACK] Seq=1 Ack=5761 Win=262656 Len=0
..client_ip...  ..server_ip..   TCP 5814    31894 → 15000 [PSH, ACK] Seq=7201 Ack=1 Win=263424 Len=5760
..server_ip..  ..client_ip...  TCP 60  15000 → 31894 [ACK] Seq=1 Ack=12961 Win=262656 Len=0

2개의 패킷으로만 나눠 가고 있습니다. (패킷 1개에 가기도 합니다.) 이러한 차이점이 서버와의 협상 차이에서 오는 것은 아닌 것 같습니다. 왜냐하면 리눅스 때와 같이 Oracle Cloud의 Linux VM에 12,960 바이트를 보내도,

..client_ip...  ...serverip...  TCP 13014   31905 → 15000 [PSH, ACK] Seq=1 Ack=1 Win=262656 Len=12960
...serverip...  ..client_ip...  TCP 60  15000 → 31905 [ACK] Seq=1 Ack=7301 Win=56576 Len=0
...serverip...  ..client_ip...  TCP 60  15000 → 31905 [ACK] Seq=1 Ack=12961 Win=56576 Len=0

1개의 패킷으로만 처리하고 있으니 최대 크기가 9000의 Jumbo Frame으로도 설명이 안 됩니다. (사실, 애당초 연결 시 결정되는 MSS 값은 1440이라 Jumbo Frame과도 연관이 없습니다.)

참... 이걸 뭐라고 해석해야 할지 모르겠군요. 관련 문서를 찾아 보면 다음과 같은 설명이 있습니다.

What is MSS (maximum segment size)?
; https://www.cloudflare.com/learning/network-layer/what-is-mss/

Essentially, the MSS is equal to MTU minus the size of a TCP header and an IP header:

MTU - (TCP header + IP header) = MSS

One of the key differences between MTU and MSS is that if a packet exceeds a device's MTU, it is broken up into smaller pieces, or "fragmented." In contrast, if a packet exceeds the MSS, it is dropped and not delivered.


혹시 윈도우 버전의 Wireshark에 버그가 있는 걸까요? 그렇다 해도 저런 식으로 버그가 발생하는 것은 쉽지 않을 듯 싶은데요. ^^; 갈수록 더 미궁으로 빠지는군요. (이와 관련한 네트워크 전문가가 계시다면 덧글 부탁드립니다. ^^) (2021-02-09 업데이트: 이것의 원인은 "Large Send Offload" 때문입니다.)




(2021-02-03 업데이트) 위의 결과를 설명할 수 있는 한 가지 가정이라면, Wireshark의 device driver가 Network 레이어의 상단에 위치해서 저런 식의 출력이 되지 않을까 싶습니다. 가령, 연결만 하고 대상 서버의 VM을 paused 상태로 바꾼 다음 send를 시도하면 다음과 같이 출력되는 것을 확인할 수 있습니다.

...[생략]...
3713    42.664245   ..client_ip...  ..server_ip...  TCP 14654   2436 → 15000 [ACK] Seq=1 Ack=1 Win=262656 Len=14600
3731    42.972303   ..client_ip...  ..server_ip...  TCP 1514    [TCP Retransmission] 2436 → 15000 [ACK] Seq=1 Ack=1 Win=262656 Len=1460
3774    43.580628   ..client_ip...  ..server_ip...  TCP 1514    [TCP Retransmission] 2436 → 15000 [ACK] Seq=1 Ack=1 Win=262656 Len=1460
3874    44.784230   ..client_ip...  ..server_ip...  TCP 1514    [TCP Retransmission] 2436 → 15000 [ACK] Seq=1 Ack=1 Win=262656 Len=1460
4074    47.194383   ..client_ip...  ..server_ip...  TCP 1514    [TCP Retransmission] 2436 → 15000 [ACK] Seq=1 Ack=1 Win=262656 Len=1460
4493    51.998457   ..client_ip...  ..server_ip...  TCP 1514    [TCP Retransmission] 2436 → 15000 [ACK] Seq=1 Ack=1 Win=262656 Len=1460
...[생략]...

저렇게 나오는 것을 보면, 14654라고 뜨긴 했지만 내부적으로는 1514로 쪼개 네트워크에 싣는 것으로 예측됩니다. (아무튼... 가정입니다. ^^)




[이 글에 대해서 여러분들과 의견을 공유하고 싶습니다. 틀리거나 미흡한 부분 또는 의문 사항이 있으시면 언제든 댓글 남겨주십시오.]







[최초 등록일: ]
[최종 수정일: 6/27/2021]

Creative Commons License
이 저작물은 크리에이티브 커먼즈 코리아 저작자표시-비영리-변경금지 2.0 대한민국 라이센스에 따라 이용하실 수 있습니다.
by SeongTae Jeong, mailto:techsharer at outlook.com

비밀번호

댓글 작성자
 




... 106  107  108  109  110  111  112  113  114  [115]  116  117  118  119  120  ...
NoWriterDateCnt.TitleFile(s)
11049정성태9/24/201621050오류 유형: 357. 윈도우 백업 시 오류 - 0x81000037
11048정성태9/24/201622056VC++: 100. 전역 변수 유형별 실행 파일 크기 차이점
11047정성태9/21/201625884기타: 61. algospot.com - 양자화(Quantization) 문제 [2]파일 다운로드1
11046정성태9/15/201627523개발 환경 구성: 298. Windows 10 - bash 실행 시 시작 디렉터리 자동 변경
11045정성태9/15/201620169Windows: 119. Windows 10 - bash 명령어 창을 실행했는데 바로 닫히는 경우
11044정성태9/15/201620435VS.NET IDE: 112. Visual Studio 확장 - 편집 화면 내에서 링크를 누르면 외부 웹 브라우저에서 열기
11043정성태9/15/201621856.NET Framework: 606. .NET 스레드 콜 스택 덤프 (7) - ClrMD(Microsoft.Diagnostics.Runtime)를 이용한 방법 [1]파일 다운로드1
11042정성태9/14/201620003오류 유형: 356. Unknown custom metadata item kind: 6
11041정성태9/10/201619480.NET Framework: 605. CLR4 보안 - yield 구문 내에서 SecurityCritical 메서드 사용 불가 - 2번째 이야기
11040정성태9/10/201626766.NET Framework: 604. C# Windows Forms - Drag & Drop 예제 코드 [2]파일 다운로드1
11039정성태9/9/201623260오류 유형: 355. Visual Studio 빌드 오류 - error CS0122: '__ComObject' is inaccessible due to its protection level
11038정성태9/9/201625114VC++: 99. 서로 다른 프로세스에서 WM_DROPFILES 메시지를 전송하는 방법파일 다운로드1
11037정성태9/8/201628343.NET Framework: 603. socket - shutdown 호출이 필요한 사례파일 다운로드1
11036정성태8/29/201624800개발 환경 구성: 297. 소스 코드가 없는 닷넷 어셈블리를 디버깅할 때 지역 변숫값을 확인하는 방법
11035정성태8/29/201620462오류 유형: 354. .NET Reflector - PDB 생성 화면에서 "Clear Store"를 하면 "Index and length must refer to a location within the string" 예외 발생
11034정성태8/25/201624480개발 환경 구성: 296. .NET Core 프로젝트를 NuGet Gallery에 배포하는 방법 [2]
11033정성태8/24/201622370오류 유형: 353. coreclr 빌드 시 error C3249: illegal statement or sub-expression for 'constexpr' function
11032정성태8/23/201621584개발 환경 구성: 295. 최신의 Visual C++ 컴파일러 도구를 사용하는 방법 [1]
11031정성태8/23/201617819오류 유형: 352. Error encountered while pushing to the remote repository: Response status code does not indicate success: 403 (Forbidden).
11030정성태8/23/201620352VS.NET IDE: 111. Team Explorer - 추가한 Git Remote 저장소가 Branch에 보이지 않는 경우
11029정성태8/18/201627522.NET Framework: 602. Process.Start의 cmd.exe에서 stdin만 redirect 하는 방법 [1]파일 다운로드1
11028정성태8/15/201621541오류 유형: 351. Octave 설치 시 JRE 경로 문제
11027정성태8/15/201622632.NET Framework: 601. ElementHost 컨트롤의 메모리 누수 현상
11026정성태8/13/201623604Math: 19. 행렬 연산으로 본 해밍코드
11025정성태8/12/201622327개발 환경 구성: 294. .NET Core 프로젝트에서 "Copy to Output Directory" 처리 [1]
11024정성태8/12/201621637오류 유형: 350. "nProtect GameMon" 실행 중에는 Visual Studio 디버깅이 안됩니다! [1]
... 106  107  108  109  110  111  112  113  114  [115]  116  117  118  119  120  ...