Repository navigation
Expand file tree
/
Copy pathsloth.h
More file actions
4767 lines (4449 loc) · 240 KB
/
Copy pathsloth.h
File metadata and controls
4767 lines (4449 loc) · 240 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#ifndef SLOTH_H
#define SLOTH_H
#include <stdint.h>
#include <time.h>
/* beacon_ap_t embeds a reg_ie_t (#101). Every header
* sloth.h pulls in depends on nothing in sloth.h itself; this one
* needs only <stdint.h>, and the alternative was a second copy of
* the type. */
#include "reg_ie.h"
#include "reg_6g.h" /* beacon_ap_t embeds reg_6g_t too (#101 slice B) */
#include "rf_track.h" /* the distance data point rows embed (2026-10-26) */
/* The view and alert-type lists, each generated from its own .def
* (#117). Re-included here so every file that took view_t or
* alert_type_t from sloth.h still does; neither depends on anything
* below. */
#include "sloth_view.h"
#include "sloth_alert.h"
#define SLOTH_VERSION "1.8.7"
/* The JSONL record stream's own contract version, reported as
* `jsonl_version` on every `sensor_health` line (ADR 0007, #185 item 3).
* Kept apart from SLOTH_VERSION deliberately: that one is this tree's
* semantic version, this one is what a consumer codes against, and they
* move for different reasons — a release that changes no record leaves
* this alone, and a record change between releases does not wait for a
* tag.
*
* MAJOR.MINOR.PATCH. The bump rule, in prose and with the reasoning, is
* docs/wiki/jsonl-schema.md "Versioning":
* MINOR a record type or a field was added, or an optional field
* became present in a case where it was absent before —
* additive, which is the only kind of change MISSION.md §4
* item 3 permits here;
* PATCH an emitted value was corrected with no field added, renamed
* or removed;
* MAJOR anything non-additive. That is an external-contract break,
* so it is a stop-and-ask (agents/dark-factory.md §4.3) and
* never a slice's own call; tests/test_jsonl.c pins the MAJOR
* so a bump has to argue with a test.
*
* 2.0.0 (#216, owner sign-off 2026-11-15, ADR 0010) is the one MAJOR so
* far: the sensor became two daemons, and the decoders' records, their
* sensor_health blocks and source_status rows, the gnss_* records and
* ADSB_EMERGENCY / GNSS_* left sloth-wifi's stream for sloth-rf's. Both
* daemons report this one value. The table of what moved is
* docs/wiki/jsonl-schema.md "1.x to 2.0.0".
*
* 1.0.0 is where the DECLARED contract starts, not a claim about the
* stream's history — the records predate the field by many releases. A
* `sensor_health` line with no `jsonl_version` is from a stream written
* before this version and says nothing more than that. */
#define SLOTH_JSONL_VERSION "2.21.0"
#define MAX_IFACES 32
#define MAX_CONNS 1024
#define MAX_WIFI_APS 64
#define MAX_PACKETS 256
#define POLL_MS 250 /* dashboard refresh interval default. Overridable via --refresh-ms. The TUI loop also wakes early on alert fires (see src/event_wake.h), so this is an upper bound on stale-render time, not a fixed cadence. */
#define HIST_LEN 30 /* rate history samples per interface (sparkline) */
/* Cross-platform key codes — outside ASCII range, returned by tui_poll_key() */
#define SLOTH_KEY_UP 0x101
#define SLOTH_KEY_DOWN 0x102
#define SLOTH_KEY_BACKSPACE 0x103
/* ── Views ──────────────────────────────────────────────── */
/* view_t, VIEW_COUNT, view_label() and view_for_key() live in
* sloth_view.h, generated from sloth_views.def (#117). */
/* ── Interface stats ────────────────────────────────────── */
/* Link-layer / mode label. IFACE_MODE_MONITOR is what the "any WiFi
* radio in monitor mode?" check keys on — see rule_no_monitor_mode(). */
typedef enum {
IFACE_MODE_UNKNOWN = 0,
IFACE_MODE_ETHER, /* ARPHRD_ETHER, loopback, virtuals */
IFACE_MODE_WIFI, /* ARPHRD_IEEE80211 (managed / station) */
IFACE_MODE_MONITOR, /* ARPHRD_IEEE80211_RADIOTAP / PRISM */
} iface_mode_t;
typedef struct {
char name[16];
uint8_t mac[6]; /* hardware address; all-zero = unknown */
iface_mode_t mode; /* IFACE_MODE_* — WIFI vs MONITOR matters */
uint64_t rx_bytes;
uint64_t tx_bytes;
uint64_t rx_packets;
uint64_t tx_packets;
uint64_t rx_errors;
uint64_t rx_drops;
uint64_t tx_errors;
uint64_t tx_drops;
double rx_rate; /* bytes/sec since last poll */
double tx_rate;
uint32_t mtu; /* 0 = unknown */
int32_t speed_mbps; /* -1 = unknown */
} iface_stat_t;
/* ── Interface rate history (sparkline data) ────────────── */
typedef struct {
char name[16];
double rx[HIST_LEN];
double tx[HIST_LEN];
int head; /* next write slot */
int count; /* entries populated (≤ HIST_LEN) */
} iface_hist_t;
/* ── Connections ────────────────────────────────────────── */
#define PROTO_TCP 6
#define PROTO_UDP 17
/* TCP socket state (conn_t.state), mirroring the kernel TCP_* enum as
reported by /proc/net/tcp. Only LISTEN is consulted outside jsonl's
pretty-printer: scan detection uses it to tell an inbound connection
(remote reached a port we listen on) from an outbound one whose local
port is just an ephemeral source port. See src/scan.c / issue #41. */
#define TCP_STATE_LISTEN 0x0A
typedef struct {
char local_addr[46];
char remote_addr[46];
uint16_t local_port;
uint16_t remote_port;
int proto;
int state;
int pid;
char proc[16];
unsigned long inode; /* socket inode for PID resolution */
uint32_t rtt_us; /* smoothed RTT in microseconds (TCP only, 0=unknown) */
uint32_t retrans; /* total retransmissions (TCP only) */
} conn_t;
/* ── Per-connection bandwidth snapshot ──────────────────── */
#define CONN_BW_HIST 20
typedef struct {
char local_addr[46];
uint16_t local_port;
char remote_addr[46];
uint16_t remote_port;
int proto;
double rx_rate; /* bytes/sec */
double tx_rate;
/* Cumulative bytes since the bw entry was created (since the flow
* was first observed by the pcap thread). 0 if WITH_PCAP=0. */
uint64_t rx_bytes;
uint64_t tx_bytes;
float rx_hist[CONN_BW_HIST];
float tx_hist[CONN_BW_HIST];
int hist_head;
int hist_count;
} conn_bw_t;
/* ── Connection view state ──────────────────────────────── */
typedef enum {
CONN_SORT_STATE = 0,
CONN_SORT_PROTO = 1,
CONN_SORT_LPORT = 2,
CONN_SORT_PID = 3,
CONN_SORT_BW = 4,
CONN_SORT_RTT = 5,
CONN_SORT_COUNT
} conn_sort_t;
typedef enum {
CONN_FILTER_ALL = 0,
CONN_FILTER_TCP = 1,
CONN_FILTER_UDP = 2,
CONN_FILTER_COUNT
} conn_filter_t;
/* ── Port scan detection ────────────────────────────────── */
#define MAX_SCAN_ENTRIES 32
#define MAX_SCAN_PORTS 64
#define SCAN_PORT_THRESH 8 /* distinct local ports from one IP to flag */
#define SCAN_TTL_SECS 60 /* seconds to keep entry after last activity */
typedef struct {
char ip[46];
uint16_t ports[MAX_SCAN_PORTS]; /* distinct local ports seen from this IP */
int port_count;
time_t first_seen;
time_t last_seen;
int flagged; /* port_count >= SCAN_PORT_THRESH */
} scan_entry_t;
/* ── NetBIOS Name Service entries ───────────────────────── */
#define MAX_NBNS_NAMES 64
typedef struct {
char name[16]; /* decoded NetBIOS name, NUL-terminated */
char ip[46]; /* resolved IP, "" = not yet known */
uint8_t suffix; /* service type: 0x00=workstation 0x20=SMB … */
time_t last_seen;
} nbns_name_t;
/* ── mDNS local services ────────────────────────────────── */
#define MAX_MDNS_SERVICES 64
typedef struct {
char instance[64]; /* "My Printer._ipp._tcp.local" */
char service[32]; /* "_ipp._tcp" */
char host[64]; /* SRV target hostname */
char ip[46]; /* resolved IP, "" = unknown */
uint16_t port; /* SRV port, 0 = unknown */
time_t last_seen;
} mdns_service_t;
/* ── SSDP/UPnP devices ──────────────────────────────────── */
#define MAX_SSDP_DEVICES 64
typedef struct {
char ip[46]; /* source IP of the announcing device */
char type[80]; /* NT (notify) or ST (search target) */
char usn[96]; /* Unique Service Name */
char location[96]; /* LOCATION: URL, "" = unknown */
char nts[16]; /* "alive", "byebye", "search" */
time_t last_seen;
/* SERVER: header, "" = never seen (#106 slice A). UDA 1.0 §1.1.2
* puts the product name here; CAM_SSDP_DEVICE reads it to tell a
* camera's Basic:1 root from anything else's. Sticky: a byebye
* carries no SERVER and must not erase what an alive said. */
char server[96];
/* Per-family source address of the same row (#106 round 2): a USN
* announced over both 239.255.255.250 and ff02::c (UDA 2.0 §1, Discovery)
* keeps one address per family, so a join by IP does not follow
* whichever family spoke last. ip[] stays the latest source. */
char ip4[46];
time_t ip4_seen;
char ip6[46];
time_t ip6_seen;
} ssdp_device_t;
/* ── WS-Discovery / ONVIF devices (#106 slice 1) ──────────
* Passive observation of UDP/3702 multicast discovery traffic.
* sloth sends nothing here: it only reads the Hello / Bye /
* ProbeMatches / ResolveMatches a device already broadcasts to
* announce itself (OASIS WS-Discovery 1.1, 2009-07-01). */
#define MAX_ONVIF_DEVICES 32
typedef struct {
char ip[46]; /* source IP of the announcing device */
char uuid[48]; /* EndpointReference, "urn:uuid:..." or ""*/
char types[96]; /* d:Types content, e.g. "dn:NetworkVideoTransmitter" */
char scopes[192]; /* d:Scopes content, space-separated onvif:// URIs */
char xaddrs[160]; /* d:XAddrs content, device service URL */
char kind[16]; /* "Hello", "Bye", "ProbeMatch", "ResolveMatch" */
int is_camera; /* 1 if Types names a NetworkVideoTransmitter */
time_t last_seen;
/* Per-family source address (#106 round 2). WS-Discovery runs on
* 239.255.255.250 and ff02::c (WS-Discovery 1.1 §2.4), and a row is
* keyed by EndpointReference, so one camera's Hellos arrive from
* both an IPv4 and an IPv6 source. ip[] is the latest; these keep
* one per family so the device join does not flap between them. */
char ip4[46];
time_t ip4_seen;
char ip6[46];
time_t ip6_seen;
} onvif_device_t;
/* ── RTSP stream exposure (#106 slice B) ─────────────────
* One row per (server IP, server port, Request-URI path) whose
* DESCRIBE sloth saw answered (RFC 2326 §10.2, RFC 7826 §13.2).
* Counts only: no Authorization value, no URL userinfo and no
* credential-shaped query is ever copied into a row — a request
* carrying any of those is either counted as authenticated (header
* present) or not tracked at all (credential in the URL). The
* cleartext_creds.h guardrail applies here unchanged. */
#define MAX_RTSP_STREAMS 32
#define RTSP_PATH_LEN 128
typedef struct {
char server[46]; /* responder IP */
uint16_t port; /* responder TCP port (554, 8554) */
char path[RTSP_PATH_LEN]; /* abs_path, query/fragment stripped */
char client[46]; /* last requester whose DESCRIBE was answered */
uint32_t anon_ok; /* 200 to a DESCRIBE with no Authorization,
* on a connection that had no 401 before */
uint32_t auth_ok; /* 200 to a DESCRIBE that carried one, or
* followed a 401 on the same connection */
uint32_t challenged; /* 401 to a DESCRIBE */
char auth_scheme[16]; /* first token of the last WWW-Authenticate */
uint8_t sdp; /* a 200 named Content-Type application/sdp */
time_t first_seen;
time_t last_seen;
} rtsp_stream_t;
/* ── Live DHCP snoop events ─────────────────────────────── */
#define MAX_DHCP_EVENTS 128
#define MAX_DHCP_ROUTES 8 /* option 121 routes kept per client row, #263 */
/* One option 121 (RFC 3442) classless static route, host byte order,
* zero-padded past prefix_len. next_hop is always the full 4 bytes the
* option carries, regardless of prefix_len. */
typedef struct {
uint8_t prefix_len; /* 0-32 */
uint32_t prefix;
uint32_t next_hop;
} dhcp_route_t;
typedef struct {
char mac[18]; /* "aa:bb:cc:dd:ee:ff" */
char ip[46]; /* assigned IP, "" = not yet known */
char hostname[64]; /* option 12, "" = unknown */
uint8_t msg_type; /* 1=DISCOVER 3=REQUEST 5=ACK … */
/* DHCP option 54 (Server Identifier) — set on server replies
* (OFFER / ACK / NAK). Multiple distinct values across events
* signal a rogue DHCP server on the segment. "" on client
* requests (DISCOVER / REQUEST / DECLINE / RELEASE / INFORM). */
char server_ip[46];
/* Option 55 Parameter Request List and option 60 Vendor Class
* Identifier (RFC 2132 §9.8, §9.13) from this client's last message
* that carried them (#155). Display-only evidence: no table maps
* either to a device class, because no licence-clean source cites
* one per row. prl is the option codes in wire order, "1,3,6,15";
* vci is netstr-filtered (#138), the client chose every byte. */
char prl[96];
char vci[64];
/* Option 3 (Router) and option 121 (Classless Static Route), from
* the last BOOTREPLY that carried each (#263). router 0 = unknown.
* TunnelVision (CVE-2024-3661) uses option 121 to install a route
* with a higher priority than the VPN client's own, pulling traffic
* out of the tunnel; rule_dhcp_opt121_vpn_decloak reads both to tell
* a route back to this message's own gateway from one that is not. */
uint32_t router;
dhcp_route_t routes[MAX_DHCP_ROUTES];
uint8_t route_count;
time_t last_seen;
} dhcp_event_t;
/* ── LAN service roles (#155) ───────────────────────────────
* Addresses seen acting as a DHCP server or a DNS responder, keyed by
* IP. Router-role evidence for the device class: a camera does neither.
*
* LAN_ROLE_DHCP_REPLY a BOOTREPLY (op 2) from UDP 67 with this source
* (RFC 2131 §4.1: the server port)
* LAN_ROLE_DHCP_SID this address named in option 54 Server
* Identifier (RFC 2132 §9.7)
* LAN_ROLE_DNS a DNS response (QR 1, RFC 1035 §4.1.1) from
* UDP 53 with this source to a LAN client
*
* dns_clients counts distinct LAN destinations, saturating at
* LAN_ROLE_DNS_CLIENTS: the veto asks "two or more", never "how many". */
#define MAX_LAN_ROLES 32
#define LAN_ROLE_DNS_CLIENTS 4
#define LAN_ROLE_DHCP_REPLY (1 << 0)
#define LAN_ROLE_DHCP_SID (1 << 1)
#define LAN_ROLE_DNS (1 << 2)
typedef struct {
char ip[46];
int roles; /* LAN_ROLE_* */
char dns_client[LAN_ROLE_DNS_CLIENTS][46]; /* first distinct ones */
int dns_clients;
time_t dhcp_seen; /* newest DHCP evidence, 0 = none */
time_t dns_seen; /* newest DNS response to a LAN client */
time_t first_seen;
time_t last_seen;
} lan_role_t;
/* ── ARP neighbors ──────────────────────────────────────── */
#define MAX_ARP_ENTRIES 256
#define MAX_DHCP_LEASES 64
typedef struct {
char ip[46];
uint8_t mac[6];
char iface[16];
} arp_entry_t;
typedef struct {
char ip[46];
char hostname[64];
time_t expire; /* 0 = unknown; >0 = absolute expiry epoch */
} dhcp_lease_t;
/* ── BGP observation tracking ─────────────────────────── */
/* BGP lives on TCP/179. The 19-byte common header (RFC 4271 §4.1)
* is unmistakable: 16 bytes of all-0xFF marker + 2-byte length +
* 1-byte type code. Tier 1 counts the four message types per
* peer-pair; that's enough for the NOTIFICATION-burst alert which
* catches session-instability / route-hijack-precursor patterns
* without needing to parse AS numbers or prefix announcements. */
#define MAX_BGP_SESSIONS 32
typedef struct {
char peer_a[46]; /* lexically smaller endpoint */
char peer_b[46]; /* lexically greater endpoint */
int open_count; /* type 1 — session start */
int update_count; /* type 2 — routes */
int notification_count; /* type 3 — session teardown */
int keepalive_count; /* type 4 — heartbeat */
time_t first_seen;
time_t last_seen;
} bgp_session_t;
/* ── SSH observation tracking ────────────────────────── */
/* SSH lives on TCP/22. The protocol begins with a cleartext
* banner exchange ("SSH-protoversion-softwareversion\r\n") before
* any key exchange happens — that's the only field we can read
* passively. Per RFC 4253 §4.2 the banner starts with the literal
* bytes "SSH-" followed by "1.99" or "2.0", a hyphen, then
* implementation text and CR/LF.
*
* Each completed banner exchange = one TCP connection that reached
* the SSH handshake. SSH brute-force tools (hydra, medusa, ncrack)
* open many connections per second; legitimate users open one and
* stay connected. Tier 1 counts banners observed per (src_ip,
* dst_ip); SSH_BRUTE_FORCE fires on `brute_count` — banners inside
* the sliding ssh.brute_window_s seconds, kept current by
* ssh_snoop.c's private flood_window_t ring — not on banner_count's
* lifetime total (#202: a lifetime count never decays, so a handful
* of ordinary reconnects over weeks eventually reads as a standing
* brute force that eviction is the only thing that ever clears). The
* ring itself stays private to ssh_snoop.c rather than living here:
* sloth_state_t is already multiple megabytes and is copied by value
* in several places, so this struct holds the one int the rule
* needs, not the 272-byte ring that produced it. banner_count stays
* a lifetime tally for operator context — "how much SSH has this
* pair ever done" — but no rule reads it. Never decrypts anything
* either way: brute-force is a TCP-shape signal, not a payload
* signal. */
#define MAX_SSH_FLOWS 64
typedef struct {
char src_ip[46]; /* client (initiator of TCP) */
char dst_ip[46]; /* server (the SSHd target) */
int banner_count; /* lifetime; informational only */
int brute_count; /* banners inside ssh.brute_window_s (#202) */
char server_banner[80]; /* last banner string seen */
time_t first_seen;
time_t last_seen;
} ssh_flow_t;
/* ── RDP observation tracking ────────────────────────── */
/* RDP lives on TCP/3389. The connection setup is TPKT (RFC 1006)
* carrying an X.224 Class 0 Connection Request TPDU, optionally
* followed by a cookie ("Cookie: mstshash=USERNAME\r\n") and an
* RDP Negotiation Request (MS-RDPBCGR §2.2.1.1) that announces
* which security protocols the client wants — vanilla RDP, SSL,
* CredSSP/NLA, or HYBRID_EX. Everything after the negotiation
* response is wrapped in TLS (or CredSSP-over-TLS) and opaque.
*
* Tier 1 counts X.224 CR TPDUs per (client_ip, server_ip), keeps
* the latest mstshash cookie value (the username the attacker is
* guessing against), and bitmasks the requested protocols. That's
* enough for the brute-force alert, which catches xfreerdp-loop /
* NLBrute / Crowbar off `brute_count` — CRs inside the sliding
* rdp.brute_window_s seconds, same mechanism and same reason as
* ssh_flow_t's brute_count above — not off connect_req_count's
* lifetime total (#202). connect_req_count remains a lifetime tally
* for operator context; no rule reads it. */
#define MAX_RDP_FLOWS 64
#define RDP_PROTO_RDP 0x01u /* vanilla legacy RDP */
#define RDP_PROTO_SSL 0x02u /* TLS-only */
#define RDP_PROTO_HYBRID 0x04u /* CredSSP / NLA */
#define RDP_PROTO_HYBRID_EX 0x08u /* CredSSP early-user */
typedef struct {
char src_ip[46]; /* client (TCP initiator) */
char dst_ip[46]; /* server (the RDP target) */
int connect_req_count; /* lifetime; informational only */
int brute_count; /* CRs inside rdp.brute_window_s (#202) */
char last_cookie[64]; /* last mstshash username seen */
uint8_t proto_mask; /* OR of RDP_PROTO_* observed */
time_t first_seen;
time_t last_seen;
} rdp_flow_t;
/* ── SNMP observation tracking ───────────────────────── */
/* SNMP lives on UDP/161 (agent) and UDP/162 (traps). v1 (RFC 1157)
* and v2c (RFC 1901-1908) carry the community string in cleartext
* ASN.1 BER. v3 (RFC 3411+) authenticates but still exposes the
* security name. We track v1/v2c here — v3 is rare on the LAN and
* the brute-force shape would be different.
*
* Tier 1 counts PDU types per (src_ip, dst_ip) and tracks up to 8
* distinct community strings seen — community-guessing is the
* unmistakable signature of snmpwalk -v2c -c <wordlist> sweeps and
* the metasploit `auxiliary/scanner/snmp/snmp_login` module.
*
* Set requests are tracked separately because they're rare in
* monitoring traffic — almost every legitimate SNMP query is a
* Get/GetNext/GetBulk. A Set with a guessed community is the
* post-exploitation config-rewrite step.
*
* SNMP_COMMUNITY_BRUTE fires on `brute_count` — community guesses not
* already in communities[] (past a full set, once per change of
* string) inside the sliding snmp.brute_window_s seconds, kept current by
* snmp_snoop.c's private flood_window_t ring — not on community_count's
* lifetime total (#203, the same bug as #202: a lifetime count never
* decays, so the rule re-fired every tick until eviction or restart).
* community_count stays as operator context; no rule reads it. */
#define MAX_SNMP_FLOWS 48
#define MAX_SNMP_COMMUNITIES 8
#define SNMP_COMMUNITY_LEN 32
typedef struct {
char src_ip[46];
char dst_ip[46];
int get_count; /* GetRequest */
int getnext_count; /* GetNextRequest */
int getbulk_count; /* GetBulkRequest (v2+) */
int set_count; /* SetRequest */
int response_count; /* GetResponse */
int trap_count; /* Trap (v1) / SNMPv2-Trap */
int version; /* 0=v1, 1=v2c, 3=v3 */
int community_count; /* lifetime unique; informational */
int brute_count; /* new communities in snmp.brute_window_s (#203) */
char communities[MAX_SNMP_COMMUNITIES][SNMP_COMMUNITY_LEN];
char last_community[SNMP_COMMUNITY_LEN];
time_t first_seen;
time_t last_seen;
} snmp_flow_t;
/* ── MQTT observation tracking ───────────────────────── */
/* MQTT (v3.1.1 RFC-equivalent OASIS spec / v5 OASIS spec) is the
* dominant IoT pub/sub protocol. Brokers default to TCP/1883
* cleartext; TLS variant is TCP/8883 and is opaque past the
* handshake. Sloth tracks the cleartext path.
*
* Tier 1 detects:
* - CONNECT packets per (client_ip, broker_ip) — high count
* means credential brute-force or a malformed-client
* reconnect storm.
* - The username field from the CONNECT payload (when the
* User Name Flag is set) — same role as the SNMP community
* or the mstshash cookie: tells operators which account the
* attacker is guessing.
* - CONNACK reason codes — code 4 in v3 / 0x86 in v5 = bad
* credentials. A high failure count is the explicit signal,
* even quieter than the connect-count threshold.
* - Protocol-level (3 / 4 / 5) for asset inventory.
*
* MQTT_BROKER_BRUTE fires on `brute_connects` / `brute_fails` — CONNECTs
* and refused CONNACKs inside the sliding mqtt.brute_window_s seconds,
* each from its own private ring in mqtt_snoop.c — not on the lifetime
* connect_count / connack_fail_count, which never decay (#203, same bug
* as #202). The lifetime counts stay as operator context. */
#define MAX_MQTT_FLOWS 32
#define MQTT_USERNAME_LEN 32
typedef struct {
char src_ip[46]; /* MQTT client */
char dst_ip[46]; /* MQTT broker */
int connect_count; /* CONNECT packets observed */
int connack_fail_count; /* bad-auth CONNACK responses */
int brute_connects; /* CONNECTs in mqtt.brute_window_s (#203) */
int brute_fails; /* refused CONNACKs in the window (#203) */
int subscribe_count; /* SUBSCRIBE packets */
int publish_count; /* PUBLISH packets */
int proto_level; /* last seen: 3 / 4 / 5 */
char last_username[MQTT_USERNAME_LEN];
time_t first_seen;
time_t last_seen;
} mqtt_flow_t;
/* ── LDAP observation tracking ───────────────────────── */
/* LDAP lives on TCP/389 (cleartext) and TCP/3268 (Global Catalog
* cleartext). TLS variants (636 / 3269) are opaque past the
* handshake and not observed here.
*
* Tier 1 detects BindRequest, SearchRequest, and SearchResult
* Reference messages via the outer ASN.1 [APPLICATION n] tag and
* counts them per-source. The aggregate feeds the
* LDAP_SEARCH_FLOOD alert — BloodHound, ldapdomaindump, and the
* impacket family produce 100+ search requests in seconds from a
* single workstation, which a normal AD client never does. */
#define MAX_LDAP_EVENTS 64
typedef struct {
char src_ip[46];
int bind_count; /* LDAP BindRequest */
int bind_anon_count; /* BindRequest with empty DN */
int search_count; /* LDAP SearchRequest */
int search_ref_count; /* SearchResultReference (referral) */
time_t first_seen;
time_t last_seen;
} ldap_event_t;
/* ── Kerberos observation tracking ────────────────────── */
/* Kerberos lives on TCP / UDP port 88. v1 of sloth's Kerberos
* snooper does message-type detection (via the outer ASN.1
* [APPLICATION] tag byte) and KRB-ERROR error-code extraction
* (via a minimal ASN.1 walk for the [6] error-code field). Per-
* source aggregate counts feed the KERB_PREAUTH_BURST alert
* (password spray detection).
*
* Deeper Kerberos visibility — username/principal extraction,
* AS-REP roasting detection, kerberoasting service-ticket
* tracking — is documented out of scope; see
* docs/wiki/kerberos-snoop.md. */
#define MAX_KERB_EVENTS 64
typedef struct {
char src_ip[46];
int as_req_count; /* AS-REQ messages seen */
int as_rep_count; /* AS-REP messages seen */
int tgs_req_count; /* TGS-REQ messages seen */
int tgs_rep_count; /* TGS-REP messages seen */
int preauth_required_count; /* KRB-ERROR 25 */
int preauth_failed_count; /* KRB-ERROR 24 (spray) */
int principal_unknown_count; /* KRB-ERROR 6 (enumeration) */
int error_other_count; /* any other error code */
time_t first_seen;
time_t last_seen;
} kerb_event_t;
/* ── SMB observation tracking ──────────────────────────── */
/* SMB lives on TCP/445 (direct) and TCP/139 (NetBIOS Session
* Service framing). v1 has been deprecated since 2017 (EternalBlue
* / WannaCry) — any observed SMB1 use is itself a finding. We
* track flows by (client, server, server_port) and record the
* highest-risk dialect ever seen on the flow.
*
* dialect values are short strings ("SMB1", "SMB2") — SMB2 / SMB3
* are merged into "SMB2" because distinguishing them requires
* parsing past the negotiate response, and the rogue-SMB1 trigger
* doesn't need the distinction. */
#define MAX_SMB_SESSIONS 64
typedef struct {
char client_ip[46];
char server_ip[46];
uint16_t server_port; /* 445 or 139 */
char dialect[8]; /* "SMB1" or "SMB2" — sticky to SMB1 */
time_t first_seen;
time_t last_seen;
int count;
} smb_session_t;
/* ── IPv6 NDP Router Advertisement tracking ─────────────── */
/* RFC 4861 §4.2 Router Advertisement (ICMPv6 type 134).
*
* For SOC visibility we only need to know *who* is acting as a
* default router on the segment — multiple distinct router IPs
* with non-zero lifetime is the rogue-RA condition (the IPv6
* analogue of rogue DHCP). NS/NA neighbor cache tracking is a
* future addition; today this struct is RA-only. */
#define MAX_NDP_RAS 16 /* distinct RA-emitting routers */
#define NDP_RA_MAX_PREFIXES 4 /* prefixes captured per router */
typedef struct {
char src_ip[46]; /* router's IPv6 source addr */
uint8_t src_mac[6]; /* SLLA option (option type 1) */
uint8_t has_src_mac; /* 1 if SLLA was present */
uint8_t cur_hop_limit;
uint8_t flags; /* M/O/H bits + reserved */
uint16_t router_lifetime; /* seconds; 0 = NOT a router */
char prefixes[NDP_RA_MAX_PREFIXES][50]; /* "2001:db8::/64" */
int prefix_count;
time_t first_seen;
time_t last_seen;
int count;
} ndp_ra_event_t;
/* ── WiFi APs ───────────────────────────────────────────── */
/* BSS status values (mirror of NL80211_BSS_STATUS_* enum) */
#define WIFI_STATUS_NONE (-1)
#define WIFI_STATUS_AUTH 0
#define WIFI_STATUS_ASSOC 1
#define WIFI_STATUS_IBSS_JOINED 2
typedef struct {
char ssid[33];
char bssid[18];
int signal_dbm;
int channel;
char enc[16];
int status; /* NL80211_BSS_STATUS_* value, or -1 if not current */
/* ── Security / capability posture (roadmap B3b) ──────
* Filled by the shared beacon IE parser. Before B3b the nl80211
* scan path had its own parser yielding SSID plus three booleans,
* so the same AP reported far less detail in managed mode than in
* monitor mode. Empty string / 0 means the IE was absent.
*
* 802.11k neighbour reports are deliberately NOT mirrored here:
* they are an AP-topology record that belongs with the monitor
* table's beacon_ap_t, and copying the array into every scan
* result would cost 7 KB of state for a view that has nowhere to
* show it. */
char pairwise[12];
char group[12];
char akm[24];
int mfp; /* 0=off 1=capable 2=required */
char vendor[24];
int has_wps;
int wps_state;
int wps_locked;
char phy[10]; /* "Wi-Fi 7" / "6" / "5" / "4" / "legacy" */
int has_qbss;
int qbss_stations;
int qbss_chan_util;
} wifi_ap_t;
/* ── WiFi stations (our link to AP in managed mode, or clients in AP mode) ── */
#define MAX_WIFI_STAS 16
typedef struct {
char mac[18]; /* station MAC (= AP bssid when we are a client) */
int8_t signal_dbm;
uint32_t tx_rate_kbps; /* TX link rate in kbps */
uint32_t rx_rate_kbps;
uint32_t connected_secs;
uint32_t inactive_ms;
uint64_t tx_bytes;
uint64_t rx_bytes;
} wifi_sta_t;
/* ── DNS query log ──────────────────────────────────────── */
#define MAX_DNS_LOG 256
#define DNS_NAME_LEN 64
typedef struct {
char src[46]; /* source IP of the DNS packet */
char qname[DNS_NAME_LEN]; /* query name (truncated at 63 chars) */
char qtype[8]; /* "A", "AAAA", "PTR", "MX", "NS", "CNAME", "TXT", "SRV", "?" */
/* First A/AAAA IP, "NXDOMAIN", or "" — or, for a PTR question
* (#165), the PTR target name. Sized to qname's 63 bytes: a
* 45-byte cut would clip common provider PTR names
* ("ec2-203-0-113-25.us-west-2.compute.amazonaws.com" is 48), and
* a target that does not fit is refused, not cut. */
char answer[DNS_NAME_LEN];
int is_resp; /* 0 = query, 1 = response */
/* 1 when qname holds less than the wire name: cut at 63 bytes, or
* stopped at a NUL octet inside a label. The stored text is then a
* PREFIX, and a prefix can end on any suffix: the first 63 bytes of
* "<43 x a>.control.verkada.com.evil.example" read as a Verkada
* hostname. A suffix-matching consumer must skip these rows. */
uint8_t qname_trunc;
time_t ts;
} dns_log_entry_t;
/* ── NTP log ────────────────────────────────────────────── */
#define MAX_NTP_LOG 256
typedef struct {
char src[46];
char dst[46];
char mode[10]; /* "client", "server", "sym-act", "sym-pas", "bcast", "ctrl", "?" */
char ref[16]; /* reference ID (server name like "GPS", "DCF", or IP) */
uint8_t version; /* NTP version 1..4 */
uint8_t stratum; /* 0=unspec, 1=primary, 2..15=secondary, 16=unsync */
time_t ts;
} ntp_log_entry_t;
/* ── Top hosts (aggregated remote IPs across all conns) ── */
#define MAX_TOP_HOSTS 32
#define TOP_HOST_STALE_S 600 /* drop a host not seen for this long */
typedef struct {
char ip[46];
char hostname[64]; /* DNS-resolved name, "" if unresolved/pending */
char owner[32]; /* hosting org from embedded IP_OWNER table */
time_t first_seen;
time_t last_seen;
int conn_count; /* distinct flows to this IP this poll */
double rx_rate; /* B/s summed across all flows */
double tx_rate;
/* Cumulative bytes since first_seen, integrated from rx_rate /
* tx_rate * poll-interval each tick. Approximate (1 Hz integration)
* but monotonic and accurate to within the poll period. */
uint64_t rx_bytes;
uint64_t tx_bytes;
} top_host_t;
/* ── Devices (synthesized device profiles, keyed by MAC) ─ */
#define MAX_DEVICES 256
#define DEV_SRC_ARP (1 << 0)
#define DEV_SRC_DHCP (1 << 1)
#define DEV_SRC_MDNS (1 << 2)
#define DEV_SRC_BEACON (1 << 3)
#define DEV_SRC_PROBE (1 << 4)
#define DEV_SRC_STA (1 << 5)
/* A camera-discovery row (WS-Discovery, mDNS, SSDP, RTSP) joined to
* this record by IP (#106 round 2). A record with only this bit and an
* all-zero MAC is a camera sloth heard announce itself but never saw a
* link-layer address for: the IP is then its only key. */
#define DEV_SRC_CAMERA (1 << 6)
/* ── Camera identity on the device record (#106 round 2) ──
*
* Which of the camera rules' inputs were seen for this device, joined
* only on a key sloth actually observes: the same IP for the LAN-side
* signals, the same MAC (BSSID) for the beacon-side ones. A setup
* SoftAP's BSSID is never joined to a LAN IP — nothing on the air ties
* the two, so the camera behind a setup AP and the same camera on the
* LAN are two records. One bit per rule, named after it. */
#define CAM_SIG_WS_DISCOVERY (1 << 0) /* CAM_WS_DISCOVERY: ONVIF NVT */
#define CAM_SIG_SETUP_SSID (1 << 1) /* CAM_SETUP_SSID: beacon SSID */
#define CAM_SIG_MDNS_SERVICE (1 << 2) /* CAM_MDNS_SERVICE */
#define CAM_SIG_SSDP_DEVICE (1 << 3) /* CAM_SSDP_DEVICE */
#define CAM_SIG_SETUP_OUI (1 << 4) /* CAM_SETUP_OUI: beacon BSSID */
#define CAM_SIG_RTSP_UNAUTH (1 << 5) /* CAM_RTSP_UNAUTH */
#define CAM_SIG_COUNT 6
/* What the device class rests on. CAMERA: the device named its own
* class — an ONVIF NetworkVideoTransmitter, UPnP DigitalSecurityCamera:1,
* a camera DNS-SD service type, a camera vendor's documented setup SSID.
* CAMERA_VENDOR: only an address block or a SERVER product token ties it
* to a camera maker, and the class itself was not observed. Either one
* corroborates; neither confirms (#145 ruling 2). RTSP alone sets no
* class: it is a protocol, served by NVRs and media servers too. */
typedef enum {
DEV_CLASS_UNKNOWN = 0,
DEV_CLASS_CAMERA_VENDOR = 1,
DEV_CLASS_CAMERA = 2,
/* #155: a mixed-vendor OUI (Ubiquiti, TP-Link, Wyze) on a record
* seen in a router role (CAM_VETO_*) with no camera evidence. Last
* and not ordered with the two above: it is a verdict against, not
* a stronger "for", so nothing may MAX() it against them. */
DEV_CLASS_NOT_CAMERA = 3,
} device_class_t;
/* ── Behavioural evidence and router-role vetoes (#155) ──
*
* What camera_join.c's classifier scored for a record, and the
* router-role observations that veto a mixed-vendor OUI. Weights are in
* camera_join.c beside their sources; only RTSP_SDP decides a class
* (RFC 2326 §10.2), the rest are shown. Nothing here was solicited:
* every bit is a frame some other host sent. */
#define CAM_EV_MIXED_OUI (1 << 0) /* +1: Ubiquiti / TP-Link / Wyze MA-L */
#define CAM_EV_RTSP_SDP (1 << 1) /* +2: DESCRIBE 200, application/sdp */
#define CAM_EV_RTSP_SERVER (1 << 2) /* +1: answered DESCRIBE, no SDP seen */
#define CAM_EV_MDNS_RTSP (1 << 3) /* +1: advertises _rtsp (a protocol) */
#define CAM_EV_COUNT 4
#define CAM_VETO_DHCP_SERVER (1 << 0) /* RFC 2131 §4.1 / RFC 2132 §9.7 */
#define CAM_VETO_SENDS_RA (1 << 1) /* RFC 4861 §4.2, lifetime > 0 */
#define CAM_VETO_DNS_RESPONDER (1 << 2) /* answers >= 2 LAN clients */
#define CAM_VETO_COUNT 3
/* ── Device risk signals (roadmap #16 phase 4) ─────
* A bitmask of signals contributing to a device's risk bucket.
* Each signal is either "observed / not observed"; the score is
* derived in device_risk_score(), where the four anonymity signals
* count once between them (#191). */
#define DEV_RISK_RANDOM_MAC (1 << 0) /* locally-administered MAC */
#define DEV_RISK_UNKNOWN_VENDOR (1 << 1) /* OUI not in the embedded table */
#define DEV_RISK_NO_HOSTNAME (1 << 2) /* no DHCP/mDNS/NBNS resolution */
#define DEV_RISK_PROBE_ONLY (1 << 3) /* probe frames, no association */
#define DEV_RISK_CLEARTEXT_CRED (1 << 4) /* cred exposure attributed to us */
#define DEV_RISK_ALERT_TAGGED (1 << 5) /* an alert's match_ip == our ip */
/* Not a risk and worth no points: one of the host's own interfaces or a
* rostered device. Recorded in place of the anonymity signals. */
#define DEV_RISK_SELF (1 << 6)
#define DEV_RISK_ANON_MASK (DEV_RISK_RANDOM_MAC | DEV_RISK_UNKNOWN_VENDOR \
| DEV_RISK_NO_HOSTNAME | DEV_RISK_PROBE_ONLY)
typedef enum {
DEV_RISK_LOW = 0,
DEV_RISK_MED = 1,
DEV_RISK_HIGH = 2,
DEV_RISK_CRIT = 3,
} device_risk_level_t;
typedef struct {
uint8_t mac[6];
char ip[46]; /* best-known IP, "" if unknown */
char hostname[64]; /* DHCP/mDNS hostname, "" if unknown */
char vendor[32]; /* OUI vendor short name, "" if unknown */
char last_ssid[33]; /* most recent probed SSID, "" if none */
int is_ap; /* seen emitting beacons */
int8_t signal_dbm; /* most recent WiFi signal, 0 if none */
int probe_count; /* total probe frames */
int sources; /* bitmask of DEV_SRC_* */
/* Risk scoring: derived once per poll from the observed signals
* below and the alert / cleartext-cred state. See src/device_risk.c
* and roadmap #16 phase 4. */
int risk_signals; /* bitmask of DEV_RISK_* */
device_risk_level_t risk_level;
time_t last_seen;
/* Camera identity (#106 round 2), from src/camera_join.c. Vendor
* and model are what the device or its address block said, filtered
* to printable ASCII: model comes from the ONVIF name / hardware
* scopes, which the camera chooses. setup_mode is 1 only on a
* BSSID record whose SSID is a camera vendor's documented setup
* SSID — the advertisement, not the provisioning state. */
device_class_t device_class;
char camera_vendor[32];
char camera_model[48];
int setup_mode;
int cam_signal_mask; /* CAM_SIG_* */
time_t cam_seen[CAM_SIG_COUNT]; /* newest source row per signal */
/* #155 classifier output. cam_conflict is 1 when camera evidence
* (a self-declaration, or the RTSP_SDP score) met a router-role
* veto: shown, never resolved - a scored-only record then stays
* DEV_CLASS_UNKNOWN, a self-declared one keeps its class. dhcp_prl
* and dhcp_vci are the client's DHCP options 55 / 60 (dhcp_event_t),
* display-only. */
int cam_score;
int cam_evidence; /* CAM_EV_* */
int cam_vetoes; /* CAM_VETO_* */
int cam_conflict;
char dhcp_prl[96];
char dhcp_vci[64];
/* Copied from the beacon or probe row signal_dbm came from, the same
* last-writer rule; invalid for a record with no monitor-mode row. */
rf_track_t dist;
} device_t;
/* Human-readable bucket name for the alerts view / JSONL. */
const char *device_risk_label(device_risk_level_t l);
/* device_risk_score() is declared alongside iface_is_hidden() below,
* after sloth_state_t is defined. */
/* ── Alerts ─────────────────────────────────────────────── */
#define MAX_ALERTS 128
#define ALERT_TITLE_LEN 20
/* Holds the longest rule detail incl. two IPv6 addrs. Raised 256 → 320
* in #89 slice 3: the same-security evil-twin detail was calibrated to
* land at exactly 255 bytes worst case (SSID + two BSSIDs + cipher +
* confidence + the longest `reason` + all three evidence notes + a BTM
* steer note), so adding the ` [class=… wired=…]` axes pushed it over
* and gcc's -Wformat-truncation caught it.
*
* Grown rather than trading a field away, because the field that would
* have been dropped is the one slice 3 exists to add — and truncating
* the tail of a twin detail silently removes `wired=?`, which is the
* single statement that stops a reader assuming sloth checked the wire.
* Cost is 64 bytes × MAX_ALERTS in the engine and the same again in the
* snapshot, ~16 KB. `detail` is a variable-length string everywhere it
* is exported (JSONL, the `--db` TEXT column), so no consumer contract
* moves with it. */
#define ALERT_DETAIL_LEN 320
#define ALERT_KEY_LEN 192 /* dedup id; worst case is rule_cleartext_cred:
* two 45-char IPv6 + port + proto + 63-char user = 184 */
#define ALERT_NXDOMAIN_WINDOW_S 60 /* sliding window for NXDOMAIN-burst rule */
#define ALERT_NXDOMAIN_THRESH 10 /* NXDOMAINs from one src to trigger */
/* Evidence-ring event IDs an alert may cite (#92). The ring is keyed by
* ID and nothing else, so an alert that carries IDs can have its own
* frames pulled back out byte-exact — the retrieval path a wireless
* detection with no IP match otherwise has no way to reach.
*
* Eight because the field is a sample a reader can judge the finding
* from, not an archive of it: a deauth flood is thousands of frames and
* the ring holds as many as its budget allows regardless. */
#define ALERT_EVIDENCE_IDS 8
/* ── Incident lifecycle (#98) ────────────────────────────────
* Both durations run on CLOCK_MONOTONIC (the #88 seam in
* flood_window.h); an NTP step must not resolve a live incident or
* hold a dead one open. Wall clock is evidence only. */
#define ALERT_RESOLVE_AFTER_S 300
/* Quiet period after which a key that no rule re-asserted is declared
* resolved. 300 s because every rule re-evaluates from retained state
* once per poll (~1 Hz), so five minutes of silence means the evidence
* itself aged out of the source ring — and it matches
* JSONL_HEARTBEAT_SECS, so "is this incident still live?" has the same
* horizon as every other entity in the stream. */
#define ALERT_UPDATE_MIN_S 60
/* Floor between two `alert.update` events on one incident. A rule whose
* detail carries a live counter re-renders it every poll; without a
* floor that is one event per tick, which is the thing #98 exists to
* stop. Severity transitions are never throttled — that is what
* consumers page on. */
#define ALERT_RESOLVE_AFTER_MS ((uint64_t)ALERT_RESOLVE_AFTER_S * 1000u)
#define ALERT_UPDATE_MIN_MS ((uint64_t)ALERT_UPDATE_MIN_S * 1000u)
#define ALERT_INCIDENT_ID_LEN 17 /* 16 hex chars + NUL */
#define ALERT_EVENT_ID_LEN 23 /* "<incident>-<4-digit seq>" + NUL */
#define ALERT_PCAP_PATH_LEN 256 /* see alert_t.pcap_path */
/* Three-tier alert severity. Numeric values are stable and consumed by
* the JSONL `sev` field — never change them. Render colour:
* LOW → yellow — reconnaissance / suspicious-but-passive
* WARN → orange — clearly malicious, not yet an active exploit
* CRIT → red — active attack or IOC hit
* Cross-panel IP coloring follows the highest severity an IP has
* been associated with within ALERT_HOT_TTL_S. */
typedef enum {
ALERT_SEV_LOW = 0,
ALERT_SEV_WARN = 1,
ALERT_SEV_CRIT = 2,
} alert_sev_t;
/* alert_type_t, ALERT_TYPE_COUNT, alert_technique() and alert_type_name()
* live in sloth_alert.h, generated from sloth_alerts.def (#117). */
/* ── Location stamp (2026-10-27, --location / --gps) ──────────
* Where the sensor was when a finding was made, as the sensor knew
* it: a fixed --location, or the newest GPS fix younger than
* gps.max_fix_age_s. src is LOC_SRC_NONE when nothing was known, and
* every consumer (JSONL, the --db alerts row, the manifest line, the
* views) then writes nothing — absence, not a zero at Null Island.
* WGS84 decimal degrees; alt_m above mean sea level; acc_m an
* ESTIMATE of horizontal error (HDOP x 5 m for NMEA, gpsd's eph where
* it gives one), never a guarantee. ts is the fix's wall time, or the
* stamp time for a fixed sensor. Plain fields, no module header:
* sloth.h is the shared header. src/gps.h owns the arbitration. */
typedef enum { LOC_SRC_NONE = 0, LOC_SRC_FIXED, LOC_SRC_GPS } loc_src_t;