/
ip_linux.go
52 lines (47 loc) · 1.07 KB
/
ip_linux.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
// SPDX-License-Identifier: Apache-2.0
// Copyright Authors of Cilium
package node
import (
"strings"
"github.com/vishvananda/netlink"
)
func init() {
initExcludedIPs()
}
func initExcludedIPs() {
// We exclude below bad device prefixes from address selection ...
prefixes := []string{
"docker",
}
links, err := netlink.LinkList()
if err != nil {
return
}
for _, l := range links {
// ... also all down devices since they won't be reachable.
//
// We need to check for both "up" and "unknown" state, as some
// drivers may not implement operstate handling, and just report
// their state as unknown even though they are operational.
if l.Attrs().OperState == netlink.OperUp ||
l.Attrs().OperState == netlink.OperUnknown {
skip := true
for _, p := range prefixes {
if strings.HasPrefix(l.Attrs().Name, p) {
skip = false
break
}
}
if skip {
continue
}
}
addr, err := netlink.AddrList(l, netlink.FAMILY_ALL)
if err != nil {
continue
}
for _, a := range addr {
excludedIPs = append(excludedIPs, a.IP)
}
}
}