Commit f5c47f8e authored by nanahira's avatar nanahira

add selection mark

parent 86648fd5
......@@ -25,7 +25,8 @@ handle_gateway() {
GATEWAY_ADDRESS=$2
GATEWAY_MAC=$3
GATEWAY_NO_ORIGIN=$4
GATEWAY_NEXT_HOP_MARK=$[$GATEWAY_ID + 1100]
GATEWAY_NEXT_HOP_MARK=$((GATEWAY_ID + 1100))
GATEWAY_SELECTION_MARK=$((GATEWAY_NEXT_HOP_MARK + 50))
BRIDGE_IP=$(ip -4 addr show dev "$BRIDGE_NAME" | grep 'inet ' | awk '{print $2}')
if [[ "$GATEWAY_ADDRESS" -eq "_use_first" ]]; then
GATEWAY_ADDRESS=$(subnetcalc "$BRIDGE_IP" -n | grep "Host Range" | awk '{print $5}')
......@@ -39,8 +40,9 @@ handle_gateway() {
ip route add default via "$GATEWAY_ADDRESS" metric "$GATEWAY_NEXT_HOP_MARK"
{% endif %}
ip rule add pref 100 fwmark "$GATEWAY_NEXT_HOP_MARK" lookup "$GATEWAY_NEXT_HOP_MARK"
ip rule add pref 400 fwmark "$GATEWAY_SELECTION_MARK" lookup "$GATEWAY_NEXT_HOP_MARK"
if [[ "$GATEWAY_NO_ORIGIN" -eq 0 ]]; then
ip rule add pref 100 fwmark "$GATEWAY_NEXT_HOP_MARK" lookup "$GATEWAY_NEXT_HOP_MARK"
eth_origin -A "$BRIDGE_NAME" "$GATEWAY_ID" "$GATEWAY_ADDRESS" "$GATEWAY_MAC"
fi
}
......
......@@ -17,7 +17,8 @@ handle_gateway() {
GATEWAY_ADDRESS=$2
GATEWAY_MAC=$3
GATEWAY_NO_ORIGIN=$4
GATEWAY_NEXT_HOP_MARK=$[$GATEWAY_ID + 1100]
GATEWAY_NEXT_HOP_MARK=$((GATEWAY_ID + 1100))
GATEWAY_SELECTION_MARK=$((GATEWAY_NEXT_HOP_MARK + 50))
BRIDGE_IP=$(ip -4 addr show dev "$BRIDGE_NAME" | grep 'inet ' | awk '{print $2}')
if [[ "$GATEWAY_ADDRESS" -eq "_use_first" ]]; then
GATEWAY_ADDRESS=$(subnetcalc "$BRIDGE_IP" -n | grep "Host Range" | awk '{print $5}')
......@@ -26,8 +27,9 @@ handle_gateway() {
GATEWAY_ADDRESS=$(subnetcalc "$BRIDGE_IP" -n | grep "Host Range" | awk '{print $7}')
fi
ip rule del pref 100 fwmark "$GATEWAY_NEXT_HOP_MARK" lookup "$GATEWAY_NEXT_HOP_MARK"
ip rule add pref 400 fwmark "$GATEWAY_SELECTION_MARK" lookup "$GATEWAY_NEXT_HOP_MARK"
if [[ "$GATEWAY_NO_ORIGIN" -eq 0 ]]; then
ip rule del pref 100 fwmark "$GATEWAY_NEXT_HOP_MARK" lookup "$GATEWAY_NEXT_HOP_MARK"
eth_origin -D "$BRIDGE_NAME" "$GATEWAY_ID" "$GATEWAY_ADDRESS" "$GATEWAY_MAC"
fi
}
......
#!/bin/bash
source {{ansible_user_dir}}/nextgen-router/scripts/utility.sh
INIT_ID=$[1000 + $(echo "$PPP_IFACE" | sed "s/ppp//g")]
PPPOE_NEXT_HOP_MARK=$[1000 + $(echo "$PPP_IFACE" | sed "s/ppp//g")]
PPPOE_SELECTION_MARK=$((PPPOE_NEXT_HOP_MARK + 50))
iptables-save | grep -- '-j TCPMSS' | grep -- "$PPP_IFACE" | sed 's/^-A/-D/g' | xargs -I '{}' bash -c 'iptables -t mangle {}'
ip6tables-save | grep -- '-j TCPMSS' | grep -- "$PPP_IFACE" | sed 's/^-A/-D/g' | xargs -I '{}' bash -c 'ip6tables -t mangle {}'
iptables -t nat -o "$PPP_IFACE" -D POSTROUTING -j MASQUERADE
ip rule del pref 100 fwmark $INIT_ID lookup $INIT_ID
ip -6 rule del pref 100 fwmark $INIT_ID lookup $INIT_ID
ip rule del pref 100 fwmark $PPPOE_NEXT_HOP_MARK lookup $PPPOE_NEXT_HOP_MARK
ip rule del pref 400 fwmark $PPPOE_SELECTION_MARK lookup $PPPOE_NEXT_HOP_MARK
ip -6 rule del pref 100 fwmark $PPPOE_NEXT_HOP_MARK lookup $PPPOE_NEXT_HOP_MARK
ppp_origin -D "$PPP_IFACE"
......
#!/bin/bash
source {{ansible_user_dir}}/nextgen-router/scripts/utility.sh
INIT_ID=$[1000 + $(echo "$PPP_IFACE" | sed "s/ppp//g")]
PPPOE_NEXT_HOP_MARK=$[1000 + $(echo "$PPP_IFACE" | sed "s/ppp//g")]
PPPOE_SELECTION_MARK=$((PPPOE_NEXT_HOP_MARK + 50))
INTERFACE_MTU=$(ip link show dev "$PPP_IFACE" | grep -oP 'mtu \d+' | cut -c 5-)
......@@ -15,15 +16,16 @@ ip6tables -t mangle -A FORWARD -i "$PPP_IFACE" -p tcp -m tcp --tcp-flags SYN,RST
iptables -t nat -o "$PPP_IFACE" -A POSTROUTING -j MASQUERADE
ip route add default dev "$PPP_IFACE" table $INIT_ID
ip route add default dev "$PPP_IFACE" metric $INIT_ID
ip rule add pref 100 fwmark $INIT_ID lookup $INIT_ID
ip route add default dev "$PPP_IFACE" table $PPPOE_NEXT_HOP_MARK
ip route add default dev "$PPP_IFACE" metric $PPPOE_NEXT_HOP_MARK
ip rule add pref 100 fwmark $PPPOE_NEXT_HOP_MARK lookup $PPPOE_NEXT_HOP_MARK
ip rule add pref 400 fwmark $PPPOE_SELECTION_MARK lookup $PPPOE_NEXT_HOP_MARK
ip -6 addr show dev "$PPP_IFACE" | grep "inet6"
if [[ "$?" == 0 ]]; then
ip -6 route add default dev "$PPP_IFACE" table $INIT_ID
ip -6 route add default dev "$PPP_IFACE" metric $INIT_ID
ip -6 rule add pref 100 fwmark $INIT_ID lookup $INIT_ID
ip -6 route add default dev "$PPP_IFACE" table $PPPOE_NEXT_HOP_MARK
ip -6 route add default dev "$PPP_IFACE" metric $PPPOE_NEXT_HOP_MARK
ip -6 rule add pref 100 fwmark $PPPOE_NEXT_HOP_MARK lookup $PPPOE_NEXT_HOP_MARK
cd {{ansible_user_dir}}/nextgen-router/services/dhcpv6
{% for br in bridges %}
......
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