Browse code

Modify GetHostIPNetworks() to also return host IPs

This will be used by network diagnostics utility.

Ravi Sankar Penta authored on 2016/08/30 04:59:10
Showing 2 changed files
... ...
@@ -104,7 +104,7 @@ func StartMaster(networkConfig osconfigapi.MasterNetworkConfig, osClient *osclie
104 104
 }
105 105
 
106 106
 func (master *OsdnMaster) validateNetworkConfig() error {
107
-	hostIPNets, err := netutils.GetHostIPNetworks([]string{TUN, LBR})
107
+	hostIPNets, _, err := netutils.GetHostIPNetworks([]string{TUN, LBR})
108 108
 	if err != nil {
109 109
 		return err
110 110
 	}
... ...
@@ -27,10 +27,10 @@ func GenerateDefaultGateway(sna *net.IPNet) net.IP {
27 27
 
28 28
 // Return Host IP Networks
29 29
 // Ignores provided interfaces and filters loopback and non IPv4 addrs.
30
-func GetHostIPNetworks(skipInterfaces []string) ([]*net.IPNet, error) {
30
+func GetHostIPNetworks(skipInterfaces []string) ([]*net.IPNet, []net.IP, error) {
31 31
 	hostInterfaces, err := net.Interfaces()
32 32
 	if err != nil {
33
-		return nil, err
33
+		return nil, nil, err
34 34
 	}
35 35
 
36 36
 	skipInterfaceMap := make(map[string]bool)
... ...
@@ -40,6 +40,7 @@ func GetHostIPNetworks(skipInterfaces []string) ([]*net.IPNet, error) {
40 40
 
41 41
 	errList := []error{}
42 42
 	var hostIPNets []*net.IPNet
43
+	var hostIPs []net.IP
43 44
 	for _, iface := range hostInterfaces {
44 45
 		if skipInterfaceMap[iface.Name] {
45 46
 			continue
... ...
@@ -60,10 +61,11 @@ func GetHostIPNetworks(skipInterfaces []string) ([]*net.IPNet, error) {
60 60
 			// Skip loopback and non IPv4 addrs
61 61
 			if !ip.IsLoopback() && ip.To4() != nil {
62 62
 				hostIPNets = append(hostIPNets, ipNet)
63
+				hostIPs = append(hostIPs, ip)
63 64
 			}
64 65
 		}
65 66
 	}
66
-	return hostIPNets, kerrors.NewAggregate(errList)
67
+	return hostIPNets, hostIPs, kerrors.NewAggregate(errList)
67 68
 }
68 69
 
69 70
 func GetNodeIP(nodeName string) (string, error) {