Skip to content

Commit

Permalink
Remove netlink package dependency from the ip package,
Browse files Browse the repository at this point in the history
so that common code no longer needs to be Linux specific.

Signed-off-by: Nate Sweet <nathanjsweet@pm.me>
  • Loading branch information
nathanjsweet authored and joestringer committed Apr 8, 2020
1 parent d8fee7c commit dcbdb1e
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 16 deletions.
2 changes: 1 addition & 1 deletion pkg/datapath/linux/node_addressing.go
Expand Up @@ -30,7 +30,7 @@ import (
// code should really move into this package.

func listLocalAddresses(family int) ([]net.IP, error) {
ipsToExclude := ip.GetExcludedIPs()
ipsToExclude := node.GetExcludedIPs()
addrs, err := netlink.AddrList(nil, family)
if err != nil {
return nil, err
Expand Down
9 changes: 0 additions & 9 deletions pkg/ip/ip.go
Expand Up @@ -755,11 +755,8 @@ func initPrivatePrefixes() {
}
}

var excludedIPs []net.IP

func init() {
initPrivatePrefixes()
initExcludedIPs()
}

// IsExcluded returns whether a given IP is must be excluded
Expand All @@ -784,12 +781,6 @@ func IsPublicAddr(ip net.IP) bool {
return true
}

// GetExcludedIPs returns a list of IPs from netdevices that Cilium
// needs to exclude to operate
func GetExcludedIPs() []net.IP {
return excludedIPs
}

// GetCIDRPrefixesFromIPs returns all of the ips as a slice of *net.IPNet.
func GetCIDRPrefixesFromIPs(ips []net.IP) []*net.IPNet {
if len(ips) == 0 {
Expand Down
14 changes: 11 additions & 3 deletions pkg/ip/ip_darwin.go → pkg/node/ip.go
@@ -1,4 +1,4 @@
// Copyright 2017-2019 Authors of Cilium
// Copyright 2017-2020 Authors of Cilium
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand All @@ -12,6 +12,14 @@
// See the License for the specific language governing permissions and
// limitations under the License.

package ip
package node

func initExcludedIPs() {}
import "net"

var excludedIPs []net.IP

// GetExcludedIPs returns a list of IPs from netdevices that Cilium
// needs to exclude to operate
func GetExcludedIPs() []net.IP {
return excludedIPs
}
6 changes: 5 additions & 1 deletion pkg/ip/ip_linux.go → pkg/node/ip_linux.go
Expand Up @@ -12,14 +12,18 @@
// See the License for the specific language governing permissions and
// limitations under the License.

package ip
package node

import (
"strings"

"github.com/vishvananda/netlink"
)

func init() {
initExcludedIPs()
}

func initExcludedIPs() {
// We exclude below bad device prefixes from address selection ...
prefixes := []string{
Expand Down
4 changes: 2 additions & 2 deletions pkg/node/node_address_linux.go
@@ -1,4 +1,4 @@
// Copyright 2016-2018 Authors of Cilium
// Copyright 2016-2020 Authors of Cilium
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -36,7 +36,7 @@ func firstGlobalAddr(intf string, preferredIP net.IP, family int) (net.IP, error
var ipLen int
var err error

ipsToExclude := ip.GetExcludedIPs()
ipsToExclude := GetExcludedIPs()
linkScopeMax := unix.RT_SCOPE_UNIVERSE
if family == netlink.FAMILY_V4 {
ipLen = 4
Expand Down

0 comments on commit dcbdb1e

Please sign in to comment.