Network config stuff in Go

This commit is contained in:
Adam Ierymenko 2019-09-21 20:40:06 -07:00
commit bcb9df9cdf
No known key found for this signature in database
GPG key ID: C8877CF2D7A5D7F3
4 changed files with 453 additions and 130 deletions

View file

@ -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
}