Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix ifcIndex usage in Windows #184

Merged
merged 1 commit into from
Apr 2, 2024
Merged
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
23 changes: 12 additions & 11 deletions conn.go
Original file line number Diff line number Diff line change
Expand Up @@ -319,22 +319,22 @@
// further out into the network stack.
if multicastPktConnV4 != nil {
if err := multicastPktConnV4.SetMulticastLoopback(true); err != nil {
c.log.Warnf("[%s] failed to SetMulticastLoopback(true) on multicast IPv4 PacketConn %v; this may cause inefficient network path c.name,communications", err)
c.log.Warnf("[%s] failed to SetMulticastLoopback(true) on multicast IPv4 PacketConn %v; this may cause inefficient network path c.name,communications", c.name, err)

Check warning on line 322 in conn.go

View check run for this annotation

Codecov / codecov/patch

conn.go#L322

Added line #L322 was not covered by tests
}
}
if multicastPktConnV6 != nil {
if err := multicastPktConnV6.SetMulticastLoopback(true); err != nil {
c.log.Warnf("[%s] failed to SetMulticastLoopback(true) on multicast IPv6 PacketConn %v; this may cause inefficient network path c.name,communications", err)
c.log.Warnf("[%s] failed to SetMulticastLoopback(true) on multicast IPv6 PacketConn %v; this may cause inefficient network path c.name,communications", c.name, err)

Check warning on line 327 in conn.go

View check run for this annotation

Codecov / codecov/patch

conn.go#L327

Added line #L327 was not covered by tests
}
}
if unicastPktConnV4 != nil {
if err := unicastPktConnV4.SetMulticastLoopback(true); err != nil {
c.log.Warnf("[%s] failed to SetMulticastLoopback(true) on unicast IPv4 PacketConn %v; this may cause inefficient network path c.name,communications", err)
c.log.Warnf("[%s] failed to SetMulticastLoopback(true) on unicast IPv4 PacketConn %v; this may cause inefficient network path c.name,communications", c.name, err)

Check warning on line 332 in conn.go

View check run for this annotation

Codecov / codecov/patch

conn.go#L332

Added line #L332 was not covered by tests
}
}
if unicastPktConnV6 != nil {
if err := unicastPktConnV6.SetMulticastLoopback(true); err != nil {
c.log.Warnf("[%s] failed to SetMulticastLoopback(true) on unicast IPv6 PacketConn %v; this may cause inefficient network path c.name,communications", err)
c.log.Warnf("[%s] failed to SetMulticastLoopback(true) on unicast IPv6 PacketConn %v; this may cause inefficient network path c.name,communications", c.name, err)

Check warning on line 337 in conn.go

View check run for this annotation

Codecov / codecov/patch

conn.go#L337

Added line #L337 was not covered by tests
}
}
}
Expand Down Expand Up @@ -590,7 +590,7 @@
return
}

c.writeToSocket(0, rawQuery, false, false, writeTypeQuestion, nil)
c.writeToSocket(-1, rawQuery, false, false, writeTypeQuestion, nil)
}

//nolint:gocognit
Expand All @@ -616,7 +616,7 @@
}
}

if ifIndex != 0 {
if ifIndex != -1 {
if wType == writeTypeQuestion {
c.log.Errorf("[%s] Unexpected question using specific interface index %d; dropping question", c.name, ifIndex)
return
Expand Down Expand Up @@ -690,7 +690,7 @@
}
}
} else {
c.log.Debugf("[%s] writing answer to IPv4: %s, IPv6: %s", c.name, dst4, dst6)
c.log.Debugf("[%s] writing answer to IPv4: %v, IPv6: %v", c.name, dst4, dst6)

Check warning on line 693 in conn.go

View check run for this annotation

Codecov / codecov/patch

conn.go#L693

Added line #L693 was not covered by tests

if ifc.supportsV4 && c.multicastPktConnV4 != nil && dst4 != nil {
if !hasIPv6Zone {
Expand Down Expand Up @@ -972,15 +972,15 @@
continue
}
if !isSupportedIPv6(addrCopy, c.multicastPktConnV4 == nil) {
c.log.Debugf("[%s] interface %d address not a supported IPv6 address %s", ifIndex, c.name, &addrCopy)
c.log.Debugf("[%s] interface %d address not a supported IPv6 address %s", c.name, ifIndex, &addrCopy)

Check warning on line 975 in conn.go

View check run for this annotation

Codecov / codecov/patch

conn.go#L975

Added line #L975 was not covered by tests
continue
}
}

selectedAddrs = append(selectedAddrs, addrCopy)
}
if len(selectedAddrs) == 0 {
c.log.Debugf("[%s] failed to find suitable IP for interface %d; deriving address from source address c.name,instead", ifIndex)
c.log.Debugf("[%s] failed to find suitable IP for interface %d; deriving address from source address c.name,instead", c.name, ifIndex)
} else {
// choose the best match
var choice *netip.Addr
Expand Down Expand Up @@ -1017,12 +1017,12 @@
}
if queryWantsV4 {
if !localAddress.Is4() {
c.log.Debugf("[%s] have IPv6 address %s to respond with but not question is for A not c.name,AAAA", localAddress)
c.log.Debugf("[%s] have IPv6 address %s to respond with but question is for A not c.name,AAAA", c.name, localAddress)

Check warning on line 1020 in conn.go

View check run for this annotation

Codecov / codecov/patch

conn.go#L1020

Added line #L1020 was not covered by tests
continue
}
} else {
if !localAddress.Is6() {
c.log.Debugf("[%s] have IPv4 address %s to respond with but not question is for AAAA not c.name,A", localAddress)
c.log.Debugf("[%s] have IPv4 address %s to respond with but question is for AAAA not c.name,A", c.name, localAddress)
continue
}
if !isSupportedIPv6(*localAddress, c.multicastPktConnV4 == nil) {
Expand All @@ -1042,6 +1042,7 @@
c.log.Debugf("[%s] refusing to send link-local address %s to an IPv4 destination %s", c.name, localAddress, dst)
continue
}
c.log.Debugf("[%s] sending response for %s on ifc %d of %s to %s", c.name, q.Name, ifIndex, *localAddress, dst)
c.sendAnswer(header.ID, q.Name.String(), ifIndex, *localAddress, dst)
}
}
Expand Down
Loading