Zone matrix: partly, what is let through, hits; hc matrix aligned
A cell reads allow, block or partly (some new connections let through, the rest not), with its exceptions counted by what they do (+3 -1), and what they let through: services with the addresses they are limited to, under the grid in hc matrix and in each cell on the Matrix page. A zone to itself is marked: only traffic routed between its interfaces passes the firewall. The details list each rule's hits. hc matrix pads the grid by visible width: the colours' escape codes had thrown it out of line. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
429c910df1
commit
5ee324c588
14 files changed
+423
-65
No files matched your search
@@ -15,6 +15,7 @@ import (
|
||||
"housecarl/internal/engine"
|
||||
"housecarl/internal/matrix"
|
||||
"housecarl/internal/model"
|
||||
"housecarl/internal/nft"
|
||||
"housecarl/internal/store"
|
||||
)
|
||||
|
||||
@@ -471,10 +472,39 @@ func (s *Server) zoneMatrix(w http.ResponseWriter, r *http.Request, p *auth.Prin
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
writeJSON(w, http.StatusOK, matrix.Build(st, matrix.Options{Connected: s.connected(st)}))
|
||||
m := matrix.Build(st, matrix.Options{Connected: s.connected(st)})
|
||||
if t, err := s.fw.Table(r.Context()); err == nil {
|
||||
matrixHits(&m, t.Counters)
|
||||
}
|
||||
writeJSON(w, http.StatusOK, m)
|
||||
return nil
|
||||
}
|
||||
|
||||
// matrixHits fills in the hits of the matrix's rules, built-ins and
|
||||
// policies from the counters.
|
||||
func matrixHits(m *api.Matrix, counters map[string]nft.Counter) {
|
||||
hits := func(marks []string) *uint64 {
|
||||
var n uint64
|
||||
found := false
|
||||
for _, mk := range marks {
|
||||
if c, ok := counters[mk]; ok {
|
||||
n, found = n+c.Packets, true
|
||||
}
|
||||
}
|
||||
if !found {
|
||||
return nil
|
||||
}
|
||||
return &n
|
||||
}
|
||||
for i := range m.Cells {
|
||||
c := &m.Cells[i]
|
||||
c.Hits = hits(c.Marks)
|
||||
for j := range c.Exceptions {
|
||||
c.Exceptions[j].Hits = hits(c.Exceptions[j].Marks)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// connected maps the networks on the firewall's interfaces (link-local
|
||||
// and loopback aside) to their zones.
|
||||
func (s *Server) connected(st *model.State) map[netip.Prefix]string {
|
||||
|
||||
@@ -891,6 +891,13 @@ func TestMatrixEndpoint(t *testing.T) {
|
||||
if c := cell("lan", "wan"); c.Verdict != "allowed" {
|
||||
t.Errorf("lan → wan with the changeset: %+v", c)
|
||||
}
|
||||
// Hits: summed over an object's counters; none without a counter.
|
||||
hm := api.Matrix{Cells: []api.MatrixCell{{Marks: []string{"p-forward"}, Exceptions: []api.MatrixException{
|
||||
{Marks: []string{"b-antispoof", "b-antispoof6"}}, {Marks: []string{"r9"}}}}}}
|
||||
matrixHits(&hm, map[string]nft.Counter{"p-forward": {Packets: 4}, "b-antispoof": {Packets: 2}, "b-antispoof6": {Packets: 3}})
|
||||
if c := hm.Cells[0]; c.Hits == nil || *c.Hits != 4 || c.Exceptions[0].Hits == nil || *c.Exceptions[0].Hits != 5 || c.Exceptions[1].Hits != nil {
|
||||
t.Errorf("hits: %+v", c)
|
||||
}
|
||||
}
|
||||
|
||||
// TestHostProblems: an enabled nftables.service, and an imported table
|
||||
|
||||
Reference in new issue
Block a user