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>
183 lines
4.7 KiB
Go
183 lines
4.7 KiB
Go
// Copyright (c) Tailscale Inc & contributors
|
|
// SPDX-License-Identifier: BSD-3-Clause
|
|
|
|
package cli
|
|
|
|
import (
|
|
"context"
|
|
"flag"
|
|
"fmt"
|
|
"net/netip"
|
|
"os"
|
|
"strings"
|
|
"text/tabwriter"
|
|
|
|
"github.com/peterbourgon/ff/v3/ffcli"
|
|
"golang.org/x/net/dns/dnsmessage"
|
|
"tailscale.com/types/dnstype"
|
|
)
|
|
|
|
var dnsQueryCmd = &ffcli.Command{
|
|
Name: "query",
|
|
ShortUsage: "tailscale dns query <name> [a|aaaa|cname|mx|ns|opt|ptr|srv|txt]",
|
|
Exec: runDNSQuery,
|
|
ShortHelp: "Perform a DNS query",
|
|
LongHelp: strings.TrimSpace(`
|
|
The 'tailscale dns query' subcommand performs a DNS query for the specified name
|
|
using the internal DNS forwarder (100.100.100.100).
|
|
|
|
By default, the DNS query will request an A record. Another DNS record type can
|
|
be specified as the second parameter.
|
|
|
|
The output also provides information about the resolver(s) used to resolve the
|
|
query.
|
|
`),
|
|
}
|
|
|
|
func runDNSQuery(ctx context.Context, args []string) error {
|
|
if len(args) < 1 {
|
|
return flag.ErrHelp
|
|
}
|
|
name := args[0]
|
|
queryType := "A"
|
|
if len(args) >= 2 {
|
|
queryType = args[1]
|
|
}
|
|
fmt.Printf("DNS query for %q (%s) using internal resolver:\n", name, queryType)
|
|
fmt.Println()
|
|
bytes, resolvers, err := localClient.QueryDNS(ctx, name, queryType)
|
|
if err != nil {
|
|
fmt.Printf("failed to query DNS: %v\n", err)
|
|
return nil
|
|
}
|
|
|
|
if len(resolvers) == 1 {
|
|
fmt.Printf("Forwarding to resolver: %v\n", makeResolverString(*resolvers[0]))
|
|
} else {
|
|
fmt.Println("Multiple resolvers available:")
|
|
for _, r := range resolvers {
|
|
fmt.Printf(" - %v\n", makeResolverString(*r))
|
|
}
|
|
}
|
|
fmt.Println()
|
|
var p dnsmessage.Parser
|
|
header, err := p.Start(bytes)
|
|
if err != nil {
|
|
fmt.Printf("failed to parse DNS response: %v\n", err)
|
|
return err
|
|
}
|
|
fmt.Printf("Response code: %v\n", header.RCode.String())
|
|
fmt.Println()
|
|
p.SkipAllQuestions()
|
|
if header.RCode != dnsmessage.RCodeSuccess {
|
|
fmt.Println("No answers were returned.")
|
|
return nil
|
|
}
|
|
answers, err := p.AllAnswers()
|
|
if err != nil {
|
|
fmt.Printf("failed to parse DNS answers: %v\n", err)
|
|
return err
|
|
}
|
|
if len(answers) == 0 {
|
|
fmt.Println(" (no answers found)")
|
|
}
|
|
|
|
w := tabwriter.NewWriter(os.Stdout, 0, 0, 2, ' ', 0)
|
|
fmt.Fprintln(w, "Name\tTTL\tClass\tType\tBody")
|
|
fmt.Fprintln(w, "----\t---\t-----\t----\t----")
|
|
for _, a := range answers {
|
|
fmt.Fprintf(w, "%s\t%d\t%s\t%s\t%s\n", a.Header.Name.String(), a.Header.TTL, a.Header.Class.String(), a.Header.Type.String(), makeAnswerBody(a))
|
|
}
|
|
w.Flush()
|
|
|
|
fmt.Println()
|
|
return nil
|
|
}
|
|
|
|
// makeAnswerBody returns a string with the DNS answer body in a human-readable format.
|
|
func makeAnswerBody(a dnsmessage.Resource) string {
|
|
switch a.Header.Type {
|
|
case dnsmessage.TypeA:
|
|
return makeABody(a.Body)
|
|
case dnsmessage.TypeAAAA:
|
|
return makeAAAABody(a.Body)
|
|
case dnsmessage.TypeCNAME:
|
|
return makeCNAMEBody(a.Body)
|
|
case dnsmessage.TypeMX:
|
|
return makeMXBody(a.Body)
|
|
case dnsmessage.TypeNS:
|
|
return makeNSBody(a.Body)
|
|
case dnsmessage.TypeOPT:
|
|
return makeOPTBody(a.Body)
|
|
case dnsmessage.TypePTR:
|
|
return makePTRBody(a.Body)
|
|
case dnsmessage.TypeSRV:
|
|
return makeSRVBody(a.Body)
|
|
case dnsmessage.TypeTXT:
|
|
return makeTXTBody(a.Body)
|
|
default:
|
|
return a.Body.GoString()
|
|
}
|
|
}
|
|
|
|
func makeABody(a dnsmessage.ResourceBody) string {
|
|
if a, ok := a.(*dnsmessage.AResource); ok {
|
|
return netip.AddrFrom4(a.A).String()
|
|
}
|
|
return ""
|
|
}
|
|
func makeAAAABody(aaaa dnsmessage.ResourceBody) string {
|
|
if a, ok := aaaa.(*dnsmessage.AAAAResource); ok {
|
|
return netip.AddrFrom16(a.AAAA).String()
|
|
}
|
|
return ""
|
|
}
|
|
func makeCNAMEBody(cname dnsmessage.ResourceBody) string {
|
|
if c, ok := cname.(*dnsmessage.CNAMEResource); ok {
|
|
return c.CNAME.String()
|
|
}
|
|
return ""
|
|
}
|
|
func makeMXBody(mx dnsmessage.ResourceBody) string {
|
|
if m, ok := mx.(*dnsmessage.MXResource); ok {
|
|
return fmt.Sprintf("%s (Priority=%d)", m.MX, m.Pref)
|
|
}
|
|
return ""
|
|
}
|
|
func makeNSBody(ns dnsmessage.ResourceBody) string {
|
|
if n, ok := ns.(*dnsmessage.NSResource); ok {
|
|
return n.NS.String()
|
|
}
|
|
return ""
|
|
}
|
|
func makeOPTBody(opt dnsmessage.ResourceBody) string {
|
|
if o, ok := opt.(*dnsmessage.OPTResource); ok {
|
|
return o.GoString()
|
|
}
|
|
return ""
|
|
}
|
|
func makePTRBody(ptr dnsmessage.ResourceBody) string {
|
|
if p, ok := ptr.(*dnsmessage.PTRResource); ok {
|
|
return p.PTR.String()
|
|
}
|
|
return ""
|
|
}
|
|
func makeSRVBody(srv dnsmessage.ResourceBody) string {
|
|
if s, ok := srv.(*dnsmessage.SRVResource); ok {
|
|
return fmt.Sprintf("Target=%s, Port=%d, Priority=%d, Weight=%d", s.Target.String(), s.Port, s.Priority, s.Weight)
|
|
}
|
|
return ""
|
|
}
|
|
func makeTXTBody(txt dnsmessage.ResourceBody) string {
|
|
if t, ok := txt.(*dnsmessage.TXTResource); ok {
|
|
return fmt.Sprintf("%q", t.TXT)
|
|
}
|
|
return ""
|
|
}
|
|
func makeResolverString(r dnstype.Resolver) string {
|
|
if len(r.BootstrapResolution) > 0 {
|
|
return fmt.Sprintf("%s (bootstrap: %v)", r.Addr, r.BootstrapResolution)
|
|
}
|
|
return fmt.Sprintf("%s", r.Addr)
|
|
}
|