7 Commits

Author SHA1 Message Date
1049057f69 Set the recursion available flag 2020-06-23 02:16:56 -07:00
0622e00f64 Add JSON tags 2020-06-23 02:16:56 -07:00
c0f98d4a25 DNS changes
go mod tidy
2020-06-23 02:16:53 -07:00
db53b259a6 Add the ability to run router7 on a normal Linux distribution 2020-06-17 06:13:07 -07:00
1250211381 github actions: try caching the module cache 2020-06-16 23:41:21 +02:00
9c7e626f7d switch from travis to GitHub actions 2020-06-16 23:22:34 +02:00
b090fa2924 qemu: enable i6300esb watchdog device
For the corresponding kernel change, see:
0f4dcc4a87
2020-06-16 23:09:35 +02:00
4 changed files with 146 additions and 68 deletions

102
.github/workflows/go.yml vendored Normal file
View 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 ]

View File

@ -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

View File

@ -9,7 +9,7 @@ PKGS := github.com/rtr7/router7/cmd/... \
build:
mkdir -p result
GOOS=linux go build -o ./result github.com/rtr7/router7/cmd/...
GOOS=linux go build -o ./result/rtr7-init -ldflags "-X main.buildTimestamp=$(shell date '+%Y-%m-%dT%H:%M:%S%z') -X github.com/gokrazy/gokrazy.httpPassword=temp" init/init.go
GOOS=linux go build -o ./result/rtr7-init -ldflags "-X main.buildTimestamp=$(shell date '+%Y-%m-%dT%H:%M:%S%z') -X github.com/gokrazy/gokrazy.httpPassword=hello" init/init.go
clean:
rm -rf result
@ -94,6 +94,7 @@ qemu:
-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,id=lan,mac=52:55:00:d1:55:04 \
-device i6300esb,id=watchdog0 -watchdog-action reset \
-smp 8 \
-machine accel=kvm \
-m 4096 \

View File

@ -44,9 +44,9 @@ var log = teelogger.NewConsole()
type lcHostname string
type IP struct {
IPv6 net.IP
IPv4 net.IP
Host lcHostname // lease that the IPs are updated from. If no lease exists for this host it is never updated.
IPv6 net.IP `json:"ipv6"`
IPv4 net.IP `json:"ipv4"`
Host lcHostname `json:"host"` // lease that the IPs are updated from. If no lease exists for this host it is never updated.
}
type Server struct {
@ -172,43 +172,40 @@ func (m measurement) String() string {
}
func (s *Server) probeUpstreamLatency() {
if !s.once {
s.once = true
upstreams := s.upstreams()
results := make([]measurement, len(upstreams))
var wg sync.WaitGroup
for idx, u := range upstreams {
wg.Add(1)
go func(idx int, u string) {
defer wg.Done()
// resolve a most-definitely cached record
m := new(dns.Msg)
m.SetQuestion("google.ch.", dns.TypeA)
start := time.Now()
_, _, err := s.client.Exchange(m, u)
rtt := time.Since(start)
if err != nil {
// including unresponsive upstreams in results makes the update
// code simpler:
results[idx] = measurement{u, time.Duration(math.MaxInt64)}
return
}
results[idx] = measurement{u, rtt}
}(idx, u)
}
wg.Wait()
// Re-order by resolving latency:
sort.Slice(results, func(i, j int) bool {
return results[i].rtt < results[j].rtt
})
log.Printf("probe results: %v %v", s.once, results)
for idx, result := range results {
upstreams[idx] = result.upstream
}
s.upstreamMu.Lock()
defer s.upstreamMu.Unlock()
s.upstream = upstreams
upstreams := s.upstreams()
results := make([]measurement, len(upstreams))
var wg sync.WaitGroup
for idx, u := range upstreams {
wg.Add(1)
go func(idx int, u string) {
defer wg.Done()
// resolve a most-definitely cached record
m := new(dns.Msg)
m.SetQuestion("google.ch.", dns.TypeA)
start := time.Now()
_, _, err := s.client.Exchange(m, u)
rtt := time.Since(start)
if err != nil {
// including unresponsive upstreams in results makes the update
// code simpler:
results[idx] = measurement{u, time.Duration(math.MaxInt64)}
return
}
results[idx] = measurement{u, rtt}
}(idx, u)
}
wg.Wait()
// Re-order by resolving latency:
sort.Slice(results, func(i, j int) bool {
return results[i].rtt < results[j].rtt
})
log.Printf("probe results: %v", results)
for idx, result := range results {
upstreams[idx] = result.upstream
}
s.upstreamMu.Lock()
defer s.upstreamMu.Unlock()
s.upstream = upstreams
}
func (s *Server) hostByName(n lcHostname) (string, bool) {
@ -480,6 +477,7 @@ func (s *Server) handleInternal(w dns.ResponseWriter, r *dns.Msg) {
if err == errEmpty {
m := new(dns.Msg)
m.SetReply(r)
m.RecursionAvailable = true
w.WriteMsg(m)
return
}
@ -488,6 +486,7 @@ func (s *Server) handleInternal(w dns.ResponseWriter, r *dns.Msg) {
if rr != nil {
m := new(dns.Msg)
m.SetReply(r)
m.RecursionAvailable = true
m.Answer = append(m.Answer, rr)
w.WriteMsg(m)
return
@ -495,6 +494,7 @@ func (s *Server) handleInternal(w dns.ResponseWriter, r *dns.Msg) {
// Send an authoritative NXDOMAIN for local:
m := new(dns.Msg)
m.SetReply(r)
m.RecursionAvailable = true
m.SetRcode(r, dns.RcodeNameError)
w.WriteMsg(m)
}
@ -582,6 +582,7 @@ func (s *Server) subnameHandler(hostname lcHostname) func(w dns.ResponseWriter,
if err == errEmpty {
m := new(dns.Msg)
m.SetReply(r)
m.RecursionAvailable = true
w.WriteMsg(m)
return
}
@ -591,6 +592,7 @@ func (s *Server) subnameHandler(hostname lcHostname) func(w dns.ResponseWriter,
s.promInc("local", r)
m := new(dns.Msg)
m.SetReply(r)
m.RecursionAvailable = true
m.Answer = append(m.Answer, rr)
w.WriteMsg(m)
return
@ -601,6 +603,7 @@ func (s *Server) subnameHandler(hostname lcHostname) func(w dns.ResponseWriter,
s.promInc("local", r)
m := new(dns.Msg)
m.SetReply(r)
m.RecursionAvailable = true
m.SetRcode(r, dns.RcodeNameError)
w.WriteMsg(m)
return