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
1cdd71ef
Commit
1cdd71ef
authored
Aug 13, 2021
by
nanahira
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'haproxy'
parents
026fb8f2
60b294a6
Changes
10
Hide whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
78 additions
and
16 deletions
+78
-16
.gitignore
.gitignore
+1
-0
ansible/configure.yaml
ansible/configure.yaml
+13
-0
ansible/route-plans.j2
ansible/route-plans.j2
+1
-0
ansible/scripts/global-postup.sh.j2
ansible/scripts/global-postup.sh.j2
+3
-0
ansible/scripts/switch-rules-down.sh.j2
ansible/scripts/switch-rules-down.sh.j2
+1
-0
ansible/scripts/switch-rules-up.sh.j2
ansible/scripts/switch-rules-up.sh.j2
+4
-1
ansible/scripts/utility.sh.j2
ansible/scripts/utility.sh.j2
+7
-0
config-with-proxy.sh
config-with-proxy.sh
+2
-2
lists/special.txt
lists/special.txt
+0
-3
src/inventory.ts
src/inventory.ts
+46
-10
No files found.
.gitignore
View file @
1cdd71ef
...
@@ -118,3 +118,4 @@ certs
...
@@ -118,3 +118,4 @@ certs
# babeld-reload.conf.j2
# babeld-reload.conf.j2
__pycache__
__pycache__
*.pyc
ansible/configure.yaml
View file @
1cdd71ef
...
@@ -144,6 +144,12 @@
...
@@ -144,6 +144,12 @@
dest
:
'
{{ansible_user_dir}}/nextgen-network/services/babeld.conf'
dest
:
'
{{ansible_user_dir}}/nextgen-network/services/babeld.conf'
#notify: restart_babeld
#notify: restart_babeld
when
:
not noBird and not systemBird
when
:
not noBird and not systemBird
-
name
:
gost.json
copy
:
content
:
'
{{gostConfig
|
to_nice_json}}'
dest
:
'
{{ansible_user_dir}}/nextgen-network/services/gost.json'
notify
:
restart_gost
when
:
installGost
-
name
:
monitor route plans
-
name
:
monitor route plans
template
:
template
:
src
:
route-plans.j2
src
:
route-plans.j2
...
@@ -231,6 +237,13 @@
...
@@ -231,6 +237,13 @@
services
:
services
:
-
ocserv
-
ocserv
when
:
not noBird
when
:
not noBird
-
name
:
restart_gost
docker_compose
:
project_src
:
'
{{ansible_user_dir}}/nextgen-network/services'
restarted
:
true
services
:
-
gost
when
:
installGost
-
name
:
restart_openconnect
-
name
:
restart_openconnect
docker_compose
:
docker_compose
:
project_src
:
'
{{ansible_user_dir}}/nextgen-network/services'
project_src
:
'
{{ansible_user_dir}}/nextgen-network/services'
...
...
ansible/route-plans.j2
View file @
1cdd71ef
# force reload 8.5
declare -A ROUTE_PLANS=(
declare -A ROUTE_PLANS=(
{% for plan in routePlans %}
{% for plan in routePlans %}
[{{plan.destMark}}]="{{plan.addressesString}}"
[{{plan.destMark}}]="{{plan.addressesString}}"
...
...
ansible/scripts/global-postup.sh.j2
View file @
1cdd71ef
...
@@ -34,6 +34,9 @@ $IPTABLES_EXEC -t mangle -A PREROUTING -m mark --mark 0x0 ! -p ospf -m set ! --m
...
@@ -34,6 +34,9 @@ $IPTABLES_EXEC -t mangle -A PREROUTING -m mark --mark 0x0 ! -p ospf -m set ! --m
$IPTABLES_EXEC
-t
mangle
-I
OUTPUT
-m
mark
!
--mark
0
-j
RETURN
$IPTABLES_EXEC
-t
mangle
-I
OUTPUT
-m
mark
!
--mark
0
-j
RETURN
$IPTABLES_EXEC
-t
nat
-N
NEXTGEN_SWITCH
$IPTABLES_EXEC
-t
nat
-A
PREROUTING
-j
NEXTGEN_SWITCH
# switch rules
# switch rules
{{
ansible_user_dir
}}
/nextgen-network/scripts/switch-rules-up.sh
{{
ansible_user_dir
}}
/nextgen-network/scripts/switch-rules-up.sh
...
...
ansible/scripts/switch-rules-down.sh.j2
View file @
1cdd71ef
...
@@ -2,6 +2,7 @@
...
@@ -2,6 +2,7 @@
source
{{
ansible_user_dir
}}
/nextgen-network/scripts/utility.sh
source
{{
ansible_user_dir
}}
/nextgen-network/scripts/utility.sh
iptables
-t
mangle
-F
NEXTGEN_SWITCH
iptables
-t
mangle
-F
NEXTGEN_SWITCH
iptables
-t
nat
-F
NEXTGEN_SWITCH
## restore mark
## restore mark
{
%
for
plan
in
routePlans %
}
{
%
for
plan
in
routePlans %
}
...
...
ansible/scripts/switch-rules-up.sh.j2
View file @
1cdd71ef
#!/bin/bash
#!/bin/bash
## reloaded at
6.24
## reloaded at
8.13
source
{{
ansible_user_dir
}}
/nextgen-network/scripts/utility.sh
source
{{
ansible_user_dir
}}
/nextgen-network/scripts/utility.sh
## route plans
## route plans
...
@@ -12,11 +12,14 @@ restore_mark_switch -A {{plan.destMark}}
...
@@ -12,11 +12,14 @@ restore_mark_switch -A {{plan.destMark}}
## local gateways
## local gateways
{
%
for
gw
in
gateways %
}
{
%
for
gw
in
gateways %
}
{
%
if
not gw.hidden %
}
{
%
if
gw.selectionMark
>
0 %
}
{
%
if
gw.selectionMark
>
0 %
}
interface_switch_china
-A
u_
{{
gw.isp
}}
_china
{{
gw.selectionMark
}}
interface_switch_china
-A
u_
{{
gw.isp
}}
_china
{{
gw.selectionMark
}}
interface_switch_oversea
-A
u_
{{
gw.isp
}}
_oversea
{{
gw.selectionMark
}}
interface_switch_oversea
-A
u_
{{
gw.isp
}}
_oversea
{{
gw.selectionMark
}}
restore_mark_switch
-A
{{
gw.selectionMark
}}
restore_mark_switch
-A
{{
gw.selectionMark
}}
{
% endif %
}
{
% endif %
}
interface_switch_redirect
-A
{{
gw.selectionMark
}}
{{
gw.redirectPort
}}
{
% endif %
}
{
% endfor %
}
{
% endfor %
}
true
true
ansible/scripts/utility.sh.j2
View file @
1cdd71ef
...
@@ -67,3 +67,10 @@ interface_switch_oversea() {
...
@@ -67,3 +67,10 @@ interface_switch_oversea() {
ipset create "$IPSET" hash:net maxelem 1000000 || true
ipset create "$IPSET" hash:net maxelem 1000000 || true
$IPTABLES_EXEC -t mangle "$OPTION" NEXTGEN_SWITCH -m mark --mark 0 -m set --match-set "$IPSET" src -m set ! --match-set mycard dst -m set --match-set chnrouter dst -j CONNMARK --set-xmark "$MARK"
$IPTABLES_EXEC -t mangle "$OPTION" NEXTGEN_SWITCH -m mark --mark 0 -m set --match-set "$IPSET" src -m set ! --match-set mycard dst -m set --match-set chnrouter dst -j CONNMARK --set-xmark "$MARK"
}
}
interface_switch_redirect() {
OPTION=$1
MARK=$2
REDIR_PORT=$3
$IPTABLES_EXEC -t nat "$OPTION" NEXTGEN_SWITCH -m mark --mark $MARK -m set --match-set mycard src -m set ! --match-set mycard dst -p tcp -m multiport --dports 80,443,21,22,23,8080,8443 -j DNAT --to-destination {{address}}:$REDIR_PORT
}
config-with-proxy.sh
View file @
1cdd71ef
#!/bin/bash
#!/bin/bash
LADDER
=
"jue"
LADDER
=
"jue"
ssh root@10.198.1.1
-p
55322 ipset add u_
${
LADDER
}
_oversea 10.198.1.57
ssh root@10.198.1.1
-p
55322 ipset add u_
${
LADDER
}
_oversea 10.198.1.57
#
ssh nanahira@10.198.0.6 sudo ipset add u_${LADDER}_oversea 10.198.1.57
ssh nanahira@10.198.0.6
sudo
ipset add u_
${
LADDER
}
_oversea 10.198.1.57
./config.sh
./config.sh
ssh root@10.198.1.1
-p
55322 ipset del u_
${
LADDER
}
_oversea 10.198.1.57
ssh root@10.198.1.1
-p
55322 ipset del u_
${
LADDER
}
_oversea 10.198.1.57
#
ssh nanahira@10.198.0.6 sudo ipset del u_${LADDER}_oversea 10.198.1.57
ssh nanahira@10.198.0.6
sudo
ipset del u_
${
LADDER
}
_oversea 10.198.1.57
lists/special.txt
View file @
1cdd71ef
0.0.0.0/8
0.0.0.0/8
1.1.1.0/24
1.0.0.0/24
1.0.0.0/24
8.8.8.0/24
8.8.4.0/24
10.0.0.0/7
10.0.0.0/7
100.64.0.0/10
100.64.0.0/10
127.0.0.0/8
127.0.0.0/8
...
...
src/inventory.ts
View file @
1cdd71ef
...
@@ -27,6 +27,18 @@ interface GatewayGroup extends Record<string, any> {
...
@@ -27,6 +27,18 @@ interface GatewayGroup extends Record<string, any> {
destMark
:
number
;
destMark
:
number
;
}
}
interface
GostRoute
{
Retries
?:
string
;
ServeNodes
:
string
[];
ChainNodes
?:
string
[];
Mark
?:
number
}
interface
GostConfig
extends
Partial
<
GostRoute
>
{
Routes
:
GostRoute
[];
Debug
?:
boolean
;
}
type
CommonEntry
=
Record
<
string
,
any
>
;
type
CommonEntry
=
Record
<
string
,
any
>
;
class
InventoryBuilder
{
class
InventoryBuilder
{
...
@@ -47,7 +59,7 @@ class InventoryBuilder {
...
@@ -47,7 +59,7 @@ class InventoryBuilder {
this
.
resolver
.
setServers
(
process
.
env
.
DNS
?
[
process
.
env
.
DNS
]
:
[
'
114.114.114.114
'
,
'
223.5.5.5
'
]);
this
.
resolver
.
setServers
(
process
.
env
.
DNS
?
[
process
.
env
.
DNS
]
:
[
'
114.114.114.114
'
,
'
223.5.5.5
'
]);
}
}
getDockerImageTag
(
host
:
an
y
)
{
getDockerImageTag
(
host
:
CommonEntr
y
)
{
if
(
host
.
arch
&&
host
.
arch
.
length
)
{
if
(
host
.
arch
&&
host
.
arch
.
length
)
{
return
`:master-
${
host
.
arch
}
`
;
return
`:master-
${
host
.
arch
}
`
;
}
else
{
}
else
{
...
@@ -90,11 +102,13 @@ class InventoryBuilder {
...
@@ -90,11 +102,13 @@ class InventoryBuilder {
const
gateways
=
await
this
.
load
(
'
gateways2
'
);
const
gateways
=
await
this
.
load
(
'
gateways2
'
);
for
(
let
gateway
of
gateways
)
{
for
(
let
gateway
of
gateways
)
{
gateway
.
isCN
=
this
.
hosts
[
gateway
.
router
]
&&
this
.
hosts
[
gateway
.
router
].
location
.
startsWith
(
'
CN
'
);
gateway
.
isCN
=
this
.
hosts
[
gateway
.
router
]
&&
this
.
hosts
[
gateway
.
router
].
location
.
startsWith
(
'
CN
'
);
gateway
.
hidden
=
!!
gateway
.
hidden
;
if
(
gateway
.
mark
)
{
if
(
gateway
.
mark
)
{
gateway
.
selectionMark
=
gateway
.
mark
+
50
;
gateway
.
selectionMark
=
gateway
.
mark
+
50
;
gateway
.
redirectPort
=
gateway
.
mark
+
60000
;
}
else
{
}
else
{
gateway
.
mark
=
0
;
gateway
.
selectionMark
=
0
;
gateway
.
selectionMark
=
0
;
gateway
.
redirectPort
=
60100
;
}
}
}
}
return
gateways
;
return
gateways
;
...
@@ -126,7 +140,7 @@ class InventoryBuilder {
...
@@ -126,7 +140,7 @@ class InventoryBuilder {
this
.
linksLimit
=
process
.
env
.
LIMIT_LINKS
.
split
(
"
,
"
);
this
.
linksLimit
=
process
.
env
.
LIMIT_LINKS
.
split
(
"
,
"
);
}
}
this
.
vars
=
await
this
.
loadUtilities
();
this
.
vars
=
await
this
.
loadUtilities
();
const
inventoryValue
=
{
wg
:
{
hosts
:
Object
.
fromEntries
(
Object
.
values
(
this
.
hosts
).
map
(
host
=>
[
host
.
name
,
this
.
getHostConnectionInfo
(
host
)]))
}
};
const
inventoryValue
=
{
wg
:
{
hosts
:
Object
.
fromEntries
(
Object
.
values
(
this
.
hosts
).
map
(
host
=>
[
host
.
name
,
this
.
getHostConnectionInfo
(
host
)]))
}
};
await
fs
.
promises
.
writeFile
(
'
result/inventory.yaml
'
,
YAML
.
stringify
(
inventoryValue
));
await
fs
.
promises
.
writeFile
(
'
result/inventory.yaml
'
,
YAML
.
stringify
(
inventoryValue
));
// console.log(Object.values(this.hosts));
// console.log(Object.values(this.hosts));
const
hosts
=
await
Promise
.
all
(
Object
.
values
(
this
.
hosts
).
map
(
async
(
h
)
=>
({
const
hosts
=
await
Promise
.
all
(
Object
.
values
(
this
.
hosts
).
map
(
async
(
h
)
=>
({
...
@@ -172,7 +186,7 @@ class InventoryBuilder {
...
@@ -172,7 +186,7 @@ class InventoryBuilder {
}
}
return
addresses
.
join
(
"
"
);
return
addresses
.
join
(
"
"
);
}
}
isGatewayGroupContains
(
gatewayGroup
:
GatewayGroup
,
host
:
an
y
)
{
isGatewayGroupContains
(
gatewayGroup
:
GatewayGroup
,
host
:
CommonEntr
y
)
{
const
locationPrefixes
=
gatewayGroup
.
locationPrefix
.
split
(
"
,
"
);
const
locationPrefixes
=
gatewayGroup
.
locationPrefix
.
split
(
"
,
"
);
const
excludeRouters
=
gatewayGroup
.
excludeRouters
.
split
(
"
,
"
);
const
excludeRouters
=
gatewayGroup
.
excludeRouters
.
split
(
"
,
"
);
const
includeRouters
=
gatewayGroup
.
includeRouters
.
split
(
"
,
"
);
const
includeRouters
=
gatewayGroup
.
includeRouters
.
split
(
"
,
"
);
...
@@ -194,11 +208,11 @@ class InventoryBuilder {
...
@@ -194,11 +208,11 @@ class InventoryBuilder {
}
}
return
false
;
return
false
;
}
}
getAddressesFromGatewayGroup
(
gatewayGroup
:
GatewayGroup
,
hosts
:
an
y
[])
{
getAddressesFromGatewayGroup
(
gatewayGroup
:
GatewayGroup
,
hosts
:
CommonEntr
y
[])
{
const
suitableHosts
=
hosts
.
filter
(
host
=>
this
.
isGatewayGroupContains
(
gatewayGroup
,
host
));
const
suitableHosts
=
hosts
.
filter
(
host
=>
this
.
isGatewayGroupContains
(
gatewayGroup
,
host
));
return
suitableHosts
.
map
(
host
=>
host
.
address
);
return
suitableHosts
.
map
(
host
=>
host
.
address
);
}
}
getRoutePlansFromGatewayGroups
(
host
:
an
y
)
{
getRoutePlansFromGatewayGroups
(
host
:
CommonEntr
y
)
{
const
allOtherHosts
=
Object
.
values
(
this
.
hosts
).
filter
(
h
=>
h
!==
host
.
name
)
const
allOtherHosts
=
Object
.
values
(
this
.
hosts
).
filter
(
h
=>
h
!==
host
.
name
)
const
routePlans
=
this
.
gatewayGroups
.
filter
(
group
=>
!
this
.
isGatewayGroupContains
(
group
,
host
)).
map
(
group
=>
{
const
routePlans
=
this
.
gatewayGroups
.
filter
(
group
=>
!
this
.
isGatewayGroupContains
(
group
,
host
)).
map
(
group
=>
{
const
addresses
=
this
.
getAddressesFromGatewayGroup
(
group
,
allOtherHosts
);
const
addresses
=
this
.
getAddressesFromGatewayGroup
(
group
,
allOtherHosts
);
...
@@ -212,7 +226,7 @@ class InventoryBuilder {
...
@@ -212,7 +226,7 @@ class InventoryBuilder {
return
routePlans
;
return
routePlans
;
}
}
getHostConnectionInfo
(
host
)
{
getHostConnectionInfo
(
host
:
CommonEntry
)
{
return
{
return
{
ansible_ssh_host
:
host
.
host
,
ansible_ssh_host
:
host
.
host
,
ansible_ssh_user
:
host
.
user
,
ansible_ssh_user
:
host
.
user
,
...
@@ -223,7 +237,7 @@ class InventoryBuilder {
...
@@ -223,7 +237,7 @@ class InventoryBuilder {
}
}
}
}
async
host_vars
(
host
)
{
async
host_vars
(
host
:
CommonEntry
)
{
const
connections
=
[];
const
connections
=
[];
host
.
dockerServices
=
{
host
.
dockerServices
=
{
version
:
'
2.4
'
,
version
:
'
2.4
'
,
...
@@ -248,6 +262,26 @@ class InventoryBuilder {
...
@@ -248,6 +262,26 @@ class InventoryBuilder {
volumes
:
[
'
./babeld.conf:/etc/babeld.conf:ro
'
]
volumes
:
[
'
./babeld.conf:/etc/babeld.conf:ro
'
]
};
};
}
}
const
gostConfig
:
GostConfig
=
{
Routes
:
Object
.
values
(
this
.
gateways
[
host
.
name
]).
filter
(
gateway
=>
!
gateway
.
hidden
).
map
(
gateway
=>
({
ServeNodes
:
[
`red://
${
host
.
address
}
:
${
gateway
.
redirectPort
}
`
],
Mark
:
gateway
.
selectionMark
as
number
,
}))
};
if
(
gostConfig
.
Routes
.
length
)
{
host
.
gostConfig
=
gostConfig
;
host
.
dockerServices
.
services
.
gost
=
{
restart
:
'
always
'
,
image
:
`git-registry.mycard.moe/nanahira/gost
${
this
.
getDockerImageTag
(
host
)}
`
,
network_mode
:
'
host
'
,
privileged
:
true
,
volumes
:
[
'
./gost.json:/etc/gost/gost.json:ro
'
],
command
:
'
-C /etc/gost/gost.json
'
};
}
host
.
frpcRestarts
=
[];
host
.
frpcRestarts
=
[];
host
.
ocRestarts
=
[];
host
.
ocRestarts
=
[];
host
.
frpsNeeded
=
false
;
host
.
frpsNeeded
=
false
;
...
@@ -290,8 +324,8 @@ class InventoryBuilder {
...
@@ -290,8 +324,8 @@ class InventoryBuilder {
});
});
}
}
}
}
return
{
return
{
//ansible_ssh_host: host.host,
//ansible_ssh_host: host.host,
...
@@ -319,6 +353,8 @@ class InventoryBuilder {
...
@@ -319,6 +353,8 @@ class InventoryBuilder {
dockerServices
:
host
.
dockerServices
,
dockerServices
:
host
.
dockerServices
,
routePlans
,
routePlans
,
iptables_type
:
host
.
iptables
||
'
auto
'
,
iptables_type
:
host
.
iptables
||
'
auto
'
,
gostConfig
,
installGost
:
!!
gostConfig
,
};
};
}
}
...
...
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