mirror of https://github.com/tailscale/tailscale/
Merge remote-tracking branch 'origin/main' into HEAD
* origin/main: net/packet: documentation pass. net/packet: remove NewIP, offer only a netaddr constructor. net/packet: documentation cleanups. net/packet: fix panic on invalid IHL field. net/packet: remove {get,put}{16,32} indirection to encoding/binary. net/packet: support full IPv6 decoding. net/packet: add IPv6 source and destination IPs to Parsed.pull/914/head
commit
563d43b2a5
@ -0,0 +1,44 @@
|
|||||||
|
// 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.
|
||||||
|
|
||||||
|
package packet
|
||||||
|
|
||||||
|
// icmp6HeaderLength is the size of the ICMPv6 packet header, not
|
||||||
|
// including the outer IP layer or the variable "response data"
|
||||||
|
// trailer.
|
||||||
|
const icmp6HeaderLength = 4
|
||||||
|
|
||||||
|
// ICMP6Type is an ICMPv6 type, as specified in
|
||||||
|
// https://www.iana.org/assignments/icmpv6-parameters/icmpv6-parameters.xhtml
|
||||||
|
type ICMP6Type uint8
|
||||||
|
|
||||||
|
const (
|
||||||
|
ICMP6Unreachable ICMP6Type = 1
|
||||||
|
ICMP6TimeExceeded ICMP6Type = 3
|
||||||
|
ICMP6EchoRequest ICMP6Type = 128
|
||||||
|
ICMP6EchoReply ICMP6Type = 129
|
||||||
|
)
|
||||||
|
|
||||||
|
func (t ICMP6Type) String() string {
|
||||||
|
switch t {
|
||||||
|
case ICMP6Unreachable:
|
||||||
|
return "Unreachable"
|
||||||
|
case ICMP6TimeExceeded:
|
||||||
|
return "TimeExceeded"
|
||||||
|
case ICMP6EchoRequest:
|
||||||
|
return "EchoRequest"
|
||||||
|
case ICMP6EchoReply:
|
||||||
|
return "EchoReply"
|
||||||
|
default:
|
||||||
|
return "Unknown"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// ICMP6Code is an ICMPv6 code, as specified in
|
||||||
|
// https://www.iana.org/assignments/icmpv6-parameters/icmpv6-parameters.xhtml
|
||||||
|
type ICMP6Code uint8
|
||||||
|
|
||||||
|
const (
|
||||||
|
ICMP6NoCode ICMP6Code = 0
|
||||||
|
)
|
@ -0,0 +1,53 @@
|
|||||||
|
// 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.
|
||||||
|
|
||||||
|
package packet
|
||||||
|
|
||||||
|
// IPProto is an IP subprotocol as defined by the IANA protocol
|
||||||
|
// numbers list
|
||||||
|
// (https://www.iana.org/assignments/protocol-numbers/protocol-numbers.xhtml),
|
||||||
|
// or the special values Unknown or Fragment.
|
||||||
|
type IPProto uint8
|
||||||
|
|
||||||
|
const (
|
||||||
|
// Unknown represents an unknown or unsupported protocol; it's
|
||||||
|
// deliberately the zero value. Strictly speaking the zero
|
||||||
|
// value is IPv6 hop-by-hop extensions, but we don't support
|
||||||
|
// those, so this is still technically correct.
|
||||||
|
Unknown IPProto = 0x00
|
||||||
|
|
||||||
|
// Values from the IANA registry.
|
||||||
|
ICMPv4 IPProto = 0x01
|
||||||
|
IGMP IPProto = 0x02
|
||||||
|
ICMPv6 IPProto = 0x3a
|
||||||
|
TCP IPProto = 0x06
|
||||||
|
UDP IPProto = 0x11
|
||||||
|
|
||||||
|
// Fragment represents any non-first IP fragment, for which we
|
||||||
|
// don't have the sub-protocol header (and therefore can't
|
||||||
|
// figure out what the sub-protocol is).
|
||||||
|
//
|
||||||
|
// 0xFF is reserved in the IANA registry, so we steal it for
|
||||||
|
// internal use.
|
||||||
|
Fragment IPProto = 0xFF
|
||||||
|
)
|
||||||
|
|
||||||
|
func (p IPProto) String() string {
|
||||||
|
switch p {
|
||||||
|
case Fragment:
|
||||||
|
return "Frag"
|
||||||
|
case ICMPv4:
|
||||||
|
return "ICMPv4"
|
||||||
|
case IGMP:
|
||||||
|
return "IGMP"
|
||||||
|
case ICMPv6:
|
||||||
|
return "ICMPv6"
|
||||||
|
case UDP:
|
||||||
|
return "UDP"
|
||||||
|
case TCP:
|
||||||
|
return "TCP"
|
||||||
|
default:
|
||||||
|
return "Unknown"
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,34 @@
|
|||||||
|
// 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.
|
||||||
|
|
||||||
|
package packet
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
|
||||||
|
"inet.af/netaddr"
|
||||||
|
)
|
||||||
|
|
||||||
|
// IP6 is an IPv6 address.
|
||||||
|
type IP6 [16]byte
|
||||||
|
|
||||||
|
// IP6FromNetaddr converts a netaddr.IP to an IP6. Panics if !ip.Is6.
|
||||||
|
func IP6FromNetaddr(ip netaddr.IP) IP6 {
|
||||||
|
if !ip.Is6() {
|
||||||
|
panic(fmt.Sprintf("IP6FromNetaddr called with non-v6 addr %q", ip))
|
||||||
|
}
|
||||||
|
return IP6(ip.As16())
|
||||||
|
}
|
||||||
|
|
||||||
|
// Netaddr converts ip to a netaddr.IP.
|
||||||
|
func (ip IP6) Netaddr() netaddr.IP {
|
||||||
|
return netaddr.IPFrom16(ip)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (ip IP6) String() string {
|
||||||
|
return ip.Netaddr().String()
|
||||||
|
}
|
||||||
|
|
||||||
|
// ip6HeaderLength is the length of an IPv6 header with no IP options.
|
||||||
|
const ip6HeaderLength = 40
|
Loading…
Reference in New Issue