Files
Aemeath ac90575b0b
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
Dawnline 0.20.0
- **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.
2026-11-13 09:43:50 +03:00

192 lines
7.6 KiB
Go

package apply
import (
"encoding/json"
"os"
"reflect"
"sort"
"strings"
"testing"
"github.com/tickcount/luci-app-dawnline/backend/i18n"
"github.com/tickcount/luci-app-dawnline/backend/model"
"github.com/tickcount/luci-app-dawnline/backend/netview"
"github.com/tickcount/luci-app-dawnline/backend/uci"
"github.com/tickcount/luci-app-dawnline/backend/usage"
)
// routed is a router that keeps the routes it is given, besides what stand keeps.
type routed struct {
stand
routes map[string]bool
fail string
ran []string
}
func (s *routed) exec(name string, args ...string) (string, int) {
if name != "ip" {
return s.stand.exec(name, args...)
}
line := strings.Join(args, " ")
switch {
case line == "-j -4 route show proto "+routeProto:
var list []IPRoute
for k := range s.routes {
f := strings.Fields(k)
list = append(list, IPRoute{Dev: f[0], Dst: f[1]})
}
sort.Slice(list, func(i, j int) bool { return list[i].Dev+list[i].Dst < list[j].Dev+list[j].Dst })
raw, _ := json.Marshal(list)
return string(raw), 0
case strings.HasPrefix(line, "-4 route replace ") && strings.HasSuffix(line, " proto "+routeProto+" scope link"):
s.ran = append(s.ran, line)
if s.fail != "" && strings.Contains(line, s.fail) {
return "RTNETLINK answers: a made-up failure\n", 2
}
s.routes[args[5]+" "+args[3]] = true
case strings.HasPrefix(line, "-4 route del ") && strings.HasSuffix(line, " proto "+routeProto):
s.ran = append(s.ran, line)
delete(s.routes, args[5]+" "+args[3])
default:
return "unknown: ip " + line, 1
}
return "", 0
}
// Access's household on the golden's router, with two routers that have networks behind them and one
// whose network the router has itself.
func sites(t *testing.T) (*uci.Config, *netview.Snapshot) {
t.Helper()
text, err := os.ReadFile("../access/testdata/access.uci")
if err != nil {
t.Fatal(err)
}
c, err := uci.Parse(string(text))
if err != nil {
t.Fatal(err)
}
c.Set("bphone", "kind", "router")
c.SetList("bphone", "behind_net", []string{"192.168.2.0/24", "172.20.0.0/16"})
c.Set("kphone", "kind", "router")
c.SetList("kphone", "behind_net", []string{"192.168.3.0/24"})
c.Set("hphone", "kind", "router")
c.SetList("hphone", "behind_net", []string{"192.168.50.0/24"})
raw, err := os.ReadFile("../netview/testdata/trace.json")
if err != nil {
t.Fatal(err)
}
var router struct {
Routes json.RawMessage `json:"routes"`
Addrs json.RawMessage `json:"addrs"`
Links map[string]netview.Link `json:"links"`
}
if err := json.Unmarshal(raw, &router); err != nil {
t.Fatal(err)
}
return c, netview.Take(netview.Sources{Routes: func() []byte { return router.Routes }, Addrs: func() []byte { return router.Addrs },
Links: func() map[string]netview.Link { return router.Links }})
}
func TestRoutesFollowTheTunnels(t *testing.T) {
c, snap := sites(t)
dir := t.TempDir()
s := &routed{stand: stand{dir: dir, refuse: map[string]bool{}, down: map[string]bool{}, confs: map[string]string{}}, routes: map[string]bool{}}
r := &Router{RunDir: dir, HostsFile: dir + "/hosts/dawnline", DHCP: dir + "/no-dhcp", Exec: s.exec, Snapshot: func() *netview.Snapshot { return snap }}
words := i18n.Use("", "")
have := func() []string {
out := []string{}
for k := range s.routes {
out = append(out, k)
}
sort.Strings(out)
return out
}
sync := func() Result {
s.ran = nil
return r.Sync(model.Load(c, nil), &usage.Usage{}, 1700000000, false, words)
}
// each router's networks leave through its own tunnel; what the router has itself gets no route
res := sync()
all := []string{"dawn0 172.20.0.0/16", "dawn0 192.168.2.0/24", "dawn2 192.168.3.0/24"}
if !reflect.DeepEqual(have(), all) || res.Routes != "" || res.Warning != "" {
t.Fatalf("routes %v, %q, %q", have(), res.Routes, res.Warning)
}
// the tunnel is told whose they are, and nobody else gets more than an address
if conf := s.confs["dawn0"]; !strings.Contains(conf, "AllowedIPs = 10.77.0.5/32, 192.168.2.0/24, 172.20.0.0/16\n") ||
strings.Count(conf, "/32\n") != strings.Count(conf, "AllowedIPs = ")-1 {
t.Errorf("dawn0's devices:\n%s", conf)
}
if conf := s.confs["dawn1"]; strings.Contains(conf, "192.168.50.0/24") {
t.Errorf("dawn1 was given a network the router has itself:\n%s", conf)
}
// nothing moved: nothing is run
if sync(); len(s.ran) != 0 {
t.Errorf("ran %v with nothing to do", s.ran)
}
// its owner paused: the route goes with the device
c.Set("boris", "paused", "1")
if sync(); !reflect.DeepEqual(have(), []string{"dawn2 192.168.3.0/24"}) {
t.Errorf("with Boris paused: %v", have())
}
c.Delete("boris", "paused")
// a tunnel that refuses its devices, and one that is down: no route leads into either
s.refuse["dawn0"], s.down["dawn2"] = true, true
if sync(); len(have()) != 0 {
t.Errorf("into tunnels that hold nobody: %v", have())
}
s.refuse["dawn0"], s.down["dawn2"] = false, false
// a route that will not go in is told, once in the log's file, and the others still go in
s.fail = "192.168.2.0/24"
res = sync()
if !reflect.DeepEqual(have(), []string{"dawn0 172.20.0.0/16", "dawn2 192.168.3.0/24"}) || !strings.Contains(res.Routes, "192.168.2.0/24 dev dawn0: RTNETLINK answers: a made-up failure") ||
!strings.Contains(res.Warning, "192.168.2.0/24 dev dawn0") {
t.Errorf("a route refused: %v, %q, %q", have(), res.Routes, res.Warning)
}
if kept, _ := os.ReadFile(dir + "/routes.err"); string(kept) != res.Routes {
t.Errorf("kept %q", kept)
}
s.fail = ""
if res = sync(); !reflect.DeepEqual(have(), all) || res.Routes != "" {
t.Errorf("after the failure: %v, %q", have(), res.Routes)
}
if _, err := os.Stat(dir + "/routes.err"); err == nil {
t.Error("the failure is still kept")
}
// a network taken off, a router that is one no more, and a route of ours nobody wants
c.SetList("bphone", "behind_net", []string{"172.20.0.0/16"})
c.Set("kphone", "kind", "phone")
s.routes["dawn9 192.168.99.0/24"] = true
if sync(); !reflect.DeepEqual(have(), []string{"dawn0 172.20.0.0/16"}) {
t.Errorf("after the changes: %v", have())
}
// a router that waits for the admin's answer: no device of the tunnel, no route to what it asks for
c.Set("kphone", "kind", "router")
c.Set("kphone", "waiting", "1")
if sync(); !reflect.DeepEqual(have(), []string{"dawn0 172.20.0.0/16"}) || strings.Contains(s.confs["dawn2"], "10.79.0.2/32") || !strings.Contains(s.confs["dawn2"], "10.79.0.3/32") {
t.Errorf("with Kira's router waiting: %v\n%s", have(), s.confs["dawn2"])
}
// the plan of a sync names them too
p := r.Plan(model.Load(c, nil), &usage.Usage{}, 1700000000)
if !reflect.DeepEqual(p.Routes, map[string][]string{"dawn0": {"172.20.0.0/16"}}) {
t.Errorf("the plan's routes: %v", p.Routes)
}
}
func TestRouteCommands(t *testing.T) {
want := map[string][]string{"dawn1": {"192.168.3.0/24"}, "dawn0": {"172.20.0.0/16", "192.168.2.0/24"}}
have := []IPRoute{{Dst: "192.168.2.0/24", Dev: "dawn0"}, {Dst: "192.168.2.0/24", Dev: "dawn1"}, {Dst: "10.9.0.0/24", Dev: "dawn7"}}
got := RouteCmds(want, have)
exp := [][]string{
{"-4", "route", "replace", "172.20.0.0/16", "dev", "dawn0", "proto", routeProto, "scope", "link"},
{"-4", "route", "replace", "192.168.3.0/24", "dev", "dawn1", "proto", routeProto, "scope", "link"},
{"-4", "route", "del", "192.168.2.0/24", "dev", "dawn1", "proto", routeProto},
{"-4", "route", "del", "10.9.0.0/24", "dev", "dawn7", "proto", routeProto},
}
if !reflect.DeepEqual(got, exp) {
t.Errorf("commands:\n%v\nwant\n%v", got, exp)
}
if got := RouteCmds(want, []IPRoute{{Dst: "172.20.0.0/16", Dev: "dawn0"}, {Dst: "192.168.2.0/24", Dev: "dawn0"}, {Dst: "192.168.3.0/24", Dev: "dawn1"}}); len(got) != 0 {
t.Errorf("as wanted, yet %v", got)
}
}