Skip to content

Commit 92f9378

Browse files
authored
[WOL] Implement wake on LAN command line tool (sonic-net#19206)
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.
1 parent d0f0a61 commit 92f9378

File tree

16 files changed

+1229
-0
lines changed

16 files changed

+1229
-0
lines changed

files/build_templates/sonic_debian_extension.j2

+5
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,11 @@ sudo mkdir -p $FILESYSTEM_ROOT_USR_SHARE_SONIC_FIRMWARE/
9999
# Keeping it generic. It should not harm anyways.
100100
sudo mkdir -p $FILESYSTEM_ROOT_USR_LIB_SYSTEMD_SYSTEM
101101

102+
# Install sonic-nettools
103+
sudo dpkg --root=$FILESYSTEM_ROOT -i $debs_path/sonic-nettools_*.deb || \
104+
sudo LANG=C DEBIAN_FRONTEND=noninteractive chroot $FILESYSTEM_ROOT apt-get -y install -f
105+
sudo setcap 'cap_net_raw=+ep' $FILESYSTEM_ROOT/usr/bin/wol
106+
102107
# Install a patched version of ifupdown2 (and its dependencies via 'apt-get -y install -f')
103108
sudo dpkg --root=$FILESYSTEM_ROOT -i $debs_path/ifupdown2_*.deb || \
104109
sudo LANG=C DEBIAN_FRONTEND=noninteractive chroot $FILESYSTEM_ROOT apt-get -y install -f

rules/sonic-nettools.mk

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
SONIC_NETTOOLS_VERSION = 0.0.1-0
2+
3+
export SONIC_NETTOOLS_VERSION
4+
5+
SONIC_NETTOOLS = sonic-nettools_$(SONIC_NETTOOLS_VERSION)_$(CONFIGURED_ARCH).deb
6+
$(SONIC_NETTOOLS)_SRC_PATH = $(SRC_PATH)/sonic-nettools
7+
SONIC_DPKG_DEBS += $(SONIC_NETTOOLS)

slave.mk

+10
Original file line numberDiff line numberDiff line change
@@ -362,6 +362,15 @@ CROSS_COMPILE_FLAGS := CGO_ENABLED=1 GOOS=linux GOARCH=$(GOARCH) CROSS_COMPILE=$
362362

363363
endif
364364

365+
ifeq ($(CROSS_BUILD_ENVIRON),y)
366+
ifeq ($(CONFIGURED_ARCH),armhf)
367+
RUST_CROSS_COMPILE_TARGET = armv7-unknown-linux-gnueabihf
368+
else ifeq ($(CONFIGURED_ARCH),arm64)
369+
RUST_CROSS_COMPILE_TARGET = aarch64-unknown-linux-gnu
370+
endif
371+
export RUST_CROSS_COMPILE_TARGET
372+
endif
373+
365374
###############################################################################
366375
## Routing stack related exports
367376
###############################################################################
@@ -1368,6 +1377,7 @@ $(addprefix $(TARGET_PATH)/, $(SONIC_INSTALLERS)) : $(TARGET_PATH)/% : \
13681377
$(PYTHON_SWSSCOMMON) \
13691378
$(PYTHON3_SWSSCOMMON) \
13701379
$(SONIC_DB_CLI) \
1380+
$(SONIC_NETTOOLS) \
13711381
$(SONIC_RSYSLOG_PLUGIN) \
13721382
$(SONIC_UTILITIES_DATA) \
13731383
$(SONIC_HOST_SERVICES_DATA) \

sonic-slave-bookworm/Dockerfile.j2

+14
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,7 @@ RUN apt-get update && apt-get install -y eatmydata && eatmydata apt-get install
113113
git-buildpackage \
114114
perl-modules \
115115
libclass-accessor-perl \
116+
libcap2-bin \
116117
libswitch-perl \
117118
libzmq5 \
118119
libzmq3-dev \
@@ -656,6 +657,7 @@ RUN eatmydata apt-get install -y \
656657
pps-tools:$arch \
657658
libpam-cap:$arch \
658659
libcap-dev:$arch \
660+
libcap2-bin:$arch \
659661
libpam0g-dev:$arch \
660662
libaudit-dev:$arch \
661663
libgtk-3-dev:$arch \
@@ -737,3 +739,15 @@ RUN eatmydata apt install -y python-is-python3
737739
ARG bazelisk_url=https://github.com/bazelbuild/bazelisk/releases/latest/download/bazelisk-linux-{{ CONFIGURED_ARCH }}
738740
RUN curl -fsSL -o /usr/local/bin/bazel ${bazelisk_url} && chmod 755 /usr/local/bin/bazel
739741
{% endif -%}
742+
743+
# Install Rust
744+
ARG RUST_ROOT=/usr/.cargo
745+
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'
746+
{% if CROSS_BUILD_ENVIRON == "y" and CONFIGURED_ARCH == "armhf" %}
747+
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
748+
{% endif -%}
749+
{% if CROSS_BUILD_ENVIRON == "y" and CONFIGURED_ARCH == "arm64" %}
750+
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
751+
{% endif -%}
752+
ENV RUSTUP_HOME $RUST_ROOT
753+
ENV PATH $PATH:$RUST_ROOT/bin

src/sonic-nettools/.gitignore

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
target/
2+
bin/
3+
.vscode/

0 commit comments

Comments
 (0)