diff --git a/Makefile b/Makefile index 36c8013..958a846 100644 --- a/Makefile +++ b/Makefile @@ -9,7 +9,7 @@ include $(INCLUDE_DIR)/package.mk EXTRA_CFLAGS:= \ $(patsubst CONFIG_%, -DCONFIG_%=1, $(patsubst %=m,%,$(filter %=m,$(EXTRA_KCONFIG)))) \ $(patsubst CONFIG_%, -DCONFIG_%=1, $(patsubst %=y,%,$(filter %=y,$(EXTRA_KCONFIG)))) \ - -DVERSION='"$(PKG_RELEASE)"' --verbose + -DVERSION="\"\\\"$(PKG_RELEASE)\\\"\"" --verbose MAKE_OPTS:=$(KERNEL_MAKE_FLAGS) \ SUBDIRS="$(PKG_BUILD_DIR)" \ diff --git a/src/rkp-ua.c b/src/rkp-ua.c index a11dd06..b4eb72a 100644 --- a/src/rkp-ua.c +++ b/src/rkp-ua.c @@ -6,14 +6,25 @@ static time_t last_flush; unsigned int hook_funcion(void *priv, struct sk_buff *skb, const struct nf_hook_state *state) { - u_int8_t rtn; - static u_int8_t crashed = 0; + unsigned rtn; + static bool crashed = 0; + + static unsigned n_skb_captured = 0, n_skb_captured_lastPrint = 1; if(crashed) return NF_ACCEPT; if(!rkpSettings_capture(skb)) return NF_ACCEPT; + rtn = rkpManager_execute(rkpm, skb); + + n_skb_captured++; + if(n_skb_captured == n_skb_captured_lastPrint * 2) + { + printk("rkp-ua: Captured %d packages.\n", n_skb_captured); + n_skb_captured_lastPrint *= 2; + } + if(rtn == NF_DROP_ERR(1)) { printk("rkp-ua: Crashed.\n"); diff --git a/src/rkpManager.h b/src/rkpManager.h index 92a960a..95780e2 100644 --- a/src/rkpManager.h +++ b/src/rkpManager.h @@ -92,11 +92,8 @@ u_int8_t rkpManager_execute(struct rkpManager* rkpm, struct sk_buff* skb) return rkpStream_execute(rkps, skb); else rkps = rkps -> next; - if(rkps == 0) - { - printk("rkp-ua::rkpStream::rkpStream_execute: Target stream not found.\n"); - return NF_DROP; - } + printk("rkp-ua::rkpStream::rkpStream_execute: Target stream not found.\n"); + return NF_DROP; } } diff --git a/src/rkpStream.h b/src/rkpStream.h index c1cfa0b..80534ab 100644 --- a/src/rkpStream.h +++ b/src/rkpStream.h @@ -43,7 +43,7 @@ struct sk_buff* __rkpStream_buff_find(const struct sk_buff*, u_int32_t); void __rkpStream_buff_execute_core(struct sk_buff**, u_int16_t, bool); // 最核心的步骤,集齐头部后被调用。搜索、替换。参数分别为:数据包链表、最后一个包中 http 头结束的位置、是否保留指定 ua -struct rkpStream* rpStream_new(const struct sk_buff* skb) +struct rkpStream* rkpStream_new(const struct sk_buff* skb) { struct rkpStream* rkps = kmalloc(sizeof(struct rkpStream), GFP_KERNEL); const struct iphdr* iph = ip_hdr(skb); @@ -271,7 +271,7 @@ unsigned char* __rkpStream_skb_appBegin(const struct sk_buff* skb) return (unsigned char*)tcp_hdr(skb) + tcp_hdr(skb) -> doff * 4; } -u_int16_t __rkpStream_dataLen(const struct sk_buff* skb) +u_int16_t __rkpStream_skb_appLen(const struct sk_buff* skb) { return ntohs(ip_hdr(skb) -> tot_len) - ip_hdr(skb) -> ihl * 4 - tcp_hdr(skb) -> doff * 4; } @@ -500,7 +500,7 @@ void __rkpStream_buff_execute_core(struct sk_buff** buff, u_int16_t last_len, bo { unsigned char* replace_begin; u_int16_t replace_len; - if(skb_ensure_writable(p, replace_begin + replace_len - p -> data) != 0) + if(skb_ensure_writable(p, __rkpStream_skb_appBegin(p) + __rkpStream_skb_appLen(p) - p -> data) != 0) { printk("rkp-ua::rkpStream::__rkpStream_buff_execute_core: Can not make skb writable, may caused by shortage of memory. Ignore it.\n"); return;