]> git.proxmox.com Git - ovs.git/blob - utilities/ovs-kmod-ctl.in
Fix renaming: libopenvswitch-2.14.so.0.0.90 -> libopenvswitch-2.15.so.0.0.0
[ovs.git] / utilities / ovs-kmod-ctl.in
1 #! /bin/sh
2 # SPDX-License-Identifier: Apache-2.0
3 # Copyright (C) 2018 Red Hat, Inc.
4 #
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:
8 #
9 # http://www.apache.org/licenses/LICENSE-2.0
10 #
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.
16
17 case $0 in
18 */*) dir0=`echo "$0" | sed 's,/[^/]*$,,'` ;;
19 *) dir0=./ ;;
20 esac
21 . "$dir0/ovs-lib" || exit 1
22
23 for dir in "$sbindir" "$bindir" /sbin /bin /usr/sbin /usr/bin; do
24 case :$PATH: in
25 *:$dir:*) ;;
26 *) PATH=$PATH:$dir ;;
27 esac
28 done
29
30 insert_mods () {
31 # Try loading openvswitch kernel module.
32 action "Inserting openvswitch module" modprobe openvswitch
33 }
34
35 insert_kmods_if_required() {
36 # If this kernel has no module support, expect we're done.
37 if test ! -e /proc/modules
38 then
39 log_success_msg "Kernel has no loadable module support. Skipping modprobe"
40 return 0
41 fi
42
43 # If openvswitch is already loaded then we're done.
44 test -e /sys/module/openvswitch && return 0
45
46 # Load openvswitch. If that's successful then we're done.
47 insert_mods && return 0
48
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)"
55 return 1
56 fi
57 action "removing bridge module" rmmod bridge || return 1
58
59 # Try loading openvswitch again.
60 insert_mods
61 }
62
63 remove_kmods() {
64 for vport in `awk '/^vport_/ { print $1 }' /proc/modules`; do
65 action "Removing $vport module" rmmod $vport
66 done
67
68 if test -e /sys/module/ip_gre; then
69 action "Forcing removal of ip_gre module" rmmod ip_gre
70 fi
71
72 if test -e /sys/module/gre; then
73 action "Forcing removal of gre module" rmmod gre
74 fi
75
76 if test -e /sys/module/openvswitch; then
77 action "Removing openvswitch module" rmmod openvswitch
78 fi
79
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
86 fi
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
90 fi
91
92 if test -e /sys/module/geneve; then
93 action "Forcing removal of geneve module" rmmod geneve
94 fi
95 if test -e /sys/module/vxlan; then
96 action "Forcing removal of vxlan module" rmmod vxlan
97 fi
98 }
99
100 usage () {
101 cat <<EOF
102 $0: controls Open vSwitch kernel modules
103 usage: $0 [OPTIONS] COMMAND
104
105 This program is intended to be invoked internally by Open vSwitch startup
106 scripts. System administrators should not normally invoke it directly.
107
108 Commands:
109 insert insert the Open vSwitch kernel modules
110 remove remove the Open vSwitch kernel modules
111
112 Options:
113 -h, --help display this help message
114 -V, --version display version information
115
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)
124
125 Please report bugs to bugs@openvswitch.org (see REPORTING-BUGS for details).
126 EOF
127
128 exit 0
129 }
130
131 set_option () {
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)"
139 return
140 fi
141 eval $var=\$value
142 }
143
144 extra_ids=
145 command=
146 for arg
147 do
148 case $arg in
149 -h | --help)
150 usage
151 ;;
152 -V | --version)
153 echo "$0 (Open vSwitch) $VERSION"
154 exit 0
155 ;;
156 --[a-z]*=*)
157 option=`expr X"$arg" : 'X--\([^=]*\)'`
158 value=`expr X"$arg" : 'X[^=]*=\(.*\)'`
159 type=string
160 set_option
161 ;;
162 --no-[a-z]*)
163 option=`expr X"$arg" : 'X--no-\(.*\)'`
164 value=no
165 type=bool
166 set_option
167 ;;
168 --[a-z]*)
169 option=`expr X"$arg" : 'X--\(.*\)'`
170 value=yes
171 type=bool
172 set_option
173 ;;
174 -*)
175 echo >&2 "$0: unknown option \"$arg\" (use --help for help)"
176 exit 1
177 ;;
178 *)
179 if test X"$command" = X; then
180 command=$arg
181 else
182 echo >&2 "$0: exactly one non-option argument required (use --help for help)"
183 exit 1
184 fi
185 ;;
186 esac
187 done
188 case $command in
189 remove)
190 remove_kmods
191 ;;
192 insert)
193 insert_kmods_if_required
194 ;;
195 help)
196 usage
197 ;;
198 '')
199 echo >&2 "$0: missing command name (use --help for help)"
200 exit 1
201 ;;
202 *)
203 echo >&2 "$0: unknown command \"$command\" (use --help for help)"
204 exit 1
205 ;;
206 esac