2 # SPDX-License-Identifier: Apache-2.0
3 # Copyright (C) 2018 Red Hat, Inc.
5 # Licensed under the Apache License, Version 2.0 (the "License");
6 # you may not use this file except in compliance with the License.
7 # You may obtain a copy of the License at:
9 # http://www.apache.org/licenses/LICENSE-2.0
11 # Unless required by applicable law or agreed to in writing, software
12 # distributed under the License is distributed on an "AS IS" BASIS,
13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 # See the License for the specific language governing permissions and
15 # limitations under the License.
18 */*) dir0
=`echo "$0" | sed 's,/[^/]*$,,'` ;;
21 .
"$dir0/ovs-lib" ||
exit 1
23 for dir
in "$sbindir" "$bindir" /sbin
/bin
/usr
/sbin
/usr
/bin
; do
31 # Try loading openvswitch kernel module.
32 action
"Inserting openvswitch module" modprobe openvswitch
35 insert_kmods_if_required
() {
36 # If this kernel has no module support, expect we're done.
37 if test ! -e /proc
/modules
39 log_success_msg
"Kernel has no loadable module support. Skipping modprobe"
43 # If openvswitch is already loaded then we're done.
44 test -e /sys
/module
/openvswitch
&& return 0
46 # Load openvswitch. If that's successful then we're done.
47 insert_mods
&& return 0
49 # If the bridge module is loaded, then that might be blocking
50 # openvswitch. Try to unload it, if there are no bridges.
51 test -e /sys
/module
/bridge ||
return 1
52 bridges
=`echo /sys/class/net/*/bridge | sed 's,/sys/class/net/,,g;s,/bridge,,g'`
53 if test "$bridges" != "*"; then
54 log_warning_msg
"not removing bridge module because bridges exist ($bridges)"
57 action
"removing bridge module" rmmod bridge ||
return 1
59 # Try loading openvswitch again.
64 for vport
in `awk '/^vport_/ { print $1 }' /proc/modules`; do
65 action
"Removing $vport module" rmmod
$vport
68 if test -e /sys
/module
/ip_gre
; then
69 action
"Forcing removal of ip_gre module" rmmod ip_gre
72 if test -e /sys
/module
/gre
; then
73 action
"Forcing removal of gre module" rmmod gre
76 if test -e /sys
/module
/openvswitch
; then
77 action
"Removing openvswitch module" rmmod openvswitch
80 # Older releases may be using the rtnetlink interface while a
81 # newer release will want to use the internal compat interface
82 # for geneve and vxlan.
83 if test -e /sys
/class
/net
/genev_sys_6081
; then
84 action
"Removing geneve device" \
85 ip link del link genev_sys_6081 dev genev_sys_6081
87 if test -e /sys
/class
/net
/vxlan_sys_4789
; then
88 action
"Removing vxlan device" \
89 ip link del link vxlan_sys_4789 dev vxlan_sys_4789
92 if test -e /sys
/module
/geneve
; then
93 action
"Forcing removal of geneve module" rmmod geneve
95 if test -e /sys
/module
/vxlan
; then
96 action
"Forcing removal of vxlan module" rmmod vxlan
102 $0: controls Open vSwitch kernel modules
103 usage: $0 [OPTIONS] COMMAND
105 This program is intended to be invoked internally by Open vSwitch startup
106 scripts. System administrators should not normally invoke it directly.
109 insert insert the Open vSwitch kernel modules
110 remove remove the Open vSwitch kernel modules
113 -h, --help display this help message
114 -V, --version display version information
116 Default directories with "configure" option and environment variable override:
117 logs: @LOGDIR@ (--with-logdir, OVS_LOGDIR)
118 pidfiles and sockets: @RUNDIR@ (--with-rundir, OVS_RUNDIR)
119 conf.db: @DBDIR@ (--with-dbdir, OVS_DBDIR)
120 system configuration: @sysconfdir@ (--sysconfdir, OVS_SYSCONFDIR)
121 data files: @pkgdatadir@ (--pkgdatadir, OVS_PKGDATADIR)
122 user binaries: @bindir@ (--bindir, OVS_BINDIR)
123 system binaries: @sbindir@ (--sbindir, OVS_SBINDIR)
125 Please report bugs to bugs@openvswitch.org (see REPORTING-BUGS for details).
132 var
=`echo "$option" | tr abcdefghijklmnopqrstuvwxyz- ABCDEFGHIJKLMNOPQRSTUVWXYZ_`
133 eval set=\
${$var+yes}
134 eval old_value
=\$
$var
135 if test X
$set = X || \
136 (test $type = bool
&& \
137 test X
"$old_value" != Xno
&& test X
"$old_value" != Xyes
); then
138 echo >&2 "$0: unknown option \"$arg\" (use --help for help)"
153 echo "$0 (Open vSwitch) $VERSION"
157 option
=`expr X"$arg" : 'X--\([^=]*\)'`
158 value
=`expr X"$arg" : 'X[^=]*=\(.*\)'`
163 option
=`expr X"$arg" : 'X--no-\(.*\)'`
169 option
=`expr X"$arg" : 'X--\(.*\)'`
175 echo >&2 "$0: unknown option \"$arg\" (use --help for help)"
179 if test X
"$command" = X
; then
182 echo >&2 "$0: exactly one non-option argument required (use --help for help)"
193 insert_kmods_if_required
199 echo >&2 "$0: missing command name (use --help for help)"
203 echo >&2 "$0: unknown command \"$command\" (use --help for help)"