2010-09-06 17:07:42 +02:00
|
|
|
#!/bin/bash
|
|
|
|
#============================================================================
|
|
|
|
# /etc/xen/vif-route-qubes
|
|
|
|
#
|
|
|
|
# Script for configuring a vif in routed mode.
|
|
|
|
# The hotplugging system will call this script if it is specified either in
|
|
|
|
# the device configuration given to Xend, or the default Xend configuration
|
|
|
|
# in /etc/xen/xend-config.sxp. If the script is specified in neither of those
|
|
|
|
# places, then vif-bridge is the default.
|
|
|
|
#
|
|
|
|
# Usage:
|
|
|
|
# vif-route (add|remove|online|offline)
|
|
|
|
#
|
|
|
|
# Environment vars:
|
|
|
|
# vif vif interface name (required).
|
|
|
|
# XENBUS_PATH path to this device's details in the XenStore (required).
|
|
|
|
#
|
|
|
|
# Read from the store:
|
|
|
|
# ip list of IP networks for the vif, space-separated (default given in
|
|
|
|
# this script).
|
|
|
|
#============================================================================
|
|
|
|
|
|
|
|
dir=$(dirname "$0")
|
|
|
|
. "$dir/vif-common.sh"
|
|
|
|
|
|
|
|
#main_ip=$(dom0_ip)
|
2015-07-01 01:25:00 +02:00
|
|
|
lockfile=/var/run/xen-hotplug/vif-lock
|
2010-09-06 17:07:42 +02:00
|
|
|
|
|
|
|
case "$command" in
|
|
|
|
online)
|
|
|
|
ifconfig ${vif} up
|
|
|
|
echo 1 >/proc/sys/net/ipv4/conf/${vif}/proxy_arp
|
2012-03-08 14:57:10 +01:00
|
|
|
ipcmd='add'
|
2012-03-03 01:30:04 +01:00
|
|
|
iptables_cmd='-I PREROUTING 1'
|
2010-09-06 17:07:42 +02:00
|
|
|
cmdprefix=''
|
|
|
|
;;
|
|
|
|
offline)
|
|
|
|
do_without_error ifdown ${vif}
|
|
|
|
ipcmd='del'
|
2012-03-03 01:30:04 +01:00
|
|
|
iptables_cmd='-D PREROUTING'
|
2010-09-06 17:07:42 +02:00
|
|
|
cmdprefix='do_without_error'
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
|
2012-03-08 14:57:10 +01:00
|
|
|
domid=${vif/vif/}
|
|
|
|
domid=${domid/.*/}
|
|
|
|
# metric must be possitive, but prefer later interface
|
|
|
|
# 32752 is max XID aka domid
|
|
|
|
metric=$[ 32752 - $domid ]
|
|
|
|
|
2010-09-06 17:07:42 +02:00
|
|
|
if [ "${ip}" ] ; then
|
|
|
|
# If we've been given a list of IP addresses, then add routes from dom0 to
|
|
|
|
# the guest using those addresses.
|
|
|
|
for addr in ${ip} ; do
|
2012-03-08 14:57:10 +01:00
|
|
|
${cmdprefix} ip route ${ipcmd} ${addr} dev ${vif} metric $metric
|
2010-09-06 17:07:42 +02:00
|
|
|
done
|
2015-06-27 04:55:56 +02:00
|
|
|
echo -e "*raw\n$iptables_cmd -i ${vif} ! -s ${ip} -j DROP\nCOMMIT" | \
|
2015-07-01 01:25:00 +02:00
|
|
|
${cmdprefix} flock $lockfile iptables-restore --noflush
|
2013-06-07 05:20:55 +02:00
|
|
|
back_ip=`qubesdb-read /qubes-netvm-gateway`
|
2012-05-31 02:03:55 +02:00
|
|
|
${cmdprefix} ip addr ${ipcmd} ${back_ip}/32 dev ${vif}
|
2010-09-06 17:07:42 +02:00
|
|
|
fi
|
|
|
|
|
|
|
|
log debug "Successful vif-route-qubes $command for $vif."
|
|
|
|
if [ "$command" = "online" ]
|
|
|
|
then
|
2015-07-01 04:52:37 +02:00
|
|
|
# disable tx checksumming offload, apparently it doesn't work with our ancient qemu in stubdom
|
|
|
|
do_without_error ethtool -K $vif tx off
|
2010-09-06 17:07:42 +02:00
|
|
|
success
|
|
|
|
fi
|