read all firewall rules stored in eeprom

This commit is contained in:
Florian Hoss 2022-04-18 17:46:17 +02:00
parent d017f28254
commit 06b122de64
2 changed files with 24 additions and 17 deletions

View file

@ -76,25 +76,31 @@ void ESPFirewall::eeprom_write_firewall_rule(firewall_rule_t *rule_ptr)
EEPROM.commit(); EEPROM.commit();
} }
void ESPFirewall::eeprom_read_firewall_rule(uint8_t &eeprom_address)
{
firewall_rule_t *rule_ptr = (firewall_rule_t *)malloc(sizeof(firewall_rule_t));
strcpy(rule_ptr->source, EEPROM.readString(eeprom_address).c_str());
eeprom_address += IP4ADDR_STRLEN_MAX;
strcpy(rule_ptr->destination, EEPROM.readString(eeprom_address).c_str());
eeprom_address += IP4ADDR_STRLEN_MAX;
rule_ptr->protocol = static_cast<firewall_protocol_t>(EEPROM.read(eeprom_address));
eeprom_address += sizeof(firewall_protocol_t);
rule_ptr->target = static_cast<firewall_target_t>(EEPROM.read(eeprom_address));
eeprom_address += sizeof(firewall_target_t);
log_i("Source: %s, Destination: %s, Protocol: %u, Target: %u",
rule_ptr->source,
rule_ptr->destination,
rule_ptr->protocol,
rule_ptr->target);
}
void ESPFirewall::eeprom_read_firewall_rules() void ESPFirewall::eeprom_read_firewall_rules()
{ {
int eeprom_address = eeprom_start_firewall_rules; uint8_t eeprom_address = eeprom_start_firewall_rules;
char source[IP4ADDR_STRLEN_MAX]; for (uint8_t i = 0; i < this->amount_of_rules; i++)
char destination[IP4ADDR_STRLEN_MAX]; {
strcpy(source, EEPROM.readString(eeprom_address).c_str()); eeprom_read_firewall_rule(eeprom_address);
eeprom_address += IP4ADDR_STRLEN_MAX; }
strcpy(destination, EEPROM.readString(eeprom_address).c_str());
eeprom_address += IP4ADDR_STRLEN_MAX;
firewall_protocol_t protocol = static_cast<firewall_protocol_t>(EEPROM.read(eeprom_address));
eeprom_address += sizeof(firewall_protocol_t);
firewall_protocol_t target = static_cast<firewall_protocol_t>(EEPROM.read(eeprom_address));
eeprom_address += sizeof(firewall_target_t);
log_i("Amount: %i, Source: %s, Destination: %s, Protocol: %u, Target: %u",
this->amount_of_rules,
source,
destination,
protocol,
target);
} }
void ESPFirewall::add_rule_to_firewall(firewall_rule_t *rule) void ESPFirewall::add_rule_to_firewall(firewall_rule_t *rule)

View file

@ -59,6 +59,7 @@ class ESPFirewall
// EEPROM // EEPROM
void setup_eeprom(); void setup_eeprom();
void eeprom_write_firewall_rule(firewall_rule_t *rule); void eeprom_write_firewall_rule(firewall_rule_t *rule);
void eeprom_read_firewall_rule(uint8_t &);
void eeprom_read_firewall_rules(); void eeprom_read_firewall_rules();
// Firewall Actions // Firewall Actions