From a81b1f8f2b391e1dca2526ecc967f521323c3e62 Mon Sep 17 00:00:00 2001 From: Vincent Li Date: Thu, 25 Sep 2025 21:36:38 +0000 Subject: [PATCH] arpwatch: add arpwatch as common package Signed-off-by: Vincent Li --- config/rootfiles/common/arpwatch | 8 ++ config/rootfiles/common/x86_64/initscripts | 5 + lfs/arpwatch | 117 ++++++++++++++++++ lfs/initscripts | 3 + make.sh | 1 + src/initscripts/sysconfig/arpwatch | 8 ++ src/initscripts/system/arpwatch | 81 ++++++++++++ .../arpwatch/53_stop-using-_getshort.patch | 25 ++++ 8 files changed, 248 insertions(+) create mode 100644 config/rootfiles/common/arpwatch create mode 100644 lfs/arpwatch create mode 100644 src/initscripts/sysconfig/arpwatch create mode 100644 src/initscripts/system/arpwatch create mode 100644 src/patches/arpwatch/53_stop-using-_getshort.patch diff --git a/config/rootfiles/common/arpwatch b/config/rootfiles/common/arpwatch new file mode 100644 index 000000000..bd0c57dd2 --- /dev/null +++ b/config/rootfiles/common/arpwatch @@ -0,0 +1,8 @@ +etc/rc.d/init.d/arpwatch +etc/sysconfig/arpwatch +usr/sbin/arpsnmp +usr/sbin/arpwatch +#usr/share/man/man8/arpsnmp.8 +#usr/share/man/man8/arpwatch.8 +#var/lib/arpwatch +var/lib/arpwatch/ethercodes.dat diff --git a/config/rootfiles/common/x86_64/initscripts b/config/rootfiles/common/x86_64/initscripts index 7ddea4088..59ef9f5f4 100644 --- a/config/rootfiles/common/x86_64/initscripts +++ b/config/rootfiles/common/x86_64/initscripts @@ -10,6 +10,7 @@ etc/rc.d/helper/oci-setup #etc/rc.d/init.d etc/rc.d/init.d/acpid etc/rc.d/init.d/apache +etc/rc.d/init.d/arpwatch etc/rc.d/init.d/beep etc/rc.d/init.d/checkfs etc/rc.d/init.d/cleanfs @@ -107,6 +108,7 @@ etc/rc.d/init.d/kdump-vars.sh #etc/rc.d/rc0.d/K01vdradmin #etc/rc.d/rc0.d/K02sslh etc/rc.d/rc0.d/K08fcron +etc/rc.d/rc0.d/K12arpwatch etc/rc.d/rc0.d/K28apache etc/rc.d/rc0.d/K30sshd etc/rc.d/rc0.d/K47setclock @@ -145,6 +147,7 @@ etc/rc.d/rc3.d/S30sshd etc/rc.d/rc3.d/S32apache etc/rc.d/rc3.d/S40fcron etc/rc.d/rc3.d/S50wireguard +etc/rc.d/rc3.d/S64arpwatch etc/rc.d/rc3.d/S98rc.local #etc/rc.d/rc3.d/S98sslh #etc/rc.d/rc3.d/S99imspetor @@ -156,6 +159,7 @@ etc/rc.d/rc3.d/S98rc.local #etc/rc.d/rc6.d/K01vdradmin #etc/rc.d/rc6.d/K02sslh etc/rc.d/rc6.d/K08fcron +etc/rc.d/rc6.d/K12arpwatch etc/rc.d/rc6.d/K28apache etc/rc.d/rc6.d/K30sshd etc/rc.d/rc6.d/K47setclock @@ -205,3 +209,4 @@ etc/sysconfig/modules etc/sysconfig/ramdisk etc/sysconfig/rc etc/sysconfig/rc.local +etc/sysconfig/arpwatch diff --git a/lfs/arpwatch b/lfs/arpwatch new file mode 100644 index 000000000..aa37563a6 --- /dev/null +++ b/lfs/arpwatch @@ -0,0 +1,117 @@ +############################################################################### +# # +# IPFire.org - A linux based firewall # +# Copyright (C) 2007-2025 IPFire Team # +# # +# This program is free software: you can redistribute it and/or modify # +# it under the terms of the GNU General Public License as published by # +# the Free Software Foundation, either version 3 of the License, or # +# (at your option) any later version. # +# # +# This program is distributed in the hope that it will be useful, # +# but WITHOUT ANY WARRANTY; without even the implied warranty of # +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # +# GNU General Public License for more details. # +# # +# You should have received a copy of the GNU General Public License # +# along with this program. If not, see . # +# # +############################################################################### + +############################################################################### +# Definitions +############################################################################### + +include Config + +SUMMARY = Monitoring tool for ARP traffic on a network + +VER = 3.8 +ETHERCODES_DATE = 20200628 + +# From: https://ee.lbl.gov/downloads/arpwatch/ + +THISAPP = arpwatch-$(VER) +DL_FILE = $(THISAPP).tar.gz +DL_FROM = $(URL_IPFIRE) +DIR_APP = $(DIR_SRC)/$(THISAPP) +TARGET = $(DIR_INFO)/$(THISAPP) +PROG = arpwatch +PAK_VER = 1 + +DEPS = + +SERVICES = arpwatch + +# Enable debugging code +CFLAGS += -DDEBUG=1 + +############################################################################### +# Top-level Rules +############################################################################### + +objects = $(DL_FILE) ethercodes.dat-$(ETHERCODES_DATE).xz + +$(DL_FILE) = $(DL_FROM)/$(DL_FILE) +ethercodes.dat-$(ETHERCODES_DATE).xz = $(DL_FROM)/ethercodes.dat-$(ETHERCODES_DATE).xz + +$(DL_FILE)_BLAKE2 = a43a2ad007da266f58b5c5fd617c8955940cffc88233c16455b553aea4c9ddad8cf744996b342f156c879aab29ce6c5ae85b93abdb0fbf5dd674d39e851de273 +ethercodes.dat-$(ETHERCODES_DATE).xz_BLAKE2 = e702b9109ef3ccce73e2637f96126bf19e7dfa533774c0bd623042b3609f147981263b84397ec155a65ae12fa57247c32644e1e7e57c2c749ef768156d853027 + +install : $(TARGET) + +check : $(patsubst %,$(DIR_CHK)/%,$(objects)) + +download :$(patsubst %,$(DIR_DL)/%,$(objects)) + +b2 : $(subst %,%_BLAKE2,$(objects)) + +dist: + @$(PAK) + +############################################################################### +# Downloading, checking, b2sum +############################################################################### + +$(patsubst %,$(DIR_CHK)/%,$(objects)) : + @$(CHECK) + +$(patsubst %,$(DIR_DL)/%,$(objects)) : + @$(LOAD) + +$(subst %,%_BLAKE2,$(objects)) : + @$(B2SUM) + +############################################################################### +# Installation Details +############################################################################### + +$(TARGET) : $(patsubst %,$(DIR_DL)/%,$(objects)) + @$(PREBUILD) + @rm -rf $(DIR_APP) && cd $(DIR_SRC) && tar axf $(DIR_DL)/$(DL_FILE) + + # Fix compilation issues + cd $(DIR_APP) && patch -Np1 < $(DIR_SRC)/src/patches/arpwatch/53_stop-using-_getshort.patch + cd $(DIR_APP) && sed -i '1i#include ' report.c + + # Don't install the initscript + cd $(DIR_APP) && sed -i '/@HAVE_FREEBSD_TRUE@/d' Makefile.in + + # Build! + cd $(DIR_APP) && ./configure --prefix=/usr + cd $(DIR_APP) && make $(MAKETUNING) + cd $(DIR_APP) && make install + + # Install initscripts + # $(call INSTALL_INITSCRIPTS,$(SERVICES)) + + # Install the data directory + -mkdir -pv /var/lib/arpwatch + + # Install ethercodes.dat + xz -dvv \ + < $(DIR_DL)/ethercodes.dat-$(ETHERCODES_DATE).xz \ + > /var/lib/arpwatch/ethercodes.dat + + @rm -rf $(DIR_APP) + @$(POSTBUILD) diff --git a/lfs/initscripts b/lfs/initscripts index 5cb6d939b..214521f85 100644 --- a/lfs/initscripts +++ b/lfs/initscripts @@ -96,6 +96,7 @@ $(TARGET) : ln -sf ../init.d/vdradmin /etc/rc.d/rc0.d/K01vdradmin ln -sf ../init.d/sslh /etc/rc.d/rc0.d/K02sslh ln -sf ../init.d/fcron /etc/rc.d/rc0.d/K08fcron + ln -sf ../init.d/arpwatch /etc/rc.d/rc0.d/K12arpwatch ln -sf ../init.d/apache /etc/rc.d/rc0.d/K28apache ln -sf ../init.d/sshd /etc/rc.d/rc0.d/K30sshd ln -sf ../init.d/setclock /etc/rc.d/rc0.d/K47setclock @@ -133,6 +134,7 @@ $(TARGET) : ln -sf ../init.d/haproxy /etc/rc.d/rc3.d/S35haproxy ln -sf ../init.d/fcron /etc/rc.d/rc3.d/S40fcron ln -sf ../init.d/wireguard /etc/rc.d/rc3.d/S50wireguard + ln -sf ../init.d/arpwatch /etc/rc.d/rc3.d/S64arpwatch ln -sf ../../sysconfig/rc.local /etc/rc.d/rc3.d/S98rc.local ln -sf ../init.d/sslh /etc/rc.d/rc3.d/S98sslh ln -sf ../init.d/imspetor /etc/rc.d/rc3.d/S99imspetor @@ -150,6 +152,7 @@ $(TARGET) : ln -sf ../init.d/vdradmin /etc/rc.d/rc6.d/K01vdradmin ln -sf ../init.d/sslh /etc/rc.d/rc6.d/K02sslh ln -sf ../init.d/fcron /etc/rc.d/rc6.d/K08fcron + ln -sf ../init.d/arpwatch /etc/rc.d/rc6.d/K12arpwatch ln -sf ../init.d/apache /etc/rc.d/rc6.d/K28apache ln -sf ../init.d/sshd /etc/rc.d/rc6.d/K30sshd ln -sf ../init.d/setclock /etc/rc.d/rc6.d/K47setclock diff --git a/make.sh b/make.sh index ddaa16a48..f5eeaa70f 100755 --- a/make.sh +++ b/make.sh @@ -1727,6 +1727,7 @@ buildipfire() { lfsmake2 wireguard-tools lfsmake2 kexec-tools lfsmake2 makedumpfile + lfsmake2 arpwatch # Kernelbuild ... current we have no platform that need diff --git a/src/initscripts/sysconfig/arpwatch b/src/initscripts/sysconfig/arpwatch new file mode 100644 index 000000000..d4886cf6c --- /dev/null +++ b/src/initscripts/sysconfig/arpwatch @@ -0,0 +1,8 @@ +# Interface to monitor +INTERFACES="green0 blue0" + +# Email address to send alerts to +WATCHER=hostmaster@somewhere.example.com + +# Sender email address +WATCHEE=hostmaster@somewhere.example.com diff --git a/src/initscripts/system/arpwatch b/src/initscripts/system/arpwatch new file mode 100644 index 000000000..09dcdf1ba --- /dev/null +++ b/src/initscripts/system/arpwatch @@ -0,0 +1,81 @@ +#!/bin/sh +############################################################################### +# # +# IPFire.org - A linux based firewall # +# Copyright (C) 2007-2022 IPFire Team # +# # +# This program is free software: you can redistribute it and/or modify # +# it under the terms of the GNU General Public License as published by # +# the Free Software Foundation, either version 3 of the License, or # +# (at your option) any later version. # +# # +# This program is distributed in the hope that it will be useful, # +# but WITHOUT ANY WARRANTY; without even the implied warranty of # +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # +# GNU General Public License for more details. # +# # +# You should have received a copy of the GNU General Public License # +# along with this program. If not, see . # +# # +############################################################################### + +. /etc/sysconfig/rc +. ${rc_functions} + +# Optionally load the configuration file +if [ -r "/etc/sysconfig/arpwatch" ]; then + . /etc/sysconfig/arpwatch +fi + +case "${1}" in + start) + args=( + -D /var/lib/arpwatch + ) + + # Add the watcher + if [ -n "${WATCHER}" ]; then + args+=( "-w" "${WATCHER}" ) + fi + + # Add the watchee + if [ -n "${WATCHEE}" ]; then + args+=( "-W" "${WATCHEE}" ) + fi + + for intf in ${INTERFACES}; do + boot_mesg "Starting ARP Watch on ${intf}..." + + # Create the data file for this interface + if [ ! -e "/var/lib/arpwatch/${intf}.dat" ]; then + : > "/var/lib/arpwatch/${intf}.dat" + fi + + PIDFILE="/var/run/arpwatch-${intf}.pid" \ + loadproc -f \ + /usr/sbin/arpwatch "${args[@]}" \ + -P "/var/run/arpwatch-${intf}.pid" \ + -f "/var/lib/arpwatch/${intf}.dat" \ + -i "${intf}" + done + ;; + + stop) + for intf in ${INTERFACES}; do + boot_mesg "Stopping ARP Watch on ${intf}..." + PIDFILE="/var/run/arpwatch-${intf}.pid" \ + killproc /usr/sbin/arpwatch + done + ;; + + restart) + ${0} stop + sleep 1 + ${0} start + ;; + + *) + echo "Usage: ${0} {start|stop|restart}" + exit 1 + ;; +esac diff --git a/src/patches/arpwatch/53_stop-using-_getshort.patch b/src/patches/arpwatch/53_stop-using-_getshort.patch new file mode 100644 index 000000000..da83f4b43 --- /dev/null +++ b/src/patches/arpwatch/53_stop-using-_getshort.patch @@ -0,0 +1,25 @@ +Description: replace private function _getshort with ns_get16 + _getshort is a private function, triggers a build log warning because it's + not present in any header file. We switch to the functionally equivalent + ns_get16. +Author: Lukas Schwaighofer + +--- + dns.c | 6 +++--- + 1 file changed, 3 insertions(+), 3 deletions(-) + +--- a/dns.c ++++ b/dns.c +@@ -115,10 +115,10 @@ + (u_char *)cp, (char *)bp, buflen)) < 0) + break; + cp += n; +- type = _getshort(cp); ++ type = ns_get16(cp); + cp += sizeof(u_short); /* class */ + cp += sizeof(u_short) + sizeof(u_int32_t); +- n = _getshort(cp); ++ n = ns_get16(cp); + cp += sizeof(u_short); + if (type == T_HINFO) { + /* Unpack */