Skip to content

Commit fcdfeab

Browse files
Orzeliussmira
authored andcommitted
fix: incorrect route source for on-link routes
when processing on-link routes, the source address was incorrectly set to the first address of the interface. This caused issues when the interface had multiple addresses, as the source address may not have been valid for the route. The source address is now set to an empty string, which allows the kernel to automatically select the appropriate source address for the route. Signed-off-by: Orzelius <33936483+Orzelius@users.noreply.github.com> (cherry picked from commit 3400059)
1 parent a8f2a0a commit fcdfeab

5 files changed

Lines changed: 127 additions & 10 deletions

File tree

internal/app/machined/pkg/runtime/v1alpha1/platform/nocloud/metadata.go

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ type Ethernet struct {
101101
OnLink bool `yaml:"on-link,omitempty"`
102102
} `yaml:"routes,omitempty"`
103103
RoutingPolicy []struct { // TODO
104-
From string `yaml:"froom,omitempty"`
104+
From string `yaml:"from,omitempty"`
105105
Table uint32 `yaml:"table,omitempty"`
106106
} `yaml:"routing-policy,omitempty"`
107107
}
@@ -733,17 +733,10 @@ func applyNetworkConfigV2Ethernet(name string, eth Ethernet, networkConfig *runt
733733

734734
networkConfig.Routes = append(networkConfig.Routes, routeSpec)
735735

736-
if route.OnLink && gw.Is4() {
737-
// This assumes an interface with multiple routes will never have multiple statically set ips.
738-
ipPrefix, err := netip.ParsePrefix(eth.Address[0])
739-
if err != nil {
740-
return fmt.Errorf("failed to parse route source: %w", err)
741-
}
742-
736+
if route.OnLink {
743737
routeSpec := network.RouteSpecSpec{
744738
ConfigLayer: network.ConfigPlatform,
745739
Destination: netip.PrefixFrom(gw, gw.BitLen()),
746-
Source: ipPrefix.Addr(),
747740
OutLinkName: name,
748741
Scope: nethelpers.ScopeLink,
749742
Table: withDefault(nethelpers.RoutingTable(route.Table), nethelpers.TableMain),
@@ -753,6 +746,10 @@ func applyNetworkConfigV2Ethernet(name string, eth Ethernet, networkConfig *runt
753746
Priority: withDefault(route.Metric, network.DefaultRouteMetric),
754747
}
755748

749+
if gw.Is6() {
750+
routeSpec.Family = nethelpers.FamilyInet6
751+
}
752+
756753
networkConfig.Routes = append(networkConfig.Routes, routeSpec)
757754
}
758755
}

internal/app/machined/pkg/runtime/v1alpha1/platform/nocloud/nocloud_test.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,9 @@ var rawNetworkConfigV2CloudInit []byte
4040
//go:embed testdata/in-v2-serverscom.yaml
4141
var rawNetworkConfigV2Serverscom []byte
4242

43+
//go:embed testdata/in-v2-nocloud-ipv6-on-link.yaml
44+
var rawNetworkConfigV2NocloudIPv6OnLink []byte
45+
4346
//go:embed testdata/expected-v1.yaml
4447
var expectedNetworkConfigV1 string
4548

@@ -52,6 +55,9 @@ var expectedNetworkConfigV2 string
5255
//go:embed testdata/expected-v2-serverscom.yaml
5356
var expectedNetworkConfigV2Serverscom string
5457

58+
//go:embed testdata/expected-v2-nocloud-ipv6-on-link.yaml
59+
var expectedNetworkConfigV2NocloudIPv6OnLink string
60+
5561
func TestParseNetworkConfig(t *testing.T) {
5662
t.Parallel()
5763

@@ -89,6 +95,12 @@ func TestParseNetworkConfig(t *testing.T) {
8995
raw: rawNetworkConfigV2Serverscom,
9096
expected: expectedNetworkConfigV2Serverscom,
9197
},
98+
{
99+
name: "V2-nocloud-ipv6-on-link",
100+
raw: rawNetworkConfigV2NocloudIPv6OnLink,
101+
expected: expectedNetworkConfigV2NocloudIPv6OnLink,
102+
expectedNeedsRecocile: true,
103+
},
92104
} {
93105
t.Run(tt.name, func(t *testing.T) {
94106
t.Parallel()
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
addresses:
2+
- address: 2a0c:6ec0:b00:c:0:1::/96
3+
linkName: nic0
4+
family: inet6
5+
scope: global
6+
flags: permanent
7+
layer: platform
8+
- address: 10.0.0.0/32
9+
linkName: nic0
10+
family: inet4
11+
scope: global
12+
flags: permanent
13+
layer: platform
14+
links:
15+
- name: nic0
16+
logical: false
17+
up: true
18+
mtu: 0
19+
kind: ""
20+
type: netrom
21+
layer: platform
22+
routes:
23+
- family: inet4
24+
dst: ""
25+
src: ""
26+
gateway: 169.254.0.1
27+
outLinkName: nic0
28+
table: main
29+
priority: 1024
30+
scope: global
31+
type: unicast
32+
flags: ""
33+
protocol: static
34+
layer: platform
35+
- family: inet4
36+
dst: 169.254.0.1/32
37+
src: ""
38+
gateway: ""
39+
outLinkName: nic0
40+
table: main
41+
priority: 1024
42+
scope: link
43+
type: unicast
44+
flags: ""
45+
protocol: static
46+
layer: platform
47+
- family: inet6
48+
dst: ""
49+
src: ""
50+
gateway: fe80::1
51+
outLinkName: nic0
52+
table: main
53+
priority: 2048
54+
scope: global
55+
type: unicast
56+
flags: ""
57+
protocol: static
58+
layer: platform
59+
- family: inet6
60+
dst: fe80::1/128
61+
src: ""
62+
gateway: ""
63+
outLinkName: nic0
64+
table: main
65+
priority: 1024
66+
scope: link
67+
type: unicast
68+
flags: ""
69+
protocol: static
70+
layer: platform
71+
hostnames:
72+
- hostname: talos
73+
domainname: fqdn
74+
layer: platform
75+
resolvers:
76+
- dnsServers:
77+
- 1.1.1.1
78+
- 2606:4700:4700::1111
79+
layer: platform
80+
timeServers: []
81+
operators: []
82+
externalIPs: []
83+
metadata:
84+
platform: nocloud
85+
hostname: talos.fqdn
86+
instanceId: "0"
87+
internalDNS: talos.fqdn

internal/app/machined/pkg/runtime/v1alpha1/platform/nocloud/testdata/expected-v2.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ routes:
137137
layer: platform
138138
- family: inet4
139139
dst: 192.168.14.1/32
140-
src: 10.22.14.2
140+
src: ""
141141
gateway: ""
142142
outLinkName: eth1
143143
table: main
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
version: 2
2+
ethernets:
3+
nic0:
4+
match:
5+
macaddress: "02:xx:xx:xx:xx:xx"
6+
dhcp4: false
7+
dhcp6: false
8+
addresses:
9+
- 2a0c:6ec0:b00:c:0:1::/96
10+
- 10.0.0.0/32
11+
routes:
12+
- to: 0.0.0.0/0
13+
via: 169.254.0.1
14+
on-link: true
15+
- to: ::/0
16+
via: fe80::1
17+
on-link: true
18+
nameservers:
19+
addresses:
20+
- 1.1.1.1
21+
- 2606:4700:4700::1111

0 commit comments

Comments
 (0)