n2n_v2: add n2n auto-nat

Signed-off-by: Tianling Shen <cnsztl@immortalwrt.org>
This commit is contained in:
dwj0 2021-03-19 11:48:32 +08:00 committed by Tianling Shen
parent 6814197580
commit b64789d40c
No known key found for this signature in database
GPG Key ID: 6850B6345C862176
4 changed files with 18 additions and 20 deletions

View File

@ -9,7 +9,7 @@ include $(TOPDIR)/rules.mk
LUCI_TITLE:=n2n_v2 VPN Configuration module
LUCI_DEPENDS:=+n2n-edge +n2n-supernode
LUCI_PKGARCH:=all
PKG_VERSION:=2.8.0
PKG_VERSION:=2.8.1
PKG_RELEASE:=2
include $(TOPDIR)/feeds/luci/luci.mk

View File

@ -5,21 +5,6 @@
local fs = require "nixio.fs"
function get_mask(v)
v:value("1 ", "128.0.0.0(1)")
v:value("2 ", "192.0.0.0(2)")
v:value("3 ", "224.0.0.0(3)")
v:value("4 ", "240.0.0.0(4)")
v:value("5 ", "248.0.0.0(5)")
v:value("6 ", "252.0.0.0(6)")
v:value("7 ", "254.0.0.0(7)")
v:value("8 ", "255.0.0.0(8)")
v:value("9 ", "255.128.0.0(9)")
v:value("10", "255.192.0.0(10)")
v:value("11", "255.224.0.0(11)")
v:value("12", "255.240.0.0(12)")
v:value("13", "255.248.0.0(13)")
v:value("14", "255.252.0.0(14)")
v:value("15", "255.254.0.0(15)")
v:value("16", "255.255.0.0(16)")
v:value("17", "255.255.128.0(17)")
v:value("18", "255.255.192.0(18)")
@ -35,8 +20,6 @@ function get_mask(v)
v:value("28", "255.255.255.240(28)")
v:value("29", "255.255.255.248(29)")
v:value("30", "255.255.255.252(30)")
v:value("31", "255.255.255.254(31)")
v:value("32", "255.255.255.255(32)")
end
m = Map("n2n_v2", translate("N2N v2 VPN"), translatef(
@ -131,4 +114,8 @@ o.optional = false
o.datatype = "ip4addr"
o.rmempty = false
---- Description
o = s:option(Value, "desc", translate("Description"))
o.optional = false
return m

View File

@ -72,4 +72,7 @@ msgid "Mask"
msgstr "掩码"
msgid "Gateway"
msgstr "网关"
msgstr "网关"
msgid "Description"
msgstr "描述"

View File

@ -29,6 +29,10 @@ start_instance() {
eval "$(ipcalc.sh "$ipaddr/$prefix")"
netmask="$NETMASK"
/usr/bin/edge -u 0 -g 0 -d $tunname -a ${mode}:${address} -s $netmask -c $community $([ -n "$key" ] && echo -k $key) -l ${supernode}:${port} $args $mtu
sleep 1
iptables -I FORWARD -i "$tunname" -j ACCEPT
iptables -I FORWARD -o "$tunname" -j ACCEPT
iptables -t nat -I POSTROUTING -o "$tunname" -j MASQUERADE
;;
supernode)
config_get_bool enabled "$cfg" 'enabled' '0'
@ -54,6 +58,10 @@ stop_instance() {
case "$type" in
edge)
config_get tunname "$cfg" 'tunname'
iptables -D FORWARD -i "$tunname" -j ACCEPT 2>/dev/null
iptables -D FORWARD -o "$tunname" -j ACCEPT 2>/dev/null
iptables -t nat -D POSTROUTING -o "$tunname" -j MASQUERADE 2>/dev/null
killall -9 edge
;;
supernode)
@ -72,6 +80,6 @@ start() {
stop() {
config_load 'n2n_v2'
killall -9 edge
config_foreach stop_instance 'edge'
ps | grep supernode | grep -v grep 2>&1 >/dev/null && killall -9 supernode
}