mirror of
https://github.com/apache/cloudstack.git
synced 2025-11-03 04:12:31 +01:00
Previously, the ethernet device index was used as rt_table index and packet marking id/integer. With eth0 that is sometimes used as link-local interface, the rt_table index `0` would fail as `0` is already defined as a catchall (unspecified). The fwmarking on packets on eth0 with 0x0 would also fail. This fixes the routing issues, by adding 100 to the ethernet device index so the value is a non-zero, for example then the relationship between rt_table index and ethernet would be like: 100 -> Table_eth0 -> eth0 -> fwmark 100 or 0x64 101 -> Table_eth1 -> eth1 -> fwmark 101 or 0x65 102 -> Table_eth2 -> eth2 -> fwmark 102 or 0x66 This would maintain the legacy design of routing based on packet mark and appropriate routing table rules per table/ids. This also fixes a minor NPE issue around listing of snapshots. This also backports fixes to smoketests from master. Signed-off-by: Rohit Yadav <rohit.yadav@shapeblue.com>
81 lines
2.6 KiB
Bash
Executable File
81 lines
2.6 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
# Licensed to the Apache Software Foundation (ASF) under one
|
|
# or more contributor license agreements. See the NOTICE file
|
|
# distributed with this work for additional information
|
|
# regarding copyright ownership. The ASF licenses this file
|
|
# to you under the Apache License, Version 2.0 (the
|
|
# "License"); you may not use this file except in compliance
|
|
# with the License. You may obtain a copy of the License at
|
|
#
|
|
# http://www.apache.org/licenses/LICENSE-2.0
|
|
#
|
|
# Unless required by applicable law or agreed to in writing,
|
|
# software distributed under the License is distributed on an
|
|
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
|
# KIND, either express or implied. See the License for the
|
|
# specific language governing permissions and limitations
|
|
# under the License.
|
|
|
|
plug_nic() {
|
|
sudo echo "$tableNo $tableName" >> /etc/iproute2/rt_tables 2>/dev/null
|
|
sudo ip rule add fwmark $tableNo table $tableName 2>/dev/null
|
|
sudo ip route flush table $tableName
|
|
sudo ip route flush cache
|
|
}
|
|
|
|
|
|
unplug_nic() {
|
|
sudo iptables -t mangle -D PREROUTING -i $dev -m state --state NEW -j CONNMARK --set-mark $tableNo 2>/dev/null
|
|
|
|
sudo ip rule del fwmark $tableNo 2>/dev/null
|
|
sudo ip route flush table $tableName
|
|
sudo sed -i /"$tableNo $tableName"/d /etc/iproute2/rt_tables 2>/dev/null
|
|
sudo ip route flush cache
|
|
# remove network usage rules
|
|
sudo iptables -F NETWORK_STATS_$dev 2>/dev/null
|
|
iptables-save | grep NETWORK_STATS_$dev | grep "\-A" | while read rule
|
|
do
|
|
rule=$(echo $rule | sed 's/\-A/\-D/')
|
|
sudo iptables $rule
|
|
done
|
|
sudo iptables -X NETWORK_STATS_$dev 2>/dev/null
|
|
# remove vpn network usage rules
|
|
sudo iptables -t mangle -F VPN_STATS_$dev 2>/dev/null
|
|
iptables-save -t mangle | grep VPN_STATS_$dev | grep "\-A" | while read rule
|
|
do
|
|
rule=$(echo $rule | sed 's/\-A/\-D/')
|
|
sudo iptables -t mangle $rule
|
|
done
|
|
sudo iptables -t mangle -X VPN_STATS_$dev 2>/dev/null
|
|
# remove rules on this dev
|
|
iptables-save -t mangle | grep $dev | grep "\-A" | while read rule
|
|
do
|
|
rule=$(echo $rule | sed 's/\-A/\-D/')
|
|
sudo iptables -t mangle $rule
|
|
done
|
|
iptables-save -t nat | grep $dev | grep "\-A" | while read rule
|
|
do
|
|
rule=$(echo $rule | sed 's/\-A/\-D/')
|
|
sudo iptables -t nat $rule
|
|
done
|
|
iptables-save | grep $dev | grep "\-A" | while read rule
|
|
do
|
|
rule=$(echo $rule | sed 's/\-A/\-D/')
|
|
sudo iptables $rule
|
|
done
|
|
# remove apache config for this eth
|
|
rm -f /etc/apache2/conf.d/vhost$dev.conf
|
|
}
|
|
|
|
action=$1
|
|
dev=$2
|
|
tableNo=$((100+${dev:3}))
|
|
tableName="Table_$dev"
|
|
|
|
if [ $action == 'add' ]
|
|
then
|
|
plug_nic
|
|
else
|
|
unplug_nic
|
|
fi
|