Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
N
nextgen-router
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
MyCard
nextgen-router
Commits
105c24a0
Commit
105c24a0
authored
Dec 02, 2023
by
nanahira
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
update for raspi
parent
cbdd7063
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
60 additions
and
7 deletions
+60
-7
files/bridge-post-scripts/post-up.sh.j2
files/bridge-post-scripts/post-up.sh.j2
+41
-2
install.yaml
install.yaml
+19
-5
No files found.
files/bridge-post-scripts/post-up.sh.j2
View file @
105c24a0
...
...
@@ -16,6 +16,43 @@ ip addr add {{address}} dev {{br.name}}
_change_mtu
-A
"
$BRIDGE_NAME
"
replace_ip
()
{
local
BRIDGE_IP
=
"
$1
"
local
INPUT
=
"
$2
"
# 检查 $INPUT 是否包含点
if
[[
"
$INPUT
"
==
*
.
*
]]
;
then
IFS
=
'.'
read
-r
-a
INPUT_PARTS
<<<
"
$INPUT
"
PART_COUNT
=
${#
INPUT_PARTS
[@]
}
# 如果有 4 个或以上的部分,那么这是一个完整的 IP 地址,直接返回
if
[[
$PART_COUNT
-ge
4
]]
;
then
echo
"
$INPUT
"
else
# 根据 PART_COUNT,补全 IP 地址
AWK_SCRIPT
=
'{print '
for
((
i
=
0
;
i <
$((
4
-
PART_COUNT
))
;
i++
))
;
do
AWK_SCRIPT
=
"
${
AWK_SCRIPT
}
\$
$((
i
+
1
))
"
if
[[
$i
-lt
3
]]
;
then
AWK_SCRIPT
=
"
${
AWK_SCRIPT
}
\"
.
\"
"
fi
done
AWK_SCRIPT
=
"
$AWK_SCRIPT
}"
IP_PREFIX
=
$(
echo
$BRIDGE_IP
|
awk
-F
'.'
"
$AWK_SCRIPT
"
)
RESULT_IP
=
"
${
IP_PREFIX
}${
INPUT
}
"
echo
"
$RESULT_IP
"
fi
elif
[[
$INPUT
=
~ ^[0-9]+
$
]]
;
then
# 如果 $INPUT 但是是纯数字,则替换最后一个数字
IP_PREFIX
=
$(
echo
$BRIDGE_IP
|
awk
-F
'.'
'{print $1"."$2"."$3"."}'
)
RESULT_IP
=
"
${
IP_PREFIX
}${
INPUT
}
"
echo
"
$RESULT_IP
"
else
# 如果 $INPUT 输入非法,直接返回输入内容
echo
"
$INPUT
"
fi
}
handle_gateway
()
{
GATEWAY_ID
=
$1
GATEWAY_ADDRESS
=
$2
...
...
@@ -25,11 +62,13 @@ handle_gateway() {
BRIDGE_IP
=
$(
ip
-4
addr show dev
"
$BRIDGE_NAME
"
|
grep
'inet '
|
awk
'{print $2}'
)
if
[[
"
$GATEWAY_ADDRESS
"
==
"_use_first"
]]
;
then
GATEWAY_ADDRESS
=
$(
subnetcalc
"
$BRIDGE_IP
"
-n
|
grep
"Host Range"
|
awk
'{print $5}'
)
fi
if
[[
"
$GATEWAY_ADDRESS
"
==
"_use_last"
]]
;
then
elif
[[
"
$GATEWAY_ADDRESS
"
==
"_use_last"
]]
;
then
GATEWAY_ADDRESS
=
$(
subnetcalc
"
$BRIDGE_IP
"
-n
|
grep
"Host Range"
|
awk
'{print $7}'
)
else
GATEWAY_ADDRESS
=
$(
replace_ip
"
$BRIDGE_IP
"
"
$GATEWAY_ADDRESS
"
)
fi
ip route replace default via
"
$GATEWAY_ADDRESS
"
dev
"
$BRIDGE_NAME
"
table
"
$GATEWAY_NEXT_HOP_MARK
"
{
%
if
br.type
!=
"dhcp"
%
}
ip route add default via
"
$GATEWAY_ADDRESS
"
dev
"
$BRIDGE_NAME
"
metric
"
$GATEWAY_NEXT_HOP_MARK
"
...
...
install.yaml
View file @
105c24a0
...
...
@@ -4,9 +4,12 @@
become
:
true
vars
:
kernel_modules
:
-
macvlan
-
bonding
-
8021q
-
name
:
macvlan
path
:
drivers/net/macvlan.ko
-
name
:
bonding
path
:
drivers/net/bonding/bonding.ko
-
name
:
8021q
path
:
net/8021q/8021q.ko
tasks
:
-
name
:
apt
apt
:
...
...
@@ -24,11 +27,22 @@
apt
:
name
:
vlan
when
:
not ansible_kernel.endswith("-pve")
# check file exists at /lib/modules/{{ansible_kernel}}/kernel/{{item.path}}, and if not, remove it from kernel_modules
-
name
:
filter existing kernel modules
stat
:
path
:
'
/lib/modules/{{ansible_kernel}}/kernel/{{item.path}}'
register
:
'
kernel_module_stat'
with_items
:
'
{{kernel_modules}}'
-
name
:
remove non-existing kernel modules
set_fact
:
kernel_modules
:
'
{{kernel_modules
|
rejectattr("name",
"equalto",
item.item.name)
|
list}}'
when
:
not item.stat.exists
with_items
:
'
{{kernel_module_stat.results}}'
-
name
:
modules file
copy
:
content
:
|
{% for module in kernel_modules %}
{{module}}
{{module
.name
}}
{% endfor %}
dest
:
/etc/modules-load.d/mycard-router-nextgen.conf
notify
:
load_modules
...
...
@@ -50,5 +64,5 @@
-
cturra/ntp
handlers
:
-
name
:
load_modules
shell
:
'
modprobe
{{item}}'
shell
:
'
modprobe
{{item
.name
}}'
with_items
:
'
{{kernel_modules}}'
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