Skip to content

Commit

Permalink
dialers: icmp dialing is not dual stack
Browse files Browse the repository at this point in the history
  • Loading branch information
ignoramous committed Oct 15, 2024
1 parent 9ee5105 commit bbdc6a3
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions intra/protect/xdial.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"errors"
"io"
"net"
"net/netip"

"github.com/celzero/firestack/intra/core"
"github.com/celzero/firestack/intra/log"
Expand Down Expand Up @@ -120,6 +121,7 @@ func (d *RDial) Accept(network, local string) (net.Listener, error) {
// Announce implements RDialer interface.
func (d *RDial) Announce(network, local string) (net.PacketConn, error) {
if network != "udp" && network != "udp4" && network != "udp6" {
log.T("xdial: Announce: invalid network %s", network)
return nil, errAnnounce
}
// todo: check if local is a local address or empty (any)
Expand Down Expand Up @@ -150,6 +152,14 @@ func (d *RDial) Announce(network, local string) (net.PacketConn, error) {

// Probe implements RDialer interface.
func (d *RDial) Probe(network, local string) (PacketConn, error) {
if network == "udp" {
ip, _ := netip.ParseAddrPort(local)
if ip.IsValid() && ip.Addr().Is4() {
network = "udp4"
} else if ip.IsValid() && ip.Addr().Is6() {
network = "udp6"
}
}
if network != "udp4" && network != "udp6" {
return nil, errAnnounce
}
Expand Down

0 comments on commit bbdc6a3

Please sign in to comment.