mirror of
https://github.com/Control-D-Inc/ctrld.git
synced 2026-02-03 22:18:39 +00:00
cmd/ctrld: silent DHCPv6 error
It's hard to imagine a system with IPv6 but not IPv4, so silent the DHCPv6 error if any.
This commit is contained in:
committed by
Cuong Manh Le
parent
149941f17f
commit
37de5441c1
@@ -221,8 +221,8 @@ func initCLI() {
|
||||
{s.Start, true},
|
||||
}
|
||||
if doTasks(tasks) {
|
||||
mainLog.Info().Msg("Service started")
|
||||
prog.setDNS()
|
||||
mainLog.Info().Msg("Service started")
|
||||
}
|
||||
},
|
||||
}
|
||||
@@ -252,8 +252,8 @@ func initCLI() {
|
||||
}
|
||||
initLogging()
|
||||
if doTasks([]task{{s.Stop, true}}) {
|
||||
mainLog.Info().Msg("Service stopped")
|
||||
prog.resetDNS()
|
||||
mainLog.Info().Msg("Service stopped")
|
||||
}
|
||||
},
|
||||
}
|
||||
@@ -321,8 +321,8 @@ func initCLI() {
|
||||
}
|
||||
initLogging()
|
||||
if doTasks(tasks) {
|
||||
mainLog.Info().Msg("Service uninstalled")
|
||||
prog.resetDNS()
|
||||
mainLog.Info().Msg("Service uninstalled")
|
||||
return
|
||||
}
|
||||
},
|
||||
|
||||
@@ -14,7 +14,7 @@ import (
|
||||
|
||||
"github.com/insomniacslk/dhcp/dhcpv4/nclient4"
|
||||
"github.com/insomniacslk/dhcp/dhcpv6"
|
||||
"github.com/insomniacslk/dhcp/dhcpv6/nclient6"
|
||||
"github.com/insomniacslk/dhcp/dhcpv6/client6"
|
||||
"tailscale.com/net/dns"
|
||||
"tailscale.com/util/dnsname"
|
||||
|
||||
@@ -84,37 +84,29 @@ func resetDNS(iface *net.Interface) error {
|
||||
ns = append(ns, nameserver.String())
|
||||
}
|
||||
|
||||
// TODO(cuonglm): handle DHCPv6 properly.
|
||||
if supportsIPv6() {
|
||||
c, err := nclient6.New(iface.Name)
|
||||
c := client6.NewClient()
|
||||
conversation, err := c.Exchange(iface.Name)
|
||||
if err != nil {
|
||||
mainLog.Warn().Err(err).Msg("could not create DHCPv6 client")
|
||||
mainLog.Debug().Err(err).Msg("could not exchange DHCPv6")
|
||||
return nil
|
||||
}
|
||||
defer c.Close()
|
||||
ctx, cancel := context.WithTimeout(context.Background(), time.Second*5)
|
||||
defer cancel()
|
||||
|
||||
solicit, err := dhcpv6.NewSolicit(iface.HardwareAddr)
|
||||
if err != nil {
|
||||
return fmt.Errorf("dhcpv6.NewSolicit: %w", err)
|
||||
}
|
||||
advertise, err := dhcpv6.NewAdvertiseFromSolicit(solicit)
|
||||
if err != nil {
|
||||
return fmt.Errorf("dhcpv6.NewAdvertiseFromSolicit: %w", err)
|
||||
}
|
||||
msg, err := c.Request(ctx, advertise)
|
||||
if err != nil {
|
||||
return fmt.Errorf("nclient6.Request: %w", err)
|
||||
}
|
||||
nameservers := msg.Options.DNS()
|
||||
for _, nameserver := range nameservers {
|
||||
if nameserver.Equal(net.IPv6zero) {
|
||||
continue
|
||||
for _, packet := range conversation {
|
||||
if packet.Type() == dhcpv6.MessageTypeReply {
|
||||
msg, err := packet.GetInnerMessage()
|
||||
if err != nil {
|
||||
mainLog.Debug().Err(err).Msg("could not get inner DHCPv6 message")
|
||||
return nil
|
||||
}
|
||||
nameservers := msg.Options.DNS()
|
||||
for _, nameserver := range nameservers {
|
||||
ns = append(ns, nameserver.String())
|
||||
}
|
||||
}
|
||||
ns = append(ns, nameserver.String())
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return ignoringEINTR(func() error {
|
||||
return setDNS(iface, ns)
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user