Skip to content

Commit

Permalink
Also only set ECN/DSCP when they are non-default for IPv6. Fix test f…
Browse files Browse the repository at this point in the history
…ailure.
  • Loading branch information
anrossi committed Feb 5, 2025
1 parent cc4d4f8 commit ac7b03e
Showing 1 changed file with 26 additions and 15 deletions.
41 changes: 26 additions & 15 deletions src/platform/datapath_winuser.c
Original file line number Diff line number Diff line change
Expand Up @@ -4554,22 +4554,26 @@ CxPlatSocketSendInline(
PktInfo6->ipi6_addr = LocalAddress->Ipv6.sin6_addr;
}

WSAMhdr.Control.len += WSA_CMSG_SPACE(sizeof(INT));
CMsg = WSA_CMSG_NXTHDR(&WSAMhdr, CMsg);
CXPLAT_DBG_ASSERT(CMsg != NULL);
CMsg->cmsg_level = IPPROTO_IPV6;
CMsg->cmsg_type = IPV6_ECN;
CMsg->cmsg_len = WSA_CMSG_LEN(sizeof(INT));
*(PINT)WSA_CMSG_DATA(CMsg) = SendData->ECN;

if (Socket->Datapath->Features & CXPLAT_DATAPATH_FEATURE_SEND_DSCP) {
WSAMhdr.Control.len += WSA_CMSG_SPACE(sizeof(INT));
CMsg = WSA_CMSG_NXTHDR(&WSAMhdr, CMsg);
CXPLAT_DBG_ASSERT(CMsg != NULL);
CMsg->cmsg_level = IPPROTO_IPV6;
CMsg->cmsg_type = IPV6_TCLASS;
CMsg->cmsg_len = WSA_CMSG_LEN(sizeof(INT));
*(PINT)WSA_CMSG_DATA(CMsg) = SendData->ECN | (SendData->DSCP << 2);
if (SendData->ECN != CXPLAT_ECN_NON_ECT || SendData->DSCP != CXPLAT_DSCP_CS0) {
WSAMhdr.Control.len += WSA_CMSG_SPACE(sizeof(INT));
CMsg = WSA_CMSG_NXTHDR(&WSAMhdr, CMsg);
CXPLAT_DBG_ASSERT(CMsg != NULL);
CMsg->cmsg_level = IPPROTO_IPV6;
CMsg->cmsg_type = IPV6_TCLASS;
CMsg->cmsg_len = WSA_CMSG_LEN(sizeof(INT));
*(PINT)WSA_CMSG_DATA(CMsg) = SendData->ECN | (SendData->DSCP << 2);
}
} else {
if (SendData->ECN != CXPLAT_ECN_NON_ECT) {
WSAMhdr.Control.len += WSA_CMSG_SPACE(sizeof(INT));
CMsg = WSA_CMSG_NXTHDR(&WSAMhdr, CMsg);
CXPLAT_DBG_ASSERT(CMsg != NULL);
CMsg->cmsg_level = IPPROTO_IPV6;
CMsg->cmsg_type = IPV6_ECN;
CMsg->cmsg_len = WSA_CMSG_LEN(sizeof(INT));
*(PINT)WSA_CMSG_DATA(CMsg) = SendData->ECN;
}
}
}

Expand All @@ -4583,6 +4587,13 @@ CxPlatSocketSendInline(
*(PDWORD)WSA_CMSG_DATA(CMsg) = SendData->SegmentSize;
}

//
// Windows' networking stack doesn't like a non-NULL Control.buf when len is 0.
//
if (WSAMhdr.Control.len == 0) {
WSAMhdr.Control.buf = NULL;
}

if (Socket->Type == CXPLAT_SOCKET_UDP && Socket->UseRio) {
CxPlatSocketSendWithRio(SendData, &WSAMhdr);
return;
Expand Down

0 comments on commit ac7b03e

Please sign in to comment.