Skip to content

Commit

Permalink
Merge pull request #2483 from openziti/router-resolver-if-tproxy
Browse files Browse the repository at this point in the history
start nameserver only if tproxy mode; resolves #2482
  • Loading branch information
qrkourier authored Oct 21, 2024
2 parents 53f8161 + ea38ce0 commit e7a5fdf
Showing 1 changed file with 15 additions and 12 deletions.
27 changes: 15 additions & 12 deletions router/xgress_edge_tunnel/tunneler.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,20 +68,22 @@ func (self *tunneler) Start(notifyClose <-chan struct{}) error {
var err error

log := pfxlog.Logger()
log.WithField("mode", self.listenOptions.mode).Info("creating interceptor")
var resolver dns.Resolver

resolver, err := dns.NewResolver(self.listenOptions.resolver)
if err != nil {
pfxlog.Logger().WithError(err).Error("failed to start DNS resolver. using dummy resolver")
resolver = dns.NewDummyResolver()
}
if strings.HasPrefix(self.listenOptions.mode, "tproxy") {
log.WithField("mode", self.listenOptions.mode).Info("creating tproxy interceptor")

if err = intercept.SetDnsInterceptIpRange(self.listenOptions.dnsSvcIpRange); err != nil {
pfxlog.Logger().Errorf("invalid dns service IP range %s: %v", self.listenOptions.dnsSvcIpRange, err)
return err
}
resolver, err = dns.NewResolver(self.listenOptions.resolver)
if err != nil {
pfxlog.Logger().WithError(err).Error("failed to start DNS resolver. using dummy resolver")
resolver = dns.NewDummyResolver()
}

if err = intercept.SetDnsInterceptIpRange(self.listenOptions.dnsSvcIpRange); err != nil {
pfxlog.Logger().Errorf("invalid dns service IP range %s: %v", self.listenOptions.dnsSvcIpRange, err)
return err
}

if strings.HasPrefix(self.listenOptions.mode, "tproxy") {
tproxyConfig := tproxy.Config{
LanIf: self.listenOptions.lanIf,
UDPIdleTimeout: self.listenOptions.udpIdleTimeout,
Expand All @@ -99,9 +101,10 @@ func (self *tunneler) Start(notifyClose <-chan struct{}) error {
self.listenOptions.resolver = ""
self.interceptor = host.New()
} else if self.listenOptions.mode == "proxy" {
log.WithField("mode", self.listenOptions.mode).Info("creating proxy interceptor")
self.listenOptions.resolver = ""
if self.interceptor, err = proxy.New(net.IPv4zero, self.listenOptions.services); err != nil {
return errors.Wrap(err, "failed to initialize tproxy interceptor")
return errors.Wrap(err, "failed to initialize proxy interceptor")
}
} else {
return errors.Errorf("unsupported tunnel mode '%v'", self.listenOptions.mode)
Expand Down

0 comments on commit e7a5fdf

Please sign in to comment.