real basic check
This commit is contained in:
parent
8e29479aea
commit
edacebb3a6
2 changed files with 16 additions and 9 deletions
|
@ -35,9 +35,7 @@ namespace fw
|
||||||
firewall_rule_t *current_rule;
|
firewall_rule_t *current_rule;
|
||||||
current_rule = this->rule_head;
|
current_rule = this->rule_head;
|
||||||
while (current_rule->next != NULL)
|
while (current_rule->next != NULL)
|
||||||
{
|
|
||||||
current_rule = current_rule->next;
|
current_rule = current_rule->next;
|
||||||
}
|
|
||||||
current_rule->next = rule_ptr;
|
current_rule->next = rule_ptr;
|
||||||
rule_ptr->next = NULL;
|
rule_ptr->next = NULL;
|
||||||
}
|
}
|
||||||
|
@ -62,19 +60,13 @@ namespace fw
|
||||||
{
|
{
|
||||||
firewall_rule_t *rule_ptr = this->rule_head;
|
firewall_rule_t *rule_ptr = this->rule_head;
|
||||||
if (this->rule_head == NULL)
|
if (this->rule_head == NULL)
|
||||||
{
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
|
||||||
while (rule_ptr->key != key)
|
while (rule_ptr->key != key)
|
||||||
{
|
{
|
||||||
if (rule_ptr->next == NULL)
|
if (rule_ptr->next == NULL)
|
||||||
{
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
|
||||||
else
|
else
|
||||||
{
|
|
||||||
rule_ptr = rule_ptr->next;
|
rule_ptr = rule_ptr->next;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return rule_ptr;
|
return rule_ptr;
|
||||||
}
|
}
|
||||||
|
@ -119,12 +111,26 @@ namespace fw
|
||||||
return SUCCESS;
|
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)
|
bool Firewall::is_client_allowed(WiFiClient client)
|
||||||
{
|
{
|
||||||
const char *ip = client.remoteIP().toString().c_str();
|
const char *ip = client.remoteIP().toString().c_str();
|
||||||
const uint16_t port = client.remotePort();
|
const uint16_t port = client.remotePort();
|
||||||
|
|
||||||
Serial.print("Client connected: ");
|
|
||||||
Serial.print(client.remoteIP());
|
Serial.print(client.remoteIP());
|
||||||
Serial.print(":");
|
Serial.print(":");
|
||||||
Serial.println(client.remotePort());
|
Serial.println(client.remotePort());
|
||||||
|
|
|
@ -19,6 +19,7 @@ namespace fw
|
||||||
firewall_rule_t *get_rule_from_firewall(const uint8_t key);
|
firewall_rule_t *get_rule_from_firewall(const uint8_t key);
|
||||||
ok_t delete_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);
|
bool is_client_allowed(WiFiClient client);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
Reference in a new issue