mirror of
https://github.com/xen-project/xen.git
synced 2026-10-28 10:11:27 +01:00
Many files:
Make interface to network/block scripts consistent:
- output on stdout is returned to the script caller
- output on stderr is logged at the error level, messages with a '-' prefix
are logged at the debug level and messages with a '*' prefix are logged
at the info level.
Signed-off-by: Christian Limpach <Christian.Limpach@cl.cam.ac.uk>
78 lines
1.5 KiB
Bash
78 lines
1.5 KiB
Bash
#!/bin/sh
|
|
#============================================================================
|
|
# Default Xen network start/stop script when using NAT.
|
|
# Xend calls a network script when it starts.
|
|
# The script name to use is defined in /etc/xen/xend-config.sxp
|
|
# in the network-script field.
|
|
#
|
|
# Usage:
|
|
#
|
|
# network-nat (start|stop|status) {VAR=VAL}*
|
|
#
|
|
# Vars:
|
|
#
|
|
# netdev The gateway interface (default eth0).
|
|
# antispoof Whether to use iptables to prevent spoofing (default no).
|
|
#
|
|
#============================================================================
|
|
|
|
|
|
|
|
# Exit if anything goes wrong.
|
|
set -e
|
|
|
|
# First arg is the operation.
|
|
OP=$1
|
|
shift
|
|
|
|
# Pull variables in args in to environment.
|
|
for arg ; do export "${arg}" ; done
|
|
|
|
netdev=${netdev:-eth0}
|
|
# antispoofing not yet implemented
|
|
antispoof=${antispoof:-no}
|
|
|
|
echo "*network-nat $OP netdev=$netdev antispoof=$antispoof" >&2
|
|
|
|
|
|
op_start() {
|
|
echo 1 >/proc/sys/net/ipv4/ip_forward
|
|
iptables -t nat -A POSTROUTING -o ${netdev} -j MASQUERADE
|
|
}
|
|
|
|
|
|
op_stop() {
|
|
iptables -t nat -D POSTROUTING -o ${netdev} -j MASQUERADE
|
|
}
|
|
|
|
|
|
show_status() {
|
|
echo '============================================================'
|
|
ifconfig
|
|
echo ' '
|
|
ip route list
|
|
echo ' '
|
|
route -n
|
|
echo '============================================================'
|
|
|
|
}
|
|
|
|
case ${OP} in
|
|
start)
|
|
op_start
|
|
;;
|
|
|
|
stop)
|
|
op_stop
|
|
;;
|
|
|
|
status)
|
|
show_status
|
|
;;
|
|
|
|
*)
|
|
echo 'Unknown command: ' ${OP} >&2
|
|
echo 'Valid commands are: start, stop, status' >&2
|
|
exit 1
|
|
esac
|