ESP32/ESP8266 Firewall 1.0.0
a software firewall for ESP23 or ESP8266
Utils.hpp
1#ifndef UTILS_HPP
2#define UTILS_HPP
3
4#include "Arduino.h"
5#include "WString.h"
6
7namespace fw
8{
9 static const uint8_t IPV4ADDRESS_LENGTH = 16;
10 static const uint8_t CREDENTIALS_LENGTH = 32;
11 static const uint8_t firewall_fields_amount = 6;
12 const char firewall_fields[firewall_fields_amount][10] = {"key", "ip", "port_from", "port_to", "protocol", "target"};
13
16 typedef enum firewall_targets : uint8_t
17 {
18 TARGET_DROP = 1,
19 TARGET_ACCEPT = 2,
20 } firewall_target_t;
21
24 typedef enum firewall_protocols : uint8_t
25 {
26 PROTOCOL_TCP = 6,
27 PROTOCOL_UDP = 17,
28 PROTOCOL_ALL = 255,
29 } firewall_protocol_t;
30
33 typedef enum ok : uint8_t
34 {
35 SUCCESS = 0,
36 ERROR = 1,
37 NO_ACTION = 2,
38 } ok_t;
39
42 typedef enum auth : uint8_t
43 {
44 AUTHENTICATED = 0,
45 DENIED = 1,
46 } auth_t;
47
50 typedef struct firewall_rules
51 {
52 uint8_t key;
53 char ip[IPV4ADDRESS_LENGTH];
54 uint16_t port_from;
55 uint16_t port_to;
56 firewall_protocol_t protocol;
57 firewall_target_t target;
58 struct firewall_rules *next;
60
63 typedef struct my_packet
64 {
65 char ip[IPV4ADDRESS_LENGTH];
66 firewall_protocol_t protocol;
67 uint16_t port;
69
72 typedef enum firewall_fields : uint8_t
73 {
74 KEY,
75 IP,
76 PORT_FROM,
77 PORT_TO,
78 PROTOCOL,
79 TARGET,
80 } firewall_fields_t;
81
84 typedef struct credentials
85 {
86 char password[CREDENTIALS_LENGTH];
87 char username[CREDENTIALS_LENGTH];
89
92 typedef struct api_endpoints
93 {
94 char uri[60];
95 char method[7];
96 char description[30];
97 struct api_endpoints *next;
99
106 String protocol_to_string(firewall_protocol_t &protocol);
107
114 firewall_protocol_t string_to_protocol(String &protocol);
115
122 String target_to_string(firewall_target_t &target);
123
130 firewall_target_t string_to_target(String &target);
131
136 void endless_loop();
137
147 bool is_in_range(const uint16_t number, const uint16_t lower, const uint16_t upper);
148}
149
150#endif
Definition: Utils.hpp:93
Definition: Utils.hpp:85
Definition: Utils.hpp:51
Definition: Utils.hpp:64