mirror of
https://codeberg.org/cunicu/cunicu.git
synced 2025-10-25 17:50:36 +08:00
33 lines
559 B
Go
33 lines
559 B
Go
package core
|
|
|
|
import (
|
|
"riasc.eu/wice/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
|
|
}
|