Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
T
tun
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Locked Files
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Security & Compliance
Security & Compliance
Dependency List
License Compliance
Packages
Packages
List
Container Registry
Analytics
Analytics
CI / CD
Code Review
Insights
Issues
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Railgun
tun
Commits
ea668061
Commit
ea668061
authored
Dec 11, 2020
by
nanahira
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
too hard to remake
parent
10021686
Changes
8
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
37 additions
and
29 deletions
+37
-29
ansible/bird.conf.bak
ansible/bird.conf.bak
+1
-1
ansible/bird.conf.j2
ansible/bird.conf.j2
+3
-3
ansible/protocols/wg/wg.conf.j2
ansible/protocols/wg/wg.conf.j2
+2
-2
ansible/protocols/wgfrp/wgfrp.conf.j2
ansible/protocols/wgfrp/wgfrp.conf.j2
+2
-2
ansible/scripts/global-postup.sh.j2
ansible/scripts/global-postup.sh.j2
+1
-1
ansible/scripts/postup.sh.j2
ansible/scripts/postup.sh.j2
+8
-5
ansible/scripts/predown.sh.j2
ansible/scripts/predown.sh.j2
+7
-4
src/inventory.ts
src/inventory.ts
+13
-11
No files found.
ansible/bird.conf.bak
View file @
ea668061
...
@@ -95,7 +95,7 @@ protocol ospf v2 {
...
@@ -95,7 +95,7 @@ protocol ospf v2 {
{% endif %}
{% endif %}
{% endfor %}
{% endfor %}
{% for interface in lan
_i
nterfaces %}
{% for interface in lan
I
nterfaces %}
interface "{{interface}}" {
interface "{{interface}}" {
type broadcast;
type broadcast;
cost 1;
cost 1;
...
...
ansible/bird.conf.j2
View file @
ea668061
...
@@ -9,7 +9,7 @@ protocol device {
...
@@ -9,7 +9,7 @@ protocol device {
# ipv6;
# ipv6;
#}
#}
{% for interface in lan
_i
nterfaces %}
{% for interface in lan
I
nterfaces %}
protocol direct {
protocol direct {
ipv4;
ipv4;
ipv6;
ipv6;
...
@@ -42,7 +42,7 @@ protocol kernel {
...
@@ -42,7 +42,7 @@ protocol kernel {
table {{connection.name.replace("-", "_")}};
table {{connection.name.replace("-", "_")}};
export all;
export all;
};
};
kernel table {{connection.remoteMark}};
kernel table {{connection.remote
Dest
Mark}};
}
}
{% endif %}
{% endif %}
{% endfor %}
{% endfor %}
...
@@ -75,7 +75,7 @@ protocol ospf v2 {
...
@@ -75,7 +75,7 @@ protocol ospf v2 {
{% endif %}
{% endif %}
{% endfor %}
{% endfor %}
{% for interface in lan
_i
nterfaces %}
{% for interface in lan
I
nterfaces %}
interface "{{interface}}" {
interface "{{interface}}" {
type broadcast;
type broadcast;
cost 1;
cost 1;
...
...
ansible/protocols/wg/wg.conf.j2
View file @
ea668061
...
@@ -8,8 +8,8 @@ FwMark = {{conn.localGatewayMark}}
...
@@ -8,8 +8,8 @@ FwMark = {{conn.localGatewayMark}}
MTU = {{conn.mtu|int - 80}}
MTU = {{conn.mtu|int - 80}}
Table = off
Table = off
PostUp = dev=%i localPeerAddress={{conn.localPeerAddress}} remotePeerAddress={{conn.remotePeerAddress}} remote
Mark={{conn.remote
Mark}} inbound={{conn.inbound}} outbound={{conn.outbound}} mtu={{conn.mtu|int - 80}} /etc/wireguard/postup.sh
PostUp = dev=%i localPeerAddress={{conn.localPeerAddress}} remotePeerAddress={{conn.remotePeerAddress}} remote
NextMark={{conn.remoteNextMark}} remoteDestMark={{conn.remoteDest
Mark}} inbound={{conn.inbound}} outbound={{conn.outbound}} mtu={{conn.mtu|int - 80}} /etc/wireguard/postup.sh
PreDown = dev=%i localPeerAddress={{conn.localPeerAddress}} remotePeerAddress={{conn.remotePeerAddress}} remote
Mark={{conn.remote
Mark}} inbound={{conn.inbound}} outbound={{conn.outbound}} mtu={{conn.mtu|int - 80}} /etc/wireguard/predown.sh
PreDown = dev=%i localPeerAddress={{conn.localPeerAddress}} remotePeerAddress={{conn.remotePeerAddress}} remote
NextMark={{conn.remoteNextMark}} remoteDestMark={{conn.remoteDest
Mark}} inbound={{conn.inbound}} outbound={{conn.outbound}} mtu={{conn.mtu|int - 80}} /etc/wireguard/predown.sh
[Peer]
[Peer]
PublicKey = {{conn.wgPublicKey}}
PublicKey = {{conn.wgPublicKey}}
...
...
ansible/protocols/wgfrp/wgfrp.conf.j2
View file @
ea668061
...
@@ -9,8 +9,8 @@ FwMark = {{conn.localGatewayMark}}
...
@@ -9,8 +9,8 @@ FwMark = {{conn.localGatewayMark}}
{% endif %}
{% endif %}
MTU = {{conn.mtu|int - 80}}
MTU = {{conn.mtu|int - 80}}
Table = off
Table = off
PostUp = dev=%i localPeerAddress={{conn.localPeerAddress}} remotePeerAddress={{conn.remotePeerAddress}} remote
Mark={{conn.remote
Mark}} inbound={{conn.inbound}} outbound={{conn.outbound}} mtu={{conn.mtu|int - 80}} /etc/wireguard/postup.sh
PostUp = dev=%i localPeerAddress={{conn.localPeerAddress}} remotePeerAddress={{conn.remotePeerAddress}} remote
NextMark={{conn.remoteNextMark}} remoteDestMark={{conn.remoteDest
Mark}} inbound={{conn.inbound}} outbound={{conn.outbound}} mtu={{conn.mtu|int - 80}} /etc/wireguard/postup.sh
PreDown = dev=%i localPeerAddress={{conn.localPeerAddress}} remotePeerAddress={{conn.remotePeerAddress}} remote
Mark={{conn.remote
Mark}} inbound={{conn.inbound}} outbound={{conn.outbound}} mtu={{conn.mtu|int - 80}} /etc/wireguard/predown.sh
PreDown = dev=%i localPeerAddress={{conn.localPeerAddress}} remotePeerAddress={{conn.remotePeerAddress}} remote
NextMark={{conn.remoteNextMark}} remoteDestMark={{conn.remoteDest
Mark}} inbound={{conn.inbound}} outbound={{conn.outbound}} mtu={{conn.mtu|int - 80}} /etc/wireguard/predown.sh
[Peer]
[Peer]
PublicKey = {{conn.wgPublicKey}}
PublicKey = {{conn.wgPublicKey}}
AllowedIPs = 0.0.0.0/0, ::/0
AllowedIPs = 0.0.0.0/0, ::/0
...
...
ansible/scripts/global-postup.sh.j2
View file @
ea668061
...
@@ -6,7 +6,7 @@ ipset restore -f /etc/wireguard/{{list}}.ipset || true
...
@@ -6,7 +6,7 @@ ipset restore -f /etc/wireguard/{{list}}.ipset || true
{
% endfor %
}
{
% endfor %
}
# 临时梯子
# 临时梯子
iptables
-t
mangle
-A
PREROUTING
-m
set
--match-set
ladder_needed src
-m
set
--match-set
gfwiplist dst
-j
MARK
--set-xmark
812/0xffffffff
#
iptables -t mangle -A PREROUTING -m set --match-set ladder_needed src -m set --match-set gfwiplist dst -j MARK --set-xmark 812/0xffffffff
echo
1
>
/tmp/mycard_global_postup_done
echo
1
>
/tmp/mycard_global_postup_done
...
...
ansible/scripts/postup.sh.j2
View file @
ea668061
...
@@ -4,8 +4,9 @@
...
@@ -4,8 +4,9 @@
ip addr add
"
$localPeerAddress
"
peer
"
$remotePeerAddress
"
dev
"
$dev
"
scope
link
ip addr add
"
$localPeerAddress
"
peer
"
$remotePeerAddress
"
dev
"
$dev
"
scope
link
if
[
"
$outbound
"
==
True
]
;
then
if
[
"
$outbound
"
==
True
]
;
then
#ip route add default dev "$dev" table "$remoteMark"
ip route add default dev
"
$dev
"
table
"
$remoteNextMark
"
ip rule add fwmark
"
$remoteMark
"
table
"
$remoteMark
"
pref 300
ip rule add fwmark
"
$remoteNextMark
"
table
"
$remoteNextMark
"
pref 300
ip rule add fwmark
"
$remoteDestMark
"
table
"
$remoteDestMark
"
pref 300
fi
fi
#if [ -z "${mtu}" ]; then
#if [ -z "${mtu}" ]; then
...
@@ -17,8 +18,10 @@ mss=$((mtu - 40))
...
@@ -17,8 +18,10 @@ mss=$((mtu - 40))
iptables
-t
mangle
-A
FORWARD
-i
"
$dev
"
-p
tcp
-m
tcp
--tcp-flags
SYN,RST SYN
-m
tcpmss
--mss
$mss
:1460
-j
TCPMSS
--set-mss
$mss
iptables
-t
mangle
-A
FORWARD
-i
"
$dev
"
-p
tcp
-m
tcp
--tcp-flags
SYN,RST SYN
-m
tcpmss
--mss
$mss
:1460
-j
TCPMSS
--set-mss
$mss
iptables
-t
mangle
-A
FORWARD
-o
"
$dev
"
-p
tcp
-m
tcp
--tcp-flags
SYN,RST SYN
-m
tcpmss
--mss
$mss
:1460
-j
TCPMSS
--set-mss
$mss
iptables
-t
mangle
-A
FORWARD
-o
"
$dev
"
-p
tcp
-m
tcp
--tcp-flags
SYN,RST SYN
-m
tcpmss
--mss
$mss
:1460
-j
TCPMSS
--set-mss
$mss
iptables
-t
mangle
-A
PREROUTING
!
-p
ospf
-i
"
$dev
"
-m
set
!
--match-set
mycard src
-j
CONNMARK
--set-xmark
"
$remoteMark
"
if
[
"
$inbound
"
==
True
]
;
then
iptables
-t
mangle
-A
PREROUTING
-m
connmark
--mark
"
$remoteMark
"
-j
CONNMARK
--restore-mark
iptables
-t
mangle
-A
PREROUTING
!
-p
ospf
-i
"
$dev
"
-m
set
!
--match-set
mycard src
-j
CONNMARK
--set-xmark
"
$remoteNextMark
"
iptables
-t
mangle
-A
OUTPUT
-m
connmark
--mark
"
$remoteMark
"
-j
CONNMARK
--restore-mark
iptables
-t
mangle
-A
PREROUTING
-m
connmark
--mark
"
$remoteNextMark
"
-j
CONNMARK
--restore-mark
iptables
-t
mangle
-A
OUTPUT
-m
connmark
--mark
"
$remoteNextMark
"
-j
CONNMARK
--restore-mark
fi
true
true
ansible/scripts/predown.sh.j2
View file @
ea668061
#!/usr/bin/env bash
#!/usr/bin/env bash
if
[
"
$outbound
"
==
True
]
;
then
if
[
"
$outbound
"
==
True
]
;
then
ip rule del fwmark
"
$remoteMark
"
table
"
$remoteMark
"
pref 300
ip rule del fwmark
"
$remoteNextMark
"
table
"
$remoteNextMark
"
pref 300
ip rule del fwmark
"
$remoteDestMark
"
table
"
$remoteDestMark
"
pref 300
fi
fi
#if [ -z "${mtu}" ]; then
#if [ -z "${mtu}" ]; then
...
@@ -13,9 +14,11 @@ mss=$((mtu - 40))
...
@@ -13,9 +14,11 @@ mss=$((mtu - 40))
iptables
-t
mangle
-D
FORWARD
-i
"
$dev
"
-p
tcp
-m
tcp
--tcp-flags
SYN,RST SYN
-m
tcpmss
--mss
$mss
:1460
-j
TCPMSS
--set-mss
$mss
iptables
-t
mangle
-D
FORWARD
-i
"
$dev
"
-p
tcp
-m
tcp
--tcp-flags
SYN,RST SYN
-m
tcpmss
--mss
$mss
:1460
-j
TCPMSS
--set-mss
$mss
iptables
-t
mangle
-D
FORWARD
-o
"
$dev
"
-p
tcp
-m
tcp
--tcp-flags
SYN,RST SYN
-m
tcpmss
--mss
$mss
:1460
-j
TCPMSS
--set-mss
$mss
iptables
-t
mangle
-D
FORWARD
-o
"
$dev
"
-p
tcp
-m
tcp
--tcp-flags
SYN,RST SYN
-m
tcpmss
--mss
$mss
:1460
-j
TCPMSS
--set-mss
$mss
iptables
-t
mangle
-D
PREROUTING
!
-p
ospf
-i
"
$dev
"
-m
set
!
--match-set
mycard src
-j
CONNMARK
--set-xmark
"
$remoteMark
"
if
[
"
$inbound
"
==
True
]
;
then
iptables
-t
mangle
-D
PREROUTING
-m
connmark
--mark
"
$remoteMark
"
-j
CONNMARK
--restore-mark
iptables
-t
mangle
-D
PREROUTING
!
-p
ospf
-i
"
$dev
"
-m
set
!
--match-set
mycard src
-j
CONNMARK
--set-xmark
"
$remoteNextMark
"
iptables
-t
mangle
-D
OUTPUT
-m
connmark
--mark
"
$remoteMark
"
-j
CONNMARK
--restore-mark
iptables
-t
mangle
-D
PREROUTING
-m
connmark
--mark
"
$remoteNextMark
"
-j
CONNMARK
--restore-mark
iptables
-t
mangle
-D
OUTPUT
-m
connmark
--mark
"
$remoteNextMark
"
-j
CONNMARK
--restore-mark
fi
# predown 始终返回成功。
# predown 始终返回成功。
true
true
src/inventory.ts
View file @
ea668061
...
@@ -20,12 +20,12 @@ class InventoryBuilder {
...
@@ -20,12 +20,12 @@ class InventoryBuilder {
}
}
async
loadGateways
()
{
async
loadGateways
()
{
const
gateways
=
await
this
.
load
(
'
gateways
'
);
const
gateways
=
await
this
.
load
(
'
gateways
2
'
);
return
gateways
;
return
gateways
;
}
}
async
main
()
{
async
main
()
{
this
.
hosts
=
_
.
keyBy
(
await
this
.
load
(
'
nextgen
links
'
),
'
name
'
);
this
.
hosts
=
_
.
keyBy
(
await
this
.
load
(
'
nextgen
2
'
),
'
name
'
);
this
.
gateways
=
_
.
mapValues
(
_
.
groupBy
(
await
this
.
loadGateways
(),
'
name
'
),
g
=>
_
.
keyBy
(
g
,
'
isp
'
));
this
.
gateways
=
_
.
mapValues
(
_
.
groupBy
(
await
this
.
loadGateways
(),
'
name
'
),
g
=>
_
.
keyBy
(
g
,
'
isp
'
));
//console.log(this.gateways);
//console.log(this.gateways);
this
.
connections
=
_
.
intersection
(
Object
.
keys
(
this
.
hosts
),
Object
.
keys
(
_
.
find
(
this
.
hosts
)));
this
.
connections
=
_
.
intersection
(
Object
.
keys
(
this
.
hosts
),
Object
.
keys
(
_
.
find
(
this
.
hosts
)));
...
@@ -43,13 +43,13 @@ class InventoryBuilder {
...
@@ -43,13 +43,13 @@ class InventoryBuilder {
async
loadUtilities
(
hosts
)
{
async
loadUtilities
(
hosts
)
{
const
raw_utility
=
_
.
keyBy
(
await
this
.
load
(
'
configurations
'
),
'
key
'
);
const
raw_utility
=
_
.
keyBy
(
await
this
.
load
(
'
configurations
'
),
'
key
'
);
let
route_plans
=
await
this
.
load
(
'
route tables
'
);
//
let route_plans = await this.load('route tables');
this
.
route_lists
=
YAML
.
parse
(
fs
.
readFileSync
(
path
.
join
(
'
lists
'
,
'
result.yaml
'
),
"
utf8
"
));
this
.
route_lists
=
YAML
.
parse
(
fs
.
readFileSync
(
path
.
join
(
'
lists
'
,
'
result.yaml
'
),
"
utf8
"
));
for
(
let
plan
of
route_plans
)
{
/*
for (let plan of route_plans) {
plan.name = plan.list + "_" + plan.gateway.replace(/-/g, "_").split(".")[0]
plan.name = plan.list + "_" + plan.gateway.replace(/-/g, "_").split(".")[0]
//plan.list = JSON.parse(JSON.stringify(this.route_lists[plan.list]));
//plan.list = JSON.parse(JSON.stringify(this.route_lists[plan.list]));
plan.gatewayAddress = hosts[plan.gateway].address;
plan.gatewayAddress = hosts[plan.gateway].address;
}
}
*/
// 所有内网网段
// 所有内网网段
this
.
route_lists
.
mycard
=
[
"
10.198.0.0/16
"
,
"
10.200.0.0/15
"
,
"
172.16.0.0/12
"
];
this
.
route_lists
.
mycard
=
[
"
10.198.0.0/16
"
,
"
10.200.0.0/15
"
,
"
172.16.0.0/12
"
];
for
(
const
h
in
this
.
hosts
)
{
for
(
const
h
in
this
.
hosts
)
{
...
@@ -66,7 +66,7 @@ class InventoryBuilder {
...
@@ -66,7 +66,7 @@ class InventoryBuilder {
const
vars
=
{
const
vars
=
{
route_lists
:
this
.
route_lists
,
route_lists
:
this
.
route_lists
,
route_list_names
:
Object
.
keys
(
this
.
route_lists
),
route_list_names
:
Object
.
keys
(
this
.
route_lists
),
route_plans
//
route_plans
};
};
for
(
let
col
in
raw_utility
)
{
for
(
let
col
in
raw_utility
)
{
vars
[
col
]
=
raw_utility
[
col
].
value
;
vars
[
col
]
=
raw_utility
[
col
].
value
;
...
@@ -77,7 +77,7 @@ class InventoryBuilder {
...
@@ -77,7 +77,7 @@ class InventoryBuilder {
host_vars
(
host
)
{
host_vars
(
host
)
{
const
connections
=
[];
const
connections
=
[];
const
null_connection
=
"
10000,null
"
;
const
null_connection
=
"
10000,null
"
;
const
lan
_interfaces
=
host
.
lan_interfaces
.
length
>
0
?
host
.
lan_i
nterfaces
.
split
(
"
,
"
)
:
[];
const
lan
Interfaces
=
host
.
lanInterfaces
.
length
>
0
?
host
.
lanI
nterfaces
.
split
(
"
,
"
)
:
[];
const
dns
=
host
.
dns
;
const
dns
=
host
.
dns
;
for
(
const
h
of
this
.
connections
)
{
for
(
const
h
of
this
.
connections
)
{
if
(
h
!=
host
.
name
)
{
if
(
h
!=
host
.
name
)
{
...
@@ -110,7 +110,7 @@ class InventoryBuilder {
...
@@ -110,7 +110,7 @@ class InventoryBuilder {
//gateways: _.mapValues(this.gateways[host.name], gw => _.pick(gw, ['mark_gateway'])),
//gateways: _.mapValues(this.gateways[host.name], gw => _.pick(gw, ['mark_gateway'])),
gateways
:
_
.
values
(
this
.
gateways
[
host
.
name
]),
gateways
:
_
.
values
(
this
.
gateways
[
host
.
name
]),
connections
,
connections
,
lan
_i
nterfaces
,
lan
I
nterfaces
,
dns
dns
};
};
}
}
...
@@ -133,7 +133,8 @@ class InventoryBuilder {
...
@@ -133,7 +133,8 @@ class InventoryBuilder {
//console.log(remoteGateway.name);
//console.log(remoteGateway.name);
const
remoteAddress
=
remoteGateway
.
address
;
const
remoteAddress
=
remoteGateway
.
address
;
const
remoteLocalAddress
=
remote
.
address
;
const
remoteLocalAddress
=
remote
.
address
;
const
remoteMark
=
remote
.
mark
;
const
remoteNextMark
=
remote
.
nextMark
;
const
remoteDestMark
=
remote
.
destMark
;
const
localPort
=
(
primary
?
remote
.
port
:
remote
.
port2
)
+
local
.
offset
;
const
localPort
=
(
primary
?
remote
.
port
:
remote
.
port2
)
+
local
.
offset
;
const
remotePort
=
(
primary
?
local
.
port
:
local
.
port2
)
+
remote
.
offset
;
const
remotePort
=
(
primary
?
local
.
port
:
local
.
port2
)
+
remote
.
offset
;
const
remoteFrpsPort
=
remote
.
frpsPort
;
const
remoteFrpsPort
=
remote
.
frpsPort
;
...
@@ -153,7 +154,8 @@ class InventoryBuilder {
...
@@ -153,7 +154,8 @@ class InventoryBuilder {
params
,
params
,
localGatewayMark
,
localGatewayMark
,
//remoteGatewayMark,
//remoteGatewayMark,
remoteMark
,
remoteNextMark
,
remoteDestMark
,
remoteAddress
,
remoteAddress
,
remoteLocalAddress
,
remoteLocalAddress
,
localPort
,
localPort
,
...
@@ -180,7 +182,7 @@ class InventoryBuilder {
...
@@ -180,7 +182,7 @@ class InventoryBuilder {
const
ipv4NatScore
=
({
const
ipv4NatScore
=
({
"
ports
"
:
0
,
"
ports
"
:
0
,
"
dmz
"
:
1
"
dmz
"
:
1
})[
gateway
.
ipv4
_n
at
]
||
2
;
})[
gateway
.
ipv4
N
at
]
||
2
;
score
|=
ipv4NatScore
<<
10
;
score
|=
ipv4NatScore
<<
10
;
const
globalSSHScore
=
({
const
globalSSHScore
=
({
"
globalssh
"
:
1
"
globalssh
"
:
1
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment