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
e56f0043
Commit
e56f0043
authored
Dec 10, 2020
by
nanahira
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix mac
parent
0c3d28ac
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
17 additions
and
11 deletions
+17
-11
files/bridge-post-scripts/post-up.sh.j2
files/bridge-post-scripts/post-up.sh.j2
+3
-2
files/bridge-post-scripts/pre-down.sh.j2
files/bridge-post-scripts/pre-down.sh.j2
+3
-2
files/utility.sh.j2
files/utility.sh.j2
+10
-7
variables.yaml
variables.yaml
+1
-0
No files found.
files/bridge-post-scripts/post-up.sh.j2
View file @
e56f0043
...
...
@@ -23,17 +23,18 @@ ip addr add {{address}} dev {{br.name}}
handle_gateway
()
{
GATEWAY_ID
=
$1
GATEWAY_ADDRESS
=
$2
GATEWAY_MAC
=
$3
GATEWAY_NEXT_HOP_MARK
=
$[$GATEWAY_ID
+ 1100]
ip route add default via
"
$GATEWAY_ADDRESS
"
table
"
$GATEWAY_NEXT_HOP_MARK
"
ip route add default via
"
$GATEWAY_ADDRESS
"
metric
"
$GATEWAY_NEXT_HOP_MARK
"
ip rule add pref 100 fwmark
"
$GATEWAY_NEXT_HOP_MARK
"
lookup
"
$GATEWAY_NEXT_HOP_MARK
"
eth_origin
-A
"
$
GATEWAY_ADDRESS
"
"
$GATEWAY_ID
"
eth_origin
-A
"
$
BRIDGE_NAME
"
$GATEWAY_ID
" "
$GATEWAY_ADDRESS
" ""
$GATEWAY_MAC
"
}
{
%
if
br.gateways %
}
# Gateways
{
%
for
gateway
in
br.gateways %
}
handle_gateway
{{
gateway.id
}}
{{
gateway.address
}}
handle_gateway
{{
gateway.id
}}
{{
gateway.address
}}
{
%
if
gateway.mac %
}
{{
gateway.mac
}}
{
% endif %
}
{
% endfor %
}
{
% endif %
}
...
...
files/bridge-post-scripts/pre-down.sh.j2
View file @
e56f0043
...
...
@@ -15,15 +15,16 @@ export BRIDGE_MAC={{br.mac}}
handle_gateway
()
{
GATEWAY_ID
=
$1
GATEWAY_ADDRESS
=
$2
GATEWAY_MAC
=
$3
GATEWAY_NEXT_HOP_MARK
=
$[$GATEWAY_ID
+ 1100]
ip rule del pref 100 fwmark
"
$GATEWAY_NEXT_HOP_MARK
"
lookup
"
$GATEWAY_NEXT_HOP_MARK
"
eth_origin
-
D
"
$GATEWAY_ADDRESS
"
"
$GATEWAY_ID
"
eth_origin
-
A
"
$BRIDGE_NAME
"
$GATEWAY_ID
" "
$GATEWAY_ADDRESS
" ""
$GATEWAY_MAC
"
}
{
%
if
br.gateways %
}
# Gateways
{
%
for
gateway
in
br.gateways %
}
handle_gateway
{{
gateway.id
}}
{{
gateway.address
}}
handle_gateway
{{
gateway.id
}}
{{
gateway.address
}}
{
%
if
gateway.mac %
}
{{
gateway.mac
}}
{
% endif %
}
{
% endfor %
}
{
% endif %
}
...
...
files/utility.sh.j2
View file @
e56f0043
...
...
@@ -31,14 +31,17 @@ initialize_ipset() {
eth_origin() {
initialize_ipset
OPTION=$1
GATEWAY_ADDRESS
=$2
BRIDGE_NAME
=$2
GATEWAY_ID=$3
ping "$GATEWAY_ADDRESS" -c 1
NEIGH_LINE=$(ip neigh show "$GATEWAY_ADDRESS")
DEV=$(echo $NEIGH_LINE | awk '{print $3}')
MAC=$(echo $NEIGH_LINE | awk '{print $5}')
GATEWAY_ADDRESS=$4
GATEWAY_MAC=$5
MARK=$[1100 + $GATEWAY_ID]
iptables -t mangle "$OPTION" PREROUTING ! -p ospf -i "$DEV" -m mac --mac-source "$MAC" -m set ! --match-set localnet src -j CONNMARK --set-xmark "$MARK"
# ip6tables -t mangle "$OPTION" PREROUTING ! -p ospf -i "$DEV" -m mac --mac-source "$MAC" -m set ! --match-set localnet src -j CONNMARK --set-xmark "$MARK"
if [[ -z "$GATEWAY_MAC" ]]; then
ping "$GATEWAY_ADDRESS" -c 1
NEIGH_LINE=$(ip neigh show "$GATEWAY_ADDRESS")
GATEWAY_MAC=$(echo $NEIGH_LINE | awk '{print $5}')
fi
iptables -t mangle "$OPTION" PREROUTING ! -p ospf -i "$BRIDGE_NAME" -m mac --mac-source "$GATEWAY_MAC" -m set ! --match-set localnet src -j CONNMARK --set-xmark "$MARK"
# ip6tables -t mangle "$OPTION" PREROUTING ! -p ospf -i "$BRIDGE_NAME" -m mac --mac-source "$GATEWAY_MAC" -m set ! --match-set localnet src -j CONNMARK --set-xmark "$MARK"
restore_mark "$OPTION" "$MARK"
}
variables.yaml
View file @
e56f0043
...
...
@@ -47,6 +47,7 @@ vars:
gateways
:
# 网关定义,DHCP关闭自动获取网关,需要手写地址。
-
id
:
0
# 网关ID,关乎mark和table
address
:
10.198.21.1
# 网关地址
mac
:
null
# 网关mac地址,为null则自动ping获取,但是bridge有启动坑容易获取失败
up
:
null
down
:
null
mac
:
null
...
...
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