# See the License for the specific language governing permissions and
# limitations under the License.
+case $0 in
+ */*) dir0=`echo "$0" | sed 's,/[^/]*$,,'` ;;
+ *) dir0=./ ;;
+esac
+. "$dir0/ovs-lib" || exit 1
+
usage() {
UTIL=$(basename $0)
cat <<EOF
network interfaces, as well as the system iptables
configuration.
save-flows Outputs a shell script on stdout that will restore
- Openflow flows of each Open vSwitch bridge.
+ OpenFlow flows of each Open vSwitch bridge.
save-ofports Outputs a shell script on stdout that will restore
the ofport value across a force-reload-kmod.
This script is meant as a helper for the Open vSwitch init script commands.
EOF
}
-PATH=/sbin:/bin:/usr/sbin:/usr/bin
-
-missing_program () {
- save_IFS=$IFS
- IFS=:
- for dir in $PATH; do
- IFS=$save_IFS
- if test -x $dir/$1; then
- return 1
- fi
- done
- IFS=$save_IFS
- return 0
-}
-
save_interfaces () {
- if missing_program ip; then
+ if (ip -V) > /dev/null 2>&1; then :; else
echo "$0: ip not found in $PATH" >&2
exit 1
fi
echo ip link set dev $dev $linkcmd
fi
- # IP addresses (including IPv6).
- echo "ip addr flush dev $dev 2>/dev/null" # Suppresses "Nothing to flush".
- ip addr show dev $dev | while read addr; do
- set -- $addr
+ move_ip_address $dev $dev
- # Check and trim family.
- family=$1
- shift
- case $family in
- inet | inet6) ;;
- *) continue ;;
- esac
-
- # Trim device off the end--"ip" insists on having "dev" precede it.
- addrcmd=
- while test $# != 0; do
- case $1 in
- dynamic)
- # Omit kernel-maintained route.
- continue 2
- ;;
- scope)
- if test "$2" = link; then
- # Omit route derived from IP address, e.g.
- # 172.16.0.0/16 derived from 172.16.12.34.
- continue 2
- fi
- ;;
- "$dev"|"$dev:"*)
- # Address label string
- addrcmd="$addrcmd label $1"
- shift
- continue
- ;;
- esac
- addrcmd="$addrcmd $1"
- shift
- done
- if test "$1" != "$dev"; then
- addrcmd="$addrcmd $1"
- fi
-
- echo ip -f $family addr add $addrcmd dev $dev
- done
-
- # Routes.
- echo "ip route flush dev $dev proto boot 2>/dev/null" # Suppresses "Nothing to flush".
- ip route show dev $dev | while read route; do
- # "proto kernel" routes are installed by the kernel automatically.
- case $route in
- *" proto kernel "*) continue ;;
- esac
-
- echo "ip route add $route dev $dev"
- done
+ move_ip_routes $dev $dev
echo
done
- if missing_program iptables-save; then
- echo "# iptables-save not found in $PATH, not saving iptables state"
- else
+ if (iptables-save) > /dev/null 2>&1; then
echo "# global"
echo "iptables-restore <<'EOF'"
iptables-save
echo "EOF"
+ else
+ echo "# iptables-save not found in $PATH, not saving iptables state"
fi
}
save_flows () {
- if missing_program ovs-ofctl; then
+ if (ovs-ofctl --version) > /dev/null 2>&1; then :; else
echo "$0: ovs-ofctl not found in $PATH" >&2
exit 1
fi
save_ofports ()
{
- if missing_program ovs-vsctl; then
+ if (ovs-vsctl --version) > /dev/null 2>&1; then :; else
echo "$0: ovs-vsctl not found in $PATH" >&2
exit 1
fi