Skip to content

Fix Static NAT/Port Forwarding when VM NIC is not the default#13200

Draft
sudo87 wants to merge 1 commit into
apache:mainfrom
shapeblue:fixStaticnatNondefault
Draft

Fix Static NAT/Port Forwarding when VM NIC is not the default#13200
sudo87 wants to merge 1 commit into
apache:mainfrom
shapeblue:fixStaticnatNondefault

Conversation

@sudo87
Copy link
Copy Markdown
Contributor

@sudo87 sudo87 commented May 20, 2026

Description

This PR intends to fix #8366

When CloudStack VR forwards traffic to a VM whose NIC is not the VM's default, the VM may reply via its default NIC (asymmetric routing). To force symmetric routing we SNAT the forwarded packet's source to the VR’s guest IP on the VM subnet so the VM replies on-link back to that VR interface. Also fix the port-forwarding SNAT to pick the correct VR guest IP for the VM's subnet

Types of changes

  • Breaking change (fix or feature that would cause existing functionality to change)
  • New feature (non-breaking change which adds functionality)
  • Bug fix (non-breaking change which fixes an issue)
  • Enhancement (improves an existing feature and functionality)
  • Cleanup (Code refactoring and cleanup, that may add test cases)
  • Build/CI
  • Test (unit or integration test code)

Feature/Enhancement Scale or Bug Severity

Feature/Enhancement Scale

  • Major
  • Minor

Bug Severity

  • BLOCKER
  • Critical
  • Major
  • Minor
  • Trivial

Screenshots (if appropriate):

How Has This Been Tested?

  1. Deploy instance vm1 on network (net_1)
  2. Create Isolated network (iso_2), attach NIC nic_2 from this to vm1
  3. Acquire public_ip from iso_2 and enable static nat to vm1
  4. Configure firewall rules e.g. enable icmp
  5. Ping via public_ip, expect response from instance vm1

How did you try to break this feature and the system with this change?

@codecov
Copy link
Copy Markdown

codecov Bot commented May 20, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 18.08%. Comparing base (3c1f031) to head (2a88f86).

Additional details and impacted files
@@            Coverage Diff            @@
##               main   #13200   +/-   ##
=========================================
  Coverage     18.08%   18.08%           
  Complexity    16718    16718           
=========================================
  Files          6037     6037           
  Lines        542611   542611           
  Branches      66433    66433           
=========================================
  Hits          98136    98136           
  Misses       433448   433448           
  Partials      11027    11027           
Flag Coverage Δ
uitests 3.51% <ø> (ø)
unittests 19.25% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

if internal_device and internal_vr_ip and internal_device != device:
self.fw.append(["nat", "front",
"-A POSTROUTING -o %s -d %s/32 -j SNAT --to-source %s" %
(internal_device, rule["internal_ip"], internal_vr_ip)])
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. this should apply to additional nics of guest VMs only. since there is no issue with first NIC of guest VMs, it is not needed.
  2. it would be better to provide an option for end users.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Static NAT and Port forwarding do not work if the VM NIC is not default

2 participants