mirror of
https://github.com/moby/moby.git
synced 2026-01-11 18:51:37 +00:00
libnetwork/netutils: remove dead code
- GetIfaceAddr is unused since moby/libnetwork@e51ead59 (moby/libnetwork#670). - ValidateAlias and ParseAlias are unused since moby/moby@0645eb84 (moby/moby#42539). Signed-off-by: Albin Kerouanton <albinker@gmail.com>
This commit is contained in:
@@ -62,35 +62,6 @@ func NetworkRange(network *net.IPNet) (net.IP, net.IP) {
|
||||
return firstIP, lastIP
|
||||
}
|
||||
|
||||
// GetIfaceAddr returns the first IPv4 address and slice of IPv6 addresses for the specified network interface
|
||||
func GetIfaceAddr(name string) (net.Addr, []net.Addr, error) {
|
||||
iface, err := net.InterfaceByName(name)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
addrs, err := iface.Addrs()
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
var addrs4, addrs6 []net.Addr
|
||||
for _, addr := range addrs {
|
||||
ip := (addr.(*net.IPNet)).IP
|
||||
if ip4 := ip.To4(); ip4 != nil {
|
||||
addrs4 = append(addrs4, addr)
|
||||
} else if ip6 := ip.To16(); len(ip6) == net.IPv6len {
|
||||
addrs6 = append(addrs6, addr)
|
||||
}
|
||||
}
|
||||
switch {
|
||||
case len(addrs4) == 0:
|
||||
return nil, nil, fmt.Errorf("interface %v has no IPv4 addresses", name)
|
||||
case len(addrs4) > 1:
|
||||
fmt.Printf("Interface %v has more than 1 IPv4 address. Defaulting to using %v\n",
|
||||
name, (addrs4[0].(*net.IPNet)).IP)
|
||||
}
|
||||
return addrs4[0], addrs6, nil
|
||||
}
|
||||
|
||||
func genMAC(ip net.IP) net.HardwareAddr {
|
||||
hw := make(net.HardwareAddr, 6)
|
||||
// The first byte of the MAC address has to comply with these rules:
|
||||
@@ -173,26 +144,3 @@ func ReverseIP(IP string) string {
|
||||
|
||||
return strings.Join(reverseIP, ".")
|
||||
}
|
||||
|
||||
// ParseAlias parses and validates the specified string as an alias format (name:alias)
|
||||
func ParseAlias(val string) (string, string, error) {
|
||||
if val == "" {
|
||||
return "", "", errors.New("empty string specified for alias")
|
||||
}
|
||||
arr := strings.SplitN(val, ":", 3)
|
||||
if len(arr) > 2 {
|
||||
return "", "", errors.New("bad format for alias: " + val)
|
||||
}
|
||||
if len(arr) == 1 {
|
||||
return val, val, nil
|
||||
}
|
||||
return arr[0], arr[1], nil
|
||||
}
|
||||
|
||||
// ValidateAlias validates that the specified string has a valid alias format (containerName:alias).
|
||||
func ValidateAlias(val string) (string, error) {
|
||||
if _, _, err := ParseAlias(val); err != nil {
|
||||
return val, err
|
||||
}
|
||||
return val, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user