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
b71c69b6
Commit
b71c69b6
authored
Feb 23, 2020
by
nanahira
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
update
parent
469a1c17
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
76 additions
and
6 deletions
+76
-6
ansible/configure.yaml
ansible/configure.yaml
+4
-4
ansible/scripts/postup.sh.j2
ansible/scripts/postup.sh.j2
+19
-0
ansible/scripts/predown.sh
ansible/scripts/predown.sh
+16
-0
ansible/scripts/predown.sh.j2
ansible/scripts/predown.sh.j2
+21
-0
src/inventory.ts
src/inventory.ts
+16
-2
No files found.
ansible/configure.yaml
View file @
b71c69b6
...
@@ -3,13 +3,13 @@
...
@@ -3,13 +3,13 @@
become
:
true
become
:
true
tasks
:
tasks
:
-
name
:
postup
-
name
:
postup
copy
:
template
:
src
:
scripts/postup.sh
src
:
scripts/postup.sh
.j2
dest
:
'
/etc/wireguard/postup.sh'
dest
:
'
/etc/wireguard/postup.sh'
mode
:
a+x
mode
:
a+x
-
name
:
predown
-
name
:
predown
copy
:
template
:
src
:
scripts/predown.sh
src
:
scripts/predown.sh
.j2
dest
:
'
/etc/wireguard/predown.sh'
dest
:
'
/etc/wireguard/predown.sh'
mode
:
a+x
mode
:
a+x
# 为了提高测试时候的性能,不改动wg的时候注释掉这段
# 为了提高测试时候的性能,不改动wg的时候注释掉这段
...
...
ansible/scripts/postup.sh
→
ansible/scripts/postup.sh
.j2
View file @
b71c69b6
#!/usr/bin/env bash
#!/usr/bin/env bash
#set -e
#set -e
if
[
"
$dev
"
==
"mc-yangtze"
]
;
then
# 初始化部分,mc-yangtze一定是第一个连接的
# 创建 ipset
ipset create mycard
hash
:net family inet
{
%
for
subnet
in
all_subnets %
}
ipset add mycard
{{
subnet
}}
{
% endfor %
}
# 针对网关设置mark
{
%
for
gateway
in
gateways %
}
{
%
if
gateway.route_tail
!=
""
%
}
ip route add default
{{
gateway.route_tail
}}
table
{{
gateway.mark
}}
ip rule add pref 301 fwmark
{{
gateway.mark
}}
lookup
{{
gateway.mark
}}
{
% endif %
}
{
% endfor %
}
fi
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
...
...
ansible/scripts/predown.sh
100755 → 100644
View file @
b71c69b6
#!/usr/bin/env bash
#!/usr/bin/env bash
if
[
"
$dev
"
==
"mc-yangtze"
]
;
then
# 初始化部分,mc-yangtze一定是第一个连接的
# 删除ipset
#iptables-save | grep "match-set mycard"
#ipset destroy mycard
# 针对网关设置mark
{
%
for
gateway
in
gateways %
}
{
%
if
gateway.route_tail
!=
""
%
}
ip route del default
{{
gateway.route_tail
}}
table
{{
gateway.mark
}}
ip rule del pref 301 fwmark
{{
gateway.mark
}}
table
{{
gateway.mark
}}
{
% endfor %
}
fi
if
[
"
$outbound
"
==
True
]
;
then
if
[
"
$outbound
"
==
True
]
;
then
ip rule del fwmark
"
$remoteMark
"
table
"
$remoteMark
"
pref 300
ip rule del fwmark
"
$remoteMark
"
table
"
$remoteMark
"
pref 300
fi
fi
...
...
ansible/scripts/predown.sh.j2
0 → 100755
View file @
b71c69b6
#!/usr/bin/env bash
if
[
"
$outbound
"
==
True
]
;
then
ip rule del fwmark
"
$remoteMark
"
table
"
$remoteMark
"
pref 300
fi
#if [ -z "${mtu}" ]; then
# mtu=$(cat /sys/class/net/"$dev"/mtu)
#fi
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
-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
-i
"
$dev
"
-m
set
!
--match-set
mycard src
-j
CONNMARK
--set-xmark
"
$remoteMark
"
iptables
-t
mangle
-D
PREROUTING
-m
connmark
--mark
"
$remoteMark
"
-j
CONNMARK
--restore-mark
iptables
-t
mangle
-D
OUTPUT
-m
connmark
--mark
"
$remoteMark
"
-j
CONNMARK
--restore-mark
# predown 始终返回成功。
true
src/inventory.ts
View file @
b71c69b6
...
@@ -11,6 +11,7 @@ class InventoryBuilder {
...
@@ -11,6 +11,7 @@ class InventoryBuilder {
hosts
:
{
[
key
:
string
]:
any
};
hosts
:
{
[
key
:
string
]:
any
};
gateways
:
any
;
gateways
:
any
;
connections
:
string
[];
connections
:
string
[];
all_subnets
:
any
;
async
load
(
sheetName
)
{
async
load
(
sheetName
)
{
const
data
=
await
fs
.
promises
.
readFile
(
path
.
join
(
'
data
'
,
`内网互联计划 -
${
sheetName
}
.csv`
));
const
data
=
await
fs
.
promises
.
readFile
(
path
.
join
(
'
data
'
,
`内网互联计划 -
${
sheetName
}
.csv`
));
...
@@ -22,6 +23,17 @@ class InventoryBuilder {
...
@@ -22,6 +23,17 @@ class InventoryBuilder {
this
.
hosts
=
_
.
keyBy
(
await
this
.
load
(
'
nextgen links
'
),
'
name
'
);
this
.
hosts
=
_
.
keyBy
(
await
this
.
load
(
'
nextgen links
'
),
'
name
'
);
this
.
gateways
=
_
.
mapValues
(
_
.
groupBy
(
await
this
.
load
(
'
gateways
'
),
'
name
'
),
g
=>
_
.
keyBy
(
g
,
'
isp
'
));
this
.
gateways
=
_
.
mapValues
(
_
.
groupBy
(
await
this
.
load
(
'
gateways
'
),
'
name
'
),
g
=>
_
.
keyBy
(
g
,
'
isp
'
));
this
.
connections
=
_
.
intersection
(
Object
.
keys
(
this
.
hosts
),
Object
.
keys
(
_
.
find
(
this
.
hosts
)));
this
.
connections
=
_
.
intersection
(
Object
.
keys
(
this
.
hosts
),
Object
.
keys
(
_
.
find
(
this
.
hosts
)));
this
.
all_subnets
=
[
"
10.199.0.0/16
"
,
"
10.200.0.0/15
"
];
for
(
const
h
in
this
.
hosts
)
{
const
host
=
this
.
hosts
[
h
]
for
(
const
c
of
host
.
subnets
.
split
(
"
,
"
))
{
if
(
!
c
.
length
)
{
continue
;
}
this
.
all_subnets
.
push
(
c
);
}
}
for
(
const
host
of
Object
.
values
(
this
.
hosts
))
{
for
(
const
host
of
Object
.
values
(
this
.
hosts
))
{
host
.
wgPublickey
=
await
this
.
wgPublickey
(
host
.
wgPrivateKey
);
host
.
wgPublickey
=
await
this
.
wgPublickey
(
host
.
wgPrivateKey
);
}
}
...
@@ -62,9 +74,11 @@ class InventoryBuilder {
...
@@ -62,9 +74,11 @@ class InventoryBuilder {
key
:
host
.
wgPrivateKey
,
key
:
host
.
wgPrivateKey
,
frpsPort
:
host
.
frpsPort
,
frpsPort
:
host
.
frpsPort
,
frpToken
:
host
.
frpToken
,
frpToken
:
host
.
frpToken
,
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
]),
connections
,
connections
,
lan_interfaces
lan_interfaces
,
all_subnets
:
JSON
.
parse
(
JSON
.
stringify
(
this
.
all_subnets
))
};
};
}
}
...
...
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