-
Notifications
You must be signed in to change notification settings - Fork 532
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
added autodetect of interfaces on private networks #893
Changes from 1 commit
48bc7ae
6a616ce
5c24428
d290d3a
32843e5
f301cab
e4ac570
7f776cc
af3a3b5
d96dac8
91f04d2
469934e
cad5243
34cae90
37e3816
f2ca89c
f88f9d6
7f0f268
7edb67d
f779130
b9dc577
f5781b4
7a4c334
b2ee51c
9ab387c
3ad728f
559f96d
f5633f2
f2bae6a
208782a
291bbe4
d0f904d
e787f47
6047d69
ebd461e
d6cc594
25ad3d0
76da7c6
e81c339
64713e0
3142120
a5c5158
679e14e
6166796
bc66a33
ef835a9
e4f0e09
775097d
ddb0e68
0fde0fa
1788e41
0cdd91f
f2109c3
3e4e533
0afeb6e
599c6d4
30d8407
844dc6d
1dd5a34
73b94ed
78275bf
f672f96
f99dcea
56dccbf
3da17b6
d47c230
bee4cb0
744b75d
2a8e3ab
0210659
6c7863a
d867e99
1135cb1
0574908
f86fc35
8cc7468
b8f67f4
80d849a
431065b
af1f249
f4a866e
91b235e
95a9a06
1f504dc
0080ea8
491a2fc
b1082f3
e4a4cef
0e2ef9b
bc4b8e9
37cc738
8e2b2e5
64a1235
3ae9013
ec0b1c3
2bd377e
f6369f8
e020e13
952e248
8665be9
8b7f340
a9dcbb2
27492b3
5bcdd60
3302af4
d9428fc
75693e2
bb843d6
cf83787
84cb23d
3a215e1
b4cf398
4632837
3df790a
c52aa99
c686755
01ae728
077a992
fe7fe60
2db99f2
43262b8
54f3e84
50ceeb7
96c0775
d17bba6
a6504ef
5a06393
79f1790
a4045ec
6dd6ad3
08682ed
58ff956
36fa2b0
408807f
ed81b39
7b5818a
3cf36f7
5a0c400
24faedb
e9d95d2
cf75315
fedd698
859fbb3
9251587
790c8a9
f6b7b47
882422d
863246f
cfa5550
171d57b
509ccbf
a0caafa
dda976e
0fe836a
76f5b0b
7dc2ead
7e0a4c4
ee2fb84
161d711
da34538
53255cd
4288152
d8816b4
038efd1
6395ee0
3cb865a
a380d30
c4716a6
488bb65
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -65,3 +65,36 @@ func filterIPs(addrs []net.Addr) string { | |
} | ||
return ipAddr | ||
} | ||
|
||
// Parses network interfaces and returns those having an address conformant to RFC1918 | ||
func PrivateNetworkInterfaces() []string { | ||
var privInts []string | ||
ints, err := net.Interfaces() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would move the logic to a private function that takes the list of interfaces in input, so that you can test it. My comment is about adding unit tests to this function :) |
||
if err != nil { | ||
level.Warn(util_log.Logger).Log("msg", "error getting interfaces", "err", err) | ||
} | ||
for _, i := range ints { | ||
fmt.Println(i.Index, i.Name) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This should be removed. |
||
addrs, err := i.Addrs() | ||
if err != nil { | ||
level.Warn(util_log.Logger).Log("msg", "error getting addresses", "inf", i.Name, "err", err) | ||
} | ||
for _, a := range addrs { | ||
s := a.String() | ||
ip, _, err := net.ParseCIDR(s) | ||
if err != nil { | ||
level.Warn(util_log.Logger).Log("msg", "error getting ip address", "inf", i.Name, "addr", s, "err", err) | ||
} | ||
if ip.IsPrivate() { | ||
privInts = append(privInts, i.Name) | ||
break | ||
} | ||
} | ||
} | ||
if len(privInts) == 0 { | ||
level.Warn(util_log.Logger).Log("msg", "couldn't find any interfaces on private networks, defaulting to [eth0 en0]") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm a bit dubious about this log because:
|
||
return []string{"eth0", "en0"} | ||
} | ||
level.Info(util_log.Logger).Log("msg", "found interfaces on private networks:", "["+strings.Join(privInts, ", ")+"]") | ||
return privInts | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How do you feel about putting this into dskit so other project can reuse the function?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I started a PR like this a while ago, but forgot about it: grafana/dskit#100