Skip to content

Commit 85071cf

Browse files
committed
sys-apps/ignition: support IPv4 and IPv6
Signed-off-by: Mathieu Tortuyaux <[email protected]>
1 parent e484e92 commit 85071cf

File tree

3 files changed

+201
-0
lines changed

3 files changed

+201
-0
lines changed
Lines changed: 200 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,200 @@
1+
From 05a301e9aea81b9f8ed54bc81d42e56774647305 Mon Sep 17 00:00:00 2001
2+
From: Mathieu Tortuyaux <[email protected]>
3+
Date: Fri, 11 Apr 2025 16:04:21 +0200
4+
Subject: [PATCH 1/3] scaleway: support IPv4 and IPv6 for metadata endpoint
5+
6+
Signed-off-by: Mathieu Tortuyaux <[email protected]>
7+
---
8+
internal/providers/scaleway/scaleway.go | 28 ++++++++++++++++---------
9+
1 file changed, 18 insertions(+), 10 deletions(-)
10+
11+
diff --git a/internal/providers/scaleway/scaleway.go b/internal/providers/scaleway/scaleway.go
12+
index d25b9aab..d987dc50 100644
13+
--- a/internal/providers/scaleway/scaleway.go
14+
+++ b/internal/providers/scaleway/scaleway.go
15+
@@ -24,28 +24,36 @@ import (
16+
17+
"github.com/flatcar/ignition/v2/config/v3_6_experimental/types"
18+
"github.com/flatcar/ignition/v2/internal/platform"
19+
- "github.com/flatcar/ignition/v2/internal/providers/util"
20+
"github.com/flatcar/ignition/v2/internal/resource"
21+
22+
"github.com/coreos/vcontext/report"
23+
)
24+
25+
var (
26+
- userdataURL = url.URL{
27+
- Scheme: "http",
28+
- Host: "169.254.42.42",
29+
- Path: "user_data/cloud-init",
30+
+ userdataURLs = map[string]url.URL{
31+
+ resource.IPv4: {
32+
+ Scheme: "http",
33+
+ Host: "169.254.42.42",
34+
+ Path: "user_data/cloud-init",
35+
+ },
36+
+ resource.IPv6: {
37+
+ Scheme: "http",
38+
+ Host: "[fd00:42::42]",
39+
+ Path: "user_data/cloud-init",
40+
+ },
41+
}
42+
)
43+
44+
func init() {
45+
platform.Register(platform.Provider{
46+
- Name: "scaleway",
47+
- Fetch: fetchConfig,
48+
+ Name: "scaleway",
49+
+ Fetch: func(f *resource.Fetcher) (types.Config, report.Report, error) {
50+
+ return resource.FetchConfigDualStack(f, userdataURLs, fetchConfig)
51+
+ },
52+
})
53+
}
54+
55+
-func fetchConfig(f *resource.Fetcher) (types.Config, report.Report, error) {
56+
+func fetchConfig(f *resource.Fetcher, userdataURL url.URL) ([]byte, error) {
57+
// For security reason, Scaleway requires to query user data with a source port below 1024.
58+
port := func() int {
59+
return rand.Intn(1022) + 1
60+
@@ -55,8 +63,8 @@ func fetchConfig(f *resource.Fetcher) (types.Config, report.Report, error) {
61+
LocalPort: port,
62+
})
63+
if err != nil && err != resource.ErrNotFound {
64+
- return types.Config{}, report.Report{}, err
65+
+ return nil, err
66+
}
67+
68+
- return util.ParseConfig(f.Logger, data)
69+
+ return data, nil
70+
}
71+
--
72+
2.45.3
73+
74+
From 61f109ac80a18f82705d8d45351bf0da284af778 Mon Sep 17 00:00:00 2001
75+
From: Mathieu Tortuyaux <[email protected]>
76+
Date: Fri, 11 Apr 2025 16:05:31 +0200
77+
Subject: [PATCH 2/3] url: support both IPv4 and IPv6
78+
79+
This defines a wrapper that will try in paralell both IPv4 and IPv6 when
80+
the provider declares those two IPs.
81+
82+
Signed-off-by: Mathieu Tortuyaux <[email protected]>
83+
---
84+
internal/resource/url.go | 42 ++++++++++++++++++++++++++++++++++++++++
85+
1 file changed, 42 insertions(+)
86+
87+
diff --git a/internal/resource/url.go b/internal/resource/url.go
88+
index 4d7a895d..c6c01927 100644
89+
--- a/internal/resource/url.go
90+
+++ b/internal/resource/url.go
91+
@@ -36,9 +36,13 @@ import (
92+
configErrors "github.com/flatcar/ignition/v2/config/shared/errors"
93+
"github.com/flatcar/ignition/v2/internal/log"
94+
"github.com/flatcar/ignition/v2/internal/util"
95+
+ "github.com/coreos/vcontext/report"
96+
"golang.org/x/oauth2/google"
97+
"google.golang.org/api/option"
98+
99+
+ "github.com/flatcar/ignition/v2/config/v3_6_experimental/types"
100+
+ providersUtil "github.com/flatcar/ignition/v2/internal/providers/util"
101+
+
102+
"github.com/Azure/azure-sdk-for-go/sdk/azidentity"
103+
"github.com/Azure/azure-sdk-for-go/sdk/storage/azblob"
104+
"github.com/aws/aws-sdk-go/aws"
105+
@@ -52,6 +56,11 @@ import (
106+
"github.com/vincent-petithory/dataurl"
107+
)
108+
109+
+const (
110+
+ IPv4 = "ipv4"
111+
+ IPv6 = "ipv6"
112+
+)
113+
+
114+
var (
115+
ErrSchemeUnsupported = errors.New("unsupported source scheme")
116+
ErrPathNotAbsolute = errors.New("path is not absolute")
117+
@@ -725,3 +734,36 @@ func (f *Fetcher) parseARN(arnURL string) (string, string, string, string, error
118+
key := strings.Join(urlSplit[1:], "/")
119+
return bucket, key, "", regionHint, nil
120+
}
121+
+
122+
+// FetchConfigDualStack is a function that takes care of fetching Ignition configuration on systems where IPv4 only, IPv6 only or both are available.
123+
+func FetchConfigDualStack(f *Fetcher, userdataURLs map[string]url.URL, fetchConfig func(*Fetcher, url.URL) ([]byte, error)) (types.Config, report.Report, error) {
124+
+ var (
125+
+ data []byte
126+
+ err error
127+
+ )
128+
+ success := make(chan string, 1)
129+
+
130+
+ fetch := func(ip url.URL) {
131+
+ data, err = fetchConfig(f, ip)
132+
+ if err != nil {
133+
+ f.Logger.Err("fetching configuration for %s: %v", ip, err)
134+
+ return
135+
+ }
136+
+
137+
+ success <- ip.String()
138+
+ }
139+
+
140+
+ if ipv4, ok := userdataURLs[IPv4]; ok {
141+
+ go fetch(ipv4)
142+
+ }
143+
+
144+
+ if ipv6, ok := userdataURLs[IPv6]; ok {
145+
+ go fetch(ipv6)
146+
+ }
147+
+
148+
+ // Wait for one success. (i.e wait for the first configuration to be available)
149+
+ ip := <-success
150+
+ f.Logger.Debug("got configuration from: %s", ip)
151+
+
152+
+ return providersUtil.ParseConfig(f.Logger, data)
153+
+}
154+
--
155+
2.45.3
156+
157+
From 7558c8ebf09633fc934affa7e80bd925f73d74a8 Mon Sep 17 00:00:00 2001
158+
From: Mathieu Tortuyaux <[email protected]>
159+
Date: Fri, 11 Apr 2025 16:14:33 +0200
160+
Subject: [PATCH 3/3] url: try local port on both IP stacks
161+
162+
Signed-off-by: Mathieu Tortuyaux <[email protected]>
163+
---
164+
internal/resource/url.go | 10 +++++++++-
165+
1 file changed, 9 insertions(+), 1 deletion(-)
166+
167+
diff --git a/internal/resource/url.go b/internal/resource/url.go
168+
index c6c01927..9a39c14f 100644
169+
--- a/internal/resource/url.go
170+
+++ b/internal/resource/url.go
171+
@@ -25,6 +25,7 @@ import (
172+
"io"
173+
"net"
174+
"net/http"
175+
+ "net/netip"
176+
"net/url"
177+
"os"
178+
"strings"
179+
@@ -339,10 +340,17 @@ func (f *Fetcher) fetchFromHTTP(u url.URL, dest io.Writer, opts FetchOptions) er
180+
p int
181+
)
182+
183+
+ host := u.Hostname()
184+
+ addr, _ := netip.ParseAddr(host)
185+
+ network := "tcp6"
186+
+ if addr.Is4() {
187+
+ network = "tcp4"
188+
+ }
189+
+
190+
// Assert that the port is not already used.
191+
for {
192+
p = opts.LocalPort()
193+
- l, err := net.Listen("tcp4", fmt.Sprintf(":%d", p))
194+
+ l, err := net.Listen(network, fmt.Sprintf(":%d", p))
195+
if err != nil && errors.Is(err, syscall.EADDRINUSE) {
196+
continue
197+
} else if err == nil {
198+
--
199+
2.45.3
200+

sdk_container/src/third_party/coreos-overlay/sys-apps/ignition/ignition-9999.ebuild

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ PATCHES=(
6060
"${FILESDIR}/0018-docs-Add-re-added-platforms-to-docs-to-pass-tests.patch"
6161
"${FILESDIR}/0019-usr-share-oem-oem.patch"
6262
"${FILESDIR}/0020-internal-exec-stages-mount-Mount-oem.patch"
63+
"${FILESDIR}/tormath1-ipv6.patch"
6364
)
6465

6566
src_compile() {

0 commit comments

Comments
 (0)