From d774220311b2d44c770e7431ec663c8875488a1e Mon Sep 17 00:00:00 2001 From: neingeist Date: Fri, 24 Jun 2022 00:35:08 +0200 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20Fix=20restricting=20address=20fa?= =?UTF-8?q?mily=20when=20watching=20for=20changes?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- addr.go | 8 ++++++++ 1 file changed, 8 insertions(+) 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,