rename types
This commit is contained in:
parent
bb1a67c49d
commit
e77ced2f0a
3 changed files with 58 additions and 58 deletions
|
@ -6,9 +6,9 @@ namespace firewall
|
||||||
{
|
{
|
||||||
switch (protocol)
|
switch (protocol)
|
||||||
{
|
{
|
||||||
case FW_TCP:
|
case PROTOCOL_TCP:
|
||||||
return "TCP";
|
return "TCP";
|
||||||
case FW_UDP:
|
case PROTOCOL_UDP:
|
||||||
return "UDP";
|
return "UDP";
|
||||||
default:
|
default:
|
||||||
return "ALL";
|
return "ALL";
|
||||||
|
@ -18,20 +18,20 @@ namespace firewall
|
||||||
firewall_protocol_t string_to_protocol(std::string &protocol)
|
firewall_protocol_t string_to_protocol(std::string &protocol)
|
||||||
{
|
{
|
||||||
if (protocol.compare("TCP") == 0)
|
if (protocol.compare("TCP") == 0)
|
||||||
return FW_TCP;
|
return PROTOCOL_TCP;
|
||||||
else if (protocol.compare("UDP") == 0)
|
else if (protocol.compare("UDP") == 0)
|
||||||
return FW_UDP;
|
return PROTOCOL_UDP;
|
||||||
else
|
else
|
||||||
return FW_ALL;
|
return PROTOCOL_ALL;
|
||||||
}
|
}
|
||||||
|
|
||||||
String target_to_string(firewall_target_t &target)
|
String target_to_string(firewall_target_t &target)
|
||||||
{
|
{
|
||||||
switch (target)
|
switch (target)
|
||||||
{
|
{
|
||||||
case FW_REJECT:
|
case TARGET_REJECT:
|
||||||
return "REJECT";
|
return "REJECT";
|
||||||
case FW_DROP:
|
case TARGET_DROP:
|
||||||
return "DROP";
|
return "DROP";
|
||||||
default:
|
default:
|
||||||
return "ACCEPT";
|
return "ACCEPT";
|
||||||
|
@ -41,11 +41,11 @@ namespace firewall
|
||||||
firewall_target_t string_to_target(std::string &target)
|
firewall_target_t string_to_target(std::string &target)
|
||||||
{
|
{
|
||||||
if (target.compare("REJECT") == 0)
|
if (target.compare("REJECT") == 0)
|
||||||
return FW_REJECT;
|
return TARGET_REJECT;
|
||||||
else if (target.compare("DROP") == 0)
|
else if (target.compare("DROP") == 0)
|
||||||
return FW_DROP;
|
return TARGET_DROP;
|
||||||
else
|
else
|
||||||
return FW_ACCEPT;
|
return TARGET_ACCEPT;
|
||||||
}
|
}
|
||||||
|
|
||||||
void endless_loop()
|
void endless_loop()
|
||||||
|
|
|
@ -5,54 +5,54 @@
|
||||||
#include "WString.h"
|
#include "WString.h"
|
||||||
#include "esp32-hal-log.h"
|
#include "esp32-hal-log.h"
|
||||||
|
|
||||||
static const uint8_t IPV4ADDRESS_LENGTH = 16;
|
|
||||||
static const uint8_t CREDENTIALS_LENGTH = 32;
|
|
||||||
|
|
||||||
typedef enum firewall_targets : uint8_t
|
|
||||||
{
|
|
||||||
FW_REJECT = 0,
|
|
||||||
FW_DROP = 1,
|
|
||||||
FW_ACCEPT = 2,
|
|
||||||
} firewall_target_t;
|
|
||||||
|
|
||||||
typedef enum firewall_protocols : uint8_t
|
|
||||||
{
|
|
||||||
FW_TCP = 0,
|
|
||||||
FW_UDP = 1,
|
|
||||||
FW_ALL = 255,
|
|
||||||
} firewall_protocol_t;
|
|
||||||
|
|
||||||
typedef enum ok : uint8_t
|
|
||||||
{
|
|
||||||
SUCCESS = 0,
|
|
||||||
ERROR = 1,
|
|
||||||
NO_ACTION = 2,
|
|
||||||
} ok_t;
|
|
||||||
|
|
||||||
typedef enum auth : uint8_t
|
|
||||||
{
|
|
||||||
AUTHENTICATED = 0,
|
|
||||||
DENIED = 1,
|
|
||||||
} auth_t;
|
|
||||||
|
|
||||||
typedef struct firewall_rules
|
|
||||||
{
|
|
||||||
uint8_t key;
|
|
||||||
char source[IPV4ADDRESS_LENGTH];
|
|
||||||
char destination[IPV4ADDRESS_LENGTH];
|
|
||||||
firewall_protocol_t protocol;
|
|
||||||
firewall_target_t target;
|
|
||||||
struct firewall_rules *next;
|
|
||||||
} firewall_rule_t;
|
|
||||||
|
|
||||||
typedef struct credentials
|
|
||||||
{
|
|
||||||
char password[CREDENTIALS_LENGTH];
|
|
||||||
char username[CREDENTIALS_LENGTH];
|
|
||||||
} credential_t;
|
|
||||||
|
|
||||||
namespace firewall
|
namespace firewall
|
||||||
{
|
{
|
||||||
|
static const uint8_t IPV4ADDRESS_LENGTH = 16;
|
||||||
|
static const uint8_t CREDENTIALS_LENGTH = 32;
|
||||||
|
|
||||||
|
typedef enum firewall_targets : uint8_t
|
||||||
|
{
|
||||||
|
TARGET_REJECT = 0,
|
||||||
|
TARGET_DROP = 1,
|
||||||
|
TARGET_ACCEPT = 2,
|
||||||
|
} firewall_target_t;
|
||||||
|
|
||||||
|
typedef enum firewall_protocols : uint8_t
|
||||||
|
{
|
||||||
|
PROTOCOL_TCP = 0,
|
||||||
|
PROTOCOL_UDP = 1,
|
||||||
|
PROTOCOL_ALL = 255,
|
||||||
|
} firewall_protocol_t;
|
||||||
|
|
||||||
|
typedef enum ok : uint8_t
|
||||||
|
{
|
||||||
|
SUCCESS = 0,
|
||||||
|
ERROR = 1,
|
||||||
|
NO_ACTION = 2,
|
||||||
|
} ok_t;
|
||||||
|
|
||||||
|
typedef enum auth : uint8_t
|
||||||
|
{
|
||||||
|
AUTHENTICATED = 0,
|
||||||
|
DENIED = 1,
|
||||||
|
} auth_t;
|
||||||
|
|
||||||
|
typedef struct firewall_rules
|
||||||
|
{
|
||||||
|
uint8_t key;
|
||||||
|
char source[IPV4ADDRESS_LENGTH];
|
||||||
|
char destination[IPV4ADDRESS_LENGTH];
|
||||||
|
firewall_protocol_t protocol;
|
||||||
|
firewall_target_t target;
|
||||||
|
struct firewall_rules *next;
|
||||||
|
} firewall_rule_t;
|
||||||
|
|
||||||
|
typedef struct credentials
|
||||||
|
{
|
||||||
|
char password[CREDENTIALS_LENGTH];
|
||||||
|
char username[CREDENTIALS_LENGTH];
|
||||||
|
} credential_t;
|
||||||
|
|
||||||
String protocol_to_string(firewall_protocol_t &protocol);
|
String protocol_to_string(firewall_protocol_t &protocol);
|
||||||
firewall_protocol_t string_to_protocol(std::string &protocol);
|
firewall_protocol_t string_to_protocol(std::string &protocol);
|
||||||
String target_to_string(firewall_target_t &target);
|
String target_to_string(firewall_target_t &target);
|
||||||
|
|
|
@ -54,8 +54,8 @@ namespace firewall
|
||||||
this->memory.begin(rulename, true);
|
this->memory.begin(rulename, true);
|
||||||
strncpy(rule_ptr->source, this->memory.getString("source", "0.0.0.0").c_str(), sizeof(rule_ptr->source));
|
strncpy(rule_ptr->source, this->memory.getString("source", "0.0.0.0").c_str(), sizeof(rule_ptr->source));
|
||||||
strncpy(rule_ptr->destination, this->memory.getString("destination", "0.0.0.0").c_str(), sizeof(rule_ptr->source));
|
strncpy(rule_ptr->destination, this->memory.getString("destination", "0.0.0.0").c_str(), sizeof(rule_ptr->source));
|
||||||
rule_ptr->protocol = static_cast<firewall_protocol_t>(this->memory.getUChar("protocol", FW_ALL));
|
rule_ptr->protocol = static_cast<firewall_protocol_t>(this->memory.getUChar("protocol", PROTOCOL_ALL));
|
||||||
rule_ptr->target = static_cast<firewall_target_t>(this->memory.getUChar("target", FW_REJECT));
|
rule_ptr->target = static_cast<firewall_target_t>(this->memory.getUChar("target", TARGET_REJECT));
|
||||||
this->memory.end();
|
this->memory.end();
|
||||||
|
|
||||||
return rule_ptr;
|
return rule_ptr;
|
||||||
|
|
Reference in a new issue