-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
NET-1780: Run Metrics And Iface Detection only on necessary IPs (#919)
* initialise metrics and iface on required ips only * add iface name to link local ipv6 addr * remove wait group * start on port 443 for new installs
- Loading branch information
1 parent
1467d86
commit 7c7bf33
Showing
11 changed files
with
161 additions
and
80 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package networking | ||
|
||
import ( | ||
"net" | ||
"strings" | ||
|
||
"github.com/gravitl/netclient/ncutils" | ||
"github.com/gravitl/netclient/stun" | ||
"github.com/gravitl/netmaker/models" | ||
) | ||
|
||
func GetInterfaces() ([]models.Iface, error) { | ||
ifaces, err := net.Interfaces() | ||
if err != nil { | ||
return nil, err | ||
} | ||
var data = []models.Iface{} | ||
var link models.Iface | ||
for _, iface := range ifaces { | ||
iface := iface | ||
if iface.Flags&net.FlagUp == 0 || // interface down | ||
iface.Flags&net.FlagLoopback != 0 || // loopback interface | ||
iface.Flags&net.FlagPointToPoint != 0 || // avoid direct connections | ||
iface.Name == ncutils.GetInterfaceName() || strings.Contains(iface.Name, "netmaker") || // avoid netmaker | ||
ncutils.IsBridgeNetwork(iface.Name) || // avoid bridges | ||
strings.Contains(iface.Name, "docker") { | ||
continue | ||
} | ||
addrs, err := iface.Addrs() | ||
if err != nil { | ||
return nil, err | ||
} | ||
for _, addr := range addrs { | ||
ip, cidr, err := net.ParseCIDR(addr.String()) | ||
if err != nil { | ||
continue | ||
} | ||
if ip.IsLoopback() || // no need to send loopbacks | ||
stun.IsPublicIP(ip) { // no need to send public IPs | ||
continue | ||
} | ||
link.Name = iface.Name | ||
link.Address = *cidr | ||
link.Address.IP = ip | ||
data = append(data, link) | ||
} | ||
} | ||
return data, nil | ||
} |