2020-11-10 09:00:35 +00:00
|
|
|
// Copyright (c) 2020 Tailscale Inc & AUTHORS All rights reserved.
|
|
|
|
// Use of this source code is governed by a BSD-style
|
|
|
|
// license that can be found in the LICENSE file.
|
|
|
|
|
2020-11-10 08:04:27 +00:00
|
|
|
package packet
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
|
|
|
|
"inet.af/netaddr"
|
|
|
|
)
|
|
|
|
|
2020-11-11 06:26:00 +00:00
|
|
|
// IP6 is an IPv6 address.
|
2020-11-10 08:04:27 +00:00
|
|
|
type IP6 [16]byte
|
|
|
|
|
2020-11-11 06:26:00 +00:00
|
|
|
// IP6FromNetaddr converts a netaddr.IP to an IP6. Panics if !ip.Is6.
|
2020-11-10 08:04:27 +00:00
|
|
|
func IP6FromNetaddr(ip netaddr.IP) IP6 {
|
|
|
|
if !ip.Is6() {
|
|
|
|
panic(fmt.Sprintf("IP6FromNetaddr called with non-v6 addr %q", ip))
|
|
|
|
}
|
|
|
|
return IP6(ip.As16())
|
|
|
|
}
|
|
|
|
|
2020-11-11 06:26:00 +00:00
|
|
|
// Netaddr converts ip to a netaddr.IP.
|
2020-11-10 08:04:27 +00:00
|
|
|
func (ip IP6) Netaddr() netaddr.IP {
|
|
|
|
return netaddr.IPFrom16(ip)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (ip IP6) String() string {
|
|
|
|
return ip.Netaddr().String()
|
|
|
|
}
|
2020-11-10 09:00:35 +00:00
|
|
|
|
2020-11-11 06:26:00 +00:00
|
|
|
// ip6HeaderLength is the length of an IPv6 header with no IP options.
|
2020-11-10 09:00:35 +00:00
|
|
|
const ip6HeaderLength = 40
|