From d4940f3c2cf43755d399111b74784edad77ab79d Mon Sep 17 00:00:00 2001 From: chn <897331845@qq.com> Date: Fri, 20 Sep 2019 12:05:36 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0offload=E8=AF=B4=E6=98=8E=20?= =?UTF-8?q?=E4=BF=AE=E6=94=B9mark=E4=BD=8D=E7=82=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Makefile | 4 ++-- README.md | 17 +++++++++++++---- src/xmurp-ua.c | 40 +--------------------------------------- 3 files changed, 16 insertions(+), 45 deletions(-) diff --git a/Makefile b/Makefile index fbb428f..8545ff7 100644 --- a/Makefile +++ b/Makefile @@ -2,7 +2,7 @@ include $(TOPDIR)/rules.mk include $(INCLUDE_DIR)/kernel.mk PKG_NAME:=xmurp-ua -PKG_RELEASE:=22 +PKG_RELEASE:=23 include $(INCLUDE_DIR)/package.mk @@ -19,7 +19,7 @@ define KernelPackage/xmurp-ua SUBMENU:=Other modules TITLE:=xmurp-ua FILES:=$(PKG_BUILD_DIR)/xmurp-ua.ko -# AUTOLOAD:=$(call AutoLoad,99,xmurp-ua) + AUTOLOAD:=$(call AutoLoad,99,xmurp-ua) KCONFIG:= endef diff --git a/README.md b/README.md index 1a3da09..a5598b3 100644 --- a/README.md +++ b/README.md @@ -1,9 +1,18 @@ -  喵喵喵,这里是一个修改 UA 的小模块。细致地讲,就是用在 OpenWrt 上修改发给外网 80 端口 GET 和 POST 请求的 UA 字段 为`XMURP/1.0`再加很多个空格的内核模块,用来防止学校检测到使用代理(接路由器)。具体情况,百度“厦大路由”然后看我的简书文章就好了。在 WNDR4300 OpenWrt 18.06.1(内核 4.9.120)测试似乎没问题。前两天还适配了一下 4.14的内核。 +喵喵喵,这里是一个修改 UA 的小模块。细致地讲,就是用在 OpenWrt 上修改发给外网 80 端口 GET 和 POST 请求的 UA 字段 为`XMURP/1.0`再加很多个空格的内核模块,用来防止学校检测到使用代理(接路由器)。具体情况,百度“厦大路由”然后看我的简书文章就好了。在 WNDR4300 OpenWrt 18.06.1(内核 4.9.120)测试似乎没问题。前两天还适配了一下 4.14的内核。 - 如果有一些包不希望被改 UA,只要在防火墙规则里将 MARK 的最低位设置为 1 就可以了。例如: +如果有一些包不希望被改 UA,只要在防火墙规则里将 MARK 的第九位设置为 1 就可以了。例如: ``` -iptables -t mangle -A PREROUTING -i br-lan_raw -j MARK --set-mark 1 +iptables -t mangle -A PREROUTING -p tcp -m tcp --dport 80 -m mac --mac-source f8:94:c2:85:e8:14 -j MARK --set-xmark 0x100/0x100 ``` -  这是我第一次在 GitHub 上搞自己的仓库,可能会有些小问题哈。要是有的话,请各路大佬指正。 \ No newline at end of file +在之前的版本中,使用的是 `0x1/0x1` 位,但是与 luci-app-shadowsocks 冲突,所以改到了 `0x100/0x100`。 + +另外,不要在 luci 中启用 flow offloading(流量分载,即 nat 加速),否则这个模块会失效。可以通过下面的命令(二选一,不需要两句都写)来对不需要这个模块的流量启用。 + +``` +iptables -t filter -I FORWARD -p tcp ! --dport 80 -m conntrack --ctstate RELATED,ESTABLISHED -j FLOWOFFLOAD --hw +iptables -t filter -I FORWARD -p tcp ! --dport 80 -m conntrack --ctstate RELATED,ESTABLISHED -j FLOWOFFLOAD +``` + +两句的区别的话,大概是前者用硬件,后者用软件。具体的东西我也不熟悉。 diff --git a/src/xmurp-ua.c b/src/xmurp-ua.c index 632a312..7ad699c 100644 --- a/src/xmurp-ua.c +++ b/src/xmurp-ua.c @@ -139,8 +139,6 @@ inline u_int8_t skb_scan(char *data_start, char *data_end) // ip地址、端口号、iph->tot_len需要网络顺序到主机顺序的转换。校验和时,除长度字段外,不需要手动进行网络顺序和主机顺序的转换。 unsigned int hook_funcion(void *priv, struct sk_buff *skb, const struct nf_hook_state *state) { - static u_int32_t debug_n = 0; - register struct tcphdr *tcph; register struct iphdr *iph; register char *data_start, *data_end; @@ -155,57 +153,21 @@ unsigned int hook_funcion(void *priv, struct sk_buff *skb, const struct nf_hook_ // 过滤发往外网的HTTP请求的包,且要求包的应用层内容不短于3字节 if(skb == 0) - { -// if(debug_n < 10) -// printk("xmurp-ua warning, something maybe wrong.\n"); return NF_ACCEPT; - } iph = ip_hdr(skb); if((ntohl(iph->daddr) & 0xffff0000) == 0xc0a80000) - { -// if(debug_n < 10) -// printk("xmurp-ua bypass as dst in local net.\n"); return NF_ACCEPT; - } if(iph->protocol != IPPROTO_TCP) - { -// if(debug_n < 10) -// printk("xmurp-ua bypass as protocol not tcp.\n"); return NF_ACCEPT; - } tcph = tcp_hdr(skb); if(ntohs(tcph->dest) != 80) - { -// if(debug_n < 10) -// printk("xmurp-ua bypass as port %u not 80.\n", ntohs(tcph->dest)); return NF_ACCEPT; - } data_start = (char *)tcph + tcph->doff * 4; data_end = (char *)tcph + ntohs(iph->tot_len) - iph->ihl * 4; - debug_n++; if(data_end - data_start < 4) - { - if(debug_n < 10) - printk("xmurp-ua bypass as data too short."); - if(debug_n < 10) - printk("xmurp-ua tcph -> doff = %x, iph -> tot_len = %x, iph -> ihl = %x.\n", tcph -> doff, iph -> tot_len, iph -> ihl); - if(debug_n < 10) - printk("xmurp-ua iph -> tot_len - iph, %x.\n", (char*)&(iph -> tot_len) - (char*)iph); - if(debug_n < 10) - printk("xmurp-ua iph -> tot_len %x.\n", *((u_int16_t*)&(iph -> tot_len))); - if(debug_n < 10) - printk("xmurp-ua iph message %x %x %x %x %x %x %x %x %x %x %x.\n", iph -> version, iph -> ihl, iph -> tos, iph -> tot_len, iph -> id, iph -> frag_off, iph -> ttl, iph -> protocol, iph -> check, iph -> saddr, iph -> daddr); return NF_ACCEPT; - } - if(skb->mark & 0x00000001) - { - if(debug_n < 10) - printk("xmurp-ua bypass as mark.\n"); + if(skb->mark & 0x100) return NF_ACCEPT; - } - - if(debug_n++ < 10) - printk("xmurp-ua catch a package.\n"); // 决定是否发送到下一层 if(catch_next_frag && iph->saddr == saddr && iph->daddr == daddr &&