Commit e56f0043 authored by nanahira's avatar nanahira

fix mac

parent 0c3d28ac
......@@ -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 %}
......
......@@ -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 %}
......
......@@ -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"
}
......@@ -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
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment