Skip to content
Snippets Groups Projects
Unverified Commit ae516792 authored by takt's avatar takt Committed by GitHub
Browse files

Merge pull request #17 from hikhvar/fix/correct-ipv4-conversion

Fix/correct ipv4 conversion
parents 64b98409 10049697
No related branches found
No related tags found
No related merge requests found
...@@ -4,5 +4,6 @@ import "net" ...@@ -4,5 +4,6 @@ import "net"
// IPv4ToUint32 converts an `net.IP` to an uint32 interpretation // IPv4ToUint32 converts an `net.IP` to an uint32 interpretation
func IPv4ToUint32(ip net.IP) uint32 { 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 return uint32(ip[3]) + uint32(ip[2])<<8 + uint32(ip[1])<<16 + uint32(ip[0])<<24
} }
...@@ -3,6 +3,8 @@ package net ...@@ -3,6 +3,8 @@ package net
import ( import (
"testing" "testing"
"net"
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
) )
...@@ -23,6 +25,10 @@ func TestIPv4ToUint32(t *testing.T) { ...@@ -23,6 +25,10 @@ func TestIPv4ToUint32(t *testing.T) {
input: []byte{172, 24, 5, 1}, input: []byte{172, 24, 5, 1},
expected: 2887255297, expected: 2887255297,
}, },
{
input: net.ParseIP("172.24.5.1"),
expected: 2887255297,
},
} }
for _, test := range tests { for _, test := range tests {
......
...@@ -63,6 +63,8 @@ func (c *ClientManager) RegisterWithOptions(client RouteTableClient, opt ClientO ...@@ -63,6 +63,8 @@ func (c *ClientManager) RegisterWithOptions(client RouteTableClient, opt ClientO
// Unregister unregisters a client // Unregister unregisters a client
func (c *ClientManager) Unregister(client RouteTableClient) { func (c *ClientManager) Unregister(client RouteTableClient) {
c.mu.Lock()
defer c.mu.Unlock()
if _, ok := c.clients[client]; !ok { if _, ok := c.clients[client]; !ok {
return return
} }
...@@ -71,6 +73,8 @@ func (c *ClientManager) Unregister(client RouteTableClient) { ...@@ -71,6 +73,8 @@ func (c *ClientManager) Unregister(client RouteTableClient) {
// Clients returns a list of registered clients // Clients returns a list of registered clients
func (c *ClientManager) Clients() []RouteTableClient { func (c *ClientManager) Clients() []RouteTableClient {
c.mu.RLock()
defer c.mu.RUnlock()
ret := make([]RouteTableClient, 0) ret := make([]RouteTableClient, 0)
for rtc := range c.clients { for rtc := range c.clients {
ret = append(ret, rtc) ret = append(ret, rtc)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment