2023-01-27 21:37:20 +00:00
|
|
|
// Copyright (c) Tailscale Inc & AUTHORS
|
|
|
|
// SPDX-License-Identifier: BSD-3-Clause
|
2020-11-10 09:00:35 +00:00
|
|
|
|
2021-03-20 04:05:51 +00:00
|
|
|
// Package ipproto contains IP Protocol constants.
|
|
|
|
package ipproto
|
2020-11-10 09:00:35 +00:00
|
|
|
|
2021-03-20 04:05:51 +00:00
|
|
|
import "fmt"
|
|
|
|
|
2023-10-11 05:52:34 +00:00
|
|
|
// Version describes the IP address version.
|
|
|
|
type Version uint8
|
2023-10-03 18:55:06 +00:00
|
|
|
|
2023-10-11 05:52:34 +00:00
|
|
|
// Valid Version values.
|
2023-10-03 18:55:06 +00:00
|
|
|
const (
|
2023-10-11 05:52:34 +00:00
|
|
|
Version4 = 4
|
|
|
|
Version6 = 6
|
2023-10-03 18:55:06 +00:00
|
|
|
)
|
|
|
|
|
2023-10-11 05:52:34 +00:00
|
|
|
func (p Version) String() string {
|
2023-10-03 18:55:06 +00:00
|
|
|
switch p {
|
2023-10-11 05:52:34 +00:00
|
|
|
case Version4:
|
2023-10-03 18:55:06 +00:00
|
|
|
return "IPv4"
|
2023-10-11 05:52:34 +00:00
|
|
|
case Version6:
|
2023-10-03 18:55:06 +00:00
|
|
|
return "IPv6"
|
|
|
|
default:
|
2023-10-11 05:52:34 +00:00
|
|
|
return fmt.Sprintf("Version-%d", int(p))
|
2023-10-03 18:55:06 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-03-20 04:05:51 +00:00
|
|
|
// Proto is an IP subprotocol as defined by the IANA protocol
|
2020-11-10 09:00:35 +00:00
|
|
|
// numbers list
|
|
|
|
// (https://www.iana.org/assignments/protocol-numbers/protocol-numbers.xhtml),
|
|
|
|
// or the special values Unknown or Fragment.
|
2021-03-20 04:05:51 +00:00
|
|
|
type Proto uint8
|
2020-11-10 09:00:35 +00:00
|
|
|
|
|
|
|
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.
|
2021-03-20 04:05:51 +00:00
|
|
|
Unknown Proto = 0x00
|
2020-11-10 09:00:35 +00:00
|
|
|
|
|
|
|
// Values from the IANA registry.
|
2021-03-20 04:05:51 +00:00
|
|
|
ICMPv4 Proto = 0x01
|
|
|
|
IGMP Proto = 0x02
|
|
|
|
ICMPv6 Proto = 0x3a
|
|
|
|
TCP Proto = 0x06
|
|
|
|
UDP Proto = 0x11
|
2023-04-24 18:54:25 +00:00
|
|
|
DCCP Proto = 0x21
|
|
|
|
GRE Proto = 0x2f
|
2021-03-20 04:05:51 +00:00
|
|
|
SCTP Proto = 0x84
|
2020-11-10 09:00:35 +00:00
|
|
|
|
2021-01-12 20:03:41 +00:00
|
|
|
// TSMP is the Tailscale Message Protocol (our ICMP-ish
|
|
|
|
// thing), an IP protocol used only between Tailscale nodes
|
|
|
|
// (still encrypted by WireGuard) that communicates why things
|
|
|
|
// failed, etc.
|
|
|
|
//
|
|
|
|
// Proto number 99 is reserved for "any private encryption
|
|
|
|
// scheme". We never accept these from the host OS stack nor
|
|
|
|
// send them to the host network stack. It's only used between
|
|
|
|
// nodes.
|
2021-03-20 04:05:51 +00:00
|
|
|
TSMP Proto = 99
|
2021-01-12 20:03:41 +00:00
|
|
|
|
2020-11-10 09:00:35 +00:00
|
|
|
// 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.
|
2021-03-20 04:05:51 +00:00
|
|
|
Fragment Proto = 0xFF
|
2020-11-10 09:00:35 +00:00
|
|
|
)
|
|
|
|
|
2021-03-20 04:05:51 +00:00
|
|
|
func (p Proto) String() string {
|
2020-11-10 09:00:35 +00:00
|
|
|
switch p {
|
2021-03-20 04:05:51 +00:00
|
|
|
case Unknown:
|
|
|
|
return "Unknown"
|
2020-11-10 09:00:35 +00:00
|
|
|
case Fragment:
|
|
|
|
return "Frag"
|
|
|
|
case ICMPv4:
|
|
|
|
return "ICMPv4"
|
|
|
|
case IGMP:
|
|
|
|
return "IGMP"
|
|
|
|
case ICMPv6:
|
|
|
|
return "ICMPv6"
|
|
|
|
case UDP:
|
|
|
|
return "UDP"
|
|
|
|
case TCP:
|
|
|
|
return "TCP"
|
2021-03-20 04:05:51 +00:00
|
|
|
case SCTP:
|
|
|
|
return "SCTP"
|
2021-01-12 20:03:41 +00:00
|
|
|
case TSMP:
|
|
|
|
return "TSMP"
|
2023-04-24 18:54:25 +00:00
|
|
|
case GRE:
|
|
|
|
return "GRE"
|
|
|
|
case DCCP:
|
|
|
|
return "DCCP"
|
2020-11-10 09:00:35 +00:00
|
|
|
default:
|
2021-03-20 04:05:51 +00:00
|
|
|
return fmt.Sprintf("IPProto-%d", int(p))
|
2020-11-10 09:00:35 +00:00
|
|
|
}
|
|
|
|
}
|