mirror of
https://codeberg.org/cunicu/cunicu.git
synced 2025-10-05 16:57:01 +08:00
33 lines
569 B
Go
33 lines
569 B
Go
package core
|
|
|
|
import (
|
|
"github.com/stv0g/cunicu/pkg/crypto"
|
|
)
|
|
|
|
// InterfaceList stores all WireGuard interfaces indexed by their unique ifindex
|
|
type InterfaceList map[string]*Interface
|
|
|
|
func (l *InterfaceList) ByIndex(index int) *Interface {
|
|
for _, i := range *l {
|
|
if i.KernelDevice.Index() == index {
|
|
return i
|
|
}
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
func (l *InterfaceList) ByName(name string) *Interface {
|
|
return (*l)[name]
|
|
}
|
|
|
|
func (l *InterfaceList) ByPublicKey(pk crypto.Key) *Interface {
|
|
for _, i := range *l {
|
|
if i.PublicKey() == pk {
|
|
return i
|
|
}
|
|
}
|
|
|
|
return nil
|
|
}
|