From 06b122de646f2c9fdb7e026e425e92037dfa64cb Mon Sep 17 00:00:00 2001 From: Florian Hoss Date: Mon, 18 Apr 2022 17:46:17 +0200 Subject: [PATCH] read all firewall rules stored in eeprom --- SourceCode/arduino/lib/Firewall/Firewall.cpp | 40 +++++++++++--------- SourceCode/arduino/lib/Firewall/Firewall.h | 1 + 2 files changed, 24 insertions(+), 17 deletions(-) diff --git a/SourceCode/arduino/lib/Firewall/Firewall.cpp b/SourceCode/arduino/lib/Firewall/Firewall.cpp index b619878..de0cd1a 100644 --- a/SourceCode/arduino/lib/Firewall/Firewall.cpp +++ b/SourceCode/arduino/lib/Firewall/Firewall.cpp @@ -76,25 +76,31 @@ void ESPFirewall::eeprom_write_firewall_rule(firewall_rule_t *rule_ptr) 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(EEPROM.read(eeprom_address)); + eeprom_address += sizeof(firewall_protocol_t); + rule_ptr->target = static_cast(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() { - int eeprom_address = eeprom_start_firewall_rules; - char source[IP4ADDR_STRLEN_MAX]; - char destination[IP4ADDR_STRLEN_MAX]; - strcpy(source, EEPROM.readString(eeprom_address).c_str()); - eeprom_address += IP4ADDR_STRLEN_MAX; - strcpy(destination, EEPROM.readString(eeprom_address).c_str()); - eeprom_address += IP4ADDR_STRLEN_MAX; - firewall_protocol_t protocol = static_cast(EEPROM.read(eeprom_address)); - eeprom_address += sizeof(firewall_protocol_t); - firewall_protocol_t target = static_cast(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); + uint8_t eeprom_address = eeprom_start_firewall_rules; + for (uint8_t i = 0; i < this->amount_of_rules; i++) + { + eeprom_read_firewall_rule(eeprom_address); + } } void ESPFirewall::add_rule_to_firewall(firewall_rule_t *rule) diff --git a/SourceCode/arduino/lib/Firewall/Firewall.h b/SourceCode/arduino/lib/Firewall/Firewall.h index a86db42..4e2cbcd 100644 --- a/SourceCode/arduino/lib/Firewall/Firewall.h +++ b/SourceCode/arduino/lib/Firewall/Firewall.h @@ -59,6 +59,7 @@ class ESPFirewall // EEPROM void setup_eeprom(); void eeprom_write_firewall_rule(firewall_rule_t *rule); + void eeprom_read_firewall_rule(uint8_t &); void eeprom_read_firewall_rules(); // Firewall Actions