Skip to content

sbr: Add rule for outbound interface when there is a single interface IP - #1144

Open
neilcook wants to merge 3 commits into
containernetworking:mainfrom
neilcook:oif_rule
Open

neilcook wants to merge 3 commits into
containernetworking:mainfrom
neilcook:oif_rule

Conversation

@neilcook

@neilcook neilcook commented Jan 26, 2025 •

Copy link
Copy Markdown

When using the sbr plugin with a CNI plugin such as multus, applications have to bind to the source IP address of the interface for the str plugin to work correctly. They cannot bind to the interface name, because the sbr plugin doesn't currently add a rule for the interface name.

This is problematic because it is straightforward to configure the name of a multus interface, however the IP address is usually assigned from a range, so the exact interface IP address to use is not known in advance unlike the interface name. It would thus be much easier for applications if the sbr plugin added a rule with the interface name in addition to the rule with the interface address.

This PR does exactly that - adds an additional rule with the outbound interface name, so that applications can configure the name of the interface to bind to, rather than having to know the interface IP address.

This functionality is only enabled if the new config option useOriginatingIf is enabled. One oif rule is added per-address-family, using the first address it finds in that family.

The functionality is deliberately additive, it still adds the IP-source rules and moves routes etc. as before. That allows applications binding specifically to interfaces to co-exist with applications that do not. The oif rule is always added last, to ensure that they continue to apply to applications only binding to source IP addresses.

@neilcook
neilcook force-pushed the oif_rule branch 2 times, most recently from a435c72 to 6dfec7f Compare January 26, 2025 14:46
@neilcook neilcook changed the title Add rule for outbound interface when there is a single interface IP sbr: Add rule for outbound interface when there is a single interface IP Jan 26, 2025
Comment thread plugins/meta/sbr/main.go Resolved
@neilcook

neilcook commented May 2, 2025

Copy link
Copy Markdown
Author

Any more thoughts on this PR?

@mlguerrero12

Copy link
Copy Markdown
Member

So, this is intended for packets originating from applications that are bound to a device. After that, a table is selected to continue with the regular routing process. Is that right?

I believe this should be a new parameter instead of applying with there is a single IP (no provided table ID case). It can take precedence over the IPs. Something like useOriginatingIf, when this is set to True by the users, then a rule is added using oif. No need to add rules for IPs (please correct me if I'm wrong here). And move all associated routes of the interface to the table.

Also, why not using the VRF plugin instead?

@neilcook

Copy link
Copy Markdown
Author

So, this is intended for packets originating from applications that are bound to a device. After that, a table is selected to continue with the regular routing process. Is that right?

Yes. Because binding to IP addresses is problematic, as they are dynamically assigned.

I believe this should be a new parameter instead of applying with there is a single IP (no provided table ID case). It can take precedence over the IPs. Something like useOriginatingIf, when this is set to True by the users, then a rule is added using oif. No need to add rules for IPs (please correct me if I'm wrong here). And move all associated routes of the interface to the table.

Yes, probably setting this via a parameter is better.

Also, why not using the VRF plugin instead?

Doesn't that require the application to be VRF aware?

@mlguerrero12

Copy link
Copy Markdown
Member

as far as I know, for vrf, you only need to use SO_BINDTODEVICE which I guess you are already using

@neilcook

Copy link
Copy Markdown
Author

as far as I know, for vrf, you only need to use SO_BINDTODEVICE which I guess you are already using

Yes, we're already using SO_BINDTODEVICE. How does the vrf plugin help here?

…on outbound interface

- UseOriginatingIf adds fallback rules for local sockets bound to the interface.
- With automatic allocation, each family uses the SBR table for its first address.
- With an explicit table, the caller provides the routes for every configured family.

Signed-off-by: Neil Cook <neil.cook@noware.co.uk>
Signed-off-by: Neil Cook <neil.cook@noware.co.uk>
Signed-off-by: Neil Cook <neil.cook@noware.co.uk>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants