diff --git a/.circleci/config.yml b/.circleci/config.yml index 510eacc..da7e498 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -13,17 +13,21 @@ jobs: cp deploy/* . mkdir artifacts - run: - name: build linux Binary + name: Run Unit Test + command: | + make test + - run: + name: Build linux Binary command: | make build tar czvf artifacts/sower_linux_amd64.tar.gz sower sower.toml sower-client.service sower-server.service - run: - name: build macOS Binary + name: Build macOS Binary command: | GOOS=darwin GOARCH=amd64 make build tar czvf artifacts/sower_darwin_amd64.tar.gz sower sower.toml cc.wweir.sower.plist - run: - name: build Windows Binary + name: Build Windows Binary command: | GOOS=windows GOARCH=amd64 make build tar czvf artifacts/sower_windows_amd64.tar.gz sower sower.toml @@ -38,7 +42,7 @@ jobs: ghr -t ${GITHUB_TOKEN} -u ${CIRCLE_PROJECT_USERNAME} -r ${CIRCLE_PROJECT_REPONAME} -c ${CIRCLE_SHA1} -delete ${VERSION%-*-*} artifacts/ fi - run: - name: build docker image + name: Build Docker Image command: | if git log -1 --pretty='%s' | grep -oE '(^|\s)@release(\s|$)'; then docker login -u $DOCKER_USER -p $DOCKER_PASS diff --git a/conf/sower.toml b/conf/sower.toml index 6ef9197..ffb55c1 100644 --- a/conf/sower.toml +++ b/conf/sower.toml @@ -28,6 +28,8 @@ blocklist=[ "**.amazon.com", "**.amazonaws.com", "*.githubusercontent.com", + "*.github.com", + "*.github.io", "**.mozilla.com", "**.mozilla.net", "**.akadns.net", diff --git a/dns/dns.go b/dns/dns.go index d486316..e70298c 100644 --- a/dns/dns.go +++ b/dns/dns.go @@ -27,7 +27,7 @@ func StartDNS(dnsServer, listenIP string) { go func() { for { <-dhcpCh - host := GetDefaultDNSServer() + host := util.GetDefaultDNSServer() if host == "" { continue } diff --git a/go.mod b/go.mod index 34cb833..9fc5d9d 100644 --- a/go.mod +++ b/go.mod @@ -6,11 +6,11 @@ require ( github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b github.com/hashicorp/golang-lru v0.5.0 // indirect github.com/klauspost/cpuid v1.2.0 // indirect - github.com/klauspost/reedsolomon v1.8.0 // indirect + github.com/klauspost/reedsolomon v1.9.0 // indirect github.com/lucas-clemente/aes12 v0.0.0-20171027163421-cd47fb39b79f // indirect github.com/lucas-clemente/quic-go v0.10.1 github.com/lucas-clemente/quic-go-certificates v0.0.0-20160823095156-d2f86524cced // indirect - github.com/miekg/dns v1.1.3 + github.com/miekg/dns v1.1.4 github.com/pelletier/go-toml v1.2.0 github.com/pkg/errors v0.8.1 github.com/templexxx/cpufeat v0.0.0-20180724012125-cef66df7f161 // indirect @@ -21,7 +21,7 @@ require ( github.com/wweir/mem-go v0.0.0-20190109100331-8673ab596296 github.com/wweir/netboot v0.0.2 github.com/xtaci/kcp-go v5.0.7+incompatible - golang.org/x/crypto v0.0.0-20190123085648-057139ce5d2b - golang.org/x/net v0.0.0-20190125091013-d26f9f9a57f3 // indirect - golang.org/x/sys v0.0.0-20190124100055-b90733256f2e // indirect + golang.org/x/crypto v0.0.0-20190211182817-74369b46fc67 + golang.org/x/net v0.0.0-20190213061140-3a22650c66bd // indirect + golang.org/x/sys v0.0.0-20190213121743-983097b1a8a3 // indirect ) diff --git a/go.sum b/go.sum index 28c24a9..1ca7d57 100644 --- a/go.sum +++ b/go.sum @@ -8,16 +8,16 @@ github.com/hashicorp/golang-lru v0.5.0 h1:CL2msUPvZTLb5O648aiLNJw3hnBxN2+1Jq8rCO github.com/hashicorp/golang-lru v0.5.0/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8= github.com/klauspost/cpuid v1.2.0 h1:NMpwD2G9JSFOE1/TJjGSo5zG7Yb2bTe7eq1jH+irmeE= github.com/klauspost/cpuid v1.2.0/go.mod h1:Pj4uuM528wm8OyEC2QMXAi2YiTZ96dNQPGgoMS4s3ek= -github.com/klauspost/reedsolomon v1.8.0 h1:lvvOkvk64cE1EGbBIgFk7WSOOsI1GexpuLiT7zjab6g= -github.com/klauspost/reedsolomon v1.8.0/go.mod h1:CwCi+NUr9pqSVktrkN+Ondf06rkhYZ/pcNv7fu+8Un4= +github.com/klauspost/reedsolomon v1.9.0 h1:usyTY5K7D2B6WOHn2jmpB7ky8Qom96mShZmmq3OW4JU= +github.com/klauspost/reedsolomon v1.9.0/go.mod h1:CwCi+NUr9pqSVktrkN+Ondf06rkhYZ/pcNv7fu+8Un4= github.com/lucas-clemente/aes12 v0.0.0-20171027163421-cd47fb39b79f h1:sSeNEkJrs+0F9TUau0CgWTTNEwF23HST3Eq0A+QIx+A= github.com/lucas-clemente/aes12 v0.0.0-20171027163421-cd47fb39b79f/go.mod h1:JpH9J1c9oX6otFSgdUHwUBUizmKlrMjxWnIAjff4m04= github.com/lucas-clemente/quic-go v0.10.1 h1:ipcMmYP9RT+b1YytOKGUY1qndxPGOczVEQkAVz3CZrs= github.com/lucas-clemente/quic-go v0.10.1/go.mod h1:wuD+2XqEx8G9jtwx5ou2BEYBsE+whgQmlj0Vz/77PrY= github.com/lucas-clemente/quic-go-certificates v0.0.0-20160823095156-d2f86524cced h1:zqEC1GJZFbGZA0tRyNZqRjep92K5fujFtFsu5ZW7Aug= github.com/lucas-clemente/quic-go-certificates v0.0.0-20160823095156-d2f86524cced/go.mod h1:NCcRLrOTZbzhZvixZLlERbJtDtYsmMw8Jc4vS8Z0g58= -github.com/miekg/dns v1.1.3 h1:1g0r1IvskvgL8rR+AcHzUA+oFmGcQlaIm4IqakufeMM= -github.com/miekg/dns v1.1.3/go.mod h1:W1PPwlIAgtquWBMBEV9nkV9Cazfe8ScdGz/Lj7v3Nrg= +github.com/miekg/dns v1.1.4 h1:rCMZsU2ScVSYcAsOXgmC6+AKOK+6pmQTOcw03nfwYV0= +github.com/miekg/dns v1.1.4/go.mod h1:W1PPwlIAgtquWBMBEV9nkV9Cazfe8ScdGz/Lj7v3Nrg= github.com/pelletier/go-toml v1.2.0 h1:T5zMGML61Wp+FlcbWjRDT7yAxhJNAiPPLOFECq181zc= github.com/pelletier/go-toml v1.2.0/go.mod h1:5z9KED0ma1S8pY6P1sdut58dfprrGBbd/94hg7ilaic= github.com/pkg/errors v0.8.1 h1:iURUrRGxPUNPdy5/HRSm+Yj6okJ6UtLINN0Q9M4+h3I= @@ -38,9 +38,9 @@ github.com/wweir/netboot v0.0.2 h1:DFuNd97kxzgblExEKn4Nqf1du0m9qUnaTQ70rFgIjLU= github.com/wweir/netboot v0.0.2/go.mod h1:p/WOnPHdqwgAI6YLEfdmwjwutbc/zDZ7EojAHlXLi4s= github.com/xtaci/kcp-go v5.0.7+incompatible h1:zs9tc8XRID0m+aetu3qPWZFyRt2UIMqbXIBgw+vcnlE= github.com/xtaci/kcp-go v5.0.7+incompatible/go.mod h1:bN6vIwHQbfHaHtFpEssmWsN45a+AZwO7eyRCmEIbtvE= -golang.org/x/crypto v0.0.0-20190123085648-057139ce5d2b h1:Elez2XeF2p9uyVj0yEUDqQ56NFcDtcBNkYP7yv8YbUE= -golang.org/x/crypto v0.0.0-20190123085648-057139ce5d2b/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= -golang.org/x/net v0.0.0-20190125091013-d26f9f9a57f3 h1:ulvT7fqt0yHWzpJwI57MezWnYDVpCAYBVuYst/L+fAY= -golang.org/x/net v0.0.0-20190125091013-d26f9f9a57f3/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= -golang.org/x/sys v0.0.0-20190124100055-b90733256f2e h1:3GIlrlVLfkoipSReOMNAgApI0ajnalyLa/EZHHca/XI= -golang.org/x/sys v0.0.0-20190124100055-b90733256f2e/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/crypto v0.0.0-20190211182817-74369b46fc67 h1:ng3VDlRp5/DHpSWl02R4rM9I+8M2rhmsuLwAMmkLQWE= +golang.org/x/crypto v0.0.0-20190211182817-74369b46fc67/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= +golang.org/x/net v0.0.0-20190213061140-3a22650c66bd h1:HuTn7WObtcDo9uEEU7rEqL0jYthdXAmZ6PP+meazmaU= +golang.org/x/net v0.0.0-20190213061140-3a22650c66bd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= +golang.org/x/sys v0.0.0-20190213121743-983097b1a8a3 h1:+KlxhGbYkFs8lMfwKn+2ojry1ID5eBSMXprS2u/wqCE= +golang.org/x/sys v0.0.0-20190213121743-983097b1a8a3/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= diff --git a/dns/dhcp.go b/util/dhcp.go similarity index 90% rename from dns/dhcp.go rename to util/dhcp.go index 9d8f34d..636d1d4 100644 --- a/dns/dhcp.go +++ b/util/dhcp.go @@ -1,8 +1,9 @@ -package dns +package util import ( "math/rand" "net" + "runtime" "github.com/golang/glog" "github.com/wweir/netboot/dhcp4" @@ -19,9 +20,14 @@ func GetDefaultDNSServer() string { dhcp4.OptRequestedOptions: []byte{byte(dhcp4.OptDNSServers)}, } + NewConn := dhcp4.NewConn + if runtime.GOOS == "linux" { + NewConn = dhcp4.NewSnooperConn + } + ifaces := mustGetInterfaces() for _, iface := range ifaces { - conn, err := dhcp4.NewConn(iface.IP.String() + ":68") + conn, err := NewConn(iface.IP.String() + ":68") if err != nil { // maybe in use glog.V(1).Infoln(err) continue diff --git a/dns/dhcp_test.go b/util/dhcp_test.go similarity index 51% rename from dns/dhcp_test.go rename to util/dhcp_test.go index 18b9a8b..8538e6f 100644 --- a/dns/dhcp_test.go +++ b/util/dhcp_test.go @@ -1,20 +1,19 @@ -package dns +package util import "testing" func TestGetDefaultDNSServer(t *testing.T) { - t.Skip("for net env") + t.Skip("skip for some enviroment not support dhcp") + tests := []struct { name string - want string }{{ "", - "192.168.1.1", }} for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { - if got := GetDefaultDNSServer(); got != tt.want { - t.Errorf("GetDefaultDNSServer() = %v, want %v", got, tt.want) + if got := GetDefaultDNSServer(); got == "" { + t.Errorf("GetDefaultDNSServer() return empty") } }) }