Compare commits
8 Commits
Author | SHA1 | Date | |
---|---|---|---|
2e8f91b1af | |||
1049057f69 | |||
0622e00f64 | |||
c0f98d4a25 | |||
db53b259a6 | |||
1250211381 | |||
9c7e626f7d | |||
b090fa2924 |
102
.github/workflows/go.yml
vendored
Normal file
102
.github/workflows/go.yml
vendored
Normal file
@ -0,0 +1,102 @@
|
|||||||
|
name: GitHub Actions CI
|
||||||
|
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
branches: [ master ]
|
||||||
|
pull_request:
|
||||||
|
branches: [ master ]
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
|
||||||
|
build:
|
||||||
|
name: build
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
|
||||||
|
- name: Set up Go 1.x
|
||||||
|
uses: actions/setup-go@v2
|
||||||
|
with:
|
||||||
|
# Run on the latest minor release of Go 1.14:
|
||||||
|
go-version: ^1.14
|
||||||
|
id: go
|
||||||
|
|
||||||
|
- name: Check out code into the Go module directory
|
||||||
|
uses: actions/checkout@v2
|
||||||
|
|
||||||
|
- name: Share cache with other actions
|
||||||
|
uses: actions/cache@v2
|
||||||
|
with:
|
||||||
|
path: ~/go/pkg/mod
|
||||||
|
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
|
||||||
|
restore-keys: |
|
||||||
|
${{ runner.os }}-go-
|
||||||
|
|
||||||
|
- name: Ensure all files were formatted as per gofmt
|
||||||
|
run: |
|
||||||
|
gofmt -l $(find . -name '*.go') >/dev/null
|
||||||
|
|
||||||
|
- name: Go Vet
|
||||||
|
run: |
|
||||||
|
go vet
|
||||||
|
|
||||||
|
- name: Build
|
||||||
|
run: |
|
||||||
|
go build -v ./cmd/...
|
||||||
|
|
||||||
|
test:
|
||||||
|
name: test
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
|
||||||
|
- name: Set up Go 1.x
|
||||||
|
uses: actions/setup-go@v2
|
||||||
|
with:
|
||||||
|
# Run on the latest minor release of Go 1.14:
|
||||||
|
go-version: ^1.14
|
||||||
|
id: go
|
||||||
|
|
||||||
|
- name: Check out code into the Go module directory
|
||||||
|
uses: actions/checkout@v2
|
||||||
|
|
||||||
|
- name: Share cache with other actions
|
||||||
|
uses: actions/cache@v2
|
||||||
|
with:
|
||||||
|
path: ~/go/pkg/mod
|
||||||
|
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
|
||||||
|
restore-keys: |
|
||||||
|
${{ runner.os }}-go-
|
||||||
|
|
||||||
|
- name: Test
|
||||||
|
run: |
|
||||||
|
go test -v -race ./internal/...
|
||||||
|
|
||||||
|
integrationtest:
|
||||||
|
name: integrationtest
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
|
||||||
|
- name: Set up Go 1.x
|
||||||
|
uses: actions/setup-go@v2
|
||||||
|
with:
|
||||||
|
# Run on the latest minor release of Go 1.14:
|
||||||
|
go-version: ^1.14
|
||||||
|
id: go
|
||||||
|
|
||||||
|
- name: Check out code into the Go module directory
|
||||||
|
uses: actions/checkout@v2
|
||||||
|
|
||||||
|
- name: Share cache with other actions
|
||||||
|
uses: actions/cache@v2
|
||||||
|
with:
|
||||||
|
path: ~/go/pkg/mod
|
||||||
|
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
|
||||||
|
restore-keys: |
|
||||||
|
${{ runner.os }}-go-
|
||||||
|
|
||||||
|
- name: Build Docker container with the tools our tests require
|
||||||
|
run: |
|
||||||
|
docker build --pull --no-cache --rm -t=router7 -f travis/Dockerfile .
|
||||||
|
|
||||||
|
- name: Run tests in Docker container
|
||||||
|
run: |
|
||||||
|
exit=0; for pkg in $(go list ./integration/...); do go test -c $pkg && docker run --privileged --net=host -v $PWD:/usr/src:ro router7 /bin/sh -c "./$(basename $pkg).test -test.v" || exit=1; done; [ $exit = 0 ]
|
28
.travis.yml
28
.travis.yml
@ -1,28 +0,0 @@
|
|||||||
# Use the (faster) container-based infrastructure, see also
|
|
||||||
# http://docs.travis-ci.com/user/workers/container-based-infrastructure/
|
|
||||||
sudo: required
|
|
||||||
dist: xenial
|
|
||||||
services:
|
|
||||||
- docker
|
|
||||||
|
|
||||||
language: go
|
|
||||||
go:
|
|
||||||
- "1.14"
|
|
||||||
|
|
||||||
install:
|
|
||||||
- go get -t -v -d ./...
|
|
||||||
|
|
||||||
script:
|
|
||||||
# Check whether files are syntactically correct.
|
|
||||||
- "gofmt -l $(find . -name '*.go' | tr '\\n' ' ') >/dev/null"
|
|
||||||
# Check whether files were not gofmt'ed.
|
|
||||||
- "gosrc=$(find . -name '*.go' | tr '\\n' ' '); [ $(gofmt -l $gosrc 2>&- | wc -l) -eq 0 ] || (echo 'gofmt was not run on these files:'; gofmt -l $gosrc 2>&-; false)"
|
|
||||||
# TODO: remove the || true suffix once vet errors are fixed
|
|
||||||
- go vet . || true
|
|
||||||
- sudo sysctl -w net.ipv6.conf.all.disable_ipv6=0
|
|
||||||
- go build ./cmd/...
|
|
||||||
- go test -v -race ./internal/...
|
|
||||||
- docker build --pull --no-cache --rm -t=router7 -f travis/Dockerfile .
|
|
||||||
- sudo service docker restart
|
|
||||||
# NOTE: this must be the last command because of the travis_terminate usage:
|
|
||||||
- exit=0; for pkg in $(go list ./integration/...); do go test -c $pkg && docker run --privileged --net=host -v $PWD:/usr/src:ro router7 /bin/sh -c "./$(basename $pkg).test -test.v" || exit=1; done; [ $exit = 0 ] || travis_terminate 1
|
|
1
Makefile
1
Makefile
@ -94,6 +94,7 @@ qemu:
|
|||||||
-netdev tap,id=uplink,fd=3 3<>/dev/tap184 \
|
-netdev tap,id=uplink,fd=3 3<>/dev/tap184 \
|
||||||
-device virtio-net-pci,netdev=uplink,mac=52:55:00:d1:55:03 \
|
-device virtio-net-pci,netdev=uplink,mac=52:55:00:d1:55:03 \
|
||||||
-device virtio-net-pci,id=lan,mac=52:55:00:d1:55:04 \
|
-device virtio-net-pci,id=lan,mac=52:55:00:d1:55:04 \
|
||||||
|
-device i6300esb,id=watchdog0 -watchdog-action reset \
|
||||||
-smp 8 \
|
-smp 8 \
|
||||||
-machine accel=kvm \
|
-machine accel=kvm \
|
||||||
-m 4096 \
|
-m 4096 \
|
||||||
|
@ -172,8 +172,6 @@ func (m measurement) String() string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (s *Server) probeUpstreamLatency() {
|
func (s *Server) probeUpstreamLatency() {
|
||||||
if !s.once {
|
|
||||||
s.once = true
|
|
||||||
upstreams := s.upstreams()
|
upstreams := s.upstreams()
|
||||||
results := make([]measurement, len(upstreams))
|
results := make([]measurement, len(upstreams))
|
||||||
var wg sync.WaitGroup
|
var wg sync.WaitGroup
|
||||||
@ -201,7 +199,7 @@ func (s *Server) probeUpstreamLatency() {
|
|||||||
sort.Slice(results, func(i, j int) bool {
|
sort.Slice(results, func(i, j int) bool {
|
||||||
return results[i].rtt < results[j].rtt
|
return results[i].rtt < results[j].rtt
|
||||||
})
|
})
|
||||||
log.Printf("probe results: %v %v", s.once, results)
|
log.Printf("probe results: %v", results)
|
||||||
for idx, result := range results {
|
for idx, result := range results {
|
||||||
upstreams[idx] = result.upstream
|
upstreams[idx] = result.upstream
|
||||||
}
|
}
|
||||||
@ -209,7 +207,6 @@ func (s *Server) probeUpstreamLatency() {
|
|||||||
defer s.upstreamMu.Unlock()
|
defer s.upstreamMu.Unlock()
|
||||||
s.upstream = upstreams
|
s.upstream = upstreams
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
func (s *Server) hostByName(n lcHostname) (string, bool) {
|
func (s *Server) hostByName(n lcHostname) (string, bool) {
|
||||||
s.mu.Lock()
|
s.mu.Lock()
|
||||||
@ -480,6 +477,7 @@ func (s *Server) handleInternal(w dns.ResponseWriter, r *dns.Msg) {
|
|||||||
if err == errEmpty {
|
if err == errEmpty {
|
||||||
m := new(dns.Msg)
|
m := new(dns.Msg)
|
||||||
m.SetReply(r)
|
m.SetReply(r)
|
||||||
|
m.RecursionAvailable = true
|
||||||
w.WriteMsg(m)
|
w.WriteMsg(m)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -488,6 +486,7 @@ func (s *Server) handleInternal(w dns.ResponseWriter, r *dns.Msg) {
|
|||||||
if rr != nil {
|
if rr != nil {
|
||||||
m := new(dns.Msg)
|
m := new(dns.Msg)
|
||||||
m.SetReply(r)
|
m.SetReply(r)
|
||||||
|
m.RecursionAvailable = true
|
||||||
m.Answer = append(m.Answer, rr)
|
m.Answer = append(m.Answer, rr)
|
||||||
w.WriteMsg(m)
|
w.WriteMsg(m)
|
||||||
return
|
return
|
||||||
@ -495,6 +494,7 @@ func (s *Server) handleInternal(w dns.ResponseWriter, r *dns.Msg) {
|
|||||||
// Send an authoritative NXDOMAIN for local:
|
// Send an authoritative NXDOMAIN for local:
|
||||||
m := new(dns.Msg)
|
m := new(dns.Msg)
|
||||||
m.SetReply(r)
|
m.SetReply(r)
|
||||||
|
m.RecursionAvailable = true
|
||||||
m.SetRcode(r, dns.RcodeNameError)
|
m.SetRcode(r, dns.RcodeNameError)
|
||||||
w.WriteMsg(m)
|
w.WriteMsg(m)
|
||||||
}
|
}
|
||||||
@ -550,6 +550,7 @@ func (s *Server) resolveSubname(domain string, q dns.Question) (dns.RR, error) {
|
|||||||
name := strings.TrimSuffix(q.Name, ".")
|
name := strings.TrimSuffix(q.Name, ".")
|
||||||
name = strings.TrimSuffix(name, "."+string(s.domain)) // trim server domain
|
name = strings.TrimSuffix(name, "."+string(s.domain)) // trim server domain
|
||||||
name = strings.TrimSuffix(name, "."+strings.TrimSuffix(domain, "."+string(s.domain))) // trim function domain
|
name = strings.TrimSuffix(name, "."+strings.TrimSuffix(domain, "."+string(s.domain))) // trim function domain
|
||||||
|
name = strings.TrimSuffix(name, ".lan") // trim function domain
|
||||||
if ip, ok := s.subname(domain, name); ok {
|
if ip, ok := s.subname(domain, name); ok {
|
||||||
if q.Qtype == dns.TypeA && ip.IPv4.To4() != nil {
|
if q.Qtype == dns.TypeA && ip.IPv4.To4() != nil {
|
||||||
return dns.NewRR(q.Name + " 3600 IN A " + ip.IPv4.String())
|
return dns.NewRR(q.Name + " 3600 IN A " + ip.IPv4.String())
|
||||||
@ -582,6 +583,7 @@ func (s *Server) subnameHandler(hostname lcHostname) func(w dns.ResponseWriter,
|
|||||||
if err == errEmpty {
|
if err == errEmpty {
|
||||||
m := new(dns.Msg)
|
m := new(dns.Msg)
|
||||||
m.SetReply(r)
|
m.SetReply(r)
|
||||||
|
m.RecursionAvailable = true
|
||||||
w.WriteMsg(m)
|
w.WriteMsg(m)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -591,6 +593,7 @@ func (s *Server) subnameHandler(hostname lcHostname) func(w dns.ResponseWriter,
|
|||||||
s.promInc("local", r)
|
s.promInc("local", r)
|
||||||
m := new(dns.Msg)
|
m := new(dns.Msg)
|
||||||
m.SetReply(r)
|
m.SetReply(r)
|
||||||
|
m.RecursionAvailable = true
|
||||||
m.Answer = append(m.Answer, rr)
|
m.Answer = append(m.Answer, rr)
|
||||||
w.WriteMsg(m)
|
w.WriteMsg(m)
|
||||||
return
|
return
|
||||||
@ -601,6 +604,7 @@ func (s *Server) subnameHandler(hostname lcHostname) func(w dns.ResponseWriter,
|
|||||||
s.promInc("local", r)
|
s.promInc("local", r)
|
||||||
m := new(dns.Msg)
|
m := new(dns.Msg)
|
||||||
m.SetReply(r)
|
m.SetReply(r)
|
||||||
|
m.RecursionAvailable = true
|
||||||
m.SetRcode(r, dns.RcodeNameError)
|
m.SetRcode(r, dns.RcodeNameError)
|
||||||
w.WriteMsg(m)
|
w.WriteMsg(m)
|
||||||
return
|
return
|
||||||
|
Reference in New Issue
Block a user