Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
lima-vm
GitHub Repository: lima-vm/lima
Path: blob/master/cmd/limactl/debug.go
1645 views
1
// SPDX-FileCopyrightText: Copyright The Lima Authors
2
// SPDX-License-Identifier: Apache-2.0
3
4
package main
5
6
import (
7
"strconv"
8
"time"
9
10
"github.com/sirupsen/logrus"
11
"github.com/spf13/cobra"
12
13
"github.com/lima-vm/lima/v2/pkg/hostagent/dns"
14
)
15
16
func newDebugCommand() *cobra.Command {
17
cmd := &cobra.Command{
18
Use: "debug",
19
Short: "Debug utilities",
20
Long: "DO NOT USE! THE COMMAND SYNTAX IS SUBJECT TO CHANGE!",
21
Hidden: true,
22
}
23
cmd.AddCommand(newDebugDNSCommand())
24
return cmd
25
}
26
27
func newDebugDNSCommand() *cobra.Command {
28
cmd := &cobra.Command{
29
Use: "dns UDPPORT [TCPPORT]",
30
Short: "Debug built-in DNS",
31
Long: "DO NOT USE! THE COMMAND SYNTAX IS SUBJECT TO CHANGE!",
32
Args: WrapArgsError(cobra.RangeArgs(1, 2)),
33
RunE: debugDNSAction,
34
}
35
cmd.Flags().BoolP("ipv6", "6", false, "Lookup IPv6 addresses too")
36
return cmd
37
}
38
39
func debugDNSAction(cmd *cobra.Command, args []string) error {
40
ipv6, err := cmd.Flags().GetBool("ipv6")
41
if err != nil {
42
return err
43
}
44
udpLocalPort, err := strconv.Atoi(args[0])
45
if err != nil {
46
return err
47
}
48
tcpLocalPort := 0
49
if len(args) > 1 {
50
tcpLocalPort, err = strconv.Atoi(args[1])
51
if err != nil {
52
return err
53
}
54
}
55
srvOpts := dns.ServerOptions{
56
UDPPort: udpLocalPort,
57
TCPPort: tcpLocalPort,
58
Address: "127.0.0.1",
59
HandlerOptions: dns.HandlerOptions{
60
IPv6: ipv6,
61
StaticHosts: map[string]string{},
62
},
63
}
64
srv, err := dns.Start(srvOpts)
65
if err != nil {
66
return err
67
}
68
logrus.Infof("Started srv %+v (UDP %d, TCP %d)", srv, udpLocalPort, tcpLocalPort)
69
for {
70
time.Sleep(time.Hour)
71
}
72
}
73
74