From 7c08057b3bc3b15ea26a3480758897de1345b1ca Mon Sep 17 00:00:00 2001 From: Jack He Date: Tue, 15 Oct 2024 14:50:34 -0700 Subject: [PATCH] implement raw socket parsing and add stubs for freeBSD and linux --- src/core/connection.c | 1 - src/platform/datapath_epoll.c | 2 ++ src/platform/datapath_kqueue.c | 1 + src/platform/datapath_raw_socket.c | 2 ++ 4 files changed, 5 insertions(+), 1 deletion(-) diff --git a/src/core/connection.c b/src/core/connection.c index 73be15cdea..6a1375c1fa 100644 --- a/src/core/connection.c +++ b/src/core/connection.c @@ -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) || diff --git a/src/platform/datapath_epoll.c b/src/platform/datapath_epoll.c index b02152376e..f4a72d0989 100644 --- a/src/platform/datapath_epoll.c +++ b/src/platform/datapath_epoll.c @@ -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; @@ -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; diff --git a/src/platform/datapath_kqueue.c b/src/platform/datapath_kqueue.c index 12aabccb68..bb75c009cd 100644 --- a/src/platform/datapath_kqueue.c +++ b/src/platform/datapath_kqueue.c @@ -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); diff --git a/src/platform/datapath_raw_socket.c b/src/platform/datapath_raw_socket.c index e0a31c07da..9368a7bcd0 100644 --- a/src/platform/datapath_raw_socket.c +++ b/src/platform/datapath_raw_socket.c @@ -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; @@ -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;