diff --git a/ESP32Firewall/include/lwip_hooks.h b/ESP32Firewall/include/lwip_hooks.h index 4ecd8bd..8c58d5a 100644 --- a/ESP32Firewall/include/lwip_hooks.h +++ b/ESP32Firewall/include/lwip_hooks.h @@ -1,10 +1,6 @@ #ifndef _LWIP_HOOKS_H_ #define _LWIP_HOOKS_H_ -#include "lwip/netif.h" -#include "lwip/pbuf.h" -#include "lwip/ip4.h" - #ifdef __cplusplus extern "C" { diff --git a/ESP32Firewall/src/main.cpp b/ESP32Firewall/src/main.cpp index 10a85f1..30b1a7d 100644 --- a/ESP32Firewall/src/main.cpp +++ b/ESP32Firewall/src/main.cpp @@ -11,14 +11,17 @@ fw::API *firewallApi; int lwip_hook_ip4_input(struct pbuf *pbuf, struct netif *input_netif) { - const struct ip_hdr *iphdr; - char ip_address[IP_HLEN]; - - iphdr = (struct ip_hdr *)pbuf->payload; - sprintf(ip_address, "%d.%d.%d.%d", ip4_addr1_16_val(iphdr->src), ip4_addr2_16_val(iphdr->src), ip4_addr3_16_val(iphdr->src), ip4_addr4_16_val(iphdr->src)); - Serial.print((u16_t)IPH_PROTO(iphdr)); - Serial.print(": "); - Serial.println(ip_address); + // Firewall is not setup yet + if (firewall != NULL) + { + if (firewall->is_packet_allowed(pbuf)) + return 0; + else + { + pbuf_free(pbuf); + return 1; + } + } return 0; }