Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Include mac80211_hwsim module in Docker development environment image. #34

Merged
merged 6 commits into from
Nov 28, 2023
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 10 additions & 7 deletions .docker/netremote-dev/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,10 @@ RUN apt-get update && \
ssh \
sudo \
# Generic development tools.
# emacs gdb nano policycoreutils-python-utils python-is-python3 vim
# emacs gdb kmod nano policycoreutils-python-utils python-is-python3 vim
emacs \
gdb \
kmod \
nano \
policycoreutils-python-utils \
python-is-python3 \
Expand All @@ -98,14 +99,16 @@ RUN apt-get update && \
rm -rf /var/lib/apt/lists/*

# Copy outside content into container.
COPY entrypoint.sh /bin/entrypoint.sh
COPY 50-sysinfo /etc/update-motd.d/50-sysinfo
COPY --chmod=0755 entrypoint.sh /bin/entrypoint.sh
COPY --chmod=0755 50-sysinfo /etc/update-motd.d/50-sysinfo
COPY --chmod=0755 build-mac80211_hwsim-kmod.sh /tmp/build-mac80211_hwsim-kmod.sh

# Message of the day settings.
RUN chmod 0755 /etc/update-motd.d/50-sysinfo && \
rm -f /etc/update-motd.d/50-landscape-sysinfo && \
# Permission for entrypoint script
chmod +x /bin/entrypoint.sh
RUN rm -f /etc/update-motd.d/50-landscape-sysinfo

# Build the mac80211_hwsim kernel module.
RUN /tmp/build-mac80211_hwsim-kmod.sh && \
mv /tmp/build-mac80211_hwsim-kmod.sh ${HOME}/

# Set entrypoint and start interactive shell (bash).
ENTRYPOINT [ "/bin/entrypoint.sh" ]
Expand Down
95 changes: 95 additions & 0 deletions .docker/netremote-dev/build-mac80211_hwsim-kmod.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
#!/bin/bash

set -euxo pipefail

DEBUG=1
abeltrano marked this conversation as resolved.
Show resolved Hide resolved

# Determine active kernel version number.
KERNEL_VERSION=`uname -r | grep -Eo '([0-9]+)*(\.?[0-9]+)*' | head -1`

# URL for kernel sources of active kernel version.
KERNEL_FILE_NAME_PREFIX=linux-msft-wsl-
KERNEL_FILE_NAME_STEM=${KERNEL_FILE_NAME_PREFIX}${KERNEL_VERSION}
KERNEL_FILE_NAME_SUFFIX=.tar.gz
KERNEL_FILE_NAME=${KERNEL_FILE_NAME_STEM}${KERNEL_FILE_NAME_SUFFIX}
KERNEL_URL_BASE=https://github.com/microsoft/WSL2-Linux-Kernel/archive/refs/tags
KERNEL_URL_FILE=${KERNEL_URL_BASE}/${KERNEL_FILE_NAME}
KERNEL_CONFIG_UTIL=scripts/config

# WSL kernel source directory name.
WSL_SRC_DIRECTORY_BASE_DEFAULT=${HOME}/src
WSL_SRC_DIRECTORY_BASE=${WSL_SRC_DIRECTORY_BASE:=${WSL_SRC_DIRECTORY_BASE_DEFAULT}}
WSL_SRC_DIRECTORY_PREFIX=WSL2-Linux-Kernel-
WSL_SRC_DIRECTORY=${WSL_SRC_DIRECTORY_PREFIX}${KERNEL_FILE_NAME_STEM}
WSL_SRC_CONFIG_FILE_NAME=config-${KERNEL_VERSION}
WSL_SRC_CONFIG_DIRECTORY=Microsoft
WSL_SRC_CONFIG=${WSL_SRC_CONFIG_DIRECTORY}/${WSL_SRC_CONFIG_FILE_NAME}

# WSL kernel compilation arguments.
WSL_KERNEL_COMPILE_ARG_PARALLEL="-j $(expr $(nproc) - 1)"

# Additional arguments passed to wget when downloading kernel source.
# Mostly used for testing.
WGET_XTRA_ARGS=

if [[ $DEBUG -eq 1 ]]; then
echo "DEBUG: KERNEL_VERSION=${KERNEL_VERSION}"
echo "DEBUG: KERNEL_FILE_NAME=${KERNEL_FILE_NAME}"
echo "DEBUG: KERNEL_URL_FILE=${KERNEL_URL_FILE}"
echo "DEBUG: WSL_SRC_DIRECTORY=${WSL_SRC_DIRECTORY}"
echo "DEBUG: WSL_SRC_CONFIG_FILE_NAME=${WSL_SRC_CONFIG_FILE_NAME}"
echo "DEBUG: WSL_SRC_CONFIG=${WSL_SRC_CONFIG}"
fi

# Install dependencies for building kernel modules.
# (see https://github.com/microsoft/WSL2-Linux-Kernel)
# added bc, python-is-python3
echo "Installing dependencies for building kernel modules..."
sudo apt-get update
sudo apt-get install -y build-essential bc bison flex dwarves kmod libssl-dev libelf-dev python-is-python3 wget

# Download and unpack kernel source.
echo "Downloading and unpacking kernel source..."
if [[ ! -d ${WSL_SRC_DIRECTORY_BASE} ]]; then
mkdir -p ${WSL_SRC_DIRECTORY_BASE}
fi

cd ${WSL_SRC_DIRECTORY_BASE}
wget ${KERNEL_URL_FILE} ${WGET_XTRA_ARGS:+"${WGET_XTRA_ARGS}"} -O - | tar xzvf -
cd ${WSL_SRC_DIRECTORY}

# Prepare the kernel source with the configuration for the running kernel.
echo "Preparing kernel source with configuration for running kernel..."
if [[ ! -f ${WSL_SRC_CONFIG} ]]; then
cat /proc/config.gz | gzip -d > ${WSL_SRC_CONFIG}
fi

if [[ ! -f .config ]]; then
ln -s ${WSL_SRC_CONFIG} .config
fi

# Supply defaults for any new/unspecified options in the configuration.
make olddefconfig

# Prepare the source tree for building external modules.
echo "Preparing kernel source tree for building external modules..."
make prepare modules_prepare ${WSL_KERNEL_COMPILE_ARG_PARALLEL}

# Update the configuration to build the mac80211_hwsim module and its dependencies.
echo "Updating kernel configuration to build mac80211_hwsim module and its dependencies..."
${KERNEL_CONFIG_UTIL} \
--module CONFIG_RFKILL \
--module CONFIG_CFG80211 \
--module CONFIG_MAC80211 \
--module CONFIG_MAC80211_HWSIM

echo "Building kernel modules..."
make modules ${WSL_KERNEL_COMPILE_ARG_PARALLEL}

echo "Installing kernel modules..."
sudo make modules_install

echo "Loading new kernel modules..."
sudo depmod -a

echo "Done."