Dawnline 0.20.0
Build packages / CI (push) Blocked by required conditions
Build packages / Version (push) Waiting to run
CI / Web (format, types, tests, bundles) (push) Blocked by required conditions
CI / ShellCheck (push) Blocked by required conditions
CI / Backend (Go: vet, tests, a real ubusd and uhttpd) (push) Blocked by required conditions
CI / Package files (push) Blocked by required conditions
Build packages / CI (push) Blocked by required conditions
Build packages / Version (push) Waiting to run
CI / Web (format, types, tests, bundles) (push) Blocked by required conditions
CI / ShellCheck (push) Blocked by required conditions
CI / Backend (Go: vet, tests, a real ubusd and uhttpd) (push) Blocked by required conditions
CI / Package files (push) Blocked by required conditions
- **Backend rewritten in Go.** One daemon, `dawnlined`, replaces the whole ucode backend: the rpcd plugin, the agent, the CLI and the updater. The package no longer depends on ucode. - **Per-architecture builds.** The release carries the backend for arm64, ARMv7, mips, mipsle and amd64; the router fetches its own after the package is installed and checks its sha256. Dawnline does not run on other architectures (older ARM, 32-bit x86, RISC-V). - **Faster on the router.** A firewall sync takes 0.06 s instead of 0.9 s; a full apply takes about 300 ms. The portal is served by the daemon itself, without a CGI process per request. - **Live pages.** The admin and the portal follow a live stream from the router instead of re-fetching the whole state every 30 seconds. - **Admin redesigned in the portal's style.** Three sections (Overview · Log · Settings); a server is a page of its own with People, Places and Settings; a device opens as a dialog over its person. - **Changes wait for «Apply».** Every setting, and a person's access, is staged in one dock before it reaches the router. - **Configuration rollout.** After a change that makes devices fetch their configuration again, the admin shows how many have fetched it and who has not. Every setting shows beforehand (⟳N) how many devices it will touch. - **Waiting for a decision.** Overview and People put first the people who need one (access ended, limit reached, a device that does not connect), each with its one action a tap away. - **Bulk actions on people.** «Select» (or a long press on a card) picks several people to extend by a month, pause or resume at once. - **Undo.** An action done from a card or a request is undone from its toast. - **Update dialogs redesigned.** An update is one view from its question to its result; Dawnline's own update runs in it like every other, and the page reloads itself once the new version answers. Other versions are a list, each with its notes and Install on a page of its own. - **Site to site: networks behind a router.** A router connected as a device can have networks behind it (up to eight, /16 to /30): the server routes them and applies the router's access to them. A network that shares addresses with a tunnel, the router's own networks or another site is refused by name. - **Routers from the portal.** People can add a router and name its networks on their own page; the admin accepts or declines with a reason, or lets them through without asking. - **Check access and Health know the networks behind routers.** - **Usage limits reworked.** A monthly limit no longer follows the calendar. A person's month starts with their first traffic and ends a month later; the next one starts only when they connect again, so time away uses up none of it. Before, everyone's limit reset on the 1st. - Extra data lasts until that person's month ends; «Reset usage» starts the month anew. - A limit is for a month or for the whole term; the admin and the portal show when it resets. - Charts that said «this month» show the last 30 days. - After the update nobody loses what was counted: the month that was running becomes the person's first and ends on the 1st. - **Access by time of day removed.** The Hours limit is gone from the admin, the portal and the backend; saved hours are dropped. - **Expiry simplified.** An end date always stops access, with a heads-up three days before; the per-person choice is gone. - **No false disconnects from sleeping phones.** A phone or a tablet stays online through ten minutes of silence. - **Mobile Safari fixes.** Pressing a control no longer sends the page to its top; tab tracks that do not fit scroll; switches animate after a press.
This commit is contained in:
1 parent
f8130e39a8
commit
ac90575b0b
788 files changed
+139244
-41720
No files matched your search
@@ -0,0 +1,334 @@
|
||||
package health
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"regexp"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"github.com/tickcount/luci-app-dawnline/backend/awg"
|
||||
"github.com/tickcount/luci-app-dawnline/backend/disguise"
|
||||
"github.com/tickcount/luci-app-dawnline/backend/endpoint"
|
||||
"github.com/tickcount/luci-app-dawnline/backend/i18n"
|
||||
"github.com/tickcount/luci-app-dawnline/backend/ipnet"
|
||||
"github.com/tickcount/luci-app-dawnline/backend/model"
|
||||
"github.com/tickcount/luci-app-dawnline/backend/uci"
|
||||
)
|
||||
|
||||
// ModelErrors is what is wrong with people and devices, as sentences in t's language (dawnline.core
|
||||
// model_errors): what the sync would have to leave out, or what points at something that does not exist.
|
||||
// Empty when the settings are consistent.
|
||||
func ModelErrors(m *model.Model, t *i18n.Catalog) []string {
|
||||
errs := []string{}
|
||||
codes := map[string]string{}
|
||||
for _, id := range m.PersonIDs() {
|
||||
p := m.People[id]
|
||||
if p.Server != "" && m.Servers[p.Server] == nil {
|
||||
errs = append(errs, fmt.Sprintf(t.T("Person %s: server %s does not exist."), p.Name, p.Server))
|
||||
}
|
||||
if p.Circle != "" && m.Circles[p.Circle] == nil {
|
||||
errs = append(errs, fmt.Sprintf(t.T("Person %s: circle %s does not exist."), p.Name, p.Circle))
|
||||
}
|
||||
for _, sid := range p.Services {
|
||||
if m.Services[sid] == nil {
|
||||
errs = append(errs, fmt.Sprintf(t.T("Person %s: home service %s does not exist."), p.Name, sid))
|
||||
}
|
||||
}
|
||||
if p.Code != "" {
|
||||
if other, twice := codes[p.Code]; twice {
|
||||
errs = append(errs, fmt.Sprintf(t.T("Person %s: has the same personal link as %s."), p.Name, other))
|
||||
}
|
||||
codes[p.Code] = p.Name
|
||||
}
|
||||
}
|
||||
type holder struct{ device, person string }
|
||||
addrs := map[string]holder{}
|
||||
for _, id := range m.DeviceIDs() {
|
||||
d := m.Devices[id]
|
||||
p := m.People[d.Person]
|
||||
if p == nil {
|
||||
errs = append(errs, fmt.Sprintf(t.T("Device %s: person %s does not exist."), d.Name, d.Person))
|
||||
continue
|
||||
}
|
||||
say := func(msg string, args ...any) {
|
||||
errs = append(errs, fmt.Sprintf(t.T(msg), append([]any{d.Name, p.Name}, args...)...))
|
||||
}
|
||||
if !awg.ValidKey(d.PublicKey) {
|
||||
say("Device %s of %s: the public key is not a key.")
|
||||
}
|
||||
if d.PrivateKey != "" && !awg.ValidKey(d.PrivateKey) {
|
||||
say("Device %s of %s: the private key is not a key.")
|
||||
}
|
||||
if d.PresharedKey != "" && !awg.ValidKey(d.PresharedKey) {
|
||||
say("Device %s of %s: the preshared key is not a key.")
|
||||
}
|
||||
// its own link values (0 / nil: the server's); one out of range is never used
|
||||
if d.MTU != 0 && (d.MTU < 1280 || d.MTU > 1500) {
|
||||
say("Device %s of %s: MTU %d is not between 1280 and 1500.", d.MTU)
|
||||
}
|
||||
if d.Keepalive != nil && (*d.Keepalive < 0 || *d.Keepalive > 600) {
|
||||
say("Device %s of %s: keep-alive %d is not between 0 and 600 seconds.", *d.Keepalive)
|
||||
}
|
||||
n, ok := ipnet.IP(d.Address)
|
||||
if !ok {
|
||||
if d.Address != "" {
|
||||
say("Device %s of %s: address %s is not a plain IPv4 address.", d.Address)
|
||||
} else {
|
||||
say("Device %s of %s: address (none) is not a plain IPv4 address.")
|
||||
}
|
||||
continue
|
||||
}
|
||||
srv := m.Servers[p.Server]
|
||||
// AmneziaWG ignores a peer with the interface's own key
|
||||
if srv != nil && srv.PublicKey != "" && d.PublicKey == srv.PublicKey {
|
||||
say("Device %s of %s: the public key is the server's own.")
|
||||
}
|
||||
if srv != nil {
|
||||
if net, ok := ipnet.Subnet(srv.Subnet); ok {
|
||||
last := uint64(net.Base) + net.Size() - 2
|
||||
if n < net.First() || uint64(n) > last {
|
||||
say("Device %s of %s: address %s is outside %s's tunnel %s.", d.Address, srv.Name, srv.Subnet)
|
||||
} else if n == net.First() {
|
||||
say("Device %s of %s: address %s is the router's own address on %s.", d.Address, srv.Name)
|
||||
}
|
||||
}
|
||||
}
|
||||
key := p.Server + " " + d.Address
|
||||
if o, taken := addrs[key]; taken {
|
||||
say("Device %s of %s: address %s is also used by device %s of %s.", d.Address, o.device, o.person)
|
||||
}
|
||||
addrs[key] = holder{d.Name, p.Name}
|
||||
}
|
||||
for _, id := range m.CircleIDs() {
|
||||
if c := m.Circles[id]; m.Servers[c.Server] == nil {
|
||||
errs = append(errs, fmt.Sprintf(t.T("Circle %s: server %s does not exist."), c.Name, c.Server))
|
||||
}
|
||||
}
|
||||
return errs
|
||||
}
|
||||
|
||||
// TunnelDevices is the devices the sync loads into a server's tunnel, in the settings' order
|
||||
// (dawnline.awg tunnel_devices): those of people who are active or held only by a limit the portal
|
||||
// explains, that are on, with a key and an address, and not the server's own key. states is each person's
|
||||
// state (package state).
|
||||
func TunnelDevices(m *model.Model, sid string, states map[string]string) []*model.Device {
|
||||
out := []*model.Device{}
|
||||
own := ""
|
||||
if srv := m.Servers[sid]; srv != nil {
|
||||
own = srv.PublicKey
|
||||
}
|
||||
for _, id := range m.DeviceIDs() {
|
||||
d := m.Devices[id]
|
||||
p := m.People[d.Person]
|
||||
// turned off, or a router its owner asked for that the admin has not taken
|
||||
if p == nil || p.Server != sid || d.Disabled || d.Waiting {
|
||||
continue
|
||||
}
|
||||
if s := states[p.ID]; s != "active" && s != "quota" {
|
||||
continue
|
||||
}
|
||||
if _, ok := ipnet.IP(d.Address); !ok || !awg.ValidKey(d.PublicKey) || (own != "" && d.PublicKey == own) {
|
||||
continue
|
||||
}
|
||||
out = append(out, d)
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
||||
// PeerDiff is how the peers read on a tunnel differ from the devices that belong there, counted by key.
|
||||
func PeerDiff(devs []*model.Device, peers map[string]awg.Peer, ifname string) Peers {
|
||||
want := map[string]bool{}
|
||||
for _, d := range devs {
|
||||
want[d.PublicKey] = true
|
||||
}
|
||||
p := Peers{Expected: len(devs)}
|
||||
found := 0
|
||||
for k, peer := range peers {
|
||||
if peer.Ifname != ifname {
|
||||
continue
|
||||
}
|
||||
p.Loaded++
|
||||
if want[k] {
|
||||
found++
|
||||
} else {
|
||||
p.Extra++
|
||||
}
|
||||
}
|
||||
p.Missing = len(want) - found
|
||||
return p
|
||||
}
|
||||
|
||||
// Divert is a policy rule that sends marked traffic into a table with `local default`, the way transparent
|
||||
// proxies capture the router's own traffic.
|
||||
type Divert struct {
|
||||
Pref int
|
||||
Mark, Mask uint32
|
||||
Table string
|
||||
}
|
||||
|
||||
const markAll = 0xffffffff
|
||||
|
||||
var (
|
||||
markRule = regexp.MustCompile(`^(\d+):.*fwmark 0x([0-9a-f]+)(/0x([0-9a-f]+))?.* lookup (\S+)`)
|
||||
localDefault = regexp.MustCompile(`(^|\n)local default`)
|
||||
)
|
||||
|
||||
// ProxyDiverts finds the diverts, one a mark and mask (dawnline.fw proxy_diverts). rules is `ip <family>
|
||||
// rule show` and table `ip <family> route show table <name>`, for "-4" and "-6".
|
||||
func ProxyDiverts(rules func(family string) string, table func(family, name string) string) []Divert {
|
||||
out := []Divert{}
|
||||
seen := map[string]bool{}
|
||||
for _, fam := range []string{"-4", "-6"} {
|
||||
for _, line := range strings.Split(rules(fam), "\n") {
|
||||
m := markRule.FindStringSubmatch(line)
|
||||
if m == nil {
|
||||
continue
|
||||
}
|
||||
pref, _ := strconv.Atoi(m[1])
|
||||
if pref >= 32766 {
|
||||
continue
|
||||
}
|
||||
mark, _ := strconv.ParseUint(m[2], 16, 32)
|
||||
mask := uint64(markAll)
|
||||
if m[4] != "" {
|
||||
mask, _ = strconv.ParseUint(m[4], 16, 32)
|
||||
}
|
||||
key := fmt.Sprintf("%d/%d", mark, mask)
|
||||
if seen[key] || !localDefault.MatchString(table(fam, m[5])) {
|
||||
continue
|
||||
}
|
||||
seen[key] = true
|
||||
out = append(out, Divert{pref, uint32(mark), uint32(mask), m[5]})
|
||||
}
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
||||
// String is a divert as `ip rule` shows it, for people: "pref 1000 fwmark 0x1 → table 100".
|
||||
func (d Divert) String() string {
|
||||
mask := ""
|
||||
if d.Mask != markAll {
|
||||
mask = fmt.Sprintf("/0x%x", d.Mask)
|
||||
}
|
||||
return fmt.Sprintf("pref %d fwmark 0x%x%s → table %s", d.Pref, d.Mark, mask, d.Table)
|
||||
}
|
||||
|
||||
// ReplyScript is the table that keeps answers from Dawnline's ports out of the diverts, as dawnline.fw
|
||||
// writes it, or "" when there is nothing to keep out of them.
|
||||
func ReplyScript(m *model.Model, diverts []Divert) string {
|
||||
var tcp, udp []int
|
||||
add := func(list []int, n int) []int {
|
||||
for _, x := range list {
|
||||
if x == n {
|
||||
return list
|
||||
}
|
||||
}
|
||||
if n < 1 || n > 65535 {
|
||||
return list
|
||||
}
|
||||
return append(list, n)
|
||||
}
|
||||
if s := m.Settings; s.PortalEnabled {
|
||||
tcp = add(tcp, s.PortalPort)
|
||||
for _, h := range append([]string{s.PortalHost}, s.PortalAlt...) {
|
||||
if _, ip := ipnet.IP(h); ip {
|
||||
tcp = add(tcp, s.PortalPort+1)
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
for _, id := range m.ServerIDs() {
|
||||
if srv := m.Servers[id]; srv.PrivateKey != "" && srv.Enabled {
|
||||
udp = add(udp, srv.Port)
|
||||
}
|
||||
}
|
||||
if len(diverts) == 0 || (len(tcp) == 0 && len(udp) == 0) {
|
||||
return ""
|
||||
}
|
||||
t := []string{"table inet dawnline_reply {", "\tchain out {", "\t\ttype route hook output priority filter + 10; policy accept;"}
|
||||
for _, proto := range []struct {
|
||||
name string
|
||||
ports []int
|
||||
}{{"tcp", tcp}, {"udp", udp}} {
|
||||
if len(proto.ports) == 0 {
|
||||
continue
|
||||
}
|
||||
var ports []string
|
||||
for _, p := range proto.ports {
|
||||
ports = append(ports, strconv.Itoa(p))
|
||||
}
|
||||
for _, d := range diverts {
|
||||
// only the divert's bits: other marks on the packet (multi-WAN) stay
|
||||
rule := fmt.Sprintf("meta mark 0x%x meta mark set 0x0", d.Mark)
|
||||
if d.Mask != markAll {
|
||||
rule = fmt.Sprintf("meta mark & 0x%x == 0x%x meta mark set meta mark & 0x%x", d.Mask, d.Mark, ^d.Mask)
|
||||
}
|
||||
t = append(t, "\t\t"+proto.name+" sport { "+strings.Join(ports, ", ")+" } "+rule)
|
||||
}
|
||||
}
|
||||
return strings.Join(append(t, "\t}", "}"), "\n") + "\n"
|
||||
}
|
||||
|
||||
// ServerErrors is what is wrong with a server's definition against the rest of the router
|
||||
// (dawnline.core server_errors): its interface name, port, tunnel network against `others`, public address.
|
||||
func ServerErrors(srv *model.Server, others []string, t *i18n.Catalog) []string {
|
||||
errs := []string{}
|
||||
if !model.ValidIfname(srv.Ifname) {
|
||||
errs = append(errs, t.T("Interface name: 1-12 lowercase letters, digits or _."))
|
||||
}
|
||||
if srv.Port < 1 || srv.Port > 65535 {
|
||||
errs = append(errs, t.T("Port must be 1-65535."))
|
||||
}
|
||||
if c, ok := ipnet.Subnet(srv.Subnet); !ok {
|
||||
errs = append(errs, t.T("Subnet must look like 10.77.0.0/24."))
|
||||
} else {
|
||||
for _, o := range others {
|
||||
if oc, ok := ipnet.Subnet(o); ok && overlap(c, oc) {
|
||||
errs = append(errs, fmt.Sprintf(t.T("Subnet overlaps %s."), o))
|
||||
}
|
||||
}
|
||||
}
|
||||
if srv.Endpoint != "" && !endpoint.ValidHost(srv.Endpoint) {
|
||||
errs = append(errs, t.T("Endpoint must be a hostname or IP address."))
|
||||
}
|
||||
return errs
|
||||
}
|
||||
|
||||
// ConfigErrors is what is wrong with settings about to replace the current ones (a restore, an import):
|
||||
// people and devices consistent (ModelErrors), and each server with a valid interface name that is its
|
||||
// own and not one of the router's (`network`: the router's network configuration), a tunnel network that
|
||||
// overlaps neither the router's (`foreign`) nor an earlier server's, a port of its own and disguise values
|
||||
// AmneziaWG takes. Empty when they can be used. dawnline.backup config_errors.
|
||||
func ConfigErrors(m *model.Model, t *i18n.Catalog, network *uci.Config, foreign []string) []string {
|
||||
errs := ModelErrors(m, t)
|
||||
ifnames, ports := map[string]string{}, map[int]string{}
|
||||
var subnets []string
|
||||
for _, id := range m.ServerIDs() {
|
||||
srv := m.Servers[id]
|
||||
for _, e := range append(ServerErrors(srv, append(append([]string{}, foreign...), subnets...), t), disguise.Unsafe(srv.Obf)...) {
|
||||
errs = append(errs, fmt.Sprintf(t.T("Server %s: %s"), srv.Name, e))
|
||||
}
|
||||
if other, used := ifnames[srv.Ifname]; used {
|
||||
errs = append(errs, fmt.Sprintf(t.T("Server %s: interface %s is also used by %s."), srv.Name, srv.Ifname, other))
|
||||
}
|
||||
ifnames[srv.Ifname] = srv.Name
|
||||
own := srv.Ifname == "dlx0" || srv.Ifname == "dll0"
|
||||
if network != nil {
|
||||
if s := network.Section(srv.Ifname); s != nil {
|
||||
_, ours := s.Values["_dawnline"]
|
||||
own = own || s.Type != "interface" || !ours
|
||||
}
|
||||
}
|
||||
if own {
|
||||
errs = append(errs, fmt.Sprintf(t.T("Server %s: %s is one of the router's own network interfaces."), srv.Name, srv.Ifname))
|
||||
}
|
||||
if other, used := ports[srv.Port]; used {
|
||||
errs = append(errs, fmt.Sprintf(t.T("Server %s: UDP %d is also used by %s."), srv.Name, srv.Port, other))
|
||||
}
|
||||
ports[srv.Port] = srv.Name
|
||||
if srv.Subnet != "" {
|
||||
subnets = append(subnets, srv.Subnet)
|
||||
}
|
||||
}
|
||||
return errs
|
||||
}
|
||||
@@ -0,0 +1,132 @@
|
||||
package health
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"os"
|
||||
"reflect"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/tickcount/luci-app-dawnline/backend/awg"
|
||||
"github.com/tickcount/luci-app-dawnline/backend/model"
|
||||
"github.com/tickcount/luci-app-dawnline/backend/state"
|
||||
"github.com/tickcount/luci-app-dawnline/backend/uci"
|
||||
"github.com/tickcount/luci-app-dawnline/backend/usage"
|
||||
)
|
||||
|
||||
// What is wrong with testdata/broken.uci, who is loaded into each tunnel and how made-up tunnels stand
|
||||
// against that, as ucode says (testdata/trace.uc, scripts/ucode-golden.sh).
|
||||
func TestBrokenSettingsAsUcode(t *testing.T) {
|
||||
raw, err := os.ReadFile("testdata/trace.json")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
var trace struct {
|
||||
TS int64 `json:"ts"`
|
||||
Errors []string `json:"errors"`
|
||||
States map[string]string `json:"states"`
|
||||
Tunnels map[string][]string `json:"tunnels"`
|
||||
Diffs []struct {
|
||||
Server string `json:"server"`
|
||||
Loaded []string `json:"loaded"`
|
||||
Diff struct{ Loaded, Missing, Extra int }
|
||||
} `json:"diffs"`
|
||||
}
|
||||
if err := json.Unmarshal(raw, &trace); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
text, _ := os.ReadFile("testdata/broken.uci")
|
||||
c, err := uci.Parse(string(text))
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
m := model.Load(c, nil)
|
||||
if got := ModelErrors(m, nil); !reflect.DeepEqual(got, trace.Errors) || len(got) < 12 {
|
||||
t.Errorf("what is wrong\n go:\n %s\n ucode:\n %s", strings.Join(got, "\n "), strings.Join(trace.Errors, "\n "))
|
||||
}
|
||||
states := map[string]string{}
|
||||
for id, p := range m.People {
|
||||
states[id] = state.Of(m, p, usage.Empty(), trace.TS)
|
||||
}
|
||||
if !reflect.DeepEqual(states, trace.States) {
|
||||
t.Fatalf("states %v, ucode %v", states, trace.States)
|
||||
}
|
||||
loaded := 0
|
||||
for sid, want := range trace.Tunnels {
|
||||
got := []string{}
|
||||
for _, d := range TunnelDevices(m, sid, states) {
|
||||
got = append(got, d.ID)
|
||||
}
|
||||
loaded += len(got)
|
||||
if !reflect.DeepEqual(got, want) {
|
||||
t.Errorf("tunnel %s holds %v, ucode %v", sid, got, want)
|
||||
}
|
||||
}
|
||||
if loaded == 0 || len(trace.Diffs) < 8 {
|
||||
t.Fatal("the golden loads nobody")
|
||||
}
|
||||
for i, d := range trace.Diffs {
|
||||
srv := m.Servers[d.Server]
|
||||
peers := map[string]awg.Peer{"YYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYA=": {Ifname: "another"}}
|
||||
for _, k := range d.Loaded {
|
||||
peers[k] = awg.Peer{Ifname: srv.Ifname}
|
||||
}
|
||||
got := PeerDiff(TunnelDevices(m, d.Server, states), peers, srv.Ifname)
|
||||
if got.Loaded != d.Diff.Loaded || got.Missing != d.Diff.Missing || got.Extra != d.Diff.Extra {
|
||||
t.Errorf("diff %d: %+v, ucode %+v", i, got, d.Diff)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestProxiesAndTheReplyTable(t *testing.T) {
|
||||
rules := map[string]string{
|
||||
"-4": "0:\tfrom all lookup local\n1000:\tfrom all fwmark 0x1 lookup 100\n1001:\tfrom all fwmark 0x1 lookup 100\n2000:\tfrom all fwmark 0x200/0xff00 lookup 200\n3000:\tfrom all fwmark 0x7 lookup 300\n32766:\tfrom all fwmark 0x9 lookup main\n",
|
||||
"-6": "1000:\tfrom all fwmark 0x1 lookup 100\n",
|
||||
}
|
||||
tables := map[string]string{"100": "local default dev lo scope host\n", "200": "10.0.0.0/8 dev x\nlocal default dev lo\n", "300": "default via 10.0.0.1 dev wan\n"}
|
||||
d := ProxyDiverts(func(f string) string { return rules[f] }, func(_, name string) string { return tables[name] })
|
||||
var said []string
|
||||
for _, x := range d {
|
||||
said = append(said, x.String())
|
||||
}
|
||||
if strings.Join(said, "; ") != "pref 1000 fwmark 0x1 → table 100; pref 2000 fwmark 0x200/0xff00 → table 200" {
|
||||
t.Fatalf("diverts: %v", said)
|
||||
}
|
||||
c, _ := uci.Parse("config settings 'settings'\n\toption portal_enabled '1'\n\toption portal_port '4500'\n\tlist portal_alt '203.0.113.7'\n" +
|
||||
"config server 'home'\n\toption port '4500'\n\toption private_key 'k'\nconfig server 'cabin'\n\toption port '4600'\n\toption private_key 'k'\n\toption enabled '0'\n")
|
||||
m := model.Load(c, nil)
|
||||
want := "table inet dawnline_reply {\n\tchain out {\n\t\ttype route hook output priority filter + 10; policy accept;\n" +
|
||||
"\t\ttcp sport { 4500, 4501 } meta mark 0x1 meta mark set 0x0\n\t\ttcp sport { 4500, 4501 } meta mark & 0xff00 == 0x200 meta mark set meta mark & 0xffff00ff\n" +
|
||||
"\t\tudp sport { 4500 } meta mark 0x1 meta mark set 0x0\n\t\tudp sport { 4500 } meta mark & 0xff00 == 0x200 meta mark set meta mark & 0xffff00ff\n\t}\n}\n"
|
||||
if got := ReplyScript(m, d); got != want {
|
||||
t.Fatalf("the reply table:\n%s", got)
|
||||
}
|
||||
if ReplyScript(m, nil) != "" {
|
||||
t.Fatal("a reply table with no proxy to keep out of")
|
||||
}
|
||||
}
|
||||
|
||||
// Settings whose servers are wrong in every way: what a restore says of them, as ucode says it.
|
||||
func TestConfigErrorsAsUcode(t *testing.T) {
|
||||
raw, _ := os.ReadFile("testdata/trace.json")
|
||||
var trace struct {
|
||||
Network string `json:"network"`
|
||||
Errors []string `json:"config_errors"`
|
||||
}
|
||||
if err := json.Unmarshal(raw, &trace); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
text, _ := os.ReadFile("testdata/servers.uci")
|
||||
c, err := uci.Parse(string(text))
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
network, err := uci.Parse(trace.Network)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
got := ConfigErrors(model.Load(c, nil), nil, network, nil)
|
||||
if !reflect.DeepEqual(got, trace.Errors) || len(got) < 12 {
|
||||
t.Errorf("what a restore says\n go:\n %s\n ucode:\n %s", strings.Join(got, "\n "), strings.Join(trace.Errors, "\n "))
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,576 @@
|
||||
// Package health is Health's checks, as dawnline.health health() makes them: each named for the healthy
|
||||
// state ("Clock is set"), a failed one also with the problem in words for notices, in the reader's
|
||||
// language. Pure: Inputs is everything read on the router, gathered by the caller, so every check can be
|
||||
// made up in a test. A check whose input is not given yet (nil) is left out.
|
||||
package health
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"github.com/tickcount/luci-app-dawnline/backend/endpoint"
|
||||
"github.com/tickcount/luci-app-dawnline/backend/i18n"
|
||||
"github.com/tickcount/luci-app-dawnline/backend/ipnet"
|
||||
"github.com/tickcount/luci-app-dawnline/backend/model"
|
||||
"github.com/tickcount/luci-app-dawnline/backend/uci"
|
||||
)
|
||||
|
||||
// Check is one result. Fix names an action (apply, sync, restart, netrestart, ifup:<name>, install:<feature>,
|
||||
// updates) or is nil; Problem is the failed check in words, nil for one that passed.
|
||||
type Check struct {
|
||||
ID string `json:"id"`
|
||||
Title string `json:"title"`
|
||||
Status string `json:"status"`
|
||||
Detail string `json:"detail"`
|
||||
Fix *string `json:"fix"`
|
||||
Problem *string `json:"problem"`
|
||||
}
|
||||
|
||||
func check(id, title, status, detail, fix, problem string) Check {
|
||||
c := Check{ID: id, Title: title, Status: status, Detail: detail}
|
||||
if fix != "" {
|
||||
c.Fix = &fix
|
||||
}
|
||||
if status == "warn" || status == "error" {
|
||||
if problem == "" {
|
||||
problem = title
|
||||
}
|
||||
c.Problem = &problem
|
||||
}
|
||||
return c
|
||||
}
|
||||
|
||||
// Iface is what netifd says of an interface.
|
||||
type Iface struct {
|
||||
Exists, Up bool
|
||||
// Errors is its error codes (INVALID_PROTO).
|
||||
Errors []string
|
||||
}
|
||||
|
||||
// Peers is how a tunnel's loaded devices stand against those it should hold.
|
||||
type Peers struct {
|
||||
Expected, Missing, Extra, Loaded int
|
||||
}
|
||||
|
||||
// Replies: whether answers from our ports go straight out, and the proxies' diverts that would swallow them.
|
||||
type Replies struct {
|
||||
OK bool
|
||||
Diverts []string
|
||||
}
|
||||
|
||||
// Subnet is an IPv4 network of a netifd interface.
|
||||
type Subnet struct {
|
||||
Iface, CIDR string
|
||||
}
|
||||
|
||||
// Portal is what was read for the portal's checks.
|
||||
type Portal struct {
|
||||
Owners []string
|
||||
Listening bool
|
||||
// IPs is where its address points; WAN the router's.
|
||||
IPs []string
|
||||
WAN string
|
||||
// Cert is the certificate in use; Valid: for more than 14 days; Names: the DNS names it covers.
|
||||
Cert string
|
||||
SelfSigned bool
|
||||
Valid bool
|
||||
Names []string
|
||||
}
|
||||
|
||||
// Inputs is everything the checks are made from.
|
||||
type Inputs struct {
|
||||
M *model.Model
|
||||
T *i18n.Catalog
|
||||
// AmneziaWG: its state after trying to load the module (missing packages, loaded, handler), the firmware
|
||||
// the installed build was for when that is not this one, why the module does not load, an update that
|
||||
// waits for a reboot.
|
||||
Missing []string
|
||||
Loaded, Handler bool
|
||||
KernelWas, KernelIs string
|
||||
WhyNotLoaded string
|
||||
WaitsForReboot bool
|
||||
Year int
|
||||
AgentRunning bool
|
||||
// FreeKB is the overlay's free space (nil: unknown).
|
||||
FreeKB *int64
|
||||
NftLoaded bool
|
||||
PolicyRouting []string
|
||||
// ModelErrors is what is wrong with people and devices (nil: not checked yet).
|
||||
ModelErrors func() []string
|
||||
Firewall, Network *uci.Config
|
||||
Iface func(ifname string) Iface
|
||||
// Unread tells a tunnel that could not be read; Peers how its devices stand (nil: not checked yet).
|
||||
Unread func(ifname string) bool
|
||||
Peers func(srv *model.Server) Peers
|
||||
Replies *Replies
|
||||
// Subnets is the router's networks; HomeNets a server's home networks; Endpoint what its public address reads as.
|
||||
Subnets []Subnet
|
||||
HomeNets func(srv *model.Server) []string
|
||||
Endpoint func(srv *model.Server, host string) endpoint.Reads
|
||||
// LikeHome is the home-like path's state (dawnline.loop status); Needs the packages each feature misses.
|
||||
LikeHome map[string]any
|
||||
Needs map[string][]string
|
||||
// The resolver for Home-only devices: its configuration's age in seconds (nil: none), whether it runs.
|
||||
ResolverConfAge *int64
|
||||
ResolverRunning bool
|
||||
Portal func() Portal
|
||||
// The networks behind people's routers: Behind, those in effect on this router by device (nil: not
|
||||
// checked); Own, the router's own networks, to name what a network shares addresses with; RouteError,
|
||||
// what the last sync said of a route that would not go in ("": none).
|
||||
Behind map[string][]string
|
||||
Own []string
|
||||
RouteError string
|
||||
}
|
||||
|
||||
// The /24s home routers come with out of the box: a home network on one of them is very likely the same as
|
||||
// the network a person connects from.
|
||||
var commonHome = []string{"192.168.0.0/24", "192.168.1.0/24", "192.168.2.0/24", "192.168.3.0/24", "192.168.8.0/24", "192.168.10.0/24", "192.168.31.0/24",
|
||||
"192.168.50.0/24", "192.168.88.0/24", "192.168.100.0/24", "192.168.178.0/24", "10.0.0.0/24", "10.1.1.0/24"}
|
||||
|
||||
func overlap(a, b ipnet.Net) bool {
|
||||
return uint64(a.Base) < uint64(b.Base)+b.Size() && uint64(b.Base) < uint64(a.Base)+a.Size()
|
||||
}
|
||||
|
||||
// CommonHome is the home networks that overlap a common out-of-the-box subnet.
|
||||
func CommonHome(nets []string) []string {
|
||||
out := []string{}
|
||||
for _, n := range nets {
|
||||
a, ok := ipnet.Subnet(n)
|
||||
if !ok {
|
||||
continue
|
||||
}
|
||||
for _, c := range commonHome {
|
||||
if b, _ := ipnet.Subnet(c); overlap(a, b) {
|
||||
out = append(out, n)
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
||||
func has(list []string, v string) bool {
|
||||
for _, x := range list {
|
||||
if x == v {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func (in *Inputs) noProto() string {
|
||||
return in.T.T("netifd doesn't know the amneziawg protocol (AmneziaWG missing, or the network wasn't restarted after installing it).")
|
||||
}
|
||||
|
||||
func (in *Inputs) awg() Check {
|
||||
t := in.T
|
||||
title := t.T("AmneziaWG installed")
|
||||
if n := len(in.Missing); n > 0 {
|
||||
// the module was built for the kernel of the firmware it was installed on
|
||||
if in.KernelWas != "" && has(in.Missing, "kmod-amneziawg") {
|
||||
return check("awg", title, "error",
|
||||
fmt.Sprintf(t.T("The firmware changed (kernel %s → %s): the AmneziaWG build installed for it is gone. Install the build for this firmware."), in.KernelWas, in.KernelIs),
|
||||
"install:awg", t.T("AmneziaWG needs a build for the new firmware"))
|
||||
}
|
||||
return check("awg", title, "error", fmt.Sprintf(t.N(int64(n), "%s is missing.", "%s are missing."), strings.Join(in.Missing, ", ")), "install:awg", t.T("AmneziaWG isn’t installed"))
|
||||
}
|
||||
if !in.Loaded {
|
||||
detail := t.T("The kernel module doesn't load. Reinstall a build for this kernel in Components.")
|
||||
if in.WhyNotLoaded != "" {
|
||||
detail = fmt.Sprintf(t.T("The kernel module doesn't load: %s Reinstall a build for this kernel in Components."), in.WhyNotLoaded)
|
||||
}
|
||||
return check("awg", title, "error", detail, "updates", t.T("AmneziaWG’s kernel module doesn’t load"))
|
||||
}
|
||||
if !in.Handler {
|
||||
return check("awg", title, "error", in.noProto(), "netrestart", t.T("The network doesn’t know AmneziaWG yet"))
|
||||
}
|
||||
if in.WaitsForReboot {
|
||||
return check("awg", title, "warn", t.T("The AmneziaWG update is installed and starts after a reboot."), "", t.T("The AmneziaWG update waits for a reboot"))
|
||||
}
|
||||
return check("awg", title, "ok", t.T("Kernel module, awg tool and the netifd protocol are present."), "", "")
|
||||
}
|
||||
|
||||
func (in *Inputs) reply(id, title, problem, proto string, port int) (Check, bool) {
|
||||
r := in.Replies
|
||||
if r == nil {
|
||||
return Check{}, false
|
||||
}
|
||||
t := in.T
|
||||
via, from := strings.Join(r.Diverts, ", "), strings.ToUpper(proto)+" "+strconv.Itoa(port)
|
||||
switch {
|
||||
case !r.OK:
|
||||
return check(id, title, "error", fmt.Sprintf(t.T("Answers from %s are swallowed by a proxy on the router (%s): clients get no reply."), from, via), "apply", problem), true
|
||||
case len(r.Diverts) > 0:
|
||||
return check(id, title, "ok", fmt.Sprintf(t.T("Answers from %s go straight out. A proxy on the router diverts its own traffic (%s); these answers skip it."), from, via), "", problem), true
|
||||
}
|
||||
return check(id, title, "ok", fmt.Sprintf(t.T("Answers from %s go straight out."), from), "", problem), true
|
||||
}
|
||||
|
||||
func sectionIs(c *uci.Config, name, kind string) bool {
|
||||
if c == nil {
|
||||
return false
|
||||
}
|
||||
s := c.Section(name)
|
||||
return s != nil && s.Type == kind
|
||||
}
|
||||
|
||||
// server is the checks of one server's tunnel.
|
||||
func (in *Inputs) server(id string, srv *model.Server, label string) []Check {
|
||||
t, m := in.T, in.M
|
||||
out := []Check{}
|
||||
st := in.Iface(srv.Ifname)
|
||||
running, down := t.T("Tunnel running")+label, t.T("AmneziaWG is down")+label
|
||||
switch {
|
||||
case !st.Up && has(st.Errors, "INVALID_PROTO"):
|
||||
out = append(out, check("up_"+id, running, "error", in.noProto(), "netrestart", down))
|
||||
case st.Up:
|
||||
out = append(out, check("up_"+id, running, "ok", fmt.Sprintf(t.T("%s is up, listening on UDP %d."), srv.Ifname, srv.Port), "", down))
|
||||
case !st.Exists:
|
||||
out = append(out, check("up_"+id, running, "error", fmt.Sprintf(t.T("%s does not exist."), srv.Ifname), "apply", down))
|
||||
case len(st.Errors) > 0:
|
||||
out = append(out, check("up_"+id, running, "error", fmt.Sprintf(t.T("%s is down: %s."), srv.Ifname, strings.Join(st.Errors, ", ")), "ifup:"+srv.Ifname, down))
|
||||
default:
|
||||
out = append(out, check("up_"+id, running, "error", fmt.Sprintf(t.T("%s is down."), srv.Ifname), "ifup:"+srv.Ifname, down))
|
||||
}
|
||||
// the devices the sync loads, by the same choice the agent compares with every minute
|
||||
loaded := t.T("Devices loaded") + label
|
||||
if st.Up && in.Unread != nil && in.Unread(srv.Ifname) {
|
||||
out = append(out, check("peers_"+id, loaded, "warn", t.T("The tunnel could not be read, so its devices could not be checked."), "",
|
||||
t.T("The devices in AmneziaWG could not be checked")+label))
|
||||
} else if st.Up && in.Peers != nil {
|
||||
p := in.Peers(srv)
|
||||
bad := t.T("Not every device is loaded into AmneziaWG") + label
|
||||
switch {
|
||||
case p.Missing == 0 && p.Extra == 0:
|
||||
out = append(out, check("peers_"+id, loaded, "ok", fmt.Sprintf(t.N(int64(p.Loaded), "%d device is loaded in the tunnel.", "%d devices are loaded in the tunnel."), p.Loaded), "", bad))
|
||||
case p.Extra != 0:
|
||||
out = append(out, check("peers_"+id, loaded, "warn", fmt.Sprintf(t.N(int64(p.Expected), "%d of %d device missing, %d loaded that should not be.",
|
||||
"%d of %d devices missing, %d loaded that should not be."), p.Missing, p.Expected, p.Extra), "sync", bad))
|
||||
default:
|
||||
out = append(out, check("peers_"+id, loaded, "warn", fmt.Sprintf(t.N(int64(p.Expected), "%d of %d device missing.", "%d of %d devices missing."), p.Missing, p.Expected), "sync", bad))
|
||||
}
|
||||
}
|
||||
rules := sectionIs(in.Firewall, "dawnline_"+id+"_port", "rule") && sectionIs(in.Firewall, "dawnline_"+id+"_zone", "zone")
|
||||
if rules {
|
||||
out = append(out, check("fw_"+id, t.T("Firewall rules")+label, "ok", fmt.Sprintf(t.T("Zone %s and the WAN rule for UDP %d exist."), srv.Ifname, srv.Port), "", ""))
|
||||
} else {
|
||||
out = append(out, check("fw_"+id, t.T("Firewall rules")+label, "error", t.T("Firewall zone or WAN rule is missing."), "apply", t.T("AmneziaWG firewall rules are missing")+label))
|
||||
}
|
||||
if c, ok := in.reply("reply_"+id, t.T("Answers reach devices")+label, t.T("AmneziaWG answers may not reach devices")+label, "udp", srv.Port); ok {
|
||||
out = append(out, c)
|
||||
}
|
||||
// port collisions with other tunnels
|
||||
var clash []string
|
||||
if in.Network != nil {
|
||||
for _, s := range in.Network.OfType("interface") {
|
||||
proto, _ := s.Get("proto")
|
||||
lp, _ := s.Get("listen_port")
|
||||
if n, _ := strconv.Atoi(strings.TrimSpace(lp)); s.Name != srv.Ifname && (proto == "amneziawg" || proto == "wireguard") && n == srv.Port {
|
||||
clash = append(clash, s.Name)
|
||||
}
|
||||
}
|
||||
}
|
||||
if len(clash) > 0 {
|
||||
out = append(out, check("port_"+id, t.T("Port is free")+label, "error", fmt.Sprintf(t.T("UDP %d is also used by %s."), srv.Port, strings.Join(clash, ", ")), "", t.T("AmneziaWG port is taken")+label))
|
||||
}
|
||||
var overlaps []string
|
||||
if sc, ok := ipnet.Subnet(srv.Subnet); ok {
|
||||
for _, o := range in.Subnets {
|
||||
// every network of the router but this server's own tunnel's
|
||||
if o.Iface == srv.Ifname {
|
||||
continue
|
||||
}
|
||||
if oc, ok := ipnet.Subnet(o.CIDR); ok && overlap(sc, oc) {
|
||||
overlaps = append(overlaps, o.Iface+" ("+o.CIDR+")")
|
||||
}
|
||||
}
|
||||
}
|
||||
if len(overlaps) > 0 {
|
||||
out = append(out, check("subnet_"+id, t.T("Subnet is unique")+label, "error", fmt.Sprintf(t.T("%s overlaps %s."), srv.Subnet, strings.Join(overlaps, ", ")), "", t.T("AmneziaWG subnet overlaps another network")+label))
|
||||
} else {
|
||||
out = append(out, check("subnet_"+id, t.T("Subnet is unique")+label, "ok", fmt.Sprintf(t.T("%s does not overlap other networks."), srv.Subnet), "", ""))
|
||||
}
|
||||
// whether the home networks are on a common subnet, while anyone on the server has home access
|
||||
reach := false
|
||||
for _, p := range m.People {
|
||||
reach = reach || (p.Server == id && (p.Access == "lan" || p.Access == "both"))
|
||||
}
|
||||
if nets := in.HomeNets(srv); reach && len(nets) > 0 {
|
||||
c := check("homenet_"+id, t.T("Home network addresses")+label, "ok",
|
||||
fmt.Sprintf(t.T("%s is not a common home subnet: the networks people connect from rarely use the same addresses."), strings.Join(nets, ", ")), "", "")
|
||||
if bad := CommonHome(nets); len(bad) > 0 {
|
||||
c.Status = "warn"
|
||||
c.Detail = fmt.Sprintf(t.T("%s is one of the most common home subnets. On a network with the same addresses, people with home access reach your home instead of their own: their printer or TV there is out of reach while connected, with LAN Bypass too. A rarer subnet for your home network avoids it, for example 10.37.12.0/24."), strings.Join(bad, ", "))
|
||||
}
|
||||
// advice, not a fault: no notice elsewhere
|
||||
out = append(out, c)
|
||||
}
|
||||
if c, has := in.behind(id, label); has {
|
||||
out = append(out, c)
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
||||
// behind is the check of the networks behind a server's routers, when any router has one written: each is
|
||||
// in effect (a peer of the tunnel, a route, a place in the access table), or the check says which is not
|
||||
// and what it shares addresses with; a route the router would not take is said in its own words.
|
||||
func (in *Inputs) behind(id, label string) (Check, bool) {
|
||||
m, t := in.M, in.T
|
||||
if in.Behind == nil {
|
||||
return Check{}, false
|
||||
}
|
||||
title := t.T("Networks behind routers") + label
|
||||
var bad []string
|
||||
written, routed := 0, 0
|
||||
for _, did := range m.DeviceIDs() {
|
||||
d := m.Devices[did]
|
||||
p := m.People[d.Person]
|
||||
if p == nil || p.Server != id || d.Kind != "router" || d.Waiting || len(d.Behind) == 0 {
|
||||
continue
|
||||
}
|
||||
written += len(d.Behind)
|
||||
routed += len(in.Behind[did])
|
||||
who := p.Name + " · " + d.Name
|
||||
for _, s := range d.Behind {
|
||||
n, why := model.BehindNet(s)
|
||||
switch {
|
||||
case why != "":
|
||||
bad = append(bad, fmt.Sprintf(t.T("%s behind %s is not a network a router may have behind it."), s, who))
|
||||
case has(in.Behind[did], n.String()):
|
||||
default:
|
||||
c := m.BehindClash(n, did, in.Own)
|
||||
switch {
|
||||
case c == nil:
|
||||
bad = append(bad, fmt.Sprintf(t.T("%s behind %s is written twice, or is one more than a router may have."), n.String(), who))
|
||||
case c.Server != "":
|
||||
bad = append(bad, fmt.Sprintf(t.T("%s behind %s shares addresses with the tunnel network of %s (%s)."), n.String(), who, m.Servers[c.Server].Name, c.Net))
|
||||
case c.Device != "":
|
||||
bad = append(bad, fmt.Sprintf(t.T("%s behind %s shares addresses with %s behind %s."), n.String(), who, c.Net, m.Devices[c.Device].Name))
|
||||
default:
|
||||
bad = append(bad, fmt.Sprintf(t.T("%s behind %s shares addresses with %s, which the router has itself."), n.String(), who, c.Net))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
switch {
|
||||
case written == 0:
|
||||
return Check{}, false
|
||||
case len(bad) > 0:
|
||||
return check("sites_"+id, title, "warn", strings.Join(bad, " ")+" "+t.T("Such a network is not in effect: change it in the server's Network settings."), "",
|
||||
t.T("A network behind a router isn’t in effect")+label), true
|
||||
case in.RouteError != "":
|
||||
return check("sites_"+id, title, "error", fmt.Sprintf(t.T("A route to a network behind a router couldn't be set: %s."), in.RouteError), "sync",
|
||||
t.T("A network behind a router has no route")+label), true
|
||||
}
|
||||
return check("sites_"+id, title, "ok",
|
||||
fmt.Sprintf(t.N(int64(routed), "%d network behind routers is carried by the tunnel.", "%d networks behind routers are carried by the tunnel."), routed), "", ""), true
|
||||
}
|
||||
|
||||
func (in *Inputs) portal() []Check {
|
||||
t, s := in.T, in.M.Settings
|
||||
portal, bad := t.T("Personal portal"), t.T("Personal portal isn’t working")
|
||||
if need := in.Needs["https"]; len(need) > 0 {
|
||||
return []Check{check("portal", portal, "error", fmt.Sprintf(t.T("HTTPS isn't available on this router: install %s."), strings.Join(need, ", ")), "install:https", bad)}
|
||||
}
|
||||
p := in.Portal()
|
||||
out := []Check{}
|
||||
switch {
|
||||
case len(p.Owners) > 0:
|
||||
out = append(out, check("portal", portal, "error", fmt.Sprintf(t.T("TCP %d is already used by %s. Choose another port in Settings."), s.PortalPort, strings.Join(p.Owners, ", ")), "", bad))
|
||||
case p.Listening:
|
||||
out = append(out, check("portal", portal, "ok", fmt.Sprintf(t.T("Listening on TCP %d."), s.PortalPort), "", bad))
|
||||
default:
|
||||
out = append(out, check("portal", portal, "error", fmt.Sprintf(t.T("Nothing listens on TCP %d."), s.PortalPort), "restart", bad))
|
||||
}
|
||||
if h := s.PortalHost; h == "" {
|
||||
out = append(out, check("portal_host", t.T("Portal address"), "error", t.T("Set the public hostname in Settings so links can be generated."), "", t.T("Portal address isn’t set")))
|
||||
} else {
|
||||
cf := false
|
||||
for _, ip := range p.IPs {
|
||||
cf = cf || endpoint.Cloudflare(ip)
|
||||
}
|
||||
ips := strings.Join(p.IPs, ", ")
|
||||
title, problem := t.T("Portal address points here"), t.T("Portal address doesn’t point here")
|
||||
switch {
|
||||
case len(p.IPs) == 0:
|
||||
out = append(out, check("portal_dns", title, "error", fmt.Sprintf(t.T("%s does not resolve."), h), "", problem))
|
||||
case cf:
|
||||
out = append(out, check("portal_dns", title, "ok", fmt.Sprintf(t.T("%s goes through Cloudflare; in Russia such connections often stall after ~16 KB."), h), "", problem))
|
||||
case p.WAN != "" && !has(p.IPs, p.WAN):
|
||||
out = append(out, check("portal_dns", title, "warn", fmt.Sprintf(t.T("%s points at %s, not this router (%s)."), h, ips, p.WAN), "", problem))
|
||||
case p.WAN != "":
|
||||
out = append(out, check("portal_dns", title, "ok", fmt.Sprintf(t.T("%s → %s (this router)."), h, ips), "", problem))
|
||||
default:
|
||||
out = append(out, check("portal_dns", title, "ok", h+" → "+ips+".", "", problem))
|
||||
}
|
||||
}
|
||||
if c, ok := in.reply("portal_reply", t.T("Portal answers reach visitors"), t.T("Portal answers may not reach visitors"), "tcp", s.PortalPort); ok {
|
||||
out = append(out, c)
|
||||
}
|
||||
// IP addresses have no certificate: the portal also answers plain HTTP for them
|
||||
var plain []string
|
||||
hosts := append([]string{s.PortalHost}, s.PortalAlt...)
|
||||
for i, h := range hosts {
|
||||
if _, ip := ipnet.IP(h); ip && h != "" && !has(hosts[:i], h) {
|
||||
plain = append(plain, h)
|
||||
}
|
||||
}
|
||||
if len(plain) > 0 {
|
||||
out = append(out, check("portal_http", t.T("Plain HTTP links"), "warn",
|
||||
fmt.Sprintf(t.T("Links on %s use plain HTTP: the link and the VPN keys in configurations travel unencrypted."), strings.Join(plain, ", ")), "", t.T("Portal links use plain HTTP")))
|
||||
}
|
||||
title := t.T("Portal certificate")
|
||||
if _, ip := ipnet.IP(s.PortalHost); ip {
|
||||
return append(out, check("cert", title, "skip", t.T("The main address is an IP: its links use plain HTTP."), "", ""))
|
||||
}
|
||||
covers := s.PortalHost == "" || p.SelfSigned
|
||||
for _, n := range p.Names {
|
||||
covers = covers || endpoint.Covers(n, s.PortalHost)
|
||||
}
|
||||
problem := t.T("Portal certificate needs attention")
|
||||
switch {
|
||||
case p.SelfSigned && len(in.Needs["acme"]) > 0:
|
||||
out = append(out, check("cert", title, "warn", t.T("Using a self-signed certificate: browsers will show a warning. ACME can get a free Let’s Encrypt one."), "", problem))
|
||||
case p.SelfSigned:
|
||||
out = append(out, check("cert", title, "warn", t.T("Using a self-signed certificate: browsers will show a warning."), "", problem))
|
||||
case !covers:
|
||||
out = append(out, check("cert", title, "warn", fmt.Sprintf(t.T("%s does not cover %s (it has %s): browsers will warn."), p.Cert, s.PortalHost, strings.Join(p.Names, ", ")), "", problem))
|
||||
case p.Valid:
|
||||
out = append(out, check("cert", title, "ok", fmt.Sprintf(t.T("%s covers %s and is valid for more than 14 days."), p.Cert, s.PortalHost), "", problem))
|
||||
default:
|
||||
out = append(out, check("cert", title, "warn", fmt.Sprintf(t.T("%s expires within 14 days."), p.Cert), "", problem))
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
||||
// Run makes every check.
|
||||
func Run(in Inputs) []Check {
|
||||
t, m := in.T, in.M
|
||||
out := []Check{}
|
||||
ids := m.ServerIDs()
|
||||
if len(ids) > 0 {
|
||||
out = append(out, in.awg())
|
||||
}
|
||||
if in.Year >= 2025 {
|
||||
out = append(out, check("clock", t.T("Clock is set"), "ok", t.T("End dates and quotas use the router clock."), "", ""))
|
||||
} else {
|
||||
out = append(out, check("clock", t.T("Clock is set"), "error", t.T("The router clock looks wrong; end dates will misbehave. Check NTP."), "", t.T("Clock isn’t set")))
|
||||
}
|
||||
fix := "restart"
|
||||
status := "error"
|
||||
if in.AgentRunning {
|
||||
fix, status = "", "ok"
|
||||
}
|
||||
out = append(out, check("agent", t.T("Background agent running"), status, t.T("Counts traffic and enforces end dates and quotas."), fix, t.T("Background agent isn’t running")))
|
||||
// a full overlay fails every config write on the router
|
||||
if in.FreeKB != nil {
|
||||
free := *in.FreeKB
|
||||
problem := t.T("The router is running out of flash")
|
||||
switch {
|
||||
case free < 2048:
|
||||
status := "warn"
|
||||
if free < 512 {
|
||||
status = "error"
|
||||
}
|
||||
mb := strconv.FormatFloat(float64(int64(float64(free)/1024*10))/10, 'g', -1, 64)
|
||||
out = append(out, check("flash", t.T("Free space on the router"), status,
|
||||
fmt.Sprintf(t.T("%s MB free: settings may stop saving. Remove old backups (Settings → Backups) or shorten the history."), mb), "", problem))
|
||||
default:
|
||||
out = append(out, check("flash", t.T("Free space on the router"), "ok", fmt.Sprintf(t.T("%d MB free on the overlay."), free/1024), "", problem))
|
||||
}
|
||||
}
|
||||
if len(ids) == 0 {
|
||||
return append(out, check("server", t.T("Server configured"), "warn", t.T("Set a server up in Settings."), "", t.T("No server yet")))
|
||||
}
|
||||
if in.NftLoaded {
|
||||
out = append(out, check("nft", t.T("Access rules loaded"), "ok", t.T("Table inet dawnline enforces who may reach LAN and the internet."), "", ""))
|
||||
} else {
|
||||
out = append(out, check("nft", t.T("Access rules loaded"), "error", t.T("Table inet dawnline is missing: no device is loaded into the tunnels until it is back."), "apply", t.T("Access rules aren’t loaded")))
|
||||
}
|
||||
likeHome := false
|
||||
for _, id := range ids {
|
||||
likeHome = likeHome || (m.Servers[id].LanLike && m.Servers[id].Enabled)
|
||||
}
|
||||
if likeHome {
|
||||
if pr := in.PolicyRouting; len(pr) > 0 {
|
||||
out = append(out, check("policy", t.T("Internet like a home device not bypassed"), "warn",
|
||||
fmt.Sprintf(t.T("Policy routing on the router (%s) sends marked traffic straight out, past the home-device path: tunnel traffic it matches skips your LAN's proxies and filters."), strings.Join(pr, "; ")),
|
||||
"", t.T("Other policy routing bypasses the home-device path")))
|
||||
} else {
|
||||
out = append(out, check("policy", t.T("Internet like a home device not bypassed"), "ok", t.T("No other policy routing ahead of the tunnel rules."), "", ""))
|
||||
}
|
||||
}
|
||||
// a device the sync has to leave out: its sentences, how many more, then what it means
|
||||
if in.ModelErrors != nil {
|
||||
if data := in.ModelErrors(); len(data) > 0 {
|
||||
parts := []string{strings.Join(data[:min(len(data), 4)], " ")}
|
||||
if len(data) > 4 {
|
||||
parts = append(parts, fmt.Sprintf(t.T("(%d more)"), len(data)-4))
|
||||
}
|
||||
parts = append(parts, t.T("Such devices are left out of the tunnels: fix or remove them."))
|
||||
out = append(out, check("data", t.T("People and devices consistent"), "error", strings.Join(parts, " "), "", t.T("People and devices are inconsistent")))
|
||||
} else {
|
||||
out = append(out, check("data", t.T("People and devices consistent"), "ok", t.T("Every device has a key and an address of its own inside its server."), "", ""))
|
||||
}
|
||||
}
|
||||
keyed := false
|
||||
for _, id := range ids {
|
||||
srv := m.Servers[id]
|
||||
keyed = keyed || (srv.Enabled && srv.PrivateKey != "")
|
||||
label := ""
|
||||
if len(ids) > 1 {
|
||||
label = " (" + srv.Name + ")"
|
||||
}
|
||||
if !srv.Enabled {
|
||||
out = append(out, check("srv_"+id, t.T("Server")+label, "skip", t.T("Server is disabled."), "", ""))
|
||||
continue
|
||||
}
|
||||
out = append(out, in.server(id, srv, label)...)
|
||||
host := m.EndpointHost(srv)
|
||||
status, text := endpoint.Words(endpoint.Of(host, in.Endpoint(srv, host)), "UDP "+strconv.Itoa(srv.Port), t)
|
||||
out = append(out, check("ep_"+id, t.T("Public address")+label, status, text, "", t.T("Public address needs attention")+label))
|
||||
if srv.LanLike {
|
||||
ls := in.LikeHome
|
||||
active, bridged := ls["active"] == true, ls["bridged"] == true
|
||||
title, problem := t.T("Internet like a home device")+label, t.T("Internet like a home device isn’t working")+label
|
||||
nh := in.Needs["home"]
|
||||
switch {
|
||||
case active && bridged:
|
||||
out = append(out, check("home_"+id, title, "ok", fmt.Sprintf(t.T("Traffic enters %s as %s, so it is handled like any device on your LAN."), ls["dev"], ls["address"]), "", problem))
|
||||
case len(nh) > 0:
|
||||
out = append(out, check("home_"+id, title, "warn", fmt.Sprintf(t.T("Needs %s. Internet traffic leaves through WAN directly until then."), strings.Join(nh, ", ")), "install:home", problem))
|
||||
case active:
|
||||
out = append(out, check("home_"+id, title, "warn", fmt.Sprintf(t.T("The link is up but not attached to %s."), ls["dev"]), "apply", problem))
|
||||
default:
|
||||
// the path's own sentence, then what it means
|
||||
why, _ := ls["error"].(string)
|
||||
if ls["error"] == nil {
|
||||
why = t.T("Not set up.")
|
||||
}
|
||||
out = append(out, check("home_"+id, title, "warn", why+" "+t.T("Internet traffic leaves through WAN directly."), "apply", problem))
|
||||
}
|
||||
}
|
||||
}
|
||||
// while every server is off the resolver only idles on loopback: nothing to check
|
||||
if keyed {
|
||||
running := in.ResolverConfAge != nil && in.ResolverRunning
|
||||
// a new config (a server turned on, the home link up) restarts it: give it a few seconds
|
||||
restarting := !running && in.ResolverConfAge != nil && *in.ResolverConfAge < 10
|
||||
title, problem := t.T("DNS for Home-only devices"), t.T("DNS for Home-only devices isn’t working")
|
||||
switch {
|
||||
case restarting:
|
||||
out = append(out, check("resolver", title, "ok", t.T("Restarting with the new settings."), "", problem))
|
||||
case running && in.LikeHome["active"] == true && in.LikeHome["transit"] != nil && in.LikeHome["transit"] != "":
|
||||
out = append(out, check("resolver", title, "ok", fmt.Sprintf(t.T("Plain resolver running next to the LAN (%s)."), in.LikeHome["transit"]), "", problem))
|
||||
case running:
|
||||
out = append(out, check("resolver", title, "ok", fmt.Sprintf(t.T("Plain resolver on port %d."), 5354), "", problem))
|
||||
default:
|
||||
out = append(out, check("resolver", title, "warn", t.T("The resolver is not running; Home-only devices cannot resolve names."), "apply", problem))
|
||||
}
|
||||
}
|
||||
if m.Settings.PortalEnabled {
|
||||
out = append(out, in.portal()...)
|
||||
}
|
||||
return out
|
||||
}
|
||||
@@ -0,0 +1,282 @@
|
||||
package health
|
||||
|
||||
import (
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/tickcount/luci-app-dawnline/backend/endpoint"
|
||||
"github.com/tickcount/luci-app-dawnline/backend/model"
|
||||
"github.com/tickcount/luci-app-dawnline/backend/uci"
|
||||
)
|
||||
|
||||
const settings = `
|
||||
config settings 'settings'
|
||||
option portal_enabled '1'
|
||||
option portal_port '4500'
|
||||
option portal_host 'vpn.example.org'
|
||||
list portal_alt '203.0.113.7'
|
||||
config server 'home'
|
||||
option name 'Home'
|
||||
option ifname 'dawn0'
|
||||
option port '4500'
|
||||
option subnet '10.77.0.0/24'
|
||||
option private_key 'k'
|
||||
option endpoint 'vpn.example.org'
|
||||
config server 'cabin'
|
||||
option name 'Cabin'
|
||||
option ifname 'dawn1'
|
||||
option port '4600'
|
||||
option subnet '10.78.0.0/24'
|
||||
option enabled '0'
|
||||
config person 'anna'
|
||||
option server 'home'
|
||||
option access 'both'
|
||||
`
|
||||
|
||||
// a router where everything is as it should be
|
||||
func healthy(t *testing.T) Inputs {
|
||||
c, err := uci.Parse(settings)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
fw, _ := uci.Parse("config rule 'dawnline_home_port'\nconfig zone 'dawnline_home_zone'\n")
|
||||
network, _ := uci.Parse("config interface 'dawn0'\n\toption proto 'amneziawg'\n\toption listen_port '4500'\n")
|
||||
free, age := int64(40960), int64(600)
|
||||
return Inputs{
|
||||
M: model.Load(c, nil), Loaded: true, Handler: true, Year: 2027, AgentRunning: true, FreeKB: &free, NftLoaded: true,
|
||||
ModelErrors: func() []string { return nil }, Firewall: fw, Network: network,
|
||||
Iface: func(string) Iface { return Iface{Exists: true, Up: true} },
|
||||
Unread: func(string) bool { return false },
|
||||
Peers: func(*model.Server) Peers { return Peers{Expected: 2, Loaded: 2} },
|
||||
Replies: &Replies{OK: true}, Subnets: []Subnet{{"lan", "192.168.77.1/24"}, {"dawn0", "10.77.0.1/24"}},
|
||||
HomeNets: func(*model.Server) []string { return []string{"192.168.77.0/24"} },
|
||||
Endpoint: func(*model.Server, string) endpoint.Reads {
|
||||
return endpoint.Reads{IPs: []string{"203.0.113.7"}, WAN: "203.0.113.7"}
|
||||
},
|
||||
LikeHome: map[string]any{"active": true, "bridged": true, "dev": "br-lan", "address": "192.168.77.9", "transit": "169.254.7.2"},
|
||||
Needs: map[string][]string{}, ResolverConfAge: &age, ResolverRunning: true,
|
||||
Portal: func() Portal {
|
||||
return Portal{Listening: true, IPs: []string{"203.0.113.7"}, WAN: "203.0.113.7", Cert: "/etc/ssl/acme/x.crt", Valid: true, Names: []string{"*.example.org"}}
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
func byID(list []Check) map[string]Check {
|
||||
out := map[string]Check{}
|
||||
for _, c := range list {
|
||||
out[c.ID] = c
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
||||
func TestAHealthyRouter(t *testing.T) {
|
||||
list := Run(healthy(t))
|
||||
var ids []string
|
||||
for _, c := range list {
|
||||
ids = append(ids, c.ID)
|
||||
// the plain HTTP links are a standing warning, the server turned off is skipped
|
||||
want := "ok"
|
||||
switch c.ID {
|
||||
case "portal_http":
|
||||
want = "warn"
|
||||
case "srv_cabin":
|
||||
want = "skip"
|
||||
}
|
||||
if c.Status != want || (c.Status == "ok") != (c.Problem == nil && c.Fix == nil) && c.ID != "srv_cabin" {
|
||||
t.Errorf("%s: %s %q fix %v problem %v", c.ID, c.Status, c.Detail, c.Fix, c.Problem)
|
||||
}
|
||||
}
|
||||
want := "awg clock agent flash nft policy data up_home peers_home fw_home reply_home subnet_home homenet_home ep_home home_home srv_cabin resolver portal portal_dns portal_reply portal_http cert"
|
||||
if got := strings.Join(ids, " "); got != want {
|
||||
t.Fatalf("the checks and their order:\n %s\n %s", got, want)
|
||||
}
|
||||
// two servers: each check of a server carries its name
|
||||
if c := byID(list)["up_home"]; c.Title != "Tunnel running (Home)" || c.Detail != "dawn0 is up, listening on UDP 4500." {
|
||||
t.Fatalf("a server's check: %+v", c)
|
||||
}
|
||||
}
|
||||
|
||||
func TestWhatGoesWrong(t *testing.T) {
|
||||
for name, c := range map[string]struct {
|
||||
break_ func(in *Inputs)
|
||||
id string
|
||||
status string
|
||||
fix string
|
||||
detail string
|
||||
}{
|
||||
"a package is missing": {func(in *Inputs) { in.Missing = []string{"kmod-amneziawg"} }, "awg", "error", "install:awg", "kmod-amneziawg is missing."},
|
||||
"the firmware changed": {func(in *Inputs) {
|
||||
in.Missing, in.KernelWas, in.KernelIs = []string{"kmod-amneziawg"}, "6.6.1", "6.12.9"
|
||||
}, "awg", "error", "install:awg", "kernel 6.6.1 → 6.12.9"},
|
||||
"the module won't load": {func(in *Inputs) { in.Loaded, in.WhyNotLoaded = false, "Exec format error." }, "awg", "error", "updates", "doesn't load: Exec format error. Reinstall"},
|
||||
"netifd has no protocol": {func(in *Inputs) { in.Handler = false }, "awg", "error", "netrestart", "netifd doesn't know"},
|
||||
"an update waits": {func(in *Inputs) { in.WaitsForReboot = true }, "awg", "warn", "", "after a reboot"},
|
||||
"the clock is wrong": {func(in *Inputs) { in.Year = 1970 }, "clock", "error", "", "Check NTP"},
|
||||
"the agent is gone": {func(in *Inputs) { in.AgentRunning = false }, "agent", "error", "restart", ""},
|
||||
"little flash": {func(in *Inputs) { kb := int64(1536); in.FreeKB = &kb }, "flash", "warn", "", "1.5 MB free"},
|
||||
"no flash": {func(in *Inputs) { kb := int64(100); in.FreeKB = &kb }, "flash", "error", "", "0 MB free"},
|
||||
"no access rules": {func(in *Inputs) { in.NftLoaded = false }, "nft", "error", "apply", "is missing"},
|
||||
"other policy routing": {func(in *Inputs) { in.PolicyRouting = []string{"pref 1000 fwmark 0x1 → table 100"} }, "policy", "warn", "", "(pref 1000 fwmark 0x1 → table 100)"},
|
||||
"broken devices": {func(in *Inputs) {
|
||||
in.ModelErrors = func() []string { return []string{"a.", "b.", "c.", "d.", "e.", "f."} }
|
||||
}, "data", "error", "",
|
||||
"a. b. c. d. (2 more) Such devices"},
|
||||
"the tunnel is down": {func(in *Inputs) { in.Iface = func(string) Iface { return Iface{Exists: true} } }, "up_home", "error", "ifup:dawn0", "dawn0 is down."},
|
||||
"the tunnel has an error": {func(in *Inputs) {
|
||||
in.Iface = func(string) Iface { return Iface{Exists: true, Errors: []string{"NO_DEVICE"}} }
|
||||
}, "up_home", "error", "ifup:dawn0", "is down: NO_DEVICE."},
|
||||
"the tunnel is not there": {func(in *Inputs) { in.Iface = func(string) Iface { return Iface{} } }, "up_home", "error", "apply", "does not exist"},
|
||||
"the tunnel's protocol": {func(in *Inputs) {
|
||||
in.Iface = func(string) Iface { return Iface{Exists: true, Errors: []string{"INVALID_PROTO"}} }
|
||||
}, "up_home", "error", "netrestart", "netifd doesn't know"},
|
||||
"the tunnel is unreadable": {func(in *Inputs) { in.Unread = func(string) bool { return true } }, "peers_home", "warn", "", "could not be read"},
|
||||
"a device is missing": {func(in *Inputs) {
|
||||
in.Peers = func(*model.Server) Peers { return Peers{Expected: 3, Missing: 1, Loaded: 2} }
|
||||
}, "peers_home", "warn", "sync", "1 of 3 devices missing."},
|
||||
"a device too many": {func(in *Inputs) {
|
||||
in.Peers = func(*model.Server) Peers { return Peers{Expected: 1, Extra: 2, Loaded: 3} }
|
||||
}, "peers_home", "warn", "sync", "0 of 1 device missing, 2 loaded"},
|
||||
"no firewall rule": {func(in *Inputs) { in.Firewall, _ = uci.Parse("config zone 'dawnline_home_zone'\n") }, "fw_home", "error", "apply", "is missing"},
|
||||
"answers are swallowed": {func(in *Inputs) { in.Replies = &Replies{Diverts: []string{"pref 9 → table 100"}} }, "reply_home", "error", "apply", "Answers from UDP 4500 are swallowed"},
|
||||
"a proxy that is passed": {func(in *Inputs) { in.Replies = &Replies{OK: true, Diverts: []string{"pref 9 → table 100"}} }, "portal_reply", "ok", "", "Answers from TCP 4500 go straight out. A proxy"},
|
||||
"the port is another's": {func(in *Inputs) {
|
||||
in.Network, _ = uci.Parse("config interface 'wg0'\n\toption proto 'wireguard'\n\toption listen_port '4500'\n")
|
||||
}, "port_home", "error", "", "UDP 4500 is also used by wg0."},
|
||||
"the subnet is another's": {func(in *Inputs) { in.Subnets = append(in.Subnets, Subnet{"guest", "10.77.0.129/25"}) }, "subnet_home", "error", "", "10.77.0.0/24 overlaps guest (10.77.0.129/25)."},
|
||||
"a common home network": {func(in *Inputs) { in.HomeNets = func(*model.Server) []string { return []string{"192.168.1.0/24"} } }, "homenet_home", "warn", "", "192.168.1.0/24 is one of the most common"},
|
||||
"the address is elsewhere": {func(in *Inputs) {
|
||||
in.Endpoint = func(*model.Server, string) endpoint.Reads {
|
||||
return endpoint.Reads{IPs: []string{"198.51.100.4"}, WAN: "203.0.113.7"}
|
||||
}
|
||||
}, "ep_home", "warn", "", "not this router"},
|
||||
"the home path needs a package": {func(in *Inputs) {
|
||||
in.LikeHome, in.Needs = map[string]any{"active": false}, map[string][]string{"home": {"kmod-veth"}}
|
||||
}, "home_home", "warn", "install:home", "Needs kmod-veth."},
|
||||
"the home path is unattached": {func(in *Inputs) { in.LikeHome = map[string]any{"active": true, "bridged": false, "dev": "br-lan"} }, "home_home", "warn", "apply", "not attached to br-lan"},
|
||||
"the home path was refused": {func(in *Inputs) { in.LikeHome = map[string]any{"active": false, "error": "No LAN detected."} }, "home_home", "warn", "apply", "No LAN detected. Internet traffic leaves"},
|
||||
"the home path is not set up": {func(in *Inputs) { in.LikeHome = map[string]any{"active": false, "error": nil} }, "home_home", "warn", "apply", "Not set up. Internet traffic"},
|
||||
"the resolver stopped": {func(in *Inputs) { in.ResolverRunning = false }, "resolver", "warn", "apply", "is not running"},
|
||||
"the resolver restarts": {func(in *Inputs) { age := int64(3); in.ResolverRunning, in.ResolverConfAge = false, &age }, "resolver", "ok", "", "Restarting"},
|
||||
"the resolver beside the tunnel": {func(in *Inputs) { in.LikeHome = map[string]any{"active": false} }, "resolver", "ok", "", "on port 5354"},
|
||||
"no HTTPS on the router": {func(in *Inputs) { in.Needs = map[string][]string{"https": {"openssl-util"}} }, "portal", "error", "install:https", "install openssl-util"},
|
||||
"the portal's port is taken": {func(in *Inputs) {
|
||||
in.Portal = func() Portal { return Portal{Owners: []string{"nginx"}, Listening: true} }
|
||||
}, "portal", "error", "", "already used by nginx"},
|
||||
"the portal is silent": {func(in *Inputs) { in.Portal = func() Portal { return Portal{} } }, "portal", "error", "restart", "Nothing listens on TCP 4500."},
|
||||
"the portal's name is elsewhere": {func(in *Inputs) {
|
||||
in.Portal = func() Portal {
|
||||
return Portal{Listening: true, IPs: []string{"198.51.100.4"}, WAN: "203.0.113.7", Valid: true, Names: []string{"vpn.example.org"}}
|
||||
}
|
||||
},
|
||||
"portal_dns", "warn", "", "points at 198.51.100.4, not this router (203.0.113.7)."},
|
||||
"the portal through Cloudflare": {func(in *Inputs) {
|
||||
in.Portal = func() Portal { return Portal{Listening: true, IPs: []string{"104.16.1.1"}, WAN: "203.0.113.7"} }
|
||||
}, "portal_dns", "ok", "", "Cloudflare"},
|
||||
"a self-signed certificate": {func(in *Inputs) {
|
||||
in.Portal = func() Portal { return Portal{Listening: true, SelfSigned: true} }
|
||||
in.Needs = map[string][]string{"acme": {"acme"}}
|
||||
}, "cert", "warn", "", "ACME can get"},
|
||||
"a certificate for another name": {func(in *Inputs) {
|
||||
in.Portal = func() Portal {
|
||||
return Portal{Listening: true, Cert: "/c.crt", Valid: true, Names: []string{"other.example.org"}}
|
||||
}
|
||||
}, "cert", "warn", "", "/c.crt does not cover vpn.example.org (it has other.example.org)"},
|
||||
"a certificate about to end": {func(in *Inputs) {
|
||||
in.Portal = func() Portal { return Portal{Listening: true, Cert: "/c.crt", Names: []string{"vpn.example.org"}} }
|
||||
}, "cert", "warn", "", "expires within 14 days"},
|
||||
} {
|
||||
in := healthy(t)
|
||||
c.break_(&in)
|
||||
got, has := byID(Run(in))[c.id]
|
||||
fix := ""
|
||||
if got.Fix != nil {
|
||||
fix = *got.Fix
|
||||
}
|
||||
// a common home network is advice, not a fault: it warns with no problem to put in a notice
|
||||
problem := c.status != "ok" && c.id != "homenet_home"
|
||||
if !has || got.Status != c.status || fix != c.fix || !strings.Contains(got.Detail, c.detail) || problem != (got.Problem != nil) {
|
||||
t.Errorf("%s: %s %s fix %q problem %v\n %s", name, c.id, got.Status, fix, got.Problem != nil, got.Detail)
|
||||
}
|
||||
}
|
||||
// no server yet: only what the router itself needs, and the advice to set one up
|
||||
in := healthy(t)
|
||||
c, _ := uci.Parse("config settings 'settings'\n")
|
||||
in.M = model.Load(c, nil)
|
||||
var ids []string
|
||||
for _, x := range Run(in) {
|
||||
ids = append(ids, x.ID)
|
||||
}
|
||||
if strings.Join(ids, " ") != "clock agent flash server" {
|
||||
t.Fatalf("with no server: %v", ids)
|
||||
}
|
||||
if got := CommonHome([]string{"192.168.1.0/24", "10.37.12.0/24", "192.168.0.0/16", "odd"}); strings.Join(got, " ") != "192.168.1.0/24 192.168.0.0/16" {
|
||||
t.Fatalf("common home networks: %v", got)
|
||||
}
|
||||
}
|
||||
|
||||
// The networks behind a server's routers: no check while none is written, then each in effect, or which is
|
||||
// not and what it shares addresses with, or the route the router would not take.
|
||||
func TestNetworksBehindRoutersAreChecked(t *testing.T) {
|
||||
c, err := uci.Parse(settings + `
|
||||
config person 'boris'
|
||||
option name 'Boris'
|
||||
option server 'home'
|
||||
option access 'both'
|
||||
config device 'r1'
|
||||
option person 'boris'
|
||||
option name 'Dacha'
|
||||
option kind 'router'
|
||||
option address '10.77.0.2'
|
||||
config device 'r2'
|
||||
option person 'boris'
|
||||
option name 'Garage'
|
||||
option kind 'router'
|
||||
option address '10.77.0.3'
|
||||
`)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
own := []string{"192.168.50.0/24"}
|
||||
run := func() (Check, bool) {
|
||||
m := model.Load(c, nil)
|
||||
in := Inputs{M: m, Behind: m.BehindOf(own), Own: own}
|
||||
return in.behind("home", "")
|
||||
}
|
||||
if _, has := run(); has {
|
||||
t.Error("a check with no network written")
|
||||
}
|
||||
c.SetList("r1", "behind_net", []string{"192.168.2.0/24", "172.20.0.0/16"})
|
||||
if got, has := run(); !has || got.ID != "sites_home" || got.Status != "ok" || got.Detail != "2 networks behind routers are carried by the tunnel." {
|
||||
t.Errorf("all in effect: %+v", got)
|
||||
}
|
||||
// each way a written network is not in effect, in its words
|
||||
c.SetList("r1", "behind_net", []string{"192.168.2.0/24", "10.77.0.128/25", "192.168.50.0/25", "the garage"})
|
||||
c.SetList("r2", "behind_net", []string{"192.168.2.128/25"})
|
||||
got, _ := run()
|
||||
for _, want := range []string{
|
||||
"10.77.0.128/25 behind Boris · Dacha shares addresses with the tunnel network of Home (10.77.0.0/24).",
|
||||
"192.168.50.0/25 behind Boris · Dacha shares addresses with 192.168.50.0/24, which the router has itself.",
|
||||
"the garage behind Boris · Dacha is not a network a router may have behind it.",
|
||||
"192.168.2.128/25 behind Boris · Garage shares addresses with 192.168.2.0/24 behind Dacha.",
|
||||
"Such a network is not in effect: change it in the server's Network settings.",
|
||||
} {
|
||||
if !strings.Contains(got.Detail, want) {
|
||||
t.Errorf("the check lacks %q:\n%s", want, got.Detail)
|
||||
}
|
||||
}
|
||||
if got.Status != "warn" || got.Problem == nil || *got.Problem != "A network behind a router isn’t in effect" {
|
||||
t.Errorf("networks not in effect: %+v", got)
|
||||
}
|
||||
// a router that waits for the admin's answer is not checked: nothing of it is in effect by design
|
||||
c.Set("r2", "waiting", "1")
|
||||
c.SetList("r1", "behind_net", []string{"192.168.2.0/24"})
|
||||
if got, _ := run(); got.Status != "ok" || got.Detail != "1 network behind routers is carried by the tunnel." {
|
||||
t.Errorf("with a waiting router: %+v", got)
|
||||
}
|
||||
// a route the router would not take
|
||||
m := model.Load(c, nil)
|
||||
in := Inputs{M: m, Behind: m.BehindOf(own), Own: own, RouteError: "192.168.2.0/24 dev dawn0: RTNETLINK answers: a made-up failure"}
|
||||
if got, _ := in.behind("home", ""); got.Status != "error" || got.Fix == nil || *got.Fix != "sync" || !strings.Contains(got.Detail, "a made-up failure") {
|
||||
t.Errorf("a route refused: %+v", got)
|
||||
}
|
||||
}
|
||||
Vendored
+136
@@ -0,0 +1,136 @@
|
||||
config settings 'settings'
|
||||
|
||||
config server 'home'
|
||||
option name 'Home'
|
||||
option ifname 'dawn0'
|
||||
option port '4500'
|
||||
option subnet '10.77.0.0/24'
|
||||
option private_key 'yAnz5TF+lXXJte14tji3zlMNq+hd2rYUIgJBgB3fBmk='
|
||||
option public_key 'xTIBA5rboUvnH4htodjb6e697QjLERt1NAB4mZqp8Dg='
|
||||
|
||||
config server 'cabin'
|
||||
option name 'Cabin'
|
||||
option ifname 'dawn1'
|
||||
option port '4600'
|
||||
option subnet '10.78.0.0/24'
|
||||
option private_key 'yAnz5TF+lXXJte14tji3zlMNq+hd2rYUIgJBgB3fBmk='
|
||||
|
||||
config circle 'family'
|
||||
option server 'home'
|
||||
option name 'Family'
|
||||
|
||||
config circle 'lost'
|
||||
option server 'gone'
|
||||
option name 'Lost'
|
||||
|
||||
config service 'nas'
|
||||
option name 'NAS'
|
||||
option address '192.168.1.5'
|
||||
|
||||
config person 'anna'
|
||||
option server 'home'
|
||||
option name 'Anna'
|
||||
option code 'abcdef-ghijkl-mnopqr'
|
||||
option circle 'family'
|
||||
list services 'nas'
|
||||
|
||||
config person 'boris'
|
||||
option server 'gone'
|
||||
option name 'Boris'
|
||||
option code 'abcdef-ghijkl-mnopqr'
|
||||
option circle 'nowhere'
|
||||
list services 'nas'
|
||||
list services 'printer'
|
||||
|
||||
config person 'clara'
|
||||
option server 'cabin'
|
||||
option name 'Clara'
|
||||
option paused '1'
|
||||
|
||||
config person 'dmitri'
|
||||
option server 'home'
|
||||
option name 'Dmitri'
|
||||
option expires '2020-01-01'
|
||||
|
||||
config device 'good'
|
||||
option person 'anna'
|
||||
option name 'Phone'
|
||||
option address '10.77.0.2'
|
||||
option public_key 'HIgo9xNzJMWLKASShiTqIybxZ0U3wGLiUeJ1PKf8ykw='
|
||||
option preshared_key 'TrMvSoP4jYQlY6RIzBgbssQqY3vxI2Pi+y71lOWWXX0='
|
||||
|
||||
config device 'same'
|
||||
option person 'anna'
|
||||
option name 'Tablet'
|
||||
option address '10.77.0.2'
|
||||
option public_key 'TrMvSoP4jYQlY6RIzBgbssQqY3vxI2Pi+y71lOWWXX0='
|
||||
|
||||
config device 'off'
|
||||
option person 'anna'
|
||||
option name 'Old laptop'
|
||||
option address '10.77.0.9'
|
||||
option public_key 'AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA='
|
||||
option disabled '1'
|
||||
|
||||
config device 'badkey'
|
||||
option person 'anna'
|
||||
option name 'Laptop'
|
||||
option address '10.77.0.3'
|
||||
option public_key 'not a key'
|
||||
option private_key 'neither'
|
||||
option preshared_key 'nor this'
|
||||
option mtu '9000'
|
||||
option keepalive '9999'
|
||||
|
||||
config device 'noaddr'
|
||||
option person 'anna'
|
||||
option name 'Watch'
|
||||
option public_key 'BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBA='
|
||||
|
||||
config device 'oddaddr'
|
||||
option person 'anna'
|
||||
option name 'TV'
|
||||
option address '10.77.0.300'
|
||||
option public_key 'CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCA='
|
||||
|
||||
config device 'outside'
|
||||
option person 'anna'
|
||||
option name 'Console'
|
||||
option address '10.99.0.4'
|
||||
option public_key 'DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDA='
|
||||
|
||||
config device 'routers'
|
||||
option person 'anna'
|
||||
option name 'Camera'
|
||||
option address '10.77.0.1'
|
||||
option public_key 'EEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEA='
|
||||
|
||||
config device 'ownkey'
|
||||
option person 'anna'
|
||||
option name 'Mirror'
|
||||
option address '10.77.0.7'
|
||||
option public_key 'xTIBA5rboUvnH4htodjb6e697QjLERt1NAB4mZqp8Dg='
|
||||
|
||||
config device 'orphan'
|
||||
option person 'nobody'
|
||||
option name 'Orphan'
|
||||
option address '10.77.0.8'
|
||||
option public_key 'FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFA='
|
||||
|
||||
config device 'noserver'
|
||||
option person 'boris'
|
||||
option name 'Boris phone'
|
||||
option address '10.77.0.2'
|
||||
option public_key 'GGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGA='
|
||||
|
||||
config device 'paused'
|
||||
option person 'clara'
|
||||
option name 'Clara phone'
|
||||
option address '10.78.0.2'
|
||||
option public_key 'HHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHA='
|
||||
|
||||
config device 'expired'
|
||||
option person 'dmitri'
|
||||
option name 'Dmitri phone'
|
||||
option address '10.77.0.20'
|
||||
option public_key 'IIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIA='
|
||||
Vendored
+47
@@ -0,0 +1,47 @@
|
||||
config settings 'settings'
|
||||
|
||||
config server 'home'
|
||||
option name 'Home'
|
||||
option ifname 'dawn0'
|
||||
option port '4500'
|
||||
option subnet '10.77.0.0/24'
|
||||
option private_key 'yAnz5TF+lXXJte14tji3zlMNq+hd2rYUIgJBgB3fBmk='
|
||||
|
||||
config server 'twin'
|
||||
option name 'Twin'
|
||||
option ifname 'dawn0'
|
||||
option port '4500'
|
||||
option subnet '10.77.0.128/25'
|
||||
option endpoint 'bad host'
|
||||
|
||||
config server 'lanname'
|
||||
option name 'Lan name'
|
||||
option ifname 'lan'
|
||||
option port '4600'
|
||||
option subnet '10.80.0.0/24'
|
||||
|
||||
config server 'ours'
|
||||
option name 'Ours'
|
||||
option ifname 'dawn5'
|
||||
option port '4700'
|
||||
option subnet '10.81.0.0/24'
|
||||
|
||||
config server 'internal'
|
||||
option name 'Internal'
|
||||
option ifname 'dlx0'
|
||||
option port '0'
|
||||
option subnet 'ten'
|
||||
|
||||
config server 'odd'
|
||||
option name 'Odd'
|
||||
option ifname 'Bad-Name-Too-Long'
|
||||
option port '70000'
|
||||
option subnet '10.82.0.0/24'
|
||||
option jmin '90'
|
||||
option jmax '50'
|
||||
option h1 '5'
|
||||
option h2 '5'
|
||||
|
||||
config person 'anna'
|
||||
option server 'gone'
|
||||
option name 'Anna'
|
||||
Vendored
+170
@@ -0,0 +1,170 @@
|
||||
{
|
||||
"ts": 1800000000,
|
||||
"errors": [
|
||||
"Person Boris: server gone does not exist.",
|
||||
"Person Boris: circle nowhere does not exist.",
|
||||
"Person Boris: has the same personal link as Anna.",
|
||||
"Device Tablet of Anna: address 10.77.0.2 is also used by device Phone of Anna.",
|
||||
"Device Laptop of Anna: the public key is not a key.",
|
||||
"Device Laptop of Anna: the private key is not a key.",
|
||||
"Device Laptop of Anna: the preshared key is not a key.",
|
||||
"Device Laptop of Anna: MTU 9000 is not between 1280 and 1500.",
|
||||
"Device Laptop of Anna: keep-alive 9999 is not between 0 and 600 seconds.",
|
||||
"Device Watch of Anna: address (none) is not a plain IPv4 address.",
|
||||
"Device TV of Anna: address 10.77.0.300 is not a plain IPv4 address.",
|
||||
"Device Console of Anna: address 10.99.0.4 is outside Home's tunnel 10.77.0.0/24.",
|
||||
"Device Camera of Anna: address 10.77.0.1 is the router's own address on Home.",
|
||||
"Device Mirror of Anna: the public key is the server's own.",
|
||||
"Device Orphan: person nobody does not exist.",
|
||||
"Circle Lost: server gone does not exist."
|
||||
],
|
||||
"states": {
|
||||
"anna": "active",
|
||||
"boris": "no_server",
|
||||
"clara": "paused",
|
||||
"dmitri": "expired"
|
||||
},
|
||||
"tunnels": {
|
||||
"home": [
|
||||
"good",
|
||||
"same",
|
||||
"outside",
|
||||
"routers"
|
||||
],
|
||||
"cabin": [
|
||||
]
|
||||
},
|
||||
"diffs": [
|
||||
{
|
||||
"server": "home",
|
||||
"loaded": [
|
||||
"HIgo9xNzJMWLKASShiTqIybxZ0U3wGLiUeJ1PKf8ykw=",
|
||||
"TrMvSoP4jYQlY6RIzBgbssQqY3vxI2Pi+y71lOWWXX0=",
|
||||
"DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDA=",
|
||||
"EEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEA="
|
||||
],
|
||||
"diff": {
|
||||
"loaded": 4,
|
||||
"missing": 0,
|
||||
"extra": 0
|
||||
}
|
||||
},
|
||||
{
|
||||
"server": "home",
|
||||
"loaded": [
|
||||
"TrMvSoP4jYQlY6RIzBgbssQqY3vxI2Pi+y71lOWWXX0=",
|
||||
"DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDA=",
|
||||
"EEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEA="
|
||||
],
|
||||
"diff": {
|
||||
"loaded": 3,
|
||||
"missing": 1,
|
||||
"extra": 0
|
||||
}
|
||||
},
|
||||
{
|
||||
"server": "home",
|
||||
"loaded": [
|
||||
"HIgo9xNzJMWLKASShiTqIybxZ0U3wGLiUeJ1PKf8ykw=",
|
||||
"TrMvSoP4jYQlY6RIzBgbssQqY3vxI2Pi+y71lOWWXX0=",
|
||||
"DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDA=",
|
||||
"EEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEA=",
|
||||
"ZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZA="
|
||||
],
|
||||
"diff": {
|
||||
"loaded": 5,
|
||||
"missing": 0,
|
||||
"extra": 1
|
||||
}
|
||||
},
|
||||
{
|
||||
"server": "home",
|
||||
"loaded": [
|
||||
"ZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZA="
|
||||
],
|
||||
"diff": {
|
||||
"loaded": 1,
|
||||
"missing": 4,
|
||||
"extra": 1
|
||||
}
|
||||
},
|
||||
{
|
||||
"server": "home",
|
||||
"loaded": [
|
||||
],
|
||||
"diff": {
|
||||
"loaded": 0,
|
||||
"missing": 4,
|
||||
"extra": 0
|
||||
}
|
||||
},
|
||||
{
|
||||
"server": "cabin",
|
||||
"loaded": [
|
||||
],
|
||||
"diff": {
|
||||
"loaded": 0,
|
||||
"missing": 0,
|
||||
"extra": 0
|
||||
}
|
||||
},
|
||||
{
|
||||
"server": "cabin",
|
||||
"loaded": [
|
||||
],
|
||||
"diff": {
|
||||
"loaded": 0,
|
||||
"missing": 0,
|
||||
"extra": 0
|
||||
}
|
||||
},
|
||||
{
|
||||
"server": "cabin",
|
||||
"loaded": [
|
||||
"ZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZA="
|
||||
],
|
||||
"diff": {
|
||||
"loaded": 1,
|
||||
"missing": 0,
|
||||
"extra": 1
|
||||
}
|
||||
},
|
||||
{
|
||||
"server": "cabin",
|
||||
"loaded": [
|
||||
"ZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZA="
|
||||
],
|
||||
"diff": {
|
||||
"loaded": 1,
|
||||
"missing": 0,
|
||||
"extra": 1
|
||||
}
|
||||
},
|
||||
{
|
||||
"server": "cabin",
|
||||
"loaded": [
|
||||
],
|
||||
"diff": {
|
||||
"loaded": 0,
|
||||
"missing": 0,
|
||||
"extra": 0
|
||||
}
|
||||
}
|
||||
],
|
||||
"network": "config interface 'lan'\n\toption proto 'static'\n\nconfig device 'odd'\n\nconfig interface 'dawn5'\n\toption proto 'amneziawg'\n\toption _dawnline '1'\n",
|
||||
"config_errors": [
|
||||
"Person Anna: server gone does not exist.",
|
||||
"Server Twin: Subnet overlaps 10.77.0.0/24.",
|
||||
"Server Twin: Endpoint must be a hostname or IP address.",
|
||||
"Server Twin: interface dawn0 is also used by Home.",
|
||||
"Server Twin: UDP 4500 is also used by Home.",
|
||||
"Server Lan name: lan is one of the router's own network interfaces.",
|
||||
"Server Internal: Port must be 1-65535.",
|
||||
"Server Internal: Subnet must look like 10.77.0.0/24.",
|
||||
"Server Internal: dlx0 is one of the router's own network interfaces.",
|
||||
"Server Odd: Interface name: 1-12 lowercase letters, digits or _.",
|
||||
"Server Odd: Port must be 1-65535.",
|
||||
"Server Odd: Jmin must not be larger than Jmax.",
|
||||
"Server Odd: H1 and H2 overlap: each packet type needs values of its own."
|
||||
]
|
||||
}
|
||||
Reference in new issue
Block a user