Skip to content

F #-: VRouter: optional SNAT to the VIP or to a given address in NAT4 - #407

Closed
netaviator wants to merge 2 commits into
OpenNebula:masterfrom
netaviator:pr/nat4-snat-to-vip
Closed

netaviator wants to merge 2 commits into
OpenNebula:masterfrom
netaviator:pr/nat4-snat-to-vip

Conversation

@netaviator

Copy link
Copy Markdown

NAT4 masquerades the traffic leaving through the selected NICs, so the outside address is the primary address of the NIC of the node that happens to forward it, and it changes with a failover. Add two opt-in ways to get a stable source address; with neither set the rules are unchanged.

  • ONEAPP_VNF_NAT4_SNAT_ADDRESS: SNAT every outgoing NIC to this address. For example a public address that is statically routed to the VIP: the address does not have to be configured on the router for the NAT to work (the replies come back through the route and are translated back), but to reach it from outside it can be added as an extra VIP (ONEAPP_VROUTER_ETH_VIP=/32), which puts it on the VRRP master only.
  • ONEAPP_VNF_NAT4_SNAT_TO_VIP: for a NIC that has a VIP, SNAT to the first IPv4 VIP of the NIC in index order (the OpenNebula floating IP counts). IPv6 VIPs are ignored.

The address wins over the VIP. The address ends up in a shell command, so anything but a plain dotted quad is rejected (a prefix length and surrounding spaces are stripped): the outgoing NICs then keep MASQUERADE, also when SNAT to the VIP is enabled, and the problem is logged with the attribute or the NIC (at most 40 characters of the value are logged). A NIC without a VIP keeps MASQUERADE.

Checked with unit tests, and on a kernel with three network namespaces (client, router, server): with SNAT to an address the server sees the client as that address, with and without the address configured on the router, and the replies are translated back; with MASQUERADE it sees the NIC address of the router.

NAT4 masquerades the traffic leaving through the selected NICs, so the
outside address is the primary address of the NIC of the node that
happens to forward it, and it changes with a failover. Add two opt-in
ways to get a stable source address; with neither set the rules are
unchanged.

* ONEAPP_VNF_NAT4_SNAT_ADDRESS: SNAT every outgoing NIC to this address.
  For example a public address that is statically routed to the VIP: the
  address does not have to be configured on the router for the NAT to
  work (the replies come back through the route and are translated back),
  but to reach it from outside it can be added as an extra VIP
  (ONEAPP_VROUTER_ETH<n>_VIP<m>=<address>/32), which puts it on the VRRP
  master only.
* ONEAPP_VNF_NAT4_SNAT_TO_VIP: for a NIC that has a VIP, SNAT to the first
  IPv4 VIP of the NIC in index order (the OpenNebula floating IP counts).
  IPv6 VIPs are ignored.

The address wins over the VIP. The address ends up in a shell command, so
anything but a plain dotted quad is rejected (a prefix length and
surrounding spaces are stripped): the outgoing NICs then keep MASQUERADE,
also when SNAT to the VIP is enabled, and the problem is logged with the
attribute or the NIC (at most 40 characters of the value are logged). A
NIC without a VIP keeps MASQUERADE.

Checked with unit tests, and on a kernel with three network namespaces
(client, router, server): with SNAT to an address the server sees the
client as that address, with and without the address configured on the
router, and the replies are translated back; with MASQUERADE it sees the
NIC address of the router.

Signed-off-by: Jan Gilla <jgilla@level66.network>
SNAT rewrote the VRRP advertisements the router sends itself to the NAT address, so both nodes appeared with the same source and kept the VIPs.
@netaviator netaviator closed this by deleting the head repository Oct 18, 2026
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.

1 participant