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
c0766b40
Commit
c0766b40
authored
Dec 29, 2020
by
nanahira
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'gwgroup'
parents
ce4c9b91
17364bd0
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
148 additions
and
72 deletions
+148
-72
ansible/bird.conf.bak.j2
ansible/bird.conf.bak.j2
+10
-7
ansible/configure.yaml
ansible/configure.yaml
+59
-53
ansible/install.yaml
ansible/install.yaml
+3
-3
ansible/route-plans.j2
ansible/route-plans.j2
+5
-0
ansible/scripts/global-postup.sh.j2
ansible/scripts/global-postup.sh.j2
+1
-1
src/inventory.ts
src/inventory.ts
+70
-8
No files found.
ansible/bird.conf.j2
→
ansible/bird.conf.
bak.
j2
View file @
c0766b40
...
...
@@ -9,19 +9,22 @@ protocol device {}
protocol kernel {
learn;
ipv4 {
import all;
import where net = 0.0.0.0/0;
export where net != 0.0.0.0/0;
};
#ipv6 { export all; };
}
{% for plan in routePlans %}
ipv4 table {{plan.name}};
protocol static {
ipv4 {
table {{plan.name}};
};
igp table master4;
route 0.0.0.0/0 recursive {{plan.address}};
{% if plan.addressesString %}
protocol pipe {
table master4;
peer table {{plan.name}};
export where ospf_router_id ~ {{plan.addressesString}};
}
{% endif %}
protocol kernel {
ipv4 {
table {{plan.name}};
...
...
ansible/configure.yaml
View file @
c0766b40
...
...
@@ -113,18 +113,24 @@
content
:
'
{{dockerServices
|
to_yaml}}'
dest
:
'
{{ansible_user_dir}}/nextgen-network/services/docker-compose.yml'
when
:
not noBird
-
name
:
bird conf
template
:
src
:
bird.conf.j2
dest
:
'
{{ansible_user_dir}}/nextgen-network/services/bird.conf'
notify
:
restart_bird
when
:
not noBird
#
- name: bird conf
#
template:
#
src: bird.conf.j2
#
dest: '{{ansible_user_dir}}/nextgen-network/services/bird.conf'
#
notify: restart_bird
#
when: not noBird
-
name
:
babeld conf
template
:
src
:
babeld.conf.j2
dest
:
'
{{ansible_user_dir}}/nextgen-network/services/babeld.conf'
#notify: restart_babeld
when
:
not noBird
-
name
:
monitor route plans
template
:
src
:
route-plans.j2
dest
:
'
{{ansible_user_dir}}/nextgen-network/services/route-plans'
notify
:
restart_monitor
when
:
not noBird
-
name
:
babeld reload conf
template
:
src
:
babeld-reload.conf.j2
...
...
@@ -142,56 +148,56 @@
remove_orphans
:
true
# pull: true
when
:
not noBird
-
name
:
systemd bird
become
:
true
template
:
src
:
bird.conf.j2
dest
:
'
/etc/bird/bird.conf'
notify
:
restart_bird_systemd
when
:
systemBird
-
name
:
enable systemd bird
become
:
true
systemd
:
name
:
bird
state
:
started
enabled
:
true
masked
:
false
when
:
systemBird
-
name
:
systemd babeld conf
become
:
true
template
:
src
:
babeld.conf.j2
dest
:
'
/etc/babeld.conf'
#notify: restart_babeld_systemd
when
:
systemBird
-
name
:
enable systemd babeld
become
:
true
systemd
:
name
:
babeld
state
:
started
enabled
:
true
masked
:
false
when
:
systemBird
#
- name: systemd bird
#
become: true
#
template:
#
src: bird.conf.j2
#
dest: '/etc/bird/bird.conf'
#
notify: restart_bird_systemd
#
when: systemBird
#
- name: enable systemd bird
#
become: true
#
systemd:
#
name: bird
#
state: started
#
enabled: true
#
masked: false
#
when: systemBird
#
- name: systemd babeld conf
#
become: true
#
template:
#
src: babeld.conf.j2
#
dest: '/etc/babeld.conf'
#
#notify: restart_babeld_systemd
#
when: systemBird
#
- name: enable systemd babeld
#
become: true
#
systemd:
#
name: babeld
#
state: started
#
enabled: true
#
masked: false
#
when: systemBird
handlers
:
-
name
:
reload_switch_rules
become
:
true
shell
:
'
{{ansible_user_dir}}/nextgen-network/scripts/switch-rules-down.sh
;
{{ansible_user_dir}}/nextgen-network/scripts/switch-rules-up.sh'
-
name
:
restart_b
ird
-
name
:
restart_b
abeld
# ocserv would be always restarted whenever key changes..
docker_compose
:
project_src
:
'
{{ansible_user_dir}}/nextgen-network/services'
restarted
:
true
services
:
-
b
ir
d
-
b
abel
d
when
:
not noBird
-
name
:
restart_babeld
# ocserv would be always restarted whenever key changes..
-
name
:
reload_babeld
shell
:
cat /tmp/babeld-reload.conf | timeout 1 nc ::1 33123 ||
true
-
name
:
restart_monitor
docker_compose
:
project_src
:
'
{{ansible_user_dir}}/nextgen-network/services'
restarted
:
true
services
:
-
babeld
-
gateways-monitor
when
:
not noBird
-
name
:
reload_babeld
shell
:
cat /tmp/babeld-reload.conf | timeout 1 nc ::1 33123 ||
true
-
name
:
restart_frps
docker_compose
:
project_src
:
'
{{ansible_user_dir}}/nextgen-network/services'
...
...
@@ -222,17 +228,17 @@
-
openconnect-{{item.name}}
with_items
:
'
{{connections}}'
when
:
'
item.protocol
==
"oc"
and
item.ocType
==
"client"
and
not
noBird
and
not
item.noUpdate'
-
name
:
restart_bird_systemd
become
:
true
systemd
:
name
:
bird
state
:
restarted
-
name
:
restart_babeld_systemd
become
:
true
systemd
:
name
:
babeld
state
:
restarted
when
:
systemBird
#
- name: restart_bird_systemd
#
become: true
#
systemd:
#
name: bird
#
state: restarted
#
- name: restart_babeld_systemd
#
become: true
#
systemd:
#
name: babeld
#
state: restarted
#
when: systemBird
-
name
:
reload_chnroute
become
:
true
shell
:
|
...
...
ansible/install.yaml
View file @
c0766b40
...
...
@@ -8,9 +8,9 @@
name
:
'
{{item}}'
source
:
pull
with_items
:
-
fatedier/frps:v0.34.2
-
fatedier/frpc:v0.34.2
-
git-registry.mycard.moe/
nanahira/docker-bird
#
- fatedier/frps:v0.34.2
#
- fatedier/frpc:v0.34.2
-
git-registry.mycard.moe/
railgun/gateways-monitor
-
git-registry.mycard.moe/railgun/babeld
-
git-registry.mycard.moe/nanahira/docker-ocserv
-
git-registry.mycard.moe/railgun/openconnect
...
...
ansible/route-plans.j2
0 → 100644
View file @
c0766b40
declare -A ROUTE_PLANS=(
{% for plan in routePlans %}
[{{plan.destMark}}]="{{plan.addressesString}}"
{% endfor %}
);
ansible/scripts/global-postup.sh.j2
View file @
c0766b40
#!/usr/bin/env bash
# Forced update 12.2
4
# Forced update 12.2
9
source
{{
ansible_user_dir
}}
/nextgen-network/scripts/utility.sh
echo
"running"
>
/tmp/mycard_global_postup_done
...
...
src/inventory.ts
View file @
c0766b40
...
...
@@ -3,7 +3,7 @@ import util from 'util';
import
fs
from
'
fs
'
;
import
path
from
'
path
'
;
import
YAML
from
'
yaml
'
;
import
_
from
'
lodash
'
;
import
_
,
{
add
}
from
'
lodash
'
;
import
child_process
from
'
child_process
'
;
import
assert
from
'
assert
'
;
import
{
promises
as
dns
}
from
'
dns
'
;
...
...
@@ -17,9 +17,20 @@ async function generateOcpasswdLine(username: string, password: string) {
return
res
;
}
interface
GatewayGroup
{
id
:
number
;
name
:
string
;
locationPrefix
:
string
;
includeRouters
:
string
;
excludeRouters
:
string
;
children
:
string
;
destMark
:
number
;
}
class
InventoryBuilder
{
hosts
:
{
[
key
:
string
]:
any
};
gateways
:
any
;
gatewayGroups
:
GatewayGroup
[];
connections
:
string
[];
routeLists
:
any
;
resolveCache
:
Map
<
string
,
string
>
;
...
...
@@ -81,6 +92,7 @@ class InventoryBuilder {
async
main
()
{
this
.
hosts
=
_
.
keyBy
(
await
this
.
load
(
'
nextgen2
'
),
'
name
'
);
this
.
gateways
=
_
.
mapValues
(
_
.
groupBy
(
await
this
.
loadGateways
(),
'
router
'
),
g
=>
_
.
keyBy
(
g
,
'
isp
'
));
this
.
gatewayGroups
=
await
this
.
load
(
'
gateway groups
'
);
//console.log(this.gateways);
this
.
connections
=
_
.
intersection
(
Object
.
keys
(
this
.
hosts
),
Object
.
keys
(
_
.
find
(
this
.
hosts
)));
...
...
@@ -140,6 +152,51 @@ class InventoryBuilder {
return
vars
;
}
getRoutePlanAddressesString
(
addresses
:
string
[])
{
if
(
!
addresses
.
length
)
{
return
null
;
}
return
addresses
.
join
(
"
"
);
}
isGatewayGroupContains
(
gatewayGroup
:
GatewayGroup
,
host
:
any
)
{
const
locationPrefixes
=
gatewayGroup
.
locationPrefix
.
split
(
"
,
"
);
const
excludeRouters
=
gatewayGroup
.
excludeRouters
.
split
(
"
,
"
);
const
includeRouters
=
gatewayGroup
.
includeRouters
.
split
(
"
,
"
);
const
children
=
gatewayGroup
.
children
.
split
(
"
,
"
);
if
(
excludeRouters
.
includes
(
host
.
name
))
{
return
false
;
}
if
(
locationPrefixes
.
some
(
prefix
=>
prefix
!==
""
&&
(
host
.
location
as
string
).
startsWith
(
prefix
))
||
includeRouters
.
includes
(
host
.
name
))
{
return
true
;
}
for
(
let
childName
of
children
)
{
const
targetGatewayGroup
=
this
.
gatewayGroups
.
find
(
g
=>
g
.
name
===
childName
);
if
(
!
targetGatewayGroup
)
{
continue
;
}
if
(
this
.
isGatewayGroupContains
(
targetGatewayGroup
,
host
))
{
return
true
;
}
}
return
false
;
}
getAddressesFromGatewayGroup
(
gatewayGroup
:
GatewayGroup
,
hosts
:
any
[])
{
const
suitableHosts
=
hosts
.
filter
(
host
=>
this
.
isGatewayGroupContains
(
gatewayGroup
,
host
));
return
suitableHosts
.
map
(
host
=>
host
.
address
);
}
getRoutePlansFromGatewayGroups
(
host
:
any
)
{
const
allOtherHosts
=
this
.
connections
.
filter
(
h
=>
h
!==
host
.
name
).
map
(
h
=>
this
.
hosts
[
h
]);
const
routePlans
=
this
.
gatewayGroups
.
filter
(
group
=>
!
this
.
isGatewayGroupContains
(
group
,
host
)).
map
(
group
=>
{
const
addresses
=
this
.
getAddressesFromGatewayGroup
(
group
,
allOtherHosts
);
return
{
name
:
group
.
name
.
replace
(
/-/g
,
"
_
"
),
destMark
:
group
.
destMark
,
addresses
,
addressesString
:
this
.
getRoutePlanAddressesString
(
addresses
)
}
}).
filter
(
plan
=>
plan
.
addresses
.
length
>
0
);
return
routePlans
;
}
getHostConnectionInfo
(
host
)
{
return
{
...
...
@@ -157,12 +214,13 @@ class InventoryBuilder {
host
.
dockerServices
=
{
version
:
'
2.4
'
,
services
:
{
bird
:
{
'
gateways-monitor
'
:
{
restart
:
'
always
'
,
image
:
'
git-registry.mycard.moe/
nanahira/docker-bird
'
,
image
:
'
git-registry.mycard.moe/
railgun/gateways-monitor
'
,
network_mode
:
'
host
'
,
cap_add
:
[
'
NET_ADMIN
'
],
volumes
:
[
'
./bird.conf:/etc/bird/bird.conf:ro
'
]
volumes
:
[
'
./route-plans:/usr/src/app/route-plans:ro
'
],
command
:
'
/usr/src/app/gateway-monitor.sh
'
},
babeld
:
{
restart
:
'
always
'
,
...
...
@@ -180,7 +238,7 @@ class InventoryBuilder {
const
localSubnets
=
host
.
subnets
;
//console.log(localSubnets);
const
masqInterfaces
=
host
.
masqInterfaces
.
length
>
0
?
host
.
masqInterfaces
.
split
(
'
,
'
)
:
[];
const
routePlans
=
[]
;
const
routePlans
=
this
.
getRoutePlansFromGatewayGroups
(
host
)
;
for
(
const
h
of
this
.
connections
)
{
if
(
h
!=
host
.
name
)
{
...
...
@@ -200,13 +258,17 @@ class InventoryBuilder {
connections
.
push
(
await
this
.
parse_connection
(
host
,
this
.
hosts
[
h
],
null_connection
,
true
,
false
,
false
));
connections
.
push
(
await
this
.
parse_connection
(
host
,
this
.
hosts
[
h
],
null_connection
,
false
,
true
,
false
));
}
const
targetHost
=
this
.
hosts
[
h
];
routePlans
.
push
({
name
:
h
.
replace
(
/-/g
,
'
_
'
),
destMark
:
this
.
hosts
[
h
].
destMark
,
address
:
this
.
hosts
[
h
].
address
name
:
h
.
replace
(
/-/g
,
"
_
"
),
destMark
:
targetHost
.
destMark
,
addresses
:
[
targetHost
.
address
],
addressesString
:
this
.
getRoutePlanAddressesString
([
targetHost
.
address
])
});
}
}
return
{
//ansible_ssh_host: host.host,
...
...
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