Quellcode durchsuchen

[bt6708]change level of checking whitelist

balbekova vor 6 Jahren
Ursprung
Commit
8283945026

+ 8 - 0
modules/Ethernet/lwipopts.h

@@ -280,6 +280,14 @@ The STM32F4x7 allows computing and verifying the IP, UDP, TCP and ICMP checksums
 
 #define MEMP_NUM_TCPIP_MSG_INPKT        20
 
+/*
+   -----------------------------------
+   ----------- HOOK options ----------
+   -----------------------------------
+*/
+#if defined HARDWARE_BT6708
+#define LWIP_HOOK_FILENAME "lwip_hook_ip4_input.h"
+#endif
 
 #endif /* __LWIPOPTS_H__ */
 

+ 7 - 3
modules/Makefile

@@ -47,6 +47,9 @@ INCLUDES += -Icommon
 INCLUDES += -Imonitor
 INCLUDES += -Ilog
 INCLUDES += -Itesting
+ifeq ($(HARDWARE), bt6708)
+INCLUDES += -Iwhitelist
+endif
 ifeq ($(HARDWARE), bt6702)
 INCLUDES += -Iradius
 endif
@@ -60,6 +63,9 @@ CSRC += $(wildcard common/*.c)
 CSRC += $(wildcard monitor/*.c)
 CSRC += $(wildcard log/*.c)
 CSRC += $(wildcard testing/*.c)
+ifeq ($(HARDWARE), bt6708)     
+CSRC += $(wildcard whitelist/*.c)
+endif
 ifeq ($(HARDWARE), bt6702)
 CSRC += $(wildcard radius/*.c)
 endif
@@ -81,10 +87,9 @@ CSRC += $(wildcard ../thirdparty/FreeRTOS/portable/MemMang/heap_4.c)
 	# LwIP + Web #	
     INCLUDES += -IHTTP_Server
     INCLUDES += -I../thirdparty/lwip/src/include
-    INCLUDES += -I../thirdparty/lwip/src/include/netif
     INCLUDES += -I../thirdparty/lwip/src/include/lwip
-    INCLUDES += -I../thirdparty/lwip/src/include/lwip/apps
     INCLUDES += -I../thirdparty/lwip/src/include/netif
+    INCLUDES += -I../thirdparty/lwip/src/include/lwip/apps
     INCLUDES += -I../thirdparty/lwip/src/apps/snmp/
 #    INCLUDES += -I../thirdparty/lwip/src/netif/ppp
     INCLUDES += -I../thirdparty/lwip/port
@@ -119,7 +124,6 @@ endif
   	CSRC += $(wildcard STM32F4x7_ETH_Driver/*.c)
     
 CSRC += $(wildcard ../stm32/system/syscalls/syscalls.c)
-
 #SSL
 #INCLUDES += -I../thirdparty/PolarSSL/include/polarssl/
 #INCLUDES += -I../thirdparty/PolarSSL/include/

+ 62 - 0
modules/whitelist/lwip_hook_ip4_input.c

@@ -0,0 +1,62 @@
+/*
+ * lwip_hook_ip4_input.c
+ *
+ *  Created on: 20.05.2019
+ *      Author: balbekova
+ */
+
+
+
+#include "lwip_hook_ip4_input.h"
+
+#include "ip4.h"
+
+#include "settings_api.h"
+#include "parameters.h"
+
+#ifdef PRINTF_STDLIB
+#include <stdio.h>
+#endif
+#ifdef PRINTF_CUSTOM
+#include "tinystdio.h"
+#endif
+#include <string.h>
+#include <stdlib.h>
+
+int ip_input_hook(struct pbuf *p, struct netif *inp)
+{
+
+	bool flag = true;
+	struct ip_hdr *iphdr;
+	uint32_t mask_white_list;
+	uint32_t ip_white_list;
+	char str[20];
+	uint8_t len = 0;
+
+	iphdr = (struct ip_hdr *)p->payload;
+
+	for(uint8_t i = 0; i < MAX_WHITE_LIST; i ++){
+		memset(str, 0, 20);
+		GetWhiteListSTR(str, &len, i);
+		GetWhiteListMask(&mask_white_list, i);
+		GetWhiteListIP(&ip_white_list, i);
+		if(strlen(str) != 0){
+
+			if((iphdr->src.addr & mask_white_list) == (ip_white_list & mask_white_list)){
+				flag = true;
+				break;
+			}
+			else{
+				flag = false;
+			}
+		}
+	}
+	if(flag){
+		return 0;
+	}
+	else{
+		pbuf_free(p);
+		return 1;
+	}
+
+}

+ 20 - 0
modules/whitelist/lwip_hook_ip4_input.h

@@ -0,0 +1,20 @@
+/*
+ * lwip_hook_ip4_input.h
+ *
+ *  Created on: 20.05.2019
+ *      Author: balbekova
+ */
+
+#ifndef LWIP_HOOK_IP4_INPUT_H_
+#define LWIP_HOOK_IP4_INPUT_H_
+
+#include "lwip/pbuf.h"
+#include "lwip/netif.h"
+
+int ip_input_hook(struct pbuf *p, struct netif *inp);
+
+#define LWIP_HOOK_IP4_INPUT(pbuf, input_netif) ip_input_hook(pbuf, input_netif)
+
+//
+
+#endif /* LWIP_HOOK_IP4_INPUT_H_ */