diff options
author | Matoro Mahri <matoro_gentoo@matoro.tk> | 2023-11-25 13:17:41 -0500 |
---|---|---|
committer | Robin H. Johnson <robbat2@gentoo.org> | 2023-11-25 21:30:57 -0800 |
commit | 8b4f91a94fad6666c957304b0108aa5c895b4d1e (patch) | |
tree | 5d3a9aa863c40512af319d26b1cc3ac99eefdf76 | |
parent | net: add qmi interface support (diff) | |
download | netifrc-8b4f91a94fad6666c957304b0108aa5c895b4d1e.tar.gz netifrc-8b4f91a94fad6666c957304b0108aa5c895b4d1e.tar.bz2 netifrc-8b4f91a94fad6666c957304b0108aa5c895b4d1e.zip |
net/dummy.sh: preload module, create interface conditionally
The dummy module has a numdummies parameter which will cause it to
automatically create N dummy interfaces at load time. Because creating
a dummy interface causes the kernel to load the module if it is not
already loaded, then if the name of the interface to be created matches
the name of one of the interfaces the kernel creates, an error will be
returned indicating that the interface already exists, despite it not
existing before the command was invoked.
Ensure we load the module before attempting to create any interface,
then only create the interface if it does not already exist, otherwise
simply configure it.
See: https://serverfault.com/q/839430
Signed-off-by: Matoro Mahri <matoro_gentoo@matoro.tk>
Signed-off-by: Robin H. Johnson <robbat2@gentoo.org>
Closes: https://github.com/gentoo/netifrc/pull/43
-rw-r--r-- | net/dummy.sh | 16 |
1 files changed, 11 insertions, 5 deletions
diff --git a/net/dummy.sh b/net/dummy.sh index 091e08c..94437c3 100644 --- a/net/dummy.sh +++ b/net/dummy.sh @@ -25,12 +25,18 @@ dummy_pre_start() eval dummy="\$type_${IFVAR}" [ "${dummy}" = "dummy" ] || return 0 - ebegin "Creating dummy interface ${IFACE}" - if _ip link add name "${IFACE}" type dummy ; then - eend 0 && _up && set_interface_type dummy - else - eend 1 + if ! test -d /sys/module/dummy && ! modprobe dummy; then + eerror "Couldn't load the dummy module (perhaps the CONFIG_DUMMY kernel option is disabled)" + return 1 fi + + if ! _exists ; then + ebegin "Creating dummy interface ${IFACE}" + _ip link add name "${IFACE}" type dummy + eend $? + fi + + _up && set_interface_type dummy } |