mirror of
https://github.com/akvorado/akvorado.git
synced 2025-12-12 06:24:10 +01:00
helpers/subnetmap: fix bug when using IPv6-mapped IPv4 addresses
Go will display them as IPv4. We want everything to be IPv6.
This commit is contained in:
@@ -70,6 +70,8 @@ func SubnetMapUnmarshallerHook[V any]() mapstructure.DecodeHookFunc {
|
|||||||
}
|
}
|
||||||
if bits == 32 {
|
if bits == 32 {
|
||||||
key = fmt.Sprintf("::ffff:%s/%d", ipNet.IP.String(), ones+96)
|
key = fmt.Sprintf("::ffff:%s/%d", ipNet.IP.String(), ones+96)
|
||||||
|
} else if ipNet.IP.To4() != nil {
|
||||||
|
key = fmt.Sprintf("::ffff:%s/%d", ipNet.IP.String(), ones)
|
||||||
} else {
|
} else {
|
||||||
key = ipNet.String()
|
key = ipNet.String()
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -62,6 +62,16 @@ func TestSubnetMapUnmarshalHook(t *testing.T) {
|
|||||||
"2001:db8:1::2": "customer2",
|
"2001:db8:1::2": "customer2",
|
||||||
"2001:db8:2::2": "",
|
"2001:db8:2::2": "",
|
||||||
},
|
},
|
||||||
|
}, {
|
||||||
|
Description: "IPv6-mapped-IPv4 subnet",
|
||||||
|
Input: gin.H{"::ffff:203.0.113.0/120": "customer2"},
|
||||||
|
Tests: map[string]string{
|
||||||
|
"::ffff:203.0.113.10": "customer2",
|
||||||
|
"203.0.113.10": "customer2",
|
||||||
|
"::ffff:203.0.112.10": "",
|
||||||
|
"203.0.112.10": "",
|
||||||
|
},
|
||||||
|
YAML: gin.H{"203.0.113.0/24": "customer2"},
|
||||||
}, {
|
}, {
|
||||||
Description: "IPv6 IP",
|
Description: "IPv6 IP",
|
||||||
Input: gin.H{"2001:db8:1::1": "customer2"},
|
Input: gin.H{"2001:db8:1::1": "customer2"},
|
||||||
|
|||||||
Reference in New Issue
Block a user