Merge pull request #6 from neingeist/fix/restrict-family
🐛 Fix restricting address family when watching for changes
This commit is contained in:
commit
d65f28d109
8
addr.go
8
addr.go
|
@ -7,12 +7,14 @@ import (
|
|||
"net"
|
||||
|
||||
"github.com/vishvananda/netlink"
|
||||
"github.com/vishvananda/netlink/nl"
|
||||
)
|
||||
|
||||
type AddrSet struct {
|
||||
linkAttrs netlink.LinkAttrs
|
||||
linkChan chan netlink.LinkUpdate
|
||||
addrChan chan netlink.AddrUpdate
|
||||
family Family
|
||||
|
||||
addrs map[string]net.IP
|
||||
}
|
||||
|
@ -37,6 +39,7 @@ func InterfaceAddrs(iface string, family Family) (*AddrSet, error) {
|
|||
return nil, fmt.Errorf("netlink.LinkByName %v: %v", iface, err)
|
||||
} else {
|
||||
addrs.linkAttrs = *link.Attrs()
|
||||
addrs.family = family
|
||||
}
|
||||
|
||||
// list
|
||||
|
@ -91,6 +94,11 @@ func (addrs *AddrSet) Read() error {
|
|||
continue
|
||||
}
|
||||
|
||||
addrUpdateFamily := Family(nl.GetIPFamily(addrUpdate.LinkAddress.IP))
|
||||
if addrs.family != netlink.FAMILY_ALL && addrUpdateFamily != addrs.family {
|
||||
continue
|
||||
}
|
||||
|
||||
// XXX: scope and other filters?
|
||||
addrs.updateAddr(netlink.Addr{
|
||||
IPNet: &addrUpdate.LinkAddress,
|
||||
|
|
Loading…
Reference in New Issue