diff --git a/patches/systemvm/debian/config/etc/cloud-nic.rules b/patches/systemvm/debian/config/etc/cloud-nic.rules new file mode 100644 index 00000000000..56e74ec4e9d --- /dev/null +++ b/patches/systemvm/debian/config/etc/cloud-nic.rules @@ -0,0 +1,2 @@ +SUBSYSTEM=="net" KERNEL=="eth*" RUN+="/opt/cloud/bin/cloud-nic.sh $env{ACTION} %k" + diff --git a/patches/systemvm/debian/config/etc/init.d/cloud-early-config b/patches/systemvm/debian/config/etc/init.d/cloud-early-config index 210a06669b4..d46a1e733e8 100755 --- a/patches/systemvm/debian/config/etc/init.d/cloud-early-config +++ b/patches/systemvm/debian/config/etc/init.d/cloud-early-config @@ -616,8 +616,9 @@ EOF chkconfig nfs-common off cp /etc/iptables/iptables-vpcrouter /etc/iptables/rules cp /etc/vpcdnsmasq.conf /etc/dnsmasq.conf + cp /etc/cloud-nic.rules /etc/udev/rules.d/cloud-nic.rules echo "" > /etc/dnsmasq.d/dhcphosts.txt - echo "dhcp-hostsfile=/etc/dnsmasq.d/dhcphosts.txt" > /etc/dnsmasq.d/cloud.conf + echo "dhcp-hostsfile=/etc/dhcphosts.txt" > /etc/dnsmasq.d/cloud.conf } diff --git a/patches/systemvm/debian/config/opt/cloud/bin/cloud-nic.sh b/patches/systemvm/debian/config/opt/cloud/bin/cloud-nic.sh new file mode 100755 index 00000000000..1f1e52e08a5 --- /dev/null +++ b/patches/systemvm/debian/config/opt/cloud/bin/cloud-nic.sh @@ -0,0 +1,35 @@ +#!/usr/bin/env bash + + +plug_nic() { + sudo iptables -t mangle -A PREROUTING -i $dev -m state --state NEW -j MARK --set-mark $tableNo 2>/dev/null + sudo iptables -t mangle -A PREROUTING -i $dev -m state --state NEW -j CONNMARK --save-mark 2>/dev/null + + 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 MARK --set-mark $tableNo 2>/dev/null + sudo iptables -t mangle -D PREROUTING -i $dev -m state --state NEW -j CONNMARK --save-mark 2>/dev/null + + sudo sed -i '/"$tableNo $tableName"/d' /etc/iproute2/rt_tables 2>/dev/null + sudo ip rule delete fwmark $tableNo table $tableName 2>/dev/null + sudo ip route flush table $tableName + sudo ip route flush cache +} + +action=$1 +dev=$2 +tableNo=$(echo $dev | awk -F'eth' '{print $2}') +tableName="Table_$dev" + +if [ $action == 'add' ] +then + plug_nic +else + unplug_nic +fi