2022-04-21 15:16:54 +02:00
|
|
|
#include "Utils.hpp"
|
|
|
|
|
|
|
|
namespace firewall
|
|
|
|
{
|
|
|
|
String protocol_to_string(firewall_protocol_t &protocol)
|
|
|
|
{
|
|
|
|
switch (protocol)
|
|
|
|
{
|
2022-04-22 22:40:01 +02:00
|
|
|
case PROTOCOL_TCP:
|
2022-04-21 15:16:54 +02:00
|
|
|
return "TCP";
|
2022-04-22 22:40:01 +02:00
|
|
|
case PROTOCOL_UDP:
|
2022-04-21 15:16:54 +02:00
|
|
|
return "UDP";
|
|
|
|
default:
|
|
|
|
return "ALL";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-04-23 23:50:46 +02:00
|
|
|
firewall_protocol_t string_to_protocol(String &protocol)
|
2022-04-21 15:16:54 +02:00
|
|
|
{
|
2022-04-23 23:50:46 +02:00
|
|
|
if (protocol.equals("TCP"))
|
2022-04-22 22:40:01 +02:00
|
|
|
return PROTOCOL_TCP;
|
2022-04-23 23:50:46 +02:00
|
|
|
else if (protocol.equals("UDP"))
|
2022-04-22 22:40:01 +02:00
|
|
|
return PROTOCOL_UDP;
|
2022-04-21 15:16:54 +02:00
|
|
|
else
|
2022-04-22 22:40:01 +02:00
|
|
|
return PROTOCOL_ALL;
|
2022-04-21 15:16:54 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
String target_to_string(firewall_target_t &target)
|
|
|
|
{
|
|
|
|
switch (target)
|
|
|
|
{
|
2022-04-22 22:40:01 +02:00
|
|
|
case TARGET_REJECT:
|
2022-04-21 15:16:54 +02:00
|
|
|
return "REJECT";
|
2022-04-22 22:40:01 +02:00
|
|
|
case TARGET_DROP:
|
2022-04-21 15:16:54 +02:00
|
|
|
return "DROP";
|
|
|
|
default:
|
|
|
|
return "ACCEPT";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-04-23 23:50:46 +02:00
|
|
|
firewall_target_t string_to_target(String &target)
|
2022-04-21 15:16:54 +02:00
|
|
|
{
|
2022-04-23 23:50:46 +02:00
|
|
|
if (target.equals("REJECT"))
|
2022-04-22 22:40:01 +02:00
|
|
|
return TARGET_REJECT;
|
2022-04-23 23:50:46 +02:00
|
|
|
else if (target.equals("DROP"))
|
2022-04-22 22:40:01 +02:00
|
|
|
return TARGET_DROP;
|
2022-04-21 15:16:54 +02:00
|
|
|
else
|
2022-04-22 22:40:01 +02:00
|
|
|
return TARGET_ACCEPT;
|
2022-04-21 15:16:54 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void endless_loop()
|
|
|
|
{
|
2022-04-23 23:36:44 +02:00
|
|
|
Serial.printf("Something went wrong. Running endless loop until fixed...");
|
2022-04-21 15:16:54 +02:00
|
|
|
while (true)
|
2022-04-23 23:36:44 +02:00
|
|
|
delay(500);
|
2022-04-21 15:16:54 +02:00
|
|
|
}
|
|
|
|
}
|