diff --git a/addr.go b/addr.go index 0b7e301..d4c277c 100644 --- a/addr.go +++ b/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,