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>
| ... | ... |
@@ -6,8 +6,8 @@ |
| 6 | 6 |
package netutils |
| 7 | 7 |
|
| 8 | 8 |
import ( |
| 9 |
- "fmt" |
|
| 10 | 9 |
"net" |
| 10 |
+ "os" |
|
| 11 | 11 |
"strings" |
| 12 | 12 |
|
| 13 | 13 |
"github.com/docker/docker/libnetwork/ipamutils" |
| ... | ... |
@@ -18,9 +18,7 @@ import ( |
| 18 | 18 |
"github.com/vishvananda/netlink" |
| 19 | 19 |
) |
| 20 | 20 |
|
| 21 |
-var ( |
|
| 22 |
- networkGetRoutesFct func(netlink.Link, int) ([]netlink.Route, error) |
|
| 23 |
-) |
|
| 21 |
+var networkGetRoutesFct func(netlink.Link, int) ([]netlink.Route, error) |
|
| 24 | 22 |
|
| 25 | 23 |
// CheckRouteOverlaps checks whether the passed network overlaps with any existing routes |
| 26 | 24 |
func CheckRouteOverlaps(toCheck *net.IPNet) error {
|
| ... | ... |
@@ -110,8 +108,8 @@ func FindAvailableNetwork(list []*net.IPNet) (*net.IPNet, error) {
|
| 110 | 110 |
// can't read /etc/resolv.conf. So instead we skip the append if resolvConf |
| 111 | 111 |
// is nil. It either doesn't exist, or we can't read it for some reason. |
| 112 | 112 |
var nameservers []string |
| 113 |
- if rc, err := resolvconf.Get(); err == nil {
|
|
| 114 |
- nameservers = resolvconf.GetNameserversAsCIDR(rc.Content) |
|
| 113 |
+ if rc, err := os.ReadFile(resolvconf.Path()); err == nil {
|
|
| 114 |
+ nameservers = resolvconf.GetNameserversAsCIDR(rc) |
|
| 115 | 115 |
} |
| 116 | 116 |
for _, nw := range list {
|
| 117 | 117 |
if err := CheckNameserverOverlaps(nameservers, nw); err == nil {
|
| ... | ... |
@@ -120,5 +118,5 @@ func FindAvailableNetwork(list []*net.IPNet) (*net.IPNet, error) {
|
| 120 | 120 |
} |
| 121 | 121 |
} |
| 122 | 122 |
} |
| 123 |
- return nil, fmt.Errorf("no available network")
|
|
| 123 |
+ return nil, errors.New("no available network")
|
|
| 124 | 124 |
} |
| ... | ... |
@@ -18,7 +18,7 @@ func ElectInterfaceAddresses(name string) ([]*net.IPNet, []*net.IPNet, error) {
|
| 18 | 18 |
|
| 19 | 19 |
// FindAvailableNetwork returns a network from the passed list which does not |
| 20 | 20 |
// overlap with existing interfaces in the system |
| 21 |
- |
|
| 21 |
+// |
|
| 22 | 22 |
// TODO : Use appropriate windows APIs to identify non-overlapping subnets |
| 23 | 23 |
func FindAvailableNetwork(list []*net.IPNet) (*net.IPNet, error) {
|
| 24 | 24 |
return nil, nil |