Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ type Config struct {
dontSpoofFor []string
spoofTypes []string
spoofSRV []string
domainSearchLists []string
spoofingTemporarilyDisabled bool
}

Expand Down Expand Up @@ -283,6 +284,8 @@ func configFromCLI() (config *Config, logger *Logger, err error) {
pflag.StringSliceVar(&config.spoofSRV, "spoof-srv", defaultSpoofSRV,
"Spoof SRV records for these services (format is `service:port`, "+
"the port can be omitted of Kerberos, HTTP, LDAP and LDAPS)")
pflag.StringSliceVar(&config.domainSearchLists, "domain-search-list", defaultDomainSearchlists,
"DHCPv6 `domain` search list for bare hostname lookups")
pflag.BoolVar(&config.IgnoreDHCPv6NoFQDN, "ignore-nofqdn", defaultIgnoreDHCPv6NoFQDN,
"Ignore DHCPv6 messages where the client did not include its\nFQDN (useful with allowlist or blocklists)")
pflag.BoolVar(&config.IgnoreNonMicrosoftDHCP, "ignore-non-microsoft-dhcp", defaultIgnoreNonMicrosoftDHCP,
Expand Down
4 changes: 3 additions & 1 deletion defaults.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ var (
vendorDontSpoofFor = ""
vendorSpoofTypes = ""
vendorSpoofSRV = ""
vendorDomainSearchlists = ""
vendorIgnoreDHCPv6NoFQDN = ""
vendorIgnoreNonMicrosoftDHCP = ""
vendorDelegateIgnoredTo = ""
Expand Down Expand Up @@ -87,6 +88,7 @@ var (
defaultDontSpoofFor = forceStrings(vendorDontSpoofFor)
defaultSpoofTypes = forceStrings(vendorSpoofTypes)
defaultSpoofSRV = forceStrings(vendorSpoofSRV)
defaultDomainSearchlists = forceStrings(vendorDomainSearchlists)
defaultIgnoreDHCPv6NoFQDN = forceBool(vendorIgnoreDHCPv6NoFQDN, false)
defaultIgnoreNonMicrosoftDHCP = forceBool(vendorIgnoreNonMicrosoftDHCP, false)
defaultDelegateIgnoredTo = vendorDelegateIgnoredTo
Expand Down Expand Up @@ -133,7 +135,7 @@ func forceStrings(input string) []string {

res := make([]string, 0, len(input))

for _, s := range strings.Split(input, ",") {
for s := range strings.SplitSeq(input, ",") {
res = append(res, strings.TrimSpace(s))
}

Expand Down
10 changes: 8 additions & 2 deletions dhcpv6.go
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,7 @@ func (h *DHCPv6Handler) configureResponseOpts(requestIANA *dhcpv6.OptIANA,
// instead.
leasedIP[8] |= 0b10000000

return leasedIP, []dhcpv6.Modifier{
mods := []dhcpv6.Modifier{
dhcpv6.WithServerID(h.serverID),
dhcpv6.WithDNS(h.config.LocalIPv6),
dhcpv6.WithOption(&dhcpv6.OptIANA{
Expand All @@ -332,7 +332,13 @@ func (h *DHCPv6Handler) configureResponseOpts(requestIANA *dhcpv6.OptIANA,
},
},
}),
}, nil
}

if len(h.config.domainSearchLists) != 0 {
mods = append(mods, dhcpv6.WithDomainSearchList(h.config.domainSearchLists...))
}

return leasedIP, mods, nil
}

func generateDeterministicRandomAddress(peer net.IP) (net.IP, error) {
Expand Down
8 changes: 4 additions & 4 deletions hostinfo/arp.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ func getMACFromLinuxARPContent(ip net.IP, arpContent []byte) net.HardwareAddr {
return nil
}

for _, line := range strings.Split(string(arpContent), "\n") {
for line := range strings.SplitSeq(string(arpContent), "\n") {
parts := strings.Fields(line)
if len(parts) < 6 { //nolint:mnd
continue
Expand Down Expand Up @@ -63,7 +63,7 @@ func getIPFromLinuxARPContent(mac net.HardwareAddr, arpContent []byte) net.IP {
return nil
}

for _, line := range strings.Split(string(arpContent), "\n") {
for line := range strings.SplitSeq(string(arpContent), "\n") {
parts := strings.Fields(line)
if len(parts) < 6 { //nolint:mnd
continue
Expand Down Expand Up @@ -101,7 +101,7 @@ func getMACFromWindowsARPOutput(ip net.IP, arpOutput []byte) net.HardwareAddr {

skip := false

for _, line := range strings.Split(string(arpOutput), "\n") {
for line := range strings.SplitSeq(string(arpOutput), "\n") {
if len(line) == 0 {
continue
}
Expand Down Expand Up @@ -156,7 +156,7 @@ func getIPFromWindowsARP(mac net.HardwareAddr) net.IP {
func getIPFromWindowsARPOutput(mac net.HardwareAddr, arpOutput []byte) net.IP {
skip := false

for _, line := range strings.Split(string(arpOutput), "\n") {
for line := range strings.SplitSeq(string(arpOutput), "\n") {
if len(line) == 0 {
continue
}
Expand Down
7 changes: 2 additions & 5 deletions local_name_resolution.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,7 @@ func RunNetBIOSResponder(ctx context.Context, logger *Logger, config *Config) er

activeListenAddresses[listenIP.String()] = true

wg.Add(1)

go func() {
defer wg.Done()
wg.Go(func() {
defer conn.Close() //nolint:errcheck

logger.Infof("listening via UDP on %s", listenAddr)
Expand All @@ -85,7 +82,7 @@ func RunNetBIOSResponder(ctx context.Context, logger *Logger, config *Config) er
if err != nil {
logger.Errorf(err.Error())
}
}()
})
}

wg.Wait()
Expand Down
7 changes: 2 additions & 5 deletions log.go
Original file line number Diff line number Diff line change
Expand Up @@ -463,12 +463,9 @@ func (l *Logger) logf(w io.Writer, format string, a ...any) {
format = fmt.Sprintf("%s%s%s %s", l.style(faint), time.Now().Format("15:04:05"), l.style(reset), format)
}

l.baseLogger.wg.Add(1)

go func() {
l.baseLogger.wg.Go(func() {
fmt.Fprintf(w, format+l.style(reset)+"\n", a...)
l.baseLogger.wg.Done()
}()
})
}

func (l *Logger) styleAndPrefix(attrs ...attribute) string {
Expand Down
Loading