real basic check

This commit is contained in:
Florian Hoss 2022-05-03 21:00:56 +02:00
parent 8e29479aea
commit edacebb3a6
2 changed files with 16 additions and 9 deletions

View file

@ -35,9 +35,7 @@ namespace fw
firewall_rule_t *current_rule;
current_rule = this->rule_head;
while (current_rule->next != NULL)
{
current_rule = current_rule->next;
}
current_rule->next = rule_ptr;
rule_ptr->next = NULL;
}
@ -62,20 +60,14 @@ namespace fw
{
firewall_rule_t *rule_ptr = this->rule_head;
if (this->rule_head == NULL)
{
return NULL;
}
while (rule_ptr->key != key)
{
if (rule_ptr->next == NULL)
{
return NULL;
}
else
{
rule_ptr = rule_ptr->next;
}
}
return rule_ptr;
}
@ -119,12 +111,26 @@ namespace fw
return SUCCESS;
}
bool Firewall::is_included_in_firewall(const char *ip, const uint16_t port)
{
firewall_rule_t *rule_ptr = this->rule_head;
while (rule_ptr != NULL)
{
if (strncmp(ip, rule_ptr->source, IPV4ADDRESS_LENGTH) == 0)
{
if (rule_ptr->port_from <= port && port <= rule_ptr->port_to)
return true;
}
rule_ptr = rule_ptr->next;
}
return false;
}
bool Firewall::is_client_allowed(WiFiClient client)
{
const char *ip = client.remoteIP().toString().c_str();
const uint16_t port = client.remotePort();
Serial.print("Client connected: ");
Serial.print(client.remoteIP());
Serial.print(":");
Serial.println(client.remotePort());

View file

@ -19,6 +19,7 @@ namespace fw
firewall_rule_t *get_rule_from_firewall(const uint8_t key);
ok_t delete_rule_from_firewall(const uint8_t key);
bool is_included_in_firewall(const char *ip, const uint16_t port);
bool is_client_allowed(WiFiClient client);
protected: