- if test -z "$NETDEVS"; then
- echo "$default: No network devices configured, switch disabled" >&2
- echo "Run ovs-switch-setup (in the openvswitch-switch-config package) or edit /etc/default/openvswitch-switch to configure" >&2
- exit 0
- fi
- if test "$MODE" = discovery; then
- unset CONTROLLER
- elif test "$MODE" = in-band || test "$MODE" = out-of-band; then
- if test -z "$CONTROLLER"; then
- echo "$default: No controller configured and not configured for discovery, switch disabled" >&2
- echo "Run ovs-switch-setup (in the openvswitch-switch-config package) or edit /etc/default/openvswitch-switch to configure" >&2
- exit 0
- fi
- else
- echo "$default: MODE must set to 'discovery', 'in-band', or 'out-of-band'" >&2
- echo "Run ovs-switch-setup (in the openvswitch-switch-config package) or edit /etc/default/openvswitch-switch to configure" >&2
- exit 1
- fi
- : ${PRIVKEY:=/etc/openvswitch-switch/of0-privkey.pem}
- : ${CERT:=/etc/openvswitch-switch/of0-cert.pem}
- : ${CACERT:=/etc/openvswitch-switch/cacert.pem}
- case $CONTROLLER in
- '')
- # Discovery mode.
- if test -e "$PRIVKEY"; then
- configure_ssl
- fi
- ;;
- tcp:*)
- ;;
- ssl:*)
- configure_ssl
- ;;
- *)
- echo "$default: CONTROLLER must be in the form 'ssl:IP[:PORT]' or 'tcp:IP[:PORT]' when not in discovery mode" >&2
- echo "Run ovs-switch-setup (in the openvswitch-switch-config package) or edit /etc/default/openvswitch-switch to configure" >&2
- exit 1
- esac
- case $DISCONNECTED_MODE in
- ''|switch|drop) ;;
- *) echo "$default: warning: DISCONNECTED_MODE is not 'switch' or 'drop'" >&2 ;;
- esac
-
- check_int_var RATE_LIMIT 100
- check_int_var INACTIVITY_PROBE 5
- check_int_var MAX_BACKOFF 1
-
- check_new_option --fail DISCONNECTED_MODE
- check_new_option --stp STP
- check_new_option --rate-limit RATE_LIMIT
- check_new_option --inactivity INACTIVITY_PROBE
- check_new_option --max-backoff MAX_BACKOFF
- case $DAEMON_OPTS in
- *--rate-limit*)
- echo "$default: --rate-limit may now be set with RATE_LIMIT" >&2
- esac
-
- echo -n "Loading openvswitch_mod: "
- if grep -q '^openvswitch_mod$' /proc/modules; then
- echo "already loaded, nothing to do."
- elif modprobe openvswitch_mod; then
- echo "success."
- else
- echo "ERROR."
- echo "openvswitch_mod has probably not been built for this kernel."
- if ! test -d /usr/share/doc/openvswitch-datapath-source; then
- echo "Install the openvswitch-datapath-source package, then read"
- echo "/usr/share/doc/openvswitch-datapath-source/README.Debian"
- else
- echo "For instructions, read"
- echo "/usr/share/doc/openvswitch-datapath-source/README.Debian"
- fi
- exit 1
- fi
-
- echo -n "Loading ip_gre_mod: "
- if grep -q '^ip_gre$' /proc/modules; then
- modprobe -r ip_gre
- fi
- if grep -q '^ip_gre_mod$' /proc/modules; then
- echo "already loaded, nothing to do."
- elif modprobe ip_gre_mod; then
- echo "success."
- else
- echo "could not find module."
- fi
-
- for netdev in $NETDEVS; do
- check_op "Removing IP address from $netdev" ifconfig $netdev 0.0.0.0
- done
-
- must_succeed "Creating datapath" ovs-dpctl add-dp of0 $NETDEVS
-
- xx='[0-9abcdefABCDEF][0-9abcdefABCDEF]'
- case $DATAPATH_ID in
- '')
- # Check if the DMI System UUID contains a Nicira mac address
- # that should be used for this datapath. The UUID is assumed
- # to be RFC 4122 compliant.
- DMIDECODE=`which dmidecode`
- if [ -n $DMIDECODE ]; then
- UUID_MAC=`$DMIDECODE -s system-uuid | cut -d'-' -f 5`
- case $UUID_MAC in
- $NICIRA_OUI*)
- ifconfig of0 down
- must_succeed "Setting of0 MAC address to $UUID_MAC" ifconfig of0 hw ether $UUID_MAC
- ifconfig of0 up
- ;;
- esac
- fi
- ;;
- $xx:$xx:$xx:$xx:$xx:$xx)
- ifconfig of0 down
- must_succeed "Setting of0 MAC address to $DATAPATH_ID" ifconfig of0 hw ether $DATAPATH_ID
- ifconfig of0 up
- ;;
- *)
- echo "DATAPATH_ID is not a valid MAC address in the form XX:XX:XX:XX:XX:XX, ignoring" >&2
- ;;
- esac
-
- if test "$MODE" = in-band; then
- if test "$SWITCH_IP" = dhcp; then
- must_succeed "Temporarily disabling of0" ifconfig of0 down
- else
- COMMAND="ifconfig of0 $SWITCH_IP"
- if test -n "$SWITCH_NETMASK"; then
- COMMAND="$COMMAND netmask $SWITCH_NETMASK"
- fi
- must_succeed "Configuring of0: $COMMAND" $COMMAND
- if test -n "$SWITCH_GATEWAY"; then
- # This can fail because the route already exists,
- # so we don't insist that it succeed.
- COMMAND="route add default gw $SWITCH_GATEWAY"
- check_op "Adding default route: $COMMAND" $COMMAND
- fi
- fi
- else
- must_succeed "Disabling of0" ifconfig of0 down
- fi
-
- if test -n "$CORE_LIMIT"; then
- check_op "Setting core limit to $CORE_LIMIT" ulimit -c "$CORE_LIMIT"
- fi
-
- # Compose ovs-openflowd options.
- set --
- set -- "$@" --verbose=ANY:console:emer --verbose=ANY:syslog:err
- set -- "$@" --log-file
- set -- "$@" --detach --pidfile=$PIDFILE
- for vconn in $MGMT_VCONNS; do
- set -- "$@" --listen="$vconn"
- done
- if test -n "$COMMANDS"; then
- set -- "$@" --command-acl="$COMMANDS"
- fi
- case $STP in
- yes) set -- "$@" --stp ;;
- no) set -- "$@" --no-stp ;;
- esac
- case $DISCONNECTED_MODE in
- switch) set -- "$@" --fail=open ;;
- drop) set -- "$@" --fail=closed ;;
- esac
- if test -n "$RATE_LIMIT"; then
- set -- "$@" --rate-limit=$RATE_LIMIT
- fi
- if test -n "$INACTIVITY_PROBE"; then
- set -- "$@" --inactivity-probe=$INACTIVITY_PROBE
- fi
- if test -n "$MAX_BACKOFF"; then
- set -- "$@" --max-backoff=$MAX_BACKOFF
- fi
- set -- "$@" $SSL_OPTS $DAEMON_OPTS
- if test "$MODE" = out-of-band; then
- set -- "$@" --out-of-band
- fi
- set -- "$@" of0 "$CONTROLLER"
- echo -n "Starting $DESC: "
- start-stop-daemon --start --quiet --pidfile $PIDFILE \
- --exec $DAEMON -- "$@"
- if running; then
- echo "$NAME."
- else
- echo " ERROR."
- fi
-
- if test "$MODE" = in-band && test "$SWITCH_IP" = dhcp; then
- echo -n "Starting dhclient on of0: "
- start-stop-daemon --start --quiet --pidfile $DHCLIENT_PIDFILE \
- --exec /sbin/dhclient -- -q -pf $DHCLIENT_PIDFILE of0
- if running; then
- echo "dhclient."
- else
- echo " ERROR."
- fi
- fi
- ;;
- stop)
- if test -e /var/run/dhclient.of0.pid; then
- echo -n "Stopping dhclient on of0: "
- start-stop-daemon --stop --quiet --oknodo \
- --pidfile $DHCLIENT_PIDFILE --exec /sbin/dhclient
- echo "dhclient."
- fi
-
- echo -n "Stopping $DESC: "
- start-stop-daemon --stop --quiet --oknodo --pidfile $PIDFILE \
- --exec $DAEMON
- echo "$NAME."
-
- check_op "Deleting datapath" ovs-dpctl del-dp of0
- echo -n "Unloading ip_gre module: "
- if modprobe -r ip_gre_mod; then
- echo "success."
- fi
- check_op "Unloading kernel module" modprobe -r openvswitch_mod
- ;;
- force-stop)
- echo -n "Forcefully stopping $DESC: "
- force_stop
- if ! running; then
- echo "$NAME."
- else
- echo " ERROR."
- fi