]>
Commit | Line | Data |
---|---|---|
15117123 AC |
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 | . "@pkgdatadir@/scripts/ovs-lib" || exit 1 | |
18 | ||
19 | for dir in "$sbindir" "$bindir" /sbin /bin /usr/sbin /usr/bin; do | |
20 | case :$PATH: in | |
21 | *:$dir:*) ;; | |
22 | *) PATH=$PATH:$dir ;; | |
23 | esac | |
24 | done | |
25 | ||
26 | insert_mods () { | |
27 | # Try loading openvswitch kernel module. | |
28 | action "Inserting openvswitch module" modprobe openvswitch | |
29 | } | |
30 | ||
31 | insert_kmods_if_required() { | |
32 | # If this kernel has no module support, expect we're done. | |
33 | if test ! -e /proc/modules | |
34 | then | |
35 | log_success_msg "Kernel has no loadable module support. Skipping modprobe" | |
36 | return 0 | |
37 | fi | |
38 | ||
39 | # If openvswitch is already loaded then we're done. | |
40 | test -e /sys/module/openvswitch && return 0 | |
41 | ||
42 | # Load openvswitch. If that's successful then we're done. | |
43 | insert_mods && return 0 | |
44 | ||
45 | # If the bridge module is loaded, then that might be blocking | |
46 | # openvswitch. Try to unload it, if there are no bridges. | |
47 | test -e /sys/module/bridge || return 1 | |
48 | bridges=`echo /sys/class/net/*/bridge | sed 's,/sys/class/net/,,g;s,/bridge,,g'` | |
49 | if test "$bridges" != "*"; then | |
50 | log_warning_msg "not removing bridge module because bridges exist ($bridges)" | |
51 | return 1 | |
52 | fi | |
53 | action "removing bridge module" rmmod bridge || return 1 | |
54 | ||
55 | # Try loading openvswitch again. | |
56 | insert_mods | |
57 | } | |
58 | ||
59 | remove_kmods() { | |
60 | for vport in `awk '/^vport_/ { print $1 }' /proc/modules`; do | |
61 | action "Removing $vport module" rmmod $vport | |
62 | done | |
63 | ||
64 | if test -e /sys/module/ip_gre; then | |
65 | action "Forcing removal of ip_gre module" rmmod ip_gre | |
66 | fi | |
67 | ||
68 | if test -e /sys/module/gre; then | |
69 | action "Forcing removal of gre module" rmmod gre | |
70 | fi | |
71 | ||
72 | if test -e /sys/module/openvswitch; then | |
73 | action "Removing openvswitch module" rmmod openvswitch | |
74 | fi | |
e95ce654 GR |
75 | |
76 | # Older releases may be using the rtnetlink interface while a | |
77 | # newer release will want to use the internal compat interface | |
78 | # for geneve and vxlan. | |
79 | if test -e /sys/class/net/genev_sys_6081; then | |
80 | action "Removing geneve device" \ | |
81 | ip link del link genev_sys_6081 dev genev_sys_6081 | |
82 | fi | |
83 | if test -e /sys/class/net/vxlan_sys_4789; then | |
84 | action "Removing vxlan device" \ | |
85 | ip link del link vxlan_sys_4789 dev vxlan_sys_4789 | |
86 | fi | |
87 | ||
88 | if test -e /sys/module/geneve; then | |
89 | action "Forcing removal of geneve module" rmmod geneve | |
90 | fi | |
91 | if test -e /sys/module/vxlan; then | |
92 | action "Forcing removal of vxlan module" rmmod vxlan | |
93 | fi | |
15117123 AC |
94 | } |
95 | ||
96 | usage () { | |
97 | cat <<EOF | |
98 | $0: controls Open vSwitch kernel modules | |
99 | usage: $0 [OPTIONS] COMMAND | |
100 | ||
101 | This program is intended to be invoked internally by Open vSwitch startup | |
102 | scripts. System administrators should not normally invoke it directly. | |
103 | ||
104 | Commands: | |
105 | insert insert the Open vSwitch kernel modules | |
106 | remove remove the Open vSwitch kernel modules | |
107 | ||
108 | Options: | |
109 | -h, --help display this help message | |
110 | -V, --version display version information | |
111 | ||
112 | Default directories with "configure" option and environment variable override: | |
113 | logs: @LOGDIR@ (--with-logdir, OVS_LOGDIR) | |
114 | pidfiles and sockets: @RUNDIR@ (--with-rundir, OVS_RUNDIR) | |
115 | conf.db: @DBDIR@ (--with-dbdir, OVS_DBDIR) | |
116 | system configuration: @sysconfdir@ (--sysconfdir, OVS_SYSCONFDIR) | |
117 | data files: @pkgdatadir@ (--pkgdatadir, OVS_PKGDATADIR) | |
118 | user binaries: @bindir@ (--bindir, OVS_BINDIR) | |
119 | system binaries: @sbindir@ (--sbindir, OVS_SBINDIR) | |
120 | ||
121 | Please report bugs to bugs@openvswitch.org (see REPORTING-BUGS for details). | |
122 | EOF | |
123 | ||
124 | exit 0 | |
125 | } | |
126 | ||
127 | set_option () { | |
128 | var=`echo "$option" | tr abcdefghijklmnopqrstuvwxyz- ABCDEFGHIJKLMNOPQRSTUVWXYZ_` | |
129 | eval set=\${$var+yes} | |
130 | eval old_value=\$$var | |
131 | if test X$set = X || \ | |
132 | (test $type = bool && \ | |
133 | test X"$old_value" != Xno && test X"$old_value" != Xyes); then | |
134 | echo >&2 "$0: unknown option \"$arg\" (use --help for help)" | |
135 | return | |
136 | fi | |
137 | eval $var=\$value | |
138 | } | |
139 | ||
140 | extra_ids= | |
141 | command= | |
142 | for arg | |
143 | do | |
144 | case $arg in | |
145 | -h | --help) | |
146 | usage | |
147 | ;; | |
148 | -V | --version) | |
149 | echo "$0 (Open vSwitch) $VERSION" | |
150 | exit 0 | |
151 | ;; | |
152 | --[a-z]*=*) | |
153 | option=`expr X"$arg" : 'X--\([^=]*\)'` | |
154 | value=`expr X"$arg" : 'X[^=]*=\(.*\)'` | |
155 | type=string | |
156 | set_option | |
157 | ;; | |
158 | --no-[a-z]*) | |
159 | option=`expr X"$arg" : 'X--no-\(.*\)'` | |
160 | value=no | |
161 | type=bool | |
162 | set_option | |
163 | ;; | |
164 | --[a-z]*) | |
165 | option=`expr X"$arg" : 'X--\(.*\)'` | |
166 | value=yes | |
167 | type=bool | |
168 | set_option | |
169 | ;; | |
170 | -*) | |
171 | echo >&2 "$0: unknown option \"$arg\" (use --help for help)" | |
172 | exit 1 | |
173 | ;; | |
174 | *) | |
175 | if test X"$command" = X; then | |
176 | command=$arg | |
177 | else | |
178 | echo >&2 "$0: exactly one non-option argument required (use --help for help)" | |
179 | exit 1 | |
180 | fi | |
181 | ;; | |
182 | esac | |
183 | done | |
184 | case $command in | |
185 | remove) | |
186 | remove_kmods | |
187 | ;; | |
188 | insert) | |
189 | insert_kmods_if_required | |
190 | ;; | |
191 | help) | |
192 | usage | |
193 | ;; | |
194 | '') | |
195 | echo >&2 "$0: missing command name (use --help for help)" | |
196 | exit 1 | |
197 | ;; | |
198 | *) | |
199 | echo >&2 "$0: unknown command \"$command\" (use --help for help)" | |
200 | exit 1 | |
201 | ;; | |
202 | esac |