-
Notifications
You must be signed in to change notification settings - Fork 662
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
Merged
Changes from 28 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
Some comments aren't visible on the classic Files Changed page.
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,31 @@ | ||
| # CIBIR | ||
|
|
||
| ## What is it | ||
|
|
||
| See [XDP](./XDP.md) first to understand the context. | ||
|
|
||
| When CIBIR is used, rather than programming XDP to filter packets on port numbers, | ||
| we now filter and de-mux packets based on QUIC connection ID. | ||
|
|
||
| CIBIR (CID-Based Identification and Routing) is just a prefix substring that XDP | ||
| will use to match and filter all packets with a QUIC CID that contains the prefix substring equal to CIBIR. | ||
|
|
||
| What using CIBIR also enables is allowing 2 or more separate server processes to share a single | ||
| port. As long as the CIBIR configuration used by each process is different, XDP can | ||
| properly de-mux and dispatch received packets to the right process. | ||
|
|
||
| ## Port sharing rules | ||
| - **IMPORTANT:** MsQuic will **NOT** reserve OS ports for server sockets using CIBIR+XDP. | ||
| - Applications should be aware that if other processes on the system aren't collaborative, then traffic stealing is very possible if some other non-cibir server process binds to the shared port. | ||
| - Applications must also provide a well-known local port for listeners using cibir+XDP. | ||
| - MsQuic client connections may **NOT** share ports, thus MsQuic will create OS port reservations | ||
| for cibir+xdp clients. | ||
|
|
||
| ## Port protection options | ||
|
|
||
| There are a variety of options applications can leverage to protect these cibir shared ports from stealing traffic. | ||
|
|
||
| - Persistent reservations: | ||
| https://learn.microsoft.com/en-us/windows/win32/api/iphlpapi/nf-iphlpapi-createpersistentudpportreservation API, to allow sysadmins to pre-allocate a block of ports and disallow other applications from binding to it. Blocks of ports reserved are safe from reboots. | ||
| - A well known CIBIR registry key can be used to detail shared ports, and sysadmins can coordinate their system such that other apps will not bind to those ports. | ||
| - ALE policies; applications can configure WFP to block certain ports from being binded to by other apps. | ||
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). While Linux XDP has been experimented | ||
| upon in the past and shown some promise for running MsQuic, it is NOT a stable datapath actively being maintained today. | ||
|
ProjectsByJackHe marked this conversation as resolved.
Outdated
|
||
|
|
||
| ## 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.