Skip to content

Commit

Permalink
ovs-kmod-ctl: introduce a kernel module load script
Browse files Browse the repository at this point in the history
Currently, Open vSwitch on linux embeds the logic of loading and unloading
kernel modules into the ovs-ctl and ovs-lib script files.  This works, but
it means that there is no way to leverage extended filesystem attributes
to grant fine grain permissions relating to module loading.

The split out utility 'ovs-kmod-ctl' will be used in an upcoming commit
for RHEL-based distributions to have a separate transition domain that
will allow module loading to be given to a separate selinux domain from
the openvswitch_t domain.

Acked-by: Ansis Atteka <[email protected]>
Acked-by: Timothy Redaelli <[email protected]>
Signed-off-by: Aaron Conole <[email protected]>
  • Loading branch information
apconole authored and Ansis Atteka committed Jun 18, 2018
1 parent 5d2988f commit 1511712
Show file tree
Hide file tree
Showing 10 changed files with 311 additions and 37 deletions.
1 change: 1 addition & 0 deletions debian/openvswitch-switch.install
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,6 @@ usr/sbin/ovs-vswitchd
usr/sbin/ovsdb-server
usr/share/openvswitch/scripts/ovs-check-dead-ifs
usr/share/openvswitch/scripts/ovs-ctl
usr/share/openvswitch/scripts/ovs-kmod-ctl
usr/share/openvswitch/scripts/ovs-save
usr/share/openvswitch/vswitch.ovsschema
1 change: 1 addition & 0 deletions debian/openvswitch-switch.manpages
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ ovsdb/ovsdb-server.5
utilities/ovs-ctl.8
utilities/ovs-dpctl-top.8
utilities/ovs-dpctl.8
utilities/ovs-kmod-ctl.8
utilities/ovs-pcap.1
utilities/ovs-tcpdump.8
utilities/ovs-tcpundump.1
Expand Down
2 changes: 2 additions & 0 deletions rhel/openvswitch-fedora.spec.in
Original file line number Diff line number Diff line change
Expand Up @@ -548,6 +548,7 @@ fi
%{_datadir}/openvswitch/scripts/ovs-save
%{_datadir}/openvswitch/scripts/ovs-vtep
%{_datadir}/openvswitch/scripts/ovs-ctl
%{_datadir}/openvswitch/scripts/ovs-kmod-ctl
%{_datadir}/openvswitch/scripts/ovs-systemd-reload
%config %{_datadir}/openvswitch/vswitch.ovsschema
%config %{_datadir}/openvswitch/vtep.ovsschema
Expand Down Expand Up @@ -581,6 +582,7 @@ fi
%{_mandir}/man8/ovs-ctl.8*
%{_mandir}/man8/ovs-dpctl.8*
%{_mandir}/man8/ovs-dpctl-top.8*
%{_mandir}/man8/ovs-kmod-ctl.8*
%{_mandir}/man8/ovs-ofctl.8*
%{_mandir}/man8/ovs-pki.8*
%{_mandir}/man8/ovs-vsctl.8*
Expand Down
2 changes: 2 additions & 0 deletions rhel/openvswitch.spec.in
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,7 @@ exit 0
/usr/share/man/man8/ovs-ctl.8.gz
/usr/share/man/man8/ovs-dpctl.8.gz
/usr/share/man/man8/ovs-dpctl-top.8.gz
/usr/share/man/man8/ovs-kmod-ctl.8.gz
/usr/share/man/man8/ovs-ofctl.8.gz
/usr/share/man/man8/ovs-parse-backtrace.8.gz
/usr/share/man/man8/ovs-pki.8.gz
Expand All @@ -251,6 +252,7 @@ exit 0
/usr/share/openvswitch/scripts/ovs-bugtool-*
/usr/share/openvswitch/scripts/ovs-check-dead-ifs
/usr/share/openvswitch/scripts/ovs-ctl
/usr/share/openvswitch/scripts/ovs-kmod-ctl
/usr/share/openvswitch/scripts/ovs-lib
/usr/share/openvswitch/scripts/ovs-save
/usr/share/openvswitch/scripts/ovs-vtep
Expand Down
1 change: 1 addition & 0 deletions utilities/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
/ovs-dpctl.8
/ovs-dpctl-top
/ovs-dpctl-top.8
/ovs-kmod-ctl
/ovs-l3ping
/ovs-l3ping.8
/ovs-lib
Expand Down
5 changes: 5 additions & 0 deletions utilities/automake.mk
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ endif
scripts_SCRIPTS += \
utilities/ovs-check-dead-ifs \
utilities/ovs-ctl \
utilities/ovs-kmod-ctl \
utilities/ovs-save
scripts_DATA += utilities/ovs-lib

Expand All @@ -44,6 +45,7 @@ EXTRA_DIST += \
utilities/ovs-dev.py \
utilities/ovs-docker \
utilities/ovs-dpctl-top.in \
utilities/ovs-kmod-ctl.in \
utilities/ovs-l3ping.in \
utilities/ovs-lib.in \
utilities/ovs-parse-backtrace.in \
Expand All @@ -63,6 +65,7 @@ MAN_ROOTS += \
utilities/ovs-ctl.8 \
utilities/ovs-dpctl.8.in \
utilities/ovs-dpctl-top.8.in \
utilities/ovs-kmod-ctl.8 \
utilities/ovs-l3ping.8.in \
utilities/ovs-ofctl.8.in \
utilities/ovs-parse-backtrace.8 \
Expand All @@ -81,6 +84,7 @@ CLEANFILES += \
utilities/ovs-dpctl.8 \
utilities/ovs-dpctl-top \
utilities/ovs-dpctl-top.8 \
utilities/ovs-kmod-ctl \
utilities/ovs-l3ping \
utilities/ovs-l3ping.8 \
utilities/ovs-lib \
Expand All @@ -106,6 +110,7 @@ man_MANS += \
utilities/ovs-testcontroller.8 \
utilities/ovs-dpctl.8 \
utilities/ovs-dpctl-top.8 \
utilities/ovs-kmod-ctl.8 \
utilities/ovs-l3ping.8 \
utilities/ovs-ofctl.8 \
utilities/ovs-parse-backtrace.8 \
Expand Down
32 changes: 2 additions & 30 deletions utilities/ovs-ctl.in
Original file line number Diff line number Diff line change
Expand Up @@ -30,37 +30,9 @@ done
## start ##
## ----- ##

