Skip to content

Commit

Permalink
implement raw socket parsing and add stubs for freeBSD and linux
Browse files Browse the repository at this point in the history
  • Loading branch information
ProjectsByJackHe committed Oct 15, 2024
1 parent ecd56a7 commit 7c08057
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 1 deletion.
1 change: 0 additions & 1 deletion src/core/connection.c
Original file line number Diff line number Diff line change
Expand Up @@ -5511,7 +5511,6 @@ QuicConnRecvDatagramBatch(
CXPLAT_DBG_ASSERT(Packets[i]->Allocated);
CXPLAT_ECN_TYPE ECN = CXPLAT_ECN_FROM_TOS(Packets[i]->TypeOfService);
Packet = Packets[i];

CXPLAT_DBG_ASSERT(Packet->PacketId != 0);
if (!QuicConnRecvPrepareDecrypt(
Connection, Packet, HpMask + i * CXPLAT_HP_SAMPLE_LENGTH) ||
Expand Down
2 changes: 2 additions & 0 deletions src/platform/datapath_epoll.c
Original file line number Diff line number Diff line change
Expand Up @@ -1782,6 +1782,7 @@ CxPlatSocketContextRecvComplete(
BytesTransferred += RecvMsgHdr[CurrentMessage].msg_len;

uint8_t TOS = 0;
uint8_t HopLimitTTL = 0;
uint16_t SegmentLength = 0;
BOOLEAN FoundLocalAddr = FALSE, FoundTOS = FALSE;
QUIC_ADDR* LocalAddr = &IoBlock->Route.LocalAddress;
Expand Down Expand Up @@ -1872,6 +1873,7 @@ CxPlatSocketContextRecvComplete(
}
RecvData->PartitionIndex = SocketContext->DatapathPartition->PartitionIndex;
RecvData->TypeOfService = TOS;
RecvData->HopLimitTTL = 0; // TODO: Set the right Linux socket options and get the TTL.
RecvData->Allocated = TRUE;
RecvData->Route->DatapathType = RecvData->DatapathType = CXPLAT_DATAPATH_TYPE_USER;
RecvData->QueuedOnConnection = FALSE;
Expand Down
1 change: 1 addition & 0 deletions src/platform/datapath_kqueue.c
Original file line number Diff line number Diff line change
Expand Up @@ -1127,6 +1127,7 @@ CxPlatSocketContextRecvComplete(

RecvPacket->Route->Queue = SocketContext;
RecvPacket->TypeOfService = 0;
RecvPacket->HopLimitTTL = 0; // TODO: Check to see if it's even possible to get this information on macOS and FreeBSD. If so, implement it. Otherwise, document that it's not supported.

struct cmsghdr *CMsg;
for (CMsg = CMSG_FIRSTHDR(&SocketContext->RecvMsgHdr);
Expand Down
2 changes: 2 additions & 0 deletions src/platform/datapath_raw_socket.c
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,7 @@ CxPlatDpRawParseIPv4(
}

Packet->TypeOfService = IP->EcnField;
Packet->HopLimitTTL = IP->TimeToLive;
Packet->Route->RemoteAddress.Ipv4.sin_family = AF_INET;
CxPlatCopyMemory(&Packet->Route->RemoteAddress.Ipv4.sin_addr, IP->Source, sizeof(IP->Source));
Packet->Route->LocalAddress.Ipv4.sin_family = AF_INET;
Expand Down Expand Up @@ -366,6 +367,7 @@ CxPlatDpRawParseIPv6(
VersionClassEcnFlow.Value = CxPlatByteSwapUint32(IP->VersionClassEcnFlow);

Packet->TypeOfService = (uint8_t)VersionClassEcnFlow.EcnField;
Packet->HopLimitTTL = IP->HopLimit;
Packet->Route->RemoteAddress.Ipv6.sin6_family = AF_INET6;
CxPlatCopyMemory(&Packet->Route->RemoteAddress.Ipv6.sin6_addr, IP->Source, sizeof(IP->Source));
Packet->Route->LocalAddress.Ipv6.sin6_family = AF_INET6;
Expand Down

0 comments on commit 7c08057

Please sign in to comment.