Move packet handling to firewall

This commit is contained in:
Florian Hoss 2022-07-26 14:07:54 +02:00
parent 929aaf39a3
commit 986b596b46
2 changed files with 11 additions and 12 deletions

View file

@ -1,10 +1,6 @@
#ifndef _LWIP_HOOKS_H_ #ifndef _LWIP_HOOKS_H_
#define _LWIP_HOOKS_H_ #define _LWIP_HOOKS_H_
#include "lwip/netif.h"
#include "lwip/pbuf.h"
#include "lwip/ip4.h"
#ifdef __cplusplus #ifdef __cplusplus
extern "C" extern "C"
{ {

View file

@ -11,14 +11,17 @@ fw::API *firewallApi;
int lwip_hook_ip4_input(struct pbuf *pbuf, struct netif *input_netif) int lwip_hook_ip4_input(struct pbuf *pbuf, struct netif *input_netif)
{ {
const struct ip_hdr *iphdr; // Firewall is not setup yet
char ip_address[IP_HLEN]; if (firewall != NULL)
{
iphdr = (struct ip_hdr *)pbuf->payload; if (firewall->is_packet_allowed(pbuf))
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)); return 0;
Serial.print((u16_t)IPH_PROTO(iphdr)); else
Serial.print(": "); {
Serial.println(ip_address); pbuf_free(pbuf);
return 1;
}
}
return 0; return 0;
} }