insert_mods () {
# Try loading openvswitch again.
action "Inserting openvswitch module" modprobe openvswitch
}

insert_mod_if_required () {
# If this kernel has no module support, expect we're done.
if test ! -e /proc/modules
then
log_success_msg "Kernel has no loadable module support. Skipping modprobe"
return 0
fi

# If openvswitch is already loaded then we're done.
test -e /sys/module/openvswitch && return 0

# Load openvswitch. If that's successful then we're done.
insert_mods && return 0

# If the bridge module is loaded, then that might be blocking
# openvswitch. Try to unload it, if there are no bridges.
test -e /sys/module/bridge || return 1
bridges=`echo /sys/class/net/*/bridge | sed 's,/sys/class/net/,,g;s,/bridge,,g'`
if test "$bridges" != "*"; then
log_warning_msg "not removing bridge module because bridges exist ($bridges)"
return 1
fi
action "removing bridge module" rmmod bridge || return 1

# Try loading openvswitch again.
insert_mods
## This takes care of inserting any required kernel modules
ovs_kmod_ctl insert
}

set_hostname () {
Expand Down
109 changes: 109 additions & 0 deletions utilities/ovs-kmod-ctl.8
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
.\" -*- nroff -*-
.de IQ
. br
. ns
. IP "\\$1"
..
.de ST
. PP
. RS -0.15in
. I "\\$1"
. RE
..
.TH ovs\-ctl 8 "February 2018" "Open vSwitch" "Open vSwitch Manual"
.ds PN ovs\-ctl
.
.SH NAME
ovs\-kmod\-ctl \- OVS startup helper script for loading kernel modules
.
.SH SYNOPSIS
\fBovs\-kmod\-ctl\fR \fBinsert
.br
\fBovs\-kmod\-ctl \fBremove
.br
\fBovs\-kmod\-ctl help \fR| \fB\-h \fR| \fB\-\-help
.br
\fBovs\-kmod\-ctl \-\-version
.br
\fBovs\-kmod\-ctl version
.
.SH DESCRIPTION
.
.PP
The \fBovs\-kmod\-ctl\fR program is responsible for inserting and
removing Open vSwitch kernel modules. It is not meant to be invoked
directly by system administrators but to be called internally by
system startup scripts. The script is used as part of an SELinux
transition domain.
.
.PP
Each of \fBovs\-kmod\-ctl\fR's commands is described separately below.
.
.SH "The ``insert'' command"
.
.PP
The \fBinsert\fR command loads the Open vSwitch kernel modules, if
needed. If this fails, and the Linux bridge module is loaded but no
bridges exist, it tries to unload the bridge module and tries loading
the Open vSwitch kernel module again.
.
.SH "The ``remove'' command"
.
.PP
The \fBremove\fR command unloads the Open vSwitch kernel module (including
the bridge compatibility module, if loaded) and any associated vport
modules.
.
.SH "EXIT STATUS"
.
\fBovs\-kmod\-ctl\fR exits with status 0 on success and nonzero on
failure. The \fBinsert\fR command is considered to succeed if kernel
modules are already loaded; the \fBremove\fR command is considered to
succeed if none of the kernel modules are loaded.
.
.SH "ENVIRONMENT"
.
The following environment variables affect \fBovs\-kmod\-ctl\fR:
.
.IP "\fBPATH\fR"
\fBovs\-kmod\-ctl\fR does not hardcode the location of any of the programs
that it runs. \fBovs\-kmod\-ctl\fR will add the \fIsbindir\fR and
\fIbindir\fR that were specified at \fBconfigure\fR time to
\fBPATH\fR, if they are not already present.
.
.IP "\fBOVS_LOGDIR\fR"
.IQ "\fBOVS_RUNDIR\fR"
.IQ "\fBOVS_DBDIR\fR"
.IQ "\fBOVS_SYSCONFDIR\fR"
.IQ "\fBOVS_PKGDATADIR\fR"
.IQ "\fBOVS_BINDIR\fR"
.IQ "\fBOVS_SBINDIR\fR"
Setting one of these variables in the environment overrides the
respective \fBconfigure\fR option, both for \fBovs\-kmod\-ctl\fR itself
and for the other Open vSwitch programs that it runs.
.
.SH "FILES"
.
\fBovs\-kmod\-ctl\fR uses the following files:
.
.IP "\fBovs\-lib"
Shell function library used internally by \fBovs\-kmod\-ctl\fR. It must
be installed in the same directory as \fBovs\-kmod\-ctl\fR.
.
.SH "EXAMPLE"
.
.PP
\fBovs\-kmod\-ctl\fR isn't intended to be manually executed. However, the
following examples demonstrate loading the kernel modules.
.
.TP
\fBovs\-kmod\-ctl\fR insert
Attempts to insert the Open vSwitch kernel modules.
.
.TP
\fBovs\-kmod\-ctl\fR remove
Attempts to remove the Open vSwitch kernel modules.
.
.SH "SEE ALSO"
.
\fBREADME.rst\fR, \fBovs\-ctl\fR(8)
Loading

0 comments on commit 1511712

Please sign in to comment.