3ec5be3f51
This file was never truly necessary and has never actually been used in the history of Tailscale's open source releases. A Brief History of AUTHORS files --- The AUTHORS file was a pattern developed at Google, originally for Chromium, then adopted by Go and a bunch of other projects. The problem was that Chromium originally had a copyright line only recognizing Google as the copyright holder. Because Google (and most open source projects) do not require copyright assignemnt for contributions, each contributor maintains their copyright. Some large corporate contributors then tried to add their own name to the copyright line in the LICENSE file or in file headers. This quickly becomes unwieldy, and puts a tremendous burden on anyone building on top of Chromium, since the license requires that they keep all copyright lines intact. The compromise was to create an AUTHORS file that would list all of the copyright holders. The LICENSE file and source file headers would then include that list by reference, listing the copyright holder as "The Chromium Authors". This also become cumbersome to simply keep the file up to date with a high rate of new contributors. Plus it's not always obvious who the copyright holder is. Sometimes it is the individual making the contribution, but many times it may be their employer. There is no way for the proejct maintainer to know. Eventually, Google changed their policy to no longer recommend trying to keep the AUTHORS file up to date proactively, and instead to only add to it when requested: https://opensource.google/docs/releasing/authors. They are also clear that: > Adding contributors to the AUTHORS file is entirely within the > project's discretion and has no implications for copyright ownership. It was primarily added to appease a small number of large contributors that insisted that they be recognized as copyright holders (which was entirely their right to do). But it's not truly necessary, and not even the most accurate way of identifying contributors and/or copyright holders. In practice, we've never added anyone to our AUTHORS file. It only lists Tailscale, so it's not really serving any purpose. It also causes confusion because Tailscalars put the "Tailscale Inc & AUTHORS" header in other open source repos which don't actually have an AUTHORS file, so it's ambiguous what that means. Instead, we just acknowledge that the contributors to Tailscale (whoever they are) are copyright holders for their individual contributions. We also have the benefit of using the DCO (developercertificate.org) which provides some additional certification of their right to make the contribution. The source file changes were purely mechanical with: git ls-files | xargs sed -i -e 's/\(Tailscale Inc &\) AUTHORS/\1 contributors/g' Updates #cleanup Change-Id: Ia101a4a3005adb9118051b3416f5a64a4a45987d Signed-off-by: Will Norris <will@tailscale.com>
200 lines
4.5 KiB
Go
200 lines
4.5 KiB
Go
// Copyright (c) Tailscale Inc & contributors
|
|
// SPDX-License-Identifier: BSD-3-Clause
|
|
|
|
// Package ipproto contains IP Protocol constants.
|
|
package ipproto
|
|
|
|
import (
|
|
"fmt"
|
|
"strconv"
|
|
|
|
"tailscale.com/util/nocasemaps"
|
|
"tailscale.com/util/vizerror"
|
|
)
|
|
|
|
// Version describes the IP address version.
|
|
type Version uint8
|
|
|
|
// Valid Version values.
|
|
const (
|
|
Version4 = 4
|
|
Version6 = 6
|
|
)
|
|
|
|
func (p Version) String() string {
|
|
switch p {
|
|
case Version4:
|
|
return "IPv4"
|
|
case Version6:
|
|
return "IPv6"
|
|
default:
|
|
return fmt.Sprintf("Version-%d", int(p))
|
|
}
|
|
}
|
|
|
|
// Proto 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 Proto 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 Proto = 0x00
|
|
|
|
// Values from the IANA registry.
|
|
ICMPv4 Proto = 0x01
|
|
IGMP Proto = 0x02
|
|
ICMPv6 Proto = 0x3a
|
|
TCP Proto = 0x06
|
|
UDP Proto = 0x11
|
|
DCCP Proto = 0x21
|
|
GRE Proto = 0x2f
|
|
SCTP Proto = 0x84
|
|
|
|
// 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.
|
|
TSMP Proto = 99
|
|
|
|
// 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 Proto = 0xFF
|
|
)
|
|
|
|
// Deprecated: use MarshalText instead.
|
|
func (p Proto) String() string {
|
|
switch p {
|
|
case Unknown:
|
|
return "Unknown"
|
|
case Fragment:
|
|
return "Frag"
|
|
case ICMPv4:
|
|
return "ICMPv4"
|
|
case IGMP:
|
|
return "IGMP"
|
|
case ICMPv6:
|
|
return "ICMPv6"
|
|
case UDP:
|
|
return "UDP"
|
|
case TCP:
|
|
return "TCP"
|
|
case SCTP:
|
|
return "SCTP"
|
|
case TSMP:
|
|
return "TSMP"
|
|
case GRE:
|
|
return "GRE"
|
|
case DCCP:
|
|
return "DCCP"
|
|
default:
|
|
return fmt.Sprintf("IPProto-%d", int(p))
|
|
}
|
|
}
|
|
|
|
// Prefer names from
|
|
// https://www.iana.org/assignments/protocol-numbers/protocol-numbers.xhtml
|
|
// unless otherwise noted.
|
|
var (
|
|
// preferredNames is the set of protocol names that re produced by
|
|
// MarshalText, and are the preferred representation.
|
|
preferredNames = map[Proto]string{
|
|
51: "ah",
|
|
DCCP: "dccp",
|
|
8: "egp",
|
|
50: "esp",
|
|
47: "gre",
|
|
ICMPv4: "icmp",
|
|
IGMP: "igmp",
|
|
9: "igp",
|
|
4: "ipv4",
|
|
ICMPv6: "ipv6-icmp",
|
|
SCTP: "sctp",
|
|
TCP: "tcp",
|
|
UDP: "udp",
|
|
}
|
|
|
|
// acceptedNames is the set of protocol names that are accepted by
|
|
// UnmarshalText.
|
|
acceptedNames = map[string]Proto{
|
|
"ah": 51,
|
|
"dccp": DCCP,
|
|
"egp": 8,
|
|
"esp": 50,
|
|
"gre": 47,
|
|
"icmp": ICMPv4,
|
|
"icmpv4": ICMPv4,
|
|
"icmpv6": ICMPv6,
|
|
"igmp": IGMP,
|
|
"igp": 9,
|
|
"ip-in-ip": 4, // IANA says "ipv4"; Wikipedia/popular use says "ip-in-ip"
|
|
"ipv4": 4,
|
|
"ipv6-icmp": ICMPv6,
|
|
"sctp": SCTP,
|
|
"tcp": TCP,
|
|
"tsmp": TSMP,
|
|
"udp": UDP,
|
|
}
|
|
)
|
|
|
|
// UnmarshalText implements encoding.TextUnmarshaler. If the input is empty, p
|
|
// is set to 0. If an error occurs, p is unchanged.
|
|
func (p *Proto) UnmarshalText(b []byte) error {
|
|
if len(b) == 0 {
|
|
*p = 0
|
|
return nil
|
|
}
|
|
|
|
if u, err := strconv.ParseUint(string(b), 10, 8); err == nil {
|
|
*p = Proto(u)
|
|
return nil
|
|
}
|
|
|
|
if newP, ok := nocasemaps.GetOk(acceptedNames, string(b)); ok {
|
|
*p = newP
|
|
return nil
|
|
}
|
|
|
|
return vizerror.Errorf("proto name %q not known; use protocol number 0-255", b)
|
|
}
|
|
|
|
// MarshalText implements encoding.TextMarshaler.
|
|
func (p Proto) MarshalText() ([]byte, error) {
|
|
if s, ok := preferredNames[p]; ok {
|
|
return []byte(s), nil
|
|
}
|
|
return []byte(strconv.Itoa(int(p))), nil
|
|
}
|
|
|
|
// MarshalJSON implements json.Marshaler.
|
|
func (p Proto) MarshalJSON() ([]byte, error) {
|
|
return []byte(strconv.Itoa(int(p))), nil
|
|
}
|
|
|
|
// UnmarshalJSON implements json.Unmarshaler. If the input is empty, p is set to
|
|
// 0. If an error occurs, p is unchanged. The input must be a JSON number or an
|
|
// accepted string name.
|
|
func (p *Proto) UnmarshalJSON(b []byte) error {
|
|
if len(b) == 0 {
|
|
*p = 0
|
|
return nil
|
|
}
|
|
if b[0] == '"' {
|
|
b = b[1 : len(b)-1]
|
|
}
|
|
return p.UnmarshalText(b)
|
|
}
|