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"
|
"net"
|
||||||
"regexp"
|
"regexp"
|
||||||
"syscall"
|
"syscall"
|
||||||
|
"time"
|
||||||
|
|
||||||
"github.com/vishvananda/netlink"
|
"github.com/vishvananda/netlink"
|
||||||
"golang.org/x/sys/unix"
|
"golang.org/x/sys/unix"
|
||||||
|
@ -19,17 +20,30 @@ func (m *Multicast) _multicastStarted() {
|
||||||
linkClose := make(chan struct{})
|
linkClose := make(chan struct{})
|
||||||
addrClose := make(chan struct{})
|
addrClose := make(chan struct{})
|
||||||
|
|
||||||
|
errorCallback := func(err error) {
|
||||||
|
fmt.Println("Netlink error:", err)
|
||||||
|
}
|
||||||
|
|
||||||
linkSubscribeOptions := netlink.LinkSubscribeOptions{
|
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 {
|
if err := netlink.LinkSubscribeWithOptions(linkChanges, linkClose, linkSubscribeOptions); err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := netlink.AddrSubscribe(addrChanges, addrClose); err != nil {
|
go func() {
|
||||||
|
time.Sleep(time.Second)
|
||||||
|
if err := netlink.AddrSubscribeWithOptions(addrChanges, addrClose, addrSubscribeOptions); err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
|
}()
|
||||||
|
|
||||||
fmt.Println("Listening for netlink changes")
|
fmt.Println("Listening for netlink changes")
|
||||||
|
|
||||||
|
@ -91,7 +105,7 @@ func (m *Multicast) _multicastStarted() {
|
||||||
case change := <-addrChanges:
|
case change := <-addrChanges:
|
||||||
name, ok := indexToIntf[change.LinkIndex]
|
name, ok := indexToIntf[change.LinkIndex]
|
||||||
if !ok {
|
if !ok {
|
||||||
return
|
break
|
||||||
}
|
}
|
||||||
add := true
|
add := true
|
||||||
add = add && change.NewAddr
|
add = add && change.NewAddr
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue