-
Notifications
You must be signed in to change notification settings - Fork 675
Add support for multi-process port sharing with CIBIR. #5798
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
ProjectsByJackHe
merged 40 commits into
main
from
jackhe/sql-cibir-fix-sock-reservation
Apr 13, 2026
+862
−632
Merged
Changes from all commits
Commits
Show all changes
40 commits
Select commit
Hold shift + click to select a range
ee68434
add a comment
ProjectsByJackHe 68a7afe
update code to account for cibir
ProjectsByJackHe 382fba7
clog fixes
ProjectsByJackHe c1c1445
update docs, update tests
ProjectsByJackHe df75326
rename reserveauxtcpsock and add explicit check for error code
ProjectsByJackHe a952c04
always false in kernel mode...
ProjectsByJackHe a0b20b3
XDP and CIBIR
ProjectsByJackHe d2bd384
add logs
ProjectsByJackHe c2ac95b
more logs
ProjectsByJackHe 7f6d88e
more logs
ProjectsByJackHe b442e8a
return error if xdp not available
ProjectsByJackHe 323d3f0
update docs on proper behavior
ProjectsByJackHe f55cc25
fix test
ProjectsByJackHe a70a8c2
get rid of bad artifact
ProjectsByJackHe cabc5a8
fix nit / clog
ProjectsByJackHe 1557c28
address feedback
ProjectsByJackHe 24e1390
clog
ProjectsByJackHe b43c894
fix inline def
ProjectsByJackHe 8da485c
clog
ProjectsByJackHe 2f06dad
update to use ifdef
ProjectsByJackHe a76904d
do not reserve any sockets at all
ProjectsByJackHe 347356e
give it a non-0 local address
ProjectsByJackHe 70a6e9e
proper port reservations
ProjectsByJackHe e4b5ecc
fix conn pool test case
ProjectsByJackHe cf4fd8b
fix tests
ProjectsByJackHe da3dfd6
put ifdef in handshaketest directly
ProjectsByJackHe 4c9753c
update docs, add dbg assert, and fix logic
ProjectsByJackHe ced6a30
update warning logs
ProjectsByJackHe 8a16a62
Merge branch 'main' into jackhe/sql-cibir-fix-sock-reservation
ProjectsByJackHe 808ea0c
more crisp behavior
ProjectsByJackHe 8a6eef8
Merge branch 'main' into jackhe/sql-cibir-fix-sock-reservation
ProjectsByJackHe ad2070a
update cibir docs
ProjectsByJackHe 18832a4
Merge branch 'main' into jackhe/sql-cibir-fix-sock-reservation
ProjectsByJackHe 078d24c
update docs based on feedback; improve log level
ProjectsByJackHe 6c06c6c
add ifdef
ProjectsByJackHe d820273
proper exclusions
ProjectsByJackHe e9f3ed7
nits
ProjectsByJackHe fdac2dd
nit
ProjectsByJackHe 05d55e1
nit; add assert
ProjectsByJackHe 3b550f8
nit
ProjectsByJackHe File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| # CIBIR | ||
|
|
||
| ## What is it | ||
|
|
||
| See the [draft IETF](https://datatracker.ietf.org/doc/html/draft-banks-quic-cibir) for CIBIR. | ||
|
|
||
| When CIBIR is used, rather than programming [XDP](./XDP.md) to filter and demux packets based on on address and port number, | ||
| XDP with CIBIR will instead filter and de-mux packets based on address, port number, and QUIC connection ID. | ||
|
|
||
| What CIBIR allows for is 2 or more separate server processes to share a single | ||
| port on the same machine, as long as their CIBIR ID is different. | ||
|
|
||
| ## CIBIR port sharing logic | ||
| - Applications must provide a well-known local port for server sockets when using CIBIR and XDP. | ||
| - **IMPORTANT:** MsQuic will **NOT** reserve an OS port for server sockets when both CIBIR and XDP is enabled and available. | ||
| - Client sockets can never share ports, so MsQuic will reserve an OS port in that scenario. | ||
| - The responsibility of book-keeping shared ports and ensuring robust protection for those shared ports is delegated to the application. | ||
|
|
||
|
|
||
| ## Port protection recommendations for shared ports | ||
|
|
||
| ### Option 1: Persistent port reservations (Recommended) | ||
|
|
||
| MsQuic strongly recommends applications leverage the Windows [persistent port reservations API](https://learn.microsoft.com/en-us/windows/win32/api/iphlpapi/nf-iphlpapi-createpersistentudpportreservation) to secure shared CIBIR ports prior to serving multi-process CIBIR traffic on a shared port. | ||
| - One time setup by a system admin to create the persistent reservation. | ||
| - A good option for book-keeping persistent port reservations is via registry keys. | ||
| - Persistent port reservations survive reboots, allowing for robust protection in the event of crashes. | ||
| - Having a persistent reservation makes sure CIBIR ports are taken out of the ephemeral port pool and forbids sockets from binding to it unless it is associated with a persistent reservation token, which can only happen in an elevated process. | ||
| - This way, an unsuspecting application process won't get accidently assigned an ephemeral port that collides with a CIBIR port. | ||
|
|
||
| ### Option 2: WFP ALE (Application Layer Enforcement) filters | ||
|
|
||
| As an alternative, applications can use the [Windows Filtering Platform (WFP)](https://learn.microsoft.com/en-us/windows/win32/fwp/windows-filtering-platform-start-page) to create ALE filters that block unauthorized bind attempts to CIBIR ports. | ||
|
|
||
| ALE filters operate at the [bind and connect authorization layers](https://learn.microsoft.com/en-us/windows/win32/fwp/ale-layers) (`FWPM_LAYER_ALE_AUTH_RECV_ACCEPT_V4/V6`, `FWPM_LAYER_ALE_RESOURCE_ASSIGNMENT_V4/V6`). A filter can be configured to block any process from binding to a specific UDP port unless it matches an allowed application path or security descriptor. | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,130 @@ | ||
| # MsQuic over XDP | ||
|
|
||
| To avoid confusion, "XDP" refers to [XDP-for-windows](https://github.com/microsoft/xdp-for-windows). | ||
| MsQuic does not support Linux XDP as a datapath. | ||
|
|
||
| ## What is XDP | ||
|
|
||
| XDP enables received packets to completely bypass the OS networking stack. | ||
|
|
||
| Applications can subscribe to XDP ring buffers to post packets to send, | ||
| and process packets that are received through AF_XDP sockets. | ||
|
|
||
| Additionally, applications can program XDP to determine the | ||
| logic for which packets to filter for, and what to do with them. | ||
|
|
||
| For instance: "drop all packets with a UDP header and destination port | ||
| 42." | ||
|
|
||
| ## Port reservation logic | ||
|
|
||
| The type of logic MsQuic programs into XDP looks like: | ||
| "redirect all packets with a destination port X to an AF_XDP socket." | ||
|
|
||
| This runs into the issue of **packet stealing.** If there was an unrelated process | ||
| that binds an OS socket to the same port MsQuic used to program XDP, XDP will steal | ||
| that traffic from underneath it. | ||
|
|
||
| Which is why MsQuic will always create an OS UDP socket on the same port as the AF_XDP | ||
| socket to play nice with the rest of the stack. | ||
|
|
||
| There are *exceptions* to this port reservation. | ||
|
|
||
| - Sometimes, MsQuic may create a TCP OS socket instead, or both TCP and UDP (see [QTIP](./QTIP.md)). | ||
| - Sometimes, MsQuic may NOT create any OS sockets at all (see [CIBIR](./CIBIR.md)). | ||
|
|
||
|
|
||
| ## MsQuic over XDP general architecture: | ||
|
|
||
| ```mermaid | ||
|
ProjectsByJackHe marked this conversation as resolved.
|
||
| flowchart TB | ||
|
|
||
| %% ========================= | ||
| %% NIC + RSS | ||
| %% ========================= | ||
| NIC["NIC interface"] | ||
|
|
||
| RSS1["RSS queue"] | ||
| RSS2["RSS queue"] | ||
|
|
||
| NIC --> RSS1 | ||
| NIC --> RSS2 | ||
|
|
||
| %% ========================= | ||
| %% XDP FILTER ENGINE | ||
| %% ========================= | ||
| subgraph XDP_ENGINE["XDP FILTER ENGINE"] | ||
|
|
||
| XDP_PROG1["XDP::XDP program"] | ||
| XDP_PROG2["XDP::XDP program"] | ||
|
|
||
| XDP_RULES["XDP::XDP RULES"] | ||
|
|
||
| AFXDP1["AF_XDP Socket"] | ||
| AFXDP2["AF_XDP Socket"] | ||
|
|
||
| RSS1 -->|packet data| XDP_PROG1 | ||
| RSS2 -->|packet data| XDP_PROG2 | ||
|
|
||
| XDP_PROG1 --> XDP_RULES | ||
| XDP_PROG2 --> XDP_RULES | ||
|
|
||
| XDP_RULES --> AFXDP1 | ||
| XDP_RULES --> AFXDP2 | ||
|
|
||
| end | ||
|
|
||
| %% ========================= | ||
| %% PACKET DEMUX | ||
| %% ========================= | ||
| DEMUX["Packet DE-MUX logic"] | ||
|
|
||
| AFXDP1 --> DEMUX | ||
| AFXDP2 --> DEMUX | ||
|
|
||
| %% ========================= | ||
| %% CXPLAT SOCKET POOL | ||
| %% ========================= | ||
| subgraph CXPLAT_POOL["CXPLAT SOCKET POOL HASH TABLE"] | ||
|
|
||
| CX1["CXPLAT Socket"] | ||
| CX2["CXPLAT Socket"] | ||
| CX3["CXPLAT Socket"] | ||
| CX4["CXPLAT Socket"] | ||
|
|
||
| end | ||
|
|
||
| DEMUX --> CX1 | ||
| DEMUX --> CX2 | ||
| DEMUX --> CX3 | ||
| DEMUX --> CX4 | ||
|
|
||
| %% ========================= | ||
| %% FIND BINDING LOGIC | ||
| %% ========================= | ||
| BIND["FIND BINDING LOGIC"] | ||
|
|
||
| CX1 --> BIND | ||
| CX2 --> BIND | ||
| CX3 --> BIND | ||
| CX4 --> BIND | ||
|
|
||
| %% ========================= | ||
| %% MSQUIC OBJECTS | ||
| %% ========================= | ||
| subgraph MSQUIC_OBJECTS["MSQUIC OBJECTS"] | ||
|
|
||
| CONN1["Connection"] | ||
| CONN2["Connection"] | ||
| CONN3["Connection"] | ||
| LIST1["Listener"] | ||
| LIST2["Listener"] | ||
|
|
||
| end | ||
|
|
||
| BIND --> CONN1 | ||
| BIND --> CONN2 | ||
| BIND --> CONN3 | ||
| BIND --> LIST1 | ||
| BIND --> LIST2 | ||
| ``` | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.