libnetwork/netutils: FindAvailableNetwork(): simplify reading of resolv.conf

We only need the content here, not the checksum, so simplifying the code by
just using os.ReadFile().

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This commit is contained in:
Sebastiaan van Stijn 2022-10-01 21:37:21 +02:00
parent 0cbe6524db
commit 0f0fce5dcc
No known key found for this signature in database
GPG key ID: 76698F39D527CE8C
2 changed files with 6 additions and 8 deletions

View file

@ -6,8 +6,8 @@
package netutils
import (
"fmt"
"net"
"os"
"strings"
"github.com/docker/docker/libnetwork/ipamutils"
@ -18,9 +18,7 @@ import (
"github.com/vishvananda/netlink"
)
var (
networkGetRoutesFct func(netlink.Link, int) ([]netlink.Route, error)
)
var networkGetRoutesFct func(netlink.Link, int) ([]netlink.Route, error)
// CheckRouteOverlaps checks whether the passed network overlaps with any existing routes
func CheckRouteOverlaps(toCheck *net.IPNet) error {
@ -110,8 +108,8 @@ func FindAvailableNetwork(list []*net.IPNet) (*net.IPNet, error) {
// can't read /etc/resolv.conf. So instead we skip the append if resolvConf
// is nil. It either doesn't exist, or we can't read it for some reason.
var nameservers []string
if rc, err := resolvconf.Get(); err == nil {
nameservers = resolvconf.GetNameserversAsCIDR(rc.Content)
if rc, err := os.ReadFile(resolvconf.Path()); err == nil {
nameservers = resolvconf.GetNameserversAsCIDR(rc)
}
for _, nw := range list {
if err := CheckNameserverOverlaps(nameservers, nw); err == nil {
@ -120,5 +118,5 @@ func FindAvailableNetwork(list []*net.IPNet) (*net.IPNet, error) {
}
}
}
return nil, fmt.Errorf("no available network")
return nil, errors.New("no available network")
}

View file

@ -18,7 +18,7 @@ func ElectInterfaceAddresses(name string) ([]*net.IPNet, []*net.IPNet, error) {
// FindAvailableNetwork returns a network from the passed list which does not
// overlap with existing interfaces in the system
//
// TODO : Use appropriate windows APIs to identify non-overlapping subnets
func FindAvailableNetwork(list []*net.IPNet) (*net.IPNet, error) {
return nil, nil