mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
Merge pull request #42502 from thaJeztah/netutils_cleanup
This commit is contained in:
commit
bdd90773ef
2 changed files with 5 additions and 11 deletions
|
@ -19,8 +19,6 @@ var (
|
||||||
ErrNetworkOverlapsWithNameservers = errors.New("requested network overlaps with nameserver")
|
ErrNetworkOverlapsWithNameservers = errors.New("requested network overlaps with nameserver")
|
||||||
// ErrNetworkOverlaps preformatted error
|
// ErrNetworkOverlaps preformatted error
|
||||||
ErrNetworkOverlaps = errors.New("requested network overlaps with existing network")
|
ErrNetworkOverlaps = errors.New("requested network overlaps with existing network")
|
||||||
// ErrNoDefaultRoute preformatted error
|
|
||||||
ErrNoDefaultRoute = errors.New("no default route")
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// CheckNameserverOverlaps checks whether the passed network overlaps with any of the nameservers
|
// CheckNameserverOverlaps checks whether the passed network overlaps with any of the nameservers
|
||||||
|
@ -74,8 +72,7 @@ func GetIfaceAddr(name string) (net.Addr, []net.Addr, error) {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, nil, err
|
return nil, nil, err
|
||||||
}
|
}
|
||||||
var addrs4 []net.Addr
|
var addrs4, addrs6 []net.Addr
|
||||||
var addrs6 []net.Addr
|
|
||||||
for _, addr := range addrs {
|
for _, addr := range addrs {
|
||||||
ip := (addr.(*net.IPNet)).IP
|
ip := (addr.(*net.IPNet)).IP
|
||||||
if ip4 := ip.To4(); ip4 != nil {
|
if ip4 := ip.To4(); ip4 != nil {
|
||||||
|
@ -86,7 +83,7 @@ func GetIfaceAddr(name string) (net.Addr, []net.Addr, error) {
|
||||||
}
|
}
|
||||||
switch {
|
switch {
|
||||||
case len(addrs4) == 0:
|
case len(addrs4) == 0:
|
||||||
return nil, nil, fmt.Errorf("Interface %v has no IPv4 addresses", name)
|
return nil, nil, fmt.Errorf("interface %v has no IPv4 addresses", name)
|
||||||
case len(addrs4) > 1:
|
case len(addrs4) > 1:
|
||||||
fmt.Printf("Interface %v has more than 1 IPv4 address. Defaulting to using %v\n",
|
fmt.Printf("Interface %v has more than 1 IPv4 address. Defaulting to using %v\n",
|
||||||
name, (addrs4[0].(*net.IPNet)).IP)
|
name, (addrs4[0].(*net.IPNet)).IP)
|
||||||
|
@ -175,9 +172,9 @@ func ParseAlias(val string) (string, string, error) {
|
||||||
if val == "" {
|
if val == "" {
|
||||||
return "", "", errors.New("empty string specified for alias")
|
return "", "", errors.New("empty string specified for alias")
|
||||||
}
|
}
|
||||||
arr := strings.Split(val, ":")
|
arr := strings.SplitN(val, ":", 3)
|
||||||
if len(arr) > 2 {
|
if len(arr) > 2 {
|
||||||
return "", "", fmt.Errorf("bad format for alias: %s", val)
|
return "", "", errors.New("bad format for alias: " + val)
|
||||||
}
|
}
|
||||||
if len(arr) == 1 {
|
if len(arr) == 1 {
|
||||||
return val, val, nil
|
return val, val, nil
|
||||||
|
|
|
@ -69,10 +69,7 @@ func GenerateIfaceName(nlh *netlink.Handle, prefix string, len int) (string, err
|
||||||
// list the first IPv4 address which does not conflict with other
|
// list the first IPv4 address which does not conflict with other
|
||||||
// interfaces on the system.
|
// interfaces on the system.
|
||||||
func ElectInterfaceAddresses(name string) ([]*net.IPNet, []*net.IPNet, error) {
|
func ElectInterfaceAddresses(name string) ([]*net.IPNet, []*net.IPNet, error) {
|
||||||
var (
|
var v4Nets, v6Nets []*net.IPNet
|
||||||
v4Nets []*net.IPNet
|
|
||||||
v6Nets []*net.IPNet
|
|
||||||
)
|
|
||||||
|
|
||||||
defer osl.InitOSContext()()
|
defer osl.InitOSContext()()
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue