Skip to content

Commit

Permalink
[WOL] Implement wake on LAN command line tool (#19206) (#21136)
Browse files Browse the repository at this point in the history
Why I did it
Implement wake on LAN command line tool to send magic packets to target interface with extra parameters like mac address, password, count and interval.

How I did it
Setup rust compile environment, write code and test to implement the tool.
Set raw socket capacity for wol binary when build image.

How to verify it
Unit test and manually test with packet capture.

Co-authored-by: Wenda Chu <[email protected]>
  • Loading branch information
mssonicbld and w1nda authored Dec 12, 2024
1 parent 2b0f9db commit 3cdb2a6
Show file tree
Hide file tree
Showing 16 changed files with 1,229 additions and 0 deletions.
5 changes: 5 additions & 0 deletions files/build_templates/sonic_debian_extension.j2
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,11 @@ sudo mkdir -p $FILESYSTEM_ROOT_USR_SHARE_SONIC_FIRMWARE/
# Keeping it generic. It should not harm anyways.
sudo mkdir -p $FILESYSTEM_ROOT_USR_LIB_SYSTEMD_SYSTEM

# Install sonic-nettools
sudo dpkg --root=$FILESYSTEM_ROOT -i $debs_path/sonic-nettools_*.deb || \
sudo LANG=C DEBIAN_FRONTEND=noninteractive chroot $FILESYSTEM_ROOT apt-get -y install -f
sudo setcap 'cap_net_raw=+ep' $FILESYSTEM_ROOT/usr/bin/wol

# Install a patched version of ifupdown2 (and its dependencies via 'apt-get -y install -f')
sudo dpkg --root=$FILESYSTEM_ROOT -i $debs_path/ifupdown2_*.deb || \
sudo LANG=C DEBIAN_FRONTEND=noninteractive chroot $FILESYSTEM_ROOT apt-get -y install -f
Expand Down
7 changes: 7 additions & 0 deletions rules/sonic-nettools.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
SONIC_NETTOOLS_VERSION = 0.0.1-0

export SONIC_NETTOOLS_VERSION

SONIC_NETTOOLS = sonic-nettools_$(SONIC_NETTOOLS_VERSION)_$(CONFIGURED_ARCH).deb
$(SONIC_NETTOOLS)_SRC_PATH = $(SRC_PATH)/sonic-nettools
SONIC_DPKG_DEBS += $(SONIC_NETTOOLS)
10 changes: 10 additions & 0 deletions slave.mk
Original file line number Diff line number Diff line change
Expand Up @@ -362,6 +362,15 @@ CROSS_COMPILE_FLAGS := CGO_ENABLED=1 GOOS=linux GOARCH=$(GOARCH) CROSS_COMPILE=$

endif

ifeq ($(CROSS_BUILD_ENVIRON),y)
ifeq ($(CONFIGURED_ARCH),armhf)
RUST_CROSS_COMPILE_TARGET = armv7-unknown-linux-gnueabihf
else ifeq ($(CONFIGURED_ARCH),arm64)
RUST_CROSS_COMPILE_TARGET = aarch64-unknown-linux-gnu
endif
export RUST_CROSS_COMPILE_TARGET
endif

###############################################################################
## Routing stack related exports
###############################################################################
Expand Down Expand Up @@ -1370,6 +1379,7 @@ $(addprefix $(TARGET_PATH)/, $(SONIC_INSTALLERS)) : $(TARGET_PATH)/% : \
$(PYTHON_SWSSCOMMON) \
$(PYTHON3_SWSSCOMMON) \
$(SONIC_DB_CLI) \
$(SONIC_NETTOOLS) \
$(SONIC_RSYSLOG_PLUGIN) \
$(SONIC_UTILITIES_DATA) \
$(SONIC_HOST_SERVICES_DATA) \
Expand Down
14 changes: 14 additions & 0 deletions sonic-slave-bookworm/Dockerfile.j2
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ RUN apt-get update && apt-get install -y eatmydata && eatmydata apt-get install
git-buildpackage \
perl-modules \
libclass-accessor-perl \
libcap2-bin \
libswitch-perl \
libzmq5 \
libzmq3-dev \
Expand Down Expand Up @@ -657,6 +658,7 @@ RUN eatmydata apt-get install -y \
pps-tools:$arch \
libpam-cap:$arch \
libcap-dev:$arch \
libcap2-bin:$arch \
libpam0g-dev:$arch \
libaudit-dev:$arch \
libgtk-3-dev:$arch \
Expand Down Expand Up @@ -738,3 +740,15 @@ RUN eatmydata apt install -y python-is-python3
ARG bazelisk_url=https://github.com/bazelbuild/bazelisk/releases/latest/download/bazelisk-linux-{{ CONFIGURED_ARCH }}
RUN curl -fsSL -o /usr/local/bin/bazel ${bazelisk_url} && chmod 755 /usr/local/bin/bazel
{% endif -%}

# Install Rust
ARG RUST_ROOT=/usr/.cargo
RUN RUSTUP_HOME=$RUST_ROOT CARGO_HOME=$RUST_ROOT bash -c 'curl --proto "=https" -sSf https://sh.rustup.rs | sh -s -- --default-toolchain 1.79.0 -y'
{% if CROSS_BUILD_ENVIRON == "y" and CONFIGURED_ARCH == "armhf" %}
RUN mkdir -p /.cargo && $RUST_ROOT/bin/rustup target add armv7-unknown-linux-gnueabihf && echo "[target.armv7-unknown-linux-gnueabihf]\nlinker = \"arm-linux-gnueabihf-gcc\"" >> /.cargo/config.toml
{% endif -%}
{% if CROSS_BUILD_ENVIRON == "y" and CONFIGURED_ARCH == "arm64" %}
RUN mkdir -p /.cargo && $RUST_ROOT/bin/rustup target add aarch64-unknown-linux-gnu && echo "[target.aarch64-unknown-linux-gnu]\nlinker = \"aarch64-linux-gnu-gcc\"" >> /.cargo/config.toml
{% endif -%}
ENV RUSTUP_HOME $RUST_ROOT
ENV PATH $PATH:$RUST_ROOT/bin
3 changes: 3 additions & 0 deletions src/sonic-nettools/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
target/
bin/
.vscode/
Loading

0 comments on commit 3cdb2a6

Please sign in to comment.