Repository navigation
Conversation
The VM-level GATEWAY_IFACE context variable (ETH0/eth0/0, or PCI0) was supported by addon-context-linux but silently dropped by the loc-10-network refactor (F OpenNebula#227). Without it, a VM with NICs on several vnets that define GATEWAY gets a default route per NIC. Re-implement it centrally in setup_iface_vars() so every netcfg backend honours it (IPv4 and IPv6), and in loc-10-network-pci for PCI NICs. Also trim whitespace from the gateways so the NIC GATEWAY=" " workaround (OpenNebula/one#2083) yields no gateway instead of an invalid "gateway " line. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: Peter Gehres <357174+pgehres@users.noreply.github.com>
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Description
Closes #329. Related: OpenNebula/one#2083.
A VM with NICs on more than one virtual network that defines
GATEWAYgets one default route per NIC. OpenNebula core copies each vnet'sGATEWAYintoETHx_GATEWAY(and overwrites a user-set emptyETHx_GATEWAY/NICGATEWAY=""), and everynetcfg-*backend installs a default route for each non-empty one. The result is two or more competing default routes, sometimes on different metrics, and asymmetric routing.The old
addon-context-linuxhandled this with the VM-level context variableGATEWAY_IFACE(ETH0or0). Only the selected interface got a gateway (OpenNebula/addon-context-linux#2). The variable was dropped without notice whenloc-10-networkwas refactored intoloc-10-network.d/(F #227, 2021). It is still in old docs and people still use it.This PR brings it back in one place,
setup_iface_vars()inloc-10-network.d/functions. Every backend (interfaces,netplan,networkd,nm,scripts,bsd) getsgateway/ip6_gatewayfrom there, so they all inherit the behaviour:GATEWAY_IFACEis set and doesn't match the interface being configured,gatewayandip6_gatewayare cleared for that interface. Accepted forms:ETH1,eth1,1(the1form keeps compatibility with the old implementation). Surrounding whitespace is ignored. The old version only affected IPv4. This one covers IPv6 too, which is what users expect from "the gateway interface".ETHnis the NIC withNIC_IDn, the same prefix asETHn_IP/ETHn_GATEWAY. It is never the guest's device name. one-context mapsETHnto the guest device by MAC (get_dev), and the check compares against the context name before the guest name is involved. SoGATEWAY_IFACE=ETH0picks NIC 0 whether the guest calls iteth0,ens3orenp1s0. Lowercaseeth0is accepted only for convenience and still meansETH0, not a kernel device calledeth0. After NIC hot-plug, NIC IDs can have gaps or be reused, soonevm showis the reference for whichETHnis which.gateway/ip6_gatewayare whitespace-trimmed. The long-standing workaround from Add option to remove gateway when adding additional nic one#2083 is to set NICGATEWAY=" "(a single space survives core asETHx_GATEWAY=" "). Before this PR it produced an invalidgatewaystanza in/etc/network/interfaces(and the same in the other backends). Now it means "no gateway".loc-10-network-pci(PCI passthrough NICs) honoursGATEWAY_IFACEtoo, matched by full name (e.g.PCI0). SettingGATEWAY_IFACE=PCI0therefore keeps the only default route on the PCI NIC, andGATEWAY_IFACE=ETH0stops PCI NICs from adding their own.Not affected:
ETHx_ROUTESstatic routes. They are read separately and still apply on every NIC.missing_onegate_proxy_route). It doesn't depend ongatewayand is still added on the first configured NIC.METHOD=dhcp/IP6_METHOD=auto|dhcpinterfaces. Their default route comes from DHCP/RA, not from context, soGATEWAY_IFACEdoesn't filter it. This matches the old behaviour.GATEWAY_IFACEunset. Nothing changes, apart from the whitespace trim.Docs:
GATEWAY_IFACEshould be added back to the context variables reference in OpenNebula/docs (Network Configuration section). I can open a separate PR there.Branches to which this PR applies
Testing
There is no automated harness for
context-linux. I tested it in two ways.1. Offline config generation. I sourced
functions+netcfg-{interfaces,netplan}with a stubbedget_interface_mac, using two NICs that both have IPv4 and IPv6 gateways (ETH1uses legacyGATEWAY6) and a link-localONEGATE_ENDPOINT:GATEWAY_IFACE=ETH1GATEWAY_IFACE=eth0GATEWAY_IFACE=1GATEWAY_IFACE=" Eth1 "GATEWAY_IFACE=PCI0ETH1_GATEWAY=" "gatewaylineOn
masterthe last case emitsgateway(gateway keyword followed by blanks) for eth1.shellcheckoutput for the touched files is unchanged.2. On a real VM. OpenNebula 7.2 with a Debian 13 guest and two NICs on vnets that both define
GATEWAY(eth0192.168.10.0/24, eth1192.168.9.0/24). I installed the releasedone-context_7.4.2-0.deb, whoseloc-10-network*files are byte-identical tomaster, then overlaid the two patched files. Each row is a full reboot afteronevm updateconf:NETCFG_TYPEinterfaces)GATEWAY_IFACE="ETH0"gatewaylines for both NICs.ifup eth1fails withRTNETLINK answers: File existsandnetworking.serviceis failed.netplan)GATEWAY_IFACE="ETH0"via 192.168.9.1 dev eth1is listed first.netplan)GATEWAY_IFACE="ETH0"dev eth0. Both linksroutable configured.netplan)GATEWAY_IFACE="ETH1"dev eth1.interfacesgatewaylines,ifup eth1fails.interfacesGATEWAY_IFACE="0"gatewayline (eth0).networking.serviceactive.interfacesGATEWAY=" "(→ETH1_GATEWAY=" ")ifup: /etc/network/interfaces:18: option with empty value→couldn't read interfaces file. No interface comes up, and the VM is unreachable.interfacesGATEWAY=" "gatewayline,networking.serviceactive, single default route via eth0.To reproduce: put
GATEWAY_IFACE = "ETH0"in a two-NIC VM'sCONTEXT, reboot, and checkip route show default,ip -6 route show defaultand the generated/etc/netplan/50-one-context.yamlor/etc/network/interfaces.New features
GATEWAY_IFACE(context NIC nameETHx/ethx/x, orPCIx; not the guest device name) limits context-provided default routes (IPv4 and IPv6) to the selected interface.🤖 Generated with Claude Code