-
Notifications
You must be signed in to change notification settings - Fork 837
sbr: Add options to configure static gateway IP and preserve default routes #1217
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
base: main
Are you sure you want to change the base?
Conversation
78e2abb to
0d9f9b1
Compare
|
Looks nice! |
|
Thanks for the review @squeed!
I'm not sure I fully understand the question. If a user wanted only source-hinted routes without custom tables, I don't think they'd need SBR at all - the kernel already creates these automatically when IPs are assigned. In my case at least, without SBR on my interface at 10.5.0.5, the source-hinted route is already in the main table: The SBR plugin (without this added plugins/plugins/meta/sbr/main.go Lines 396 to 402 in 0d9f9b1
Does that make sense? Please let me know if I've misunderstood your question. |
|
🤦 of course. I don't know what I was thinking. |
plugins/meta/sbr/main.go
Outdated
| Table *int `json:"table,omitempty"` | ||
| // Gateway allows specifying a static/hardcoded gateway IP address | ||
| // If set, this will be used instead of the gateway from prevResult | ||
| Gateway string `json:"gateway,omitempty"` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note: This should permit dual-stack :-). Ideally this is a list.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also could be useful for anyone simply having multiple gateways
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@squeed I have updated the plugin to support dual-stack, PTAL when you get a chance.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also could be useful for anyone simply having multiple gateways
Currently the static gateway option introduced in this PR will apply the same gateway to all IPs passed in from prevResult.
I see two potential enhancements here:
- Support multiple IPs by configuring a mapping of subnets to gateways, e.g.
{
"type": "sbr",
"gateways": {
"192.168.1.209/24": "192.168.1.1",
"192.168.101.209/24"": "192.168.101.1"
},
"preserveDefaultRoutes": true
}
- Support multiple gateways per subnet (multiple default routes per address, ECMP load-balancing). This would be a net-new feature that goes beyond what the sbr plugin currently does with prevResult
Are you ok with the current limitation on static gateways, or would you prefer if I implement matching gateways to subnets for the mulitiple IP case in this PR?
plugins/meta/sbr/main.go
Outdated
| Table *int `json:"table,omitempty"` | ||
| // Gateway allows specifying a static/hardcoded gateway IP address | ||
| // If set, this will be used instead of the gateway from prevResult | ||
| Gateway string `json:"gateway,omitempty"` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also could be useful for anyone simply having multiple gateways
karampok
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some comments from my side
- 5 commits seem too many imo, maybe 2 (one for static gateway on for preserveDefaultRoutes) or even 1 (like atomic commits)
- test look a bit thin, like only ipv4 not unhappy path
(Note: I am not maintainer of the repo)
plugins/meta/sbr/main.go
Outdated
| // PreserveDefaultRoutes keeps subnet routes in the main routing table | ||
| // with proper source IP hints for destination-based routing. | ||
| // This allows packets without an explicit source IP to be routed correctly. | ||
| PreserveDefaultRoutes bool `json:"preserveDefaultRoutes,omitempty"` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
PreserveDefaultRoutes: is not so clear to me.
The "defaultRoutes" suffix makes think that in the main table I see a default route, which is not true, I only should see the subnet via eth0 src x.y.z.k, is that correct?
thx
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this is a good point. I renamed this option to AddSourceHints. Do you think that is more clear?
plugins/meta/sbr/main.go
Outdated
| } else if ipCfg.Gateway != nil { | ||
| gateway = ipCfg.Gateway | ||
| } | ||
| } else { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is more golang if we have code without else and else if
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, I made this a switch statement.
| "cniVersion": "0.3.0", | ||
| "name": "cni-plugin-sbr-test", | ||
| "type": "sbr", | ||
| "gateways": ["192.168.1.254"], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ideally a test for ipv4, ipv6 and dualstack
squeed
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you please squash your commits? And a v6 test would be good.
Add two new configuration options:
1. "gateways" ([]string): Static gateway IPs that override prevResult.
Supports dual-stack (one IPv4 and/or one IPv6 address).
2. "addSourceHints" (bool): Preserves subnet routes in the main table
with source IP hints, enabling destination-based routing to work
alongside source-based routing.
Example:
{
"type": "sbr",
"gateways": ["10.0.0.1"],
"addSourceHints": true
}
Signed-off-by: David Whyte-Gray <[email protected]>
This PR aims to solve two problems I faced using the source-based router CNI plugin for distributed LLM inference with vLLM / llm-d.
In my environment (IBM Cloud), the DHCP server my secondary high-speed networks does not provide the gateway IP, so I needed a way to override / statically define the gateway IPs to ensure that the custom routing tables included the default route to the gateway.
ping -I 10.0.0.6 10.1.0.7would work, butping 10.1.0.7. With"preserveDefaultRoutes": true, both work.Tested in my environment with this CNI config:
In a Pod, the result of the statically defined gateway:
and the result of preserve default route: