From 85b8ba9469a466227f95958f252e740f18e98517 Mon Sep 17 00:00:00 2001 From: Tyson Moore Date: Sun, 2 May 2021 14:26:42 -0400 Subject: [PATCH] fshttp: rework address parsing for DSCP (fixes #5293) --- fs/fshttp/dialer.go | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/fs/fshttp/dialer.go b/fs/fshttp/dialer.go index 533754649..122fd1284 100644 --- a/fs/fshttp/dialer.go +++ b/fs/fshttp/dialer.go @@ -3,6 +3,7 @@ package fshttp import ( "context" "net" + "strings" "time" "github.com/rclone/rclone/fs" @@ -53,15 +54,14 @@ func (d *Dialer) DialContext(ctx context.Context, network, address string) (net. return c, err } if d.tclass != 0 { - if addr, ok := c.RemoteAddr().(*net.IPAddr); ok { - if addr.IP.To16() != nil && addr.IP.To4() == nil { - err = ipv6.NewConn(c).SetTrafficClass(d.tclass) - } else { - err = ipv4.NewConn(c).SetTOS(d.tclass) - } - if err != nil { - return c, err - } + // IPv6 addresses must have two or more ":" + if strings.Count(c.RemoteAddr().String(), ":") > 1 { + err = ipv6.NewConn(c).SetTrafficClass(d.tclass) + } else { + err = ipv4.NewConn(c).SetTOS(d.tclass) + } + if err != nil { + return c, err } } return newTimeoutConn(c, d.timeout)