mirror of
https://github.com/yggdrasil-network/yggdrasil-go.git
synced 2025-04-30 07:05:06 +03:00
Handle addresses
This commit is contained in:
parent
e59756224f
commit
872a6d18e8
1 changed files with 19 additions and 5 deletions
|
@ -7,6 +7,7 @@ import (
|
|||
"net"
|
||||
"regexp"
|
||||
"syscall"
|
||||
"time"
|
||||
|
||||
"github.com/vishvananda/netlink"
|
||||
"golang.org/x/sys/unix"
|
||||
|
@ -19,17 +20,30 @@ func (m *Multicast) _multicastStarted() {
|
|||
linkClose := make(chan struct{})
|
||||
addrClose := make(chan struct{})
|
||||
|
||||
errorCallback := func(err error) {
|
||||
fmt.Println("Netlink error:", err)
|
||||
}
|
||||
|
||||
linkSubscribeOptions := netlink.LinkSubscribeOptions{
|
||||
ListExisting: true,
|
||||
ListExisting: true,
|
||||
ErrorCallback: errorCallback,
|
||||
}
|
||||
|
||||
addrSubscribeOptions := netlink.AddrSubscribeOptions{
|
||||
ListExisting: true,
|
||||
ErrorCallback: errorCallback,
|
||||
}
|
||||
|
||||
if err := netlink.LinkSubscribeWithOptions(linkChanges, linkClose, linkSubscribeOptions); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
if err := netlink.AddrSubscribe(addrChanges, addrClose); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
go func() {
|
||||
time.Sleep(time.Second)
|
||||
if err := netlink.AddrSubscribeWithOptions(addrChanges, addrClose, addrSubscribeOptions); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}()
|
||||
|
||||
fmt.Println("Listening for netlink changes")
|
||||
|
||||
|
@ -91,7 +105,7 @@ func (m *Multicast) _multicastStarted() {
|
|||
case change := <-addrChanges:
|
||||
name, ok := indexToIntf[change.LinkIndex]
|
||||
if !ok {
|
||||
return
|
||||
break
|
||||
}
|
||||
add := true
|
||||
add = add && change.NewAddr
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue