ETH_PAD_SIZE는 이더넷 헤더 앞에 여유 바이트를 두어, 뒤에 오는 IP 헤더와 페이로드의 정렬을 맞추기 위한 설정이다.
이더넷 헤더는 목적지 MAC 6바이트, 출발지 MAC 6바이트, EtherType 2바이트로 총 14바이트다. 32비트 경계 정렬이 필요한 환경에서는 2바이트를 더해 IP 헤더가 정렬된 위치에서 시작하도록 둘 수 있다.
패킷 버퍼 구조
아래처럼 ETH_PAD_SIZE 2바이트와 Ethernet 헤더 14바이트를 합치면 IP 헤더는 버퍼 시작점에서 16바이트 떨어진 위치에서 시작한다.
<mxGraphModel dx="700" dy="240" grid="1" gridSize="10" guides="1" tooltips="1" connect="1" arrows="1" fold="1" page="1" pageScale="1" pageWidth="1169" pageHeight="827" math="0" shadow="0">
<root>
<mxCell id="0" />
<mxCell id="1" parent="0" />
<mxCell id="title" value="Packet buffer layout" style="text;html=1;align=left;verticalAlign=middle;fontSize=18;fontStyle=1;fontColor=#1f2937;" vertex="1" parent="1">
<mxGeometry x="20" y="20" width="640" height="30" as="geometry" />
</mxCell>
<mxCell id="pad" value="ETH_PAD_SIZE (2 bytes)" style="rounded=0;whiteSpace=wrap;html=1;fillColor=#fef3c7;strokeColor=#d97706;fontColor=#92400e;align=center;verticalAlign=middle;fontSize=14;" vertex="1" parent="1">
<mxGeometry x="20" y="90" width="145" height="72" as="geometry" />
</mxCell>
<mxCell id="ethernet" value="Ethernet header (14 bytes)" style="rounded=0;whiteSpace=wrap;html=1;fillColor=#dbeafe;strokeColor=#2563eb;fontColor=#1e3a8a;align=center;verticalAlign=middle;fontSize=14;" vertex="1" parent="1">
<mxGeometry x="165" y="90" width="220" height="72" as="geometry" />
</mxCell>
<mxCell id="ip" value="IP header (offset 16, 32-bit aligned)" style="rounded=0;whiteSpace=wrap;html=1;fillColor=#dcfce7;strokeColor=#16a34a;fontColor=#166534;align=center;verticalAlign=middle;fontSize=13;" vertex="1" parent="1">
<mxGeometry x="385" y="90" width="180" height="72" as="geometry" />
</mxCell>
<mxCell id="payload" value="Payload" style="rounded=0;whiteSpace=wrap;html=1;fillColor=#f3e8ff;strokeColor=#9333ea;fontColor=#6b21a8;align=center;verticalAlign=middle;fontSize=14;" vertex="1" parent="1">
<mxGeometry x="565" y="90" width="95" height="72" as="geometry" />
</mxCell>
<mxCell id="start" value="buffer start: 0 byte" style="text;html=1;align=left;verticalAlign=middle;fontSize=12;fontColor=#6b7280;" vertex="1" parent="1">
<mxGeometry x="20" y="174" width="145" height="20" as="geometry" />
</mxCell>
<mxCell id="aligned" value="IP header starts at 16-byte boundary" style="text;html=1;align=center;verticalAlign=middle;fontSize=12;fontStyle=1;fontColor=#15803d;" vertex="1" parent="1">
<mxGeometry x="385" y="174" width="180" height="20" as="geometry" />
</mxCell>
</root>
</mxGraphModel>모든 환경에서 같은 값을 쓸 수 있는 것은 아니다. 네트워크 드라이버가 요구하는 버퍼 구조와 CPU의 정렬 제약을 먼저 확인해야 한다.
댓글을 불러오고 있습니다.