From 6a7ec2411f7670b93a73036d948d93791e5e70a9 Mon Sep 17 00:00:00 2001 From: chn <897331845@qq.com> Date: Fri, 18 Oct 2019 09:49:26 +0800 Subject: [PATCH] avoid unnecessary memory copy. --- Makefile | 2 +- src/xmurp-ua.c | 37 ++++++++++++++++++------------------- 2 files changed, 19 insertions(+), 20 deletions(-) diff --git a/Makefile b/Makefile index 1f92ae5..3057041 100644 --- a/Makefile +++ b/Makefile @@ -2,7 +2,7 @@ include $(TOPDIR)/rules.mk include $(INCLUDE_DIR)/kernel.mk PKG_NAME:=xmurp-ua -PKG_RELEASE:=28 +PKG_RELEASE:=29 include $(INCLUDE_DIR)/package.mk diff --git a/src/xmurp-ua.c b/src/xmurp-ua.c index dbee14c..1b05350 100644 --- a/src/xmurp-ua.c +++ b/src/xmurp-ua.c @@ -181,6 +181,24 @@ unsigned int hook_funcion(void *priv, struct sk_buff *skb, const struct nf_hook_ return NF_ACCEPT; } + // 决定是否发送到下一层 + if(catch_next_frag && iph->saddr == saddr && iph->daddr == daddr && + tcph->seq == seq && tcph->source == sport && tcph->dest == dport) + jump_to_next_function = 1; + else if(data_end - data_start > 3) + if(memcmp(data_start, "GET", 3) == 0 || memcmp(data_start, "POST", 4) == 0) + { + if(catch_next_frag) + { + n_ua_modify_faild++; + char_scan(0); + catch_next_frag = 0; + } + jump_to_next_function = 1; + } + if(!jump_to_next_function) + return NF_ACCEPT; + // 确保 skb 可以被修改,或者不可以被修改的话把它变得可修改 if(skb_ensure_writable(skb, (char*)data_end - (char*)skb -> data)) { @@ -201,25 +219,6 @@ unsigned int hook_funcion(void *priv, struct sk_buff *skb, const struct nf_hook_ data_start = (char *)tcph + tcph->doff * 4; data_end = (char *)tcph + ntohs(iph->tot_len) - iph->ihl * 4; } - - - // 决定是否发送到下一层 - if(catch_next_frag && iph->saddr == saddr && iph->daddr == daddr && - tcph->seq == seq && tcph->source == sport && tcph->dest == dport) - jump_to_next_function = 1; - else if(data_end - data_start > 3) - if(memcmp(data_start, "GET", 3) == 0 || memcmp(data_start, "POST", 4) == 0) - { - if(catch_next_frag) - { - n_ua_modify_faild++; - char_scan(0); - catch_next_frag = 0; - } - jump_to_next_function = 1; - } - if(!jump_to_next_function) - return NF_ACCEPT; // 发送到下一层,并回收数据 ret = skb_scan(data_start, data_end);