From e8529b06769d1b3ef781882c4377cc652288ee07 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Do=C4=9Fan=20Can=20Bak=C4=B1r?= Date: Thu, 8 Oct 2026 18:18:34 +0300 Subject: [PATCH] linode: strip prefix length from instance ipv6 --- pkg/providers/linode/instances.go | 5 +++- pkg/providers/linode/instances_test.go | 35 ++++++++++++++++++++++++++ 2 files changed, 39 insertions(+), 1 deletion(-) create mode 100644 pkg/providers/linode/instances_test.go diff --git a/pkg/providers/linode/instances.go b/pkg/providers/linode/instances.go index 62c91d7a..b5ffa0e5 100644 --- a/pkg/providers/linode/instances.go +++ b/pkg/providers/linode/instances.go @@ -2,6 +2,7 @@ package linode import ( "context" + "strings" "github.com/linode/linodego" "github.com/projectdiscovery/cloudlist/pkg/schema" @@ -32,11 +33,13 @@ func (d *instanceProvider) GetResource(ctx context.Context) (*schema.Resources, for _, inst := range instances { // Assuming (and obseved the same) first IP in the list is the public IP ip4 := inst.IPv4[0].String() + // The API returns the IPv6 address with its prefix length (e.g. "/128"). + ip6, _, _ := strings.Cut(inst.IPv6, "/") list.Append(&schema.Resource{ Provider: providerName, PublicIPv4: ip4, - PublicIPv6: inst.IPv6, + PublicIPv6: ip6, ID: d.id, Public: ip4 != "", Service: d.name(), diff --git a/pkg/providers/linode/instances_test.go b/pkg/providers/linode/instances_test.go new file mode 100644 index 00000000..4d6b0cc2 --- /dev/null +++ b/pkg/providers/linode/instances_test.go @@ -0,0 +1,35 @@ +package linode + +import ( + "context" + "net/http" + "net/http/httptest" + "testing" + + "github.com/linode/linodego" + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" +) + +func TestInstanceIPv6(t *testing.T) { + server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + w.Header().Set("Content-Type", "application/json") + // The API returns the SLAAC address with its prefix length. + _, _ = w.Write([]byte(`{"data":[{"id":1,"label":"web","ipv4":["172.105.10.20"],"ipv6":"2600:3c03::f03c:91ff:fe24:3a2f/128"}],"page":1,"pages":1,"results":1}`)) + })) + t.Cleanup(server.Close) + + client := linodego.NewClient(server.Client()) + client.SetBaseURL(server.URL) + + resources, err := (&instanceProvider{id: "test", client: &client}).GetResource(context.Background()) + require.NoError(t, err) + + var ipv6 []string + for _, r := range resources.Items { + if r.PublicIPv6 != "" { + ipv6 = append(ipv6, r.PublicIPv6) + } + } + assert.Equal(t, []string{"2600:3c03::f03c:91ff:fe24:3a2f"}, ipv6) +}