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

비밀번호

댓글 작성자
 




... 46  47  48  49  50  51  52  53  54  55  56  57  58  [59]  60  ...
NoWriterDateCnt.TitleFile(s)
12170정성태3/6/20209900오류 유형: 599. "Docker Desktop is switching..." 메시지와 DockerDesktopVM CPU 소비 현상
12169정성태3/5/202011913개발 환경 구성: 473. Windows nanoserver에 대한 docker pull의 태그 사용 [1]
12168정성태3/5/202012634개발 환경 구성: 472. 윈도우 환경에서의 dockerd.exe("Docker Engine" 서비스)가 Linux의 것과 다른 점
12167정성태3/5/202011855개발 환경 구성: 471. C# - 닷넷 응용 프로그램에서 DB2 Express-C 데이터베이스 사용 (3) - ibmcom/db2express-c 컨테이너 사용
12166정성태3/4/202011468개발 환경 구성: 470. Windows Server 컨테이너 - DockerMsftProvider 모듈을 이용한 docker 설치
12165정성태3/2/202011091.NET Framework: 900. 실행 시에 메서드 가로채기 - CLR Injection: Runtime Method Replacer 개선 - 네 번째 이야기(Monitor.Enter 후킹)파일 다운로드1
12164정성태2/29/202011962오류 유형: 598. Surface Pro 6 - Windows Hello Face Software Device가 인식이 안 되는 문제
12163정성태2/27/202010424.NET Framework: 899. 익명 함수를 가리키는 delegate 필드에 대한 직렬화 문제
12162정성태2/26/202013270디버깅 기술: 166. C#에서 만든 COM 객체를 C/C++로 P/Invoke Interop 시 메모리 누수(Memory Leak) 발생 [6]파일 다운로드2
12161정성태2/26/20209877오류 유형: 597. manifest - The value "x64" of attribute "processorArchitecture" in element "assemblyIdentity" is invalid.
12160정성태2/26/202010597개발 환경 구성: 469. Reg-free COM 개체 사용을 위한 manifest 파일 생성 도구 - COMRegFreeManifest
12159정성태2/26/20208699오류 유형: 596. Visual Studio - The project needs to include ATL support
12158정성태2/25/202010612디버깅 기술: 165. C# - Marshal.GetIUnknownForObject/GetIDispatchForObject 사용 시 메모리 누수(Memory Leak) 발생파일 다운로드1
12157정성태2/25/202010585디버깅 기술: 164. C# - Marshal.GetNativeVariantForObject 사용 시 메모리 누수(Memory Leak) 발생 및 해결 방법파일 다운로드1
12156정성태2/25/20209872오류 유형: 595. LINK : warning LNK4098: defaultlib 'nafxcw.lib' conflicts with use of other libs; use /NODEFAULTLIB:library
12155정성태2/25/20209094오류 유형: 594. Warning NU1701 - This package may not be fully compatible with your project
12154정성태2/25/20208890오류 유형: 593. warning LNK4070: /OUT:... directive in .EXP differs from output filename
12153정성태2/23/202011666.NET Framework: 898. Trampoline을 이용한 후킹의 한계파일 다운로드1
12152정성태2/23/202011391.NET Framework: 897. 실행 시에 메서드 가로채기 - CLR Injection: Runtime Method Replacer 개선 - 세 번째 이야기(Trampoline 후킹)파일 다운로드1
12151정성태2/22/202011860.NET Framework: 896. C# - Win32 API를 Trampoline 기법을 이용해 C# 메서드로 가로채는 방법 - 두 번째 이야기 (원본 함수 호출)파일 다운로드1
12150정성태2/21/202011739.NET Framework: 895. C# - Win32 API를 Trampoline 기법을 이용해 C# 메서드로 가로채는 방법 [1]파일 다운로드1
12149정성태2/20/202011513.NET Framework: 894. eBEST C# XingAPI 래퍼 - 연속 조회 처리 방법 [1]
12148정성태2/19/202012784디버깅 기술: 163. x64 환경에서 구현하는 다양한 Trampoline 기법 [1]
12147정성태2/19/202011417디버깅 기술: 162. x86/x64의 기계어 코드 최대 길이
12146정성태2/18/202011615.NET Framework: 893. eBEST C# XingAPI 래퍼 - 로그인 처리파일 다운로드1
12145정성태2/18/202010840.NET Framework: 892. eBEST C# XingAPI 래퍼 - Sqlite 지원 추가파일 다운로드1
... 46  47  48  49  50  51  52  53  54  55  56  57  58  [59]  60  ...