diff --git a/net/helper.go b/net/helper.go index 4f7319cddfd92ef975819b143e4c03488ec22fb8..4b82b2425fdc199023c675c904e92cd6bcce27b3 100644 --- a/net/helper.go +++ b/net/helper.go @@ -4,5 +4,6 @@ import "net" // IPv4ToUint32 converts an `net.IP` to an uint32 interpretation func IPv4ToUint32(ip net.IP) uint32 { + ip = ip.To4() return uint32(ip[3]) + uint32(ip[2])<<8 + uint32(ip[1])<<16 + uint32(ip[0])<<24 } diff --git a/net/helper_test.go b/net/helper_test.go index 7a267c3c9e26715bd9b14e3579265e2057aac8db..d5a038cbb6bd2683b50ba50c658fae797e46d39c 100644 --- a/net/helper_test.go +++ b/net/helper_test.go @@ -3,6 +3,8 @@ package net import ( "testing" + "net" + "github.com/stretchr/testify/assert" ) @@ -23,6 +25,10 @@ func TestIPv4ToUint32(t *testing.T) { input: []byte{172, 24, 5, 1}, expected: 2887255297, }, + { + input: net.ParseIP("172.24.5.1"), + expected: 2887255297, + }, } for _, test := range tests { diff --git a/routingtable/client_manager.go b/routingtable/client_manager.go index ee0275c3f2358ae96b4e297b17b540e29139bf90..20d848b2c090a4c311cb4a81fc8c1c4697cf5891 100644 --- a/routingtable/client_manager.go +++ b/routingtable/client_manager.go @@ -63,6 +63,8 @@ func (c *ClientManager) RegisterWithOptions(client RouteTableClient, opt ClientO // Unregister unregisters a client func (c *ClientManager) Unregister(client RouteTableClient) { + c.mu.Lock() + defer c.mu.Unlock() if _, ok := c.clients[client]; !ok { return } @@ -71,6 +73,8 @@ func (c *ClientManager) Unregister(client RouteTableClient) { // Clients returns a list of registered clients func (c *ClientManager) Clients() []RouteTableClient { + c.mu.RLock() + defer c.mu.RUnlock() ret := make([]RouteTableClient, 0) for rtc := range c.clients { ret = append(ret, rtc)