Fix macvlan gateway interface detection for names with dots or dashes (#13642)

The [[:alnum:]]* capture truncates interface names at the first character
that is not a letter or digit: eth0.100 (VLAN) becomes eth0, br-9a93...
becomes br, bond0.200 becomes bond0. The result feeds
node_default_gateway_interface, which the macvlan MASQUERADE rules use as
the -o match (RedHat post-up/post-down and the Flatcar NAT service under
enable_nat_default_gateway), so pod traffic egressing the default gateway
loses NAT because the rule references a wrong or nonexistent interface.

Capture the whole whitespace-delimited token after ' dev ' instead. The
leading space also keeps the greedy match from latching onto names that
themselves end in 'dev' (e.g. lan-dev).
This commit is contained in:
longxiucai
2026-10-14 08:27:05 +00:00
committed by GitHub
parent cbc8d9abc0
commit 8a88284568
+1 -1
View File
@@ -11,7 +11,7 @@
- name: Macvlan | Retrieve default gateway network interface - name: Macvlan | Retrieve default gateway network interface
become: false become: false
raw: ip -4 route list 0/0 | sed 's/.*dev \([[:alnum:]]*\).*/\1/' raw: ip -4 route list 0/0 | sed -E 's/.* dev ([^ ]+).*/\1/'
changed_when: false changed_when: false
register: node_default_gateway_interface_cmd register: node_default_gateway_interface_cmd