diff --git a/.travis.yml b/.travis.yml index ff3d7e14..d8680645 100644 --- a/.travis.yml +++ b/.travis.yml @@ -4,6 +4,9 @@ before_install: windows) export MAKE=mingw32-make ;; + freebsd) + export MAKE=gmake + ;; *) export MAKE=make ;; @@ -11,18 +14,19 @@ before_install: dist: focal language: go go: -- 1.15.x -script: -- $MAKE +- 1.16.x branches: only: - - master - "/v\\d+\\.\\d+\\.\\d+/" matrix: include: - os: linux + arch: amd64 + - os: linux + arch: arm64 - os: osx - os: windows + - os: freebsd before_deploy: - $MAKE deploy: diff --git a/Makefile b/Makefile index eade2626..fe590063 100644 --- a/Makefile +++ b/Makefile @@ -4,45 +4,26 @@ GOCLEAN=$(GOCMD) clean VERSION=$(shell git describe --tags) DEBUG_LDFLAGS='' RELEASE_LDFLAGS='-s -w -X main.version=$(VERSION)' -STATIC_RELEASE_LDFLAGS='-s -w -X main.version=$(VERSION) -extldflags "-static"' BUILD_TAGS?=socks BUILDDIR=$(shell pwd)/build CMDDIR=$(shell pwd)/cmd/tun2socks PROGRAM=tun2socks GOOS:=$(strip $(shell go env GOOS)) +GOARCH:=$(strip $(shell go env GOARCH)) ifeq "$(GOOS)" "windows" SUFFIX=.exe endif -ifeq "$(GOOS)" "freebsd" -# customized vendor dir with a patch -$(shell go mod vendor) -$(shell patch -si freebsd.patch) -GOBUILD := $(GOBUILD) -mod=vendor -endif - -BUILD_CMD="cd $(CMDDIR) && $(GOBUILD) -ldflags $(RELEASE_LDFLAGS) -o $(BUILDDIR)/$(PROGRAM)_$(GOOS)$(SUFFIX) -v -tags '$(BUILD_TAGS)'" - .PHONY: build -all: build +all: fmt build build: - mkdir -p $(BUILDDIR) - eval $(BUILD_CMD) - -xbuild_linux: - mkdir -p $(BUILDDIR) - eval $(XBUILD_LINUX_CMD) - -xbuild_others: - mkdir -p $(BUILDDIR) - eval $(XBUILD_OTHERS_CMD) - -xbuild: xbuild_linux xbuild_others + $(GOBUILD) -ldflags $(RELEASE_LDFLAGS) -o $(BUILDDIR)/$(PROGRAM)_$(GOOS)_$(GOARCH)$(SUFFIX) -v -tags '$(BUILD_TAGS)' $(CMDDIR) -travisbuild: xbuild +fmt: + gofmt -w -s . clean: rm -rf $(BUILDDIR) diff --git a/freebsd.patch b/freebsd.patch deleted file mode 100644 index 30e3ed3c..00000000 --- a/freebsd.patch +++ /dev/null @@ -1,45 +0,0 @@ -diff --git a/vendor/golang.zx2c4.com/wireguard/tun/tun_freebsd.go b/vendor/golang.zx2c4.com/wireguard/tun/tun_freebsd.go -index 174e7f8..2cb3ea7 100644 ---- a/vendor/golang.zx2c4.com/wireguard/tun/tun_freebsd.go -+++ b/vendor/golang.zx2c4.com/wireguard/tun/tun_freebsd.go -@@ -344,22 +344,24 @@ func CreateTUN(name string, mtu int) (Device, error) { - return nil, fmt.Errorf("Unable to set nd6 flags for %s: %w", assignedName, errno) - } - -- // Rename the interface -- var newnp [unix.IFNAMSIZ]byte -- copy(newnp[:], name) -- var ifr ifreq_ptr -- copy(ifr.Name[:], assignedName) -- ifr.Data = uintptr(unsafe.Pointer(&newnp[0])) -- _, _, errno = unix.Syscall( -- unix.SYS_IOCTL, -- uintptr(confd), -- uintptr(unix.SIOCSIFNAME), -- uintptr(unsafe.Pointer(&ifr)), -- ) -- if errno != 0 { -- tunFile.Close() -- tunDestroy(assignedName) -- return nil, fmt.Errorf("Failed to rename %s to %s: %w", assignedName, name, errno) -+ if name != "" { -+ // Rename the interface -+ var newnp [unix.IFNAMSIZ]byte -+ copy(newnp[:], name) -+ var ifr ifreq_ptr -+ copy(ifr.Name[:], assignedName) -+ ifr.Data = uintptr(unsafe.Pointer(&newnp[0])) -+ _, _, errno = unix.Syscall( -+ unix.SYS_IOCTL, -+ uintptr(confd), -+ uintptr(unix.SIOCSIFNAME), -+ uintptr(unsafe.Pointer(&ifr)), -+ ) -+ if errno != 0 { -+ tunFile.Close() -+ tunDestroy(assignedName) -+ return nil, fmt.Errorf("Failed to rename %s to %s: %w", assignedName, name, errno) -+ } - } - - return CreateTUNFromFile(tunFile, mtu) diff --git a/go.mod b/go.mod index 1ac8a043..aa6ace41 100644 --- a/go.mod +++ b/go.mod @@ -1,12 +1,15 @@ module github.com/eycorsican/go-tun2socks -go 1.13 +go 1.15 require ( github.com/IBM/netaddr v1.4.0 github.com/stretchr/testify v1.6.1 // indirect github.com/vishvananda/netlink v1.1.0 - golang.org/x/net v0.0.0-20201201195509-5d6afe98e0b7 - golang.org/x/sys v0.0.0-20201201145000-ef89a241ccb3 - golang.zx2c4.com/wireguard v0.0.20201119-0.20201127121345-b6303091fc8c + golang.org/x/net v0.0.0-20210224082022-3d97a244fca7 + golang.org/x/sys v0.0.0-20210225014209-683adc9d29d7 + golang.zx2c4.com/wireguard v0.0.0-20210225140808-70b7b7158fc9 ) + +// a fork with a FreeBSD default tun name patch +replace golang.zx2c4.com/wireguard v0.0.0-20210225140808-70b7b7158fc9 => github.com/kayrus/wireguard v0.0.0-20210228102730-04afc3c4c795 diff --git a/go.sum b/go.sum index 621225c0..675f5603 100644 --- a/go.sum +++ b/go.sum @@ -2,6 +2,8 @@ github.com/IBM/netaddr v1.4.0 h1:6T+fAXurIdgA9+nVlehOOkhhxmzU2MTxtok7qNldDVo= github.com/IBM/netaddr v1.4.0/go.mod h1:eXOsTXDZemcAXuuddrfHcWdA0on76PJwaH37JnS5PKE= github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/kayrus/wireguard v0.0.0-20210228102730-04afc3c4c795 h1:jssAOd/ifYICiV/LWyQt1TG0KOu8513mYLuLxfdqLR8= +github.com/kayrus/wireguard v0.0.0-20210228102730-04afc3c4c795/go.mod h1:39ZQQ95hUxDxT7opsWy/rtfgvXXc8s30qfZ02df69Fo= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= @@ -12,26 +14,21 @@ github.com/vishvananda/netlink v1.1.0/go.mod h1:cTgwzPIzzgDAYoQrMm0EdrjRUBkTqKYp github.com/vishvananda/netns v0.0.0-20191106174202-0a2b9b5464df h1:OviZH7qLw/7ZovXvuNyL3XQl8UFofeikI1NW1Gypu7k= github.com/vishvananda/netns v0.0.0-20191106174202-0a2b9b5464df/go.mod h1:JP3t17pCcGlemwknint6hfoeCVQrEMVwxRLRjXpq+BU= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= -golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= -golang.org/x/crypto v0.0.0-20201124201722-c8d3bf9c5392/go.mod h1:jdWPYTVW3xRLrWPugEBEK3UY2ZEsg3UU495nc5E+M+I= +golang.org/x/crypto v0.0.0-20210220033148-5ea612d1eb83/go.mod h1:jdWPYTVW3xRLrWPugEBEK3UY2ZEsg3UU495nc5E+M+I= golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= -golang.org/x/net v0.0.0-20201110031124-69a78807bb2b/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU= -golang.org/x/net v0.0.0-20201201195509-5d6afe98e0b7 h1:3uJsdck53FDIpWwLeAXlia9p4C8j0BO2xZrqzKpL0D8= -golang.org/x/net v0.0.0-20201201195509-5d6afe98e0b7/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU= +golang.org/x/net v0.0.0-20210224082022-3d97a244fca7 h1:OgUuv8lsRpBibGNbSizVwKWlysjaNzmC9gYMhPVfqFM= +golang.org/x/net v0.0.0-20210224082022-3d97a244fca7/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg= golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= -golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20190606203320-7fc4e5ec1444/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20191026070338-33540a1f6037/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20201126233918-771906719818/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20201201145000-ef89a241ccb3 h1:kzM6+9dur93BcC2kVlYl34cHU+TYZLanmpSJHVMmL64= -golang.org/x/sys v0.0.0-20201201145000-ef89a241ccb3/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20210225014209-683adc9d29d7 h1:pk3Y+QnSKjMLfO/HIqzn/Zvv3/IHjRPhwblrmUuodzw= +golang.org/x/sys v0.0.0-20210225014209-683adc9d29d7/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/term v0.0.0-20201117132131-f5c789dd3221/go.mod h1:Nr5EML6q2oocZ2LXRh80K7BxOlk5/8JxuGnuhpl+muw= +golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= -golang.zx2c4.com/wireguard v0.0.20201119-0.20201127121345-b6303091fc8c h1:9hQ0/h+C/WejiYNxvDeY/euDCfmMJBTlUb46+jHTmHs= -golang.zx2c4.com/wireguard v0.0.20201119-0.20201127121345-b6303091fc8c/go.mod h1:MLNavHGuHO1M5coT9hkHgdN8AoJHdUWLpsLKSeR63VE= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo=