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

x/net/ipv4: SetTOS() not working on MacOS #37422

Closed
hipatrickpark opened this issue Feb 24, 2020 · 2 comments
Closed

x/net/ipv4: SetTOS() not working on MacOS #37422

hipatrickpark opened this issue Feb 24, 2020 · 2 comments
Labels
FrozenDueToAge NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Milestone

Comments

@hipatrickpark
Copy link

@hipatrickpark hipatrickpark commented Feb 24, 2020

What version of Go are you using (go version)?

$ go version
go version go1.13.7 darwin/amd64

Does this issue reproduce with the latest release?

Yes

What operating system and processor architecture are you using (go env)?

go env Output
$ go env
GO111MODULE=""
GOARCH="amd64"
GOBIN=""
GOCACHE="/Users/ppark/Library/Caches/go-build"
GOENV="/Users/ppark/Library/Application Support/go/env"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GONOPROXY=""
GONOSUMDB=""
GOOS="darwin"
GOPATH="/Users/ppark/go"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/usr/local/Cellar/go/1.13.7/libexec"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/usr/local/Cellar/go/1.13.7/libexec/pkg/tool/darwin_amd64"
GCCGO="gccgo"
AR="ar"
CC="clang"
CXX="clang++"
CGO_ENABLED="1"
GOMOD=""
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/dt/jdkzprhd797dnqtb6t0my0vm0000gn/T/go-build046374812=/tmp/go-build -gno-record-gcc-switches -fno-common"

What did you do?

I tried to create an IP packet with a custom TOS bits by using SetTOS() as below, but it didn't work on MacOS 10.14.6, even though it works on Linux (RHEL 7.4):

package main
import (
	"golang.org/x/net/icmp"
	"golang.org/x/net/ipv4"
	"log"
	"net"
	"os"
)

func main() {
	c, err := net.ListenPacket("ip4:1", "0.0.0.0")
	if err != nil {
		log.Fatal(err)
	}
	defer c.Close()

	p := ipv4.NewPacketConn(c)

	err = p.SetTOS(0x38)           // Setting TOS doesn't work!
	if err != nil {
		log.Fatal(err)
	}
	p.SetTTL(30)                          // Setting TTL works!

	wm := icmp.Message{
		Type: ipv4.ICMPTypeEcho,
		Code: 0,
		Body: &icmp.Echo{
			ID:   os.Getpid() & 0xffff,
			Data: []byte("Hello-Hello"),
		},
	}
	wb, err := wm.Marshal(nil)
	var dst net.IPAddr
	dst.IP = []byte{8, 8, 8, 8}

	_, err = p.WriteTo(wb, nil, &dst)
	if err != nil {
		log.Fatal(err)
	}
}

TCPdump output as below, TOS bits not changed but TTL changed to 30:

12:09:00.315783 IP (tos 0x0, ttl 30, id 60823, offset 0, flags [none], proto ICMP (1), length 39)
    17.236.28.116 > 8.8.8.8: ICMP echo request, id 39543, seq 0, length 19
	0x0000:  4500 0027 ed97 0000 1e01 70cf 11ec 1c74  E..'......p....t
	0x0010:  0808 0808 0800 15b7 9a77 0000 4865 6c6c  .........w..Hell
	0x0020:  6f2d 4865 6c6c 6f                        o-Hello

What did you expect to see?

TOS bits are supposed to be changed as IPv4 package provides

What did you see instead?

Unchanged TOS bits.

@gopherbot gopherbot added this to the Unreleased milestone Feb 24, 2020
@hipatrickpark
Copy link
Author

@hipatrickpark hipatrickpark commented Feb 24, 2020

Just want to add one more example here. Even when using ipv4.Header as below, still TOS bits not changed, although other header fields (TTL, ID, Dst etc.) were changed correctly:

package main
  
import (
    //  "fmt"
    "golang.org/x/net/ipv4"
    "log"
    "net"
)

func main() {

    c, err := net.ListenPacket("ip4:1", "0.0.0.0")
    if err != nil {
        log.Fatal(err)
    }
    defer c.Close()

    p, err := ipv4.NewRawConn(c)
    if err != nil {
        log.Fatal(err)
    }

    b := []byte("HELLO-R-U-THERE")
    h := &ipv4.Header{
        Version:  ipv4.Version,
        Len:      ipv4.HeaderLen,
        TOS:      56, //0x38
        TotalLen: ipv4.HeaderLen + len(b),
        ID:       12345,
        Protocol: 1,
        Dst:      net.IP{8, 8, 8, 8},
        TTL:      30,
    }

    if err := p.WriteTo(h, b, nil); err != nil {
        log.Println(err)
    }
}

TCPdump output:

$ sudo tcpdump -i en0 host 8.8.8.8 -vvv -n -X 
tcpdump: listening on en0, link-type EN10MB (Ethernet), capture size 262144 bytes
    
11:56:56.261756 IP (tos 0x0, ttl 30, id 12345, offset 0, flags [none], proto ICMP (1), length 35)
    17.236.28.116 > 8.8.8.8: ICMP type-#72, length 15 (wrong icmp cksum 4c4c (->e297)!)
	0x0000:  4500 0023 3039 0000 1e01 2e32 11ec 1c74  E..#09.....2...t
	0x0010:  0808 0808 4845 4c4c 4f2d 522d 552d 5448  ....HELLO-R-U-TH
	0x0020:  4552 45                                  ERE

@ALTree ALTree added the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label Feb 25, 2020
@hipatrickpark
Copy link
Author

@hipatrickpark hipatrickpark commented Mar 9, 2020

Identified that the cause was on my wireless network setting which resets the TOS bits.

@golang golang locked and limited conversation to collaborators Mar 9, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Projects
None yet
Development

No branches or pull requests

3 participants