upleb.uk

Public git repos — served from a NIP-34 GRASP relay at git.upleb.uk

summaryrefslogtreecommitdiff
path: root/main/session.c
diff options
context:
space:
mode:
authorYour Name <you@example.com>2026-05-16 04:46:32 +0530
committerYour Name <you@example.com>2026-05-16 04:46:32 +0530
commit50b5975ac8793d6d820c35b5999f8a909f64e71b (patch)
tree2592f9e7a671af2aca56e46887e50b8ad8e418b6 /main/session.c
parent3f46bb83cb1041889034c88adce1895dd330793f (diff)
Captive portal detection fix + Phase 2 tests 16-18,20 passing (17/17)
- Add DoT reject server on port 853 (TCP RST forces DNS-over-TLS fallback) - DNS hijack returns NXDOMAIN for all non-A query types (no forwarding for unauthed) - Shorter TTL on hijack responses (10s) for faster captive detection - Explicit 302 redirect handlers for /generate_204, /hotspot-detect.html, etc. - HTTP and DNS request logging for debugging captive detection - Per-MAC tracking in firewall (find_by_mac, get_mac_for_ip with ARP fallback) - Session MAC tracking (session_find_by_mac) - Phase 2 test 18: add route through TollGate before ping test - All 17 Phase 2 tests pass (15-21 + whoami + portal form)
Diffstat (limited to 'main/session.c')
-rw-r--r--main/session.c25
1 files changed, 23 insertions, 2 deletions
diff --git a/main/session.c b/main/session.c
index 6d9c334..5d2efee 100644
--- a/main/session.c
+++ b/main/session.c
@@ -29,6 +29,13 @@ esp_err_t session_manager_init(void)
29 return ESP_OK; 29 return ESP_OK;
30} 30}
31 31
32static void populate_mac(session_t *session, uint32_t client_ip)
33{
34 if (firewall_get_mac_for_ip(client_ip, session->mac, sizeof(session->mac)) != ESP_OK) {
35 session->mac[0] = '\0';
36 }
37}
38
32session_t *session_create(uint32_t client_ip, uint64_t allotment_ms, 39session_t *session_create(uint32_t client_ip, uint64_t allotment_ms,
33 const char *spent_secrets[], int secret_count) 40 const char *spent_secrets[], int secret_count)
34{ 41{
@@ -59,6 +66,7 @@ session_t *session_create(uint32_t client_ip, uint64_t allotment_ms,
59 s_sessions[i].start_time_ms = get_time_ms(); 66 s_sessions[i].start_time_ms = get_time_ms();
60 s_sessions[i].active = true; 67 s_sessions[i].active = true;
61 s_sessions[i].spent_secret_count = 0; 68 s_sessions[i].spent_secret_count = 0;
69 populate_mac(&s_sessions[i], client_ip);
62 70
63 for (int j = 0; j < secret_count && j < 5; j++) { 71 for (int j = 0; j < secret_count && j < 5; j++) {
64 strncpy(s_sessions[i].spent_secrets[s_sessions[i].spent_secret_count], 72 strncpy(s_sessions[i].spent_secrets[s_sessions[i].spent_secret_count],
@@ -77,7 +85,8 @@ session_t *session_create(uint32_t client_ip, uint64_t allotment_ms,
77 firewall_grant_access(client_ip); 85 firewall_grant_access(client_ip);
78 86
79 esp_ip4_addr_t ip = { .addr = client_ip }; 87 esp_ip4_addr_t ip = { .addr = client_ip };
80 ESP_LOGI(TAG, "Session created: " IPSTR " allotment=%llums", IP2STR(&ip), 88 ESP_LOGI(TAG, "Session created: " IPSTR " mac=%s allotment=%llums", IP2STR(&ip),
89 s_sessions[i].mac[0] ? s_sessions[i].mac : "unknown",
81 (unsigned long long)allotment_ms); 90 (unsigned long long)allotment_ms);
82 return &s_sessions[i]; 91 return &s_sessions[i];
83 } 92 }
@@ -97,6 +106,17 @@ session_t *session_find_by_ip(uint32_t client_ip)
97 return NULL; 106 return NULL;
98} 107}
99 108
109session_t *session_find_by_mac(const char *mac)
110{
111 for (int i = 0; i < SESSION_MAX_CLIENTS; i++) {
112 if (s_sessions[i].active && s_sessions[i].mac[0] != '\0' &&
113 strcmp(s_sessions[i].mac, mac) == 0) {
114 return &s_sessions[i];
115 }
116 }
117 return NULL;
118}
119
100void session_extend(session_t *session, uint64_t additional_ms) 120void session_extend(session_t *session, uint64_t additional_ms)
101{ 121{
102 if (!session || !session->active) return; 122 if (!session || !session->active) return;
@@ -126,7 +146,8 @@ void session_check_expiry(void)
126 for (int i = 0; i < SESSION_MAX_CLIENTS; i++) { 146 for (int i = 0; i < SESSION_MAX_CLIENTS; i++) {
127 if (s_sessions[i].active && session_is_expired(&s_sessions[i])) { 147 if (s_sessions[i].active && session_is_expired(&s_sessions[i])) {
128 esp_ip4_addr_t ip = { .addr = s_sessions[i].client_ip }; 148 esp_ip4_addr_t ip = { .addr = s_sessions[i].client_ip };
129 ESP_LOGI(TAG, "Session expired: " IPSTR, IP2STR(&ip)); 149 ESP_LOGI(TAG, "Session expired: " IPSTR " mac=%s", IP2STR(&ip),
150 s_sessions[i].mac[0] ? s_sessions[i].mac : "unknown");
130 session_revoke(&s_sessions[i]); 151 session_revoke(&s_sessions[i]);
131 } 152 }
132 } 153 }