-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
配置文件设计 #1
Comments
好的,我看一下。 |
可以保持目前 chinadns 的配置文件状态, 主要问题是 4700+ 条的 route add 命令执行速度可能会比较慢。 |
可以把临时文件写到 tempfs (内存)里,然后用 ip -batch 加载。 |
在路由器测试了一下,速度在可接受范围。
|
发布的时候可以分成两个版本:一个给所有人用的普通版,和一个国内用户专用的整合版,就脚本不一样。 |
已经编译好在 openwrt 上测试通过。 up.sh 部分 old_intf=$(ip route show | awk '/^default/ {print $NF}') 下面就是添加 route 的部分 ############################################
# insert chnroutes rules here if you need! #
suf="via $old_gw dev $old_intf"
awk -v suf="$suf" '$1 ~ /^([0-9]{1,3}\.){3}[0-9]{1,3}/\
{printf("route add %s %s\n",$1,suf)}' /etc/chinadns_chnroute.txt > /tmp/routes
ip -batch /tmp/routes
############################################ down.sh部分 ############################################
# remove chnroutes rules here if you need! #
if [ -f /tmp/routes ]; then
sed -i 's#route add#route del#g' /tmp/routes
ip -batch /tmp/routes
rm -f /tmp/routes
fi
############################################ |
可以在 client.conf 里添加一个参数来指定 chnroutes 列表文件(默认留空),这样 up.sh 可以做成通用的了。 ############################################
# insert chnroutes rules here if you need! #
if [ ! -z "$chnroutes" ] && [ -f $chnroutes ]; then
suf="via $old_gw dev $old_intf"
awk -v suf="$suf" '$1 ~ /^([0-9]{1,3}\.){3}[0-9]{1,3}/\
{printf("route add %s %s\n",$1,suf)}' $chnroutes > /tmp/routes
ip -batch /tmp/routes
fi
############################################ |
started 打印到下一行的问题已经修正。 chnroutes 文件的路径可以在 up.sh 里写死,因为一般这个文件是由打包者决定摆在哪里的,打包者也可以随意定义 up.sh 的内容,不一定需要使用 samples 目录里的文件。 |
嗯,这样的话可以写成这样 ############################################
# insert chnroutes rules here if you need! #
chnroutes=/etc/chinadns_chnroute.txt
if [ -f $chnroutes ]; then
suf="via $old_gw dev $old_intf"
awk -v suf="$suf" '$1 ~ /^([0-9]{1,3}\.){3}[0-9]{1,3}/\
{printf("route add %s %s\n",$1,suf)}' $chnroutes > /tmp/routes
ip -batch /tmp/routes
fi
############################################ |
我来维护通用的(不含 chnroutes)的包,你来维护和 chinadns chnroutes 的整合版如何? |
可以的,整合版的话 chinadns 就不用动了,只改 up.sh 和 down.sh 就可以了。 |
为什么要把服务管理的事情也给做了 |
|
@aa65535 不知道有没有办法更快捷的帮助用户配置这些,比如一键更新配置? |
好的,我参考一下。 |
新的脚本好像有问题: https://v2ex.com/t/137015#r_1391392 我测试了一下网关一样都是
这个路由是作为二级路由使用的,不过应该不是这个原因。 觉得在 LuCI 中建立 Interfaces 有点复杂,还是在 |
另外看到讨论到 iptables 和 ipset ,不过这两个都有内核依赖, |
新的脚本是为 pppoe 设计的,旧脚本在重新拨号的时候记的网关是错的,导致不能恢复。似乎对 DHCP 的 wan 来说工作就不正常了。 |
因为我用的光纤是固定IP的,所以没有测试。 相当于在 IP 变化的时候重启了一下 VPN,只是交给 Hotplug 处理。 |
@aa65535 |
可是使用 LuCI 不容易做到通用。 下面是根据 Configure via LuCI on OpenWRT 写的 UCI 命令。 #!/bin/sh
uci get network.wan || exit 0
# add a new interface named tun, select tun0.
uci set network.tun='interface'
uci set network.tun.proto='static'
uci set network.tun.ifname='tun0'
uci set network.tun.ipaddr='10.7.0.2'
uci set network.tun.netmask='255.255.255.0'
uci set network.tun.gateway='10.7.0.1'
# disable use default gateway of wan.
uci set network.wan.defaultroute='0'
# add static routes for tun
uci set network.tun_r='route'
uci set network.tun_r.interface='tun'
uci set network.tun_r.target='0.0.0.0'
uci set network.tun_r.netmask='0.0.0.0'
uci set network.tun_r.gateway='10.7.0.1'
uci set network.tun_r.metric='5'
# add static routes for wan
uci set network.wan_r='route'
uci set network.wan_r.interface='wan'
uci set network.wan_r.target='$server'
uci set network.wan_r.metric='10'
# commit the settings
uci commit network
# add a new zone called tun.
# add interface tun to tun zone.
uci set firewall.tun_z='zone'
uci set firewall.tun_z.input='ACCEPT'
uci set firewall.tun_z.forward='REJECT'
uci set firewall.tun_z.output='ACCEPT'
uci set firewall.tun_z.name='tun'
uci set firewall.tun_z.network='tun'
uci set firewall.tun_z.masq='1'
# update forward rules: tun => wan.
uci set firewall.wan_f='forwarding'
uci set firewall.wan_f.dest='wan'
uci set firewall.wan_f.src='tun'
# update forward rules: lan => tun.
uci set firewall.lan_f='forwarding'
uci set firewall.lan_f.dest='tun'
uci set firewall.lan_f.src='lan'
# commit the settings
uci commit firewall 但是我这路由器没有 |
那个是直接修改 uci 配置文件,跟使用命令没区别。 |
用命令应该更灵活,可以做一些判断。如果没有 wan,可以走另一套配置。 |
使用这种形式的话,可以将上面的命令拆开写, 建立 tun 可以在 ipk 的 postinst 中完成。 剩下部分可以根据需要做一些判断。 |
@aa65535 不小心看到这个命令形式的配置觉得很不错,如果关闭该如何使用 udi 恢复?全部改为 delete? |
@hfcorriez 使用 uci del network.tun
uci del network.tun_r
uci del network.wan_r
uci commit network
uci del firewall.tun_z
uci del firewall.wan_f
uci del firewall.lan_f
uci commit firewall |
需要讨论的issues 先Reopen |
@aa65535 多谢。。。 |
@cj1324 噢,好的! |
@aa65535 那个是直接修改 uci 配置文件 和通过uci接口配置还有一些,细微的差别。
对配置的阅读有不少帮助。当然不影响功能效果。 |
@aa65535 其实把 client_up 和 client_down 换成 udi 脚本也行,如果提供这种方式可能会解决很多 openwrt 的问题。 |
update libsodium version
* Update .travis.yml * Update README.md
This reverts commit 25b8397.
This reverts commit 25b8397.
This reverts commit 25b8397.
@aa65535
The text was updated successfully, but these errors were encountered: