summaryrefslogtreecommitdiffhomepage
path: root/table
diff options
context:
space:
mode:
authorFUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>2015-11-18 21:07:45 -0800
committerFUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>2015-11-18 21:07:45 -0800
commitf6897fd47f74abf4c33f003063d6cd201c6e4d05 (patch)
tree1c963c1cf74f6ee9def46d36a4035cdccd250241 /table
parente8bff5b3662713180518de6eb12b3c11bd0d7775 (diff)
rpki: fix IPv4-mapped addresss handling
Signed-off-by: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>
Diffstat (limited to 'table')
-rw-r--r--table/destination.go12
-rw-r--r--table/destination_test.go2
2 files changed, 3 insertions, 11 deletions
diff --git a/table/destination.go b/table/destination.go
index 9c7b4f91..c2794a6a 100644
--- a/table/destination.go
+++ b/table/destination.go
@@ -42,7 +42,7 @@ const (
BPR_ROUTER_ID = "Router ID"
)
-func toRadixkey(b []byte, max uint8) string {
+func IpToRadixkey(b []byte, max uint8) string {
var buffer bytes.Buffer
for i := 0; i < len(b) && i < int(max); i++ {
buffer.WriteString(fmt.Sprintf("%08b", b[i]))
@@ -50,18 +50,10 @@ func toRadixkey(b []byte, max uint8) string {
return buffer.String()[:max]
}
-func IpToRadixkey(prefix net.IP, prefixLen uint8) string {
- b := prefix.To4()
- if b == nil {
- b = prefix.To16()
- }
- return toRadixkey(b, prefixLen)
-}
-
func CidrToRadixkey(cidr string) string {
_, n, _ := net.ParseCIDR(cidr)
ones, _ := n.Mask.Size()
- return toRadixkey(n.IP, uint8(ones))
+ return IpToRadixkey(n.IP, uint8(ones))
}
type PeerInfo struct {
diff --git a/table/destination_test.go b/table/destination_test.go
index e8edf562..8624bc8d 100644
--- a/table/destination_test.go
+++ b/table/destination_test.go
@@ -194,6 +194,6 @@ func updateMsgD3() *bgp.BGPMessage {
func TestRadixkey(t *testing.T) {
assert.Equal(t, "000010100000001100100000", CidrToRadixkey("10.3.32.0/24"))
- assert.Equal(t, "000010100000001100100000", IpToRadixkey(net.ParseIP("10.3.32.0"), 24))
+ assert.Equal(t, "000010100000001100100000", IpToRadixkey(net.ParseIP("10.3.32.0").To4(), 24))
assert.Equal(t, "000010100000001100100000", IpToRadixkey(net.ParseIP("10.3.32.0").To4(), 24))
}