mirror of
https://github.com/ZeroTier/ZeroTierOne
synced 2025-08-14 02:27:38 -07:00
Network config stuff in Go
This commit is contained in:
parent
2eef9d22e6
commit
bcb9df9cdf
4 changed files with 453 additions and 130 deletions
|
@ -13,7 +13,10 @@
|
|||
|
||||
package zerotier
|
||||
|
||||
import "net"
|
||||
import (
|
||||
"net"
|
||||
"unsafe"
|
||||
)
|
||||
|
||||
// Route represents a route in a host's routing table
|
||||
type Route struct {
|
||||
|
@ -29,3 +32,13 @@ type Route struct {
|
|||
// Metric is an interface metric that can affect route priority (behavior can be OS-specific)
|
||||
Metric uint16
|
||||
}
|
||||
|
||||
// key generates a key suitable for a map[] from this route
|
||||
func (r *Route) key() (k [6]uint64) {
|
||||
copy(((*[16]byte)(unsafe.Pointer(&k[0])))[:], r.Target.IP)
|
||||
ones, bits := r.Target.Mask.Size()
|
||||
k[2] = (uint64(ones) << 32) | uint64(bits)
|
||||
copy(((*[16]byte)(unsafe.Pointer(&k[3])))[:], r.Via)
|
||||
k[5] = (uint64(r.Flags) << 32) | uint64(r.Metric)
|
||||
return
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue